Esempio n. 1
0
    public override void GenerateUI()
    {
        StringBuilder init = new StringBuilder();
        ComponentInfo info = GetComponentInfo();
        string        gameObjectInitTemplate = "    0} = transform:Find(\"{1}\").gameObject;\n";
        string        transformInitTemplate  = "    {0} = transform:Find(\"{1}\");\n";
        string        componentInitTemplate  = "    {0} = transform:Find(\"{1}\"):GetComponent(\"{2}\");\n";

        foreach (Transform tran in GetChildrenTransform())
        {
            string name = tran.name;
            string tag  = tran.gameObject.tag;

            if (CheckTag(tag))
            {
                CheckPrefabName(name);
                if (tag == TagType.UI_Button)
                {
                    init.Append(string.Format(componentInitTemplate, name, GetHierarchy(tran), info.GetButton()));
                }
                else if (tag == TagType.UI_GameObject)
                {
                    init.Append(string.Format(gameObjectInitTemplate, name, GetHierarchy(tran)));
                }
                else if (tag == TagType.UI_Lable)
                {
                    init.Append(string.Format(componentInitTemplate, name, GetHierarchy(tran), info.GetLable()));
                }
                else if (tag == TagType.UI_Sprite)
                {
                    init.Append(string.Format(componentInitTemplate, name, GetHierarchy(tran), info.GetSprite()));
                }
                else if (tag == TagType.UI_Texture)
                {
                    init.Append(string.Format(componentInitTemplate, name, GetHierarchy(tran), info.GetTexture()));
                }
                else if (tag == TagType.UI_Toggle)
                {
                    init.Append(string.Format(componentInitTemplate, name, GetHierarchy(tran), info.GetToggle()));
                }
                else if (tag == TagType.UI_Transform)
                {
                    init.Append(string.Format(transformInitTemplate, name, GetHierarchy(tran)));
                }
            }
        }

        content = ReadTemplateString();
        content = content.Replace("{#class#}", GetClassName());
        content = content.Replace("{#init#}", init.ToString());
        SaveFile();
    }