├── README.md
├── ProjectSettings
├── TagManager.asset
├── TimeManager.asset
├── AudioManager.asset
├── InputManager.asset
├── NavMeshLayers.asset
├── DynamicsManager.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── NetworkManager.asset
├── ProjectSettings.asset
├── QualitySettings.asset
├── Physics2DSettings.asset
└── EditorBuildSettings.asset
├── .gitignore
├── Assets
├── Signals.meta
└── Signals
│ ├── Scripts.meta
│ └── Scripts
│ ├── Editor.meta
│ ├── Signal.cs.meta
│ ├── Editor
│ ├── SignalDrawer.cs.meta
│ └── SignalDrawer.cs
│ └── Signal.cs
├── Signals.userprefs
└── LICENSE
/README.md:
--------------------------------------------------------------------------------
1 | Signals
2 | =======
3 |
4 | A simple, easy to implement, editor-driven signal/event system for Unity.
5 |
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshLayers.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/NavMeshLayers.asset
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/GraphicsSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/Physics2DSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UnityPatterns/Signals/HEAD/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 |
5 | # Autogenerated VS/MD solution and project files
6 | *.csproj
7 | *.unityproj
8 | *.sln
9 |
--------------------------------------------------------------------------------
/Assets/Signals.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d83ebddbe76fec64f98782854387d2e2
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Assets/Signals/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 138f962d34b9ef54d8a9a7aaa38d67ee
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Assets/Signals/Scripts/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fbe18cae771f9fa44aeedb9f48905509
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Assets/Signals/Scripts/Signal.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e1e76cc6f0d5c0d4491eac30fa181d1a
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Signals/Scripts/Editor/SignalDrawer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 90ba375698f332749911762c6bce8c65
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Signals.userprefs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 UnityPatterns
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/Assets/Signals/Scripts/Signal.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | [System.Serializable]
5 | public class Signal
6 | {
7 | public GameObject target;
8 | public string method;
9 | public string argType;
10 |
11 | public Signal()
12 | {
13 |
14 | }
15 | public Signal(System.Type argType)
16 | {
17 | this.argType = argType.FullName;
18 | }
19 |
20 | public void Invoke()
21 | {
22 | if (target != null && !string.IsNullOrEmpty(method))
23 | target.SendMessage(method, SendMessageOptions.RequireReceiver);
24 | }
25 | public void Invoke(object value)
26 | {
27 | if (argType != null)
28 | {
29 | if (target != null && !string.IsNullOrEmpty(method))
30 | {
31 | if (argType.Equals(value.GetType().FullName))
32 | target.SendMessage(method, value, SendMessageOptions.RequireReceiver);
33 | else
34 | Debug.LogError("Incorrect parameter type, expected [" + argType + "], got [" + value.GetType().FullName + "].");
35 | }
36 | }
37 | else
38 | Invoke();
39 | }
40 | }
41 |
42 | public class SignalAttribute : System.Attribute
43 | {
44 | public string name;
45 |
46 | public SignalAttribute()
47 | {
48 |
49 | }
50 | public SignalAttribute(string name)
51 | {
52 | this.name = name;
53 | }
54 | }
--------------------------------------------------------------------------------
/Assets/Signals/Scripts/Editor/SignalDrawer.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UnityEditor;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System.Reflection;
6 |
7 | [CustomPropertyDrawer(typeof(Signal))]
8 | public class SignalDrawer : PropertyDrawer
9 | {
10 | public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
11 | {
12 | EditorGUI.BeginProperty(position, label, property);
13 |
14 | GUI.Label(position, label.text + " (Signal)", EditorStyles.label);
15 | var indent = 30f;
16 | var prefixRect = new Rect(position.x + indent, position.y + position.height / 3, (position.width - indent) * 0.25f, position.height / 3);
17 | var valueRect = new Rect(prefixRect.x + prefixRect.width, prefixRect.y, (position.width - indent) * 0.75f, position.height / 3);
18 |
19 | var targetProperty = property.FindPropertyRelative("target");
20 | GUI.Label(prefixRect, "Target", EditorStyles.miniLabel);
21 | targetProperty.objectReferenceValue = EditorGUI.ObjectField(valueRect, targetProperty.objectReferenceValue, typeof(GameObject), true);
22 |
23 | prefixRect.y += prefixRect.height + 1;
24 | valueRect.y += valueRect.height + 1;
25 |
26 | var methodProperty = property.FindPropertyRelative("method");
27 | GUI.Label(prefixRect, "Method", EditorStyles.miniLabel);
28 |
29 | var argType = property.FindPropertyRelative("argType").stringValue;
30 | var names = new List();
31 | var methodNames = new List();
32 | names.Add("None");
33 | methodNames.Add(null);
34 | var index = 0;
35 | var obj = targetProperty.objectReferenceValue as GameObject;
36 | if (obj != null)
37 | {
38 | var components = obj.GetComponents();
39 | foreach (var component in components)
40 | {
41 | var type = component.GetType();
42 | var methods = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
43 | foreach (var method in methods)
44 | {
45 | var attributes = method.GetCustomAttributes(typeof(SignalAttribute), true);
46 | if (attributes.Length > 0)
47 | {
48 | var parameters = method.GetParameters();
49 | var addMethod = false;
50 |
51 | if (string.IsNullOrEmpty(argType))
52 | {
53 | if (parameters.Length == 0)
54 | addMethod = true;
55 | }
56 | else
57 | {
58 | if (parameters.Length == 1 && parameters[0].ParameterType.FullName.Equals(argType))
59 | addMethod = true;
60 | }
61 |
62 | if (addMethod)
63 | {
64 | var attribute = (SignalAttribute)attributes[0];
65 | if (string.IsNullOrEmpty(attribute.name))
66 | {
67 | var name = ObjectNames.NicifyVariableName(method.Name);
68 | if (name.Contains("Signal"))
69 | name = name.Replace("Signal", "");
70 | names.Add(type.Name + ": " + name);
71 | }
72 | else
73 | names.Add(type.Name + ": " + attribute.name);
74 | if (methodProperty.stringValue == method.Name)
75 | index = methodNames.Count;
76 | methodNames.Add(method.Name);
77 | }
78 | }
79 | }
80 | }
81 |
82 | if (names.Count > 1)
83 | {
84 | EditorGUI.BeginChangeCheck();
85 | index = EditorGUI.Popup(valueRect, index, names.ToArray());
86 | if (EditorGUI.EndChangeCheck())
87 | methodProperty.stringValue = methodNames[index];
88 | }
89 | else
90 | GUI.Label(valueRect, "None");
91 | }
92 | else
93 | GUI.Label(valueRect, "None");
94 |
95 | EditorGUI.EndProperty();
96 | }
97 |
98 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
99 | {
100 | return base.GetPropertyHeight(property, label) * 3;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------