// ================================================================================= // Import // --------------------------------------------------------------------------------- public static bool Import(iCS_VisualScriptData storage, string path) { // -- Decode JSON string. -- JObject root = JSONFile.Read(path); if (root == null || root.isNull) { Debug.LogWarning("iCanScript: Import failure: JSON file corrupted."); return(false); } // -- Extract version information. -- var cache = new iCS_VisualScriptData(); JNumber majorVersion = root.GetValueFor("Storage.MajorVersion") as JNumber; JNumber minorVersion = root.GetValueFor("Storage.MinorVersion") as JNumber; JNumber bugFixVersion = root.GetValueFor("Storage.BugFixVersion") as JNumber; cache.MajorVersion = (int)majorVersion.value; cache.MinorVersion = (int)minorVersion.value; cache.BugFixVersion = (int)bugFixVersion.value; // -- Extract visual script attributes. -- JBool isEditorScript = root.GetValueFor("Storage.IsEditorScript") as JBool; JString csharpFileName = root.GetValueFor("Storage.CSharpFileName") as JString; JBool baseTypeOverride = root.GetValueFor("Storage.BaseTypeOverride") as JBool; JString baseType = root.GetValueFor("Storage.BaseType") as JString; JString sourceFileGUID = root.GetValueFor("Storage.SourceFileGUID") as JString; cache.IsEditorScript = isEditorScript.value; cache.CSharpFileName = csharpFileName.value; cache.BaseTypeOverride = baseTypeOverride.value; cache.BaseType = baseType.value; cache.SourceFileGUID = sourceFileGUID.value; // -- Extract engine objects. -- JArray engineObjects = root.GetValueFor("Storage.EngineObjects") as JArray; if (engineObjects == null) { Debug.LogWarning("iCanScript: Import failure: Unable to locate engine array."); return(false); } cache.EngineObjects.Capacity = engineObjects.value.Length; foreach (var eobj in engineObjects.value) { var newObj = ReadEngineObject(eobj as JObject); if (newObj != null) { cache.EngineObjects.Add(newObj); } else { Debug.LogWarning("iCanScript: Unable to create instance of iCS_EngineObject"); } } cache.CopyTo(storage); return(true); }
// ================================================================================= /// Load the package file from disk. /// /// @param absolutePath The absolute path of the project file. /// @info The active project set to the newly loaded project. /// public static PackageInfo Load(string absolutePath, bool declareError = false) { var jsonRoot = JSONFile.Read(absolutePath); if (jsonRoot == null || jsonRoot.isNull) { if (declareError) { Debug.LogError("iCanScript: Unable to load package at=> " + absolutePath); } return(null); } return(Load(jsonRoot)); }