static void setupSceneViewer() { if (Application.isPlaying) { return; } SceneView sceneView = (SceneView)SceneView.sceneViews[0]; if (sceneView == null) { Debug.Log("failed to find a valid viewport, press reload again when you have a 3d view visible"); return; } Camera camera = sceneView.camera; // camera.renderingPath = RenderingPath.Forward;//DeferredShading; ClaySceneViewer oldClaySceneView = camera.gameObject.GetComponent <ClaySceneViewer>(); if (oldClaySceneView != null) { SceneView.duringSceneGui -= oldClaySceneView.onSceneGUI; // oldClaySceneView.OnLostFocus -= oldClaySceneView.onLostFocus; ClaySceneViewer.globalInstanceRef = null; DestroyImmediate(oldClaySceneView); } ClaySceneViewer claySceneView = (ClaySceneViewer)camera.gameObject.AddComponent <ClaySceneViewer>(); ClaySceneViewer.globalInstanceRef = new WeakReference(claySceneView); SceneView.duringSceneGui += claySceneView.onSceneGUI; }
public static ClaySceneViewer getGlobalInstance() { if (ClaySceneViewer.globalInstanceRef == null) { ClaySceneViewer globalInst = ((SceneView)SceneView.sceneViews[0]).camera.GetComponent <ClaySceneViewer>(); ClaySceneViewer.globalInstanceRef = new WeakReference(globalInst); } return((ClaySceneViewer)ClaySceneViewer.globalInstanceRef.Target); }
public override void OnInspectorGUI() { Clayxel clayxel = (Clayxel)this.target; EditorGUILayout.LabelField("Clayxels, V0.462 beta"); EditorGUILayout.LabelField("contained clayObjects: " + clayxel.getNumClayObjects()); EditorGUILayout.LabelField("limit is 64 on free version"); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); int chunkSize = EditorGUILayout.IntField("resolution", clayxel.chunkSize); int numChunksX = EditorGUILayout.IntField("containerSizeX", clayxel.numChunksX); int numChunksY = EditorGUILayout.IntField("containerSizeY", clayxel.numChunksY); int numChunksZ = EditorGUILayout.IntField("containerSizeZ", clayxel.numChunksZ); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(this.target, "changed clayxel grid"); clayxel.chunkSize = chunkSize; clayxel.numChunksX = numChunksX; clayxel.numChunksY = numChunksY; clayxel.numChunksZ = numChunksZ; clayxel.init(); clayxel.needsUpdate = true; UnityEditor.EditorApplication.QueuePlayerLoopUpdate(); clayxel.getSceneView().Repaint(); #if DEBUG_CLAYXEL_REPAINT_WARN Debug.Log("ClayxelInspector 1!"); #endif return; } bool showContainer = EditorGUILayout.Toggle("showContainer", clayxel.showContainer); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); float materialSmoothness = EditorGUILayout.FloatField("Smoothness", clayxel.materialSmoothness); float materialMetallic = EditorGUILayout.FloatField("Metallic", clayxel.materialMetallic); Color materialEmission = EditorGUILayout.ColorField("Emission", clayxel.materialEmission); float splatSizeMultiplier = EditorGUILayout.FloatField("clayxelsSize", clayxel.splatSizeMultiplier); float normalOrientedSplat = EditorGUILayout.FloatField("clayxelsNormalOriented", clayxel.normalOrientedSplat); Texture2D splatTexture = (Texture2D)EditorGUILayout.ObjectField("clayxelsTexture", clayxel.splatTexture, typeof(Texture2D), false); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(this.target, "changed clayxel container"); clayxel.showContainer = showContainer; clayxel.materialSmoothness = materialSmoothness; clayxel.materialMetallic = materialMetallic; clayxel.materialEmission = materialEmission; clayxel.splatSizeMultiplier = splatSizeMultiplier; clayxel.normalOrientedSplat = normalOrientedSplat; clayxel.splatTexture = splatTexture; if (clayxel.normalOrientedSplat < 0.0f) { clayxel.normalOrientedSplat = 0.0f; } else if (clayxel.normalOrientedSplat > 1.0f) { clayxel.normalOrientedSplat = 1.0f; } clayxel.updateSplatLook(); clayxel.needsUpdate = true; UnityEditor.EditorApplication.QueuePlayerLoopUpdate(); clayxel.getSceneView().Repaint(); #if DEBUG_CLAYXEL_REPAINT_WARN Debug.Log("ClayxelInspector 2!"); #endif return; } EditorGUILayout.Space(); if (GUILayout.Button("reload all")) { Clayxel.reloadAll(); } if (GUILayout.Button("pick solid (p)")) { ClaySceneViewer.getGlobalInstance().startPicking(); } if (GUILayout.Button("add solid")) { ClayObject clayObj = ((Clayxel)this.target).addSolid(); Undo.RegisterCreatedObjectUndo(clayObj.gameObject, "added clayxel solid"); UnityEditor.Selection.objects = new GameObject[] { clayObj.gameObject }; clayxel.needsUpdate = true; UnityEditor.EditorApplication.QueuePlayerLoopUpdate(); clayxel.getSceneView().Repaint(); return; } if (!clayxel.hasCachedMesh()) { if (GUILayout.Button("freeze to mesh")) { clayxel.generateMesh(); } } else { if (GUILayout.Button("defrost clayxels")) { clayxel.disableMesh(); UnityEditor.EditorApplication.QueuePlayerLoopUpdate(); clayxel.getSceneView().Repaint(); } } }