internal void Initialize(AnimationStep step, AnimationHolder holder) { this.step = step; this.holder = holder; animationElementObjects = new List <AnimationElementObject>(); foreach (Transform child in transform) { AnimationElementObject aeo = child.gameObject.GetComponent <AnimationElementObject>(); if (!aeo) { Debug.LogError(name + ": Object " + child.name + " is not an AnimationElementObject"); } animationElementObjects.Add(aeo); } }
public void InitObjects(GameObject[] selection) { foreach (GameObject o in selection) { if (!(o.transform.parent == holder.animationObjectsParentAR.transform || o.transform.parent == holder.animationObjectsParentNonAR.transform)) { Debug.LogError("Error! Animated object is not a direct child of a Animation Objects Parent!"); return; } AnimationElementObject found = animationElementObjects.Find(o); if (found) { found.obj.ReCreate(); } else { animationElementObjects.Add(AnimationElementObject.CreateFrom(o, this, o.transform.parent.gameObject)); } } }
/* internal IEnumerator PlayElementOLD(uint stepNumber) * { * yield return 0; * if (positionOnReset) * animationElementObjects.ResetAll(); * foreach (AnimationElementObject aeo in animationElementObjects) * aeo.obj.ResetPosition(); * while (step.stepTime < unhideDelay) * yield return 0; * * animationElementObjects.UnhideAll(); * foreach (AnimationElementObject aeo in animationElementObjects) * aeo.obj.Unhide(); * * float lastTime = step.stepTime - animationStartDelay; * while (stepNumber == holder.stepsPlayed) * { * float t = step.stepTime - animationStartDelay; * if (lastTime > t || t > animationLength) * break; * lastTime = t; * float dT = step.deltaTime; * float lerp = t / animationLength; * * if (t > 0 && lerp < 1) * foreach (AnimationElementObject o in animationElementObjects) * Animate(o, t, lerp, dT); * * yield return 0; * } * lastTime = step.stepTime - animationStartDelay - animationLength; * * animationElementObjects.HideAll(); * }*/ #endregion internal virtual void Animate(AnimationElementObject o, float time, float lerp, float delta) { bool visible = time > o.delayVisible && time < o.delayHide; if (o.obj.instance.activeInHierarchy != visible) { o.obj.instance.SetActive(visible); } if (!visible) { return; } Transform t = o.obj.instance.transform; /* Empty = 0, * DelayedVisible = 1, // nothing * Translate = 10, // local = lerp(aeo.par[0] > aeo.par[1]) * TranslateLocal = 11, // local = lerp(aeo.start (=aeo.par[0]) > aeo.start + this.local) * TranslateUp = 12, // world += this.worldUp * deltaTime * this.par[0] * Rotate = 20, // rotate around (this.worldUp x this.position, this.par[0] * deltaTime) * RotateLocal = 21 // rotate around (this.worldUp x aeo.position, this.par[0] * deltaTime)*/ switch (animationElementType) { case AnimationElementType.Translate: t.localPosition = Vector3.Lerp(o.parameters[0], o.parameters[1], lerp); break; case AnimationElementType.TranslateLocal: t.localPosition = Vector3.Lerp(o.parameters[0], o.parameters[0] + transform.localPosition, lerp); break; case AnimationElementType.TranslateUp: t.position += transform.up * parameters[0] * delta; break; case AnimationElementType.Rotate: t.RotateAround(transform.position, transform.up, parameters[0] * delta); break; case AnimationElementType.RotateAdvanced: t.localEulerAngles = o.obj.eulerAngles; t.RotateAround(transform.position, transform.up, parameters[0] * lerp); break; case AnimationElementType.RotateLocalAdvanced: t.localEulerAngles = o.obj.eulerAngles; t.RotateAround(o.transform.position, transform.up, parameters[0] * lerp); break; case AnimationElementType.RotateLocal: t.RotateAround(t.position, transform.up, parameters[0] * delta); break; case AnimationElementType.DelayedVisible: break; case AnimationElementType.Screw: t.localPosition = Vector3.Lerp(o.parameters[0] + t.up * animationLength * parameters[1], o.parameters[0], lerp); t.RotateAround(t.position, t.transform.up, parameters[0] * delta); // rotate around (aeo.worldup x aeo.position, this.par[0] * deltaTime) // local = lerp (aeo.start=o.parameters[0] - aeo.up*length*this.par[1] > aeo.start) break; case AnimationElementType.Empty: break; default: Debug.LogError(name + " is a undefined AnimationElement!"); break; } }