private void LoadInstance()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
 void Start()
 {
     this.gameStageLengths = new List <float>();
     this.totalStageTime   = 0;
     foreach (var stage in  this.gameStages)
     {
         stage.AwakeStage();
         totalStageTime += stage.getStageLengthSeconds();
         gameStageLengths.Add(totalStageTime);
     }
     GameTimeKeeper.SetTotalDuration(totalStageTime);
 }
    // Update is called once per frame
    void Update()
    {
        float currentPercent = GameTimeKeeper.GetCurrentPercent();

        if (UpdateColors(
                currentPercent,
                0,
                GameManager.fractalSunriseEnd,
                ColorManager.MintP,
                ColorManager.MintS,
                ColorManager.BasicWhite,
                ColorManager.BasicGrey
                ))
        {
            // Debug.Log("sunrise starts");
        }

        if (UpdateColors(
                currentPercent,
                GameManager.fractalSunriseEnd,
                GameManager.fractalAfternoonEnd,
                ColorManager.YellowP,
                ColorManager.YellowS,
                ColorManager.MintP,
                ColorManager.MintS
                ))
        {
            // Debug.Log("afternoon starts");
        }
        if (UpdateColors(
                currentPercent,
                GameManager.fractalAfternoonEnd,
                GameManager.fractalSunsetEnd,
                ColorManager.OrangeP,
                ColorManager.OrangeS,
                ColorManager.YellowP,
                ColorManager.YellowS
                ))
        {
            //  Debug.Log("sunset starts");
        }

        if (UpdateColors(
                currentPercent,
                GameManager.fractalSunsetEnd,
                GameManager.fractalEveningEnd,
                ColorManager.PinkP,
                ColorManager.PinkS,
                ColorManager.OrangeP,
                ColorManager.OrangeS
                ))
        {
            // Debug.Log("evening starts");
        }

        if (UpdateColors(
                currentPercent,
                GameManager.fractalEveningEnd,
                GameManager.fractalEndPercent,
                ColorManager.PurpleP,
                ColorManager.PurpleS,
                ColorManager.PinkP,
                ColorManager.PinkS
                ))
        {
            //  Debug.Log("late evening starts");
        }

        if (UpdateFractalExponentPercent(
                currentPercent,
                GameManager.fractalEndPercent,
                GameManager.interactEndPercent
                ))
        {
            // Debug.Log("interaction Event starts");
        }

        if (UpdateFractalPulsatingPercent())
        {
            // Debug.Log("updating fractal Pulsating");
        }

        if (MergeInteractionColor())
        {
            Debug.Log("Mixing in Interaction Color");
        }
        else
        {
            Debug.Log("Mixing out of Interaction Color");
        }

        this.ringManager.SetRingColor(this.PrimaryColor);


        // lerp ranges from 0-1
        mat.SetVector(FractalManager.PRIMARY_COLOR_KEY, this.PrimaryColor);
        mat.SetVector(FractalManager.SECONDARY_COLOR_KEY, this.SecondaryColor);
        mat.SetVector(FractalManager.GLOW_COLOR_KEY, this.GlowColor);
        mat.SetFloat(FractalManager.EXPONENT_KEY, this.Exponent);
    }
    void Update()
    {
        float seconds           = GameTimeKeeper.GetCurrentSeconds();
        float stageSecondsTotal = 0f;
        int   index             = -1;

        foreach (var stage in this.gameStages)
        {
            index++;
            var stageEnd   = stageSecondsTotal + stage.getStageLengthSeconds();
            var stageStart = stageSecondsTotal;

            // Skips over the stages until the current stage is found
            if (stageEnd < seconds)
            {
                stageSecondsTotal = stageEnd;
                continue;
            }

            // Used for the first stage
            if (stage.isLoadedInScene() == false)
            {
                stage.loadStageToGameView();
                Debug.Log("Warning Force Loading Stage " + stage.getStageName());
                GameObjectContainer.instance.RunActivations();
                GameObjectContainer.instance.RunDeactivations();
                GameObjectContainer.instance.CompleteTransation();
            }



            // update current stage
            stage.updateStage(GameTimeKeeper.GetPercentInRange(stageStart, stageEnd));


            #if UNITY_EDITOR
            // For Debuging
            this.Log(index);
            this.currentStage = stage.getStageName();
            #endif



            // Check for the next stage to transition to
            if (index != this.gameStages.Length - 1)
            {
                var nextGameStage = this.gameStages[index + 1];
                var startTime     = stageEnd - nextGameStage.getTransisionInTimeSeconds();
                if (seconds >= startTime - Time.deltaTime * 2)
                {
                    if (nextGameStage.isLoadedInScene() == false)
                    {
                        Debug.Log("Loading Next Stage " + nextGameStage.getStageName());
                        nextGameStage.loadStageToGameView();
                        GameObjectContainer.instance.RunActivations();
                    }
                    nextGameStage.transisionToStage(GameTimeKeeper.GetPercentInRange(startTime, stageEnd));
                }
            }

            // Check for a previous stage to transition from
            if (index != 0)
            {
                var lastGameStage = this.gameStages[index - 1];
                var endTime       = stageStart + lastGameStage.getTransisionFromSeconds();
                if (seconds <= endTime + Time.deltaTime * 2)
                {
                    lastGameStage.transisionFromStage(GameTimeKeeper.GetPercentInRange(stageStart, endTime));
                }
                else if (lastGameStage.isLoadedInScene() == true)
                {
                    Debug.Log("Unloaded last stage " + lastGameStage.getStageName());
                    lastGameStage.unloadStageFromGameView();
                    GameObjectContainer.instance.RunDeactivations();
                    GameObjectContainer.instance.CompleteTransation();
                }
            }


            lastIndex = index;

            break;
        }
    }