1
0
forked from cgvr/DeltaVR

WIP: spawn generated model as archery range target

This commit is contained in:
2025-12-01 17:19:31 +02:00
parent 40e273f51e
commit 408949e5c2
3 changed files with 19 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using _PROJECT.Scripts.Bow;
using FishNet.Object;
using FishNet.Object.Synchronizing;
@@ -36,6 +37,8 @@ public class ArcheryRange : NetworkBehaviour
private float _nextTargetTime;
private bool _roundActive;
private string targetModelName;
private readonly List<XROrigin> _presentPlayers = new();
private XROrigin _scoredPlayer;
@@ -112,7 +115,7 @@ public class ArcheryRange : NetworkBehaviour
}
}
private void SpawnTarget()
async private void SpawnTarget()
{
if (!IsServer) return;
@@ -122,18 +125,22 @@ public class ArcheryRange : NetworkBehaviour
Random.Range(minRandomOffset.z, maxRandomOffset.z)
);
var target = SpawnTarget(randomPos);
var target = await SpawnTarget(randomPos);
_targets.Add(target);
}
private ArcheryTarget SpawnTarget(Vector3 randomPos)
async private Task<ArcheryTarget> SpawnTarget(Vector3 randomPos)
{
var prefab = Instantiate(targetPrefab, randomPos, Quaternion.identity, null);
var targetObject = Instantiate(targetPrefab, randomPos, Quaternion.identity, null);
GameObject targetReplacement = await PipelineManager.Instance.SpawnModel(targetModelName);
// TODO: replace target prefab's child with the generated model
ArcheryTarget target = prefab.GetComponent<ArcheryTarget>();
targetReplacement.transform.parent = targetObject.transform;
targetReplacement.transform.position = targetObject.transform.position;
ArcheryTarget target = targetObject.GetComponent<ArcheryTarget>();
target.endPosition = targetEndPosition.position;
target.addScore = AddScore;
Spawn(prefab);
Spawn(targetObject);
return target;
}
@@ -176,9 +183,12 @@ public class ArcheryRange : NetworkBehaviour
SetTimeLeftText("");
}
public void StartRound()
async public void StartRound()
{
if (!IsServer) return;
targetModelName = await PipelineManager.Instance.GenerateModelAsync("unicorn with golden horn and long fluffy tail and butterfly wings");
_roundEndTime = Time.time + roundLength;
_nextTargetTime = Time.time;
_roundActive = true;

View File

@@ -82,7 +82,6 @@ public class PipelineManager : MonoBehaviour
if (loadSuccess)
{
GameObject spawnedObject = new GameObject("spawned model");
bool spawnSuccess = await gltf.InstantiateMainSceneAsync(spawnedObject.transform);
if (spawnSuccess)