示例#1
0
        public AudioClip LoadAudioClip(string name)
        {
            AudioClip ac = null;

            clipCache.TryGetValue(name, out ac);
            if (ac == null)
            {
                ac = AssetsManager.LoadPrefabFromResources <AudioClip> ("Sound/" + name);

                //if (Application.platform == RuntimePlatform.OSXPlayer) {
                //	ac = AssetsManager.Load<AudioClip> ("Sound/" + name);
                //}

                if (ac != null)
                {
                    clipCache.Add(name, ac);
                }
                else
                {
                    Debug.Log("Can`t load sound " + name);
                }
            }

            return(ac);
        }
示例#2
0
        public void LoadScene(string sceneName, SceneLoadMode loadMode, object sceneData = null)
        {
            //string sceneName = typeof (T).ToString ();


            GameObject uiObject;
            string     perfbName = "Scenes/" + sceneName;

            if (m_loadedScene.Contains(sceneName))
            {
                return;
            }
            sceneName = sceneName.ToLower();
            m_loadedScene.Add(sceneName);
            //Debug.Log ("Loaded Perfab : " + perfbName);
            if (loadMode == SceneLoadMode.Single)
            {
                AssetsManager.Instance().LoadScene(
                    sceneName,
                    UnityEngine.SceneManagement.LoadSceneMode.Single);
            }
            else if (loadMode == SceneLoadMode.Additive)
            {
                AssetsManager.Instance().LoadScene(
                    sceneName,
                    UnityEngine.SceneManagement.LoadSceneMode.Additive);
            }

            //UnityEngine.SceneManagement.LoadSceneMode.Single

            return;
        }
示例#3
0
        public T ShowDialog <T> (Dictionary <string, object> varList = null) where T : UIDialog
        {
            if (m_currentDialog != null)
            {
                m_currentDialog.gameObject.SetActive(false);
                m_currentDialog = null;
            }

            string     name = typeof(T).ToString();
            GameObject uiObject;

            Transform dialogTran = m_panel.transform.Find(name);

            if (!dialogTran)
            {
                string perfbName = "UI/Dialog/" + typeof(T).ToString();
                Debug.Log(perfbName);
                GameObject perfb = AssetsManager.LoadPrefab <GameObject> (perfbName);
                if (perfb == null)
                {
                    Debug.Log("UIDialog Can`t Find Perfab");
                }
                uiObject      = GameObject.Instantiate(perfb);
                uiObject.name = name;
                T t = uiObject.AddComponent <T> ();
                uiObject.transform.SetParent(m_dialog.transform);

                t.PanelInit();
            }
            else
            {
                uiObject = dialogTran.gameObject;
            }

            if (uiObject)
            {
                T panel = uiObject.GetComponent <T> ();
                panel.PanelOpen();
                if (varList != null)
                {
                    panel.m_userData = varList;
                }

                m_currentDialog = panel;

                m_dialogs.Push(uiObject);

                uiObject.SetActive(true);
            }
            return(uiObject.GetComponent <T> ());
        }
示例#4
0
        /// <summary>
        /// Shows the panel.
        ///
        /// 显示一个panel,panel是最为简单的UI元素,只是单纯显示在画面中,
        /// 所有的处理都交给Panel本身解决,建议在复杂频繁的UI切换中中不要使用panel
        /// 或者把一系列Panel置于一个父对象上统一管理开关
        /// </summary>
        /// <returns>The panel.</returns>
        /// <param name="isFramework">这个UI是否为框架使用的。设为<c>true</c>是用于框架级的UI预设。通常都是false。</param>
        /// <param name="varList">Variable list.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public T ShowPanel <T> (bool isFramework = false, Dictionary <string, object> varList = null) where T : UIPanel
        {
            string name = typeof(T).ToString();
            //Debug.Log (name);
            Transform  panelTran = m_panel.transform.Find(name);
            GameObject uiObject;
            T          panel = null;

            if (panelTran == null)
            {
                string perfbName;
                if (!isFramework)
                {
                    perfbName = "UI/Panel/" + typeof(T).ToString();
                }
                else
                {
                    perfbName = "Skylight/UI/Panel/" + typeof(T).ToString();
                }
                GameObject perfb = AssetsManager.LoadPrefab <GameObject> (perfbName);
                if (perfb == null)
                {
                    Debug.Log("UIPanel Can`t Find Perfab");
                }
                uiObject      = GameObject.Instantiate(perfb);
                uiObject.name = name;
                T t = uiObject.AddComponent <T> ();
                uiObject.transform.SetParent(m_panel.transform);

                t.PanelInit();
            }
            else
            {
                uiObject = panelTran.gameObject;
            }
            if (uiObject)
            {
                panel = uiObject.GetComponent <T> ();
                panel.PanelOpen();
                if (varList != null)
                {
                    panel.m_userData = varList;
                }

                uiObject.SetActive(true);
            }

            return(panel);
        }
