示例#1
0
        private static void DrawInterfaceHandler <T>(TriggerBase trigger, string triggerActionName, bool createChildObject)
        {
            if (trigger.GetComponentInChildren <T>() == null)
            {
                if (_interfaceTypeLookup.ContainsKey(typeof(T)) == false)
                {
                    _interfaceTypeLookup[typeof(T)] = ReflectionUtility.GetAllTypesThatImplement(typeof(T));
                }

                EditorGUILayout.HelpBox("You can add a " + typeof(T).Name + " to control this trigger's " + triggerActionName.ToLower(), MessageType.Info);
                foreach (var type in _interfaceTypeLookup[typeof(T)])
                {
                    var tempType    = type;
                    var tempTrigger = trigger;
                    if (GUILayout.Button("Add: " + tempType.Name))
                    {
                        var objToAddTo = tempTrigger.gameObject;
                        if (createChildObject)
                        {
                            objToAddTo = new GameObject("_" + tempType.Name);
                            objToAddTo.transform.SetParent(tempTrigger.transform);
                            objToAddTo.transform.localPosition = Vector3.zero;
                            objToAddTo.transform.localRotation = Quaternion.identity;
                        }

                        objToAddTo.AddComponent(tempType);
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox(triggerActionName + " is handled by " + typeof(T).Name, MessageType.Info);
            }
        }