Unity客户端架构-PanelManager

来源:互联网 发布:网络团队建设 编辑:程序博客网 时间:2024/06/05 17:11
using UnityEngine;using System.Collections;using System.Diagnostics;using System;public class PanelManager : MonoBehaviour {    private Transform parent;    private string path;    public Transform Parent    {        get        {            if (this.parent == null)            {                GameObject gui = io.Gui;                if (gui)                {                    this.parent = gui.transform.Find("Camera");                }            }            return this.parent;        }    }    public void CreatePanel(DialogType type)    {#if UNITY_EDITOR        string typename = Util.ConvertPanelName(type);        this.CreatePanel(typename);#else         base.StartCoroutine(this.OnCreatePanel(type));#endif    }    private IEnumerator OnCreatePanel(DialogType type)    {        path = Util.AppContentDataUri + "UI/" + type.ToString() + "Panel.unity3d";        GameObject go = null;        WWW bundle = new WWW(path);        yield return bundle;        try        {            if (bundle.assetBundle.Contains(type.ToString() + "Panel"))            {                go = Instantiate(bundle.assetBundle.Load(type.ToString() + "Panel" + typeof(GameObject))) as GameObject;            }        }        catch (System.Exception e)        {            NGUIDebug.Log("catch go..... " + e.ToString());        }        go.name = type.ToString() + "Panel";        go.transform.parent = UIContainer.instance.transform;        go.transform.localPosition = Vector3.zero;        go.transform.localScale = Vector3.one;        bundle.assetBundle.Unload(false);    }    public void CreatePanel(string name)    {        if (this.Parent.FindChild(name) != null)        {            return;        }        GameObject gameObject = Util.LoadPrefab(Const.PanelPrefabDir + name + ".prefab");        if (gameObject == null)        {            return;        }//         GameObject go = GameObject.Instantiate(gameObject) as GameObject;//         go.transform.localPosition = Vector3.zero;//         go.name = name;        GameObject gameObject2 = Util.AddChild(gameObject, UIContainer.instance.transform);        gameObject2.name = name;        gameObject2.transform.localPosition = Vector3.zero;        this.OnCreatePanel(name, gameObject2);    }     private void OnCreatePanel(string name, GameObject go)    {        switch (name)        {            case "LoginPanel":                this.OnLoginPanel(go);                break;            case "CharacterPanel":                this.OnCharacterPanel(go);                break;            case "MainPanel":                this.OnMainPanel(go);                break;            case "WorldPanel":                this.OnWorldPanel(go);                break;            case "DuplicatePanel":                this.OnDuplicatePanel(go);                break;        }    }    private void OnLoginPanel(GameObject go)     {         go.transform.localPosition = new Vector3(0f, 0f, 0f);         io.container.loginPanel = go;     }    private void OnCharacterPanel(GameObject go)    {        go.transform.localPosition = new Vector3(0f, 0f, 0f);        io.container.characterPanel = go;    }    private void OnMainPanel(GameObject go)    {        go.transform.localPosition = new Vector3(0f, 0f, 0f);        io.container.mainPanel = go;    }    private void OnDuplicatePanel(GameObject go)    {        go.transform.localPosition = new Vector3(0f, 0f, 0f);        io.container.duplicatePanel = go;    }    private void OnWorldPanel(GameObject go)    {        go.transform.localPosition = new Vector3(0f, 0f, 0f);        io.container.WorldPanel = go;    }}
0 0
原创粉丝点击