/// <summary> /// Initializes a sequence /// </summary> public void InitSequence(AnimationSequenceObject obj, EntityController u, EntityController t) { user = u; target = t; // Iinitialize position of user and target userPosition = user.transform.position; userRotation = user.transform.eulerAngles; userScale = user.transform.localScale; userSprite = user.GetSpriteRenderer(); userColor = userSprite.color; // Calculate direction of motion. This allows all animations to be uniform regardless of positioning. directionX = user.transform.localScale.x / Mathf.Abs(user.transform.localScale.x); directionY = user.transform.localScale.y / Mathf.Abs(user.transform.localScale.y); if (target != null) { targetPosition = target.transform.position; targetRotation = target.transform.eulerAngles; targetScale = target.transform.localScale; targetSprite = target.GetSpriteRenderer(); targetColor = targetSprite.color; } // Split the animation script. string[] sequence = obj.animationSequence.text.Split('\n'); for (int i = 0; i < sequence.Length; i++) { // Remove dividing characters string[] line = sequence[i].Split('|'); // If line does not have enough values, show an error if (line.Length > 3 || line.Length < 2) { Debug.LogError("Invalid format on line " + (i + 1) + "!"); return; } // Create the action for the given line AnimationSequenceAction seq = new AnimationSequenceAction(); seq.frame = int.Parse(line[0]); seq.action = (AnimationSequenceAction.Action)Enum.Parse(typeof(AnimationSequenceAction.Action), line[1]); // If the line length is greater than 2, add the param if (line.Length > 2) { seq.param = line[2]; } // Add the action to our list sequenceActions.Add(seq); } initialized = true; }
/// <summary> /// Creates a sequence /// </summary> public AnimationSequence(AnimationSequenceObject obj, EntityController u, EntityController t) { InitSequence(obj, u, t); }
/// <summary> /// Creates a sequence cast from the given spell with all loops matching the number of hits /// </summary> public AnimationSequence(AnimationSequenceObject obj, EntityController u, EntityController t, SpellCast s) { InitSequence(obj, u, t); spell = s; loop = s.GetNumHits(); }