Пример #1
0
        static void renameToAnimate(MenuCommand command)
        {
            if (UnityEditor.Selection.gameObjects.Length > 0)
            {
                ClayObject clayObj = UnityEditor.Selection.gameObjects[0].GetComponent <ClayObject>();
                if (clayObj != null)
                {
                    ClayContainer container = clayObj.getClayContainer();
                    ClayContainer._skipHierarchyChanges = true;            // otherwise each rename will trigger onHierarchyChange

                    int numClayObjs = container.getNumClayObjects();

                    for (int i = 0; i < numClayObjs; ++i)
                    {
                        ClayObject currentClayObj = container.getClayObject(i);

                        if (currentClayObj.gameObject.name.StartsWith("clay_"))
                        {
                            container.autoRenameClayObject(currentClayObj);
                            currentClayObj.name = "(" + i + ")" + currentClayObj.gameObject.name;
                        }
                    }

                    ClayContainer._skipHierarchyChanges = false;
                }
            }
        }
Пример #2
0
 static void sendAfterClayObject(MenuCommand command)
 {
     if (UnityEditor.Selection.gameObjects.Length > 0)
     {
         ClayObject clayObj = UnityEditor.Selection.gameObjects[0].GetComponent <ClayObject>();
         if (clayObj != null)
         {
             clayObj.getClayContainer().selectToReorder(clayObj, 1);
         }
     }
 }
Пример #3
0
 static void OrderFromHierarchyOn(MenuCommand command)
 {
     if (UnityEditor.Selection.gameObjects.Length > 0)
     {
         ClayObject clayObj = UnityEditor.Selection.gameObjects[0].GetComponent <ClayObject>();
         if (clayObj != null)
         {
             clayObj.getClayContainer().setClayObjectsOrderLocked(true);
         }
     }
 }
