Beispiel #1
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            EditorGUILayout.Space();

            // toolbar with available brush modes  for the current property:
            editor.currentProperty.BrushModes(paintBrush);

            EditorGUILayout.Space();

            if (editor.PropertySelector())
            {
                editor.currentProperty.OnSelect(paintBrush);
            }

            if (paintBrush.brushMode.needsInputValue)
            {
                editor.currentProperty.PropertyField();
            }

            paintBrush.radius      = EditorGUILayout.Slider("Brush size", paintBrush.radius, 0.0001f, 0.5f);
            paintBrush.innerRadius = EditorGUILayout.Slider("Brush inner size", paintBrush.innerRadius, 0, 1);
            paintBrush.opacity     = EditorGUILayout.Slider("Brush opacity", paintBrush.opacity, 0, 1);

            EditorGUI.BeginChangeCheck();
            meshBasedEditor.particleCulling = (ObiMeshBasedActorBlueprintEditor.ParticleCulling)EditorGUILayout.EnumPopup("Culling", meshBasedEditor.particleCulling);
            if (editor.selectedCount == 0)
            {
                EditorGUILayout.HelpBox("Select at least one particle to use selection mask.", MessageType.Info);
                selectionMask = false;
                GUI.enabled   = false;
            }
            selectionMask = EditorGUILayout.Toggle("Selection mask", selectionMask);
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
            GUI.enabled = true;

            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            visualizationOptions = EditorGUILayout.Foldout(visualizationOptions, "Visualization");

            if (visualizationOptions)
            {
                editor.RenderModeSelector();
                editor.currentProperty.VisualizationOptions();
            }
            EditorGUILayout.EndVertical();
        }
Beispiel #2
0
        protected void DrawTools()
        {
            GUIContent[] contents = new GUIContent[tools.Count];

            for (int i = 0; i < tools.Count; ++i)
            {
                contents[i] = new GUIContent(tools[i].icon, tools[i].name);
            }

            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            EditorGUI.BeginChangeCheck();
            int newSelectedTool = ObiEditorUtils.DoToolBar(currentToolIndex, contents);

            EditorGUILayout.EndVertical();

            if (EditorGUI.EndChangeCheck())
            {
                if (currentTool != null)
                {
                    currentTool.OnDisable();
                }

                currentToolIndex = newSelectedTool;

                if (currentTool != null)
                {
                    currentTool.OnEnable();
                }

                SceneView.RepaintAll();
            }

            if (currentTool != null)
            {
                EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
                EditorGUILayout.LabelField(currentTool.name, EditorStyles.boldLabel);

                string help = currentTool.GetHelpString();
                if (!help.Equals(string.Empty))
                {
                    EditorGUILayout.LabelField(help, EditorStyles.helpBox);
                }
                EditorGUILayout.EndVertical();

                currentTool.OnInspectorGUI();
            }
        }
