XmlForm

出自 ProgWiki
前往: 導覽搜尋

XmlFormUnity的UI進行XML化。

檔案

XmlForm.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Xml;
using System.Xml.Serialization;
using UnityEngine;
 
public class XmlForm
{
    private static ConfigInfo _Config = null;
 
    private XmlDocument _Document;
    private string _FormID;
    private string _FormID2;
 
    private Dictionary<string, string> _FromData;
    private Dictionary<string, string> _headers;
    private Dictionary<string, Texture2D> _uiTexture2D;
    private Dictionary<string, GUIStyle> _uiStyle;
 
    private Dictionary<string, string> _uiStrValue;
    private Dictionary<string, int> _uiIntValue;
    private Dictionary<string, float> _uiFloatValue;
    private Dictionary<string, Vector2> _uiVector2Value;
 
    private Dictionary<int, string> _uiIdes;
    private int _uiIdIndex;
 
    public Dictionary<string, string> FromData
    {
        get { return this._FromData; }
    }
 
    public static string UserConfigFile { get; set; }
 
    public static bool IsExistConfig { get; set; }
 
    public static Uri BaseUri { get; set; }
 
    public static string HomeUrl { get; set; }
 
    private void WaitHttpComplete(ref WWW http)
    {
        while ((http.isDone == false) &&
                (http.error == null))
        {
            Thread.Sleep(1);
        }
    }
 
    private void DebugOut(object obj)
    {
        if (obj is string)
        {
            Debug.Log(obj as string);
        }
        else if (obj is Exception)
        {
            Debug.Log((obj as Exception).Message);
        }
        else if (obj is WWW)
        {
            Debug.Log((obj as WWW).error);
        }
        else
        {
            XmlWriter w = XmlWriter.Create("");
            (obj as XmlNode).WriteTo(w);
            Debug.Log(w.ToString());
        }
    }
 
    public XmlForm(string FormID = "")
    {
        _FormID = "";
        _FormID2 = FormID;
    }
 
    // Use this for initialization
    public void Awake()
    {
        _Document = new XmlDocument();
        _FormID = "";
 
        _FromData = new Dictionary<string, string>();
        _headers = new Dictionary<string, string>();
        _uiTexture2D = new Dictionary<string, Texture2D>();
        _uiStyle = new Dictionary<string, GUIStyle>();
 
        //UI相關變數暫存用
        _uiStrValue = new Dictionary<string, string>();
        _uiIntValue = new Dictionary<string, int>();
        _uiFloatValue = new Dictionary<string, float>();
        _uiVector2Value = new Dictionary<string, Vector2>();
 
        _uiIdes = new Dictionary<int, string>();
        _uiIdIndex = 0;
 
        if (_Config == null)
        {
            _Config = new ConfigInfo();
            if (IsExistConfig)
                loadConfig();
        }
 
        _headers.Add("GroupID", _Config.GroupID);
        _headers.Add("LoginID", _Config.LoginID);
        _headers.Add("Password", _Config.Password);
    }
 
    // Update is called once per frame
    public void Update()
    {
        if (_FormID != _FormID2)
        {
            Uri url = new Uri(_FormID2);
            if ((url.Scheme == "http") && (url.Scheme == "https"))
            {
            }
            else if (_FormID2[0] == '/')
            {
                _FormID2 = (new Uri(BaseUri, _FormID2)).PathAndQuery;
            }
            else
            {
                //從用戶端讀取GUI設定檔
                string GUIFile = Application.dataPath + "/" + _FormID2 + ".xml";
                if (Path.DirectorySeparatorChar != '/')
                    GUIFile = GUIFile.Replace('/', Path.DirectorySeparatorChar);
 
                _Document.Load(GUIFile);
                _FormID = _FormID2;
                ReInitForm();
                return;
            }
 
            {
                //從WebServer端讀取GUI設定檔
                WWW http = new WWW(_FormID2);
                WaitHttpComplete(ref http);
 
                if (http.error != null)
                {
                    DebugOut(http.error);
                    return;
                }
 
                _Document.LoadXml(http.text);
 
                _FormID = _FormID2;
                ReInitForm();
            }
        }
    }
 
    public void OnGUI()
    {
        try
        {
            if (_Document == null)
                return;
 
            XmlNodeList formList = _Document.SelectNodes("/form");
            if ((formList == null) ||
                (formList.Count == 0))
                return;
 
            _uiIdIndex = 0;
 
            XmlNode form = formList.Item(0);
            TryParseXmlForm(form);
        }
        catch (Exception ex)
        {
            DebugOut(ex);
        }
    }
 
    private void TryParseXmlForm(XmlNode node)
    {
        if ((node == null) || (!node.HasChildNodes))
            return;
 
        XmlNodeList uiList = node.ChildNodes;
 
        foreach (XmlNode ui in uiList)
        {
            string type = ui.Name;
 
            string id = getXmlAttributesValue(ui, "id", string.Empty);
            string text = getXmlAttributesValue(ui, "text", string.Empty);
            string image = getXmlAttributesValue(ui, "image", string.Empty);
            string tooltip = getXmlAttributesValue(ui, "tooltip", string.Empty);
 
            string class2 = getXmlAttributesValue(ui, "class", string.Empty);
            string style = getXmlAttributesValue(ui, "style", string.Empty);
            string rect = getXmlAttributesValue(ui, "rect", string.Empty);
 
            bool IsExistId = false;
            if (!string.IsNullOrEmpty(id))
            {
                IsExistId = true;
                GUI.SetNextControlName(id);
                _uiIdIndex++;
                _uiIdes.Add(_uiIdIndex, id);
            }
 
            bool isFocus = false;
            string Focus = getXmlAttributesValue(node, "focus", string.Empty);
            if (!string.IsNullOrEmpty(Focus))
                if (!bool.TryParse(Focus, out isFocus))
                    isFocus = false;
 
            GUIStyle style2 = null;
            if (!string.IsNullOrEmpty(style) ||
                !string.IsNullOrEmpty(class2))
            {
                if (type == "style")
                {
                    TryParseStyle(string.Empty, class2, style, out style2);
 
                    if (IsExistId == false)
                    {
                        DebugOut(ui);
                        continue;
                    }
 
                    _uiStyle.Add(id, style2);
                    continue;
                }
                else
                {
                    TryParseStyle(type, class2, style, out style2);
                }
            }
 
            bool useGUILayout = false;
            Rect position;
            GUILayoutOption[] layout2 = null;
            if (!TryParseRect(rect, out position))
            {
                //DebugOut(ui);
                //continue;
                useGUILayout = true;
 
                string layout = getXmlAttributesValue(node, "layout", string.Empty);
                if (!string.IsNullOrEmpty(layout))
                    TryParseGUILayoutOption(layout, out layout2);
                else
                    layout2 = new GUILayoutOption[0];
            }
            else
            {
                //------------------------------------------
                //UI水平位置修正
                string align = getXmlAttributesValue(ui, "align", string.Empty);
                if (!string.IsNullOrEmpty(align))
                {
                    switch (align)
                    {
                        case "Left":     //水平置左(Left)
                            position.x = 0;
                            break;
 
                        case "Center":  //水平置中(Center)
                            position.x = (Screen.width >= position.width) ? ((Screen.width - position.width) / 2) : 0;
                            break;
 
                        case "Right":   //水平置右(Right)
                            position.x = (Screen.width >= position.width) ? (Screen.width - position.width) : 0;
                            break;
                    }
                }
 
                //UI垂直位置修正
                string valign = getXmlAttributesValue(ui, "valign", string.Empty);
                if (!string.IsNullOrEmpty(valign))
                {
                    switch (valign)
                    {
                        case "Top":     //垂直置頂(Top)
                            position.y = 0;
                            break;
 
                        case "Center":  //垂直置中
                            position.y = (Screen.height >= position.height) ? ((Screen.height - position.height) / 2) : 0;
                            break;
 
                        case "Bottom":  //垂直置底(Bottom)
                            position.y = (Screen.height >= position.height) ? (Screen.height - position.height) : 0;
                            break;
                    }
                }
            }
            //------------------------------------------
 
            Texture2D image2 = null;
            GUIContent content2 = new GUIContent();
 
            if (!string.IsNullOrEmpty(image))
            {
                image2 = getTexture2D(image);
                content2.image = image2;
            }
 
            if (!string.IsNullOrEmpty(text))
                content2.text = text;
 
            if (!string.IsNullOrEmpty(tooltip))
                content2.tooltip = tooltip;
 
            switch (type)
            {
                case "box":
                    {
                        //TODO: Box
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                GUI.Box(position, content2);
                            else
                                GUI.Box(position, content2, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                GUILayout.Box(content2, layout2);
                            else
                                GUILayout.Box(content2, style2, layout2);
                        }
                    }
                    break;
 
                case "button":
                    {
                        //TODO: Button
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                            {
                                if (GUI.Button(position, content2))
                                    onButtonClick(ui);
                            }
                            else
                            {
                                if (GUI.Button(position, content2, style2))
                                    onButtonClick(ui);
                            }
                        }
                        else
                        {
                            if (style2 == null)
                            {
                                if (GUILayout.Button(content2, layout2))
                                    onButtonClick(ui);
                            }
                            else
                            {
                                if (GUILayout.Button(content2, style2, layout2))
                                    onButtonClick(ui);
                            }
                        }
                    }
                    break;
 
                case "drawtexture":
                    {
                        //TODO: DrawTexture
                        if ((image2 == null) || (useGUILayout == true))
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string scaleMode = getXmlAttributesValue(ui, "scalemode", string.Empty);
                        string alphaBlend = getXmlAttributesValue(ui, "alphablend", string.Empty);
                        string imageAspect = getXmlAttributesValue(ui, "imageaspect", string.Empty);
 
                        ScaleMode scaleMode2;
                        bool alphaBlend2;
                        float imageAspect2;
 
                        if (!TryParseScaleMode(scaleMode, out scaleMode2))
                            scaleMode2 = ScaleMode.StretchToFill;
                        if (!bool.TryParse(alphaBlend, out alphaBlend2))
                            alphaBlend2 = true;
                        if (!float.TryParse(imageAspect, out imageAspect2))
                            imageAspect2 = 0;
 
                        GUI.DrawTexture(position, image2, scaleMode2, alphaBlend2, imageAspect2);
                    }
                    break;
 
                case "drawtexturewithtexcoords":
                    {
                        //TODO: DrawTextureWithTexCoords
                        string texCoords = getXmlAttributesValue(ui, "texcoords", string.Empty);
                        string alphaBlend = getXmlAttributesValue(ui, "alphablend", string.Empty);
                        Rect texCoords2;
                        bool alphaBlend2;
 
                        if ((image2 == null) ||
                            (useGUILayout == true) ||
                            !TryParseRect(texCoords, out texCoords2))
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        if (!bool.TryParse(alphaBlend, out alphaBlend2))
                            alphaBlend2 = true;
 
                        GUI.DrawTextureWithTexCoords(position, image2, texCoords2, alphaBlend2);
                    }
                    break;
 
                case "group":
                    {
                        //TODO: Group
                        if (useGUILayout == false)
                        {
                            if (string.IsNullOrEmpty(text) && (image2 == null))
                            {
                                if (style2 == null)
                                    GUI.BeginGroup(position);
                                else
                                    GUI.BeginGroup(position, style2);
                            }
                            else
                            {
                                if (style2 == null)
                                    GUI.BeginGroup(position, content2);
                                else
                                    GUI.BeginGroup(position, content2, style2);
                            }
 
                            //遞迴展開
                            TryParseXmlForm(ui);
                            GUI.EndGroup();
                        }
                        else 
                        {
                            string screenRect = getXmlAttributesValue(ui, "screenrect", string.Empty);
                            if (!TryParseRect(screenRect, out position))
                                position = new Rect(0, 0, Screen.width, Screen.height);
 
                            if (string.IsNullOrEmpty(text) && (image2 == null))
                            {
                                if (style2 == null)
                                    GUILayout.BeginArea(position);
                                else
                                    GUILayout.BeginArea(position, style2);
                            }
                            else
                            {
                                if (style2 == null)
                                    GUILayout.BeginArea(position, content2);
                                else
                                    GUILayout.BeginArea(position, content2, style2);
                            }
 
                            //遞迴展開
                            TryParseXmlForm(ui);
                            GUILayout.EndArea();
                        }
                    }
                    break;
 
                case "horizontalscrollbar":
                    {
                        //TODO: HorizontalScrollbar
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string post = getXmlAttributesValue(ui, "post", string.Empty);
                        bool isPost;
                        if (!bool.TryParse(post, out isPost))
                            isPost = true;
 
                        string size = getXmlAttributesValue(ui, "size", "1");
                        string left = getXmlAttributesValue(ui, "left", "0");
                        string right = getXmlAttributesValue(ui, "right", "100");
 
                        float leftValue;
                        float rightValue;
                        float size2;
                        float scrollPos;
 
                        if (!float.TryParse(size, out size2))
                            size2 = 1;
 
                        if (!float.TryParse(left, out leftValue))
                            leftValue = 0;
 
                        if (!float.TryParse(right, out rightValue))
                            rightValue = 100;
 
                        if (_uiFloatValue.ContainsKey(id))
                            scrollPos = _uiFloatValue[id];
                        else
                            scrollPos = 0;
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUI.HorizontalScrollbar(position, scrollPos, size2, leftValue, rightValue);
                            else
                                _uiFloatValue[id] = GUI.HorizontalScrollbar(position, scrollPos, size2, leftValue, rightValue, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUILayout.HorizontalScrollbar(scrollPos, size2, leftValue, rightValue, layout2);
                            else
                                _uiFloatValue[id] = GUILayout.HorizontalScrollbar(scrollPos, size2, leftValue, rightValue, style2, layout2);
                        }
 
                        if (isPost)
                            _FromData[id] = _uiFloatValue[id].ToString();
                    }
                    break;
 
                case "horizontalslider":
                    {
                        //TODO: HorizontalSlider
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string post = getXmlAttributesValue(ui, "post", string.Empty);
                        bool isPost;
                        if (!bool.TryParse(post, out isPost))
                            isPost = true;
                        string left = getXmlAttributesValue(ui, "left", "0");
                        string right = getXmlAttributesValue(ui, "right", "100");
 
                        float leftValue;
                        float rightValue;
                        float SliderValue;
 
                        if (!float.TryParse(left, out leftValue))
                            leftValue = 0;
 
                        if (!float.TryParse(right, out rightValue))
                            rightValue = 100;
 
                        if (_uiFloatValue.ContainsKey(id))
                            SliderValue = _uiFloatValue[id];
                        else
                            SliderValue = 0;
 
                        GUIStyle thumb2 = null;
                        if (style2 != null)
                        {
                            string thumb = getXmlAttributesValue(ui, "thumb", string.Empty);
                            TryParseStyle("horizontalSliderThumb", string.Empty, thumb, out thumb2);
                        }
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUI.HorizontalSlider(position, SliderValue, leftValue, rightValue);
                            else
                                _uiFloatValue[id] = GUI.HorizontalSlider(position, SliderValue, leftValue, rightValue, style2, thumb2);
                        }
                        else
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUILayout.HorizontalSlider(SliderValue, leftValue, rightValue, layout2);
                            else
                                _uiFloatValue[id] = GUILayout.HorizontalSlider(SliderValue, leftValue, rightValue, style2, thumb2, layout2);
                        }
 
                        if (isPost)
                            _FromData[id] = _uiFloatValue[id].ToString();
                    }
                    break;
 
