diff --git a/Assets/TierIV.meta b/Assets/TierIV.meta new file mode 100644 index 000000000..e88e79d4f --- /dev/null +++ b/Assets/TierIV.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9d04975e5ec319a4cbcf378088bf69de +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TierIV/Event.meta b/Assets/TierIV/Event.meta new file mode 100644 index 000000000..4a38d1de1 --- /dev/null +++ b/Assets/TierIV/Event.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 160b0111f376f4b45b482514732b26be +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TierIV/Event/Scripts.meta b/Assets/TierIV/Event/Scripts.meta new file mode 100644 index 000000000..436b91b41 --- /dev/null +++ b/Assets/TierIV/Event/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d4b25c5289f00ba4cacf32cefd800021 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TierIV/Event/Scripts/BatteryObjectEvent.cs b/Assets/TierIV/Event/Scripts/BatteryObjectEvent.cs new file mode 100644 index 000000000..713b13f37 --- /dev/null +++ b/Assets/TierIV/Event/Scripts/BatteryObjectEvent.cs @@ -0,0 +1,38 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TierIV.Event; + + +public class BatteryObjectEvent : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + } + + void OnEnable() + { + EventNotifier.Instance.SubscribeEvent(OnReceiveChargeEvent, "Charge"); + } + + void OnDisable() + { + EventNotifier.Instance.UnSubscribeEvent(OnReceiveChargeEvent); + } + + void OnReceiveChargeEvent(EventArgsBase chargeEvent) + { + if (typeof(ChargeStationEvent.BatteryVolume).GetHashCode() != chargeEvent.TypeHash) + { + throw new System.ArgumentException(string.Format("different class hashcode {0}({1}) / {2}({3})", + typeof(ChargeStationEvent.BatteryVolume).GetHashCode(), + typeof(EventArgsBase).Name, + chargeEvent.TypeHash, + chargeEvent.GetType().Name + )); + } + + // receive chargeEvent values to appropriate proces + } +} diff --git a/Assets/TierIV/Event/Scripts/BatteryObjectEvent.cs.meta b/Assets/TierIV/Event/Scripts/BatteryObjectEvent.cs.meta new file mode 100644 index 000000000..bf67b3966 --- /dev/null +++ b/Assets/TierIV/Event/Scripts/BatteryObjectEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f3415d843c7eff44930a3d4858b8ab6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TierIV/Event/Scripts/ChargeStationEvent.cs b/Assets/TierIV/Event/Scripts/ChargeStationEvent.cs new file mode 100644 index 000000000..73278b93a --- /dev/null +++ b/Assets/TierIV/Event/Scripts/ChargeStationEvent.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TierIV.Event; + +public class ChargeStationEvent : MonoBehaviour +{ + public class BatteryVolume : EventArgsBase + { + public float parcentage; + } + + BatteryVolume volume = new BatteryVolume { parcentage = 10f }; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + void OnTriggerStay(Collider target) + { + // send to event + EventNotifier.Instance.BroadcastEvent("Charge", volume); + } + +} \ No newline at end of file diff --git a/Assets/TierIV/Event/Scripts/ChargeStationEvent.cs.meta b/Assets/TierIV/Event/Scripts/ChargeStationEvent.cs.meta new file mode 100644 index 000000000..d5bc79fbe --- /dev/null +++ b/Assets/TierIV/Event/Scripts/ChargeStationEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8fdb797a77ed1d2408e3240ea6ad6bfb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TierIV/Event/Scripts/EventArgsBase.cs b/Assets/TierIV/Event/Scripts/EventArgsBase.cs new file mode 100644 index 000000000..2d65d9e52 --- /dev/null +++ b/Assets/TierIV/Event/Scripts/EventArgsBase.cs @@ -0,0 +1,15 @@ + +public class EventArgsBase +{ + private int typeHash; + + public int TypeHash + { + get { return typeHash; } + } + + public EventArgsBase() + { + typeHash = this.GetType().GetHashCode(); + } +} diff --git a/Assets/TierIV/Event/Scripts/EventArgsBase.cs.meta b/Assets/TierIV/Event/Scripts/EventArgsBase.cs.meta new file mode 100644 index 000000000..236449e1b --- /dev/null +++ b/Assets/TierIV/Event/Scripts/EventArgsBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ef4d3fc5570c9c42bb6a1ef9aa224b2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TierIV/Event/Scripts/EventNotifier.cs b/Assets/TierIV/Event/Scripts/EventNotifier.cs new file mode 100644 index 000000000..96fa39ce8 --- /dev/null +++ b/Assets/TierIV/Event/Scripts/EventNotifier.cs @@ -0,0 +1,83 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace TierIV.Event +{ + public class EventNotifier + { + private static EventNotifier _instance = null; + + public static EventNotifier Instance + { + get + { + if (_instance == null) + { + _instance = new EventNotifier(); + } + + return _instance; + } + } + + private EventNotifier() + { + } + + public delegate void OnNotifyEvent(EventArgsBase text); + event OnNotifyEvent _notifyEvent; + Dictionary _evt = new Dictionary(); + + public void SubscribeEvent(OnNotifyEvent notifyEventHandler, string tag = "") + { + Debug.LogFormat("SubscribeEvent({0},{1})", notifyEventHandler, tag); + if (_evt.ContainsKey(tag)) + { + _evt[tag] += notifyEventHandler; + } + else + { + _evt.Add(tag, notifyEventHandler); + } + + _notifyEvent += notifyEventHandler; + } + + public void UnSubscribeEvent(OnNotifyEvent notifyEventHandler) + { + foreach (var v in _evt) + { + var eh = v.Value; + eh -= notifyEventHandler; + _evt[v.Key] = eh; + } + } + + public void BroadcastEvent(EventArgsBase value) + { + BroadcastEvent(null, value); + } + + public void BroadcastEvent(string tag, EventArgsBase value) + { + List handlerList = new List(); + + // tag == null is all handler message send + if (tag == null) + { + handlerList.AddRange(_evt.Values); + } + else + { + handlerList.Add(_evt[tag]); + } + + foreach (var handler in handlerList) + { + handler(value); + } + } + } +} diff --git a/Assets/TierIV/Event/Scripts/EventNotifier.cs.meta b/Assets/TierIV/Event/Scripts/EventNotifier.cs.meta new file mode 100644 index 000000000..9990dc72a --- /dev/null +++ b/Assets/TierIV/Event/Scripts/EventNotifier.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 79effb4bb5ee92e4e8310dffbe954d3f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: