Ejemplo n.º 1
0
        static public JsonOperationResult ExportPartial(UnityEngine.Component targetComp, JsonModifier jsonModifier)
        {
            // Conver target object to JSON object
            //   (It can take any System.Object as target)
            //   Conver to JSON string from
            string cmpJsonStr = JsonUtility.ToJson(targetComp, false);

            //   Convert to JSON object from JSON string
            SimpleJSON.JSONNode cmpJsonObj = SimpleJSON.JSON.Parse(cmpJsonStr);

            // Prepare export JSON object from template JSON string
            string expJsonTemplate = "{\"format\":\"" + jsonFormatName_partialObject + "\", objectType:null, \"hint\":{}, \"data\":{}";

            SimpleJSON.JSONNode expJsonObj = SimpleJSON.JSON.Parse(expJsonTemplate);

            // Add meta info to export JSON object
            expJsonObj["hint"].Add("PlayerSettings.productName", PlayerSettings.productName);
            var scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();

            expJsonObj["hint"].Add("scene.name", scene.name);
            expJsonObj["hint"].Add("scene.path", scene.path);
            expJsonObj["hint"].Add("objectPath", IwsdSubInspectorWindow.GetGameObjectPath(targetComp.gameObject));
            expJsonObj["hint"].Add("created", DateTime.UtcNow.ToString("o"));
            expJsonObj.Add("objectType", targetComp.GetType().FullName); // specify type by full name

            // Copy partial elements from target JSON object to export JSON object
            JsonOperationResult r = jsonModifier(cmpJsonObj, expJsonObj);

            // Convert to portable string (from export JSON object to JSON string)
            r.Output = expJsonObj.ToString();

            return(r);

            // TODO use EditorJsonUtility
        }
Ejemplo n.º 2
0
        static int _m_Add(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                SimpleJSON.JSONNode gen_to_be_invoked = (SimpleJSON.JSONNode)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && translator.Assignable <SimpleJSON.JSONNode>(L, 2))
                {
                    SimpleJSON.JSONNode _aItem = (SimpleJSON.JSONNode)translator.GetObject(L, 2, typeof(SimpleJSON.JSONNode));

                    gen_to_be_invoked.Add(_aItem);



                    return(0);
                }
                if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <SimpleJSON.JSONNode>(L, 3))
                {
                    string _aKey = LuaAPI.lua_tostring(L, 2);
                    SimpleJSON.JSONNode _aItem = (SimpleJSON.JSONNode)translator.GetObject(L, 3, typeof(SimpleJSON.JSONNode));

                    gen_to_be_invoked.Add(_aKey, _aItem);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to SimpleJSON.JSONNode.Add!"));
        }