//static float EventHeight = 83;

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // EditorGUI.HelpBox(position, "",MessageType.None);

            EditorGUI.BeginProperty(position, label, property);

            var DefaultPosition = position;

            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            property.FindPropertyRelative("name").stringValue = label.text;

            var height = EditorGUIUtility.singleLineHeight;
            // Calculate rects
            var activeRect = new Rect(position.x, position.y, 15, height);
            var LabelRect  = new Rect(position.x + 17, position.y, 100, height);


            // Draw fields - passs GUIContent.none to each so they are drawn without labels
            EditorGUI.PropertyField(activeRect, property.FindPropertyRelative("active"), GUIContent.none);
            EditorGUI.LabelField(LabelRect, label, EditorStyles.miniBoldLabel);

            //Set Rect to the Parameters Values
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(" "));

            // Calculate rects
            var typeRect   = new Rect(position.x - 30, position.y, 44, height);
            var valueRect  = new Rect(position.x - 30 + 45, position.y, position.width / 2 - 11, height);
            var ActionRect = new Rect(position.width / 2 + position.x - 30 + 40 - 5, position.y, (position.width / 2 - 7) - 16, height);
            var ShowRect   = new Rect(DefaultPosition.width + 6, position.y, 16, height - 1);

            EditorGUI.PropertyField(typeRect, property.FindPropertyRelative("type"), GUIContent.none);

            InputType current = (InputType)property.FindPropertyRelative("type").enumValueIndex;

            switch (current)
            {
            case InputType.Input:
                EditorGUI.PropertyField(valueRect, property.FindPropertyRelative("input"), GUIContent.none);
                break;

            case InputType.Key:
                EditorGUI.PropertyField(valueRect, property.FindPropertyRelative("key"), GUIContent.none);
                break;

            default:
                break;
            }

            EditorGUI.PropertyField(ActionRect, property.FindPropertyRelative("GetPressed"), GUIContent.none);

            SerializedProperty show = property.FindPropertyRelative("ShowEvents");


            show.boolValue = GUI.Toggle(ShowRect, show.boolValue, new GUIContent("" /*!show.boolValue ? "▼" : "▲"*/, "Show Events for the " + property.FindPropertyRelative("name").stringValue + " Input"), EditorStyles.foldout);

            //if (show.boolValue)
            //{
            //    DefaultPosition.y += EditorGUIUtility.singleLineHeight+3;



            //    InputButton enumValueIndex = (InputButton)property.FindPropertyRelative("GetPressed").enumValueIndex;



            //    switch (enumValueIndex)
            //    {
            //        case InputButton.Press:
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputPressed"));

            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputChanged"));

            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputUp"));

            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputDown"));
            //            break;
            //        case InputButton.Down:
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputDown"));

            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputChanged"));
            //            break;
            //        case InputButton.Up:
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputUp"));

            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputChanged"));
            //            break;
            //        case InputButton.LongPress:
            //            Rect LonRect = DefaultPosition;
            //            LonRect.height = EditorGUIUtility.singleLineHeight;
            //            EditorGUI.PropertyField(LonRect, property.FindPropertyRelative("LongPressTime"), new GUIContent("On Long Press", "Time the Input Should be Pressed"));
            //            DefaultPosition.y += EditorGUIUtility.singleLineHeight + 3;

            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnLongPress"), new GUIContent("On Long Press"));
            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnPressedNormalized"), new GUIContent("On Pressed Time Normalized"));
            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputDown"), new GUIContent("On Pressed Down"));
            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputUp"), new GUIContent("On Pressed Interrupted"));
            //            DefaultPosition.y += EventHeight;
            //            break;
            //        case InputButton.DoubleTap:
            //            Rect LonRect1 = DefaultPosition;
            //            LonRect1.height = EditorGUIUtility.singleLineHeight;
            //            EditorGUI.PropertyField(LonRect1, property.FindPropertyRelative("DoubleTapTime"), new GUIContent("Double Tap Time", "Time between the double tap"));
            //            DefaultPosition.y += EditorGUIUtility.singleLineHeight + 3;

            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnInputDown"), new GUIContent("On First Tap"));
            //            DefaultPosition.y += EventHeight;
            //            EditorGUI.PropertyField(DefaultPosition, property.FindPropertyRelative("OnDoubleTap"));
            //            break;
            //        default:
            //            break;
            //    }
            //}

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();
        }
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            if (property == null)
            {
                return;
            }

            SerializedProperty nameProperty   = property.FindPropertyRelative("name");
            SerializedProperty mirrorProperty = property.FindPropertyRelative("mirror");
            SerializedProperty typeProperty   = property.FindPropertyRelative("type");
            SerializedProperty valueProperty  = null;

            switch (typeProperty.enumValueIndex)
            {
            case (int)VRC_DataStorage.VrcDataType.Bool:
                valueProperty = property.FindPropertyRelative("valueBool");
                break;

            case (int)VRC_DataStorage.VrcDataType.Float:
                valueProperty = property.FindPropertyRelative("valueFloat");
                break;

            case (int)VRC_DataStorage.VrcDataType.Int:
                valueProperty = property.FindPropertyRelative("valueInt");
                break;

            case (int)VRC_DataStorage.VrcDataType.String:
                valueProperty = property.FindPropertyRelative("valueString");
                break;

            case (int)VRC_DataStorage.VrcDataType.SerializeObject:
                valueProperty = property.FindPropertyRelative("serializeComponent");
                break;

            case (int)VRC_DataStorage.VrcDataType.None:
            case (int)VRC_DataStorage.VrcDataType.SerializeBytes:
                break;
            }

            EditorGUI.BeginProperty(rect, label, property);

            int  baseWidth     = (int)(rect.width / 4);
            Rect nameRect      = new Rect(rect.x, rect.y, baseWidth, rect.height);
            Rect mirrorRect    = new Rect(rect.x + baseWidth, rect.y, baseWidth, rect.height);
            Rect typeRect      = new Rect(rect.x + baseWidth * 2, rect.y, baseWidth, rect.height);
            Rect valueRect     = new Rect(rect.x + baseWidth * 3, rect.y, baseWidth, rect.height);
            Rect typeValueRect = new Rect(rect.x + baseWidth * 2, rect.y, baseWidth * 2, rect.height);

            EditorGUI.PropertyField(nameRect, nameProperty, GUIContent.none);
            EditorGUI.PropertyField(mirrorRect, mirrorProperty, GUIContent.none);

            switch (mirrorProperty.enumValueIndex)
            {
            case (int)VRC_DataStorage.VrcDataMirror.None:
                if (valueProperty == null)
                {
                    VRC_EditorTools.FilteredEnumPopup <VRC_DataStorage.VrcDataType>(typeValueRect, typeProperty, t => true);
                }
                else
                {
                    VRC_EditorTools.FilteredEnumPopup <VRC_DataStorage.VrcDataType>(typeRect, typeProperty, t => true);
                    EditorGUI.PropertyField(valueRect, valueProperty, GUIContent.none);
                }
                break;

            case (int)VRC_DataStorage.VrcDataMirror.SerializeComponent:
                typeProperty.enumValueIndex = (int)VRC_DataStorage.VrcDataType.SerializeObject;
                EditorGUI.PropertyField(typeValueRect, valueProperty, GUIContent.none);
                break;

            default:
                VRC_EditorTools.FilteredEnumPopup <VRC_DataStorage.VrcDataType>(typeValueRect, typeProperty, t => true);
                break;
            }

            EditorGUI.EndProperty();
        }