                case "label":
                    {
                        //TODO: Label
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                GUI.Label(position, content2);
                            else
                                GUI.Label(position, content2, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                GUILayout.Label(content2, layout2);
                            else
                                GUILayout.Label(content2, style2, layout2);
                        }
                    }
                    break;
 
                case "modalwindow":
                    {
                        //TODO: ModalWindow
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string func = getXmlAttributesValue(ui, "func", string.Empty);
                        GUI.WindowFunction func2;
                        if (!TryParseWindowFunction(func, out func2))
                            func2 = DefaultDoWindow;
 
                        if (style2 == null)
                            GUI.ModalWindow(_uiIdIndex, position, func2, content2, style2);
                        else
                            GUI.ModalWindow(_uiIdIndex, position, func2, content2);
                    }
                    break;
 
                case "passwordfield":
                    {
                        //TODO: PasswordField
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        if (_FromData.ContainsKey(id))
                            text = _FromData[id];
 
                        int maxLength2;
                        string maxLength = getXmlAttributesValue(ui, "maxlength", string.Empty);
                        if (!int.TryParse(maxLength, out maxLength2))
                            maxLength2 = -1;
 
                        char maskChar = '*';
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                text = GUI.PasswordField(position, text, maskChar, maxLength2);
                            else
                                text = GUI.PasswordField(position, text, maskChar, maxLength2, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                text = GUILayout.PasswordField(text, maskChar, maxLength2, layout2);
                            else
                                text = GUILayout.PasswordField(text, maskChar, maxLength2, style2, layout2);
                        }
                        _FromData[id] = text;
                    }
                    break;
 
