forked from cgvr/DeltaVR
manage spawned object node hierarchy better
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using _PROJECT.Scripts.Bow;
|
||||
using FishNet.Component.Transforming;
|
||||
using FishNet.Object;
|
||||
using FishNet.Object.Synchronizing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using _PROJECT.Scripts.Bow;
|
||||
using FishNet.Object;
|
||||
using FishNet.Object.Synchronizing;
|
||||
using TMPro;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
@@ -21,6 +22,8 @@ public class ArcheryRange : NetworkBehaviour
|
||||
public GameObject targetPrefab;
|
||||
public StartTarget startTarget;
|
||||
|
||||
public GameObject archeryTargetPointsText;
|
||||
|
||||
public Vector3 minRandomOffset = new Vector3(0f, -2f, -5f);
|
||||
public Vector3 maxRandomOffset = new Vector3(0f, 2f, 5f);
|
||||
public float roundLength = 60f;
|
||||
@@ -130,14 +133,19 @@ public class ArcheryRange : NetworkBehaviour
|
||||
|
||||
async private Task<ArcheryTarget> SpawnTarget(Vector3 randomPos)
|
||||
{
|
||||
var targetObject = Instantiate(targetPrefab, randomPos, Quaternion.identity, null);
|
||||
string targetModelPath = modelGenerationBox.LastModelPath;
|
||||
|
||||
// Replace target prefab's child with the generated model
|
||||
GameObject targetReplacement = await PipelineManager.Instance.SpawnModel(targetModelPath, false);
|
||||
Destroy(targetObject.transform.GetChild(0).gameObject);
|
||||
targetReplacement.transform.parent = targetObject.transform;
|
||||
targetReplacement.transform.position = targetObject.transform.position;
|
||||
GameObject targetObject;
|
||||
if (modelGenerationBox.LastModelPath == null)
|
||||
{
|
||||
// spawn default UFO
|
||||
targetObject = Instantiate(targetPrefab, randomPos, Quaternion.identity, null);
|
||||
} else
|
||||
{
|
||||
// spawn generated model
|
||||
targetObject = await PipelineManager.Instance.SpawnModel(modelGenerationBox.LastModelPath);
|
||||
targetObject.transform.position = randomPos;
|
||||
targetObject.transform.rotation = Quaternion.identity;
|
||||
InitializeArcherytargetObject(targetObject);
|
||||
}
|
||||
|
||||
ArcheryTarget target = targetObject.GetComponent<ArcheryTarget>();
|
||||
target.endPosition = targetEndPosition.position;
|
||||
@@ -146,6 +154,19 @@ public class ArcheryRange : NetworkBehaviour
|
||||
return target;
|
||||
}
|
||||
|
||||
private void InitializeArcherytargetObject(GameObject targetObject)
|
||||
{
|
||||
ArcheryTarget archeryTarget = targetObject.AddComponent<ArcheryTarget>();
|
||||
archeryTarget.pointsText = archeryTargetPointsText;
|
||||
|
||||
Rigidbody rigidbody = targetObject.AddComponent<Rigidbody>();
|
||||
rigidbody.useGravity = false;
|
||||
rigidbody.isKinematic = true;
|
||||
|
||||
targetObject.AddComponent<NetworkObject>();
|
||||
targetObject.AddComponent<NetworkTransform>();
|
||||
}
|
||||
|
||||
|
||||
public void ResetRange()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user