Пример #1
0
 private void SlowTranslate(TileRenderer.SlowTranslateWrapper objectToMove, Vector3 translation, float speed, UnityAction stepCallBack, UnityAction endCallback)
 {
     if (objectToMove.translating)
     {
         objectToMove.translations.Enqueue(this.SlowTranslateCoroutine(objectToMove, translation, speed, stepCallBack, endCallback));
     }
     else
     {
         base.StartCoroutine(this.SlowTranslateCoroutine(objectToMove, translation, speed, stepCallBack, endCallback));
     }
 }
Пример #2
0
    private IEnumerator SlowTranslateCoroutine(TileRenderer.SlowTranslateWrapper objectToMove, Vector3 translation, float speed, UnityAction stepCallBack, UnityAction endCallback)
    {
        if (stepCallBack != null)
        {
            stepCallBack();
        }

        objectToMove.translating = true;
        Vector3 endposition = objectToMove.transform.position + translation;
        float   stepsize    = speed / (objectToMove.transform.position - endposition).magnitude * Time.fixedDeltaTime;
        float   distance    = Vector3.Distance(objectToMove.transform.position, endposition);
        float   moved       = 0f;

        while (distance - moved >= 0f)
        {
            objectToMove.transform.Translate(translation * stepsize, Space.World);
            moved += (translation * stepsize).magnitude;

            //This is a secret update to the water material, i uses world coordinates so we need to update its offset while we are moving
            Vector2 textureOffset = new Vector2(distance - moved, 0);
            //TileObjectManger.getMaterial("Water").mainTextureOffset = -textureOffset;

            yield return(new WaitForFixedUpdate());
        }
        objectToMove.transform.position = endposition;
        if (objectToMove.translations.Count > 0)
        {
            base.StartCoroutine(objectToMove.translations.Dequeue());
        }
        else
        {
            objectToMove.translating = false;

            if (endCallback != null)
            {
                endCallback();
            }
        }


        yield break;
    }