Beispiel #1
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));
        }
    }
Beispiel #2
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));
        }
    }