void OnEnable() { hideFlags = HideFlags.HideAndDontSave; //subscribe to onSceneGUI SceneView.onSceneGUIDelegate += SceneGUI; //Initialize prefablist if(preFabList.Count == 0) { prefabToAdd tempPTA = new prefabToAdd(); preFabList.Add (tempPTA); } //ensure that number of slots displayed matches list size newNumPrefab = preFabList.Count; }
void OnGUI() { scrollPos = EditorGUILayout.BeginScrollView(scrollPos); EditorGUILayout.Space(); EditorGUILayout.Space(); // Check if list is full // adds to list of prefabs // Will only occur when GUI repaints to avoid errors if(Event.current.type == EventType.Layout) { int lastIndex; lastIndex = preFabList.Count - 1; if(preFabList[lastIndex].prefab != null) { newNumPrefab++; } } //dynamically add to prefab list for(int i = 0; i < newNumPrefab; i++) { prefabToAdd tempPTA = new prefabToAdd(); if(preFabList.Count != newNumPrefab) { if(Event.current.type == EventType.Layout) { preFabList.Add (tempPTA); } } if(preFabList.Count == newNumPrefab) { string fieldLabel; int tempInt = i + 1; fieldLabel = "Prefab # " + tempInt; preFabList[i].prefab = EditorGUILayout.ObjectField(fieldLabel, preFabList[i].prefab, typeof(GameObject),false) as GameObject; EditorGUI.indentLevel++; preFabList[i].weight = EditorGUILayout.Slider("Weight", preFabList[i].weight, 0f,1f); //preFabList[i].connected = EditorGUILayout.ToggleLeft("Connected Prefab", preFabList[i].connected); EditorGUI.indentLevel--; } } EditorGUILayout.Space(); GUILayout.BeginVertical(); EditorGUILayout.LabelField("Weight Settings"); GUILayout.BeginHorizontal(); if(GUILayout.Button("Zero")) { ZeroWeights(); } if(GUILayout.Button("Equal")) { EqualWeghts(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if(GUILayout.Button("Save Custom")) { SaveCustomWeights(); } if(GUILayout.Button("Use Custom")) { UseCustomWeights(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); //Remove extra rows from prefab lists if(Event.current.type == EventType.Repaint) { int lastIndex; lastIndex = preFabList.Count - 1; if(preFabList.Count > 1) { if(preFabList[lastIndex - 1].prefab == null && preFabList[lastIndex].prefab == null) { newNumPrefab--; preFabList.RemoveAt(lastIndex); } } } EditorGUILayout.Space(); autoParent = EditorGUILayout.ToggleLeft("Set Parent to Target", autoParent); EditorGUILayout.Space(); assetParent = EditorGUILayout.ObjectField("Parent (Optional)", assetParent, typeof(GameObject), true); EditorGUILayout.Space(); asPrefab = EditorGUILayout.ToggleLeft("Instantiate as connected Prefab", asPrefab); EditorGUILayout.Space(); EditorGUILayout.LabelField("Randomly Rotate Asset on:"); EditorGUI.indentLevel++; rotateX = EditorGUILayout.BeginToggleGroup("X axis", rotateX); EditorGUI.indentLevel++; rotationX = EditorGUILayout.Slider("Rotation Limit", rotationX,0f,180f); EditorGUI.indentLevel--; EditorGUILayout.EndToggleGroup(); rotateY = EditorGUILayout.BeginToggleGroup("Y axis", rotateY); EditorGUI.indentLevel++; rotationY = EditorGUILayout.Slider("Rotation Limit", rotationY,0f,180f); EditorGUI.indentLevel--; EditorGUILayout.EndToggleGroup(); rotateZ = EditorGUILayout.BeginToggleGroup("Z axis", rotateZ); EditorGUI.indentLevel++; rotationZ = EditorGUILayout.Slider("Rotation Limit", rotationZ,0f,180f); EditorGUI.indentLevel--; EditorGUILayout.EndToggleGroup(); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Align Prefab to Target Normal"); EditorGUI.indentLevel++; alignToNormal = EditorGUILayout.ToggleLeft("Rotate Y-axis to Normal", alignToNormal); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Option to Mass Place Prefabs"); EditorGUI.indentLevel++; //Mass Place UI massPlace = EditorGUILayout.BeginToggleGroup("Mass Place", massPlace); EditorGUI.indentLevel++; //Radius in which to instantiate prefabs radiusToPlace = EditorGUILayout.Slider("Radius To Place In", radiusToPlace,1f,50f); //Adjust max number of placements portional to area int maxToPlace; maxToPlace = Mathf.RoundToInt(radiusToPlace * radiusToPlace) / 2; //Number of prefabs to instantiate numberToPlace = EditorGUILayout.IntSlider("Number To Place", numberToPlace,1,maxToPlace); EditorGUI.indentLevel--; EditorGUILayout.EndToggleGroup(); EditorGUI.indentLevel--; if(!placing) { if(GUILayout.Button("Start Placing")) { placing = true; } } else { if(GUILayout.Button("Stop Placing")) { placing = false; } } EditorGUILayout.Space (); EditorGUILayout.EndScrollView(); }