架构大更
This commit is contained in:
@@ -6,49 +6,44 @@ using UnityEditor;
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// This class will automatically destroy the object when entering play mode, and will destroy it again when exiting play mode.
|
||||
/// This is used for instance by the sound feedbacks to ensure that test audio sources created outside of play mode don't persist in your scene
|
||||
/// This class will automatically destroy the object when entering play mode, and will destroy it again when exiting
|
||||
/// play mode.
|
||||
/// This is used for instance by the sound feedbacks to ensure that test audio sources created outside of play mode
|
||||
/// don't persist in your scene
|
||||
/// </summary>
|
||||
public class MMForceDestroyInPlayMode : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
static MMForceDestroyInPlayMode()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += ModeChanged;
|
||||
}
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
if (Application.isPlaying) Delete();
|
||||
}
|
||||
|
||||
private static void ModeChanged(PlayModeStateChange playModeState)
|
||||
{
|
||||
switch (playModeState)
|
||||
{
|
||||
case PlayModeStateChange.EnteredEditMode:
|
||||
DeleteAll();
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void Delete()
|
||||
{
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
static MMForceDestroyInPlayMode()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += ModeChanged;
|
||||
}
|
||||
|
||||
static void DeleteAll()
|
||||
{
|
||||
MMForceDestroyInPlayMode[] sounds = FindObjectsByType<MMForceDestroyInPlayMode>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
foreach (var sound in sounds)
|
||||
{
|
||||
sound.Delete();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
Delete();
|
||||
}
|
||||
}
|
||||
|
||||
void Delete()
|
||||
{
|
||||
DestroyImmediate(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void ModeChanged(PlayModeStateChange playModeState)
|
||||
{
|
||||
switch (playModeState)
|
||||
{
|
||||
case PlayModeStateChange.EnteredEditMode:
|
||||
DeleteAll();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void DeleteAll()
|
||||
{
|
||||
var sounds =
|
||||
FindObjectsByType<MMForceDestroyInPlayMode>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
foreach (var sound in sounds) sound.Delete();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple struct used to store information about the sounds played by the MMSoundManager
|
||||
/// A simple struct used to store information about the sounds played by the MMSoundManager
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct MMSoundManagerSound
|
||||
{
|
||||
/// the ID of the sound
|
||||
public int ID;
|
||||
/// the track the sound is being played on
|
||||
public MMSoundManager.MMSoundManagerTracks Track;
|
||||
/// the associated audiosource
|
||||
public AudioSource Source;
|
||||
/// whether or not this sound will play over multiple scenes
|
||||
public bool Persistent;
|
||||
public struct MMSoundManagerSound
|
||||
{
|
||||
/// the ID of the sound
|
||||
public int ID;
|
||||
|
||||
public float PlaybackTime;
|
||||
public float PlaybackDuration;
|
||||
}
|
||||
/// the track the sound is being played on
|
||||
public MMSoundManager.MMSoundManagerTracks Track;
|
||||
|
||||
/// the associated audiosource
|
||||
public AudioSource Source;
|
||||
|
||||
/// whether or not this sound will play over multiple scenes
|
||||
public bool Persistent;
|
||||
|
||||
public float PlaybackTime;
|
||||
public float PlaybackDuration;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user