using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BF { [ExecuteInEditMode] [DisallowMultipleComponent] public class NodeHelper : MonoBehaviour { public List prefabList = new List(); public float PositionX { get; private set; } public float PositionY { get; private set; } public float PositionZ { get; private set; } public GameObject GetGameObjectByName(string name) { int count = prefabList.Count; for (int i = 0; i < count; i++) { if (prefabList[i].name == name) { return prefabList[i].gameObject; } } return null; } public int GetListCount() { return prefabList.Count; } public uint GetHashNameByIndex(int index) { if (index >= 0 && index < prefabList.Count) { return prefabList[index].hashName; } return 0; } public int GetObjectTypeByIndex(int index) { if (index >= 0 && index < prefabList.Count) { return prefabList[index].objectType; } return 0; } public GameObject GetGameObjectByIndex(int index) { if (index >= 0 && index < prefabList.Count) { return prefabList[index].gameObject; } else if (index < 0) { return this.gameObject; } return null; } public void SetLocalPosition(int index, float x, float y, float z) { if (index >= 0 && index < prefabList.Count) { prefabList[index].gameObject.transform.localPosition = new Vector3(x, y, z); } else if (index < 0) { this.transform.localPosition = new Vector3(x, y, z); } } public void CachePosition(int index) { if (index >= 0 && index < prefabList.Count) { var position = prefabList[index].gameObject.transform.position; PositionX = position.x; PositionY = position.y; PositionZ = position.z; } else if (index < 0) { PositionX = this.transform.position.x; PositionY = this.transform.position.y; PositionZ = this.transform.position.z; } } public void SetPosition(int index, float x, float y, float z) { if (index >= 0 && index < prefabList.Count) { prefabList[index].gameObject.transform.position = new Vector3(x, y, z); } else if (index < 0) { this.transform.position = new Vector3(x, y, z); } } public void SetPositionX(int index, float x) { if (index >= 0 && index < prefabList.Count) { var childTransform = prefabList[index].gameObject.transform; childTransform.position = new Vector3(x, childTransform.position.y, childTransform.position.z); } else if (index < 0) { this.transform.position = new Vector3(x, this.transform.position.y, this.transform.position.z); } } public void SetPositionY(int index, float y) { if (index >= 0 && index < prefabList.Count) { var childTransform = prefabList[index].gameObject.transform; childTransform.position = new Vector3(childTransform.position.x, y, childTransform.position.z); } else if (index < 0) { this.transform.position = new Vector3(this.transform.position.x, y, this.transform.position.z); } } public void SetPositionZ(int index, float z) { if (index >= 0 && index < prefabList.Count) { var childTransform = prefabList[index].gameObject.transform; childTransform.position = new Vector3(childTransform.position.x, childTransform.position.y, z); } else if (index < 0) { this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, z); } } public void CacheLocalEulerAngles(int index) { if (index >= 0 && index < prefabList.Count) { var localEulerAngles = prefabList[index].gameObject.transform.localEulerAngles; PositionX = localEulerAngles.x; PositionY = localEulerAngles.y; PositionZ = localEulerAngles.z; } else if (index < 0) { PositionX = this.transform.localEulerAngles.x; PositionY = this.transform.localEulerAngles.y; PositionZ = this.transform.localEulerAngles.z; } } public void SetLocalEulerAngles(int index, float x, float y, float z) { if (index >= 0 && index < prefabList.Count) { prefabList[index].gameObject.transform.localEulerAngles = new Vector3(x, y, z); } else if (index < 0) { this.transform.localEulerAngles = new Vector3(x, y, z); } } public float GetLocalEulerAnglesZ(int index) { if (index >= 0 && index < prefabList.Count) { var localEulerAngles = prefabList[index].gameObject.transform.localEulerAngles; return localEulerAngles.z; } else if (index < 0) { return this.transform.localEulerAngles.z; } return 0.0f; } public void SetLocalEulerAnglesZ(int index, float z) { if (index >= 0 && index < prefabList.Count) { var localEulerAngles = prefabList[index].gameObject.transform.localEulerAngles; prefabList[index].gameObject.transform.localEulerAngles = new Vector3(localEulerAngles.x, localEulerAngles.y, z); } else if (index < 0) { this.transform.localEulerAngles = new Vector3(this.transform.localEulerAngles.x, this.transform.localEulerAngles.y, z); } } public void SetLocalScale(int index, float x, float y, float z) { if (index >= 0 && index < prefabList.Count) { prefabList[index].gameObject.transform.localScale = new Vector3(x, y, z); } else if (index < 0) { this.transform.localScale = new Vector3(x, y, z); } } void OnDestroy() { prefabList.Clear(); prefabList = null; } } }