コード例 #1
0
ファイル: SharedUtils.cs プロジェクト: XCVG/commoncore
        /// <summary>
        /// Gets the HUD controller (throws on fail)
        /// </summary>
        public static BaseHUDController GetHudController()
        {
            BaseHUDController bhc = TryGetHudController();

            if (bhc != null)
            {
                return(bhc);
            }

            //still couldn't find it, throw an error
            Debug.LogError("Couldn't find HudController");

            throw new NullReferenceException(); //not having a scene controller is fatal
        }
コード例 #2
0
ファイル: SharedUtils.cs プロジェクト: XCVG/commoncore
        /// <summary>
        /// Gets the HUD controller (returns null on fail)
        /// </summary>
        public static BaseHUDController TryGetHudController()
        {
            if (BaseHUDController.Current != null)
            {
                return(BaseHUDController.Current);
            }

            // try searching UIRoot
            var uiRoot = CoreUtils.GetUIRoot();

            if (uiRoot != null)
            {
                foreach (Transform t in uiRoot)
                {
                    BaseHUDController bhc = t.GetComponent <BaseHUDController>();
                    if (bhc != null)
                    {
                        return(bhc);
                    }
                }
            }

            return(null);
        }