Пример #1
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());
        }
    }
Пример #2
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;
    }
Пример #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
    /* 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));
        }
    }
Пример #5
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));
        }
    }
Пример #6
0
    /*
     * 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);
        }
    }
Пример #7
0
    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));
    }
Пример #8
0
 /*
  * thisObj : the obj that's doing the animation
  * targetObj: "Target" for the obj
  * animEnum: Animation for the target to play */
 public virtual IEnumerator Play(RSRMonoBehaviour thisObj, RSRMonoBehaviour targetObj, AnimationEnum animEnum)
 {
     throw new System.NotImplementedException("Play(GameObject,AnimationEnum) not implemented for this object");
 }
Пример #9
0
    protected IEnumerator InvokePlayAnimation(RSRMonoBehaviour targetObj, AnimationEnum animEnum, float time)
    {
        yield return(new WaitForSeconds(time));

        PlayTarget(targetObj, animEnum);
    }