Пример #1
0
 // Prevent the class from behind created by the client
 public Singleton()
 {
     if (mUniqueInstance != null)
     {
         QLogger.LogErrorAndThrowException("Singleton [" + typeof(T) + "] cannot be manually instantiated and Singleton.Instance can only be called from the main thread.");
     }
 }
Пример #2
0
        public void UnloadLevel(string sceneFilePath, Action completeAction, bool async)
        {
            if (async)
            {
                if (QLogger.CanLogInfo)
                {
                    QLogger.LogInfo("Unload of scene " + sceneFilePath + " has begun");
                }

                AsyncOperation operation = SceneManager.UnloadSceneAsync(sceneFilePath);
                operation.completed += delegate(AsyncOperation o)
                {
                    if (QLogger.CanLogInfo)
                    {
                        QLogger.LogInfo("Unload of scene " + sceneFilePath + " has completed");
                    }
                    if (completeAction != null)
                    {
                        completeAction();
                    }
                };
            }
            else
            {
                QLogger.LogErrorAndThrowException("We only have async version for unload as direct one was made obselete by unity");
            }
        }
Пример #3
0
        public UIPanel ShowGamePlayScreen(string screenName, bool visible)
        {
            UIPanelInstance panelInstance = GetPanelInstance(screenName);

            if (panelInstance == null)
            {
                UIPanelInfo panelInfo = GetPanelReference(screenName);
                if (panelInfo == null)
                {
                    QLogger.LogErrorAndThrowException("No screen found with name:" + screenName);
                }
                if (panelInfo.type != UIPanelInfo.Type.GamePlay)
                {
                    QLogger.LogErrorAndThrowException("This panel is not a screen type");
                }
                panelInstance = CreatePanelInstanceAndAddToListIfNess(panelInfo);
                if (panelInstance == null)
                {
                    QLogger.LogErrorAndThrowException("Panel instance was not created!");
                }
            }
            if (!(panelInstance is GamePlayScreenPanelInstance))
            {
                QLogger.LogErrorAndThrowException("This panel is not screen type - 2");
            }
            GamePlayScreenPanelInstance screenInstance = panelInstance as GamePlayScreenPanelInstance;

            if (!gamePlayScreenPanels.Contains(screenInstance))
            {
                gamePlayScreenPanels.Add(screenInstance);
            }

            panelInstance.instance.SetActive(visible);
            return(panelInstance.uiPanel);
        }
Пример #4
0
        public UIPanelInstance CreatePanelInstanceAndAddToListIfNess(UIPanelInfo panel)
        {
            if (GetPanelInstance(panel.panelName) != null)
            {
                return(GetPanelInstance(panel.panelName));
            }

            if (panel.uiObjectReference == null)
            {
                panel.uiObjectReference = ResourceManager.Instance.LoadAsset <UnityEngine.Object>(panel.objectPath);
            }

            if (panel.uiObjectReference == null)
            {
                QLogger.LogErrorAndThrowException("Panel object not found!");
            }

            GameObject instance = GameObject.Instantiate(panel.uiObjectReference, new Vector3(9999, 9999, 9999), Quaternion.identity, transform) as GameObject;

            instance.SetActive(false);
            instance.transform.localPosition = panel.localPosition;
            UIPanelInstance panelInstance = null;

            if (panel.type == UIPanelInfo.Type.Screen)
            {
                panelInstance = new ScreenPanelInstance();
            }
            else if (panel.type == UIPanelInfo.Type.Popup)
            {
                panelInstance = new PopupPanelInstance();
            }
            else if (panel.type == UIPanelInfo.Type.Alert)
            {
                panelInstance = new AlertPanelInstance();
            }
            else if (panel.type == UIPanelInfo.Type.GamePlay)
            {
                panelInstance = new GamePlayScreenPanelInstance();
            }
            else
            {
                QLogger.LogErrorAndThrowException("Should not be here !");
            }

            panelInstance.panelInfo = panel;
            panelInstance.instance  = instance;
            panelInstance.uiPanel   = instance.GetComponent <UIPanel>();
            if (panelInstance.uiPanel == null)
            {
                QLogger.LogErrorAndThrowException("Ui panel instance not found ");
            }
            panelsInMemory.Add(panelInstance);
            return(panelInstance);
        }