Beispiel #3
0
        static void DrawerPerspectiveType(ISerializedCamera p, Editor owner)
        {
            var cam = p.baseCameraSettings;

            var targets = p.serializedObject.targetObjects;
            var camera0 = targets[0] as Camera;

            float fovCurrentValue;
            bool  multipleDifferentFovValues = false;
            bool  isPhysicalCamera           = p.projectionMatrixMode.intValue == (int)ProjectionMatrixMode.PhysicalPropertiesBased;

            var rect = EditorGUILayout.GetControlRect();

            var guiContent = EditorGUI.BeginProperty(rect, Styles.FOVAxisModeContent, cam.fovAxisMode);

            EditorGUI.showMixedValue = cam.fovAxisMode.hasMultipleDifferentValues;

            CoreEditorUtils.DrawEnumPopup <Camera.FieldOfViewAxis>(rect, guiContent, cam.fovAxisMode);

            bool fovAxisVertical = cam.fovAxisMode.intValue == 0;

            if (!fovAxisVertical && !cam.fovAxisMode.hasMultipleDifferentValues)
            {
                float aspectRatio = isPhysicalCamera ? cam.sensorSize.vector2Value.x / cam.sensorSize.vector2Value.y : camera0.aspect;
                // camera.aspect is not serialized so we have to check all targets.
                fovCurrentValue = Camera.VerticalToHorizontalFieldOfView(camera0.fieldOfView, aspectRatio);
                if (targets.Cast <Camera>().Any(camera => camera.fieldOfView != fovCurrentValue))
                {
                    multipleDifferentFovValues = true;
                }
            }
            else
            {
                fovCurrentValue            = cam.verticalFOV.floatValue;
                multipleDifferentFovValues = cam.fovAxisMode.hasMultipleDifferentValues;
            }

            EditorGUI.showMixedValue = multipleDifferentFovValues;
            var content = EditorGUI.BeginProperty(EditorGUILayout.BeginHorizontal(), Styles.fieldOfViewContent, cam.verticalFOV);

            EditorGUI.BeginDisabledGroup(p.projectionMatrixMode.hasMultipleDifferentValues || isPhysicalCamera && (cam.sensorSize.hasMultipleDifferentValues || cam.fovAxisMode.hasMultipleDifferentValues));
            EditorGUI.BeginChangeCheck();
            s_FovLastValue = EditorGUILayout.Slider(content, fovCurrentValue, 0.00001f, 179f);
            s_FovChanged   = EditorGUI.EndChangeCheck();
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndProperty();
            EditorGUI.showMixedValue = false;

            Drawer_FieldClippingPlanes(p, owner);

            content = EditorGUI.BeginProperty(EditorGUILayout.BeginHorizontal(), Styles.physicalCameraContent, p.projectionMatrixMode);
            EditorGUI.showMixedValue = p.projectionMatrixMode.hasMultipleDifferentValues;

            EditorGUI.BeginChangeCheck();
            isPhysicalCamera = EditorGUILayout.Toggle(content, isPhysicalCamera);
            if (EditorGUI.EndChangeCheck())
            {
                p.projectionMatrixMode.intValue = isPhysicalCamera ? (int)ProjectionMatrixMode.PhysicalPropertiesBased : (int)ProjectionMatrixMode.Implicit;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndProperty();

            EditorGUI.showMixedValue = false;
            if (s_FovChanged)
            {
                if (!isPhysicalCamera || p.projectionMatrixMode.hasMultipleDifferentValues)
                {
                    cam.verticalFOV.floatValue = fovAxisVertical
                        ? s_FovLastValue
                        : Camera.HorizontalToVerticalFieldOfView(s_FovLastValue, camera0.aspect);
                }
                else if (!p.projectionMatrixMode.hasMultipleDifferentValues)
                {
                    cam.verticalFOV.floatValue = fovAxisVertical
                        ? s_FovLastValue
                        : Camera.HorizontalToVerticalFieldOfView(s_FovLastValue, camera0.aspect);
                }
            }
        }
Beispiel #4
0
    public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
    {
        // We get a local reference to the MultilineAttribute as we use it twice in this method and it
        // saves calling the logic twice for minimal optimization, etc...
        var multiline = multilineAttribute;

        EditorGUI.BeginProperty(position, label, prop);

        // Copy the position out so we can calculate the position of our HelpBox without affecting the
        // original position.
        var helpPos = position;

        helpPos.height -= baseHeight + marginHeight;


        if (multiline != null)
        {
            helpPos.height -= addedHeight;
        }

        // Renders the HelpBox in the Unity inspector UI.
        EditorGUI.HelpBox(helpPos, helpAttribute.text, helpAttribute.type);

        position.y     += helpPos.height + marginHeight;
        position.height = baseHeight;


        // If we have a RangeAttribute on our field, we need to handle the PropertyDrawer differently to
        // keep the same style as Unity's default.
        var range = rangeAttribute;

        if (range != null)
        {
            if (prop.propertyType == SerializedPropertyType.Float)
            {
                EditorGUI.Slider(position, prop, range.min, range.max, label);
            }
            else if (prop.propertyType == SerializedPropertyType.Integer)
            {
                EditorGUI.IntSlider(position, prop, (int)range.min, (int)range.max, label);
            }
            else
            {
                // Not numeric so draw standard property field as punishment for adding RangeAttribute to
                // a property which can not have a range :P
                EditorGUI.PropertyField(position, prop, label);
            }
        }
        else if (multiline != null)
        {
            // Here's where we handle the PropertyDrawer differently if we have a MultiLineAttribute, to try
            // and keep some kind of multiline text area. This is not identical to Unity's default but is
            // better than nothing...
            if (prop.propertyType == SerializedPropertyType.String)
            {
                var style = GUI.skin.label;
                var size  = style.CalcHeight(label, EditorGUIUtility.currentViewWidth);

                EditorGUI.LabelField(position, label);

                position.y      += size;
                position.height += addedHeight - size;

                // Fixed text dissappearing thanks to: http://answers.unity3d.com/questions/244043/textarea-does-not-work-text-dissapears-solution-is.html
                prop.stringValue = EditorGUI.TextArea(position, prop.stringValue);
            }
            else
            {
                // Again with a MultilineAttribute on a non-text field deserves for the standard property field
                // to be drawn as punishment :P
                EditorGUI.PropertyField(position, prop, label);
            }
        }
        else
        {
            // If we get to here it means we're drawing the default property field below the HelpBox. More custom
            // and built in PropertyDrawers could be implemented to enable HelpBox but it could easily make for
            // hefty else/if block which would need refactoring!
            EditorGUI.PropertyField(position, prop, label);
        }

        EditorGUI.EndProperty();
    }
Beispiel #5
0
        private void DrawEventListener(Rect rect, int index, bool isactive, bool isfocused)
        {
            SerializedProperty arrayElementAtIndex = this.m_ListenersArray.GetArrayElementAtIndex(index);

            ++rect.y;
            Rect[]             rowRects          = this.GetRowRects(rect);
            Rect               position1         = rowRects[0];
            Rect               position2         = rowRects[1];
            Rect               rect1             = rowRects[2];
            Rect               position3         = rowRects[3];
            SerializedProperty propertyRelative1 = arrayElementAtIndex.FindPropertyRelative("m_CallState");
            SerializedProperty propertyRelative2 = arrayElementAtIndex.FindPropertyRelative("m_Mode");
            SerializedProperty propertyRelative3 = arrayElementAtIndex.FindPropertyRelative("m_Arguments");
            SerializedProperty propertyRelative4 = arrayElementAtIndex.FindPropertyRelative("m_Target");
            SerializedProperty propertyRelative5 = arrayElementAtIndex.FindPropertyRelative("m_MethodName");
            Color              backgroundColor   = GUI.backgroundColor;

            GUI.backgroundColor = Color.white;
            EditorGUI.PropertyField(position1, propertyRelative1, GUIContent.none);
            EditorGUI.BeginChangeCheck();
            GUI.Box(position2, GUIContent.none);
            EditorGUI.PropertyField(position2, propertyRelative4, GUIContent.none);
            if (EditorGUI.EndChangeCheck())
            {
                propertyRelative5.stringValue = (string)null;
            }
            PersistentListenerMode persistentListenerMode = UnityEventDrawer.GetMode(propertyRelative2);

            if (propertyRelative4.objectReferenceValue == (UnityEngine.Object)null || string.IsNullOrEmpty(propertyRelative5.stringValue))
            {
                persistentListenerMode = PersistentListenerMode.Void;
            }
            SerializedProperty propertyRelative6;

            switch (persistentListenerMode)
            {
            case PersistentListenerMode.Object:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_ObjectArgument");
                break;

            case PersistentListenerMode.Int:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_IntArgument");
                break;

            case PersistentListenerMode.Float:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_FloatArgument");
                break;

            case PersistentListenerMode.String:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_StringArgument");
                break;

            case PersistentListenerMode.Bool:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_BoolArgument");
                break;

            default:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_IntArgument");
                break;
            }
            string stringValue = propertyRelative3.FindPropertyRelative("m_ObjectArgumentAssemblyTypeName").stringValue;

            System.Type type = typeof(UnityEngine.Object);
            if (!string.IsNullOrEmpty(stringValue))
            {
                type = System.Type.GetType(stringValue, false) ?? typeof(UnityEngine.Object);
            }
            if (persistentListenerMode == PersistentListenerMode.Object)
            {
                EditorGUI.BeginChangeCheck();
                UnityEngine.Object @object = EditorGUI.ObjectField(position3, GUIContent.none, propertyRelative6.objectReferenceValue, type, true);
                if (EditorGUI.EndChangeCheck())
                {
                    propertyRelative6.objectReferenceValue = @object;
                }
            }
            else if (persistentListenerMode != PersistentListenerMode.Void && persistentListenerMode != PersistentListenerMode.EventDefined)
            {
                EditorGUI.PropertyField(position3, propertyRelative6, GUIContent.none);
            }
            EditorGUI.BeginDisabledGroup(propertyRelative4.objectReferenceValue == (UnityEngine.Object)null);
            EditorGUI.BeginProperty(rect1, GUIContent.none, propertyRelative5);
            GUIContent content;

            if (EditorGUI.showMixedValue)
            {
                content = EditorGUI.mixedValueContent;
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (propertyRelative4.objectReferenceValue == (UnityEngine.Object)null || string.IsNullOrEmpty(propertyRelative5.stringValue))
                {
                    stringBuilder.Append("No Function");
                }
                else if (!UnityEventDrawer.IsPersistantListenerValid(this.m_DummyEvent, propertyRelative5.stringValue, propertyRelative4.objectReferenceValue, UnityEventDrawer.GetMode(propertyRelative2), type))
                {
                    string             str = "UnknownComponent";
                    UnityEngine.Object objectReferenceValue = propertyRelative4.objectReferenceValue;
                    if (objectReferenceValue != (UnityEngine.Object)null)
                    {
                        str = objectReferenceValue.GetType().Name;
                    }
                    stringBuilder.Append(string.Format("<Missing {0}.{1}>", (object)str, (object)propertyRelative5.stringValue));
                }
                else
                {
                    stringBuilder.Append(propertyRelative4.objectReferenceValue.GetType().Name);
                    if (!string.IsNullOrEmpty(propertyRelative5.stringValue))
                    {
                        stringBuilder.Append(".");
                        if (propertyRelative5.stringValue.StartsWith("set_"))
                        {
                            stringBuilder.Append(propertyRelative5.stringValue.Substring(4));
                        }
                        else
                        {
                            stringBuilder.Append(propertyRelative5.stringValue);
                        }
                    }
                }
                content = GUIContent.Temp(stringBuilder.ToString());
            }
            if (GUI.Button(rect1, content, EditorStyles.popup))
            {
                UnityEventDrawer.BuildPopupList(propertyRelative4.objectReferenceValue, this.m_DummyEvent, arrayElementAtIndex).DropDown(rect1);
            }
            EditorGUI.EndProperty();
            EditorGUI.EndDisabledGroup();
            GUI.backgroundColor = backgroundColor;
        }
Beispiel #6
0
        private void DrawEventListener(Rect rect, int index, bool isactive, bool isfocused)
        {
            var arrayElementAtIndex = _listenersArray.GetArrayElementAtIndex(index);

            ++rect.y;
            var rowRects  = GetRowRects(rect);
            var position1 = rowRects[0];
            var position2 = rowRects[1];
            var rect1     = rowRects[2];
            var position3 = rowRects[3];
            SerializedProperty propertyRelative1 = arrayElementAtIndex.FindPropertyRelative("_callState");
            SerializedProperty propertyRelative2 = arrayElementAtIndex.FindPropertyRelative("_mode");
            SerializedProperty propertyRelative3 = arrayElementAtIndex.FindPropertyRelative("_arguments");
            //SerializedProperty propertyRelative4 = arrayElementAtIndex.FindPropertyRelative("_target");
            SerializedProperty propertyRelative5 = arrayElementAtIndex.FindPropertyRelative("_methodName");
            SerializedProperty propertyRelative7 = arrayElementAtIndex.FindPropertyRelative("_vmName");

            _targetIndex = _targetVms.IndexOf(propertyRelative7.stringValue);

            var backColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.white;
            EditorGUI.PropertyField(position1, propertyRelative1, GUIContent.none);
            EditorGUI.BeginChangeCheck();
            GUI.Box(position2, GUIContent.none);
            // EditorGUI.PropertyField(position2, propertyRelative4, GUIContent.none);
            var newTargetIndex = EditorGUI.Popup(position2, _targetIndex, _targetVms.ToArray());

            if (_targetIndex != newTargetIndex)
            {
                propertyRelative7.stringValue = _targetVms[newTargetIndex];
            }
            if (EditorGUI.EndChangeCheck())
            {
                propertyRelative5.stringValue = null;
            }
            PersistentListenerMode persistentListenerMode = GetMode(propertyRelative2);

            if (string.IsNullOrEmpty(propertyRelative7.stringValue) || string.IsNullOrEmpty(propertyRelative5.stringValue))
            {
                persistentListenerMode = PersistentListenerMode.Void;
            }
            SerializedProperty propertyRelative6;

            switch (persistentListenerMode)
            {
            case PersistentListenerMode.Object:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_ObjectArgument");
                break;

            case PersistentListenerMode.Int:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_IntArgument");
                break;

            case PersistentListenerMode.Float:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_FloatArgument");
                break;

            case PersistentListenerMode.String:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_StringArgument");
                break;

            case PersistentListenerMode.Bool:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_BoolArgument");
                break;

            default:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_IntArgument");
                break;
            }
            string stringValue = propertyRelative3.FindPropertyRelative("m_ObjectArgumentAssemblyTypeName").stringValue;

            System.Type type = typeof(UnityEngine.Object);
            if (!string.IsNullOrEmpty(stringValue))
            {
                type = System.Type.GetType(stringValue, false) ?? typeof(UnityEngine.Object);
            }
            switch (persistentListenerMode)
            {
            case PersistentListenerMode.EventDefined:
            case PersistentListenerMode.Void:
                var funcMenu = BuildPopupList(propertyRelative7.stringValue, _dummyEvent, arrayElementAtIndex);
                using (new EditorGUI.DisabledScope(!Util.ViewModelProvider.IsViewModelTypeNameValid(propertyRelative7.stringValue) || funcMenu.GetItemCount() <= 0))
                {
                    EditorGUI.BeginProperty(rect1, GUIContent.none, propertyRelative5);
                    GUIContent content;
                    if (EditorGUI.showMixedValue)
                    {
                        content = GetEditorGUIMixedValueContent();
                    }
                    else
                    {
                        var sb = new StringBuilder();
                        if (funcMenu.GetItemCount() <= 0)
                        {
                            sb.Append("No Function");
                        }
                        else
                        {
                            sb.Append(propertyRelative7.stringValue);
                            if (!string.IsNullOrEmpty(propertyRelative5.stringValue))
                            {
                                sb.Append(".");
                                if (propertyRelative5.stringValue.StartsWith("set_"))
                                {
                                    sb.Append(propertyRelative5.stringValue.Substring(4));
                                }
                                else
                                {
                                    sb.Append(propertyRelative5.stringValue);
                                }
                            }
                        }
                        content = GetGUIContentTemp(sb.ToString());
                        // StringBuilder stringBuilder = new StringBuilder();
                        // if (propertyRelative4.objectReferenceValue == (UnityEngine.Object)null || string.IsNullOrEmpty(propertyRelative5.stringValue))
                        //     stringBuilder.Append("No Function");
                        // else if (!UnityEventDrawer.IsPersistantListenerValid(_dummyEvent, propertyRelative5.stringValue, propertyRelative4.objectReferenceValue, GetMode(propertyRelative2), type))
                        // {
                        //     string str = "UnknownComponent";
                        //     UnityEngine.Object objectReferenceValue = propertyRelative4.objectReferenceValue;
                        //     if (objectReferenceValue != (UnityEngine.Object)null)
                        //         str = objectReferenceValue.GetType().Name;
                        //     stringBuilder.Append(string.Format("<Missing {0}.{1}>", (object)str, (object)propertyRelative5.stringValue));
                        // }
                        // else
                        // {
                        //     stringBuilder.Append(propertyRelative4.objectReferenceValue.GetType().Name);
                        //     if (!string.IsNullOrEmpty(propertyRelative5.stringValue))
                        //     {
                        //         stringBuilder.Append(".");
                        //         if (propertyRelative5.stringValue.StartsWith("set_"))
                        //             stringBuilder.Append(propertyRelative5.stringValue.Substring(4));
                        //         else
                        //             stringBuilder.Append(propertyRelative5.stringValue);
                        //     }
                        // }
                        // content = GetGUIContentTemp(stringBuilder.ToString());
                    }
                    if (GUI.Button(rect1, content, EditorStyles.popup))
                    {
                        funcMenu.DropDown(rect1);
                    }
                    EditorGUI.EndProperty();
                }
                GUI.backgroundColor = backColor;
                break;

            case PersistentListenerMode.Object:
                EditorGUI.BeginChangeCheck();
                UnityEngine.Object @object = EditorGUI.ObjectField(position3, GUIContent.none, propertyRelative6.objectReferenceValue, type, true);
                if (EditorGUI.EndChangeCheck())
                {
                    propertyRelative6.objectReferenceValue = @object;
                    goto case PersistentListenerMode.EventDefined;
                }
                else
                {
                    goto case PersistentListenerMode.EventDefined;
                }

            default:
                EditorGUI.PropertyField(position3, propertyRelative6, GUIContent.none);
                goto case PersistentListenerMode.EventDefined;
            }
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.String)
        {
            EditorGUI.BeginProperty(position, label, property);

            var attrib = this.attribute as TagSelectorAttribute;

            if (attrib.useDefaultTagFieldDrawer)
            {
                property.stringValue = EditorGUI.TagField(position, label, property.stringValue);
            }
            else
            {
                //generate the taglist + custom tags
                List <string> tagList = new List <string> {
                    "<NoTag>"
                };
                tagList.AddRange(UnityEditorInternal.InternalEditorUtility.tags);
                string propertyString = property.stringValue;
                int    index          = -1;
                if (propertyString == "")
                {
                    //The tag is empty
                    index = 0; //first index is the special <notag> entry
                }
                else
                {
                    //check if there is an entry that matches the entry and get the index
                    //we skip index 0 as that is a special custom case
                    for (int i = 1; i < tagList.Count; i++)
                    {
                        if (tagList[i] == propertyString)
                        {
                            index = i;
                            break;
                        }
                    }
                }

                //Draw the popup box with the current selected index
                index = EditorGUI.Popup(position, label.text, index, tagList.ToArray());

                //Adjust the actual string value of the property based on the selection
                if (index == 0)
                {
                    property.stringValue = "";
                }
                else if (index >= 1)
                {
                    property.stringValue = tagList[index];
                }
                else
                {
                    property.stringValue = "";
                }
            }

            EditorGUI.EndProperty();
        }
        else
        {
            EditorGUI.PropertyField(position, property, label);
        }
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        serializedObject.Update();

        SerializedProperty sortingLayerID = serializedObject.FindProperty("m_SortingLayerID");
        SerializedProperty sortingOrder   = serializedObject.FindProperty("m_SortingOrder");

        Rect firstHoriz = EditorGUILayout.BeginHorizontal();

        EditorGUI.BeginChangeCheck();

        EditorGUI.BeginProperty(firstHoriz, GUIContent.none, sortingLayerID);

        string[] layerNames = GetSortingLayerNames();
        int[]    layerID    = GetSortingLayerUniqueIDs();

        int selected = -1;
        //What is selected?
        int sID = sortingLayerID.intValue;

        for (int i = 0; i < layerID.Length; i++)
        {
            //Debug.Log(sID + " " + layerID[i]);
            if (sID == layerID[i])
            {
                selected = i;
            }
        }

        if (selected == -1)
        {
            //Select Default.
            for (int i = 0; i < layerID.Length; i++)
            {
                if (layerID[i] == 0)
                {
                    selected = i;
                }
            }
        }

        selected = EditorGUILayout.Popup("Sorting Layer", selected, layerNames);

        //Translate to ID
        sortingLayerID.intValue = layerID[selected];


        EditorGUI.EndProperty();

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUI.BeginChangeCheck();

        EditorGUILayout.PropertyField(sortingOrder, new GUIContent("Order in Layer"));


        EditorGUILayout.EndHorizontal();
        serializedObject.ApplyModifiedProperties();
    }