                case "repeatbutton":
                    {
                        //TODO: RepeatButton
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                            {
                                if (GUI.RepeatButton(position, content2))
                                    onButtonClick(ui);
                            }
                            else
                            {
                                if (GUI.RepeatButton(position, content2, style2))
                                    onButtonClick(ui);
                            }
                        }
                        else
                        {
                            if (style2 == null)
                            {
                                if (GUILayout.RepeatButton(content2, layout2))
                                    onButtonClick(ui);
                            }
                            else
                            {
                                if (GUILayout.RepeatButton(content2, style2, layout2))
                                    onButtonClick(ui);
                            }
                        }
                    }
                    break;
 
                case "scrollview":
                    {
                        //TODO: BeginScrollView
                        if (string.IsNullOrEmpty(id))
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string viewRect = getXmlAttributesValue(ui, "viewrect", string.Empty);
                        Rect viewRect2;
 
                        Vector2 scrollPosition;
                        if (_uiVector2Value.ContainsKey(id))
                            scrollPosition = _uiVector2Value[id];
                        else
                            scrollPosition = Vector2.zero;
 
                        string ShowHorizontal = getXmlAttributesValue(ui, "showhorizontal", string.Empty);
                        string ShowVertical = getXmlAttributesValue(ui, "showvertical", string.Empty);
                        bool alwaysShowHorizontal;
                        bool alwaysShowVertical;
                        if (!bool.TryParse(ShowHorizontal, out alwaysShowHorizontal))
                            alwaysShowHorizontal = false;
                        if (!bool.TryParse(ShowVertical, out alwaysShowVertical))
                            alwaysShowVertical = false;
 
                        if (useGUILayout == false)
                        {
                            if (!TryParseRect(viewRect, out viewRect2))
                            {
                                DebugOut(ui);
                                continue;
                            }
 
                            if (style2 == null)
                                _uiVector2Value[id] = GUI.BeginScrollView(position, scrollPosition, viewRect2, alwaysShowHorizontal, alwaysShowVertical);
                            else
                                _uiVector2Value[id] = GUI.BeginScrollView(position, scrollPosition, viewRect2, alwaysShowHorizontal, alwaysShowVertical, style2, style2);
 
                            //遞迴展開
                            TryParseXmlForm(ui);
                            GUI.EndScrollView();
                        }
                        else
                        {
                            if (style2 == null)
                                _uiVector2Value[id] = GUILayout.BeginScrollView(scrollPosition, alwaysShowHorizontal, alwaysShowVertical, layout2);
                            else
                                _uiVector2Value[id] = GUILayout.BeginScrollView(scrollPosition, alwaysShowHorizontal, alwaysShowVertical, style2, style2, layout2);
 
                            //遞迴展開
                            TryParseXmlForm(ui);
                            GUILayout.EndScrollView();
                        }
                    }
                    break;
 
                case "selectiongrid":
                    {
                        //TODO: SelectionGrid
                        string post = getXmlAttributesValue(ui, "post", string.Empty);
 
                        GUIContent[] option;
                        string[] values;
                        if (string.IsNullOrEmpty(id) ||
                            !TryParseOption(node, out option, out values))
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        bool isPost;
                        if (!bool.TryParse(post, out isPost))
                            isPost = true;
 
                        int xCount = 2;
                        int selectedIndex;
 
                        if (_uiIntValue.ContainsKey(id))
                            selectedIndex = _uiIntValue[id];
                        else
                            selectedIndex = 0;
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                selectedIndex = GUI.SelectionGrid(position, selectedIndex, option, xCount);
                            else
                                selectedIndex = GUI.SelectionGrid(position, selectedIndex, option, xCount, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                selectedIndex = GUILayout.SelectionGrid(selectedIndex, option, xCount, layout2);
                            else
                                selectedIndex = GUILayout.SelectionGrid(selectedIndex, option, xCount, style2, layout2);
                        }
 
                        _uiIntValue[id] = selectedIndex;
                        _uiStrValue[id] = values[selectedIndex];
 
                        if (isPost)
                            _FromData[id] = values[selectedIndex];
                    }
                    break;
 
                case "space":
                    if (useGUILayout == true) 
                    {
                        float height2;
                        string height = getXmlAttributesValue(ui, "height", string.Empty);
                        if (!float.TryParse(height, out height2))
                            height2 = 1;
                        GUILayout.Space(height2);
                    }
                    break;
                case "textarea":
                    {
                        //TODO: TextArea
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        if (_FromData.ContainsKey(id))
                            text = _FromData[id];
 
                        int maxLength2;
                        string maxLength = getXmlAttributesValue(ui, "maxlength", string.Empty);
                        if (!int.TryParse(maxLength, out maxLength2))
                            maxLength2 = -1;
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                text = GUI.TextArea(position, text, maxLength2);
                            else
                                text = GUI.TextArea(position, text, maxLength2, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                text = GUILayout.TextArea(text, maxLength2, layout2);
                            else
                                text = GUILayout.TextArea(text, maxLength2, style2, layout2);
                        }
                        _FromData[id] = text;
                    }
                    break;
 
                case "textfield":
                    {
                        //TODO: TextField
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        if (_FromData.ContainsKey(id))
                            text = _FromData[id];
 
                        int maxLength2;
                        string maxLength = getXmlAttributesValue(ui, "maxlength", string.Empty);
                        if (!int.TryParse(maxLength, out maxLength2))
                            maxLength2 = -1;
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                text = GUI.TextField(position, text, maxLength2);
                            else
                                text = GUI.TextField(position, text, maxLength2, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                text = GUILayout.TextField(text, maxLength2, layout2);
                            else
                                text = GUILayout.TextField(text, maxLength2, style2, layout2);
                        }
                        _FromData[id] = text;
                    }
                    break;
 
                case "toggle":
                    {
                        //TODO: Toggle
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        bool value = false;
                        bool value2 = false;
                        if (_FromData.ContainsKey(id))
                            bool.TryParse(_FromData[id], out value);
                        else if (ui.Attributes["value"] != null)
                            bool.TryParse(ui.Attributes["value"].Value, out value);
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                value2 = GUI.Toggle(position, value, content2);
                            else
                                value2 = GUI.Toggle(position, value, content2, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                value2 = GUILayout.Toggle(value, content2, layout2);
                            else
                                value2 = GUILayout.Toggle(value, content2, style2, layout2);
                        }
 
                        _FromData[id] = value2.ToString();
                    }
                    break;
 
                case "toolbar":
                    {
                        //TODO: Toolbar
                        string post = getXmlAttributesValue(ui, "post", string.Empty);
 
                        GUIContent[] option;
                        string[] values;
 
                        if (string.IsNullOrEmpty(id) ||
                            !TryParseOption(node, out option, out values))
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        bool isPost;
                        if (!bool.TryParse(post, out isPost))
                            isPost = true;
 
                        int selectedIndex;
 
                        if (_uiIntValue.ContainsKey(id))
                            selectedIndex = _uiIntValue[id];
                        else
                            selectedIndex = 0;
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                selectedIndex = GUI.Toolbar(position, selectedIndex, option);
                            else
                                selectedIndex = GUI.Toolbar(position, selectedIndex, option, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                selectedIndex = GUILayout.Toolbar(selectedIndex, option, layout2);
                            else
                                selectedIndex = GUILayout.Toolbar(selectedIndex, option, style2, layout2);
                        }
 
                        _uiIntValue[id] = selectedIndex;
                        _uiStrValue[id] = values[selectedIndex];
 
                        if (isPost)
                            _FromData[id] = values[selectedIndex];
                    }
                    break;
 
                case "verticalscrollbar":
                    {
                        //TODO: VerticalScrollbar
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string size = getXmlAttributesValue(ui, "size", "1");
                        string top = getXmlAttributesValue(ui, "top", "0");
                        string bottom = getXmlAttributesValue(ui, "bottom", "100");
 
                        float topValue;
                        float bottomValue;
                        float size2;
                        float scrollPos;
 
                        if (!float.TryParse(size, out size2))
                            size2 = 1;
 
                        if (!float.TryParse(top, out topValue))
                            topValue = 0;
 
                        if (!float.TryParse(bottom, out bottomValue))
                            bottomValue = 100;
 
                        if (_uiFloatValue.ContainsKey(id))
                            scrollPos = _uiFloatValue[id];
                        else
                            scrollPos = 0;
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUI.VerticalScrollbar(position, scrollPos, size2, topValue, bottomValue);
                            else
                                _uiFloatValue[id] = GUI.VerticalScrollbar(position, scrollPos, size2, topValue, bottomValue, style2);
                        }
                        else
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUILayout.VerticalScrollbar(scrollPos, size2, topValue, bottomValue, layout2);
                            else
                                _uiFloatValue[id] = GUILayout.VerticalScrollbar(scrollPos, size2, topValue, bottomValue, style2, layout2);
                        }
                    }
                    break;
 
                case "verticalslider":
                    {
                        //TODO: VerticalSlider
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string top = getXmlAttributesValue(ui, "top", "0");
                        string bottom = getXmlAttributesValue(ui, "bottomt", "100");
 
                        float topValue;
                        float bottomValue;
                        float SliderValue = 0;
 
                        if (!float.TryParse(top, out topValue))
                            topValue = 0;
 
                        if (!float.TryParse(bottom, out bottomValue))
                            bottomValue = 100;
 
                        if (_uiFloatValue.ContainsKey(id))
                            SliderValue = _uiFloatValue[id];
 
                        GUIStyle thumb2 = null;
                        if (style2 != null)
                        {
                            string thumb = getXmlAttributesValue(ui, "thumb", string.Empty);
                            TryParseStyle("verticalSliderThumb", string.Empty, thumb, out thumb2);
                        }
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUI.VerticalSlider(position, SliderValue, topValue, bottomValue);
                            else
                                _uiFloatValue[id] = GUI.VerticalSlider(position, SliderValue, topValue, bottomValue, style2, thumb2);
                        }
                        else
                        {
                            if (style2 == null)
                                _uiFloatValue[id] = GUILayout.VerticalSlider(SliderValue, topValue, bottomValue, layout2);
                            else
                                _uiFloatValue[id] = GUILayout.VerticalSlider(SliderValue, topValue, bottomValue, style2, thumb2, layout2);
                        }
                    }
                    break;
 
                case "window":
                    {
                        //TODO: Window
                        if (IsExistId == false)
                        {
                            DebugOut(ui);
                            continue;
                        }
 
                        string depend = getXmlAttributesValue(ui, "depend", string.Empty);
                        if (!string.IsNullOrEmpty(depend))
                        {
                            if (_uiStrValue.ContainsKey(depend))
                            {
                                if (_uiStrValue[depend] != id)
                                    continue;
                            }
                        }
 
                        string func = getXmlAttributesValue(ui, "func", string.Empty);
                        GUI.WindowFunction func2;
                        if (!TryParseWindowFunction(func, out func2))
                            func2 = DefaultDoWindow;
 
                        if (useGUILayout == false)
                        {
                            if (style2 == null)
                                GUI.Window(_uiIdIndex, position, func2, content2);
                            else
                                GUI.Window(_uiIdIndex, position, func2, content2, style2);
                        }
                        else
                        {
                            string screenRect = getXmlAttributesValue(ui, "screenrect", string.Empty);
                            if (!TryParseRect(screenRect, out position))
                                position = new Rect(0, 0, Screen.width, Screen.height);
 
                            if (style2 == null)
                                GUILayout.Window(_uiIdIndex, position, func2, content2, layout2);
                            else
                                GUILayout.Window(_uiIdIndex, position, func2, content2, style2, layout2);
                        }                        
                    }
                    break;
            }
 
            if ((isFocus == true) && (IsExistId == true))
                GUI.FocusControl(id);
        }
    }
 
    private void ReInitForm()
    {
        _FromData.Clear();
 
        _uiTexture2D.Clear();
        _uiStyle.Clear();
 
        //UI相關變數暫存用
        _uiStrValue.Clear();
        _uiIntValue.Clear();
        _uiFloatValue.Clear();
        _uiVector2Value.Clear();
 
        _uiIdes.Clear();
        _uiIdIndex = 0;
    }
 
    private string getXmlAttributesValue(XmlNode node, string name, string defaultValue)
    {
        XmlAttribute attr = node.Attributes[name];
        if (attr != null)
            return attr.Value;
        else
            return defaultValue;
    }
 
    private bool TryParseGUILayoutOption(string src, out GUILayoutOption[] options)
    {
        if (string.IsNullOrEmpty(src))
        {
            options = new GUILayoutOption[0];
            return false;
        }
 
        string[] LayoutOptions = src.Split(new Char[] { ';' });
        IList<GUILayoutOption> temp = new List<GUILayoutOption>();
        string key, value;
 
        foreach (string str in LayoutOptions)
        {
            string[] s = str.Split(new Char[] { ':' });
 
            if (s.Length == 2)
            {
                key = s[0];
                value = s[1];
 
                switch (key)
                {
                    case "ExpandHeight":
                        {
                            bool expand;
                            if (bool.TryParse(value, out expand))
                                temp.Add(GUILayout.ExpandHeight(expand));
                        }
                        break;
 
                    case "ExpandWidth":
                        {
                            bool expand;
                            if (bool.TryParse(value, out expand))
                                temp.Add(GUILayout.ExpandWidth(expand));
                        }
                        break;
 
                    case "Height":
                        {
                            float height;
                            if (float.TryParse(value, out height))
                                temp.Add(GUILayout.Height(height));
                        }
                        break;
 
                    case "MaxHeight":
                        {
                            float maxHeight;
                            if (float.TryParse(value, out maxHeight))
                                temp.Add(GUILayout.MaxHeight(maxHeight));
                        }
                        break;
 
                    case "MaxWidth":
                        {
                            float maxWidth;
                            if (float.TryParse(value, out maxWidth))
                                temp.Add(GUILayout.MaxWidth(maxWidth));
                        }
                        break;
 
                    case "MinHeight":
                        {
                            float minHeight;
                            if (float.TryParse(value, out minHeight))
                                temp.Add(GUILayout.MinHeight(minHeight));
                        }
                        break;
 
                    case "MinWidth":
                        {
                            float minWidth;
                            if (float.TryParse(value, out minWidth))
                                temp.Add(GUILayout.MinWidth(minWidth));
                        }
                        break;
 
                    case "Width":
                        {
                            float width;
                            if (float.TryParse(value, out width))
                                temp.Add(GUILayout.Width(width));
                        }
                        break;
                }
            }
        }
 
        options = new GUILayoutOption[temp.Count];
        temp.CopyTo(options, 0);
        return true;
    }
 
    private bool TryParseOption(XmlNode node, out GUIContent[] option, out string[] values)
    {
        if ((node != null) && !node.HasChildNodes)
        {
            XmlNodeList uiList = node.ChildNodes;
            int count = uiList.Count;
            int index = 0;
 
            Texture2D image2;
 
            option = new GUIContent[count];
            values = new string[count];
 
            foreach (XmlNode ui in uiList)
            {
                string type = ui.Name;
                if (type == "option")
                {
                    string text = getXmlAttributesValue(ui, "text", string.Empty);
                    string image = getXmlAttributesValue(ui, "image", string.Empty);
                    string value = getXmlAttributesValue(ui, "value", string.Empty);
 
                    GUIContent content2 = new GUIContent();
 
                    if (!string.IsNullOrEmpty(image))
                    {
                        image2 = getTexture2D(image);
                        content2.image = image2;
                    }
 
                    if (!string.IsNullOrEmpty(text))
                        content2.text = text;
 
                    if (string.IsNullOrEmpty(value))
                        if (!string.IsNullOrEmpty(text))
                            value = text;
                        else if (!string.IsNullOrEmpty(image))
                            value = image;
                        else
                            value = "";
 
                    option[index] = content2;
                    values[index] = value;
 
                    index++;
                }
            }
            return true;
        }
 
        option = null;
        values = null;
        return false;
    }
 
    private bool TryParseScaleMode(string src, out ScaleMode scaleMode)
    {
        switch (src)
        {
            case "StretchToFill":
                scaleMode = ScaleMode.StretchToFill;
                break;
 
            case "ScaleAndCrop":
                scaleMode = ScaleMode.ScaleAndCrop;
                break;
 
            case "ScaleToFit":
                scaleMode = ScaleMode.ScaleToFit;
                break;
 
            default:
                scaleMode = ScaleMode.StretchToFill;
                return false;
        }
        return true;
    }
 
    private bool TryParseRect(string src, out Rect rect)
    {
        string[] num = src.Split(new Char[] { ',' });
        if (num.Length == 4)
        {
            float x, y, w, h;
            if (float.TryParse(num[0], out x) &&
                float.TryParse(num[1], out y) &&
                float.TryParse(num[2], out w) &&
                float.TryParse(num[3], out h))
            {
                rect = new Rect(x, y, w, h);
                return true;
            }
        }
        rect = new Rect();
        return false;
    }
 
    private bool TryParseVector2(string src, out Vector2 vec)
    {
        string[] num = src.Split(new Char[] { ',' });
        if (num.Length == 2)
        {
            float x, y;
            if (float.TryParse(num[0], out x) &&
                float.TryParse(num[1], out y))
            {
                vec = new Vector2(x, y);
                return true;
            }
        }
        vec = new Vector2();
        return false;
    }
 
    private bool TryParseRectOffset(string src, out RectOffset rectOffset)
    {
        string[] num = src.Split(new Char[] { ',' });
        if (num.Length == 4)
        {
            int left, right, top, bottom;
            if (int.TryParse(num[0], out left) &&
                int.TryParse(num[1], out right) &&
                int.TryParse(num[2], out top) &&
                int.TryParse(num[3], out bottom))
            {
                rectOffset = new RectOffset(left, right, top, bottom);
                return true;
            }
        }
        rectOffset = null;
        return false;
    }
 
    private bool TryParseTextAnchor(string src, out TextAnchor textAnchor)
    {
        switch (src)
        {
            case "UpperLeft":
                textAnchor = TextAnchor.UpperLeft;
                break;
 
            case "UpperCenter":
                textAnchor = TextAnchor.UpperCenter;
                break;
 
            case "UpperRight":
                textAnchor = TextAnchor.UpperRight;
                break;
 
            case "MiddleLeft":
                textAnchor = TextAnchor.MiddleLeft;
                break;
 
            case "MiddleCenter":
                textAnchor = TextAnchor.MiddleCenter;
                break;
 
            case "MiddleRight":
                textAnchor = TextAnchor.MiddleRight;
                break;
 
            case "LowerLeft":
                textAnchor = TextAnchor.LowerLeft;
                break;
 
            case "LowerCenter":
                textAnchor = TextAnchor.LowerCenter;
                break;
 
            case "LowerRight":
                textAnchor = TextAnchor.LowerRight;
                break;
 
            default:
                textAnchor = TextAnchor.UpperLeft;
                return false;
        }
        return true;
    }
 
    private bool TryParseTextClipping(string src, out TextClipping textClipping)
    {
        switch (src)
        {
            case "Overflow":
                textClipping = TextClipping.Overflow;
                break;
 
            case "Clip":
                textClipping = TextClipping.Clip;
                break;
 
            default:
                textClipping = TextClipping.Overflow;
                return false;
        }
        return true;
    }
 
    private bool TryParseWindowFunction(string src, out GUI.WindowFunction func2)
    {
        if (!string.IsNullOrEmpty(src))
        {
            Type thisType = this.GetType();
            MethodInfo theMethod = thisType.GetMethod(src, new Type[] { typeof(int) });
            if (theMethod != null)
            {
                Delegate test = Delegate.CreateDelegate(typeof(GUI.WindowFunction), this, theMethod, false);
                if (test != null)
                {
                    func2 = (GUI.WindowFunction)test;
                    return true;
                }
            }
        }
        func2 = null;
        return false;
    }
 
    private bool TryParseFontStyle(string src, out FontStyle fontStyle)
    {
        switch (src)
        {
            case "Bold":
                fontStyle = FontStyle.Bold;
                break;
 
            case "BoldAndItalic":
                fontStyle = FontStyle.BoldAndItalic;
                break;
 
            case "Italic":
                fontStyle = FontStyle.Italic;
                break;
 
            case "Normal":
                fontStyle = FontStyle.Normal;
                break;
 
            default:
                fontStyle = FontStyle.Normal;
                return false;
        }
        return true;
    }
 
    private bool TryParseImagePosition(string src, out ImagePosition imagePosition)
    {
        switch (src)
        {
            case "ImageLeft":
                imagePosition = ImagePosition.ImageLeft;
                break;
 
            case "ImageAbove":
                imagePosition = ImagePosition.ImageAbove;
                break;
 
            case "ImageOnly":
                imagePosition = ImagePosition.ImageOnly;
                break;
 
            case "TextOnly":
                imagePosition = ImagePosition.TextOnly;
                break;
 
            default:
                imagePosition = ImagePosition.ImageLeft;
                return false;
        }
        return true;
    }
 
    private bool TryParseStyleState(string src, out GUIStyleState styleState)
    {
        Color textColor;
        Texture2D background = null;
        string[] num = src.Split(new Char[] { ',' });
        if (num.Length == 5)
        {
            float r, g, b, a;
            if (float.TryParse(num[0], out r) &&
                float.TryParse(num[1], out g) &&
                float.TryParse(num[2], out b) &&
                float.TryParse(num[3], out a))
            {
                textColor = new Color(r, g, b, a);
 
                background = getTexture2D(num[4]);
 
                styleState = new GUIStyleState();
                styleState.textColor = textColor;
                styleState.background = background;
 
                return true;
            }
        }
        else if (num.Length == 4)
        {
            float r, g, b;
            if (float.TryParse(num[0], out r) &&
                float.TryParse(num[1], out g) &&
                float.TryParse(num[2], out b))
            {
                textColor = new Color(r, g, b);
 
                background = getTexture2D(num[3]);
 
                styleState = new GUIStyleState();
                styleState.textColor = textColor;
                styleState.background = background;
 
                return true;
            }
        }
 
        styleState = null;
        return false;
    }
 
    private Texture2D getTexture2D(string image)
    {
        Texture2D ret;
 
        if (_uiTexture2D.ContainsKey(image))
        {
            ret = _uiTexture2D[image];
        }
        else
        {
            string image2;
            Uri url = new Uri(_FormID2);
            if ((url.Scheme == "http") && (url.Scheme == "https"))
            {
                image2 = image;
            }
            else if (_FormID2[0] == '/')
            {
                image2 = (new Uri(BaseUri, image)).PathAndQuery;
            }
            else
            {
                //從用戶端讀取Texture檔
                ret = Resources.Load(image) as Texture2D;
                _uiTexture2D.Add(image, ret);
                return ret;
            }
 
            {
                //從WebServer端讀取Texture檔
                WWW http = new WWW(image2);
                WaitHttpComplete(ref http);
 
                if (http.error != null)
                {
                    DebugOut(http.error);
                    return null;
                }
 
                ret = http.texture;
 
                _uiTexture2D.Add(image, ret);
            }
        }
 
        return ret;
    }
 
    private void TryParseStyle(string type, string class2, string src, out GUIStyle style2)
    {
        if (!string.IsNullOrEmpty(class2))
            style2 = _uiStyle[class2];
        else if (!string.IsNullOrEmpty(type))
            style2 = new GUIStyle(GUI.skin.GetStyle(type));
        else
            style2 = new GUIStyle();
 
        if (string.IsNullOrEmpty(src))
            return;
 
        string[] style = src.Split(new Char[] { ';' });
 
        string key, value;
 
        foreach (string str in style)
        {
            string[] s = str.Split(new Char[] { ':' });
 
            if (s.Length == 2)
            {
                key = s[0].Trim();
                value = s[1].Trim();
 
                switch (key)
                {
                    case "active":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.active = styleState;
                        }
                        break;
 
                    case "alignment":
                        {
                            TextAnchor textAnchor;
                            if (TryParseTextAnchor(value, out textAnchor))
                                style2.alignment = textAnchor;
                        }
                        break;
 
                    case "border":
                        {
                            RectOffset rectOffset;
                            if (TryParseRectOffset(value, out rectOffset))
                                style2.border = rectOffset;
                        }
                        break;
 
                    case "clipping":
                        {
                            TextClipping textClipping;
                            if (TryParseTextClipping(value, out textClipping))
                                style2.clipping = textClipping;
                        }
                        break;
 
                    //過時功能
                    //case "clipOffset":
                    //    {
                    //        Vector2 vec;
                    //        TryParseVector2(value, out vec);
                    //        style2.clipOffset = vec;
                    //    }
                    //    break;
 
                    case "contentOffset":
                        {
                            Vector2 vec;
                            if (TryParseVector2(value, out vec))
                                style2.contentOffset = vec;
                        }
                        break;
 
                    case "fixedHeight":
                        {
                            float fixedHeight;
                            if (float.TryParse(value, out fixedHeight))
                                style2.fixedHeight = fixedHeight;
                        }
                        break;
 
                    case "fixedWidth":
                        {
                            float fixedWidth;
                            if (float.TryParse(value, out fixedWidth))
                                style2.fixedWidth = fixedWidth;
                        }
                        break;
 
                    case "focused":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.focused = styleState;
                        }
                        break;
 
                    case "font":
                        {
                            Font font = new Font(value);
                            style2.font = font;
                        }
                        break;
 
                    case "fontSize":
                        {
                            int fontSize;
                            if (int.TryParse(value, out fontSize))
                                style2.fontSize = fontSize;
                        }
                        break;
 
                    case "fontStyle":
                        {
                            FontStyle fontStyle;
                            if (TryParseFontStyle(value, out fontStyle))
                                style2.fontStyle = fontStyle;
                        }
                        break;
 
                    case "hover":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.hover = styleState;
                        }
                        break;
 
                    case "imagePosition":
                        {
                            ImagePosition imagePosition;
                            if (TryParseImagePosition(value, out imagePosition))
                                style2.imagePosition = imagePosition;
                        }
                        break;
 
                    case "margin":
                        {
                            RectOffset rectOffset;
                            if (TryParseRectOffset(value, out rectOffset))
                                style2.margin = rectOffset;
                        }
                        break;
 
                    case "normal":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.normal = styleState;
                        }
                        break;
 
                    case "onActive":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.onActive = styleState;
                        }
                        break;
 
                    case "onFocused":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.onFocused = styleState;
                        }
                        break;
 
                    case "onHover":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.onHover = styleState;
                        }
                        break;
 
                    case "onNormal":
                        {
                            GUIStyleState styleState;
                            if (TryParseStyleState(value, out styleState))
                                style2.onNormal = styleState;
                        }
                        break;
 
                    case "overflow":
                        {
                            RectOffset rectOffset;
                            if (TryParseRectOffset(value, out rectOffset))
                                style2.padding = rectOffset;
                        }
                        break;
 
                    case "padding":
                        {
                            RectOffset rectOffset;
                            if (TryParseRectOffset(value, out rectOffset))
                                style2.padding = rectOffset;
                        }
                        break;
 
                    case "richText":
                        {
                            bool richText;
                            if (bool.TryParse(value, out richText))
                                style2.richText = richText;
                        }
                        break;
 
                    case "stretchHeight":
                        {
                            bool stretchHeight;
                            if (bool.TryParse(value, out stretchHeight))
                                style2.stretchHeight = stretchHeight;
                        }
                        break;
 
                    case "stretchWidth":
                        {
                            bool stretchWidth;
                            if (bool.TryParse(value, out stretchWidth))
                                style2.stretchWidth = stretchWidth;
                        }
                        break;
 
                    case "wordWrap":
                        {
                            bool wordWrap;
                            if (bool.TryParse(value, out wordWrap))
                                style2.wordWrap = wordWrap;
                        }
                        break;
                }
            }
        }
    }
 
    private void onButtonClick(XmlNode node)
    {
        if (node != null)
        {
            string method = getXmlAttributesValue(node, "method", "");
            string action = getXmlAttributesValue(node, "action", "");
 
            if (!string.IsNullOrEmpty(method))
            {
                switch (method)
                {
                    case "browser":
                        Application.OpenURL(action);
                        break;
 
                    case "start":
                        startProcess(action, node);
                        break;
 
                    case "call":
                        callFunc(action, node);
                        break;
 
                    case "post":
                        if (string.IsNullOrEmpty(action))
                            xmlFormPost(action);
                        break;
 
                    case "reset":
                        _FormID2 = _FormID;
                        _FormID = "";
                        break;
 
                    case "redirect":
                        _FormID2 = action;
                        _FormID = "";
                        break;
 
                    case "quit":
                        Application.Quit();
                        break;
                }
            }
        }
    }
 
    private void callFunc(string action, XmlNode node)
    {
        if (!string.IsNullOrEmpty(action))
        {
            Type thisType = this.GetType();
            MethodInfo theMethod = thisType.GetMethod(action, new Type[] { typeof(XmlNode) });
            if (theMethod != null)
                theMethod.Invoke(this, new object[] { node });
        }
    }
 
    private void startProcess(string action, XmlNode node)
    {
 
 
        System.Diagnostics.Process Process = new System.Diagnostics.Process();
        try
        {
            Process.StartInfo.FileName = action;
 
            string arguments = getXmlAttributesValue(node, "arg", string.Empty);
            if (!string.IsNullOrEmpty(arguments))
                Process.StartInfo.Arguments = arguments;
 
            string ShellExecute = getXmlAttributesValue(node, "shellexecute", string.Empty);
            if (!string.IsNullOrEmpty(ShellExecute))
            {
                bool ShellExecute2;
                if (bool.TryParse(ShellExecute, out ShellExecute2))
                    Process.StartInfo.UseShellExecute = ShellExecute2;
            }
 
            string NoWindow = getXmlAttributesValue(node, "nowindow", string.Empty);
            if (!string.IsNullOrEmpty(NoWindow))
            {
                bool NoWindow2;
                if (bool.TryParse(NoWindow, out NoWindow2))
                    Process.StartInfo.CreateNoWindow = NoWindow2;
            }
 
            Process.Start();
        }
        catch (System.ComponentModel.Win32Exception ex)
        {
            DebugOut(ex.ToString());
        }
    }
 
    //private IEnumerator xmlFormPost(string strUrl)
    private void xmlFormPost(string strUrl)
    {
        //yield return new WaitForEndOfFrame();
 
        if (IsExistConfig == true)
        {
            var form = new WWWForm();
 
            foreach (string key in _FromData.Keys)
                form.AddField(key, _FromData[key]);
 
            string strUrl2;
            Uri url = new Uri(strUrl);
            if ((url.Scheme == "http") || (url.Scheme == "https"))
                strUrl2 = strUrl;
            else
                strUrl2 = (new Uri(BaseUri, strUrl)).PathAndQuery;
 
            var http = new WWW(strUrl2, form.data, _headers);
            WaitHttpComplete(ref http);
 
            if (http.error != null)
            {
                DebugOut(http.error);
                return;
            }
 
            string Location = http.responseHeaders["Location"];
            if (!string.IsNullOrEmpty(Location))
            {
                _FormID2 = Location;
            }
            else
            {
                _FormID = _FormID2 = "";
                _Document.LoadXml(http.text);
                ReInitForm();
            }
        }
    }
 
    private void DefaultDoWindow(int windowID)
    {
        string id2;
        if (_uiIdes.ContainsKey(windowID))
        {
            id2 = _uiIdes[windowID];
        }
        else
        {
            DebugOut(string.Format("id={0} is not exist at DefaultDoWindow(int windowID)", windowID));
            return;
        }
 
        XmlNode node = findXmlNode(id2);
        if (node != null)
        {
            TryParseXmlForm(node);
 
            bool isFocus = false;
            string Focus = getXmlAttributesValue(node, "focus", string.Empty);
            if (!string.IsNullOrEmpty(Focus))
                if (!bool.TryParse(Focus, out isFocus))
                    isFocus = false;
 
            if (isFocus == true)
                GUI.FocusWindow(windowID);
        }
    }
 
    private XmlNode findXmlNode(string id)
    {
        string find = "//*[@id='" + id + "']";
        XmlNodeList uiList = _Document.SelectNodes(find);
        foreach (XmlNode ui in uiList)
            return ui;
        return null;
    }
 
    public void loadConfig(XmlNode node = null)
    {
        FileInfo info = new FileInfo(UserConfigFile);
        if (info != null && info.Exists != false)
        {
            using (FileStream fs = new FileStream(UserConfigFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(fs);
                XmlReader reader = new XmlNodeReader(doc.DocumentElement);
                XmlSerializer serializer = new XmlSerializer(typeof(ConfigInfo));
                _Config = (ConfigInfo)serializer.Deserialize(reader);
                fs.Close();
            }
            _FormID2 = HomeUrl;
        }
    }
 
    public void saveConfig(XmlNode node)
    {
        //if (_FormID != "Config")
        //    return;
 
        //Get Config Value
        _Config.GroupID = _FromData["GroupID"];
        _Config.LoginID = _FromData["LoginID"];
        _Config.Password = _FromData["Password"];
 
        // Serialise to the XML document
        XmlDocument doc = new XmlDocument();
        using (XmlWriter writer = doc.CreateNavigator().AppendChild())
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ConfigInfo));
            serializer.Serialize(writer, _Config);
        }
 
        doc.Save(UserConfigFile);
 
        _FormID2 = HomeUrl;
    }
}

