Ejemplo n.º 1
0
    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());
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    void Awake()
    {
//        Debug.Log("The audio caller is waking up");

        if (_instance != null)
        {
            Debug.LogError("There is more than one AudioCaller fix this!");
            return;
        }
        _instance = this;
    }
Ejemplo n.º 4
0
    private void RePopulate()
    {
        if (_instance == null)
        {
            _instance = this;
        }

        _audioObjects = new Dictionary <string, AudioObject>();

        foreach (AudioObject audio in GetAllInstances <AudioObject>())
        {
            _audioObjects.Add(audio.name, audio);
        }
    }
    public override void OnInspectorGUI()
    {
        AudioCaller v_controller = target as AudioCaller;

        v_controller.Clip = EditorGUILayout.ObjectField("Clip", v_controller.Clip, typeof(AudioClip), false) as AudioClip;

        v_controller.SoundPlayerOption  = (SoundTriggerEnum)EditorGUILayout.EnumPopup("Sound Player Option", v_controller.SoundPlayerOption);
        v_controller.SoundStopperOption = (SoundTriggerEnum)EditorGUILayout.EnumPopup("Sound Stopper Option", v_controller.SoundStopperOption);
        v_controller.CanPlayInFade      = EditorGUILayout.Toggle("Can Play In Fade", v_controller.CanPlayInFade);
        v_controller.IsBackgroundMusic  = EditorGUILayout.Toggle("Is Background Music", v_controller.IsBackgroundMusic);
        if (!v_controller.IsBackgroundMusic)
        {
            v_controller.Loop = EditorGUILayout.Toggle("Loop", v_controller.Loop);
            v_controller.OneSoundOfThisTypeOnly = EditorGUILayout.Toggle("One Sound Of This Type Only", v_controller.OneSoundOfThisTypeOnly);
            v_controller.SpartialBlend          = EditorGUILayout.Slider("SpartialBlend", v_controller.SpartialBlend, 0, 1);
        }


        if (GUI.changed)
        {
            EditorUtility.SetDirty(v_controller);
        }
    }