Example #1
0
        /// <summary>
        /// 显示面板
        /// </summary>
        /// <typeparam name="T">面板脚本类型</typeparam>
        /// <param name="panelName">面板名</param>
        /// <param name="layer">显示在哪一层</param>
        /// <param name="callBack">当面板预设体创建成功后 你想做的事</param>
        public void OpenPanel <T>(string panelName, E_UI_Layer layer = E_UI_Layer.Mid, UnityAction <T> callBack = null) where T : BasePanel
        {
            if (panelDic.ContainsKey(panelName))
            {
                //处理面板创建完成后的逻辑
                if (callBack != null)
                {
                    callBack(panelDic[panelName] as T);
                }
            }

            ResMgr.GetInstance().LoadAsync <GameObject>(AssetUtility.GetUIAsset(panelName), (obj) =>
            {
                //把他作为Canvas的子对象
                //并且 要设置它的相对位置
                //找到父对象 你到底显示再哪一层
                Transform father = bot;
                switch (layer)
                {
                case E_UI_Layer.Mid:
                    father = mid;
                    break;

                case E_UI_Layer.Top:
                    father = top;
                    break;

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

                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale    = Vector3.one;

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

                //得到预设体身上的面板脚本
                T panel = obj.GetComponent <T>();
                //处理面板创建后的逻辑
                if (callBack != null)
                {
                    callBack(panel);
                }

                //把面板存起来
                panelDic.Add(panelName, panel);
            });
        }
Example #2
0
        /// <summary>
        /// 播放背景音乐
        /// </summary>
        /// <param name="name"></param>
        public void PlayBkMusic(string name)
        {
            if (bkMusic == null)
            {
                GameObject obj = new GameObject();
                obj.name = "BkMusic";
                bkMusic  = obj.AddComponent <AudioSource>();
            }

            //异步加载背景音乐 加载完成后 播放
            ResMgr.GetInstance().LoadAsync <AudioClip>("Music/BK/" + name, (clip) =>
            {
                bkMusic.clip   = clip;
                bkMusic.loop   = true;
                bkMusic.volume = bkValue;
                bkMusic.Play();
            });
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public void GetObj(string name, UnityEngine.Events.UnityAction <GameObject> callBack)
 {
     //有抽屉 并且抽屉里面有东西
     if (poolDic.ContainsKey(name) && poolDic[name].poolList.Count > 0)
     {
         callBack(poolDic[name].GetObj());
     }
     else
     {
         //通过异步加载资源 创建对象给外部用
         ResMgr.GetInstance().LoadAsync <GameObject>(name, (o) =>
         {
             o.name = name;
             callBack(o);
         });
         //obj = GameObject.Instantiate(Resources.Load<GameObject>(name));
         //把对象名字改的和池子名字一样
         //obj.name = name;
     }
 }
Example #4
0
        /// <summary>
        /// 播放音效
        /// </summary>
        /// <param name="name"></param>
        /// <param name="callBack"></param>
        public void PlaySound(string name, bool isLoop, UnityAction <AudioSource> callBack = null)
        {
            if (soundObj == null)
            {
                soundObj      = new GameObject();
                soundObj.name = "Sound";
            }
            //当音效资源异步资源加载结束后 再添加一个音效
            AudioSource source = soundObj.AddComponent <AudioSource>();

            //异步加载背景音乐 加载完成后 播放
            ResMgr.GetInstance().LoadAsync <AudioClip>("Music/Sound/" + name, (clip) =>
            {
                source.clip   = clip;
                source.loop   = isLoop;
                source.volume = bkValue;
                source.Play();
                soundList.Add(source);
                if (callBack != null)
                {
                    callBack(source);
                }
            });
        }
Example #5
0
        void Start()
        {
            resources = GameEntry.Res;

            GenerateMap();
        }