Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            Color defaultColor = GUI.backgroundColor;

            ClayContainer clayxel = (ClayContainer)this.target;

            EditorGUILayout.LabelField("Clayxels V1.31");

            EditorGUILayout.Space();

            string userWarn = clayxel._getUserWarning();

            if (userWarn != "")
            {
                GUIStyle s = new GUIStyle();
                s.wordWrap         = true;
                s.normal.textColor = Color.yellow;
                EditorGUILayout.LabelField(userWarn, s);
            }

            if (clayxel.getNumSolids() > clayxel.getMaxSolids())
            {
                GUIStyle s = new GUIStyle();
                s.wordWrap         = true;
                s.normal.textColor = Color.yellow;
                EditorGUILayout.LabelField("Max solid count exeeded, open Global Config to tweak settings.");
            }

            if (clayxel.instanceOf != null)
            {
                ClayContainer newInstance = (ClayContainer)EditorGUILayout.ObjectField(new GUIContent("instance", "Set this to point at another clayContainer in scene to make this into an instance and avoid having to compute the same thing twice."), clayxel.instanceOf, typeof(ClayContainer), true);

                if (newInstance != clayxel.instanceOf && newInstance != clayxel)
                {
                    clayxel.instanceOf = newInstance;
                    clayxel.init();

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

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

                EditorGUILayout.Space();
                if (GUILayout.Button((new GUIContent("global config", ""))))
                {
                    ClayxelsPrefsWindow.Open();
                }

                return;
            }

            if (clayxel.isFrozen())
            {
                if (GUILayout.Button(new GUIContent("defrost clayxels", "Back to live clayxels.")))
                {
                    clayxel.defrostContainersHierarchy();
                    // UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                    // ClayContainer.getSceneView().Repaint();
                }

                EditorGUILayout.Space();
                if (GUILayout.Button((new GUIContent("global config", ""))))
                {
                    ClayxelsPrefsWindow.Open();
                }

                return;
            }

            EditorGUI.BeginChangeCheck();

            int clayxelDetail = EditorGUILayout.IntField(new GUIContent("clayxel detail", "How coarse or finely detailed is your sculpt. Enable Gizmos in your viewport to see the boundaries."), clayxel.getClayxelDetail());

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

                clayxel.setClayxelDetail(clayxelDetail);

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

                return;
            }

            GUILayout.BeginHorizontal();

            GUI.backgroundColor = defaultColor;

            if (!clayxel.isAutoBoundsActive())
            {
                EditorGUI.BeginChangeCheck();
                Vector3Int boundsScale = EditorGUILayout.Vector3IntField(new GUIContent("bounds scale", "How much work area you have for your sculpt within this container. Enable Gizmos in your viewport to see the boundaries."), clayxel.getBoundsScale());

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

                    clayxel.setBoundsScale(boundsScale.x, boundsScale.y, boundsScale.z);

                    clayxel.init();
                    clayxel.needsUpdate = true;
                    // UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                    // ClayContainer.getSceneView().Repaint();

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

                    return;
                }

                if (GUILayout.Button(new GUIContent("-", "")))
                {
                    ClayContainer._inspectorUpdate();

                    Vector3Int bounds = clayxel.getBoundsScale();
                    clayxel.setBoundsScale(bounds.x - 1, bounds.y - 1, bounds.z - 1);

                    clayxel.init();
                    clayxel.needsUpdate = true;
                    // UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                    // ClayContainer.getSceneView().Repaint();

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

                    return;
                }

                if (GUILayout.Button(new GUIContent("+", "")))
                {
                    ClayContainer._inspectorUpdate();

                    Vector3Int bounds = clayxel.getBoundsScale();
                    clayxel.setBoundsScale(bounds.x + 1, bounds.y + 1, bounds.z + 1);

                    clayxel.init();
                    clayxel.needsUpdate = true;
                    // UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                    // ClayContainer.getSceneView().Repaint();

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

                    return;
                }

                if (GUILayout.Button(new GUIContent("auto", "")))
                {
                    clayxel.setAutoBoundsActive(true);

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

                    if (!Application.isPlaying)
                    {
                        EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
                    }
                }
            }
            else
            {
                GUI.backgroundColor = Color.yellow;

                GUILayout.BeginHorizontal();

                EditorGUILayout.LabelField("bounds scale");

                if (GUILayout.Button(new GUIContent("auto", "")))
                {
                    clayxel.setAutoBoundsActive(false);
                }

                GUILayout.EndHorizontal();
            }

            GUI.backgroundColor = defaultColor;

            GUILayout.EndHorizontal();

            EditorGUILayout.Space();

            if (GUILayout.Button(new GUIContent("add clay", "lets get this party started")))
            {
                ClayObject clayObj = ((ClayContainer)this.target).addClayObject();

                Undo.RegisterCreatedObjectUndo(clayObj.gameObject, "added clayxel solid");
                UnityEditor.Selection.objects = new GameObject[] { clayObj.gameObject };

                clayxel.needsUpdate = true;
                // UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
                // ClayContainer.getSceneView().Repaint();

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

                return;
            }

            if (GUILayout.Button(new GUIContent("pick clay (" + ClayContainer.pickingKey + ")", "Press p on your keyboard to mouse pick ClayObjects from the viewport. Pressing Shift will add to a previous selection.")))
            {
                ClayContainer.startScenePicking();
            }

            if (GUILayout.Button((new GUIContent("global config", ""))))
            {
                ClayxelsPrefsWindow.Open();
            }

            clayxel.forceUpdate = EditorGUILayout.Toggle(new GUIContent("animate (forceUpdate)", "Enable if you're animating/moving the container as well as the clayObjects inside it."), clayxel.forceUpdate);

            EditorGUILayout.Space();

            ClayxelInspector.extrasPanel = EditorGUILayout.Foldout(ClayxelInspector.extrasPanel, "extras", true);

            if (ClayxelInspector.extrasPanel)
            {
                ClayContainer instance = (ClayContainer)EditorGUILayout.ObjectField(new GUIContent("instance", "Set this to point at another clayContainer in scene to make this into an instance and avoid having to compute the same thing twice."), clayxel.instanceOf, typeof(ClayContainer), true);
                if (instance != clayxel.instanceOf && instance != clayxel)
                {
                    clayxel.instanceOf = instance;

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

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

                EditorGUILayout.Space();

                if (clayxel.storeAssetPath == "")
                {
                    clayxel.storeAssetPath = clayxel.gameObject.name;
                }
                clayxel.storeAssetPath = EditorGUILayout.TextField(new GUIContent("frozen asset name", "Specify an asset name to store frozen mesh or claymation on disk. Files are saved relative to this project's Assets folder."), clayxel.storeAssetPath);
                string[] paths = clayxel.storeAssetPath.Split('.');
                if (paths.Length > 0)
                {
                    clayxel.storeAssetPath = paths[0];
                }

                EditorGUILayout.Space();

                                #if CLAYXELS_RETOPO
                clayxel.shouldRetopoMesh = EditorGUILayout.Toggle(new GUIContent("retopology", "Use this to generate meshes with a better topology."), clayxel.shouldRetopoMesh);
                if (clayxel.shouldRetopoMesh)
                {
                    clayxel.retopoMaxVerts = EditorGUILayout.IntField(new GUIContent("vertex count", "-1 will let the tool decide on the best number of vertices."), clayxel.retopoMaxVerts);
                }
                                #endif

                if (GUILayout.Button(new GUIContent("freeze mesh", "Switch between live clayxels and a frozen mesh.")))
                {
                    clayxel.freezeContainersHierarchyToMesh();

                                        #if CLAYXELS_RETOPO
                    if (clayxel.shouldRetopoMesh)
                    {
                        int targetVertCount = RetopoUtils.getRetopoTargetVertsCount(clayxel.gameObject, clayxel.retopoMaxVerts);
                        if (targetVertCount == 0)
                        {
                            return;
                        }

                        RetopoUtils.retopoMesh(clayxel.gameObject.GetComponent <MeshFilter>().sharedMesh, targetVertCount, -1);
                    }
                                        #endif

                    clayxel.transferMaterialPropertiesToMesh();

                    if (clayxel.storeAssetPath != "")
                    {
                        clayxel.storeMesh(clayxel.storeAssetPath);
                    }
                }

                EditorGUILayout.Space();

                AnimationClip claymationAnimClip = (AnimationClip)EditorGUILayout.ObjectField(new GUIContent("animClip (optional)", "Freeze an animation to disk using the claymation file format"), clayxel.claymationAnimClip, typeof(AnimationClip), true);
                if (claymationAnimClip != null && claymationAnimClip != clayxel.claymationAnimClip)
                {
                    clayxel.claymationStartFrame = 0;
                    clayxel.claymationEndFrame   = (int)(claymationAnimClip.length * claymationAnimClip.frameRate);
                }
                clayxel.claymationAnimClip = claymationAnimClip;

                if (clayxel.claymationAnimClip != null)
                {
                    clayxel.claymationStartFrame = EditorGUILayout.IntField(new GUIContent("start", ""), clayxel.claymationStartFrame);
                    clayxel.claymationEndFrame   = EditorGUILayout.IntField(new GUIContent("end", ""), clayxel.claymationEndFrame);
                }

                if (GUILayout.Button(new GUIContent("freeze claymation", "Freeze this container to a point-cloud file stored on disk and skip heavy computing.")))
                {
                    clayxel.freezeClaymation();
                }

                EditorGUI.BeginChangeCheck();

                EditorGUILayout.Space();

                bool castShadows = EditorGUILayout.Toggle("cast shadows", clayxel.getCastShadows());

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

                    clayxel.setCastShadows(castShadows);

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

                // end of extras
            }

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Space();

            Material customMaterial = (Material)EditorGUILayout.ObjectField(new GUIContent("customMaterial", "Custom materials need to use shaders specifically made for clayxels. Use the provided shaders and examples as reference. "), clayxel.customMaterial, typeof(Material), false);

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

                Undo.RecordObject(this.target, "changed clayxel container");

                if (customMaterial != clayxel.customMaterial)
                {
                    clayxel.setCustomMaterial(customMaterial);

                    // clayxel.needsUpdate = true;
                    // clayxel.forceUpdateAllSolids();
                }

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

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

            if (!clayxel.isFrozenToMesh())
            {
                this.inspectMaterial(clayxel);
            }
        }