Ejemplo n.º 1
0
        public static MCMenu[] GetSharedMenus()
        {
            MenuControllerSharedProps instance = GetInstance();

            if (instance)
            {
                if (instance != null)
                {
                    return(instance.Menus);
                }
            }
            return(new MCMenu[0]);
        }
Ejemplo n.º 2
0
 private void EnsureSharedProps()
 {
     if (_menuControllerSharedProps)
     {
         if (_menuControllerSharedPropsObject == null)
         {
             _menuControllerSharedPropsObject = new SerializedObject(_menuControllerSharedProps);
         }
         return;
     }
     _menuControllerSharedProps       = MenuControllerSharedProps.GetOrCreateInstance();
     _menuControllerSharedPropsObject = new SerializedObject(_menuControllerSharedProps);
 }
Ejemplo n.º 3
0
        private void Awake()
        {
            // Set the singleton reference.
            if (_instance && _global)
            {
                if (_instance._global)
                {
                    Debug.Log("Some MenuManager is defined as global and is currently set as the instance reference. Are multiple static MenuManager in the scene?");
                }
                else
                {
                    // The current instance is not defined as global and can thus be overwritten.
                    _instance = this;
                }
            }
            else
            {
                _instance = this;
            }

            // For faster referencing, convert the array to a dictionary for run-time use.
            for (int i = 0; i < _mcMenus.Length; i++)
            {
                if (_menus.ContainsKey(_mcMenus[i].Id))
                {
                    Debug.LogError(string.Format("This menu could not be added, since this canvas ({0}) already contains a key for {1}", this.name, _mcMenus[i].Id));
                    continue;
                }
                _menus.Add(_mcMenus[i].Id, _mcMenus[i]);
            }

            // Add the shared menus.
            MCMenu[] sharedMenus = MenuControllerSharedProps.GetSharedMenus();
            for (int i = 0; i < sharedMenus.Length; i++)
            {
                if (_menus.ContainsKey(sharedMenus[i].Id))
                {
                    Debug.LogError(string.Format("This shared menu could not be added, since this canvas ({0}) already contains a key for {1}", this.name, sharedMenus[i].Id));
                    continue;
                }
                _menus.Add(sharedMenus[i].Id, sharedMenus[i]);
            }

            // Create the object that checks clicking outside of the current menu.
            _clickOutsideMenu = CreateOutsideMenuObject();
        }
Ejemplo n.º 4
0
        public static MenuControllerSharedProps GetOrCreateInstance()
        {
            MenuControllerSharedProps instance = GetInstance();

            if (!instance)
            {
                                #if UNITY_EDITOR
                Debug.Log(string.Format("Creating MenuControllerSharedProps in: {0}", RESOURCE_PATH));
                Directory.CreateDirectory(RESOURCE_PATH);

                string path = Path.Combine(RESOURCE_PATH, "MenuControllerSharedProps.asset");

                instance = CreateInstance <MenuControllerSharedProps>();
                AssetDatabase.CreateAsset(instance, path);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                #else
                Debug.LogError("Could not find MenuControllerSharedProps. Run this in the editor to create an asset.");
                #endif
            }
            return(instance);
        }