示例#5
0
        public GameObject LoadPrefab(string prefabName)
        {
            string name = "Prefabs/" + prefabName;

            if (m_allPrefab.ContainsKey(prefabName))
            {
                return(m_allPrefab [prefabName]);
            }
            else
            {
                GameObject perfb = AssetsManager.LoadPrefab <GameObject> (name);
                if (perfb == null)
                {
                    Debug.Log(prefabName + "can`t find in Prefabs/" + prefabName);
                    return(null);
                }
                m_allPrefab.Add(prefabName, perfb);
                return(perfb);
            }
        }
示例#6
0
        public void ShowBox <T> (Dictionary <string, object> varList = null) where T : UIBox
        {
            string name = typeof(T).ToString();

            var        panelTran = m_box.transform.Find(name);
            GameObject uiObject;

            if (panelTran == null)
            {
                string     perfbName = "UI/Box/" + typeof(T).ToString();
                GameObject perfb     = AssetsManager.LoadPrefab <GameObject> (perfbName);
                uiObject      = GameObject.Instantiate(perfb);
                uiObject.name = name;
                T t = uiObject.AddComponent <T> ();
                uiObject.transform.SetParent(m_box.transform);
                t.PanelInit();
            }
            else
            {
                uiObject = panelTran.gameObject;
            }
            if (uiObject)
            {
                T box = uiObject.GetComponent <T> ();
                box.PanelOpen();
                if (varList != null)
                {
                    box.m_userData = varList;
                }

                if (m_currentBox)
                {
                    m_currentBox.gameObject.SetActive(false);
                }

                uiObject.SetActive(true);
                m_currentBox = box;
            }
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="text">显示在屏幕上的文字</param>
        /// <param name="rectPos">显示在屏幕上的位置,左下角是(0,0)</param>
        /// <param name="offset">UI在屏幕上的偏移,UI的位置会被限制在(x-offseX,y-offsetY)之中</param>
        /// <param name="WaitingTime">等待消失的时间</param>
        /// <param name="isAutoFade">是否需要自动消失,false会自动屏蔽等待时间</param>
        /// <param name="varList">变量列表</param>
        /// <returns></returns>
        public T ShowOverlay <T> (string text,
                                  Vector3 rectPos   = default(Vector3),
                                  Vector2 offset    = default(Vector2),
                                  float WaitingTime = 1.5f,
                                  bool isAutoFade   = true,
                                  Dictionary <string, object> varList = null
                                  ) where T : UIOverlay
        {
            rectPos = new Vector3(380, 700, 0);
            offset  = new Vector2(200, 100);
            string name = typeof(T).ToString();

            Debug.Log(name);
            var        panelTran = m_panel.transform.Find(name);
            GameObject uiObject;
            T          panel = null;

            if (panelTran == null)
            {
                string     perfbName = "UI/Overlay/" + typeof(T).ToString();
                GameObject perfb     = AssetsManager.LoadPrefab <GameObject> (perfbName);
                if (perfb == null)
                {
                    Debug.Log("UIOverlay Can`t Find Perfab");
                }
                uiObject      = GameObject.Instantiate(perfb);
                uiObject.name = name;
                T t = uiObject.AddComponent <T> ();
                uiObject.transform.SetParent(m_overlay.transform);
                float maxWidth  = Screen.width - offset.x;
                float maxHeight = Screen.height - offset.y;
                if (rectPos.x > maxWidth)
                {
                    rectPos.x = maxWidth;
                }
                if (rectPos.x < offset.x)
                {
                    rectPos.x = offset.x;
                }
                if (rectPos.y > maxHeight)
                {
                    rectPos.y = maxHeight;
                }
                if (rectPos.y < offset.y)
                {
                    rectPos.y = offset.y;
                }
                //Debug.Log("(uiObject.transform " + uiObject.transform.GetChild(0).transform.position);
                uiObject.transform.GetChild(0).transform.position = rectPos;
                //Debug.Log("After calculate, uiObject RectTransform " + uiObject.GetComponent<RectTransform>().position);

                t.PanelInit();
            }
            else
            {
                uiObject = panelTran.gameObject;
            }
            if (uiObject)
            {
                panel = uiObject.GetComponent <T> ();
                panel.ShowMsg(text);
                panel.PanelOpen();
                if (varList != null)
                {
                    panel.m_userData = varList;
                }

                uiObject.SetActive(true);
                if (isAutoFade)
                {
                    StartCoroutine(DelayToInvokeDo(() => {
                        AnimationService.Instance().UIToFade(uiObject.transform);
                    }, WaitingTime));

                    StartCoroutine(DelayToInvokeDo(() => {
                        panel.Callback();
                    }, 1.5f + WaitingTime));
                }
            }
            return(panel);
        }