playMaker

Author Topic: Having an issue with OnGUI  (Read 1021 times)

PocketUnityDev

  • Playmaker Newbie
  • *
  • Posts: 1
Having an issue with OnGUI
« on: August 03, 2018, 03:57:39 PM »
Hello,

Just updated my Playmaker asset to 1.9.0.p4 in Unity 2017.1.3p3 and for some reason OnGUI isn't being called anymore. Is there any reason this may be occurring. Thanks for any help.

Here is an example of the code that isn't working. It's suppose to fade the camera to black.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Camera)]
    [Tooltip("Fade to a fullscreen Color. NOTE: Uses OnGUI so requires a PlayMakerGUI component in the scene.")]
    public class CameraFadeOut : FsmStateAction
    {
        [RequiredField]
        [Tooltip("Color to fade to. E.g., Fade to black.")]
        public FsmColor color;

        [RequiredField]
        [HasFloatSlider(0, 10)]
        [Tooltip("Fade out time in seconds.")]
        public FsmFloat time;

        [Tooltip("Event to send when finished.")]
        public FsmEvent finishEvent;

        [Tooltip("Ignore TimeScale. Useful if the game is paused.")]
        public bool realTime;

        public override void Reset()
        {
            color = Color.black;
            time = 1.0f;
            finishEvent = null;
        }

        private float startTime;
        private float currentTime;
        private Color colorLerp;

        public override void OnEnter()
        {
            startTime = FsmTime.RealtimeSinceStartup;
            currentTime = 0f;
            colorLerp = Color.clear;
            Fsm.HandleOnGUI = true;
        }

        public override void OnUpdate()
        {
            if (realTime)
            {
                currentTime = FsmTime.RealtimeSinceStartup - startTime;
            }
            else
            {
                currentTime += Time.deltaTime;
            }

            colorLerp = Color.Lerp(Color.clear, color.Value, currentTime / time.Value);

            if (currentTime > time.Value)
            {
                if (finishEvent != null)
                {
                    Fsm.Event(finishEvent);
                }

                // Don't finish since it will stop drawing the fullscreen color
                //Finish();
            }
        }

        public override void OnGUI()
        {
            base.OnGUI();
            var guiColor = GUI.color;
            GUI.color = colorLerp;
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), ActionHelpers.WhiteTexture);
            GUI.color = guiColor;
        }

#if UNITY_EDITOR

        public override float GetProgress()
        {
            return Mathf.Min(currentTime / time.Value, 1f);
        }

#endif

    }
}
« Last Edit: August 03, 2018, 04:34:20 PM by PocketUnityDev »