public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            //Draw ActivationType Popup
            var r0  = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            var act = EventTriggerTargetPropertyDrawer.DrawTriggerActivationTypeDropdown(r0, property, true);

            //Draw Advanced
            var area = new Rect(position.xMin, r0.yMax, position.width, position.height - r0.height);

            switch (act)
            {
            case TriggerActivationType.TriggerAllOnTarget:
                this.DrawAdvanced_TriggerAll(area, property);
                break;

            case TriggerActivationType.TriggerSelectedTarget:
                this.DrawAdvanced_TriggerSelected(area, property);
                break;

            case TriggerActivationType.SendMessage:
                this.DrawAdvanced_SendMessage(area, property);
                break;

            case TriggerActivationType.CallMethodOnSelectedTarget:
                this.DrawAdvanced_CallMethodOnSelected(area, property);
                break;

            case TriggerActivationType.EnableTarget:
                this.DrawAdvanced_EnableTarget(area, property);
                break;

            case TriggerActivationType.DestroyTarget:
                this.DrawAdvanced_DestroyTarget(area, property);
                break;
            }

            EditorGUI.EndProperty();
        }
Exemplo n.º 2
0
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var targProp = element.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG);

            const float MARGIN             = 1.0f;
            const float WEIGHT_FIELD_WIDTH = 60f;
            const float PERC_FIELD_WIDTH   = 45f;
            const float FULLWEIGHT_WIDTH   = WEIGHT_FIELD_WIDTH + PERC_FIELD_WIDTH;

            EditorGUI.BeginProperty(area, GUIContent.none, targProp);

            Rect trigRect;

            if (_drawWeight && area.width > FULLWEIGHT_WIDTH)
            {
                var top        = area.yMin + MARGIN;
                var labelRect  = new Rect(area.xMin, top, EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, EditorGUIUtility.singleLineHeight);
                var weightRect = new Rect(area.xMin + EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, top, WEIGHT_FIELD_WIDTH, EditorGUIUtility.singleLineHeight);
                var percRect   = new Rect(area.xMin + EditorGUIUtility.labelWidth - PERC_FIELD_WIDTH, top, PERC_FIELD_WIDTH, EditorGUIUtility.singleLineHeight);
                trigRect = new Rect(area.xMin + EditorGUIUtility.labelWidth, top, area.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);

                var   weightProp = element.FindPropertyRelative(PROP_WEIGHT);
                float weight     = weightProp.floatValue;

                if (this.OnDrawCustomizedEntryLabel != null)
                {
                    this.OnDrawCustomizedEntryLabel(labelRect, element, index);
                }
                else
                {
                    DrawDefaultListElementLabel(labelRect, element, index);
                }
                weightProp.floatValue = EditorGUI.FloatField(weightRect, weight);
                float p = (_totalWeight > 0f) ? (100f * weight / _totalWeight) : ((index == 0) ? 100f : 0f);
                EditorGUI.LabelField(percRect, string.Format("{0:0.#}%", p));
            }
            else
            {
                //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
                var top       = area.yMin + MARGIN;
                var labelRect = new Rect(area.xMin, top, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);
                trigRect = new Rect(area.xMin + EditorGUIUtility.labelWidth, top, area.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);

                if (this.OnDrawCustomizedEntryLabel != null)
                {
                    this.OnDrawCustomizedEntryLabel(labelRect, element, index);
                }
                else
                {
                    DrawDefaultListElementLabel(labelRect, element, index);
                }
            }

            //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
            EditorGUI.BeginChangeCheck();
            var targObj = EventTriggerTargetPropertyDrawer.TargetObjectField(trigRect, GUIContent.none, targProp.objectReferenceValue);

            if (EditorGUI.EndChangeCheck())
            {
                var actInfo = EventTriggerTargetPropertyDrawer.GetTriggerActivationInfo(element);
                targProp.objectReferenceValue = EventTriggerTarget.IsValidTriggerTarget(targObj, actInfo.ActivationType) ? targObj : null;
            }
            EditorGUI.EndProperty();

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }