示例#1
0
 void onUndoPerformed()
 {
     if (Undo.GetCurrentGroupName() == "changed clayobject" ||
         Undo.GetCurrentGroupName() == "changed clayxel container")
     {
         this.needsUpdate = true;
     }
     else if (Undo.GetCurrentGroupName() == "changed clayxel grid")
     {
         this.init();
     }
     else if (Undo.GetCurrentGroupName() == "added clayxel solid")
     {
         this.needsUpdate = true;
     }
     else if (Undo.GetCurrentGroupName() == "Selection Change")
     {
         if (UnityEditor.Selection.Contains(this.gameObject))
         {
             this.init();
         }
         else
         {
             if (UnityEditor.Selection.gameObjects.Length > 0)
             {
                 ClayObject clayObj = UnityEditor.Selection.gameObjects[0].GetComponent <ClayObject>();
                 if (clayObj != null)
                 {
                     if (clayObj.getClayxelContainer() == this)
                     {
                         this.needsUpdate = true;
                     }
                 }
             }
         }
     }
 }
示例#2
0
    public override void OnInspectorGUI()
    {
        ClayObject clayObj = (ClayObject)this.targets[0];

        EditorGUI.BeginChangeCheck();

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

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

        Clayxel clayxel       = clayObj.getClayxelContainer();
        int     primitiveType = EditorGUILayout.Popup("solidType", clayObj.primitiveType, clayxel.getSolidsCatalogueLabels());

        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);
            }

            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())
        {
            Undo.RecordObjects(this.targets, "changed clayobject");

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

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

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

                if (clayObj.primitiveType != primitiveType)
                {
                    currentClayObj.primitiveType = primitiveType;
                    somethingChanged             = 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;
                }

                if (somethingChanged)
                {
                    currentClayObj.getClayxelContainer().needsUpdate = true;
                }
            }

            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"];

            clayxel.needsUpdate = true;
            UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
            clayxel.getSceneView().Repaint();
                        #if DEBUG_CLAYXEL_REPAINT_WARN
            Debug.Log("editor update");
                        #endif
        }
    }