154 lines
4.5 KiB
C#
154 lines
4.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace BF
|
|
{
|
|
[ExecuteInEditMode]
|
|
[DisallowMultipleComponent]
|
|
public class NodeHelper : MonoBehaviour
|
|
{
|
|
public List<GameObjectInfo> prefabList = new List<GameObjectInfo>();
|
|
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 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 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;
|
|
}
|
|
}
|
|
}
|