예제 #1
0
        /// <summary>
        /// Draws the event property with a minus button to remove the event.
        /// </summary>
        /// <param name="inspectorData">Event we are drawing.</param>
        /// <returns>Returns EventInspectorData of the field that needs to be removed</returns>
        static EventInspectorData DrawEventPropertyField(EventInspectorData inspectorData)
        {
            if (inspectorData.hidden)
            {
                return(null);
            }

            var eventProperty = inspectorData.property;

            using (var check = new EditorGUI.ChangeCheckScope())
            {
                var callsProperty  = eventProperty.FindPropertyRelative("m_PersistentCalls.m_Calls");
                var prevCallsCount = callsProperty.arraySize;
                EditorGUILayout.PropertyField(inspectorData.property, false);
                if (check.changed)
                {
                    var callsCount = callsProperty.arraySize;
                    if (callsCount > prevCallsCount)
                    {
                        // For each new call that was added, default to Editor And Runtime for compatibility with simulation
                        var callIndex = prevCallsCount;
                        while (callIndex < callsCount)
                        {
                            var callState = callsProperty.GetArrayElementAtIndex(callIndex).FindPropertyRelative("m_CallState");
                            callState.enumValueIndex = 1;
                            callIndex++;
                        }
                    }
                }
            }

            var callbackRect     = GUILayoutUtility.GetLastRect();
            var removeButtonSize = MarsEditorGUI.Styles.IconToolbarMinusSize;

            const float edgePaddingScale = 1.5f;
            const float topPadding       = 1f;
            var         removeButtonPos  = new Rect(callbackRect.xMax - removeButtonSize.x * edgePaddingScale,
                                                    callbackRect.y + topPadding, removeButtonSize.x, removeButtonSize.y);

            EventInspectorData returnType = null;

            if (GUI.Button(removeButtonPos, MarsEditorGUI.Styles.IconToolbarMinus, GUIStyle.none))
            {
                returnType = inspectorData;
                var remove = eventProperty.FindPropertyRelative("m_PersistentCalls.m_Calls");
                remove.arraySize = 0;
            }

            EditorGUILayout.Space();
            return(returnType);
        }
        /// <summary>
        /// This method is called when the object is created. Called after Init.
        /// </summary>
        public virtual void OnEnable()
        {
            k_Fields.Clear();
            EventInspectorUtils.GetEvents(target.GetType(), k_Fields);
            foreach (var field in k_Fields)
            {
                m_EventInspectorData[field] = new EventInspectorData();
            }

            EventInspectorUtils.SyncEventDrawers(serializedObject, m_EventInspectorData);
            Undo.undoRedoPerformed += SyncEventDrawers;
            m_Parameters            = new List <SerializedPropertyData>();
            GetParameters();
            isDirty = false;

            foreach (var parameter in m_Parameters)
            {
                if (typeof(UnityEventBase).IsAssignableFrom(parameter.Type))
                {
                    parameter.AddAttribute(new HideInInspector());
                }
            }
        }