public object Load(string path, Type type)
        {
            string json   = File.ReadAllText(path);
            var    jtoken = JToken.Parse(json);

            return(ObjectPipeline.BuildObject(jtoken, type));
        }
        public static void Save(PlayerProfile profile)
        {
            JToken json = ObjectPipeline.UnbuildObject(profile, true);

            Directory.CreateDirectory(ProfileFolder);
            File.WriteAllText(GetPath(profile.Name), json.ToString());
        }
示例#3
0
        public object Load(string path, Type type)
        {
            var data  = DataSerialization.FromFile(path);
            var model = ObjectPipeline.DeserializeObject(data);

            return(new ContentCachedTurretAssemblyPrefab(model));
        }
示例#4
0
    private void Disassemble()
    {
        GameObjectAssembler     _assembler         = new GameObjectAssembler();
        TurretAssemblyAssembler _assemblyAssembler = new TurretAssemblyAssembler();

        string path = Paths.StreamingAssets;
        string name = string.Empty;
        string data = "";

        switch (Type)
        {
        case TargetType.Assembly:
            data = ObjectPipeline.SerializeObject(_assemblyAssembler.Disassemble((Object as GameObject).GetComponent <TurretAssembly>())).ToString();
            name = Object.name;
            break;

        case TargetType.GameObject:
            data = ObjectPipeline.SerializeObject(_assembler.Disassemble(Object as GameObject)).ToString();
            name = Object.name;
            break;

        case TargetType.Object:
            data = ObjectPipeline.UnbuildObject(Object == null ? Activator.CreateInstance(ReflectionUtils.GetType(_objectTypeName)) : Object, Implicit).ToString();
            name = Object == null?_objectTypeName.Replace(".", "") : Object.name;

            break;
        }

        path = path + Path + name + ".json";


        File.WriteAllText(path, data);
    }
        public IContentPack Load(string path)
        {
            ContentPackInfo info    = new ContentPackInfo();
            Texture2D       texture = new Texture2D(2, 2);

            try
            {
                JToken data = DataSerialization.FromFile(Path.Combine(path, ABOUT_FILE));
                info = ObjectPipeline.BuildObject <ContentPackInfo>(data);

                if (File.Exists(Path.Combine(path, IMAGE_FILE)))
                {
                    texture.LoadImage(File.ReadAllBytes(Path.Combine(path, IMAGE_FILE)));
                    texture.filterMode = FilterMode.Point; // TODO: Allow content packs to decide this individually.
                }
                else
                {
                    texture = null;
                }
            }
            catch (FileNotFoundException)
            {
                info.Name        = Path.GetFileName(path);
                info.Author      = "Unknown Author";
                info.Version     = "Unknown Version";
                info.Description = "Unknown Description";

                File.WriteAllText(Path.Combine(path, ABOUT_FILE), ObjectPipeline.UnbuildObject(info, true).ToString());
            }

            return(new ContentPack(path + "/", info.Name, info.Author, info.Description, info.Version, texture));
        }
        public static void SaveFile(string path, TurretAssembly assembly)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            TurretAssemblyAssembler assembler = new TurretAssemblyAssembler();
            var model = assembler.Disassemble(assembly);

            File.WriteAllText(path, ObjectPipeline.SerializeObject(model).ToString());
            Alert.Open("Assembly has been saved.");
        }
        private void LoadFile(string file)
        {
            JObject obj = JObject.Parse(File.ReadAllText(file));

            MapData = ObjectPipeline.BuildObject <MapData>(obj);

            _mapController.IfExists(x => x.ApplyMapData(MapData));

            NameInput.text        = MapData.Name;
            DescriptionInput.text = MapData.Description;
        }
 public static PlayerProfile Load(string profileName)
 {
     try
     {
         JToken json = JToken.Parse(File.ReadAllText(GetPath(profileName)));
         return(ObjectPipeline.BuildObject <PlayerProfile>(json));
     }
     catch
     {
         return(null);
     }
 }
        public IEnumerable <KeyValuePair <string, string> > GetTranslations(string cultureName)
        {
            string file = Path.Combine(_path, cultureName) + ".json";

            if (File.Exists(file))
            {
                JToken           token = JToken.Parse(File.ReadAllText(file));
                LocalizationData data  = ObjectPipeline.BuildObject <LocalizationData>(token);

                foreach (var pair in data)
                {
                    yield return(pair);
                }
            }
        }
示例#10
0
        public PlayerProfile[] LoadProfiles()
        {
            if (!Directory.Exists(ProfileManager.ProfileFolder))
            {
                Directory.CreateDirectory(ProfileManager.ProfileFolder);
            }

            string[]        files    = Directory.GetFiles(ProfileManager.ProfileFolder);
            PlayerProfile[] profiles = new PlayerProfile[files.Length];

            for (int i = 0; i < files.Length; i++)
            {
                JObject obj = JObject.Parse(File.ReadAllText(files[i]));
                profiles[i] = ObjectPipeline.BuildObject <PlayerProfile>(obj);
            }

            return(profiles);
        }
示例#11
0
    private void Assemble()
    {
        GameObjectAssembler _assembler = new GameObjectAssembler();

        string path = Paths.StreamingAssets;

        path += Path;

        JToken data = JToken.Parse(File.ReadAllText(path));

        switch (Type)
        {
        case TargetType.GameObject:
            _assembler.Assemble(ObjectPipeline.DeserializeObject(data)).SetActive(true);
            break;
        }

        Debug.Log(path);
    }
        public static void CompileAsset(string guid, string targetPath, CompilationType type, bool implicitType)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);
            string directory = Directory.GetParent(targetPath).FullName;

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (type == CompilationType.Copy)
            {
                File.Copy(assetPath, targetPath, true);
                return;
            }

            object asset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(Object));
            JToken json;

            switch (type)
            {
            case CompilationType.SerializeGameObject:
                GameObjectAssembler assembler = new GameObjectAssembler();
                RootModel           model     = assembler.Disassemble(asset as GameObject);
                json = ObjectPipeline.SerializeObject(model);
                break;

            case CompilationType.SerializeAssembly:
                TurretAssemblyAssembler tAssembler = new TurretAssemblyAssembler();
                RootModel tModel = tAssembler.Disassemble((asset as GameObject).GetComponent <TurretAssembly>());
                json = ObjectPipeline.SerializeObject(tModel);
                break;

            case CompilationType.SerializeObject:

            default:
                json = ObjectPipeline.UnbuildObject(asset, implicitType);
                break;
            }

            File.WriteAllText(Path.ChangeExtension(targetPath, ".json"), json.ToString());
        }
        private void LoadFile(string path)
        {
            if (CurrentAsssembly)
            {
                DeleteCurrentAssembly();
            }

            var json  = JObject.Parse(File.ReadAllText(path));
            var model = ObjectPipeline.DeserializeObject(json);

            TurretAssemblyAssembler assembler = new TurretAssemblyAssembler();

            CurrentAsssembly = assembler.Assemble(model);

            if (CurrentAsssembly is Component comp)
            {
                comp.transform.position = Vector3.zero;
                comp.transform.rotation = Quaternion.identity;
            }

            NameText.text        = CurrentAsssembly.Name;
            DescriptionText.text = CurrentAsssembly.Description;
        }