using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; using UnityEngine.Serialization; public enum AniType { buYuan, taoKou } public class ModelAniTool : MonoBehaviour { public string moveModelName; public int objectCount=0; private Vector3[] oriV3; public float speed=2.0f; public GameObject[] targetObjs; public AniType aniType; private float[] openValues; public void FindObje() { targetObjs = new GameObject[objectCount]; oriV3 = new Vector3[objectCount]; for (int i = 0; i < objectCount; i++) { targetObjs[i] = this.transform.Find(moveModelName+"(Clone)").GetChild(objectCount-1-i).gameObject; switch (aniType) { case AniType.buYuan: oriV3[i] = targetObjs[i].transform.localPosition; break; case AniType.taoKou: oriV3[i] = targetObjs[i].transform.localEulerAngles; break; } } ActionInstance._Instance.ModelAni_On += Ani_On; ActionInstance._Instance.ModelAni_Off += Ani_Off; } public void Ani_On(AniType type,float[] v3s) { if (type != aniType) { return; } if (v3s == null) { v3s = new float[targetObjs.Length]; for (int i = 0; i < v3s.Length; i++) { v3s[i] = 1; } } openValues = v3s; switch (aniType) { case AniType.buYuan: for (int i = 0; i < targetObjs.Length; i++) { int tempIndex = i; targetObjs[i].transform.localPosition = oriV3[tempIndex]; targetObjs[i].transform.DOLocalMoveZ(8*openValues[tempIndex], speed); //Debug.Log($"{targetObjs[i].name}:{openValues[tempIndex]}"); } break; case AniType.taoKou: for (int i = 0; i < targetObjs.Length; i++) { int tempIndex = i; targetObjs[i].transform.localEulerAngles = oriV3[tempIndex]; targetObjs[i].transform.DOLocalRotate(new Vector3(-45.0f,0,0) *openValues[tempIndex], speed); } break; } } public void Ani_Off() { switch (aniType) { case AniType.buYuan: for (int i = 0; i < targetObjs.Length; i++) { int tempIndex = i; targetObjs[i].transform.localPosition = oriV3[tempIndex] + new Vector3(0, 0, 8); targetObjs[i].transform.DOLocalMoveZ(0, speed); } break; case AniType.taoKou: for (int i = 0; i < targetObjs.Length; i++) { int tempIndex = i; targetObjs[i].transform.localEulerAngles = new Vector3(-45.0f,0,0)*openValues[tempIndex]; targetObjs[i].transform.DOLocalRotate(Vector3.zero, speed); } break; } } }