예제 #1
0
    List <string> saveTextureAssets(string path)
    {
        List <string> textureAssetMetas = new List <string>();
        var           settings          = new JsonSerializerSettings {
            TypeNameHandling = TypeNameHandling.All
        };

        foreach (var gameTexture in gameTextures)
        {
            string textureFilePath = AssetDatabase.GetAssetPath(gameTexture.Value);
            string textureName     = Path.GetFileName(textureFilePath);

            var textureAssetMeta = new Game.MetaData();
            textureAssetMeta.type = "TextureAsset";
            textureAssetMeta.guid = gameTexture.Key;
            textureAssetMeta.path = "../Assets/Images/" + textureName;

            textureAssetMetas.Add(textureAssetMeta.path + ".meta");

            if (!savedAssets.Contains(gameTexture.Key))
            {
                // Save meta file for the texture asset
                var          jsonMeta = JsonConvert.SerializeObject(textureAssetMeta, settings);
                StreamWriter writer1  = new StreamWriter(path + "/Images/" + textureName + ".meta");
                writer1.Write(jsonMeta);
                writer1.Close();

                // Save the texture asset file
                try
                {
                    // Will not overwrite if the destination file already exists.
                    File.Copy(textureFilePath, path + "/Images/" + textureName, true);
                }
                catch (IOException copyError)
                {
                    Debug.LogError(copyError.Message);
                }

                if (!savedAssets.Contains(gameTexture.Key))
                {
                    savedAssets.Add(gameTexture.Key);
                }
            }
        }

        return(textureAssetMetas);
    }
예제 #2
0
    List <string> saveGamePrefabs(string path)
    {
        List <string> prefabMetas = new List <string>();
        var           settings    = new JsonSerializerSettings {
            TypeNameHandling = TypeNameHandling.All
        };

        int prefabNum = 0;

        foreach (var prefab in gamePrefabs)
        {
            //string prefabFileName = "prefab" + prefabNum.ToString() + "_" + prefab.Value.objectName;
            string prefabFileName = "prefab_" + prefab.Value.objectName;

            var prefabMeta = new Game.MetaData();
            prefabMeta.type = "PrefabAsset";
            prefabMeta.guid = prefab.Value.prefabGuid;
            prefabMeta.path = "../Assets/Prefabs/" + prefabFileName + ".prefab";

            prefabNum++;
            prefabMetas.Add("../Assets/Prefabs/" + prefabFileName + ".meta");

            if (!savedAssets.Contains(prefab.Key))
            {
                // Save meta file for the prefab
                var          jsonMeta = JsonConvert.SerializeObject(prefabMeta, settings);
                StreamWriter writer1  = new StreamWriter(path + "/Prefabs/" + prefabFileName + ".meta");
                writer1.Write(jsonMeta);
                writer1.Close();

                // Save the prefab file
                Game.GameObject gameObject = saveMapObject(prefab.Value, 1, 0, 0);
                var             jsonPrefab = JsonConvert.SerializeObject(gameObject, settings);
                StreamWriter    writer2    = new StreamWriter(path + "/Prefabs/" + prefabFileName + ".prefab");
                writer2.Write(jsonPrefab);
                writer2.Close();
            }
            if (!savedAssets.Contains(prefab.Key))
            {
                savedAssets.Add(prefab.Key);
            }
        }

        return(prefabMetas);
    }