-
-
Save omizumotimoti/b9f6470ca5e1ec805641c4badfac300a 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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Events; | |
namespace MLibrary | |
{ | |
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 AddChannel(bool truth) { | |
if (truth) | |
{ | |
channel++; | |
} | |
else { | |
channel --; | |
} | |
if (channelLoop == false) { | |
return; | |
} | |
if (channel > maxLoop) { | |
channel = minLoop; | |
} | |
if (channel < minLoop) { | |
channel = maxLoop; | |
} | |
} | |
public void Define() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetDefine().Invoke(); | |
} | |
} | |
} | |
public void Delete() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetDelete().Invoke(); | |
} | |
} | |
} | |
public void Select() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetSelect().Invoke(); | |
} | |
} | |
} | |
public void Deselect() | |
{ | |
foreach (SignalListen listener in caster.GetLisnters()) | |
{ | |
if (listener.GetChannel() == channel) | |
{ | |
listener.GetDeselect().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 OnSelect; | |
[SerializeField] | |
private UnityEvent OnDeselect; | |
[SerializeField] | |
private UnityEvent OnDefine; | |
[SerializeField] | |
private UnityEvent OnDelete; | |
public int GetChannel() { | |
return channel; | |
} | |
public UnityEvent GetSelect() | |
{ | |
return OnSelect; | |
} | |
public UnityEvent GetDeselect() | |
{ | |
return OnDeselect; | |
} | |
public UnityEvent GetDefine() | |
{ | |
return OnDefine; | |
} | |
public UnityEvent GetDelete() | |
{ | |
return OnDelete; | |
} | |
private void Start() | |
{ | |
Caster.AddListner(this); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment