public void Initialize(USEventBase evt)
        {
            Event = evt;

            // Use Reflection to find the Function we require and call it.
            var baseType  = typeof(USEventBaseEditor);
            var foundType = baseType;
            var types     = USEditorUtility.GetAllSubTypes(baseType);

            foreach (var type in types)
            {
                if (type.IsSubclassOf(baseType))
                {
                    foreach (Attribute attr in type.GetCustomAttributes(true))
                    {
                        var eventAttr = attr as CustomUSEditorAttribute;

                        if (eventAttr == null)
                        {
                            continue;
                        }

                        if (eventAttr.InspectedType == Event.GetType())
                        {
                            foundType = type;
                        }
                    }
                }
            }

            eventEditor             = CreateInstance(foundType) as USEventBaseEditor;
            eventEditor.TargetEvent = Event;
        }
Exemple #2
0
        private void HandleEvent()
        {
            var isContext = Event.current.type == EventType.MouseDown && Event.current.button == 1;

            if (!isContext)
            {
                return;
            }

            var contextMenu = new GenericMenu();

            foreach (var data in cachedEventRenderData)
            {
                if (data.RenderRect.Contains(Event.current.mousePosition))
                {
                    contextMenu.AddItem(new GUIContent("Remove Event"), false, () => { RemoveEvent(data.Event); });
                    contextMenu.AddSeparator("");
                    break;
                }
            }

            if (DisplayArea.Contains(Event.current.mousePosition))
            {
                var baseAdd = "Add Event/";
                var newTime = (((Event.current.mousePosition.x + XScroll - DisplayArea.x) / DisplayArea.width) * Duration) / XScale;

                var baseType = typeof(USEventBase);
                var types    = USEditorUtility.GetAllSubTypes(baseType).Where(type => type.IsSubclassOf(baseType));
                foreach (var type in types)
                {
                    var fullAdd          = baseAdd;
                    var customAttributes = type.GetCustomAttributes(true).Where(attr => attr is USequencerEventAttribute).Cast <USequencerEventAttribute>();
                    foreach (var customAttribute in customAttributes)
                    {
                        fullAdd += customAttribute.EventPath;
                    }

                    contextMenu.AddItem(new GUIContent(fullAdd), false, (obj) => AddEvent(newTime, (Type)obj), (object)type);
                }
            }

            if (DisplayArea.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                contextMenu.ShowAsContext();
            }
        }