Пример #5
0
        // Prevent the class from behind created by the client
        protected virtual void Awake()
        {
            if (uniqueInstance == null)
            {
                uniqueInstance = this;
                if (!DestroyOnSceneSwitch && transform.parent == null)
                {
                    DontDestroyOnLoad(this.gameObject);
                }
            }

            if (uniqueInstance != this)
            {
                QLogger.LogErrorAndThrowException("Cannot have two instances of a SingletonMonoBehaviour " + typeof(T).ToString() + ".");
            }
        }
Пример #6
0
        // Prevent the class from behind created by the client
        protected virtual void Awake()
        {
            if (QLogger.CanLogInfo)
            {
                QLogger.LogInfo(string.Format("{0} instantiated.", typeof(T)));
            }

            if (uniqueInstance == null)
            {
                uniqueInstance = this;
            }
            else if (uniqueInstance != this)
            {
                QLogger.LogErrorAndThrowException("Cannot have two instances of a SingletonMonoBehaviour : " + typeof(T).ToString() + ".");
            }
        }
Пример #7
0
        public void CloseUiPanelAndRemoveFromListIfNess(UIPanelInstance instance)
        {
            if (instance == null)
            {
                QLogger.LogErrorAndThrowException("panel instance is null"); return;
            }

            if (instance.panelInfo.keepInMemory)
            {
                instance.uiPanel.Reset();
                instance.instance.SetActive(false);
            }
            else
            {
                GameObject.Destroy(instance.instance);
                panelsInMemory.Remove(instance);
            }
        }
Пример #8
0
        public T LoadAsset <T>(string path) where T : UnityEngine.Object
        {
            if (!isInitiated)
            {
                Initialize();
            }

            UnityEngine.Object obj = resouceMap.GetObjectAtPath(path);
            if (obj == null)
            {
                QLogger.LogErrorAndThrowException("Object not found for " + path);
            }
            if ((obj as T) == null)
            {
                QLogger.LogErrorAndThrowException("Object casting failed " + path);
            }

            return(obj as T);
        }
Пример #9
0
 public UnityEngine.Object GetObjectAtPath(string path)
 {
     if (Mapping == null)
     {
         QLogger.LogErrorAndThrowException("Mapping is empty");
     }
     foreach (Map map in Mapping)
     {
         if (map.path == path)
         {
             return(map.obj);
         }
     }
     foreach (Map map in FolderMapping)
     {
         if (map.path == path)
         {
             return(map.obj);
         }
     }
     return(null);
 }
Пример #10
0
        public UIPanel PushScreen(string screenName, bool visible)
        {
            UIPanelInstance panelInstance = GetPanelInstance(screenName);

            if (panelInstance == null)
            {
                UIPanelInfo panelInfo = GetPanelReference(screenName);
                if (panelInfo == null)
                {
                    QLogger.LogErrorAndThrowException("No screen found with name:" + screenName);
                }
                if (panelInfo.type != UIPanelInfo.Type.Screen)
                {
                    QLogger.LogErrorAndThrowException("This panel is not a screen type");
                }
                panelInstance = CreatePanelInstanceAndAddToListIfNess(panelInfo);
                if (panelInstance == null)
                {
                    QLogger.LogErrorAndThrowException("Panel instance was not created!");
                }
            }
            if (!(panelInstance is ScreenPanelInstance))
            {
                QLogger.LogErrorAndThrowException("This panel is not screen type - 2");
            }
            ScreenPanelInstance screenInstance = panelInstance as ScreenPanelInstance;

            if (screenPanelStack.Count > 0)
            {
                screenPanelStack.Peek().uiPanel.OnPusedBack();
                screenPanelStack.Peek().instance.SetActive(false);
            }
            screenPanelStack.Push(screenInstance);
            panelInstance.instance.SetActive(visible);
            return(panelInstance.uiPanel);
        }