Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            var targetScript = (EventBinding)target;

            // Get list of events we can bind to.
            events = EventBinder.GetBindableEvents(targetScript.gameObject)
                     .OrderBy(evt => evt.Name)
                     .ToArray();

            // Popup for the user to pick a UnityEvent on the UI to bind to.
            var selectedEventIndex = ShowEventSelector(targetScript);

            Type[] eventType = null;
            if (selectedEventIndex >= 0)
            {
                eventType = events[selectedEventIndex].GetEventTypes();

                // Save properties on the target script so they'll be serialised into the scene
                targetScript.uiEventName        = events[selectedEventIndex].Name;
                targetScript.boundComponentType = events[selectedEventIndex].ComponentType.Name;
            }

            var bindableViewModelMethods = GetBindableViewModelMethods(targetScript);

            // Show a popup for selecting which method to bind to.
            ShowMethodSelector(targetScript, bindableViewModelMethods, eventType);
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            // Initialise everything
            var targetScript = (TwoWayPropertyBinding)target;

            events = EventBinder
                     .GetBindableEvents(targetScript.gameObject)
                     .Where(evt => evt.GetEventTypes().Length == 1) // Only select events that can be bound directly to properties
                     .OrderBy(evt => evt.Name)
                     .ToArray();

            properties = PropertyBinder
                         .GetBindableProperties(targetScript.gameObject)
                         .OrderBy(property => property.PropertyInfo.Name)
                         .ToArray();

            Type selectedEventType  = null;
            var  selectedEventIndex = ShowEventSelector(targetScript);

            if (selectedEventIndex >= 0)
            {
                selectedEventType = events[selectedEventIndex].GetEventTypes().Single();;

                targetScript.uiEventName        = events[selectedEventIndex].Name;
                targetScript.boundComponentType = events[selectedEventIndex].ComponentType.Name;
            }

            var selectedPropertyIndex = ShowUIPropertySelector(targetScript);

            if (selectedPropertyIndex >= 0)
            {
                targetScript.uiPropertyName = properties[selectedPropertyIndex].PropertyInfo.Name;
            }

            var bindableViewModelProperties = GetBindableViewModelProperties(targetScript);

            ShowViewModelPropertySelector(targetScript, bindableViewModelProperties, selectedEventType);
        }