Exemplo n.º 1
0
        /// <summary>
        /// Controls the internal clock of the MapElement.
        /// <para>Executes the map events with "execute with time elapse" enabled, updates the objective property to cover and tries to execute the next planned event.</para>
        /// </summary>
        private IEnumerator ClockCoroutine()
        {
            // Initial delay so not all of them start at the same time
            yield return(new WaitForSeconds(new RandomEssentials(transform.position.GetHashCode()).GetRandomFloat(5f)));        // Maximum 5 seconds of delay to start the clock

            while (true)
            {
                yield return(new WaitForSeconds(GameManager.instance.gameClockInterval));

                propertyManager.ExecuteMapEventsWithTimeElapseEnabled();

                if (stateManager.currentState.stateType == StateType.None)
                {
                    UpdateObjectivePropertyToCover();
                    if (!DoNextPlanedMapEvents())
                    {
                        Debug.LogWarning("The next planned event could not be executed. Updating the execution plans to cover the objective property");
                        UpdateExecutionPlansToCoverObjectiveProperty();
                    }
                }

                stateManager.Step(GameManager.instance.gameClockInterval);

                if (!animationsManager.UpdateAnimationsByTrigger())
                {
                    animationsManager.UpdateAnimation();
                }
            }

            // ReSharper disable once IteratorNeverReturns
        }