Esempio 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
        }
Esempio n. 2
0
        private void ImportToTail(string importString, VRCSDK2.VRC_Trigger triggerComp)
        {
            JsonOperationResult r = JsonTools.ImportPartial_VRC_Trigger_Trigger(importString, triggerComp);

            OpResultType    = r.Type;
            OpResultMessage = r.Message;
        }
Esempio n. 3
0
        private string ExportSelected(VRCSDK2.VRC_Trigger triggerComp)
        {
            JsonOperationResult r = JsonTools.ExportPartial_VRC_Trigger_Trigger(triggerComp, UserSelects);

            OpResultType    = r.Type;
            OpResultMessage = r.Message;
            return(r.Output);
        }
Esempio n. 4
0
        static public JsonOperationResult ImportPartial(string importString, UnityEngine.Component targetComp, JsonModifier jsonModifier)
        {
            // Parse importing JSON string to JSON object
            SimpleJSON.JSONNode expJsonObj;
            try
            {
                expJsonObj = SimpleJSON.JSON.Parse(importString);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return(new JsonOperationResult(MessageType.Warning, "not appropriate data"));
            }

            // Check format
            if ((expJsonObj["format"] != jsonFormatName_partialObject) ||
                (expJsonObj["objectType"] != targetComp.GetType().FullName))
            {
                return(new JsonOperationResult(MessageType.Error, "Unknown or unsupported format data"));
            }

            // Convert target object to JSON object
            //   Convert to JSON string
            var cmpJsonStr = JsonUtility.ToJson(targetComp, false);
            //   Convert to JSON object
            var cmpJsonObj = SimpleJSON.JSON.Parse(cmpJsonStr);

            JsonOperationResult r = jsonModifier(cmpJsonObj, expJsonObj);

            // Modify target object
            //   Convert modified target object to JSON string
            string modified = cmpJsonObj.ToString();

            //   Load/merge from JSON string
            Undo.RecordObject(targetComp, "Paste to VRC_Trigger");
            JsonUtility.FromJsonOverwrite(modified, targetComp);

            return(r);
        }