public static void CreateVTXSphere() { //Create the object GameObject vtxSphere = new GameObject(); //Name the object vtxSphere.name = "VertexInfluenceSphere"; //Add the relevant script vtxSphere.AddComponent <VertexInfluenceSphere>(); VertexInfluenceSphere vInfluenceSphere = vtxSphere.GetComponent <VertexInfluenceSphere>(); vInfluenceSphere.enabled = true; //Place the object properly if (Selection.activeTransform != null) { vtxSphere.transform.position = Selection.activeTransform.position; } else { Camera sceneCamera = SceneView.lastActiveSceneView.camera; Vector3 objectSpawnPoint = sceneCamera.transform.position + (sceneCamera.transform.forward * 6); vtxSphere.transform.position = objectSpawnPoint; } //Select the object GameObject[] newSelection = new GameObject[1]; newSelection[0] = vtxSphere; Selection.objects = newSelection; //Make this creation undoable Undo.RegisterCreatedObjectUndo(vtxSphere, "Created Vertex Influence Sphere"); }
void OnGUI() { //All the buttons and the functions they correspond to... string tooltip = ("Vertex Influence Spheres allow for environment blending."); GUILayout.Label(new GUIContent("Vertex Influence Spheres", tooltip), EditorStyles.boldLabel); GUILayout.BeginHorizontal(); tooltip = "This creates a vertex influence sphere. If you parent this to another object, it will only work on that object's children. This can be used to help performance. Otherwise it will apply to every paintable object in the scene"; if (GUILayout.Button(new GUIContent("Create Sphere", tooltip))) { VertexInfluenceSphere.CreateVTXSphere(); VertexInfluenceManager.SetAutoRefresh(autoRefresh); } tooltip = "This will paint the vertex colors on all the spheres in the scene. This will force a refresh no matter what, including if there are no spheres"; if (GUILayout.Button(new GUIContent("Paint Spheres", tooltip))) { VertexInfluenceManager.RefreshAll(); VertexInfluenceManager.SetAutoRefresh(autoRefresh); } GUILayout.EndHorizontal(); tooltip = "Automatically paints whenever one of the spheres is modified. Note that this doesn't update in all cases, unlike the 'Paint Spheres' button. Also note this can get slow. To optimize, consider parenting influence spheres under groups so they don't have to check every mesh in the scene."; autoRefresh = EditorGUILayout.Toggle(new GUIContent("Auto-Paint", tooltip), autoRefresh); if (autoRefresh != autoRefreshStored) { VertexInfluenceManager.SetAutoRefresh(autoRefresh); } autoRefreshStored = autoRefresh; GUILayout.Label("Material Swap", EditorStyles.boldLabel); string[] matTintTypeStrings = new string[] { "Standard", "Sandstone" }; materialTintType = GUILayout.SelectionGrid(materialTintType, matTintTypeStrings, 2); string[] matBlendTypeStrings = new string[] { "Snow", "Overgrowth", "Sand" }; materialBlendType = GUILayout.SelectionGrid(materialBlendType, matBlendTypeStrings, 3); tooltip = "Changes all relevant materials in the scene to use the materials specified above."; if (GUILayout.Button(new GUIContent("Swap Materials", tooltip))) { MaterialSwapManager.UpdateMaterials(materialTintType, materialBlendType); } tooltip = "Reverts all the materials to the default (standard + snow)"; if (GUILayout.Button(new GUIContent("Revert Materials", tooltip))) { MaterialSwapManager.RevertMaterials(); } tooltip = "Checking this will automatically update new objects to be the material type you specified. Note this could get slow on larger scenes, and if so it is reccoemended you leave this off and manually swap materials from time to time"; autoSwap = EditorGUILayout.Toggle(new GUIContent("Auto-Swap", tooltip), autoSwap); if (autoSwap != autoSwapStored) { MaterialSwapManager.SetAutoRefresh(autoSwap); } autoSwapStored = autoSwap; EditorGUILayout.HelpBox("Note: Every button and attribute has a rollover tooltip", MessageType.Info); }
public override void OnInspectorGUI() { //Overwrite the vanilla inspector VertexInfluenceSphere inspector = (VertexInfluenceSphere)target; //Fixes color enum from reseting if (inspector.color == 0) { colorType = ColorType.Environmental; } else { colorType = ColorType.Wetness; } //Fixes ParentedTp enum from reseting if (inspector.parentedToSet == VertexInfluenceSphere.ParentedTo.World) { parentedTo = ParentedTo.World; } else { parentedTo = ParentedTo.Parent; } //Starts a listener for if anything is changed in the GUI EditorGUI.BeginChangeCheck(); //Any changes that happen to any of these fields is undoable Undo.RecordObject(inspector, "Vertex Influence Sphere modified"); //The new fields that overwrote the old ones colorType = (ColorType)EditorGUILayout.EnumPopup("Type", colorType); inspector.radius = EditorGUILayout.FloatField("Radius", inspector.radius); inspector.maxValue = EditorGUILayout.Slider("Max Value", inspector.maxValue, 0, 1); inspector.curve = EditorGUILayout.CurveField("Falloff Curve", inspector.curve); parentedTo = (ParentedTo)EditorGUILayout.EnumPopup("Parented To", parentedTo); //Help box stuff string sphereCount = inspector.vertexInfluenceManager.vertexInfluenceSpheres.Count.ToString(); string parentString; if (inspector.parentedTo == VertexInfluenceSphere.ParentedTo.World) { parentString = "the world"; } else { parentString = inspector.transform.parent.name; } string meshCount = inspector.vertexInfluenceManager.staticMeshFilters.Count.ToString(); EditorGUILayout.HelpBox("There are currently " + sphereCount + " influence spheres parented to " + parentString + ", which contains " + meshCount + " meshes", MessageType.Info); //If the GUI was changed, do this if (EditorGUI.EndChangeCheck()) { inspector.externalRefresh = true; EditorUtility.SetDirty(inspector); } //Changes elements of the inspector and VIS based on the color type. if (colorType != storedColorType) { int colorIndex = (int)(colorType); inspector.SetNewColor(colorIndex); storedColorType = colorType; } //Changes VTX spheres based on a change in parented to if (parentedTo != parentedToStored) { if (parentedTo == ParentedTo.World) { inspector.parentedToSet = VertexInfluenceSphere.ParentedTo.World; } else { inspector.parentedToSet = VertexInfluenceSphere.ParentedTo.Parent; } parentedToStored = parentedTo; VertexInfluenceManager.ForceUpdate(); } }
public static void CreateVTXSphere() { VertexInfluenceSphere.CreateVTXSphere(); }