-
-
Save omizumotimoti/6478e529d1cd06d16680a9e743cbaac2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Signal | |
{ | |
public class SignalBroadCast : MonoBehaviour | |
{ | |
[SerializeField] | |
private int channel; //チャンネル | |
public bool channelLoop; //ループの有無 | |
[SerializeField] | |
private int maxLoop; //ループ最大 | |
[SerializeField] | |
private int minLoop; //ループ最小 | |
private Caster caster = new Caster(); | |
public void CalcChannel(int calc) { | |
channel += calc; | |
if (channelLoop == false) { | |
return; | |
} | |
if (channel > maxLoop) { | |
channel = minLoop; | |
} | |
if (channel < minLoop) { | |
channel = maxLoop; | |
} //ループ | |
}//チャンネルの数値変更 | |
public void Select() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetSelect().Invoke(); | |
} | |
} | |
} | |
public void Cancel() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetCancel().Invoke(); | |
} | |
} | |
} | |
public void Enter() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetEnter().Invoke(); | |
} | |
} | |
} | |
public void Exit() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetExit().Invoke(); | |
} | |
} | |
}//イベントの発火 | |
} | |
public class Caster | |
{ | |
private static List<SignalListen> listeners = new List<SignalListen>(); | |
public static void AddListner(SignalListen listener){ | |
listeners.Add(listener); | |
}//リスナーの追加 | |
public List<SignalListen> GetLisnters(){ | |
return listeners; | |
} | |
} | |
public class SignalListen : MonoBehaviour | |
{ | |
[SerializeField] | |
private int channel = 0; | |
[SerializeField] | |
private UnityEvent OnEnter; | |
[SerializeField] | |
private UnityEvent OnExit; | |
[SerializeField] | |
private UnityEvent OnSelect; | |
[SerializeField] | |
private UnityEvent OnCancel; | |
public int GetChannel() { | |
return channel; | |
} | |
public UnityEvent GetSelect() | |
{ | |
return OnSelect; | |
} | |
public UnityEvent GetCancel() | |
{ | |
return OnCancel; | |
} | |
public UnityEvent GetEnter() | |
{ | |
return OnEnter; | |
} | |
public UnityEvent GetExit() | |
{ | |
return OnExit; | |
} | |
private void Start() | |
{ | |
Caster.AddListner(this);//自身をキャスターに追加 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment