示例#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());
                    }
                }
            }
        }
示例#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");
            }
        }
示例#3
0
        public static void CreateAudioSample(AudioClip audioClip)
        {
            SoundToolKitDebug.Assert(audioClip != null, "AudioClip is null");

            var soundToolKitSamples = AssetManager.FindAssets <SoundToolKitSample>();

            var audioSample = soundToolKitSamples.FirstOrDefault(x => x.name == audioClip.name);

            if (audioSample == null)
            {
                if (!AssetDatabase.IsValidFolder(AUDIO_SAMPLES_PATH))
                {
                    AssetDatabase.CreateFolder(AUDIO_SAMPLES_PARENT_PATH, AUDIO_SAMPLES_FOLDER_NAME);
                }

                audioSample = ScriptableObjectUtility.CreateAsset <SoundToolKitSample>(AUDIO_SAMPLES_PATH, audioClip.name);
            }

            audioSample.AudioClip = audioClip;

            EditorUtility.SetDirty(audioSample);

            Debug.Log("[SoundToolKit] AudioClip has been added; AudioSample: " + audioClip.name + " has been created in AudioSamples folder.");
        }
示例#4
0
        public static void SynchronzeDefaultMeshCluster()
        {
            var geometrySceneObject = Object.FindObjectOfType <SoundToolKitGeometry>();

            if (geometrySceneObject != null)
            {
                geometrySceneObject.MeshClusters.ForEach(x =>
                {
                    if (x == null)
                    {
                        geometrySceneObject.MeshClusters.Remove(x);
                    }
                });

                var oldDefaultCluster = geometrySceneObject.MeshClusters.FirstOrDefault(x => x.name == DefaultSceneClusterName());
                if (oldDefaultCluster)
                {
                    GetCorrespondingMeshes(oldDefaultCluster).ForEach(x =>
                    {
                        if (x != null)
                        {
                            x.MeshCluster = null;
                        }
                    });

                    geometrySceneObject.MeshClusters.Remove(oldDefaultCluster);
                }
            }
            else
            {
                PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath(GEOMETRY_PREFAB_PATH, typeof(GameObject)));
                geometrySceneObject = Object.FindObjectOfType <SoundToolKitGeometry>();

                if (geometrySceneObject == null)
                {
                    SoundToolKitDebug.LogWarning("SoundToolKitGeometry prefab failed to instantiate automatically.");
                }
                else
                {
                    EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
                }
            }

            var cluster = GetDefaultMeshCluster();
            var meshes  = Object.FindObjectsOfType <SoundToolKitMesh>();

            foreach (var mesh in meshes)
            {
                if (mesh.MeshCluster != null && mesh.MeshCluster.name == DefaultSceneClusterName())
                {
                    mesh.MeshCluster = null;
                }
            }

            foreach (var mesh in meshes)
            {
                if (mesh.MeshCluster == null)
                {
                    mesh.MeshCluster = cluster;
                }
            }

            if (geometrySceneObject != null)
            {
                geometrySceneObject.MeshClusters.Add(cluster);
                EditorUtility.SetDirty(geometrySceneObject);
            }

            EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
        }