public static AudioCaller CreateAsset() { _instance = ScriptableObject.CreateInstance <AudioCaller>(); string path = UnityEditor.AssetDatabase.GetAssetPath(UnityEditor.Selection.activeObject); if (path == "") { path = "Assets"; } else if (System.IO.Path.GetExtension(path) != "") { path = path.Replace(System.IO.Path.GetFileName(UnityEditor.AssetDatabase.GetAssetPath(UnityEditor.Selection.activeObject)), ""); } string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(path + "/Resources/" + "TheAudioCaller" + ".asset"); UnityEditor.AssetDatabase.CreateAsset(_instance, assetPathAndName); UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.AssetDatabase.Refresh(); UnityEditor.EditorUtility.FocusProjectWindow(); UnityEditor.Selection.activeObject = _instance; _audioObjects = new Dictionary <string, AudioObject>(); _instance.RePopulate(); return(_instance); }
public static SoundKraft.AudioController PlayAudioByName(string name) { if (_instance == null) { _instance = Resources.Load("TheAudioCaller") as AudioCaller; } #if UNITY_EDITOR if (_instance == null) { _instance = CreateAsset(); return(null); } if (_audioObjects == null || !_audioObjects.ContainsKey(name)) { _instance.RePopulate(); } #endif if (!_audioObjects.ContainsKey(name)) { Debug.LogError("There is no audio by the name " + name + " in the audio caller"); return(null); } return(_audioObjects[name].Play()); }