Beispiel #1
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.Getinstate().LoadAsync <AudioClip>("Music/BK" + name, (Clip) =>
     {
         bkMusic.clip   = Clip;
         bkMusic.loop   = true;
         bkMusic.volume = bkValue;
         bkMusic.Play();
     });
 }
Beispiel #2
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, E_UI_Layer layer, UnityAction <T> callback) where T : BasePanel
    {
        ResMgr.Getinstate().LoadAsync <GameObject>("UI/" + panelName, (obj) =>
        {
            panelDic[panelName].ShowMe();
            //把他作为 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;

            default:
                break;
            }
            //设置父对象 设置相对位置和大小
            obj.transform.SetParent(father);
            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);
            }
            panel.ShowMe();
            //把面板存起来
            panelDic.Add(panelName, panel);
        });
    }
Beispiel #3
0
    public UIManager()
    {
        //创建 Canvas 让其过场景不被移除
        GameObject obj = ResMgr.Getinstate().Load <GameObject>("UI/Canvas");

        canvas = obj.transform;

        GameObject.DontDestroyOnLoad(obj);
        //找到各层
        bot    = canvas.Find("Bot");
        Mid    = canvas.Find("Mid");
        top    = canvas.Find("top");
        system = canvas.Find("system");


        //创建EventSystem 让过场景不溢出
        obj = ResMgr.Getinstate().Load <GameObject>("UI/EventSystem");
        GameObject.DontDestroyOnLoad(obj);
    }
Beispiel #4
0
    /// <summary>
    /// 往外拿东西,东西名字(路径),拿完之后要执行的函数 重载1创造的第一个物体啥也不干(默认创造在世界中心)
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public void GetObj(string name, UnityAction <GameObject> callback)
    {
        //有抽屉,抽屉里有东西
        if (poolDic.ContainsKey(name) && poolDic[name].poolList.Count > 0)//有抽屉并且有东西
        {
            callback(poolDic[name].GetObj());
        }
        else
        {//通过异步加载资源 创建对象给外部用
            ResMgr.Getinstate().LoadAsync <GameObject>(name, (o) =>
            {
                o.name = name;
            });


            //obj = GameObject.Instantiate(Resources.Load<GameObject>(name), transform);//从文件实例化对象
            ////把对象名字改成池子的名字
            //obj.name = name;
        }
    }
Beispiel #5
0
    /// <summary>
    /// 播放音效 回调这个音效,可以在外部主动停止 使用方法,public AudioSource sound (s)=>{sound=s} 形参s代表这个音效,此时对sound操作即可
    /// </summary>
    /// <param name="name"></param>
    public void PlaySound(string name, bool isLoop, UnityAction <AudioSource> callBack = null)
    {
        if (soundObj == null)
        {
            soundObj      = new GameObject();
            soundObj.name = "Sound";
        }

        //当音效资源异步加载结束后,再添加一个音效
        ResMgr.Getinstate().LoadAsync <AudioClip>("Music/Sound" + name, (Clip) =>
        {
            AudioSource source = soundObj.AddComponent <AudioSource>();
            source.clip        = Clip;
            source.loop        = isLoop;
            source.volume      = soundValue;
            source.Play();
            soundList.Add(source);
            if (callBack != null)
            {
                callBack(source);
            }
        });
    }