示例#1
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());
        }