IEnumerator PlayAnyAnimation(RSRMonoBehaviour targetObj, AnimObject.AnimationEnum thisAnimEnum, AnimObject.AnimationEnum targetAnimEnum) { //Debug.Log("Trying to play Animation " + thisAnimEnum.ToString() + " for object " + gameObject.ToString()); AnimObjectHolder aoh; if (_animController.TryGetAnimObjectHolder(thisAnimEnum, out aoh)) { //Debug.Log(thisAnimEnum.ToString() + " found for " + gameObject.ToString()); for (int i = 0; i < aoh.GetAnimObjects().Count; i++) { AnimObject ao = aoh.GetAnimObjects()[i]; if (ao.concurrent) { StartCoroutine(ao.Play(this, targetObj, targetAnimEnum)); } else { yield return(StartCoroutine(ao.Play(this, targetObj, targetAnimEnum))); } } } else { throw new System.NotImplementedException("PlayAnimation(" + targetObj.ToString() + ", " + thisAnimEnum.ToString() + ") --> Could not find Animation " + thisAnimEnum.ToString() + " for " + gameObject.ToString()); } }
public void PlayAnimation(AnimObject.AnimationEnum thisAnimEnum, RSRMonoBehaviour target, AnimObject.AnimationEnum targetAnimEnum) { if (_animController == null) { throw new System.NullReferenceException("PlayAnimation(" + target.ToString() + ", " + thisAnimEnum.ToString() + ") --> _animController null for " + gameObject.ToString()); } else { StartCoroutine(PlayAnyAnimation(target, thisAnimEnum, targetAnimEnum)); } }
void DrawAnimationEnum() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("Choose new Animation to add"); _animEnum = (AnimObject.AnimationEnum)EditorGUILayout.EnumPopup( "", _animEnum, GUILayout.MaxWidth(300f)); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
/* * targetObj: in this case, the object that will be doing an animation * animEnum: Animation for targetObj to play */ public virtual IEnumerator PlayTarget(RSRMonoBehaviour targetObj, AnimObject.AnimationEnum animEnum) { RSRAnimationController targetAnimController = targetObj.GetComponent <RSRAnimationController>(); if (targetAnimController == null) { Debug.LogWarning("targetObj " + targetObj.ToString() + "does not have an AnimationController attached!"); yield break; } yield return(new WaitForSeconds(delayForTargetAnim)); //DELAY if (optionalTargetAnimationOverride == AnimationEnum.Default) { targetObj.PlayAnimation(animEnum); } else { targetObj.PlayAnimation(optionalTargetAnimationOverride); } }
/* Draw the "header" for a single animation type you can create a sequence for. * EXAMPLE: * 'Animation 1... (button)[Add AnimObject]' */ void DrawAnimationTitle(AnimObject.AnimationEnum animEnum) { GUILayout.BeginHorizontal(); GUILayout.Label(animEnum.ToString() + " Animation", TitleStyle, GUILayout.Height(20f)); //show title of animation if (GUILayout.Button("X", GUILayout.MaxWidth(25f))) { _animController.RemoveAnimObjectHolder(animEnum); } GUILayout.FlexibleSpace(); // fill up the middle GUILayout.Label(". . ."); GUILayout.FlexibleSpace(); //TO-DO: Add in a Button for adding a new AnimObject if (GUILayout.Button("Add AnimObject")) { //TO-DO: Implement adding a new AnimObject AddNewAnimObject.ShowAddNewAnimObjectWindow(_animController, animEnum); } GUILayout.EndHorizontal(); }
protected void ShowTargetGUI() { GUILayout.BeginVertical(); commonWaitForAnimObjectToEnd = UnityEditor.EditorGUILayout.ToggleLeft( "Wait For AnimObject to End", commonWaitForAnimObjectToEnd, GUILayout.MinWidth(400f)); commonDelayForTargetAnim = UnityEditor.EditorGUILayout.FloatField("Delay", commonDelayForTargetAnim, GUILayout.MaxWidth(200f)); commonDelayForTargetAnim = AnimObject.EnsureNoNegativeFloat(commonDelayForTargetAnim);//ensure you can't have a negative delay GUILayout.BeginHorizontal(); //"(optional) Target animation play " GUILayout.FlexibleSpace(); GUILayout.Label("(Optional) Target Animation to Play"); commonOptionalTargetAnimationOverride = (AnimObject.AnimationEnum)UnityEditor.EditorGUILayout.EnumPopup( "", commonOptionalTargetAnimationOverride, GUILayout.MaxWidth(250f)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
public float speed = 1f; //How many hexes should it cross per second? public override IEnumerator PlayTarget(RSRMonoBehaviour targetObj, AnimObject.AnimationEnum animEnum) { return(base.PlayTarget(targetObj, animEnum)); }
void CreateNewAddNewAnimObjectWindow(AnimObject.AnimationEnum animationType) { AddNewAnimObject.ShowAddNewAnimObjectWindow(_animController, animationType); }
public void SetAnimationEnum(AnimObject.AnimationEnum aEnum) { animationEnum = aEnum; }
public void SetFields(AnimObject[] animObjectCollection, AnimObject.AnimationEnum aEnum) { _animObjectCollection = animObjectCollection.ToList(); animationEnum = aEnum; }
public void SetFields(AnimObject.AnimationEnum aEnum) { SetFields(new AnimObject[0], aEnum); }
/// <summary> /// Use this function to show a new editor window for creating a new AnimObject asset. /// </summary> /// <param name="animController">The AnimationController that this AnimObject will be added to</param> /// <param name="animation">Which "Animation" we're adding this AnimObject to</param> public static void ShowAddNewAnimObjectWindow(RSRAnimationController animController, AnimObject.AnimationEnum animation) { window = EditorWindow.GetWindow <AddNewAnimObject>(false, "Add New AnimObject"); window.SetTargetAnimController(animController); /* Now we need to find which Animation we're dealing with */ window._targetAOH = window._targetAnimController.GetAnimObjectHolders().First(aoh => aoh.GetAnimationEnum() == animation); }
public float speed = 1f; //speed PS plays at, as a percentage of regular speed. #region Play Method public override IEnumerator Play(RSRMonoBehaviour thisObj, RSRMonoBehaviour targetObj, AnimObject.AnimationEnum animEnum) { if (particleSystem == null) { throw new System.NullReferenceException("Particle System for " + thisObj.gameObject.ToString() + " in animation " + animEnum.ToString() + " is null."); } Debug.Log("Playing Particle System anim for object " + thisObj.gameObject.ToString()); if (target && !waitForAnimObjectToEnd) { /* Play target's animation right away */ StartCoroutine(InvokePlayAnimation(targetObj, animEnum, delayForTargetAnim)); } particleSystem.loop = loop; //Sets whether ps should loop or not /* Play actual animation */ particleSystem.Play(); Vector3 worldStartCord = Grid.GetWorldCoords(targetObj.GetCoords()); Vector3 worldEndCoord = Grid.GetWorldCoords(TranslateGameCoord( thisObj.GetCoords(), //start pos of obj that's moving direction, //direction distance, // distance (in hexes) targetObj.GetCoords())); //targetObj's coords, in case the direction is TargetDirection float t = 0; Vector3 newWorldCoord; float tIncreaseRate = (1f / 60f) * speed; while (t < 1f) { newWorldCoord = Vector3.Lerp(worldStartCord, worldEndCoord, t); particleSystem.transform.position = newWorldCoord; yield return(new WaitForFixedUpdate()); t += tIncreaseRate; } particleSystem.transform.position = worldEndCoord; /**************************/ if (target && waitForAnimObjectToEnd) { /* Play target's animation after this is now done */ StartCoroutine(InvokePlayAnimation(targetObj, animEnum, delayForTargetAnim)); } }
/* What can "play" for a tween (excluding target stuff): * - moves object attached to rsrmonobehaviour in a direction, over a given distance, * with a given speed */ public override IEnumerator Play(RSRMonoBehaviour thisObj, RSRMonoBehaviour targetObj, AnimObject.AnimationEnum animEnum) { //Debug.Log("Playing Tween anim for object " + thisObj.gameObject.ToString()); if (target && !waitForAnimObjectToEnd) { StartCoroutine(InvokePlayAnimation(targetObj, animEnum, delayForTargetAnim));//plays target's specified animation right away } if (speed <= 0) { speed = 1f; } /* Play actual animation */ ///////////////////// Vector3 gameEndCoord = TranslateGameCoord( thisObj.GetCoords(), //start pos of obj that's moving direction, //direction distance, // distance (in hexes) targetObj.GetCoords()); //targetObj's coords, in case the direction is TargetDirection //Debug.Log(thisObj.GetCoords().ToString() + ", " + direction.ToString() + ", " + distance.ToString() + ", " + targetObj.GetCoords().ToString()); Vector3 worldStartCord = thisObj.transform.position; Vector3 worldEndCoord = Grid.GetWorldCoords(gameEndCoord); //Debug.Log("From: " + worldStartCord.ToString() + ". To: " + worldEndCoord.ToString()); /* Forces game object to face in correct direction, if implemented */ Vector3 directionMoving = worldEndCoord - worldStartCord; thisObj.MakeSpriteFace(thisObj.GetDirection(directionMoving)); float t = 0; Vector3 newWorldCoord; float tIncreaseRate = (1f / 60f) * speed; while (t < 1f) { newWorldCoord = Vector3.Lerp(worldStartCord, worldEndCoord, t); thisObj.transform.position = newWorldCoord; yield return(new WaitForFixedUpdate()); t += tIncreaseRate; } thisObj.transform.position = worldEndCoord; //thisObj.MoveTo(gameEndCoord); /***********************/ if (target && waitForAnimObjectToEnd) { /* plays target's specified animation after this animobj is done */ StartCoroutine(InvokePlayAnimation(targetObj, animEnum, delayForTargetAnim)); } }
public void SetField(List <AnimObject> listAnimObjects, AnimObject.AnimationEnum aEnum) { _animObjectCollection = listAnimObjects; animationEnum = aEnum; }
public Animator _animator; //this obj's animator /* What can "play" for a sprite animation (excluding target stuff): * - the animation */ public override IEnumerator Play(RSRMonoBehaviour thisObj, RSRMonoBehaviour targetObj, AnimObject.AnimationEnum animEnum) { if (_animator == null) { throw new System.NullReferenceException("Sprite Animation for " + thisObj.gameObject.ToString() + " in animation " + animEnum.ToString() + " is null."); } if (target && !waitForAnimObjectToEnd) { /* Play target's animation right away */ StartCoroutine(InvokePlayAnimation(targetObj, animEnum, delayForTargetAnim)); } /* Play actual animation */ _animator.SetTrigger(animEnum.ToString()); // plays actual animation yield return(null); //gotta let it update before we get its state float clipLength = _animator.GetCurrentAnimatorStateInfo(0).length; Debug.Log("sprite clip length: " + clipLength.ToString()); if (loop) { /* Loop the animation as many times as we need to! */ int currentLoopCount = timesToLoop; /* While currentLoopCount > 0, keep playing the sprite animation! */ while (currentLoopCount > 0) { if (timesToLoop == 0) // loop forever { currentLoopCount = 10; //arbitrary number greater than 1 } Debug.Log("playing clip"); //thisObj.animation.Play("clip"); yield return(new WaitForSeconds(clipLength + .1f)); _animator.SetTrigger(animEnum.ToString()); currentLoopCount--; } } else { //spriteAnimation.Play(); Debug.Log("PlayingClip no loop"); //thisObj.animation.Play("clip"); } /************************/ if (target && waitForAnimObjectToEnd) { /* Play target's animation after this is now done */ StartCoroutine(InvokePlayAnimation(targetObj, animEnum, delayForTargetAnim)); } yield break; }
/* All possible animation methods a game object could ever use. * Note not all game objects will (or necessarily should) implement every * animation. */ public void PlayAnimation(AnimObject.AnimationEnum animEnum) { PlayAnimation(animEnum, gameObject.GetComponent <RSRMonoBehaviour>(), animEnum); }