123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Linq;
- namespace MetaClient
- {
- public class AniRoByTime : MonoBehaviour
- {
- public Dictionary<int, Quaternion> dicRo = new Dictionary<int, Quaternion>();
- public Dictionary<int,Vector3> pos = new Dictionary<int,Vector3>();
- private Quaternion initRo = new Quaternion();
- private Vector3 initPos = new Vector3();
- private int startTime = 0;
- private Vector3 startPos = new Vector3();
- private Vector3 endPos = new Vector3();
- private Quaternion startRo = new Quaternion();
- private int endTime = 0;
- private Quaternion endRo = new Quaternion();
- private List<Quaternion> mList = new List<Quaternion>();
- private int lasttime = 0;
- public AniManager aniManager;
- public bool allBody=false;
- // Start is called before the first frame update
- void Start()
- {
-
- }
- public void Init()
- {
- if (this.gameObject.name == aniManager.nowAniName)
- {
- allBody = true;
- initRo = this.gameObject.transform.localRotation;
- initPos = this.gameObject.transform.localPosition;
- }
- else
- {
- initRo = this.gameObject.transform.parent.localRotation;
- }
- }
- public void DicOrderBy()
- {
- Dictionary<int, Quaternion> newdic = dicRo.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
- dicRo = newdic;
- Dictionary<int,Vector3> newpos=pos.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
- pos = newpos;
- }
- public void RoAllBodyChangeFun(int _time)
- {
- startTime = 0;
- startRo = initRo;
- startPos = initPos;
- endPos = initPos;
- endTime = 0;
- endRo = initRo;
- lasttime = -1;
- if (dicRo.Count == 0)
- {
- // return;
- this.gameObject.transform.localRotation = initRo;
- this.gameObject.transform.localPosition = initPos;
- return;
- }
- else if (dicRo.Count == 1)
- {
- mList = new List<Quaternion>();
- var value = dicRo.Values.GetEnumerator();
- value.MoveNext();
- var valuePos = pos.Values.GetEnumerator();
- valuePos.MoveNext();
- this.gameObject.transform.localRotation = value.Current;
- this.gameObject.transform.localPosition = valuePos.Current;
- }
- else
- {
- mList = new List<Quaternion>();
- var value = dicRo.Keys.GetEnumerator();
- var valuePos = pos.Values.GetEnumerator();
- while (value.MoveNext())
- {
- valuePos.MoveNext();
- int data = value.Current;
- if (_time < data)
- {
- endTime = data;
- endRo = dicRo[endTime];
- endPos = pos[endTime];
- if (lasttime != -1)
- {
- startTime = lasttime;
- startRo = dicRo[lasttime];
- startPos = pos[lasttime];
- RoAllBodyChange(_time);
- }
- else
- {
- if (dicRo.ContainsKey(lasttime))
- {
- this.gameObject.transform.localRotation = dicRo[lasttime];
- this.gameObject.transform.localPosition = pos[lasttime];
- }
- else
- {
- this.gameObject.transform.localPosition = endPos;
- }
- return;
- //startTime = endTime;
- //startRo = endRo;
- }
- }
- else
- {
- lasttime = value.Current;
- }
- }
- }
- }
- public void RoChangeFun(int _time)
- {
- if (allBody)
- {
- RoAllBodyChangeFun(_time);
- return;
- }
- startTime = 0;
- startRo = initRo;
- endTime = 0;
- endRo = initRo;
- lasttime = -1;
- if (dicRo.Count == 0)
- {
- // return;
- this.gameObject.transform.parent.localRotation = initRo;
- return;
- }
- else if (dicRo.Count == 1)
- {
- //List<Quaternion> mList;
- mList = new List<Quaternion>();
- var value = dicRo.Values.GetEnumerator();
- value.MoveNext();
- this.gameObject.transform.parent.localRotation = value.Current;
- //while (value.MoveNext())
- //{
- // Quaternion data = value.Current;
- // mList.Add(data);
- //}
- //this.gameObject.transform.localEulerAngles = dicRo;
- }
- else
- {
- mList = new List<Quaternion>();
- var value = dicRo.Keys.GetEnumerator();
- while (value.MoveNext())
- {
- int data = value.Current;
- if (_time < data)
- {
- endTime = data;
- endRo = dicRo[endTime];
- if (lasttime != -1)
- {
- startTime = lasttime;
- startRo = dicRo[lasttime];
- RoChange(_time);
- }
- else
- {
- if (dicRo.ContainsKey(lasttime))
- {
- this.gameObject.transform.parent.localRotation = dicRo[lasttime];
- }
- else
- {
- this.gameObject.transform.parent.localRotation = endRo;
- }
- return;
- //startTime = endTime;
- //startRo = endRo;
- }
- }
- else
- {
- lasttime = value.Current;
- }
- }
- }
- }
- public void RoAllBodyChange(int _time)
- {
- Quaternion _nextRo = new Quaternion();
- Vector3 _nextPos = new Vector3();
- if (endTime <= _time)
- {
- this.gameObject.transform.localRotation = endRo;
- this.gameObject.transform.localPosition = endPos;
- return;
- }
- else if (endTime == startTime)
- {
- this.gameObject.transform.localRotation = endRo;
- this.gameObject.transform.localPosition = endPos;
- return;
- }
- _nextRo = Quaternion.Lerp(endRo, startRo, (endTime - _time) / (endTime - startTime));
- Debug.Log("结束旋转" + endRo + "");
- Debug.Log("开始旋转" + startRo + "");
- this.gameObject.transform.localRotation = _nextRo;
- _nextPos =Vector3.Lerp(endPos, startPos, (endTime - _time) / (endTime - startTime));
- Debug.Log("结束距离" + endPos + "");
- Debug.Log("开始距离" + startPos + "");
- this.gameObject.transform.localPosition = _nextPos;
- }
- public void RoChange(int _time)
- {
- Quaternion _nextRo = new Quaternion();
- if (endTime <= _time)
- {
- this.gameObject.transform.parent.localRotation = endRo;
- return;
- }
- else if (endTime == startTime)
- {
- this.gameObject.transform.parent.localRotation = endRo;
- return;
- }
- _nextRo = Quaternion.Lerp(endRo, startRo, (endTime - _time) / (endTime - startTime));
- Debug.Log("结束距离" + endRo + "");
- Debug.Log("开始距离" + startRo + "");
- this.gameObject.transform.parent.localRotation = _nextRo;
- }
- public void DicAdd(int _time)
- {
- if (allBody)
- {
- if (dicRo.ContainsKey(_time))
- {
- dicRo[_time] = this.gameObject.transform.localRotation;
- pos[_time] = this.gameObject.transform.localPosition;
- }
- else
- {
- dicRo.Add(_time, this.gameObject.transform.localRotation);
- pos[_time] = this.gameObject.transform.localPosition;
- }
- }
- else
- {
- if (dicRo.ContainsKey(_time))
- {
- dicRo[_time] = this.gameObject.transform.parent.localRotation;
- }
- else
- {
- dicRo.Add(_time, this.gameObject.transform.parent.localRotation);
- }
- }
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
- }
|