private void StopRoutine(RoutineActivity transformation)
 {
     if (transformation.routine != null)
     {
         StopCoroutine(transformation.routine);
     }
     transformation.isActive = false;
 }
Esempio n. 2
0
 private static void StopCoroutine(RoutineActivity routineActivity)
 {
     if (routineActivity.coroutine != null)
     {
         routineActivity.monoBehaviour.StopCoroutine(routineActivity.coroutine);
     }
     routineActivity.isActive = false;
 }
Esempio n. 3
0
 private static IEnumerator ComposeRoutineWithCallback(MonoBehaviour mb, RoutineActivity activity, IEnumerator routine, System.Action onFinished)
 {
     activity.isActive = true;
     while (activity.isActive && routine.MoveNext())
     {
         yield return(routine.Current);
     }
     //yield return routine;
     activity.isActive = false;
     onFinished?.Invoke();
 }
        public void StartTransformation(IEnumerator routine, TransformationType type, System.Action onFinished = null)
        {
            RoutineActivity transformation = null;

            bool isTranslation = type.HasFlag(TransformationType.Translate);
            bool isRotation    = type.HasFlag(TransformationType.Rotate);
            bool isScaling     = type.HasFlag(TransformationType.Scale);

            // For readability: if need better perf, just move to the branches?
            if (isTranslation)
            {
                StopTranslation();
            }
            if (isRotation)
            {
                StopRotation();
            }
            if (isScaling)
            {
                StopScaling();
            }

            if (isTranslation)
            {
                StopTranslation();
                transformation = translation;
                if (isRotation)
                {
                    rotation = transformation;
                }
                if (isScaling)
                {
                    scaling = transformation;
                }
            }
            else if (isRotation)
            {
                transformation = rotation;
                if (isScaling)
                {
                    scaling = transformation;
                }
            }
            else
            {
                transformation = scaling;
            }

            StartRoutine(routine, transformation, onFinished);
        }
Esempio n. 5
0
        public static void StopCoroutine(MonoBehaviour mb, string tag)
        {
            if (!routinesMap.ContainsKey(mb))
            {
                return;
            }

            RoutineActivity current = null;

            // Stop an already running coroutine if present
            bool isPresent = routinesMap[mb].TryGetValue(tag, out current);

            if (isPresent)
            {
                //Trace.Script("Stopping " + tag);
                current.Stop();
            }
        }
Esempio n. 6
0
        public static void StartCoroutine(MonoBehaviour mb, IEnumerator routine, string tag, System.Action onFinished = null)
        {
            RoutineActivity current = null;

            // Check if this monobehaviour has already been used before
            if (!routinesMap.ContainsKey(mb))
            {
                routinesMap.Add(mb, new Dictionary <string, RoutineActivity>());
            }

            // Stop an already running coroutine if present
            bool isPresent = routinesMap[mb].TryGetValue(tag, out current);

            if (isPresent)
            {
                current.Stop();
            }
            // Otherwise add it to the list
            else
            {
                current = new RoutineActivity(mb);
                routinesMap[mb].Add(tag, current);
            }

            // Now add/replace the current routine
            if (onFinished != null)
            {
                IEnumerator composedRoutine = ComposeRoutineWithCallback(mb, current, routine, onFinished);
                if (mb.isActiveAndEnabled)
                {
                    current.coroutine = mb.StartCoroutine(composedRoutine);
                }
            }
            else
            {
                if (mb.isActiveAndEnabled)
                {
                    current.coroutine = mb.StartCoroutine(routine);
                }
            }

            // Start it
            //Trace.Script("Starting " + tag);
        }
        private void StartRoutine(IEnumerator newRoutine, RoutineActivity transformation, System.Action onFinished = null)
        {
            StopRoutine(transformation);

            if (newRoutine == null)
            {
                return;
            }

            transformation.routine = newRoutine;

            // If there's a callback to be called when this routine stops
            if (onFinished != null)
            {
                StartCoroutine(StartRoutineWithCallback(newRoutine, onFinished));
            }
            // Otherwise just start it
            else
            {
                StartCoroutine(newRoutine);
            }
            transformation.isActive = true;
        }