Ejemplo n.º 1
0
        public static void MakeMeshNamesUnique()
        {
            var meshes = Object.FindObjectsOfType <SoundToolKitMesh>().ToList();

            foreach (var meshesWithSameCluster in meshes.GroupBy(x => x.MeshCluster))
            {
                var nameList = new List <string>();
                foreach (var mesh in meshesWithSameCluster)
                {
                    if (!nameList.Contains(mesh.CombinedName()))
                    {
                        nameList.Add(mesh.CombinedName());
                    }
                    else
                    {
                        var originalName = mesh.gameObject.name;

                        while (nameList.Contains(mesh.CombinedName()))
                        {
                            mesh.gameObject.name += "'";
                        }

                        SoundToolKitDebug.Log("Mesh: " + originalName + " renamed to: " + mesh.gameObject.name);

                        EditorUtility.SetDirty(mesh.gameObject);
                        EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());

                        nameList.Add(mesh.CombinedName());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void SerializeToFile(SoundToolKitMaterial material)
        {
            if (SoundToolKitManager.Instance != null && material != null)
            {
                // Create json file with serialized material
                var customJsonDirectory = Path.Combine(Path.Combine(Application.streamingAssetsPath, SOUNDTOOLKIT_JSON_MATERIALS_PATH), "Custom");
                Directory.CreateDirectory(customJsonDirectory);
                var name = "Custom " + material.name;

                var serializedData = SoundToolKit.Extensions.Scene.MaterialsSerializer.Serialize(SoundToolKitManager.Instance.StkAudioEngine, material.GetStkMaterial());

                customJsonDirectory = Path.Combine(customJsonDirectory, name);
                customJsonDirectory = Path.ChangeExtension(customJsonDirectory, ".json");

                File.WriteAllText(customJsonDirectory, serializedData);

                // Create SoundToolKitMaterial Asset from a newly serialized material
                var directoryRelativeToRoot = Path.GetDirectoryName(customJsonDirectory.Substring(
                                                                        customJsonDirectory.IndexOf(MATERIAL_DIRECTORY) + MATERIAL_DIRECTORY.Length));

                var materialDirectory = Path.Combine(SOUNDTOOLKIT_MATERIALS_PATH, directoryRelativeToRoot);

                var relativeJsonPath = customJsonDirectory.Substring(
                    customJsonDirectory.IndexOf(SOUNDTOOLKIT_JSON_MATERIALS_PATH));

                Directory.CreateDirectory(materialDirectory);
                CreateAcousticMaterial(materialDirectory, relativeJsonPath);

                SoundToolKitDebug.Log(name + " SoundToolKitMaterial successfully created. " +
                                      "Corresponding Material config file available in StreamingAssets/SoundToolKit/Materials/Custom");
            }
        }