private AnimatorDelegate _callback; // 回调 public RisingInfo(float time, float distance, AnimatorDelegate callback) { _time = time; _distance = distance; _step = distance / (time / Time.deltaTime); _callback = callback; }
public float CurTime; // time after scale begin public ScaleInfo(GameObject go, float totalTime, float scaleStepX, float scaleStepY, float targetScaleX, float targetScaleY, AnimatorDelegate scaleCallback) { Go = go; TotalTime = totalTime; TargetScaleX = targetScaleX; TargetScaleY = targetScaleY; ScaleCallback = scaleCallback; ScaleStepX = scaleStepX; ScaleStepY = scaleStepY; CurTime = 0; }
void ChangeCharacter(int n) { if (currentCharacter == n) { return; } if (factory == null || !factory.HasAWalker(n)) { return; } currentCharacter = n; Animator current = GetComponentInChildren <Animator> (); Debug.Log(current); Transform parent = transform; Quaternion orgRot = transform.localRotation; if (current != null) { parent = current.transform.parent; orgRot = current.transform.localRotation; DestroyImmediate(current.gameObject); } AAgent agent2 = factory.GetAWalker(n); Animator nAnim = agent2.GetComponentInChildren <Animator> (); nAnim.runtimeAnimatorController = controller; nAnim.transform.SetParent(parent); nAnim.transform.localPosition = Vector3.zero; nAnim.transform.localRotation = orgRot; DestroyImmediate(agent2.gameObject); AnimatorDelegate ad = nAnim.gameObject.AddComponent <AnimatorDelegate> (); ad.target = gameObject; MonoBehaviour[] monos = gameObject.GetComponents <MonoBehaviour> (); foreach (MonoBehaviour mono in monos) { mono.SendMessage("OnModelChanged", nAnim, SendMessageOptions.DontRequireReceiver); } }
// 增加一个新的动画 public void AddRising(GameObject go, float time, float distance, AnimatorDelegate callback = null) { RisingInfo info = new RisingInfo(time, distance, callback); _risingSet[go] = info; }
public void AddScale(GameObject go, float time, float targetScaleX, float targetScaleY, AnimatorDelegate callback = null) { var curScale = go.transform.localScale; float scaleStepX = 0; float scaleStepY = 0; if (Mathf.Abs(targetScaleX - scaleStepX) > 1e-7) { scaleStepX = (targetScaleX - curScale.x) / (time / Time.deltaTime); } if (Mathf.Abs(targetScaleY - scaleStepY) > 1e-7) { scaleStepY = (targetScaleY - curScale.y) / (time / Time.deltaTime); } var info = new ScaleInfo(go, time, scaleStepX, scaleStepY, targetScaleX, targetScaleY, callback); _scaleSet [go] = info; }