Beispiel #1
0
        public ContentCachedTurretAssemblyPrefab(RootModel model)
        {
            TurretAssemblyAssembler assembler = new TurretAssemblyAssembler();
            GameObject instance = assembler.Assemble(model).gameObject;

            _cache = new SceneCachedGameObject(instance);
        }
Beispiel #2
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 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.");
        }
        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;
        }