예제 #1
0
        private void CustomizeLabel(Rect area, SerializedProperty property, int index)
        {
            var targ = this.serializedObject.targetObject as i_TriggerRandomElimination;

            if (!Application.isPlaying ||
                this.serializedObject.isEditingMultipleObjects ||
                targ == null)
            {
                TriggerPropertyDrawer.DrawDefaultListElementLabel(area, property, index);
            }
            else
            {
                if (targ.TargetHasBeenUsed(index))
                {
                    var r0 = new Rect(area.xMin, area.yMin, Mathf.Min(36f, area.width), EditorGUIUtility.singleLineHeight);
                    var r1 = new Rect(r0.xMax, area.yMin, Mathf.Max(0f, area.width - r0.width), EditorGUIUtility.singleLineHeight);
                    EditorGUI.LabelField(r0, index.ToString("X 00:"));
                    TriggerTargetPropertyDrawer.DrawTriggerActivationTypeDropdown(r1, property, false);
                }
                else
                {
                    TriggerPropertyDrawer.DrawDefaultListElementLabel(area, property, index);
                }
            }
        }
예제 #2
0
        public static void DrawDefaultListElementLabel(Rect area, SerializedProperty property, int index)
        {
            var r0 = new Rect(area.xMin, area.yMin, Mathf.Min(25f, area.width), EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(r0.xMax, area.yMin, Mathf.Max(0f, area.width - r0.width), EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(r0, index.ToString("00:"));
            TriggerTargetPropertyDrawer.DrawTriggerActivationTypeDropdown(r1, property, false);
        }
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var targProp = element.FindPropertyRelative(TriggerTargetPropertyDrawer.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;
            var        actInfo      = TriggerTargetPropertyDrawer.GetTriggerActivationInfo(element);
            GUIContent labelContent = EditorHelper.TempContent(index.ToString("00: ") + actInfo.ActivationTypeDisplayName);

            if (this.CustomizeEntryLabel != null)
            {
                this.CustomizeEntryLabel(labelContent, index);
            }
            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;

                EditorGUI.LabelField(labelRect, labelContent);
                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, area.width, EditorGUIUtility.singleLineHeight);

                trigRect = EditorGUI.PrefixLabel(labelRect, labelContent);
            }

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

            if (EditorGUI.EndChangeCheck())
            {
                targProp.objectReferenceValue = TriggerTargetPropertyDrawer.IsValidTriggerTarget(targObj, actInfo.ActivationType) ? targObj : null;
            }
            EditorGUI.EndProperty();

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }
        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 = TriggerTargetPropertyDrawer.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();
        }
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var targProp = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG);
            var actProp  = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_ACTIVATIONTYPE);
            //var act = (TriggerActivationType)actProp.enumValueIndex;
            var act = actProp.GetEnumValue <TriggerActivationType>();

            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;
            GUIContent labelContent = EditorHelper.TempContent(index.ToString("00: ") + act.ToString()); //(act == TriggerActivationType.TriggerAllOnTarget) ? EditorHelper.TempContent("Target") : EditorHelper.TempContent(string.Format("Target ({0})", act));

            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;

                EditorGUI.LabelField(labelRect, labelContent);
                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, area.width, EditorGUIUtility.singleLineHeight);

                trigRect = EditorGUI.PrefixLabel(labelRect, labelContent);
            }

            //Draw Triggerable - this is the simple case to make a clean designer set up for newbs

            /*
             * var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue);
             * var newTargGo = EditorGUI.ObjectField(trigRect, GUIContent.none, targGo, typeof(GameObject), true) as GameObject;
             * if (newTargGo != targGo)
             * {
             *  targGo = newTargGo;
             *  targProp.objectReferenceValue = (targGo != null) ? targGo.transform : null;
             * }
             */
            EditorGUI.BeginChangeCheck();
            var targObj = TriggerTargetPropertyDrawer.TargetObjectField(trigRect, GUIContent.none, targProp.objectReferenceValue);

            if (EditorGUI.EndChangeCheck())
            {
                targProp.objectReferenceValue = TriggerTargetPropertyDrawer.IsValidTriggerTarget(targObj, act) ? targObj : null;
            }
            EditorGUI.EndProperty();

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }
예제 #6
0
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var trigProp = element.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLETARG);
            var actProp  = element.FindPropertyRelative(TriggerTargetProps.PROP_ACTIVATIONTYPE);
            //var act = (TriggerActivationType)actProp.enumValueIndex;
            var act = actProp.GetEnumValue <TriggerActivationType>();

            const float MARGIN = 1.0f;

            if (act == TriggerActivationType.TriggerAllOnTarget)
            {
                //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
                var trigRect  = new Rect(area.xMin, area.yMin + MARGIN, area.width, EditorGUIUtility.singleLineHeight);
                var trigLabel = new GUIContent("Target");
                EditorGUI.BeginProperty(trigRect, trigLabel, trigProp);
                trigProp.objectReferenceValue = SPEditorGUI.ComponentField(trigRect,
                                                                           trigLabel,
                                                                           TriggerTargetPropertyDrawer.ValidateTriggerableTargAsMechanism(trigProp.objectReferenceValue) as Component,
                                                                           typeof(ITriggerableMechanism),
                                                                           true);
                EditorGUI.EndProperty();
            }
            else
            {
                //Draw Triggerable - this forces the user to use the advanced settings, not for newbs
                var trigRect  = new Rect(area.xMin, area.yMin + MARGIN, area.width, EditorGUIUtility.singleLineHeight);
                var trigLabel = new GUIContent("Advanced Target", "A target is not set, see advanced settings section to set a target.");

                if (trigProp.objectReferenceValue != null)
                {
                    var        go       = GameObjectUtil.GetGameObjectFromSource(trigProp.objectReferenceValue);
                    var        trigType = trigProp.objectReferenceValue.GetType();
                    GUIContent extraLabel;
                    switch (act)
                    {
                    case TriggerActivationType.SendMessage:
                        extraLabel = new GUIContent("(SendMessage) " + go.name);
                        break;

                    case TriggerActivationType.TriggerSelectedTarget:
                        extraLabel = new GUIContent("(TriggerSelectedTarget) " + go.name + " -> " + trigType.Name);
                        break;

                    case TriggerActivationType.CallMethodOnSelectedTarget:
                        extraLabel = new GUIContent("(CallMethodOnSelectedTarget) " + go.name + " -> " + trigType.Name + "." + element.FindPropertyRelative(TriggerTargetProps.PROP_METHODNAME).stringValue);
                        break;

                    default:
                        extraLabel = GUIContent.none;
                        break;
                    }
                    EditorGUI.LabelField(trigRect, trigLabel, extraLabel);
                }
                else
                {
                    EditorGUI.LabelField(trigRect, trigLabel, new GUIContent("No Target"), new GUIStyle("Label")
                    {
                        alignment = TextAnchor.MiddleCenter
                    });
                }
            }

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