Пример #4
0
        public override void OnInspectorGUI()
        {
            UnityEditor.EditorApplication.QueuePlayerLoopUpdate();

            ClayObject    clayObj = (ClayObject)this.targets[0];
            ClayContainer clayxel = clayObj.getClayContainer();

            if (clayxel == null)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();

            string[] solidsLabels  = clayxel.getSolidsCatalogueLabels();
            int      primitiveType = EditorGUILayout.Popup("solidType", clayObj.primitiveType, solidsLabels);

            float blend = EditorGUILayout.Slider("blend", Mathf.Abs(clayObj.blend) * 100.0f, 0.0f, 100.0f);

            if (clayObj.blend < 0.0f)
            {
                if (blend < 0.001f)
                {
                    blend = 0.001f;
                }

                blend *= -1.0f;
            }

            blend *= 0.01f;
            if (blend > 1.0f)
            {
                blend = 1.0f;
            }
            else if (blend < -1.0f)
            {
                blend = -1.0f;
            }

            GUILayout.BeginHorizontal();

            Color defaultColor = GUI.backgroundColor;

            if (clayObj.blend >= 0.0f)
            {
                GUI.backgroundColor = Color.yellow;
            }

            if (GUILayout.Button(new GUIContent("add", "Additive blend")))
            {
                blend = Mathf.Abs(blend);
            }

            GUI.backgroundColor = defaultColor;

            if (clayObj.blend < 0.0f)
            {
                GUI.backgroundColor = Color.yellow;
            }

            if (GUILayout.Button(new GUIContent("sub", "Subtractive blend")))
            {
                if (blend == 0.0f)
                {
                    blend = 0.0001f;
                }

                blend = blend * -1.0f;
            }

            GUI.backgroundColor = defaultColor;

            GUILayout.EndHorizontal();

            Color color = EditorGUILayout.ColorField("color", clayObj.color);

            Dictionary <string, float> paramValues = new Dictionary <string, float>();

            paramValues["x"] = clayObj.attrs.x;
            paramValues["y"] = clayObj.attrs.y;
            paramValues["z"] = clayObj.attrs.z;
            paramValues["w"] = clayObj.attrs.w;

            List <string[]> parameters  = clayxel.getSolidsCatalogueParameters(primitiveType);
            List <string>   wMaskLabels = new List <string>();

            for (int paramIt = 0; paramIt < parameters.Count; ++paramIt)
            {
                string[] parameterValues = parameters[paramIt];
                string   attr            = parameterValues[0];
                string   label           = parameterValues[1];
                string   defaultValue    = parameterValues[2];

                if (primitiveType != clayObj.primitiveType)
                {
                    // reset to default params when changing primitive type
                    paramValues[attr] = float.Parse(defaultValue, CultureInfo.InvariantCulture);
                }

                if (attr.StartsWith("w"))
                {
                    wMaskLabels.Add(label);
                }
                else
                {
                    paramValues[attr] = EditorGUILayout.FloatField(label, paramValues[attr] * 100.0f) * 0.01f;
                }
            }

            if (wMaskLabels.Count > 0)
            {
                paramValues["w"] = (float)EditorGUILayout.MaskField("options", (int)clayObj.attrs.w, wMaskLabels.ToArray());
            }

            if (EditorGUI.EndChangeCheck())
            {
                ClayContainer._inspectorUpdate();
                ClayContainer._skipHierarchyChanges = true;

                Undo.RecordObjects(this.targets, "changed clayobject");

                for (int i = 1; i < this.targets.Length; ++i)
                {
                    bool       somethingChanged = false;
                    ClayObject currentClayObj   = (ClayObject)this.targets[i];
                    bool       shouldAutoRename = false;

                    if (Mathf.Abs(clayObj.blend - blend) > 0.001f || Mathf.Sign(clayObj.blend) != Mathf.Sign(blend))
                    {
                        currentClayObj.blend = blend;
                        somethingChanged     = true;
                        shouldAutoRename     = true;
                    }

                    if (clayObj.color != color)
                    {
                        currentClayObj.color = color;
                        somethingChanged     = true;
                    }

                    if (clayObj.primitiveType != primitiveType)
                    {
                        currentClayObj.primitiveType = primitiveType;
                        somethingChanged             = true;
                        shouldAutoRename             = true;
                    }

                    if (clayObj.attrs.x != paramValues["x"])
                    {
                        currentClayObj.attrs.x = paramValues["x"];
                        somethingChanged       = true;
                    }

                    if (clayObj.attrs.y != paramValues["y"])
                    {
                        currentClayObj.attrs.y = paramValues["y"];
                        somethingChanged       = true;
                    }

                    if (clayObj.attrs.z != paramValues["z"])
                    {
                        currentClayObj.attrs.z = paramValues["z"];
                        somethingChanged       = true;
                    }

                    if (clayObj.attrs.w != paramValues["w"])
                    {
                        currentClayObj.attrs.w = paramValues["w"];
                        somethingChanged       = true;
                        shouldAutoRename       = true;
                    }

                    if (somethingChanged)
                    {
                        currentClayObj.getClayContainer().clayObjectUpdated(currentClayObj);

                        if (shouldAutoRename)
                        {
                            if (currentClayObj.gameObject.name.StartsWith("clay_"))
                            {
                                clayxel.autoRenameClayObject(currentClayObj);
                            }
                        }
                    }

                    ClayContainer._skipHierarchyChanges = false;
                }

                clayObj.blend         = blend;
                clayObj.color         = color;
                clayObj.primitiveType = primitiveType;
                clayObj.attrs.x       = paramValues["x"];
                clayObj.attrs.y       = paramValues["y"];
                clayObj.attrs.z       = paramValues["z"];
                clayObj.attrs.w       = paramValues["w"];

                if (clayObj.gameObject.name.StartsWith("clay_"))
                {
                    clayxel.autoRenameClayObject(clayObj);
                }

                clayObj.forceUpdate();

                UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                ClayContainer.getSceneView().Repaint();

                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();

            ClayObject.ClayObjectMode mode = (ClayObject.ClayObjectMode)EditorGUILayout.EnumPopup("mode", clayObj.mode);

            if (EditorGUI.EndChangeCheck())
            {
                clayObj.setMode(mode);

                UnityEditor.EditorApplication.QueuePlayerLoopUpdate();

                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
                }
            }

            if (clayObj.mode == ClayObject.ClayObjectMode.offset)
            {
                this.drawOffsetMode(clayObj);
            }
            else if (clayObj.mode == ClayObject.ClayObjectMode.spline)
            {
                this.drawSplineMode(clayObj);
            }

            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            GUI.enabled = !clayxel.isClayObjectsOrderLocked();
            int clayObjectId = EditorGUILayout.IntField("order", clayObj.clayObjectId);

            GUI.enabled = true;

            if (!clayxel.isClayObjectsOrderLocked())
            {
                if (clayObjectId != clayObj.clayObjectId)
                {
                    int idOffset = clayObjectId - clayObj.clayObjectId;
                    clayxel.reorderClayObject(clayObj.clayObjectId, idOffset);
                }
            }

            if (GUILayout.Button(new GUIContent("↑", "")))
            {
                clayxel.reorderClayObject(clayObj.clayObjectId, -1);
            }
            if (GUILayout.Button(new GUIContent("↓", "")))
            {
                clayxel.reorderClayObject(clayObj.clayObjectId, 1);
            }
            if (GUILayout.Button(new GUIContent("⋮", "")))
            {
                EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), "Component/Clayxels/ClayObject", null);
            }
            GUILayout.EndHorizontal();
        }
Пример #5
0
        public override void OnInspectorGUI()
        {
            ClayObject    clayObj = (ClayObject)this.targets[0];
            ClayContainer clayxel = clayObj.getClayContainer();

            EditorGUI.BeginChangeCheck();

            ClayObject.ClayObjectMode mode = (ClayObject.ClayObjectMode)EditorGUILayout.EnumPopup("mode", clayObj.mode);

            if (EditorGUI.EndChangeCheck())
            {
                clayObj.setMode(mode);

                UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
            }

            if (clayObj.mode == ClayObject.ClayObjectMode.offset)
            {
                this.drawOffsetMode(clayObj);
            }
            else if (clayObj.mode == ClayObject.ClayObjectMode.spline)
            {
                this.drawSplineMode(clayObj);
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();

            float blend = EditorGUILayout.FloatField("blend", clayObj.blend);

            if (blend > 1.0f)
            {
                blend = 1.0f;
            }
            else if (blend < -1.0f)
            {
                blend = -1.0f;
            }

            Color color = EditorGUILayout.ColorField("color", clayObj.color);

            string[] solidsLabels  = clayxel.getSolidsCatalogueLabels();
            int      primitiveType = EditorGUILayout.Popup("solidType", clayObj.primitiveType, solidsLabels);

            Dictionary <string, float> paramValues = new Dictionary <string, float>();

            paramValues["x"] = clayObj.attrs.x;
            paramValues["y"] = clayObj.attrs.y;
            paramValues["z"] = clayObj.attrs.z;
            paramValues["w"] = clayObj.attrs.w;

            List <string[]> parameters  = clayxel.getSolidsCatalogueParameters(primitiveType);
            List <string>   wMaskLabels = new List <string>();

            for (int paramIt = 0; paramIt < parameters.Count; ++paramIt)
            {
                string[] parameterValues = parameters[paramIt];
                string   attr            = parameterValues[0];
                string   label           = parameterValues[1];
                string   defaultValue    = parameterValues[2];

                if (primitiveType != clayObj.primitiveType)
                {
                    // reset to default params when changing primitive type
                    paramValues[attr] = float.Parse(defaultValue, CultureInfo.InvariantCulture);
                }

                if (attr.StartsWith("w"))
                {
                    wMaskLabels.Add(label);
                }
                else
                {
                    paramValues[attr] = EditorGUILayout.FloatField(label, paramValues[attr]);
                }
            }

            if (wMaskLabels.Count > 0)
            {
                paramValues["w"] = (float)EditorGUILayout.MaskField("options", (int)clayObj.attrs.w, wMaskLabels.ToArray());
            }

            if (EditorGUI.EndChangeCheck())
            {
                ClayContainer.inspectorUpdate();

                Undo.RecordObjects(this.targets, "changed clayobject");

                for (int i = 1; i < this.targets.Length; ++i)
                {
                    bool       somethingChanged = false;
                    ClayObject currentClayObj   = (ClayObject)this.targets[i];

                    bool shouldAutoRename = false;

                    if (clayObj.blend != blend)
                    {
                        currentClayObj.blend = blend;
                        somethingChanged     = true;
                        shouldAutoRename     = true;
                    }

                    if (clayObj.color != color)
                    {
                        currentClayObj.color = color;
                        somethingChanged     = true;
                    }

                    if (clayObj.primitiveType != primitiveType)
                    {
                        currentClayObj.primitiveType = primitiveType;
                        somethingChanged             = true;
                        shouldAutoRename             = true;
                    }

                    if (clayObj.attrs.x != paramValues["x"])
                    {
                        currentClayObj.attrs.x = paramValues["x"];
                        somethingChanged       = true;
                    }

                    if (clayObj.attrs.y != paramValues["y"])
                    {
                        currentClayObj.attrs.y = paramValues["y"];
                        somethingChanged       = true;
                    }

                    if (clayObj.attrs.z != paramValues["z"])
                    {
                        currentClayObj.attrs.z = paramValues["z"];
                        somethingChanged       = true;
                    }

                    if (clayObj.attrs.w != paramValues["w"])
                    {
                        currentClayObj.attrs.w = paramValues["w"];
                        somethingChanged       = true;
                        shouldAutoRename       = true;
                    }

                    if (somethingChanged)
                    {
                        currentClayObj.getClayContainer().clayObjectUpdated(currentClayObj);

                        if (shouldAutoRename)
                        {
                            if (currentClayObj.gameObject.name.StartsWith("clay_"))
                            {
                                this.autoRename(currentClayObj, solidsLabels);
                            }
                        }
                    }
                }

                clayObj.blend         = blend;
                clayObj.color         = color;
                clayObj.primitiveType = primitiveType;
                clayObj.attrs.x       = paramValues["x"];
                clayObj.attrs.y       = paramValues["y"];
                clayObj.attrs.z       = paramValues["z"];
                clayObj.attrs.w       = paramValues["w"];

                if (clayObj.gameObject.name.StartsWith("clay_"))
                {
                    this.autoRename(clayObj, solidsLabels);
                }

                clayObj.forceUpdate();

                UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                ClayContainer.getSceneView().Repaint();
            }
        }