ConfigInfo.cs

using System;
using System.Xml;
using System.Xml.Serialization;
 
[XmlRoot("root")]
public class ConfigInfo {
	[XmlAttribute("GroupID")]
	public string GroupID = "";
 
	[XmlAttribute("LoginID")]
	public string LoginID = "";
 
	[XmlAttribute("Password")]
	public string Password = "";
}

AppScript.cs

using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
 
public class AppScript : MonoBehaviour
{
    private string _ConfigUrl = "/f1/Index";
    static public string _HomeUrl = "/f1/Home";
 
    private bool _isScaleAroundPivot;
    private Vector2 _baseSize;
    private Vector2 _scale;
 
    private Dictionary<string, XmlForm> _AllXmlForm;
 
 
    //當物件第一次進行初始化時
    private void Awake()
    {
        bool _IsExistConfig = false; 
        string _UserConfigFile;
        Uri _BaseUri = new Uri("http://app.player.idv.tw"); 
 
        _baseSize = new Vector2(640, 960);
        _scale = new Vector2((float)Screen.width / _baseSize.x, (float)Screen.height / _baseSize.y);
        _isScaleAroundPivot = (Screen.width < Screen.height);
 
        _UserConfigFile = Application.persistentDataPath + "/Config.xml";
        if (Path.DirectorySeparatorChar != '/')
            _UserConfigFile = _UserConfigFile.Replace('/', Path.DirectorySeparatorChar);
 
        _AllXmlForm = new Dictionary<string, XmlForm>();
 
        FileInfo info = new FileInfo(_UserConfigFile);
        if (info == null || info.Exists == false)
        {
            _IsExistConfig = false;
            _AllXmlForm.Add("", new XmlForm(_ConfigUrl));
        }
        else
        {
            _IsExistConfig = true;
            _AllXmlForm.Add("", new XmlForm(_HomeUrl));
        }
 
        XmlForm.IsExistConfig = _IsExistConfig;
        XmlForm.UserConfigFile = _UserConfigFile;
        XmlForm.BaseUri = _BaseUri;
        XmlForm.HomeUrl = _HomeUrl;
 
        foreach (KeyValuePair<string, XmlForm> item in _AllXmlForm)
        {
            item.Value.Awake();
        }
    }
 
    //在物件生命週期的第一幀中,並且在使用任何“Update”方法之前呼叫
    private void Start()
    {
 
    }
 
    // Update is called once per frame
    private void Update()
    {
        foreach (KeyValuePair<string, XmlForm> item in _AllXmlForm)
        {
            item.Value.Update();
        }
    }
 
    private void OnGUI()
    {
        if (_isScaleAroundPivot == true)
            GUIUtility.ScaleAroundPivot(_scale, Vector2.zero);
 
        foreach (KeyValuePair<string, XmlForm> item in _AllXmlForm)
        {
            item.Value.OnGUI();
        }
    }
}