177 lines
5.5 KiB
C#
177 lines
5.5 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace BF
|
||
{
|
||
[ExecuteInEditMode]
|
||
[DisallowMultipleComponent]
|
||
public class WeaponHelper : MonoBehaviour
|
||
{
|
||
public GameObject modelObject;
|
||
public List<CharacterObjectInfo> objectList = new List<CharacterObjectInfo>();
|
||
public List<CharacterAnimationInfo> animationList = new List<CharacterAnimationInfo>();
|
||
|
||
public float PositionX { get; private set; }
|
||
public float PositionY { get; private set; }
|
||
public float PositionZ { get; private set; }
|
||
|
||
public GameObject GetModelObject()
|
||
{
|
||
return modelObject;
|
||
}
|
||
|
||
public int GetModelHashCode()
|
||
{
|
||
return gameObject.GetHashCode();
|
||
}
|
||
|
||
public int GetListCount()
|
||
{
|
||
return objectList.Count;
|
||
}
|
||
|
||
public GameObject GetGameObjectByIndex(int index)
|
||
{
|
||
if (index >= 0 && index < objectList.Count)
|
||
{
|
||
return objectList[index].gameObject;
|
||
}
|
||
else if (index < 0)
|
||
{
|
||
return this.gameObject;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public uint GetHashNameByIndex(int index)
|
||
{
|
||
if (index >= 0 && index < objectList.Count)
|
||
{
|
||
return objectList[index].hashName;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
// Lua层可以使用PositionX,PositionY,PositionZ,减少直接传递localPosition的开销
|
||
public void CacheLocalPosition(int index)
|
||
{
|
||
if (index >= 0 && index < objectList.Count)
|
||
{
|
||
var localPosition = objectList[index].gameObject.transform.localPosition;
|
||
PositionX = localPosition.x;
|
||
PositionY = localPosition.y;
|
||
PositionZ = localPosition.z;
|
||
}
|
||
else if (index < 0)
|
||
{
|
||
PositionX = this.transform.localPosition.x;
|
||
PositionY = this.transform.localPosition.y;
|
||
PositionZ = this.transform.localPosition.z;
|
||
}
|
||
}
|
||
|
||
public void SetLocalPosition(int index, float x, float y, float z)
|
||
{
|
||
if (index >= 0 && index < objectList.Count)
|
||
{
|
||
objectList[index].gameObject.transform.localPosition = new Vector3(x, y, z);
|
||
}
|
||
else if (index < 0)
|
||
{
|
||
this.transform.localPosition = new Vector3(x, y, z);
|
||
}
|
||
}
|
||
// Lua层可以使用PositionX,PositionY,PositionZ,减少直接传递position的开销
|
||
public void CachePosition(int index)
|
||
{
|
||
if (index >= 0 && index < objectList.Count)
|
||
{
|
||
var position = objectList[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 < objectList.Count)
|
||
{
|
||
objectList[index].gameObject.transform.position = new Vector3(x, y, z);
|
||
}
|
||
else if (index < 0)
|
||
{
|
||
this.transform.position = new Vector3(x, y, z);
|
||
}
|
||
}
|
||
|
||
public void SetLocalEulerAngles(int index, float x, float y, float z)
|
||
{
|
||
if (index >= 0 && index < objectList.Count)
|
||
{
|
||
objectList[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 < objectList.Count)
|
||
{
|
||
objectList[index].gameObject.transform.localScale = new Vector3(x, y, z);
|
||
}
|
||
else if (index < 0)
|
||
{
|
||
this.transform.localScale = new Vector3(x, y, z);
|
||
}
|
||
}
|
||
|
||
public void SetMainModelLocalPosition(float x, float y, float z)
|
||
{
|
||
modelObject.transform.localPosition = new Vector3(x, y, z);
|
||
}
|
||
|
||
public float GetStateTime(uint index)
|
||
{
|
||
int count = animationList.Count;
|
||
for(int i = 0; i < count; i++)
|
||
{
|
||
if(animationList[i].hashName == index)
|
||
{
|
||
return animationList[i].animationTime;
|
||
}
|
||
}
|
||
return 0.0f;
|
||
}
|
||
|
||
public uint GetStateKeyFrame(uint hashName, int index)
|
||
{
|
||
int count = animationList.Count;
|
||
CharacterAnimationInfo characterAnimationInfo;
|
||
for(int i = 0; i < count; i++)
|
||
{
|
||
characterAnimationInfo = animationList[i];
|
||
if(characterAnimationInfo.hashName == hashName)
|
||
{
|
||
if(characterAnimationInfo.keyFrame != null && characterAnimationInfo.keyFrame.Count > index)
|
||
{
|
||
return characterAnimationInfo.keyFrame[index];
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
}
|
||
}
|