Beispiel #9
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        const float textWidthPercent  = 0.3f;
        const float textSpeedPercent  = 0.6f;
        const float textRemovePercent = 0.1f;

        Undo.RecordObject(property.serializedObject.targetObject, "name");

        // Using BeginProperty / EndProperty on the parent property means that
        // prefab override logic works on the entire property.
        EditorGUI.BeginProperty(position, label, property);

        // Draw label
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Speed lookup table"));

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        HeightmapSpeedLookupTable propertyLut = (HeightmapSpeedLookupTable)fieldInfo.GetValue(property.serializedObject.targetObject);

        Rect rectNextKeyAdd   = new Rect(position.x + position.width * textWidthPercent, position.y + (propertyLut.Keys.Count) * lineHeight, position.width * (1.0f - textWidthPercent), lineHeight);
        Rect rectNextKeyInput = new Rect(position.x, position.y + (propertyLut.Keys.Count) * lineHeight, position.width * textWidthPercent, lineHeight);

        if (propertyLut.Keys.Count == 0)
        {
            Rect rectObjectInput = new Rect(position.x, position.y + 1 * lineHeight, position.width, lineHeight);

            TextAsset textAsset = (TextAsset)EditorGUI.ObjectField(rectObjectInput, "Speed lookup table json", null, typeof(TextAsset), false);
            if (textAsset != null)
            {
                propertyLut.Overwrite(textAsset.text);
            }
        }

        for (int i = 0; i < propertyLut.Keys.Count; i++)
        {
            Rect rectText      = new Rect(position.x, position.y + i * lineHeight, position.width * textWidthPercent, lineHeight);
            Rect rectSpeed     = new Rect(position.x + position.width * textWidthPercent, position.y + i * lineHeight, position.width * textSpeedPercent, lineHeight);
            Rect rectRemoveKey = new Rect(position.x + position.width * (textWidthPercent + textSpeedPercent), position.y + i * lineHeight, position.width * textRemovePercent, lineHeight);

            EditorGUI.LabelField(rectText, propertyLut.Keys[i].ToString());

            float val = EditorGUI.DelayedFloatField(rectSpeed, propertyLut[propertyLut.Keys[i]]);
            if (val != propertyLut[propertyLut.Keys[i]])
            {
                propertyLut[propertyLut.Keys[i]] = val;
            }

            if (!EditorGUI.Toggle(rectRemoveKey, true))
            {
                propertyLut.Remove(propertyLut.Keys[i]);
            }
        }

        EditorGUI.BeginChangeCheck();
        nextInd = EditorGUI.DelayedIntField(rectNextKeyInput, nextInd);
        if (EditorGUI.EndChangeCheck())
        {
            propertyLut[nextInd] = default;
        }

        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();

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

            float x     = position.x;
            float y     = position.y;
            float width = position.width;

            // Draw label
            EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            var entries = property.FindPropertyRelative("entries");

            if (entries.arraySize > 0)
            {
                float actionWidth = .25f * width;
                float targetWidth = .6f * width;
                float delayWidth  = .1f * width;
                float buttonWidth = .05f * width;

                for (int i = 0; i < entries.arraySize; ++i)
                {
                    y += k_LineHeight + k_Spacing;

                    var entry = entries.GetArrayElementAtIndex(i);

                    float rowX = x;

                    // Calculate rects
                    Rect actionRect = new Rect(rowX, y, actionWidth, k_LineHeight);
                    rowX += actionWidth;

                    Rect targetRect = new Rect(rowX, y, targetWidth, k_LineHeight);
                    rowX += targetWidth;

                    Rect delayRect = new Rect(rowX, y, delayWidth, k_LineHeight);
                    rowX += delayWidth;

                    Rect buttonRect = new Rect(rowX, y, buttonWidth, k_LineHeight);
                    rowX += buttonWidth;

                    // Draw fields - passs GUIContent.none to each so they are drawn without labels

                    if (entry.FindPropertyRelative("action").enumValueIndex !=
                        (int)TimedObjectActivator.Action.ReloadLevel)
                    {
                        EditorGUI.PropertyField(actionRect, entry.FindPropertyRelative("action"), GUIContent.none);
                        EditorGUI.PropertyField(targetRect, entry.FindPropertyRelative("target"), GUIContent.none);
                    }
                    else
                    {
                        actionRect.width = actionRect.width + targetRect.width;
                        EditorGUI.PropertyField(actionRect, entry.FindPropertyRelative("action"), GUIContent.none);
                    }

                    EditorGUI.PropertyField(delayRect, entry.FindPropertyRelative("delay"), GUIContent.none);
                    if (GUI.Button(buttonRect, "-"))
                    {
                        entries.DeleteArrayElementAtIndex(i);
                        break;
                    }
                }
            }

            // add & sort buttons
            y += k_LineHeight + k_Spacing;

            var addButtonRect = new Rect(position.x + position.width - 120, y, 60, k_LineHeight);

            if (GUI.Button(addButtonRect, "Add"))
            {
                entries.InsertArrayElementAtIndex(entries.arraySize);
            }

            var sortButtonRect = new Rect(position.x + position.width - 60, y, 60, k_LineHeight);

            if (GUI.Button(sortButtonRect, "Sort"))
            {
                bool changed = true;
                while (entries.arraySize > 1 && changed)
                {
                    changed = false;
                    for (int i = 0; i < entries.arraySize - 1; ++i)
                    {
                        var e1 = entries.GetArrayElementAtIndex(i);
                        var e2 = entries.GetArrayElementAtIndex(i + 1);

                        if (e1.FindPropertyRelative("delay").floatValue > e2.FindPropertyRelative("delay").floatValue)
                        {
                            entries.MoveArrayElement(i + 1, i);
                            changed = true;
                            break;
                        }
                    }
                }
            }


            // Set indent back to what it was
            EditorGUI.indentLevel = indent;
            //


            EditorGUI.EndProperty();
        }
