Ejemplo n.º 1
0
        /// <summary>
        /// 播放背景音乐
        /// </summary>
        /// <param name="name">音乐名字</param>
        public void LoadPlayBGMusic(string name, UnityAction <AudioSource> callback = null)
        {
            if (bgMusic == null)
            {
                //Debug.Log("Plyer");
                GameObject obj = new GameObject();
                obj.name      = "BGMusic";
                bgMusic       = obj.AddComponent <AudioSource>();
                bgTargetMusic = obj.AddComponent <AudioSource>();
                //PushSource(bgTargetMusic);
                bgMusic.transform.SetParent(musicMgrObj.transform);
            }
            ResMgr.GetInstance().loadAsync <AudioClip>("Music/BG/" + name, (clip) =>
            {
                if (clip != null)
                {
                    if (!audioClipsDic.ContainsValue(clip))
                    {
                        if (!audioClipsDic.ContainsKey(clip.name))
                        {
                            audioClipsDic.Add(clip.name, clip);
                        }
                    }

                    bgMusic.clip = clip;
                }
                bgMusic.loop        = true;
                bgMusic.volume      = bgValue;
                bgMusic.playOnAwake = false;
                // bgMusic.i
                bgMusic.Play();
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 通过 Resource 加载音效
        /// </summary>
        /// <param name="_clipName"></param>
        /// <param name="isLoop"></param>
        /// <param name="callback"></param>
        public void PlaySound(string _clipName, bool isLoop, UnityAction <AudioSource> callback = null)
        {
            if (soundObj == null)
            {
                soundObj      = new GameObject();
                soundObj.name = "Sound";
                soundObj.transform.SetParent(musicMgrObj.transform);
            }


            ResMgr.GetInstance().loadAsync <AudioClip>("Music/Sound/" + _clipName, (clip) =>
            {
                if (clip == null)
                {
                    return;
                }

                AudioSource source = soundObj.AddComponent <AudioSource>();

                source.clip         = clip;
                source.loop         = isLoop;
                source.volume       = soundValue;
                source.spatialBlend = 0f;
                source.Play();

                soundList.Add(source);

                if (callback != null)
                {
                    callback?.Invoke(source);
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 显示面板
        /// </summary>
        /// <typeparam name="T">面板基类类型</typeparam>
        /// <param name="panelName">面板名称</param>
        /// <param name="layer">显示在哪一层</param>
        /// <param name="callback">最终需要执行的函数</param>
        public void ShowPanel <T>(string panelName, UI_layer layer = UI_layer.Mid, UnityAction <T> callback = null) where T : BasePanel
        {
            if (panelDic.ContainsKey(panelName))
            {
                panelDic[panelName].ShowUI();

                if (callback != null)
                {
                    callback(panelDic[panelName] as T);
                }

                return;
            }

            ResMgr.GetInstance().loadAsync <GameObject>("UI/" + panelName, (obj) =>
            {
                //把父对象设置为canvas
                //设置到相应位置
                Transform father = mid;

                Debug.Log(system.gameObject);
                switch (layer)
                {
                case UI_layer.Top:
                    father = top;
                    break;

                case UI_layer.Down:
                    father = down;
                    break;

                case UI_layer.System:
                    father = system;
                    break;
                }
                //设置父对象
                obj.transform.SetParent(father);

                //obj.name = panelName;

                //设置相对位置和大小
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale    = Vector3.zero;

                (obj.transform as RectTransform).offsetMax = Vector2.zero;
                (obj.transform as RectTransform).offsetMin = Vector2.zero;

                T panel = obj.GetComponent <T>();

                if (callback != null)
                {
                    callback(panel);
                }

                panel.ShowUI();

                panelDic.Add(panelName, panel);
            });
        }
Ejemplo n.º 4
0
        public UIManager()
        {
            GameObject obj = ResMgr.GetInstance().load <GameObject>("UI/Canvas");

            canvas = obj.transform as RectTransform;
            GameObject.DontDestroyOnLoad(obj);

            top    = canvas.Find("Top");
            mid    = canvas.Find("Mid");
            down   = canvas.Find("Down");
            system = canvas.Find("System");

            obj = ResMgr.GetInstance().load <GameObject>("UI/EventSystem");
            GameObject.DontDestroyOnLoad(obj);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 获得对象池中的闲置对象
 /// </summary>
 /// <param name="name">地址</param>
 /// <returns></returns>
 public void GetObj(string name, UnityAction <GameObject> callback)
 {
     //GameObject obj = null;
     //判断缓存池中是否有缓存空间和闲置对象
     if (poolDic.ContainsKey(name) && poolDic[name].poolList.Count > 0)
     {
         //obj = poolDic[name].GetObj();
         callback?.Invoke(poolDic[name].GetObj());
     }
     else
     {
         ResMgr.GetInstance().loadAsync <GameObject>(name, (o) =>
         {
             o.name = name;
             callback?.Invoke(o);
         });
         //obj = GameObject.Instantiate(Resources.Load<GameObject>(name));
     }
 }