Пример #1
0
    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;
    }
Пример #2
0
    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());
        }
    }
Пример #3
0
 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));
     }
 }
Пример #4
0
    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));
        }
    }
Пример #5
0
    /* 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();
    }
Пример #6
0
 void DrawOverrideWarning()
 {
     EditorGUILayout.LabelField("WARNING!!! \nAdding this animation will overwrite this object's current " +
                                _animEnum.ToString() + " Animation!!!", GUILayout.MinHeight(100f));
 }
Пример #7
0
    //public AnimObjectHolder(AnimObject[] animObjectCollection)
    //    {
    //        _animObjectCollection = animObjectCollection;
    //        animationEnum = AnimObject.AnimationEnum.Default;
    //    }
    //
    //public AnimObjectHolder(AnimObject[] animObjectCollection, AnimObject.AnimationEnum aEnum)
    //    {
    //        _animObjectCollection = animObjectCollection;
    //        animationEnum = aEnum;
    //    }
    //
    //public AnimObjectHolder(AnimObject.AnimationEnum aEnum)
    //    {
    //        _animObjectCollection = new AnimObject[0];
    //        animationEnum = aEnum;
    //    }

    #endregion

    #region Set/Get Methods

    public void SetAnimObject(List <AnimObject> listAnimObjects)
    {
        Debug.Log("For " + animationEnum.ToString() + ": collection now has " + listAnimObjects.Count.ToString() + " objects");
        _animObjectCollection = listAnimObjects;
    }