// editor gui window void OnGUI() { if (instance == null) { instance = (PrefabStamper)GetWindow(typeof(PrefabStamper)); } isEnabled = EditorGUILayout.Toggle("Enabled", isEnabled); EditorGUILayout.LabelField("Current stamp", currentStampName); targetLayer = EditorGUILayout.LayerField("Target layer", targetLayer); alignToNormal = EditorGUILayout.Toggle("Align to Normal", alignToNormal); randomYRot = EditorGUILayout.Toggle("Randomize Y Rotation", randomYRot); sizeVariation = EditorGUILayout.Toggle("Randomize Scale", sizeVariation); GUI.enabled = sizeVariation; Rect r = EditorGUILayout.BeginHorizontal(); GUILayout.Label("Min " + smallest.ToString()); GUILayout.FlexibleSpace(); GUILayout.Label(largest.ToString() + " Max"); EditorGUILayout.EndHorizontal(); EditorGUILayout.MinMaxSlider(ref smallest, ref largest, 0.25f, 2.0f); GUI.enabled = true; if (GUILayout.Button("Done", GUILayout.MinHeight(30))) { instance.Close(); } }
// main loop static void OnScene(SceneView sceneview) { if (isEnabled == false) { return; } if (Event.current.alt) // lat key is down { return; } if (instance == null) { instance = (PrefabStamper)GetWindow(typeof(PrefabStamper)); } if (instance.Stamp == null) { return; } // get raycast hit for preview circle Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << targetLayer)) { Handles.color = Color.blue; // FIXME not accurate radius/area Handles.DrawWireDisc(hit.point, hit.normal, instance.Stamp.bounds.extents.magnitude * 0.5f); //Handles.DrawWireCube(hit.point, instance.Stamp.bounds.size); HandleUtility.Repaint(); } // left mouse button is down if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { PaintStamp(); Event.current.Use(); } if (Event.current.type == EventType.MouseUp) { instance.stampedTransforms.Clear(); } // move stamp with mouse if (instance.stampedTransforms.Count > 0) { UpdateStamper(); } // stops selecting other objects if (Event.current.type == EventType.Layout) { HandleUtility.AddDefaultControl(0); } }
public static void Init() { if (LayerMask.GetMask("Terrain") > 0) { targetLayer = LayerMask.NameToLayer("Terrain"); } // Get existing open window or if none, make a new one: PrefabStamper window = (PrefabStamper)GetWindow(typeof(PrefabStamper)); window.Show(); window.titleContent.text = "PrefabStamper"; window.minSize = new Vector2(248, 188); window.maxSize = new Vector2(250, 190); instance = window; }