Example #1
0
        public UIManager()
        {
            //实例化时创建UI
            GameObject ob = ResourcesManager.GetInstance().LoadRes <GameObject>("UI/Canvas");

            canvas = ob.transform;
            bottom = canvas.Find("Bottom");
            middle = canvas.Find("Middle");
            top    = canvas.Find("Top");
            system = canvas.Find("System");

            ResourcesManager.GetInstance().LoadRes <GameObject>("UI/EventSystem");
        }
Example #2
0
        /// <summary>
        /// 创建并显示面板
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="layer"></param>
        /// <param name="action"></param>
        public void ShowPanel <T>(string name, UILayer layer, Action <T> action = null) where T : BasePanel
        {
            if (panelDic.ContainsKey(name))
            {
                Debug.Log("已经显示UI");
            }
            else
            {
                ResourcesManager.GetInstance().LoadResAsync <GameObject>("prefab/UI" + name, (o) =>
                {
                    Transform parent = null;
                    switch (layer)
                    {
                    case UILayer.bottom:
                        parent = bottom;
                        break;

                    case UILayer.middle:
                        parent = middle;
                        break;

                    case UILayer.top:
                        parent = top;
                        break;

                    case UILayer.system:
                        parent = system;
                        break;
                    }
                    //复位控件
                    o.transform.SetParent(parent);
                    o.transform.localPosition = Vector3.zero;
                    o.transform.localScale    = Vector2.one;
                    (o.transform as RectTransform).offsetMax = Vector2.zero;
                    (o.transform as RectTransform).offsetMin = Vector2.zero;


                    //执行回调
                    T panel = o.GetComponent <T>();
                    if (action != null)
                    {
                        action(panel);
                    }
                    //面板显示时执行的方法
                    panel.ShowUIPanel();
                    //保存控件
                    panelDic.Add(name, panel);
                });
            }
        }
Example #3
0
 public void PlayEffectSound(string name, Action <AudioClip> action = null)
 {
     if (effectMusic == null)
     {
         effectMusic = new GameObject("EffectMusic");
     }
     ResourcesManager.GetInstance().LoadResAsync <AudioClip>("Music/effect/" + name,
                                                             (o) => {
         AudioSource effect = effectMusic.AddComponent <AudioSource>();
         effect.clip        = o;
         effect.loop        = false;
         effect.Play();
         effectMusicList.Add(effect);
         if (action != null)
         {
             action(o);
         }
     });
 }
Example #4
0
 /// <summary>
 /// 播放背景音乐
 /// </summary>
 /// <param name="name"></param>
 public void PlayBackgroundMusic(string name, float volume, Action <AudioClip> action = null)
 {
     if (backgroundMusic == null)
     {
         GameObject ob = new GameObject("BackgroundMusic");
         backgroundMusic = ob.AddComponent <AudioSource>();
     }
     ResourcesManager.GetInstance().LoadResAsync <AudioClip>("Music/bgm/" + name,
                                                             (o) => {
         backgroundMusic.clip   = o;
         backgroundMusic.volume = volume;
         backgroundMusic.loop   = true;
         backgroundMusic.Play();
         if (action != null)
         {
             action(o);
         }
     });
 }
Example #5
0
        /// <summary>
        /// 获取物体 异步加载
        /// </summary>
        /// <param name="name"></param>
        /// <param name="loadComplete"></param>
        /// <returns></returns>
        public GameObject GetGameObject(string name, Action <GameObject> loadComplete)
        {
            GameObject ob = null;

            if (poolDir.ContainsKey(name) && poolDir[name].poolList.Count != 0)
            {
                ob = poolDir[name].GetObj();
                loadComplete(ob);
            }
            else
            {
                ResourcesManager.GetInstance().LoadResAsync <GameObject>(name, (e) =>
                {
                    e.name = name;
                    loadComplete(e);
                });
            }
            return(ob);
        }
Example #6
0
        /// <summary>
        /// 获取物体 同步加载
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public GameObject GetGameObject(string name)
        {
            GameObject ob = null;

            if (poolDir.ContainsKey(name))
            {
                //存在但没库存
                if (poolDir[name].poolList.Count == 0)
                {
                    ob      = ResourcesManager.GetInstance().LoadRes <GameObject>(name);
                    ob.name = name;
                }
                else
                {
                    ob = poolDir[name].GetObj();
                }
            }
            else
            {
                ob      = ResourcesManager.GetInstance().LoadRes <GameObject>(name);
                ob.name = name;
            }
            return(ob);
        }