Beispiel #3
0
        void UpdateEditMode()
        {
            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

            EditorGUILayout.PropertyField(barycentricWeight);
            EditorGUILayout.PropertyField(normalAlignmentWeight);
            EditorGUILayout.PropertyField(elevationWeight);

            EditorGUI.BeginChangeCheck();
            paintMode    = GUILayout.Toggle(paintMode, new GUIContent("Paint skin", Resources.Load <Texture2D>("PaintButton")), "LargeButton");
            Tools.hidden = paintMode || subject == SubjectBeingEdited.Master;
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }

            // Buttons:
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Bind") && masterObject != null && slaveObject != null)
            {
                EditorUtility.SetDirty(target);
                CoroutineJob job = new CoroutineJob();
                routine = job.Start(skinMap.Bind());
                EditorCoroutine.ShowCoroutineProgressBar("Generating skinmap...", ref routine);
                EditorGUIUtility.ExitGUI();
            }

            if (GUILayout.Button("Done"))
            {
                EditorApplication.delayCall += ExitSkinEditMode;
            }

            GUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            // skin channel selector:
            if (paintMode)
            {
                EditorGUILayout.Space();
                GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

                EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

                // Brush parameters:
                paintBrush.radius      = EditorGUILayout.Slider("Brush size", paintBrush.radius, 0.0001f, 0.5f);
                paintBrush.innerRadius = 1;
                paintBrush.opacity     = 1;

                EditorGUI.BeginChangeCheck();
                if (paintBrush.brushMode.needsInputValue)
                {
                    currentProperty.PropertyField();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    SceneView.RepaintAll();
                }

                GUILayout.BeginHorizontal();

                if (GUILayout.Button(new GUIContent("Fill"), EditorStyles.miniButtonLeft))
                {
                    if (subject == SubjectBeingEdited.Master)
                    {
                        skinMap.FillChannel(skinMap.m_MasterChannels, currentProperty.GetDefault());
                    }
                    else
                    {
                        skinMap.FillChannel(skinMap.m_SlaveChannels, currentProperty.GetDefault());
                    }
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button(new GUIContent("Clear"), EditorStyles.miniButtonMid))
                {
                    if (subject == SubjectBeingEdited.Master)
                    {
                        skinMap.ClearChannel(skinMap.m_MasterChannels, currentProperty.GetDefault());
                    }
                    else
                    {
                        skinMap.ClearChannel(skinMap.m_SlaveChannels, currentProperty.GetDefault());
                    }
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button(new GUIContent("Copy"), EditorStyles.miniButtonMid))
                {
                    targetSkinChannel = currentProperty.GetDefault();
                }

                if (GUILayout.Button(new GUIContent("Paste"), EditorStyles.miniButtonRight))
                {
                    if (subject == SubjectBeingEdited.Master)
                    {
                        skinMap.CopyChannel(skinMap.m_MasterChannels, targetSkinChannel, currentProperty.GetDefault());
                    }
                    else
                    {
                        skinMap.CopyChannel(skinMap.m_SlaveChannels, targetSkinChannel, currentProperty.GetDefault());
                    }
                    SceneView.RepaintAll();
                }

                GUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Slave transform", EditorStyles.boldLabel);
            if (GUILayout.Button("Reset", EditorStyles.miniButton))
            {
                skinMap.m_SlaveTransform.Reset();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_SlaveTransform"));

            EditorGUILayout.EndVertical();
        }
        public override void OnInspectorGUI()
        {
            // Selection tools:
            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            EditorGUILayout.Space();

            selectionBrush.radius = EditorGUILayout.Slider("Brush size", selectionBrush.radius, 5, 200);

            if (editor is ObiMeshBasedActorBlueprintEditor)
            {
                EditorGUI.BeginChangeCheck();
                (editor as ObiMeshBasedActorBlueprintEditor).particleCulling = (ObiMeshBasedActorBlueprintEditor.ParticleCulling)EditorGUILayout.EnumPopup("Culling", (editor as ObiMeshBasedActorBlueprintEditor).particleCulling);
                if (EditorGUI.EndChangeCheck())
                {
                    SceneView.RepaintAll();
                }
            }


            EditorGUILayout.Space();
            SelectionTools();

            EditorGUILayout.EndVertical();


            // Properties:
            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Properties", EditorStyles.boldLabel);
            if (editor.PropertySelector())
            {
                UpdateSelection();
            }

            // Property value:
            EditorGUI.showMixedValue = mixedPropertyValue;
            EditorGUI.BeginChangeCheck();
            editor.currentProperty.PropertyField();
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(editor.Blueprint, "Set particle property");
                for (int i = 0; i < editor.selectionStatus.Length; i++)
                {
                    if (!editor.selectionStatus[i])
                    {
                        continue;
                    }
                    editor.currentProperty.SetDefaultToIndex(i);
                }
                editor.Refresh();
            }

            EditorGUI.showMixedValue = false;

            EditorGUILayout.EndVertical();


            // Particle groups:
            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Particle groups", EditorStyles.boldLabel);
            particleGroupList.DoLayoutList();

            EditorGUILayout.EndVertical();



            if (editor.Blueprint.usesTethers)
            {
                EditorGUILayout.Space();
                GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());
                EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
                EditorGUILayout.Space();
                tethersTool.DoTethers(editor);
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            visualizationOptions = EditorGUILayout.Foldout(visualizationOptions, "Visualization");

            if (visualizationOptions)
            {
                editor.RenderModeSelector();
                editor.currentProperty.VisualizationOptions();
            }
            EditorGUILayout.EndVertical();
        }
        public override void OnInspectorGUI()
        {
            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            EditorGUILayout.Space();
            editor.RenderModeSelector();
            editor.PropertySelector();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            import = EditorGUILayout.Foldout(import, "Import texture");

            if (import)
            {
                propertyTexture = (Texture2D)EditorGUILayout.ObjectField("Source", propertyTexture, typeof(Texture2D), false);

                floatProperty = editor.currentProperty as ObiBlueprintFloatProperty;
                colorProperty = editor.currentProperty as ObiBlueprintColorProperty;

                if (floatProperty != null)
                {
                    textureReadCallback = FloatFromTexture;
                    textureChannel      = (TextureChannel)EditorGUILayout.EnumPopup("Source channel", textureChannel);
                    minPropertyValue    = EditorGUILayout.FloatField("Min value", minPropertyValue);
                    maxPropertyValue    = EditorGUILayout.FloatField("Max value", maxPropertyValue);
                }
                else if (colorProperty != null)
                {
                    textureReadCallback = ColorFromTexture;
                }

                if (GUILayout.Button("Import"))
                {
                    Undo.RecordObject(editor.blueprint, "Import particle property");
                    if (!meshBasedEditor.ReadParticlePropertyFromTexture(propertyTexture, textureReadCallback))
                    {
                        EditorUtility.DisplayDialog("Invalid texture", "The texture is either null or not readable.", "Ok");
                    }

                    // force automatic range calculation for floating point properties.
                    if (floatProperty != null)
                    {
                        floatProperty.autoRange = true;
                    }
                    editor.Refresh();
                }
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();
            GUILayout.Box(GUIContent.none, ObiEditorUtils.GetSeparatorLineStyle());

            EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
            export = EditorGUILayout.Foldout(export, "Export texture");

            if (export)
            {
                exportWidth  = EditorGUILayout.IntField("Texture width", exportWidth);
                exportHeight = EditorGUILayout.IntField("Texture height", exportHeight);
                padding      = EditorGUILayout.IntField("Padding", padding);
                if (GUILayout.Button("Export"))
                {
                    var path = EditorUtility.SaveFilePanel("Save texture as PNG",
                                                           "",
                                                           "property.png",
                                                           "png");
                    if (path.Length > 0)
                    {
                        // force automatic range calculation for floating point properties.
                        if (floatProperty != null)
                        {
                            floatProperty.autoRange = true;
                        }
                        editor.Refresh();

                        if (!meshBasedEditor.WriteParticlePropertyToTexture(path, exportWidth, exportHeight, padding))
                        {
                            EditorUtility.DisplayDialog("Invalid path", "Could not write a texture to that location.", "Ok");
                        }
                    }
                }
            }

            EditorGUILayout.EndVertical();
        }
        private void DrawControlPointInspector()
        {
            GUI.enabled = selectedCount > 0;
            EditorGUILayout.BeginVertical();

            GUILayout.Box("", ObiEditorUtils.GetSeparatorLineStyle());

            // tangent mode:
            EditorGUI.showMixedValue = false;
            var  mode          = ObiWingedPoint.TangentMode.Free;
            bool firstSelected = true;

            for (int i = 0; i < path.ControlPointCount; ++i)
            {
                if (selectedStatus[i])
                {
                    if (firstSelected)
                    {
                        mode          = path.points[i].tangentMode;
                        firstSelected = false;
                    }
                    else if (mode != path.points[i].tangentMode)
                    {
                        EditorGUI.showMixedValue = true;
                        break;
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            var newMode = (ObiWingedPoint.TangentMode)EditorGUILayout.EnumPopup("Tangent mode", mode, GUI.skin.FindStyle("DropDown"), GUILayout.MinWidth(94));

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change control points mode");

                for (int i = 0; i < path.ControlPointCount; ++i)
                {
                    if (selectedStatus[i])
                    {
                        var wp = path.points[i];
                        wp.tangentMode = newMode;
                        path.points[i] = wp;
                    }
                }
                path.FlushEvents();
                needsRepaint = true;
            }

            // thickness:
            EditorGUI.showMixedValue = false;
            float thickness = 0;

            firstSelected = true;
            for (int i = 0; i < path.ControlPointCount; ++i)
            {
                if (selectedStatus[i])
                {
                    if (firstSelected)
                    {
                        thickness     = path.thicknesses[i];
                        firstSelected = false;
                    }
                    else if (!Mathf.Approximately(thickness, path.thicknesses[i]))
                    {
                        EditorGUI.showMixedValue = true;
                        break;
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            thickness = EditorGUILayout.FloatField("Thickness", thickness, GUILayout.MinWidth(94));
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change control point thickness");

                for (int i = 0; i < path.ControlPointCount; ++i)
                {
                    if (selectedStatus[i])
                    {
                        path.thicknesses[i] = Mathf.Max(0, thickness);
                    }
                }
                path.FlushEvents();
                needsRepaint = true;
            }

            // mass:
            EditorGUI.showMixedValue = false;
            float mass = 0;

            firstSelected = true;
            for (int i = 0; i < path.ControlPointCount; ++i)
            {
                if (selectedStatus[i])
                {
                    if (firstSelected)
                    {
                        mass          = path.masses[i];
                        firstSelected = false;
                    }
                    else if (!Mathf.Approximately(mass, path.masses[i]))
                    {
                        EditorGUI.showMixedValue = true;
                        break;
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            mass = EditorGUILayout.FloatField("Mass", mass, GUILayout.MinWidth(94));
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change control point mass");

                for (int i = 0; i < path.ControlPointCount; ++i)
                {
                    if (selectedStatus[i])
                    {
                        path.masses[i] = mass;
                    }
                }
                path.FlushEvents();
                needsRepaint = true;
            }

            if (useOrientation)
            {
                // rotational mass:
                EditorGUI.showMixedValue = false;
                float rotationalMass = 0;
                firstSelected = true;
                for (int i = 0; i < path.ControlPointCount; ++i)
                {
                    if (selectedStatus[i])
                    {
                        if (firstSelected)
                        {
                            rotationalMass = path.rotationalMasses[i];
                            firstSelected  = false;
                        }
                        else if (!Mathf.Approximately(rotationalMass, path.rotationalMasses[i]))
                        {
                            EditorGUI.showMixedValue = true;
                            break;
                        }
                    }
                }

                EditorGUI.BeginChangeCheck();
                rotationalMass           = EditorGUILayout.FloatField("Rotational mass", rotationalMass, GUILayout.MinWidth(94));
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(target, "Change control point rotational mass");

                    for (int i = 0; i < path.ControlPointCount; ++i)
                    {
                        if (selectedStatus[i])
                        {
                            path.rotationalMasses[i] = rotationalMass;
                        }
                    }
                    path.FlushEvents();
                    needsRepaint = true;
                }
            }

            // phase:
            EditorGUI.showMixedValue = false;
            int phase = 0;

            firstSelected = true;
            for (int i = 0; i < path.ControlPointCount; ++i)
            {
                if (selectedStatus[i])
                {
                    if (firstSelected)
                    {
                        phase         = path.phases[i];
                        firstSelected = false;
                    }
                    else if (!Mathf.Approximately(phase, path.phases[i]))
                    {
                        EditorGUI.showMixedValue = true;
                        break;
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            phase = EditorGUILayout.IntField("Phase", phase, GUILayout.MinWidth(94));
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change control point phase");

                for (int i = 0; i < path.ControlPointCount; ++i)
                {
                    if (selectedStatus[i])
                    {
                        path.phases[i] = phase;
                    }
                }
                path.FlushEvents();
                needsRepaint = true;
            }

            // color:
            EditorGUI.showMixedValue = false;
            Color color = Color.white;

            firstSelected = true;
            for (int i = 0; i < path.ControlPointCount; ++i)
            {
                if (selectedStatus[i])
                {
                    if (firstSelected)
                    {
                        color         = path.colors[i];
                        firstSelected = false;
                    }
                    else if (color != path.colors[i])
                    {
                        EditorGUI.showMixedValue = true;
                        break;
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            color = EditorGUILayout.ColorField("Color", color, GUILayout.MinWidth(94));
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change control point color");

                for (int i = 0; i < path.ControlPointCount; ++i)
                {
                    if (selectedStatus[i])
                    {
                        path.colors[i] = color;
                    }
                }
                path.FlushEvents();
                needsRepaint = true;
            }

            // name:
            EditorGUI.showMixedValue = false;
            string name = "";

            firstSelected = true;
            for (int i = 0; i < path.ControlPointCount; ++i)
            {
                if (selectedStatus[i])
                {
                    if (firstSelected)
                    {
                        name          = path.GetName(i);
                        firstSelected = false;
                    }
                    else if (name != path.GetName(i))
                    {
                        EditorGUI.showMixedValue = true;
                        break;
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            name = EditorGUILayout.DelayedTextField("Name", name, GUILayout.MinWidth(94));
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change control point name");

                for (int i = 0; i < path.ControlPointCount; ++i)
                {
                    if (selectedStatus[i])
                    {
                        path.SetName(i, name);
                    }
                }
                path.FlushEvents();
                needsRepaint = true;
            }


            EditorGUILayout.EndVertical();

            GUI.enabled = true;
        }