Beispiel #11
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        NPVoxMeshOutput          target        = property.serializedObject.targetObject as NPVoxMeshOutput;
        NPVoxNormalProcessorList processorList = target.NormalProcessors;

        EditorGUI.BeginProperty(position, label, property);
        // Customize gui style
        Color previousBGColor = GUI.backgroundColor;
        Color previousFGColor = GUI.contentColor;

        GUI.backgroundColor = s_colorBackgroundGUIPrimary;
        // GUI.contentColor = s_colorForegroundGUI; // Doesn't seem to work

        // Header + Expand / Collapse Button
        GUILayout.BeginHorizontal();
        GUILayout.Label("Normal Processors (" + processorList.GetProcessors().Count + ")", GUILayout.Width(s_widthHeaderLabel));

        if (!m_expanded)
        {
            if (GUILayout.Button("Expand", GUILayout.Width(s_widthExpandButton)))
            {
                m_expanded = true;
            }
        }
        else
        {
            if (GUILayout.Button("Collapse", GUILayout.Width(s_widthExpandButton)))
            {
                m_expanded = false;
            }
        }

        GUILayout.EndHorizontal();

        if (!m_expanded)
        {
            GUILayout.Space(12.0f);
        }

        // List management
        if (m_expanded)
        {
            Dictionary <string, System.Type> processorClasses = new Dictionary <string, System.Type>();
            processorClasses.Add("<None>", null);
            List <System.Type> allTypes = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPVoxAttributeNormalProcessorListItem)));
            allTypes = allTypes.OrderBy(x => (( NPVoxAttributeNormalProcessorListItem )x.GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0]).ListPriority).ToList();
            foreach (System.Type factoryType in allTypes)
            {
                NPVoxAttributeNormalProcessorListItem attr = ( NPVoxAttributeNormalProcessorListItem )factoryType.GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0];

                if (attr.ClassType.BaseType != typeof(NPVoxNormalProcessor))
                {
                    continue;
                }

                processorClasses.Add(attr.EditorName, factoryType);
            }

            string[] processorKeys = processorClasses.Keys.ToArray();

            GUILayout.BeginHorizontal();
            GUILayout.Space(s_widthTab);
            m_indexPopupAddProcessor = EditorGUILayout.Popup(m_indexPopupAddProcessor, processorKeys);
            bool optionAdded = GUILayout.Button("Add");
            GUILayout.EndHorizontal();

            if (optionAdded)
            {
                System.Type processorClass = processorClasses[processorKeys[m_indexPopupAddProcessor]];
                if (processorClass != null)
                {
                    if (UnityEditor.AssetDatabase.GetAssetPath(processorList).Length == 0)
                    {
                        target.IncludeSubAssets(UnityEditor.AssetDatabase.GetAssetPath(target));
                    }
                    processorList.AddProcessor(processorClass)
                    .AddToAsset(UnityEditor.AssetDatabase.GetAssetPath(target));
                }
            }

            NPVoxNormalProcessor itemToMoveUp   = null;
            NPVoxNormalProcessor itemToMoveDown = null;

            foreach (NPVoxNormalProcessor processor in processorList.GetProcessors())
            {
                NPVoxAttributeNormalProcessorListItem attr = ( NPVoxAttributeNormalProcessorListItem )processor.GetType().GetCustomAttributes(typeof(NPVoxAttributeNormalProcessorListItem), true)[0];

                GUILayout.Space(s_verticalSpacePerItem);

                GUILayout.BeginHorizontal();
                GUILayout.Space(s_widthTab);
                GUILayout.Label(attr.EditorName, GUILayout.MinWidth(s_widthMinItemName));

                GUILayout.Space(20.0f);

                GUI.backgroundColor = s_colorBackgroundGUISecondary;

                if (GUILayout.Button("View"))
                {
                    // TODO: Implement view window
                }

                GUILayout.Space(20.0f);

                if (GUILayout.Button("^", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    itemToMoveUp = processor;
                }

                if (GUILayout.Button("v", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    itemToMoveDown = processor;
                }

                if (GUILayout.Button("X", GUILayout.Width(s_widthUpDownButton), GUILayout.ExpandWidth(true)))
                {
                    processorList.DestroyProcessor(processor);
                    break;
                }

                GUI.backgroundColor = s_colorBackgroundGUIPrimary;

                GUILayout.EndHorizontal();

                processor.OnGUI();
                GUILayout.Space(10.0f);
            }

            if (itemToMoveUp)
            {
                processorList.MoveProcessorUp(itemToMoveUp);
                itemToMoveUp = null;
            }

            if (itemToMoveDown)
            {
                processorList.MoveProcessorDown(itemToMoveDown);
                itemToMoveDown = null;
            }

            GUILayout.Space(s_verticalSpaceEnd);
        }

        // Restore previous gui style
        GUI.backgroundColor = previousBGColor;
        GUI.contentColor    = previousFGColor;

        EditorGUI.EndProperty();
    }
        /// <summary>
        /// Override Unity OnGUI to make a custom GUI for the property with HelpAttribute.
        /// </summary>
        /// <param name="position">Rectangle on the screen to use for the property GUI.</param>
        /// <param name="property">The SerializedProperty to make the custom GUI for.</param>
        /// <param name="label">The label of this property.</param>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            Rect  labelPosition  = position;
            float labelHeight    = base.GetPropertyHeight(property, label);
            float propertyHeight = GetOriginalPropertyHeight(property, label);

            labelPosition.height = labelHeight;

            // Draw property based on defualt Unity GUI behavior.
            string warningMessage = GetIncompatibleAttributeWarning(property);

            if (!string.IsNullOrEmpty(warningMessage))
            {
                var warningContent = new GUIContent(warningMessage);
                EditorGUI.LabelField(labelPosition, label, warningContent);
            }
            else if (GetPropertyAttribute <TextAreaAttribute>() != null)
            {
                Rect textAreaPosition = position;
                textAreaPosition.y     += labelHeight;
                textAreaPosition.height = propertyHeight - labelHeight;
                EditorGUI.LabelField(labelPosition, label);
                EditorGUI.BeginChangeCheck();
                string text = EditorGUI.TextArea(textAreaPosition, property.stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.stringValue = text;
                }
            }
            else if (GetPropertyAttribute <MultilineAttribute>() != null)
            {
                Rect multilinePosition = position;
                multilinePosition.x     += EditorGUIUtility.labelWidth;
                multilinePosition.width -= EditorGUIUtility.labelWidth;
                multilinePosition.height = propertyHeight;
                EditorGUI.LabelField(labelPosition, label);
                EditorGUI.BeginChangeCheck();
                string text = EditorGUI.TextArea(multilinePosition, property.stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.stringValue = text;
                }
            }
            else if (GetPropertyAttribute <RangeAttribute>() != null)
            {
                var rangeAttribute = GetPropertyAttribute <RangeAttribute>();
                if (property.propertyType == SerializedPropertyType.Integer)
                {
                    EditorGUI.IntSlider(labelPosition, property,
                                        (int)rangeAttribute.min, (int)rangeAttribute.max, label);
                }
                else
                {
                    EditorGUI.Slider(labelPosition, property,
                                     rangeAttribute.min, rangeAttribute.max, label);
                }
            }
            else
            {
                EditorGUI.PropertyField(labelPosition, property);
            }

            if (!IsHelpBoxEmpty())
            {
                var helpBoxPosition = position;
                helpBoxPosition.y     += propertyHeight + EditorStyles.helpBox.padding.top;
                helpBoxPosition.height = GetHelpAttributeHeight();
                EditorGUI.HelpBox(helpBoxPosition, GetHelpAttribute().HelpMessage,
                                  (MessageType)GetHelpAttribute().MessageType);
            }

            EditorGUI.EndProperty();
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //Begin the property drawer
        EditorGUI.BeginProperty(position, label, property);
        //Get a rect to draw a label
        Rect _rect = new Rect(position.position.x, position.position.y, position.width / 2, 20);

        EditorGUI.LabelField(_rect, label, TDS_EditorUtility.HeaderStyle);

        // Get a rect to draw a color field for the property debugColor
        _rect = new Rect(position.position.x + position.width / 2, position.position.y, position.width / 2, 20);
        property.FindPropertyRelative("debugColor").colorValue = EditorGUI.ColorField(_rect, property.FindPropertyRelative("debugColor").colorValue);

        // Get a rect for the fold out
        _rect = new Rect(position.position.x + 10, _rect.position.y + 25, position.width - 10, 20);
        property.FindPropertyRelative("isWaveFoldOut").boolValue = EditorGUI.Foldout(_rect, property.FindPropertyRelative("isWaveFoldOut").boolValue, new GUIContent("Spawn Points"), true);

        // Display them if the fold out is true
        if (property.FindPropertyRelative("isWaveFoldOut").boolValue)
        {
            //Get the size of the array
            int                _arraySize = property.FindPropertyRelative("spawnPoints").arraySize;
            GUIContent         _label;
            SerializedProperty _pointProperty;
            for (int i = 0; i < _arraySize; i++)
            {
                //Get the property
                _pointProperty = property.FindPropertyRelative($"spawnPoints.Array.data[{i}]");
                // Get a rect to draw the edition button
                _rect  = new Rect(position.position.x, _rect.position.y + 25, (position.width / 2) - 5, 20);
                _label = new GUIContent($"Edit Spawn Point n° {i}");
                //Open the SpawnPointEditorWindow for the spawn point.
                GUI.color = Color.green;
                if (GUI.Button(_rect, _label))
                {
                    InitWindow(_pointProperty, i);
                }

                // Get a rect to draw the delete button
                _rect  = new Rect(position.position.x + position.width / 2, _rect.position.y, (position.width / 2) - 5, 20);
                _label = new GUIContent($"Delete Spawn Point n° {i}");
                // Remove the point when the button is pressed
                GUI.color = Color.red;
                if (GUI.Button(_rect, _label))
                {
                    property.FindPropertyRelative("spawnPoints").DeleteArrayElementAtIndex(i);
                }
                GUI.color = Color.white;
            }
            // Draw a rect to display the add spawn point button
            _rect  = new Rect(position.position.x, _rect.position.y + 25, position.width, 20);
            _label = new GUIContent($"Add Spawn Point");
            if (GUI.Button(_rect, _label))
            {
                // Add a new spawn point
                property.FindPropertyRelative("spawnPoints").InsertArrayElementAtIndex(0);
            }
        }
        //Is the wave activated by event
        TDS_EditorUtility.Toggle("Is Activated by event", "Are the enemies of this wave starting behaviour on event", property.FindPropertyRelative("isActivatedByEvent"));
        EditorGUI.EndProperty();
    }
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(property.displayName));

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            // Caluculate rects
            var spacing       = 5.0f;
            var rectWidth     = Mathf.Round((position.width - spacing) * 0.5f);
            var enumTypeRect  = new Rect(position.x, position.y, rectWidth, position.height);
            var enumValueRect = new Rect(position.x + rectWidth + spacing, position.y, rectWidth, position.height);

            var roleTypeProp  = property.FindPropertyRelative("m_roleTypeFullName");
            var roleValueProp = property.FindPropertyRelative("m_roleValueName");

            var roleTypeName  = roleTypeProp.stringValue;
            var roleValueName = roleValueProp.stringValue;

            // find current role type / type index
            Type roleType;
            var  roleTypeIndex = ViveRoleEnum.ValidViveRoleTable.IndexOf(roleTypeName);

            if (roleTypeIndex < 0)
            {
                // name not found
                roleType      = defaultRoleType;
                roleTypeIndex = defaultRoleTypeIndex;
            }
            else
            {
                roleType = ViveRoleEnum.ValidViveRoleTable.GetValueByIndex(roleTypeIndex);
            }

            // find current role value index
            var roleTypeInfo   = ViveRoleEnum.GetInfo(roleType);
            var roleValueIndex = roleTypeInfo.GetElementIndexByName(roleValueName);

            if (roleValueIndex < 0)
            {
                roleValueIndex = roleTypeInfo.InvalidRoleValueIndex;
            }

            // draw pupup box, get new role type index / value index
            var newRoleTypeIndex  = EditorGUI.Popup(enumTypeRect, roleTypeIndex, roleTypeNames);
            var newRoleValueIndex = EditorGUI.Popup(enumValueRect, roleValueIndex, roleTypeInfo.RoleValueNames);

            // if new role index changed
            var newRoleType     = roleType;
            var newRoleTypeInfo = roleTypeInfo;

            if (newRoleTypeIndex != roleTypeIndex)
            {
                newRoleType              = ViveRoleEnum.ValidViveRoleTable.GetValueByIndex(newRoleTypeIndex);
                newRoleTypeInfo          = ViveRoleEnum.GetInfo(newRoleType);
                roleTypeProp.stringValue = ViveRoleEnum.ValidViveRoleTable.GetKeyByIndex(newRoleTypeIndex);
            }

            if (newRoleTypeIndex != roleTypeIndex || newRoleValueIndex != roleValueIndex)
            {
                if (newRoleValueIndex < 0 || newRoleValueIndex >= newRoleTypeInfo.ElementCount)
                {
                    newRoleValueIndex = newRoleTypeInfo.InvalidRoleValueIndex;
                }

                roleValueProp.stringValue = newRoleTypeInfo.GetNameByElementIndex(newRoleValueIndex);
            }

            property.serializedObject.ApplyModifiedProperties();

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();

            // update target
            if (newRoleTypeIndex != roleTypeIndex || newRoleValueIndex != roleValueIndex)
            {
                var target = GetTarget(fieldInfo, property);
                if (newRoleTypeIndex != roleTypeIndex)
                {
                    target.SetTypeDirty();
                }
                if (newRoleValueIndex != roleValueIndex)
                {
                    target.SetValueDirty();
                }
            }
        }
Beispiel #15
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);


            var refer  = property.FindPropertyRelative("ProgressName");
            var refer2 = property.FindPropertyRelative("TypeID");

            var labelRect = new Rect(position.x, position.y, InspectorValues.LabelWidth, position.height);

            EditorGUI.LabelField(labelRect, property.name);


            //this is defining the sizes of the rectangles for the editor
            var propStartPos = labelRect.position.x + labelRect.width;

            if (position.width > InspectorValues.MinRectWidth)
            {
                propStartPos += (position.width - InspectorValues.MinRectWidth) / InspectorValues.WidthScaler;
            }

            var toggleRect = new Rect(propStartPos, position.y, ToggleWidth, EditorGUIUtility.singleLineHeight);
            var eventRect  = new Rect(toggleRect.position.x + toggleRect.width, position.y, position.width - (toggleRect.position.x + toggleRect.width) + 14, EditorGUIUtility.singleLineHeight);

            //var enumRect = new Rect(propStartPos, position.y, 40, EditorGUIUtility.singleLineHeight);

            refer.stringValue = EditorGUI.TextField(eventRect, refer.stringValue);
            PointTypes ty = (PointTypes)EditorGUI.EnumPopup(toggleRect, (PointTypes)refer2.enumValueIndex);

            refer2.enumValueIndex = (int)ty;
            //ref2.boolValue = EditorGUI.ToggleLeft(toggleRect, "Value", ref2.boolValue);

            switch (ty)
            {
            case PointTypes.Flag:
                var refboo = property.FindPropertyRelative("BoolValue");
                toggleRect.y    += EditorGUIUtility.singleLineHeight + 2;
                refboo.boolValue = EditorGUI.ToggleLeft(toggleRect, "Value", refboo.boolValue);
                break;

            case PointTypes.Float:
                var refflo = property.FindPropertyRelative("FloatValue");

                eventRect.y      += EditorGUIUtility.singleLineHeight + 2;
                refflo.floatValue = EditorGUI.FloatField(eventRect, refflo.floatValue);

                var compare = property.FindPropertyRelative("compare");
                toggleRect.y += EditorGUIUtility.singleLineHeight + 2;
                ValueCompare com = (ValueCompare)EditorGUI.EnumPopup(toggleRect, (ValueCompare)compare.enumValueIndex);
                compare.enumValueIndex = (int)com;
                break;

            case PointTypes.Integer:
                var refint = property.FindPropertyRelative("IntValue");

                eventRect.y    += EditorGUIUtility.singleLineHeight + 2;
                refint.intValue = EditorGUI.IntField(eventRect, refint.intValue);

                var compare2 = property.FindPropertyRelative("compare");
                toggleRect.y += EditorGUIUtility.singleLineHeight + 2;
                ValueCompare com2 = (ValueCompare)EditorGUI.EnumPopup(toggleRect, (ValueCompare)compare2.enumValueIndex);
                compare2.enumValueIndex = (int)com2;
                break;

            case PointTypes.String:
                var refst = property.FindPropertyRelative("StringValue");
                eventRect.y      += EditorGUIUtility.singleLineHeight + 2;
                refst.stringValue = EditorGUI.TextField(eventRect, refst.stringValue);
                break;

            default:
                break;
            }


            EditorGUI.EndProperty();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var showDatePickerProperty = property.FindPropertyRelative("m_showEditorCalendar");
            var showDatePicker         = showDatePickerProperty.boolValue;

            var serializedProperty = property.FindPropertyRelative("m_SerializedDate");

            SelectedDate = !String.IsNullOrEmpty(serializedProperty.stringValue) ? DateTime.Parse(serializedProperty.stringValue) : DateTime.Today;

            if (!String.IsNullOrEmpty(serializedProperty.stringValue))
            {
                if (!DateTime.TryParse(serializedProperty.stringValue, out SelectedDate))
                {
                    SelectedDate = DateTime.Today;
                }
            }
            else
            {
                SelectedDate = DateTime.Today;
            }

            if (buttonImage == null)
            {
                buttonImage = new GUIContent(Resources.Load("Sprites/Editor/Calendar_Editor") as Texture2D);
            }

            if (textStyle == null)
            {
                textStyle           = new GUIStyle(EditorStyles.textField);
                textStyle.fontSize  = 18;
                textStyle.alignment = TextAnchor.MiddleCenter;
            }

            EditorGUI.BeginProperty(position, label, property);

            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            var textFieldPosition = new Rect(position.x, position.y, 224, 24);
            var buttonPosition    = new Rect(position.x + 224, position.y, 40, 24);

            EditorGUI.BeginDisabledGroup(true);
            serializedProperty.stringValue = EditorGUI.TextField(textFieldPosition, serializedProperty.stringValue, textStyle);
            EditorGUI.EndDisabledGroup();
            if (GUI.Button(buttonPosition, buttonImage))
            {
                showDatePicker = !showDatePicker;
            }

            buttonPosition.x    += 48;
            buttonPosition.width = 24;

            if (GUI.Button(buttonPosition, "X"))
            {
                serializedProperty.stringValue = null;
                showDatePicker = false;
            }

            position.y += 24;

            if (showDatePicker)
            {
                showDatePicker = DrawDatePicker(position, serializedProperty, showDatePickerProperty);
            }

            EditorGUI.indentLevel = indent;

            showDatePickerProperty.boolValue = showDatePicker;

            EditorGUI.EndProperty();
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            int isGlobal = m_IsGlobal.boolValue ? 0 : 1;

            isGlobal             = EditorGUILayout.Popup(EditorGUIUtility.TrTextContent("Mode", "A global volume is applied to the whole scene."), isGlobal, m_Modes);
            m_IsGlobal.boolValue = isGlobal == 0;

            if (isGlobal != 0) // Blend radius is not needed for global volumes
            {
                if (!actualTarget.TryGetComponent <Collider>(out _))
                {
                    EditorGUILayout.HelpBox("Add a Collider to this GameObject to set boundaries for the local Volume.", MessageType.Info);

                    if (GUILayout.Button(EditorGUIUtility.TrTextContent("Add Collider"), EditorStyles.miniButton))
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(EditorGUIUtility.TrTextContent("Box"), false, () => Undo.AddComponent <BoxCollider>(actualTarget.gameObject));
                        menu.AddItem(EditorGUIUtility.TrTextContent("Sphere"), false, () => Undo.AddComponent <SphereCollider>(actualTarget.gameObject));
                        menu.AddItem(EditorGUIUtility.TrTextContent("Capsule"), false, () => Undo.AddComponent <CapsuleCollider>(actualTarget.gameObject));
                        menu.AddItem(EditorGUIUtility.TrTextContent("Mesh"), false, () => Undo.AddComponent <MeshCollider>(actualTarget.gameObject));
                        menu.ShowAsContext();
                    }
                }

                EditorGUILayout.PropertyField(m_BlendRadius);
                m_BlendRadius.floatValue = Mathf.Max(m_BlendRadius.floatValue, 0f);
            }

            EditorGUILayout.PropertyField(m_Weight);
            EditorGUILayout.PropertyField(m_Priority);

            bool assetHasChanged = false;
            bool showCopy        = m_Profile.objectReferenceValue != null;
            bool multiEdit       = m_Profile.hasMultipleDifferentValues;

            // The layout system breaks alignment when mixing inspector fields with custom layout'd
            // fields, do the layout manually instead
            int   buttonWidth    = showCopy ? 45 : 60;
            float indentOffset   = EditorGUI.indentLevel * 15f;
            var   lineRect       = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
            var   labelRect      = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
            var   fieldRect      = new Rect(labelRect.xMax, lineRect.y, lineRect.width - labelRect.width - buttonWidth * (showCopy ? 2 : 1), lineRect.height);
            var   buttonNewRect  = new Rect(fieldRect.xMax, lineRect.y, buttonWidth, lineRect.height);
            var   buttonCopyRect = new Rect(buttonNewRect.xMax, lineRect.y, buttonWidth, lineRect.height);

            GUIContent guiContent;

            if (actualTarget.HasInstantiatedProfile())
            {
                guiContent = EditorGUIUtility.TrTextContent("Profile (Instance)", "A copy of a profile asset.");
            }
            else
            {
                guiContent = EditorGUIUtility.TrTextContent("Profile", "A reference to a profile asset.");
            }
            EditorGUI.PrefixLabel(labelRect, guiContent);

            using (var scope = new EditorGUI.ChangeCheckScope())
            {
                EditorGUI.BeginProperty(fieldRect, GUIContent.none, m_Profile);

                VolumeProfile profile;

                if (actualTarget.HasInstantiatedProfile())
                {
                    profile = (VolumeProfile)EditorGUI.ObjectField(fieldRect, actualTarget.profile, typeof(VolumeProfile), false);
                }
                else
                {
                    profile = (VolumeProfile)EditorGUI.ObjectField(fieldRect, m_Profile.objectReferenceValue, typeof(VolumeProfile), false);
                }

                if (scope.changed)
                {
                    assetHasChanged = true;
                    m_Profile.objectReferenceValue = profile;

                    if (actualTarget.HasInstantiatedProfile()) // Clear the instantiated profile, from now on we're using shared again
                    {
                        actualTarget.profile = null;
                    }
                }

                EditorGUI.EndProperty();
            }

            using (new EditorGUI.DisabledScope(multiEdit))
            {
                if (GUI.Button(buttonNewRect, EditorGUIUtility.TrTextContent("New", "Create a new profile."), showCopy ? EditorStyles.miniButtonLeft : EditorStyles.miniButton))
                {
                    // By default, try to put assets in a folder next to the currently active
                    // scene file. If the user isn't a scene, put them in root instead.
                    var targetName = actualTarget.name;
                    var scene      = actualTarget.gameObject.scene;
                    var asset      = VolumeProfileFactory.CreateVolumeProfile(scene, targetName);
                    m_Profile.objectReferenceValue = asset;
                    actualTarget.profile           = null; // Make sure we're not using an instantiated profile anymore
                    assetHasChanged = true;
                }

                if (actualTarget.HasInstantiatedProfile())
                {
                    guiContent = EditorGUIUtility.TrTextContent("Save", "Save the instantiated profile");
                }
                else
                {
                    guiContent = EditorGUIUtility.TrTextContent("Clone", "Create a new profile and copy the content of the currently assigned profile.");
                }
                if (showCopy && GUI.Button(buttonCopyRect, guiContent, EditorStyles.miniButtonRight))
                {
                    // Duplicate the currently assigned profile and save it as a new profile
                    var origin = profileRef;
                    var path   = AssetDatabase.GetAssetPath(m_Profile.objectReferenceValue);
                    path = AssetDatabase.GenerateUniqueAssetPath(path);

                    var asset = Instantiate(origin);
                    asset.components.Clear();
                    AssetDatabase.CreateAsset(asset, path);

                    foreach (var item in origin.components)
                    {
                        var itemCopy = Instantiate(item);
                        itemCopy.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
                        itemCopy.name      = item.name;
                        asset.components.Add(itemCopy);
                        AssetDatabase.AddObjectToAsset(itemCopy, asset);
                    }

                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    m_Profile.objectReferenceValue = asset;
                    actualTarget.profile           = null; // Make sure we're not using an instantiated profile anymore
                    assetHasChanged = true;
                }
            }

            EditorGUILayout.Space();

            if (m_Profile.objectReferenceValue == null && !actualTarget.HasInstantiatedProfile())
            {
                if (assetHasChanged)
                {
                    m_ComponentList.Clear(); // Asset wasn't null before, do some cleanup
                }
            }
            else
            {
                if (assetHasChanged || profileRef != m_ComponentList.asset)
                {
                    RefreshEffectListEditor(profileRef);
                }

                if (!multiEdit)
                {
                    m_ComponentList.OnGUI();
                    EditorGUILayout.Space();
                }
            }

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

        try
        {
            SerializedProperty pEnabled = property.FindPropertyRelative("_enabled");
            EditorGUI.BeginChangeCheck();
            bool newEnabled = EditorGUI.ToggleLeft(new Rect(position.x, position.y, position.width, 16), label, pEnabled.boolValue);
            if (EditorGUI.EndChangeCheck())
            {
                if (Application.isPlaying)
                {
                    isEnabledChanged = newEnabled;
                }
                else
                {
                    pEnabled.boolValue = newEnabled;
                }
            }

            Rect rect = new Rect(position.x, position.y, position.width, 16);

            EditorGUI.BeginChangeCheck();
            SerializedProperty pLat = DrawProperty(property, "latitude", ref rect);
            if (EditorGUI.EndChangeCheck())
            {
#if UNITY_5_0P
                if (pLat.doubleValue < -90)
                {
                    pLat.doubleValue = -90;
                }
                else if (pLat.doubleValue > 90)
                {
                    pLat.doubleValue = 90;
                }
#else
                if (pLat.floatValue < -90)
                {
                    pLat.floatValue = -90;
                }
                else if (pLat.floatValue > 90)
                {
                    pLat.floatValue = 90;
                }
#endif
            }

            EditorGUI.BeginChangeCheck();
            SerializedProperty pLng = DrawProperty(property, "longitude", ref rect);
            if (EditorGUI.EndChangeCheck())
            {
#if UNITY_5_0P
                if (pLng.doubleValue < -180)
                {
                    pLng.doubleValue += 360;
                }
                else if (pLng.doubleValue > 180)
                {
                    pLng.doubleValue -= 360;
                }
#else
                if (pLng.floatValue < -180)
                {
                    pLng.floatValue += 360;
                }
                else if (pLng.floatValue > 180)
                {
                    pLng.floatValue -= 360;
                }
#endif
            }

            DrawProperty(property, "range", ref rect, new GUIContent("Zooms"));

            DrawProperty(property, "_scale", ref rect);
            DrawProperty(property, "label", ref rect);
            DrawProperty(property, "prefab", ref rect);

            rect.y += 18;
            if (GUI.Button(rect, "Remove"))
            {
                isRemoved = true;
            }
        }
        catch
        {
        }


        EditorGUI.EndProperty();
    }
        public override void OnInspectorGUI()
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            serializedObject.Update();

            var bs = NavMesh.GetSettingsByID(m_AgentTypeID.intValue);

            if (bs.agentTypeID != -1)
            {
                // Draw image
                const float diagramHeight    = 80.0f;
                Rect        agentDiagramRect = EditorGUILayout.GetControlRect(false, diagramHeight);
                NavMeshEditorHelpers.DrawAgentDiagram(agentDiagramRect, bs.agentRadius, bs.agentHeight, bs.agentClimb, bs.agentSlope);
            }
            NavMeshComponentsGUIUtility.AgentTypePopup("Agent Type", m_AgentTypeID);

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(m_CollectObjects);
            if ((CollectObjects)m_CollectObjects.enumValueIndex == CollectObjects.Volume)
            {
                EditorGUI.indentLevel++;

                EditMode.DoEditModeInspectorModeButton(EditMode.SceneViewEditMode.Collider, "Edit Volume",
                                                       EditorGUIUtility.IconContent("EditCollider"), GetBounds, this);
                EditorGUILayout.PropertyField(m_Size);
                EditorGUILayout.PropertyField(m_Center);

                EditorGUI.indentLevel--;
            }
            else
            {
                if (editingCollider)
                {
                    EditMode.QuitEditMode();
                }
            }

            EditorGUILayout.PropertyField(m_LayerMask, s_Styles.m_LayerMask);
            EditorGUILayout.PropertyField(m_UseGeometry);

            EditorGUILayout.Space();

            m_OverrideVoxelSize.isExpanded = EditorGUILayout.Foldout(m_OverrideVoxelSize.isExpanded, "Advanced");
            if (m_OverrideVoxelSize.isExpanded)
            {
                EditorGUI.indentLevel++;

                NavMeshComponentsGUIUtility.AreaPopup("Default Area", m_DefaultArea);

                // Override voxel size.
                EditorGUILayout.PropertyField(m_OverrideVoxelSize);

                using (new EditorGUI.DisabledScope(!m_OverrideVoxelSize.boolValue || m_OverrideVoxelSize.hasMultipleDifferentValues))
                {
                    EditorGUI.indentLevel++;

                    EditorGUILayout.PropertyField(m_VoxelSize);

                    if (!m_OverrideVoxelSize.hasMultipleDifferentValues)
                    {
                        if (!m_AgentTypeID.hasMultipleDifferentValues)
                        {
                            float voxelsPerRadius = m_VoxelSize.floatValue > 0.0f ? (bs.agentRadius / m_VoxelSize.floatValue) : 0.0f;
                            EditorGUILayout.LabelField(" ", voxelsPerRadius.ToString("0.00") + " voxels per agent radius", EditorStyles.miniLabel);
                        }
                        if (m_OverrideVoxelSize.boolValue)
                        {
                            EditorGUILayout.HelpBox("Voxel size controls how accurately the navigation mesh is generated from the level geometry. A good voxel size is 2-4 voxels per agent radius. Making voxel size smaller will increase build time.", MessageType.None);
                        }
                    }
                    EditorGUI.indentLevel--;
                }

                // Override tile size
                EditorGUILayout.PropertyField(m_OverrideTileSize);

                using (new EditorGUI.DisabledScope(!m_OverrideTileSize.boolValue || m_OverrideTileSize.hasMultipleDifferentValues))
                {
                    EditorGUI.indentLevel++;

                    EditorGUILayout.PropertyField(m_TileSize);

                    if (!m_TileSize.hasMultipleDifferentValues && !m_VoxelSize.hasMultipleDifferentValues)
                    {
                        float tileWorldSize = m_TileSize.intValue * m_VoxelSize.floatValue;
                        EditorGUILayout.LabelField(" ", tileWorldSize.ToString("0.00") + " world units", EditorStyles.miniLabel);
                    }

                    if (!m_OverrideTileSize.hasMultipleDifferentValues)
                    {
                        if (m_OverrideTileSize.boolValue)
                        {
                            EditorGUILayout.HelpBox("Tile size controls the how local the changes to the world are (rebuild or carve). Small tile size allows more local changes, while potentially generating more data overall.", MessageType.None);
                        }
                    }
                    EditorGUI.indentLevel--;
                }


                // Height mesh
                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUILayout.PropertyField(m_BuildHeightMesh);
                }

                EditorGUILayout.Space();
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();

            serializedObject.ApplyModifiedProperties();

            var hadError        = false;
            var multipleTargets = targets.Length > 1;

            foreach (NavMeshSurface navSurface in targets)
            {
                var settings = navSurface.GetBuildSettings();
                // Calculating bounds is potentially expensive when unbounded - so here we just use the center/size.
                // It means the validation is not checking vertical voxel limit correctly when the surface is set to something else than "in volume".
                var bounds = new Bounds(Vector3.zero, Vector3.zero);
                if (navSurface.collectObjects == CollectObjects.Volume)
                {
                    bounds = new Bounds(navSurface.center, navSurface.size);
                }

                var errors = settings.ValidationReport(bounds);
                if (errors.Length > 0)
                {
                    if (multipleTargets)
                    {
                        EditorGUILayout.LabelField(navSurface.name);
                    }
                    foreach (var err in errors)
                    {
                        EditorGUILayout.HelpBox(err, MessageType.Warning);
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(EditorGUIUtility.labelWidth);
                    if (GUILayout.Button("Open Agent Settings...", EditorStyles.miniButton))
                    {
                        NavMeshEditorHelpers.OpenAgentSettings(navSurface.agentTypeID);
                    }
                    GUILayout.EndHorizontal();
                    hadError = true;
                }
            }

            if (hadError)
            {
                EditorGUILayout.Space();
            }

#if NAVMESHCOMPONENTS_SHOW_NAVMESHDATA_REF
            var nmdRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);

            EditorGUI.BeginProperty(nmdRect, GUIContent.none, m_NavMeshData);
            var rectLabel = EditorGUI.PrefixLabel(nmdRect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(m_NavMeshData.displayName));
            EditorGUI.EndProperty();

            using (new EditorGUI.DisabledScope(true))
            {
                EditorGUI.BeginProperty(nmdRect, GUIContent.none, m_NavMeshData);
                EditorGUI.ObjectField(rectLabel, m_NavMeshData, GUIContent.none);
                EditorGUI.EndProperty();
            }
#endif
            using (new EditorGUI.DisabledScope(Application.isPlaying || m_AgentTypeID.intValue == -1))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUIUtility.labelWidth);
                if (GUILayout.Button("Clear"))
                {
                    NavMeshAssetManager.instance.ClearSurfaces(targets);
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button("Bake"))
                {
                    NavMeshAssetManager.instance.StartBakingSurfaces(targets);
                }

                GUILayout.EndHorizontal();
            }

            // Show progress for the selected targets
            var bakeOperations = NavMeshAssetManager.instance.GetBakeOperations();
            for (int i = bakeOperations.Count - 1; i >= 0; --i)
            {
                if (!targets.Contains(bakeOperations[i].surface))
                {
                    continue;
                }

                var oper = bakeOperations[i].bakeOperation;
                if (oper == null)
                {
                    continue;
                }

                var p = oper.progress;
                if (oper.isDone)
                {
                    SceneView.RepaintAll();
                    continue;
                }

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Cancel", EditorStyles.miniButton))
                {
                    var bakeData = bakeOperations[i].bakeData;
                    UnityEngine.AI.NavMeshBuilder.Cancel(bakeData);
                    bakeOperations.RemoveAt(i);
                }

                EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(), p, "Baking: " + (int)(100 * p) + "%");
                if (p <= 1)
                {
                    Repaint();
                }

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

                    SerializedProperty controllerProp   = property.FindPropertyRelative("_controller");
                    SerializedProperty animatorLODsProp = property.FindPropertyRelative("_animatorLODs");

                    Rect controllerRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

                    EditorGUI.PropertyField(controllerRect, controllerProp, new GUIContent("Animator Controller"));

                    Rect lodsRect = new Rect(position.x + EditorGUIUtility.singleLineHeight, controllerRect.y + controllerRect.height, position.width - EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);

                    animatorLODsProp.isExpanded = EditorGUI.BeginFoldoutHeaderGroup(lodsRect, animatorLODsProp.isExpanded, "LODs");
                    if (animatorLODsProp.isExpanded)
                    {
                        EditorGUI.indentLevel++;
                        float labelWidth = EditorGUIUtility.labelWidth;
                        EditorGUIUtility.labelWidth = labelWidth * 0.5f;

                        float deleteButtonWidth   = EditorGUIUtility.singleLineHeight * 2f;
                        float deleteButtonSpacing = EditorGUIUtility.singleLineHeight;
                        float elementPropWidth    = lodsRect.width - deleteButtonWidth - deleteButtonSpacing;
                        Rect  elementRect         = new Rect(lodsRect.x, lodsRect.y + lodsRect.height, elementPropWidth, EditorGUIUtility.singleLineHeight);

                        //Draw LODS
                        for (int i = 0; i < animatorLODsProp.arraySize;)
                        {
                            SerializedProperty minLODLevelProp = property.FindPropertyRelative("_animatorLODs.Array.data[" + i + "]._minLODLevel");
                            SerializedProperty avatarMaskProp  = property.FindPropertyRelative("_animatorLODs.Array.data[" + i + "]._avatarMask");

                            Rect lodLevelRect = new Rect(elementRect.x, elementRect.y, elementRect.width * 0.5f, elementRect.height);
                            minLODLevelProp.intValue = EditorGUI.IntSlider(lodLevelRect, new GUIContent("Min LOD Level"), minLODLevelProp.intValue, 1, 8);

                            Rect maskRect = new Rect(lodLevelRect.x + lodLevelRect.width, elementRect.y, elementRect.width - lodLevelRect.width, elementRect.height);
                            avatarMaskProp.objectReferenceValue = (AvatarMask)EditorGUI.ObjectField(maskRect, new GUIContent("LOD Bone Mask"), avatarMaskProp.objectReferenceValue, typeof(AvatarMask), false);

                            Rect deleteElementRect = new Rect(maskRect.x + maskRect.width + deleteButtonSpacing, elementRect.y, deleteButtonWidth, elementRect.height);
                            if (GUI.Button(deleteElementRect, "-"))
                            {
                                animatorLODsProp.DeleteArrayElementAtIndex(i);
                            }
                            else
                            {
                                i++;
                            }

                            elementRect.y += EditorGUIUtility.singleLineHeight;
                        }

                        Rect addElementRect = new Rect(elementRect.x + elementRect.width + deleteButtonSpacing, elementRect.y, deleteButtonWidth, elementRect.height);
                        if (GUI.Button(addElementRect, "+"))
                        {
                            animatorLODsProp.InsertArrayElementAtIndex(animatorLODsProp.arraySize);
                        }

                        EditorGUI.indentLevel--;
                        EditorGUIUtility.labelWidth = labelWidth;
                    }
                    EditorGUI.EndFoldoutHeaderGroup();

                    EditorGUI.EndProperty();
                }
 protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
 {
     EditorGUI.BeginProperty(rect, label, property);
     EditorGUI.PropertyField(rect, property, label, true);
     EditorGUI.EndProperty();
 }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label = EditorGUI.BeginProperty(position, label, property);

        Action buttonAction      = Action.None;
        int    buttonActionIndex = 0;

        var keyArrayProperty   = property.FindPropertyRelative(KeysFieldName);
        var valueArrayProperty = property.FindPropertyRelative(ValuesFieldName);

        ConflictState conflictState = GetConflictState(property);

        if (conflictState.conflictIndex != -1)
        {
            keyArrayProperty.InsertArrayElementAtIndex(conflictState.conflictIndex);
            var keyProperty = keyArrayProperty.GetArrayElementAtIndex(conflictState.conflictIndex);
            SetPropertyValue(keyProperty, conflictState.conflictKey);
            keyProperty.isExpanded = conflictState.conflictKeyPropertyExpanded;

            valueArrayProperty.InsertArrayElementAtIndex(conflictState.conflictIndex);
            var valueProperty = valueArrayProperty.GetArrayElementAtIndex(conflictState.conflictIndex);
            SetPropertyValue(valueProperty, conflictState.conflictValue);
            valueProperty.isExpanded = conflictState.conflictValuePropertyExpanded;
        }

        var buttonWidth = s_buttonStyle.CalcSize(s_iconPlus).x;

        var labelPosition = position;

        labelPosition.height = EditorGUIUtility.singleLineHeight;
        if (property.isExpanded)
        {
            labelPosition.xMax -= s_buttonStyle.CalcSize(s_iconPlus).x;
        }

        EditorGUI.PropertyField(labelPosition, property, label, false);
        // property.isExpanded = EditorGUI.Foldout(labelPosition, property.isExpanded, label);
        if (property.isExpanded)
        {
            var buttonPosition = position;
            buttonPosition.xMin   = buttonPosition.xMax - buttonWidth;
            buttonPosition.height = EditorGUIUtility.singleLineHeight;
            EditorGUI.BeginDisabledGroup(conflictState.conflictIndex != -1);
            if (GUI.Button(buttonPosition, s_iconPlus, s_buttonStyle))
            {
                buttonAction      = Action.Add;
                buttonActionIndex = keyArrayProperty.arraySize;
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.indentLevel++;
            var linePosition = position;
            linePosition.y    += EditorGUIUtility.singleLineHeight;
            linePosition.xMax -= buttonWidth;

            foreach (var entry in EnumerateEntries(keyArrayProperty, valueArrayProperty))
            {
                var keyProperty   = entry.keyProperty;
                var valueProperty = entry.valueProperty;
                int i             = entry.index;

                float lineHeight = DrawKeyValueLine(keyProperty, valueProperty, linePosition, i);

                buttonPosition        = linePosition;
                buttonPosition.x      = linePosition.xMax;
                buttonPosition.height = EditorGUIUtility.singleLineHeight;
                if (GUI.Button(buttonPosition, s_iconMinus, s_buttonStyle))
                {
                    buttonAction      = Action.Remove;
                    buttonActionIndex = i;
                }

                if (i == conflictState.conflictIndex && conflictState.conflictOtherIndex == -1)
                {
                    var iconPosition = linePosition;
                    iconPosition.size = s_buttonStyle.CalcSize(s_warningIconNull);
                    GUI.Label(iconPosition, s_warningIconNull);
                }
                else if (i == conflictState.conflictIndex)
                {
                    var iconPosition = linePosition;
                    iconPosition.size = s_buttonStyle.CalcSize(s_warningIconConflict);
                    GUI.Label(iconPosition, s_warningIconConflict);
                }
                else if (i == conflictState.conflictOtherIndex)
                {
                    var iconPosition = linePosition;
                    iconPosition.size = s_buttonStyle.CalcSize(s_warningIconOther);
                    GUI.Label(iconPosition, s_warningIconOther);
                }


                linePosition.y += lineHeight;
            }

            EditorGUI.indentLevel--;
        }

        if (buttonAction == Action.Add)
        {
            keyArrayProperty.InsertArrayElementAtIndex(buttonActionIndex);
            valueArrayProperty.InsertArrayElementAtIndex(buttonActionIndex);
        }
        else if (buttonAction == Action.Remove)
        {
            DeleteArrayElementAtIndex(keyArrayProperty, buttonActionIndex);
            DeleteArrayElementAtIndex(valueArrayProperty, buttonActionIndex);
        }

        conflictState.conflictKey                   = null;
        conflictState.conflictValue                 = null;
        conflictState.conflictIndex                 = -1;
        conflictState.conflictOtherIndex            = -1;
        conflictState.conflictLineHeight            = 0f;
        conflictState.conflictKeyPropertyExpanded   = false;
        conflictState.conflictValuePropertyExpanded = false;

        foreach (var entry1 in EnumerateEntries(keyArrayProperty, valueArrayProperty))
        {
            var    keyProperty1      = entry1.keyProperty;
            int    i                 = entry1.index;
            object keyProperty1Value = GetPropertyValue(keyProperty1);

            if (keyProperty1Value == null)
            {
                var valueProperty1 = entry1.valueProperty;
                SaveProperty(keyProperty1, valueProperty1, i, -1, conflictState);
                DeleteArrayElementAtIndex(valueArrayProperty, i);
                DeleteArrayElementAtIndex(keyArrayProperty, i);

                break;
            }


            foreach (var entry2 in EnumerateEntries(keyArrayProperty, valueArrayProperty, i + 1))
            {
                var    keyProperty2      = entry2.keyProperty;
                int    j                 = entry2.index;
                object keyProperty2Value = GetPropertyValue(keyProperty2);

                if (ComparePropertyValues(keyProperty1Value, keyProperty2Value))
                {
                    var valueProperty2 = entry2.valueProperty;
                    SaveProperty(keyProperty2, valueProperty2, j, i, conflictState);
                    DeleteArrayElementAtIndex(keyArrayProperty, j);
                    DeleteArrayElementAtIndex(valueArrayProperty, j);

                    goto breakLoops;
                }
            }
        }
breakLoops:

        EditorGUI.EndProperty();
    }
Beispiel #23
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            float x = position.x;
            float y = position.y;
            float inspectorWidth = position.width;

            // Draw label


            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            var   items         = property.FindPropertyRelative("items");
            var   titles        = new string[] { "Transform", "", "", "" };
            var   props         = new string[] { "transform", "^", "v", "-" };
            var   widths        = new float[] { .7f, .1f, .1f, .1f };
            float lineHeight    = 18;
            bool  changedLength = false;

            if (items.arraySize > 0)
            {
                for (int i = 0; i < items.arraySize; i++)
                //for (int i = -1; i < items.arraySize; ++i)
                {
                    var item = items.GetArrayElementAtIndex(i);

                    float rowX = x;
                    for (int n = 0; n < props.Length; ++n)
                    {
                        float w = widths[n] * inspectorWidth;

                        // Calculate rects
                        Rect rect = new Rect(rowX, y, w, lineHeight);
                        rowX += w;

                        if (i == -1)
                        {
                            EditorGUI.LabelField(rect, titles[n]);
                        }
                        else
                        {
                            if (n == 0)
                            {
                                EditorGUI.ObjectField(rect, item.objectReferenceValue, typeof(Transform), true);
                            }
                            else
                            {
                                if (GUI.Button(rect, props[n]))
                                {
                                    switch (props[n])
                                    {
                                    case "-":
                                        items.DeleteArrayElementAtIndex(i);
                                        items.DeleteArrayElementAtIndex(i);
                                        changedLength = true;
                                        break;

                                    case "v":
                                        if (i > 0)
                                        {
                                            items.MoveArrayElement(i, i + 1);
                                        }
                                        break;

                                    case "^":
                                        if (i < items.arraySize - 1)
                                        {
                                            items.MoveArrayElement(i, i - 1);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    y += lineHeight + spacing;
                    if (changedLength)
                    {
                        break;
                    }
                }
            }
            else
            {
                // add button
                var addButtonRect = new Rect((x + position.width) - widths[widths.Length - 1] * inspectorWidth, y,
                                             widths[widths.Length - 1] * inspectorWidth, lineHeight);
                if (GUI.Button(addButtonRect, "+"))
                {
                    items.InsertArrayElementAtIndex(items.arraySize);
                }

                y += lineHeight + spacing;
            }

            // add all button
            var addAllButtonRect = new Rect(x, y, inspectorWidth, lineHeight);

            if (GUI.Button(addAllButtonRect, "Assign using all child objects"))
            {
                var circuit  = property.FindPropertyRelative("circuit").objectReferenceValue as WaypointCircuit;
                var children = new Transform[circuit.transform.childCount];
                int n        = 0;
                foreach (Transform child in circuit.transform)
                {
                    children[n++] = child;
                }
                Array.Sort(children, new TransformNameComparer());
                circuit.waypointList.items = new Transform[children.Length];
                for (n = 0; n < children.Length; ++n)
                {
                    circuit.waypointList.items[n] = children[n];
                }
            }
            y += lineHeight + spacing;

            // rename all button
            var renameButtonRect = new Rect(x, y, inspectorWidth, lineHeight);

            if (GUI.Button(renameButtonRect, "Auto Rename numerically from this order"))
            {
                var circuit = property.FindPropertyRelative("circuit").objectReferenceValue as WaypointCircuit;
                int n       = 0;
                foreach (Transform child in circuit.waypointList.items)
                {
                    child.name = "Waypoint " + (n++).ToString("000");
                }
            }
            y += lineHeight + spacing;

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
Beispiel #24
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!cache)
            {
                //get the name before it's gone
                name = property.displayName;

                //get the X and Y values
                property.Next(true);
                X = property.Copy();
                property.Next(true);
                Y = property.Copy();

                cache = false;
            }
            bool changed         = false;
            Rect contentPosition = EditorGUI.PrefixLabel(position, new GUIContent(name));

            //Check if there is enough space to put the name on the same line (to save space)
            if (position.height > 16f)
            {
                position.height        = 16f;
                EditorGUI.indentLevel += 1;
                contentPosition        = EditorGUI.IndentedRect(position);
                contentPosition.y     += 18f;
            }

            float half = contentPosition.width / 2;

            GUI.skin.label.padding = new RectOffset(3, 3, 6, 6);

            //show the X and Y from the point
            EditorGUIUtility.labelWidth = 14f;
            contentPosition.width      *= 0.5f;
            EditorGUI.indentLevel       = 0;

            // Begin/end property & change check make each field
            // behave correctly when multi-object editing.
            EditorGUI.BeginProperty(contentPosition, label, X);
            {
                EditorGUI.BeginChangeCheck();
                var newVal = FixedNumberField(contentPosition, new GUIContent("X"), X.longValue);
                if (EditorGUI.EndChangeCheck())
                {
                    X.longValue = newVal;
                    changed     = true;
                }
            }
            EditorGUI.EndProperty();

            contentPosition.x += half;

            EditorGUI.BeginProperty(contentPosition, label, Y);
            {
                EditorGUI.BeginChangeCheck();
                var newVal = FixedNumberField(contentPosition, new GUIContent("Y"), Y.longValue);
                if (EditorGUI.EndChangeCheck())
                {
                    Y.longValue = newVal;
                    changed     = true;
                }
            }
            EditorGUI.EndProperty();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            float x = position.x;
            float y = position.y;
            float inspectorWidth = position.width;

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            var         items         = property.FindPropertyRelative("items");
            var         titles        = new string[] { "Original", "Replacement", "" };
            var         props         = new string[] { "original", "replacement", "-" };
            var         widths        = new float[] { .45f, .45f, .1f };
            const float lineHeight    = 18;
            bool        changedLength = false;

            if (items.arraySize > 0)
            {
                for (int i = -1; i < items.arraySize; ++i)
                {
                    var item = items.GetArrayElementAtIndex(i);

                    float rowX = x;
                    for (int n = 0; n < props.Length; ++n)
                    {
                        float w = widths[n] * inspectorWidth;

                        // Calculate rects
                        Rect rect = new Rect(rowX, y, w, lineHeight);
                        rowX += w;

                        if (i == -1)
                        {
                            // draw title labels
                            EditorGUI.LabelField(rect, titles[n]);
                        }
                        else
                        {
                            if (props[n] == "-" || props[n] == "^" || props[n] == "v")
                            {
                                if (GUI.Button(rect, props[n]))
                                {
                                    switch (props[n])
                                    {
                                    case "-":
                                        items.DeleteArrayElementAtIndex(i);
                                        items.DeleteArrayElementAtIndex(i);
                                        changedLength = true;
                                        break;

                                    case "v":
                                        if (i > 0)
                                        {
                                            items.MoveArrayElement(i, i + 1);
                                        }
                                        break;

                                    case "^":
                                        if (i < items.arraySize - 1)
                                        {
                                            items.MoveArrayElement(i, i - 1);
                                        }
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                SerializedProperty prop = item.FindPropertyRelative(props[n]);
                                EditorGUI.PropertyField(rect, prop, GUIContent.none);
                            }
                        }
                    }

                    y += lineHeight + k_Spacing;
                    if (changedLength)
                    {
                        break;
                    }
                }
            }

            // add button
            var addButtonRect = new Rect((x + position.width) - widths[widths.Length - 1] * inspectorWidth, y,
                                         widths[widths.Length - 1] * inspectorWidth, lineHeight);

            if (GUI.Button(addButtonRect, "+"))
            {
                items.InsertArrayElementAtIndex(items.arraySize);
            }

            y += lineHeight + k_Spacing;

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
Beispiel #26
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // Indent label
        label.text = " " + label.text;

#if UNITY_2019_1_OR_NEWER
        GUI.Box(position, "");
#else
        GUI.Box(position, "", (GUIStyle)
                "flow overlay box");
#endif
        position.y += 4;
        // Using BeginProperty / EndProperty on the parent property means that
        // prefab override logic works on the entire property.
        EditorGUI.BeginProperty(position, label, property);
        // Draw label
        Rect pos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        Rect targetRect = new Rect(pos.x, pos.y, pos.width, EditorGUIUtility.singleLineHeight);

        // Get target
        SerializedProperty targetProp = property.FindPropertyRelative("_target");
        object             target     = targetProp.objectReferenceValue;
        if (attribute != null && attribute is TargetConstraintAttribute)
        {
            Type targetType = (attribute as TargetConstraintAttribute).targetType;
            EditorGUI.ObjectField(targetRect, targetProp, targetType, GUIContent.none);
        }
        else
        {
            EditorGUI.PropertyField(targetRect, targetProp, GUIContent.none);
        }

        if (target == null)
        {
            Rect   helpBoxRect = new Rect(position.x + 8, targetRect.max.y + EditorGUIUtility.standardVerticalSpacing, position.width - 16, EditorGUIUtility.singleLineHeight);
            string msg         = "Call not set. Execution will be slower.";
            EditorGUI.HelpBox(helpBoxRect, msg, MessageType.Warning);
        }
        else if (target is MonoScript)
        {
            Rect   helpBoxRect = new Rect(position.x + 8, targetRect.max.y + EditorGUIUtility.standardVerticalSpacing, position.width - 16, EditorGUIUtility.singleLineHeight + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
            string msg         = "Assign a GameObject, Component or a ScriptableObject, not a script.";
            EditorGUI.HelpBox(helpBoxRect, msg, MessageType.Warning);
        }
        else
        {
            int indent = EditorGUI.indentLevel;
            EditorGUI.indentLevel++;

            // Get method name
            SerializedProperty methodProp = property.FindPropertyRelative("_methodName");
            string             methodName = methodProp.stringValue;

            // Get args
            SerializedProperty argProps = property.FindPropertyRelative("_args");
            Type[]             argTypes = GetArgTypes(argProps);

            // Get dynamic
            SerializedProperty dynamicProp = property.FindPropertyRelative("_dynamic");
            bool dynamic = dynamicProp.boolValue;

            // Get active method
            MethodInfo activeMethod = GetMethod(target, methodName, argTypes);

            GUIContent methodlabel = new GUIContent("n/a");
            if (activeMethod != null)
            {
                methodlabel = new GUIContent(PrettifyMethod(activeMethod));
            }
            else if (!string.IsNullOrEmpty(methodName))
            {
                methodlabel = new GUIContent("Missing (" + PrettifyMethod(methodName, argTypes) + ")");
            }

            Rect methodRect = new Rect(position.x, targetRect.max.y + EditorGUIUtility.standardVerticalSpacing, position.width, EditorGUIUtility.singleLineHeight);

            // Method select button
            pos = EditorGUI.PrefixLabel(methodRect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(dynamic ? "Method (dynamic)" : "Method"));
            if (EditorGUI.DropdownButton(pos, methodlabel, FocusType.Keyboard))
            {
                MethodSelector(property);
            }

            if (activeMethod != null && !dynamic)
            {
                // Args
                ParameterInfo[] activeParameters = activeMethod.GetParameters();
                Rect            argRect          = new Rect(position.x, methodRect.max.y + EditorGUIUtility.standardVerticalSpacing, position.width, EditorGUIUtility.singleLineHeight);
                string[]        types            = new string[argProps.arraySize];
                for (int i = 0; i < types.Length; i++)
                {
                    SerializedProperty argProp  = argProps.FindPropertyRelative("Array.data[" + i + "]");
                    GUIContent         argLabel = new GUIContent(ObjectNames.NicifyVariableName(activeParameters[i].Name));

                    EditorGUI.BeginChangeCheck();
                    switch ((Arg.ArgType)argProp.FindPropertyRelative("argType").enumValueIndex)
                    {
                    case Arg.ArgType.Bool:
                        EditorGUI.PropertyField(argRect, argProp.FindPropertyRelative("boolValue"), argLabel);
                        break;

                    case Arg.ArgType.Int:
                        EditorGUI.PropertyField(argRect, argProp.FindPropertyRelative("intValue"), argLabel);
                        break;

                    case Arg.ArgType.Float:
                        EditorGUI.PropertyField(argRect, argProp.FindPropertyRelative("floatValue"), argLabel);
                        break;

                    case Arg.ArgType.String:
                        EditorGUI.PropertyField(argRect, argProp.FindPropertyRelative("stringValue"), argLabel);
                        break;

                    case Arg.ArgType.Object:
                        EditorGUI.PropertyField(argRect, argProp.FindPropertyRelative("objectValue"), argLabel);
                        break;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        property.FindPropertyRelative("dirty").boolValue = true;
                    }
                    argRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                }
            }
            EditorGUI.indentLevel = indent;
        }

        // Set indent back to what it was
        EditorGUI.EndProperty();
    }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            this.Init(property);

            EditorGUI.BeginProperty(position, label, property);

            //################################
            //FIRST LINE
            var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);

            rect = EditorGUI.PrefixLabel(rect, label);

            var targetProp = property.FindPropertyRelative(PROP_TARGET);

            var w0 = Mathf.Min(rect.width * 0.3f, 80f);
            var w1 = rect.width - w0;
            var r0 = new Rect(rect.xMin, rect.yMin, w0, EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(r0.xMax, rect.yMin, w1, EditorGUIUtility.singleLineHeight);

            var searchProp = property.FindPropertyRelative(PROP_SEARCHBY);
            var queryProp  = property.FindPropertyRelative(PROP_QUERY);

            var eSearchBy = (SearchByAlt)searchProp.GetEnumValue <SearchBy>();

            EditorGUI.BeginChangeCheck();
            eSearchBy = (SearchByAlt)EditorGUI.EnumPopup(r0, eSearchBy);
            if (EditorGUI.EndChangeCheck())
            {
                searchProp.SetEnumValue((SearchBy)eSearchBy);
            }

            switch (eSearchBy)
            {
            case SearchByAlt.Direct:
            {
                //SPEditorGUI.PropertyField(r1, targetProp, GUIContent.none);
                if (_selectableDrawer == null)
                {
                    _selectableDrawer = new SelectableComponentPropertyDrawer();
                }
                _selectableDrawer.AllowSceneObjects = true;
                _selectableDrawer.RestrictionType   = _inheritsFromType;
                _selectableDrawer.AllowProxy        = _allowProxy;
                _selectableDrawer.OnGUI(r1, targetProp, GUIContent.none);
            }
            break;

            case SearchByAlt.Tag:
            {
                queryProp.stringValue           = EditorGUI.TagField(r1, queryProp.stringValue);
                targetProp.objectReferenceValue = null;
            }
            break;

            case SearchByAlt.Name:
            {
                queryProp.stringValue           = EditorGUI.TextField(r1, queryProp.stringValue);
                targetProp.objectReferenceValue = null;
            }
            break;

            case SearchByAlt.Type:
            {
                var tp = TypeUtil.FindType(queryProp.stringValue);
                if (!TypeUtil.IsType(tp, typeof(UnityEngine.Object)))
                {
                    tp = null;
                }
                tp = SPEditorGUI.TypeDropDown(r1, GUIContent.none, typeof(UnityEngine.Object), tp);
                queryProp.stringValue           = (tp != null) ? tp.FullName : null;
                targetProp.objectReferenceValue = null;
            }
            break;
            }

            EditorGUI.EndProperty();
        }
        public override void OnInspectorGUI()
        {
            var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;

            if (renderPipelineAsset != null && renderPipelineAsset.GetType().Name == "HDRenderPipelineAsset")
            {
                serializedObject.Update();

                var  probeReferenceVolumes = FindObjectsOfType <ProbeReferenceVolumeAuthoring>();
                bool mismatchedProfile     = false;
                bool mismatchedTransform   = false;
                if (probeReferenceVolumes.Length > 1)
                {
                    foreach (var o1 in probeReferenceVolumes)
                    {
                        foreach (var o2 in probeReferenceVolumes)
                        {
                            if (!o1.profile.IsEquivalent(o2.profile))
                            {
                                mismatchedProfile = true;
                            }
                            if (o1.transform.worldToLocalMatrix != o2.transform.worldToLocalMatrix)
                            {
                                mismatchedTransform = true;
                            }
                        }
                    }

                    if (mismatchedProfile)
                    {
                        EditorGUILayout.HelpBox("Multiple Probe Reference Volume components are loaded, but they have different profiles. "
                                                + "This is unsupported, please make sure all loaded Probe Reference Volume have the same profile or profiles with equal values.", MessageType.Error, wide: true);
                    }
                    if (mismatchedTransform)
                    {
                        EditorGUILayout.HelpBox("Multiple Probe Reference Volume components are loaded, but they have different transforms. "
                                                + "This is currently unsupported, please make sure all loaded Probe Reference Volume have the same transform.", MessageType.Error, wide: true);
                    }
                }

                EditorGUI.BeginChangeCheck();

                // The layout system breaks alignment when mixing inspector fields with custom layout'd
                // fields, do the layout manually instead
                int   buttonWidth   = 60;
                float indentOffset  = EditorGUI.indentLevel * 15f;
                var   lineRect      = EditorGUILayout.GetControlRect();
                var   labelRect     = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
                var   fieldRect     = new Rect(labelRect.xMax, lineRect.y, lineRect.width - labelRect.width - buttonWidth, lineRect.height);
                var   buttonNewRect = new Rect(fieldRect.xMax, lineRect.y, buttonWidth, lineRect.height);

                GUIContent guiContent = EditorGUIUtility.TrTextContent("Profile", "A reference to a profile asset.");
                EditorGUI.PrefixLabel(labelRect, guiContent);

                using (var scope = new EditorGUI.ChangeCheckScope())
                {
                    EditorGUI.BeginProperty(fieldRect, GUIContent.none, m_Profile);

                    m_Profile.objectReferenceValue = (ProbeReferenceVolumeProfile)EditorGUI.ObjectField(fieldRect, m_Profile.objectReferenceValue, typeof(ProbeReferenceVolumeProfile), false);

                    EditorGUI.EndProperty();
                }

                if (GUI.Button(buttonNewRect, EditorGUIUtility.TrTextContent("New", "Create a new profile."), EditorStyles.miniButton))
                {
                    // By default, try to put assets in a folder next to the currently active
                    // scene file. If the user isn't a scene, put them in root instead.
                    var targetName = actualTarget.name;
                    var scene      = actualTarget.gameObject.scene;
                    var asset      = ProbeReferenceVolumeAuthoring.CreateReferenceVolumeProfile(scene, targetName);
                    m_Profile.objectReferenceValue = asset;
                }

                m_VolumeAsset.objectReferenceValue = EditorGUILayout.ObjectField(s_DataAssetLabel, m_VolumeAsset.objectReferenceValue, typeof(ProbeVolumeAsset), false);

                DebugVisualizationGroupEnabled = EditorGUILayout.BeginFoldoutHeaderGroup(DebugVisualizationGroupEnabled, "Debug Visualization");
                if (DebugVisualizationGroupEnabled)
                {
                    m_DrawCells.boolValue  = EditorGUILayout.Toggle("Draw Cells", m_DrawCells.boolValue);
                    m_DrawBricks.boolValue = EditorGUILayout.Toggle("Draw Bricks", m_DrawBricks.boolValue);
                    m_DrawProbes.boolValue = EditorGUILayout.Toggle("Draw Probes", m_DrawProbes.boolValue);
                    EditorGUI.BeginDisabledGroup(!m_DrawProbes.boolValue);
                    m_ProbeShading.enumValueIndex = EditorGUILayout.Popup("Probe Shading Mode", m_ProbeShading.enumValueIndex, ProbeShadingModes);
                    EditorGUI.BeginDisabledGroup(m_ProbeShading.enumValueIndex != 1);
                    m_ExposureCompensation.floatValue = EditorGUILayout.FloatField("Probe Exposure Compensation", m_ExposureCompensation.floatValue);
                    EditorGUI.EndDisabledGroup();
                    EditorGUI.EndDisabledGroup();
                    m_CullingDistance.floatValue = EditorGUILayout.FloatField("Culling Distance", m_CullingDistance.floatValue);
                }
                EditorGUILayout.EndFoldoutHeaderGroup();

                DilationGroupEnabled = EditorGUILayout.BeginFoldoutHeaderGroup(DilationGroupEnabled, "Dilation");
                if (DilationGroupEnabled)
                {
                    m_Dilate.boolValue = EditorGUILayout.Toggle("Dilate", m_Dilate.boolValue);
                    EditorGUI.BeginDisabledGroup(!m_Dilate.boolValue);
                    m_MaxDilationSamples.intValue          = EditorGUILayout.IntField("Max Dilation Samples", m_MaxDilationSamples.intValue);
                    m_MaxDilationSampleDistance.floatValue = EditorGUILayout.FloatField("Max Dilation Sample Distance", m_MaxDilationSampleDistance.floatValue);
                    DilationValidityThresholdInverted      = EditorGUILayout.Slider("Dilation Validity Threshold", DilationValidityThresholdInverted, 0f, 1f);
                    m_GreedyDilation.boolValue             = EditorGUILayout.Toggle("Greedy Dilation", m_GreedyDilation.boolValue);
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUILayout.EndFoldoutHeaderGroup();

                if (EditorGUI.EndChangeCheck())
                {
                    Constrain();
                    serializedObject.ApplyModifiedProperties();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Probe Volume is not a supported feature by this SRP.", MessageType.Error, wide: true);
            }
        }
Beispiel #29
0
 public AreaLightShapeEditionScope(Rect rect, GUIContent label, SerializedHDLight serialized)
 {
     EditorGUI.BeginProperty(rect, label, serialized.pointLightHDType);
     EditorGUI.BeginProperty(rect, label, serialized.settings.lightType);
     EditorGUI.BeginProperty(rect, label, serialized.areaLightShapeProperty);
 }
		public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){
			if (warningIcon == null)
			{
				warningIcon = EditorGUIUtility.FindTexture("console.warnicon.sml");
			}
			EditorGUI.BeginProperty (position, label, property);
			var r0 = new Rect (position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
			SerializedProperty foldoutProp1 = property.FindPropertyRelative ("defaultAnimationController");
			foldoutProp1.isExpanded = EditorGUI.Foldout (r0, foldoutProp1.isExpanded, "Race Animation Controllers");

			if (foldoutProp1.isExpanded) {
				EditorGUI.indentLevel++;
				var valR = r0;
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				EditorGUI.PropertyField (valR,property.FindPropertyRelative ("defaultAnimationController"));
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				SerializedProperty foldoutProp2 = property.FindPropertyRelative ("animators");
				foldoutProp2.isExpanded = EditorGUI.Foldout (valR, foldoutProp2.isExpanded, "Race Animators");
				//we cant delete elements in the loop so ...
				List<int> willDeleteArrayElementAtIndex = new List<int> ();

				if (foldoutProp2.isExpanded) {
					EditorGUI.indentLevel++;
					var thisAnimatorsProp = property.FindPropertyRelative ("animators");
					var numAnimators = thisAnimatorsProp.arraySize;
					var warningStyle = new GUIStyle(EditorStyles.label);
					warningStyle.fixedHeight = warningIcon.height + 4f;
					warningStyle.contentOffset = new Vector2(0, -2f);
					for (int i = 0; i < numAnimators; i++) {
						var thisAnimtorProp = thisAnimatorsProp.GetArrayElementAtIndex (i);
						valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
						var propsR = valR;
						propsR.width = propsR.width - 20f;
						var rPropR = propsR;
						rPropR.width = rPropR.width / 2;
						var aPropR = rPropR;
						aPropR.x = propsR.x + rPropR.width;
						var rLabelR = rPropR;
						rLabelR.width = (float)(rLabelR.width * 0.3)+(15f * (EditorGUI.indentLevel -1));
						var rFieldR = rPropR;
						rFieldR.x = rFieldR.x + rLabelR.width;
						rFieldR.width = rFieldR.width - rLabelR.width;
						//
						var aLabelR = aPropR;
						aLabelR.width = (float)(aLabelR.width * 0.3);
						var aFieldR = aPropR;
						aFieldR.x = aFieldR.x + aLabelR.width;
						aFieldR.width = aFieldR.width - aLabelR.width;
						var removeR = propsR;
						removeR.x = aFieldR.xMax;
						removeR.width = 20f;

						EditorGUI.LabelField (rLabelR, "Race");
						EditorGUI.indentLevel--;
						EditorGUI.indentLevel--;
						if (thisAnimtorProp.FindPropertyRelative ("raceName").stringValue == "") {
							//draw an object field for RaceData
							EditorGUI.BeginChangeCheck();
							RaceData thisRD = null;
							thisRD = (RaceData)EditorGUI.ObjectField (rFieldR, thisRD, typeof(RaceData),false);
							//if this gets filled set the values
							if(EditorGUI.EndChangeCheck()){
								if (thisRD != null) {
									thisAnimatorsProp.GetArrayElementAtIndex (i).FindPropertyRelative ("raceName").stringValue = thisRD.raceName;
								}
							}
						}
						else
						{
							EditorGUI.BeginDisabledGroup (true);
							EditorGUI.TextField (rFieldR, thisAnimtorProp.FindPropertyRelative ("raceName").stringValue);
							EditorGUI.EndDisabledGroup ();
						}
						EditorGUI.LabelField (aLabelR, "Animator");
						var thisAnimatorName = thisAnimtorProp.FindPropertyRelative("animatorControllerName").stringValue;
						if (thisAnimatorName == "")
						{
							//draw an object field for RunTimeAnimatorController
							EditorGUI.BeginChangeCheck();
							RuntimeAnimatorController thisRC = null;
							thisRC = (RuntimeAnimatorController)EditorGUI.ObjectField (aFieldR, thisRC, typeof(RuntimeAnimatorController), false);
							//if this gets filled set the values
							if(EditorGUI.EndChangeCheck()){
								if (thisRC != null) {
									thisAnimatorsProp.GetArrayElementAtIndex (i).FindPropertyRelative ("animatorControllerName").stringValue = thisRC.name;
								}
							}
						}
						else
						{
							if (DynamicAssetLoader.Instance)
							{
								if (!CheckAnimatorAvailability(thisAnimatorName))
								{
									var warningRect = new Rect((removeR.xMin - 20f), removeR.yMin, 20f, removeR.height);
									aFieldR.xMax = aFieldR.xMax - 20f;
									//if its in an assetbundle we need a different message (i.e "turn on 'Dynamically Add From AssetBundles"') 
									var warningGUIContent = new GUIContent("", thisAnimtorProp.FindPropertyRelative("animatorControllerName").stringValue + " was not Live. If the asset is in an assetBundle check 'Dynamically Add from AssetBundles' below otherwise click this button to add it to the Global Library.");
									warningGUIContent.image = warningIcon;
									if (GUI.Button(warningRect, warningGUIContent, warningStyle))
									{
										var thisAnimator = FindMissingAnimator(thisAnimatorName);
										if (thisAnimator != null)
											UMAAssetIndexer.Instance.EvilAddAsset(thisAnimator.GetType(), thisAnimator);
										else
											UMAAssetIndexerEditor.ShowWindow();
									}
								}
							}
							EditorGUI.BeginDisabledGroup(true);
							EditorGUI.TextField(aFieldR, thisAnimtorProp.FindPropertyRelative("animatorControllerName").stringValue);
							EditorGUI.EndDisabledGroup();
						}
						if(GUI.Button(removeR,"X")){
							willDeleteArrayElementAtIndex.Add(i);
						}
						EditorGUI.indentLevel++;
						EditorGUI.indentLevel++;
					}
					if (willDeleteArrayElementAtIndex.Count > 0) {
						foreach (int i in willDeleteArrayElementAtIndex) {
							thisAnimatorsProp.DeleteArrayElementAtIndex (i);
						}
					}
					thisAnimatorsProp.serializedObject.ApplyModifiedProperties();
					valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
					var butValR = valR;
					//GUI doesn't know EditorGUI.indentLevel
					butValR.xMin = valR.xMin + (15 * EditorGUI.indentLevel);
					if(GUI.Button(butValR,"Add Race Animator")){
						//add a new element to the list
						thisAnimatorsProp.InsertArrayElementAtIndex(numAnimators);
						thisAnimatorsProp.serializedObject.ApplyModifiedProperties();
						//make sure its blank
						thisAnimatorsProp.GetArrayElementAtIndex(numAnimators).FindPropertyRelative("raceName").stringValue = "";
						thisAnimatorsProp.GetArrayElementAtIndex(numAnimators).FindPropertyRelative("animatorControllerName").stringValue = "";
						thisAnimatorsProp.GetArrayElementAtIndex(numAnimators).FindPropertyRelative("animatorController").objectReferenceValue = null;
						thisAnimatorsProp.serializedObject.ApplyModifiedProperties();
					}
					EditorGUI.indentLevel--;
				}
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				var dynamicallyAddFromResources = property.FindPropertyRelative ("dynamicallyAddFromResources").boolValue;
				EditorGUI.BeginChangeCheck();
				dynamicallyAddFromResources = EditorGUI.ToggleLeft(valR,"Dynamically Add from Global Library", dynamicallyAddFromResources);
				if(EditorGUI.EndChangeCheck()){
					property.FindPropertyRelative ("dynamicallyAddFromResources").boolValue = dynamicallyAddFromResources;
					property.serializedObject.ApplyModifiedProperties ();
				}
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				EditorGUI.PropertyField (valR,property.FindPropertyRelative ("resourcesFolderPath"), new GUIContent("Global Library Folder Filter"));
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				var dynamicallyAddFromAssetBundles = property.FindPropertyRelative ("dynamicallyAddFromAssetBundles").boolValue;
				EditorGUI.BeginChangeCheck();
				dynamicallyAddFromAssetBundles = EditorGUI.ToggleLeft(valR,"Dynamically Add from Asset Bundles", dynamicallyAddFromAssetBundles);
				if(EditorGUI.EndChangeCheck()){
					property.FindPropertyRelative ("dynamicallyAddFromAssetBundles").boolValue = dynamicallyAddFromAssetBundles;
					property.serializedObject.ApplyModifiedProperties ();
				}
				valR = new Rect (valR.xMin, valR.yMax + padding, valR.width, EditorGUIUtility.singleLineHeight);
				EditorGUI.PropertyField (valR,property.FindPropertyRelative ("assetBundleNames"), new GUIContent("AssetBundles to Search"));
				EditorGUI.indentLevel--;
			}
			EditorGUI.EndProperty ();
		}