Exemplo n.º 1
0
    public static string CreateJson(GameObject obj, string jsonDataName, string ParentPath)
    {
        //  My_UIEditorToos.InitProgress(obj.transform.GetChildCount());

        JsonData jd = new JsonData();
        JsonData RootpositionJson  = new JsonData();
        JsonData RootsizeDeltaJson = new JsonData();
        JsonData jd2 = new JsonData();
        int      i   = 0;

        foreach (Transform item in obj.transform)
        {
            JsonData tmp           = new JsonData();
            JsonData TransformJson = new JsonData();
            JsonData positionJson  = new JsonData();
            JsonData sizeDeltaJson = new JsonData();
            i++;
            tmp["PrefabName"]  = item.name;
            positionJson["x"]  = item.GetComponent <RectTransform>().localPosition.x;
            positionJson["y"]  = item.GetComponent <RectTransform>().localPosition.y;
            positionJson["z"]  = item.GetComponent <RectTransform>().localPosition.z;
            sizeDeltaJson["w"] = item.GetComponent <RectTransform>().sizeDelta.x;
            sizeDeltaJson["h"] = item.GetComponent <RectTransform>().sizeDelta.y;
            tmp["position"]    = positionJson;
            tmp["sizeDelta"]   = sizeDeltaJson;
            if (item.GetComponent <UIAnimation>() != null)
            {
                tmp["AnimationType"] = item.GetComponent <UIAnimation>().AnimationType;
                tmp["ScriptType"]    = item.GetComponent <UIAnimation>().ScriptType;
                tmp["Direction"]     = item.GetComponent <UIAnimation>().direction.ToString();
            }
            if (item.GetComponent <SUIButton>() != null)
            {
                string s = item.GetComponent <SUIButton>().m_ButtonMsg.ToString();
                tmp["ButtonEvent"] = "" + s;
            }
            else
            {
                tmp["ButtonEvent"] = "";
            }
            jd2.Add(tmp);
            //  My_UIEditorToos.Progress();
            MyParent.make(item.gameObject, "Assets/Resources/UI/" + ParentPath + "/" + item.name + ".prefab");
        }
        RootpositionJson["x"]  = obj.GetComponent <RectTransform>().localPosition.x;
        RootpositionJson["y"]  = obj.GetComponent <RectTransform>().localPosition.y;
        RootpositionJson["z"]  = obj.GetComponent <RectTransform>().localPosition.z;
        RootsizeDeltaJson["w"] = obj.GetComponent <RectTransform>().sizeDelta.x;
        RootsizeDeltaJson["h"] = obj.GetComponent <RectTransform>().sizeDelta.y;
        jd["parentURL"]        = ParentPath;
        jd["Name"]             = obj.name;
        jd["position"]         = RootpositionJson;
        jd["sizeDelta"]        = RootsizeDeltaJson;
        jd["Child"]            = jd2;
        Debug.Log(jd.ToJson());
        string filepath = Application.dataPath + "/Resources";

        My_UIEditorToos.CreateFile(filepath, jsonDataName, jd);
        return(filepath);
    }