├── .gitignore ├── Assets ├── Plugins.meta └── Plugins │ ├── Unibus.meta │ ├── Unibus │ ├── CHANGELOG.md │ ├── CHANGELOG.md.meta │ ├── Prefabs.meta │ ├── Prefabs │ │ ├── Unibus.prefab │ │ └── Unibus.prefab.meta │ ├── README.md │ ├── README.md.meta │ ├── Scripts.meta │ ├── Scripts │ │ ├── MonoBehaviourExtension.cs │ │ ├── MonoBehaviourExtension.cs.meta │ │ ├── SingletonMonoBehaviour.cs │ │ ├── SingletonMonoBehaviour.cs.meta │ │ ├── Unibus.cs │ │ ├── Unibus.cs.meta │ │ ├── UnibusDestroySubscriber.cs │ │ ├── UnibusDestroySubscriber.cs.meta │ │ ├── UnibusDisableSubscriber.cs │ │ ├── UnibusDisableSubscriber.cs.meta │ │ ├── UnibusEvent.asmdef │ │ ├── UnibusEvent.asmdef.meta │ │ ├── UnibusObject.cs │ │ ├── UnibusObject.cs.meta │ │ ├── UnibusSubscriberBase.cs │ │ └── UnibusSubscriberBase.cs.meta │ ├── package.json │ └── package.json.meta │ ├── UnibusExample.meta │ └── UnibusExample │ ├── Scenes.meta │ ├── Scenes │ ├── CountExample.unity │ └── CountExample.unity.meta │ ├── Scripts.meta │ └── Scripts │ ├── ReceiverText.cs │ ├── ReceiverText.cs.meta │ ├── SenderButton.cs │ ├── SenderButton.cs.meta │ ├── UnibusExample.asmdef │ └── UnibusExample.asmdef.meta ├── CHANGELOG.md ├── LICENSE.md ├── Packages ├── manifest.json └── packages-lock.json ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── MemorySettings.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── PackageManagerSettings.asset ├── Physics2DSettings.asset ├── PresetManager.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityConnectSettings.asset ├── VFXManager.asset └── VersionControlSettings.asset ├── README.md └── art ├── place_unibus_prefab.png ├── unibus.png └── unibus_message_passing.png /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Uu]ser[Ss]ettings/ 12 | 13 | # MemoryCaptures can get excessive in size. 14 | # They also could contain extremely sensitive data 15 | /[Mm]emoryCaptures/ 16 | 17 | # Recordings can get excessive in size 18 | /[Rr]ecordings/ 19 | 20 | # Uncomment this line if you wish to ignore the asset store tools plugin 21 | # /[Aa]ssets/AssetStoreTools* 22 | 23 | # Autogenerated Jetbrains Rider plugin 24 | /[Aa]ssets/Plugins/Editor/JetBrains* 25 | 26 | # Visual Studio cache directory 27 | .vs/ 28 | 29 | # Gradle cache directory 30 | .gradle/ 31 | 32 | # Autogenerated VS/MD/Consulo solution and project files 33 | ExportedObj/ 34 | .consulo/ 35 | *.csproj 36 | *.unityproj 37 | *.sln 38 | *.suo 39 | *.tmp 40 | *.user 41 | *.userprefs 42 | *.pidb 43 | *.booproj 44 | *.svd 45 | *.pdb 46 | *.mdb 47 | *.opendb 48 | *.VC.db 49 | 50 | # Unity3D generated meta files 51 | *.pidb.meta 52 | *.pdb.meta 53 | *.mdb.meta 54 | 55 | # Unity3D generated file on crash reports 56 | sysinfo.txt 57 | 58 | # Builds 59 | *.apk 60 | *.aab 61 | *.unitypackage 62 | *.app 63 | 64 | # Crashlytics generated file 65 | crashlytics-build.properties 66 | 67 | # Packed Addressables 68 | /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* 69 | 70 | # Temporary auto-generated Android Assets 71 | /[Aa]ssets/[Ss]treamingAssets/aa.meta 72 | /[Aa]ssets/[Ss]treamingAssets/aa/* 73 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5815222f7204c407bbbd0656cfa74506 3 | folderAsset: yes 4 | timeCreated: 1476867815 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3e1c6fbd652b4799a0548052d7d4d17 3 | folderAsset: yes 4 | timeCreated: 1465739536 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 1.0.2 (2024-01-03) 2 | 3 | Features: 4 | 5 | - #23 Bump up unity version to 2022.x 6 | - #25 Support upm 7 | 8 | Bugs: 9 | 10 | - #21 UnibusDestroySubscriber used wrong mono event? 11 | 12 | # 1.0.1 (2016-11-12) 13 | 14 | Features: 15 | 16 | - #19 Show warnings if no subscriber is assigned 17 | 18 | # 1.0.0 (2016-10-15) 19 | 20 | Intial Release :tada: 21 | 22 | Features: 23 | 24 | - #3 Renamed `Bus` to `UnibusEvent` 25 | - #4 Created shortcut Dispatch, Subscirbe, Unsubscribe 26 | - #6 Renamed `BindEnableEvent()` to `BindUntilDisable()` 27 | - #7 Created Unibus Prefab 28 | - #17 `UnibusEvent` for namespace, `Unibus` for class name 29 | 30 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2bfb87721f0d64226a073252aaacc601 3 | timeCreated: 1476868973 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c897ca4e2ad8a47debc09ddf00fddf38 3 | folderAsset: yes 4 | timeCreated: 1476695907 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Prefabs/Unibus.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/Unibus/2b2538f6b32b5f69357f639dbd272a299fb6504c/Assets/Plugins/Unibus/Prefabs/Unibus.prefab -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Prefabs/Unibus.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83d896bca7f1248d9bdc1c9dce4e986f 3 | timeCreated: 1476695914 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/README.md: -------------------------------------------------------------------------------- 1 | # Unibus 2 | 3 | ![Unibus](./art/unibus.png) 4 | 5 | Unibus is event passing system for Unity3D. 6 | 7 | It is inspired by EventBus. 8 | 9 | # Why Unibus? 10 | 11 | Unity is great framework for creating game, but there is no standard event passing system. 12 | 13 | For example in GameJam, there is no time to solve GameObject dependencies and create so many callback. 14 | 15 | So I create instant event passing system. 16 | 17 | It's easy to use, thin dependency, flexible to fit any type of message. 18 | 19 | # Architecture 20 | 21 | ![Unibus](./art/unibus_message_passing.png) 22 | 23 | Unibus is singleton GameObject. 24 | 25 | It manages receivers and senders to handle message. 26 | 27 | The message is classified by tag and type. 28 | 29 | For example, if you dispatch message with `HP` tag and `int` type, then receivers subscribing `HP` tag and `int` type can only receives the dispatched value. 30 | 31 | # Install 32 | 33 | Install from UPM 34 | 35 | ``` 36 | { 37 | "dependencies": { 38 | "me.mattak.unibus": "https://github.com/mattak/Unibus.git?path=Assets/Plugins/Unibus" 39 | } 40 | } 41 | ``` 42 | 43 | # Usage 44 | 45 | ## 1. Place Unibus object 46 | 47 | Place `Unibus` prefab object into your scene. 48 | It will be singleton to handle event. 49 | 50 | ![Place Unibus prefab](./art/place_unibus_prefab.png) 51 | 52 | Then it's ready to use. 53 | 54 | ## 2. Implement event sender 55 | 56 | Send any event what you want. 57 | 58 | ```csharp 59 | using UnibusEvent; 60 | 61 | public class SampleEventSender : MonoBehaviour 62 | { 63 | void OnClick() 64 | { 65 | // Send string message 66 | Unibus.Dispatch("message"); 67 | } 68 | } 69 | ``` 70 | 71 | ## 3. Implement event receiver 72 | 73 | Receive sent message. 74 | 75 | ```csharp 76 | using UnibusEvent; 77 | 78 | public class SampleEventReceiver : MonoBehavour 79 | { 80 | void OnEnable() 81 | { 82 | Unibus.Subscribe(OnEvent); 83 | } 84 | 85 | void OnDisable() 86 | { 87 | Unibus.Unsubscribe(OnEvent); 88 | } 89 | 90 | // This is receiver 91 | void OnEvent(string message) 92 | { 93 | var text = this.GetComponent(); 94 | text.text = message; 95 | } 96 | } 97 | ``` 98 | 99 | Or you can use simple style subscriber. 100 | `BindUntilDisable()` is shortcut to unsubscribe automatically when gameobject reach `onDisable()`. 101 | 102 | ```csharp 103 | using UnibusEvent; 104 | 105 | public class SampleEventReceiver : MonoBehavour 106 | { 107 | void OnEnable() 108 | { 109 | this.BindUntilDisable((string message) => { this.GetComponent().text = message; }); 110 | } 111 | } 112 | ``` 113 | 114 | ## Sending Object 115 | 116 | It's able to send any type of object. 117 | 118 | ```csharp 119 | // Subscribe 120 | this.BindUntilDisable((int value) => {}); 121 | this.BindUntilDisable((string value) => {}); 122 | this.BindUntilDisable((Person value) => {}); 123 | 124 | // Dispatch 125 | Unibus.Dispatch(0); 126 | Unibus.Dispatch("message"); 127 | Unibus.Dispatch(new Person("john", "due")); 128 | ``` 129 | 130 | ## Tagging 131 | 132 | Divide same type of object event by attaching tag. 133 | 134 | ```csharp 135 | // Subscribe 136 | this.BindUntilDisable("HP", (int value) => {}); 137 | this.BindUntilDisable("MP", (int value) => {}); 138 | 139 | // Dispatch 140 | Unibus.Dispatch("HP", 100); 141 | Unibus.Dispatch("MP", 200); 142 | ``` 143 | 144 | # License 145 | 146 | [MIT](./LICENSE.md) 147 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d576b5076a6cc49a6a1a12b085bd8318 3 | timeCreated: 1476868323 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 812bfd44bc4314b0c998545fae3c9dac 3 | folderAsset: yes 4 | timeCreated: 1476695763 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/MonoBehaviourExtension.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace UnibusEvent 5 | { 6 | public static class MonoBehaviourExtension 7 | { 8 | public static void BindUntilDisable(this MonoBehaviour mono, OnEvent onEvent) 9 | { 10 | GetOrAddComponent(mono, UnibusObject.DefaultTag, onEvent); 11 | } 12 | 13 | public static void BindUntilDisable(this MonoBehaviour mono, object tag, OnEvent onEvent) 14 | { 15 | GetOrAddComponent(mono, tag, onEvent); 16 | } 17 | 18 | public static void BindUntilDestroy(this MonoBehaviour mono, OnEvent onEvent) 19 | { 20 | GetOrAddComponent(mono, UnibusObject.DefaultTag, onEvent); 21 | } 22 | 23 | public static void BindUntilDestroy(this MonoBehaviour mono, object tag, OnEvent onEvent) 24 | { 25 | GetOrAddComponent(mono, tag, onEvent); 26 | } 27 | 28 | private static void GetOrAddComponent(MonoBehaviour mono, object tag, OnEvent onEvent) where S : UnibusSubscriberBase 29 | { 30 | var component = mono.GetComponent(); 31 | 32 | if (null == component) 33 | { 34 | component = mono.gameObject.AddComponent(); 35 | } 36 | 37 | component.SetSubscribeCaller(tag, onEvent); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/MonoBehaviourExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9f1b08c22a7a8420fb19038db4994620 3 | timeCreated: 1465833847 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/SingletonMonoBehaviour.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace UnibusEvent 4 | { 5 | public class SingletonMonoBehaviour : MonoBehaviour where T : SingletonMonoBehaviour 6 | { 7 | protected static T instance; 8 | 9 | public static T Instance 10 | { 11 | get 12 | { 13 | if (instance == null) 14 | { 15 | instance = (T)FindObjectOfType(typeof(T)); 16 | 17 | if (instance == null) 18 | { 19 | Debug.LogWarning(typeof(T) + "is nothing"); 20 | } 21 | } 22 | 23 | return instance; 24 | } 25 | } 26 | 27 | protected void Awake() 28 | { 29 | CheckInstance(); 30 | } 31 | 32 | protected bool CheckInstance() 33 | { 34 | if (instance == null) 35 | { 36 | instance = (T)this; 37 | return true; 38 | } 39 | else if (Instance == this) 40 | { 41 | return true; 42 | } 43 | 44 | Destroy(this); 45 | return false; 46 | } 47 | 48 | public static bool IsExistInstance() 49 | { 50 | return instance != null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/SingletonMonoBehaviour.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a85454526b7f47a7ae61d9510544179 3 | timeCreated: 1465830423 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/Unibus.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | namespace UnibusEvent 7 | { 8 | public static class Unibus 9 | { 10 | public static void Subscribe(OnEvent eventCallback) 11 | { 12 | UnibusObject.Instance.Subscribe(eventCallback); 13 | } 14 | 15 | public static void Subscribe(object tag, OnEvent eventCallback) 16 | { 17 | UnibusObject.Instance.Subscribe(tag, eventCallback); 18 | } 19 | 20 | public static void Unsubscribe(OnEvent eventCallback) 21 | { 22 | UnibusObject.Instance.Unsubscribe(UnibusObject.DefaultTag, eventCallback); 23 | } 24 | 25 | public static void Unsubscribe(object tag, OnEvent eventCallback) 26 | { 27 | UnibusObject.Instance.Unsubscribe(tag, eventCallback); 28 | } 29 | 30 | public static void Dispatch(T action) 31 | { 32 | UnibusObject.Instance.Dispatch(UnibusObject.DefaultTag, action); 33 | } 34 | 35 | public static void Dispatch(object tag, T action) 36 | { 37 | UnibusObject.Instance.Dispatch(tag, action); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/Unibus.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4509142fa0a114095a866ce2f96b5556 3 | timeCreated: 1465739621 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusDestroySubscriber.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | 5 | namespace UnibusEvent 6 | { 7 | public class UnibusDestroySubscriber : UnibusSubscriberBase 8 | { 9 | private void Awake() 10 | { 11 | if (subscribeCaller != null) 12 | { 13 | subscribeCaller(true); 14 | } 15 | } 16 | 17 | private void OnDestroy() 18 | { 19 | if (subscribeCaller != null) 20 | { 21 | subscribeCaller(false); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusDestroySubscriber.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68d79df5ce8db423287c87ff98135ef9 3 | timeCreated: 1465898821 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusDisableSubscriber.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | 5 | namespace UnibusEvent 6 | { 7 | public class UnibusDisableSubscriber : UnibusSubscriberBase 8 | { 9 | void OnEnable() 10 | { 11 | if (subscribeCaller != null) 12 | { 13 | subscribeCaller(true); 14 | } 15 | } 16 | 17 | void OnDisable() 18 | { 19 | if (subscribeCaller != null) 20 | { 21 | subscribeCaller(false); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusDisableSubscriber.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 806b9c662135a49afa033ddb64ca36af 3 | timeCreated: 1465898821 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusEvent.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "UnibusEvent", 3 | "rootNamespace": "", 4 | "references": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": false, 8 | "overrideReferences": false, 9 | "precompiledReferences": [], 10 | "autoReferenced": true, 11 | "defineConstraints": [], 12 | "versionDefines": [], 13 | "noEngineReferences": false 14 | } -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusEvent.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29d6a2137109048af966af5fb828f6a4 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace UnibusEvent 6 | { 7 | public delegate void OnEvent(T action); 8 | 9 | public delegate void OnEventWrapper(object _object); 10 | 11 | class DictionaryKey 12 | { 13 | public Type Type; 14 | public object Tag; 15 | 16 | public DictionaryKey(object tag, Type type) 17 | { 18 | this.Tag = tag; 19 | this.Type = type; 20 | } 21 | 22 | public override int GetHashCode() 23 | { 24 | return this.Tag.GetHashCode() ^ this.Type.GetHashCode(); 25 | } 26 | 27 | public override bool Equals(object obj) 28 | { 29 | if (obj is DictionaryKey) 30 | { 31 | var key = (DictionaryKey) obj; 32 | return this.Tag.Equals(key.Tag) && this.Type.Equals(key.Type); 33 | } 34 | 35 | return false; 36 | } 37 | } 38 | 39 | public class UnibusObject : SingletonMonoBehaviour 40 | { 41 | public const string DefaultTag = "default"; 42 | 43 | private Dictionary> observerDictionary = 44 | new Dictionary>(); 45 | 46 | public void Subscribe(OnEvent eventCallback) 47 | { 48 | this.Subscribe(DefaultTag, eventCallback); 49 | } 50 | 51 | public void Subscribe(object tag, OnEvent eventCallback) 52 | { 53 | var key = new DictionaryKey(tag, typeof(T)); 54 | 55 | if (!observerDictionary.ContainsKey(key)) 56 | { 57 | observerDictionary[key] = new Dictionary(); 58 | } 59 | 60 | observerDictionary[key][eventCallback.GetHashCode()] = (object _object) => { eventCallback((T) _object); }; 61 | } 62 | 63 | public void Unsubscribe(OnEvent eventCallback) 64 | { 65 | this.Unsubscribe(DefaultTag, eventCallback); 66 | } 67 | 68 | public void Unsubscribe(object tag, OnEvent eventCallback) 69 | { 70 | var key = new DictionaryKey(tag, typeof(T)); 71 | 72 | if (observerDictionary[key] != null) 73 | { 74 | observerDictionary[key].Remove(eventCallback.GetHashCode()); 75 | } 76 | } 77 | 78 | public void Dispatch(T action) 79 | { 80 | this.Dispatch(DefaultTag, action); 81 | } 82 | 83 | public void Dispatch(object tag, T action) 84 | { 85 | var key = new DictionaryKey(tag, typeof(T)); 86 | 87 | if (observerDictionary.ContainsKey(key)) 88 | { 89 | foreach (var caller in observerDictionary[key].Values) 90 | { 91 | caller(action); 92 | } 93 | } 94 | else 95 | { 96 | string tagAndAction = string.Format("(tag:{0}, action:{1})", tag, action); 97 | Debug.LogWarning("Unibus.Dispatch failed to send: " + tagAndAction); 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusObject.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a286885f1c0049ca907a9c84337f0b7 3 | timeCreated: 1465739621 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusSubscriberBase.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | 4 | namespace UnibusEvent 5 | { 6 | public class UnibusSubscriberBase : MonoBehaviour 7 | { 8 | protected Action subscribeCaller; 9 | 10 | public void SetSubscribeCaller(object tag, OnEvent onEvent) 11 | { 12 | 13 | subscribeCaller = (bool active) => 14 | { 15 | if (active) 16 | { 17 | UnibusObject.Instance.Subscribe(tag, onEvent); 18 | } 19 | else 20 | { 21 | if (UnibusObject.IsExistInstance()) 22 | { 23 | UnibusObject.Instance.Unsubscribe(tag, onEvent); 24 | } 25 | } 26 | }; 27 | 28 | subscribeCaller(true); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/Scripts/UnibusSubscriberBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3da65959ccb7546ce9330eb7dba0492e 3 | timeCreated: 1465898821 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "me.mattak.unibus", 3 | "displayName": "Unibus", 4 | "version": "1.0.2", 5 | "unity": "2022.3", 6 | "description": "Event passing system for Unity", 7 | "license": "MIT", 8 | "author": { 9 | "name": "Takuma Maruyama" 10 | }, 11 | "dependencies": { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Assets/Plugins/Unibus/package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7ec126709224c4a30a1a538e64456af4 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d286958b3193648c99810e9e472bce82 3 | folderAsset: yes 4 | timeCreated: 1465829961 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2a781cdf70ce4cce83fc45d0975b367 3 | folderAsset: yes 4 | timeCreated: 1465899597 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample/Scenes/CountExample.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattak/Unibus/2b2538f6b32b5f69357f639dbd272a299fb6504c/Assets/Plugins/UnibusExample/Scenes/CountExample.unity -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample/Scenes/CountExample.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa34e002be58e4f179e9d3884e8bff83 3 | timeCreated: 1465742629 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa25ec510afff4ab98ce4614fc25e54e 3 | folderAsset: yes 4 | timeCreated: 1465899604 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample/Scripts/ReceiverText.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | using System.Collections; 4 | using UnibusEvent; 5 | 6 | namespace UnibusEvent.Example 7 | { 8 | public class ReceiverText : MonoBehaviour 9 | { 10 | public string Tag = "Count"; 11 | private Text Text; 12 | 13 | void OnEnable() 14 | { 15 | this.Text = this.GetComponent(); 16 | this.BindUntilDisable(Tag, (int count) => 17 | { 18 | this.Text.text = count.ToString(); 19 | }); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample/Scripts/ReceiverText.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad69f3f6c8fe8477b95a2856afad5ced 3 | timeCreated: 1465830165 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Plugins/UnibusExample/Scripts/SenderButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | 4 | namespace UnibusEvent.Example 5 | { 6 | public class SenderButton : MonoBehaviour 7 | { 8 | public string Tag = "Count"; 9 | 10 | void Start() 11 | { 12 | var count = 0; 13 | var button = this.GetComponent