UIDialog.OnCreate C# (CSharp) Method

OnCreate() public method

public OnCreate ( ) : void
return void
    public override void OnCreate()
    {
        base.OnCreate();
		m_dialogText = GetChildComponent<AocTypewriterEffect>("DialogText");
		m_head1Sprite = GetChildComponent<UISprite>("LeftHead");
		m_head2Sprite = GetChildComponent<UISprite>("RightHead");
        m_dialogBoardSprite = GetChildComponent<UISprite>("DialogBoard");
        m_dialogEffectPlayer = m_dialogBoardSprite.GetComponent<UIEffectPlayer>();

        m_backPic = GetChildComponent<UISprite>("Background");
		m_itemBoard = GetChildComponent<UISprite>("ItemBoard");
        m_clickSprite = GetChildComponent<UISprite>("ClickSprite");

        m_pressReceiver = m_dialogBoardSprite.transform.GetComponent<PressReceiver>();

        AddChildComponentMouseClick("SkipBtn", delegate()
        {
            EndDialog();
        });

        //解析DialogEvent配置文件
        string eventContent = ResourceManager.Singleton.LoadTextFile("DialogEvent");
        //解析Dialog配置文件////////////////////////////////////////////////////////////////////////
        StringReader sr = new StringReader(eventContent);
        string line = sr.ReadLine();
        while (line != null)
        {
            if (line.Contains("//"))
            {
                line = sr.ReadLine();
                continue;
            }
            if (string.IsNullOrEmpty(line))
            {
                line = sr.ReadLine();
                continue;
            }
            string[] values = line.Split(new string[] { "\t", " " }, System.StringSplitOptions.RemoveEmptyEntries);
            if (values.Length > 0)
            {
                int curStageNum = System.Convert.ToInt32(values[0]);
                DialogTriggerPos triggerPos = (DialogTriggerPos)System.Convert.ToInt32(values[1]);

                DialogEvent data = new DialogEvent();
                data.dialogGroupNum = System.Convert.ToInt32(values[2]);
                data.need3Star = (values[2] == "Y");
                data.backPic = values[3];
                data.triggerPos = triggerPos;

                m_dialogEventMap.Add(new KeyValuePair<int, DialogTriggerPos>(curStageNum, triggerPos), data);                               //添加对话数据
            }

            line = sr.ReadLine();
        }
        sr.Close();

        string content = ResourceManager.Singleton.LoadTextFile("Dialog");
        //解析Dialog配置文件////////////////////////////////////////////////////////////////////////
        sr = new StringReader(content);
        line = sr.ReadLine();
        int curDialogGroupNum = -1;
        List<DialogData> curDialogGroup = new List<DialogData>();
        while (line != null)
        {
            if (line.Contains("//"))
            {
                line = sr.ReadLine();
                continue;
            }
            if (string.IsNullOrEmpty(line))
            {
                line = sr.ReadLine();
                continue;
            }
            string[] values = line.Split(new string[] { "\t", " " }, System.StringSplitOptions.RemoveEmptyEntries);
            if (values.Length > 0)
            {
                int num = System.Convert.ToInt32(values[0]);
				if(curDialogGroupNum == -1)
				{
					curDialogGroupNum = num;
					m_dialogGroupMap.Add(curDialogGroupNum, curDialogGroup);
				}
                else if (num != curDialogGroupNum)                           //若数字变化了,新加一组对话
                {
					curDialogGroup = new List<DialogData>();            //重新创建一个对话组数据
					curDialogGroupNum = num;                            //更改当前在编的对话组数字
                    m_dialogGroupMap.Add(curDialogGroupNum, curDialogGroup);
                }

                DialogData data = new DialogData();
                data.activeLeftHead = (values[1] == "L");
                data.headLeft = values[2];
                data.headRight = values[3];
                data.itemSprite = values[4];
                data.speed = System.Convert.ToInt32(values[5]);
                data.content = values[6];
                data.content.Replace('_', ' ');                         //下划线替换成空格

                curDialogGroup.Add(data);                               //添加对话数据
            }

            line = sr.ReadLine();
        }
        sr.Close();
    }

Usage Example

Exemplo n.º 1
0
    public T OpenUI <T>() where T : UIPanelBase
    {
        System.Type type = typeof(T);

        GameObject prefab = ResourcesMgr.Instance.LoadUIPrefab(type.ToString());

        if (type.IsSubclassOf(typeof(UIWindow)))
        {
            GameObject go  = Instantiate(prefab, Vector3.zero, Quaternion.identity, wndParent);
            UIWindow   wnd = go.GetComponent <UIWindow>();
            wnd.OnCreate();
            //创建新的主界面时,删除所有界面
            if (wnd.isMain)
            {
                while (windowsStack.Count > 0)
                {
                    UIWindow temp = windowsStack.Pop();
                    temp.OnDispose();
                    Destroy(temp.gameObject);
                }
            }
            else if (windowsStack.Count > 0)
            {
                UIWindow temp = windowsStack.Peek();
                temp.OnHide();
                temp.gameObject.SetActive(false);
            }
            wnd.OnShow();
            windowsStack.Push(wnd);
            return(wnd as T);
        }
        else if (type.IsSubclassOf(typeof(UIDialog)))
        {
            GameObject go  = Instantiate(prefab, Vector3.zero, Quaternion.identity, dlgParent);
            UIDialog   dlg = go.GetComponent <UIDialog>();
            dlg.OnCreate();
            dlg.OnShow();
            dialogsStack.Push(dlg);
            return(dlg as T);
        }
        else
        {
            Debug.LogError("打開的UI類型有問題,請檢測類型");
            return(null);
        }
    }