有一个基类 - AudioPlayer 和两个继承自它:SoundPlayer 和 MusicPlayer。
音频播放器:
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class AudioPlayer : Singleton<AudioPlayer>
{
protected AudioSource _source;
protected partial void Awake()
{
_source = GetComponent<AudioSource>();
}
}
声音播放器:
using UnityEngine;
public class SoundPlayer : AudioPlayer
{
private void Awake()
{
Debug.Log("AWAKE!");
}
}
如何使 Awake() 方法保持在 AudioPlayer 中的状态,但同时我可以在继承的类中声明它。从而重新定义它们,但不改变基类中方法的指令。