public override void OnInspectorGUI() { Undo.RecordObject(target, "Modified Inspector"); Water2D_Tool water2D = (Water2D_Tool)target; // Render the custom inspector fields. CustomInspector(water2D); if (GUI.changed) { EditorUtility.SetDirty(target); water2D.RecreateWaterMesh(); } if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": water2D.RecreateWaterMesh(); break; } } // A button for updating the Transform Position of the water object. if (GUILayout.Button("Center Position")) { water2D.ReCenterPivotPoint(); } }
void OnSceneGUI() { Water2D_Tool water2D_Tool = (Water2D_Tool)target; EditorUtility.SetSelectedWireframeHidden(water2D_Tool.gameObject.GetComponent <Renderer>(), water2D_Tool.showMesh); GUIStyle iconStyle = new GUIStyle(); iconStyle.alignment = TextAnchor.MiddleCenter; // Setup undoing things Undo.RecordObject(target, "Handles Position"); if (Event.current.type == EventType.repaint) { DrawRectangle(water2D_Tool); DrawFlowDirection(water2D_Tool); } // Draw and interact with the handles. if (water2D_Tool.useHandles) { UpdateHandles(water2D_Tool, iconStyle); } if (Event.current.type == EventType.repaint && water2D_Tool.use3DCollider) { DrawOverlapSphereGizmo(water2D_Tool); } // Update everything that relies on the handles, if the GUI changed. if (GUI.changed) { water2D_Tool.RecreateWaterMesh(); EditorUtility.SetDirty(target); prevChanged = true; } else if (Event.current.type == EventType.used) { if (prevChanged == true) { water2D_Tool.RecreateWaterMesh(); } prevChanged = false; } }
void OnEnable() { texDot = GetGizmo("water2D_circle.png"); selectedPoints.Clear(); Water2D_Tool water2D_Tool = (Water2D_Tool)target; if (water2D_Tool.GetComponent <MeshFilter>().sharedMesh == null) { water2D_Tool.RecreateWaterMesh(); } }
private void CreateTopMeshObject(Water2D_Tool water) { if (water.topMeshGameObject == null) { GameObject obj = new GameObject("new Water2D_TM"); obj.AddComponent <MeshRenderer>(); obj.AddComponent <MeshFilter>(); obj.transform.position = water.transform.position; obj.transform.SetParent(water.transform); water.topMeshGameObject = obj; water.RecreateWaterMesh(); } }
static GameObject CreateGPUWater(bool collider2D) { GameObject fmObject = new GameObject("New Water2D_FM"); Water2D_Tool water2DTool = fmObject.AddComponent <Water2D_Tool>(); fmObject.AddComponent <Water2D_Simulation>(); fmObject.AddComponent <Water2D_Ripple>(); water2DTool.Add(new Vector3(0, 3, 0)); water2DTool.Add(new Vector3(0, -3, 0)); water2DTool.Add(new Vector3(-8, 0, 0)); water2DTool.Add(new Vector3(8, 0, 0)); water2DTool.Add(new Vector3(0, 3, 10)); if (!collider2D) { water2DTool.use3DCollider = true; } water2DTool.squareSegments = true; water2DTool.segmentsPerUnit = 4; water2DTool.cubeWater = true; GameObject tmObject = new GameObject("New Water2D_TM"); tmObject.AddComponent <MeshRenderer>(); tmObject.AddComponent <MeshFilter>(); tmObject.AddComponent <Water2D_PlanarReflection>(); tmObject.transform.position = water2DTool.transform.position; tmObject.transform.SetParent(water2DTool.transform); water2DTool.topMeshGameObject = tmObject; water2DTool.SetGPUWaterDefaultMaterial(); water2DTool.RecreateWaterMesh(); fmObject.transform.position = GetSpawnPos(); return(fmObject); }
static GameObject CreateWater2D(bool collider2D) { GameObject obj = new GameObject("New Water2D_FM"); Water2D_Tool water = obj.AddComponent <Water2D_Tool>(); obj.AddComponent <Water2D_Simulation>(); water.Add(new Vector2(0, 3)); water.Add(new Vector2(0, -3)); water.Add(new Vector2(-5, 0)); water.Add(new Vector2(5, 0)); if (!collider2D) { water.use3DCollider = true; } water.SetDefaultMaterial(); water.RecreateWaterMesh(); obj.transform.position = GetSpawnPos(); return(obj); }
void OnSceneGUI() { Water2D_Tool water2D_Tool = (Water2D_Tool)target; if (water2D_Tool.showMesh) { EditorUtility.SetSelectedRenderState(water2D_Tool.gameObject.GetComponent <Renderer>(), EditorSelectedRenderState.Wireframe); if (water2D_Tool.cubeWater) { EditorUtility.SetSelectedRenderState(water2D_Tool.topMeshGameObject.gameObject.GetComponent <Renderer>(), EditorSelectedRenderState.Wireframe); } } else { EditorUtility.SetSelectedRenderState(water2D_Tool.gameObject.GetComponent <Renderer>(), EditorSelectedRenderState.Highlight); if (water2D_Tool.cubeWater) { EditorUtility.SetSelectedRenderState(water2D_Tool.topMeshGameObject.gameObject.GetComponent <Renderer>(), EditorSelectedRenderState.Highlight); } } GUIStyle iconStyle = new GUIStyle(); iconStyle.alignment = TextAnchor.MiddleCenter; // Setup undoing things Undo.RecordObject(target, "Handles Position"); if (Event.current.type == EventType.Repaint) { ResetChildTransform(water2D_Tool); DrawRectangle(water2D_Tool); } // Draw and interact with the handles. if (water2D_Tool.useHandles) { UpdateHandles(water2D_Tool, iconStyle); } if (water2D_Tool.use3DCollider && !water2D_Tool.GetComponent <Water2D_Ripple>() && Event.current.type == EventType.Repaint) { DrawOverlapSphereGizmo(water2D_Tool); } // Update everything that relies on the handles, if the GUI changed. if (GUI.changed) { water2D_Tool.RecreateWaterMesh(); EditorUtility.SetDirty(target); prevChanged = true; } else if (Event.current.type == EventType.Used) { if (prevChanged == true) { water2D_Tool.RecreateWaterMesh(); } prevChanged = false; } }
private void CustomInspector(Water2D_Simulation water2D_Sim) { showSpringProperties = EditorGUILayout.Foldout(showSpringProperties, "Spring"); if (showSpringProperties) { EditorGUI.indentLevel = 1; InspectorBox(10, () => { water2D_Sim.springSimulation = EditorGUILayout.Toggle(new GUIContent("Spring Simulation", "Enables the simulation of springs. This what makes the surface of the water react to objects."), water2D_Sim.springSimulation); if (water2D_Sim.springSimulation) { water2D_Sim.springConstant = EditorGUILayout.FloatField(new GUIContent("Spring Constant", "This value controls the stiffness of the springs. " + "A low spring constant will make the springs loose. This means a force will cause large waves that oscillate slowly. A high spring " + "constant will increase the tension in the spring. Forces will create small waves that oscillate quickly."), water2D_Sim.springConstant); water2D_Sim.damping = EditorGUILayout.FloatField(new GUIContent("Damping", "The damping slows down the oscillation of the springs. " + " A high dampening value will make the water look thick like molasses, while a low value will allow the waves to oscillate for a long time."), water2D_Sim.damping); water2D_Sim.spread = EditorGUILayout.FloatField(new GUIContent("Spread", "Controls how fast the waves spread."), water2D_Sim.spread); water2D_Sim.collisionVelocity = EditorGUILayout.FloatField(new GUIContent("Collision Velocity", "Limits the velocity " + " a spring will receive from a falling object."), water2D_Sim.collisionVelocity); water2D_Sim.waveSpeed = EditorGUILayout.FloatField(new GUIContent("Wave Speed", "Another variable to control the spread speed of the waves."), water2D_Sim.waveSpeed); Water2D_Tool water2D_Tool = water2D_Sim.GetComponent <Water2D_Tool>(); if (water2D_Tool.use3DCollider) { water2D_Sim.overlapSphereRadius = EditorGUILayout.FloatField(new GUIContent("Overlap Sphere Radius", "The radius of a sphere that will be used to check " + " if there is a 3D collider near a surface vertex."), water2D_Sim.overlapSphereRadius); } } }); EditorGUI.indentLevel = 0; } if (water2D_Sim.waterType == Water2D_Type.Dynamic) { showfloatingBuoyantForce = EditorGUILayout.Foldout(showfloatingBuoyantForce, "Buoyancy"); if (showfloatingBuoyantForce) { EditorGUI.indentLevel = 1; InspectorBox(10, () => { water2D_Sim.buoyantForceMode = (Water2D_BuoyantForceMode)EditorGUILayout.EnumPopup(new GUIContent("Buoyant Force", "List of methods to simulate the buoyant force. " + "This is what makes the objects float in the water"), water2D_Sim.buoyantForceMode); if (water2D_Sim.buoyantForceMode != Water2D_BuoyantForceMode.None) { if (water2D_Sim.buoyantForceMode == Water2D_BuoyantForceMode.Linear) { water2D_Sim.floatHeight = EditorGUILayout.FloatField(new GUIContent("Float Height", "Determines how much force should be applied to an object submerged " + "in the water. A value of 3 means that 3 m under the water the force applied to an object will be 2 times greater than the force applied at the " + "surface of the water."), water2D_Sim.floatHeight); water2D_Sim.bounceDamping = EditorGUILayout.FloatField(new GUIContent("Bounce Damping", "Slows down the vertical oscillation of the object."), water2D_Sim.bounceDamping); water2D_Sim.liniarBFDragCoefficient = EditorGUILayout.FloatField(new GUIContent("Drag Coefficient", "Determines how much drag force should be applied to an object."), water2D_Sim.liniarBFDragCoefficient); water2D_Sim.liniarBFAbgularDragCoefficient = EditorGUILayout.FloatField(new GUIContent("Angular Drag Coefficient", "Slow down the angular rotation of the object."), water2D_Sim.liniarBFAbgularDragCoefficient); water2D_Sim.forceScale = EditorGUILayout.FloatField(new GUIContent("Force Scale", "A value of 1 will make an object with the mass of " + " 1kg float at the surface of the water and an object with the mass of 2kg float 3m below the water surface if Float Height " + "is set to 3m."), water2D_Sim.forceScale); water2D_Sim.forcePositionOffset = EditorGUILayout.Vector3Field(new GUIContent("Force Position Offset", "By default the force will " + " be applied at the center of the object. Use this to offset the position where the force will be applied to an object."), water2D_Sim.forcePositionOffset); } else { water2D_Sim.clippingMethod = (Water2D_ClippingMethod)EditorGUILayout.EnumPopup(new GUIContent("Polygon Clipping", "Determines which clipping method will be used to calculate the shape of the polygon that is below the water. " + "The simple clipping is the cheapest option in terms of performance because the clipping polygon is always a horizontal line." + "The complex option is best to use when you want the objects to better react to water waves."), water2D_Sim.clippingMethod); if (water2D_Sim.clippingMethod == Water2D_ClippingMethod.Complex) { water2D_Sim.showClippingPlolygon = EditorGUILayout.Toggle(new GUIContent("Show Clipping Polygon", "When enabled will show in the Scene View the shape of the clipping polygon."), water2D_Sim.showClippingPlolygon); water2D_Sim.meshSegmentsPerWaterLineSegment = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Water Line Segments", "The number of vertical mesh segments that should fit in a water line segment."), water2D_Sim.meshSegmentsPerWaterLineSegment), 1, 1000); } water2D_Sim.polygonCorners = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Polygon Vertices", "When an object with a circleCollider2D " + "is detected an imaginary regular polygon collider is created based on its radius and position. " + "Use this to set the number of vertices the regular polygon collider should have."), water2D_Sim.polygonCorners), 3, 100); water2D_Sim.maxDrag = EditorGUILayout.FloatField(new GUIContent("Max Drag", "The max drag force that should be applied to an object."), water2D_Sim.maxDrag); water2D_Sim.dragCoefficient = EditorGUILayout.FloatField(new GUIContent("Drag Coefficient", "Determines how much drag force should be applied to an object."), water2D_Sim.dragCoefficient); water2D_Sim.maxLift = EditorGUILayout.FloatField(new GUIContent("Max Lift", "The max lift force that should be applied to an object."), water2D_Sim.maxLift); water2D_Sim.liftCoefficient = EditorGUILayout.FloatField(new GUIContent("Lift Coefficient", "Determines how much lift force should be applied to an object."), water2D_Sim.liftCoefficient); water2D_Sim.waterDensity = EditorGUILayout.FloatField(new GUIContent("Water Density", "Sets the water density. In a water with low " + " density the objects will submerge faster and come to the surface slower. If the water density is great the objects will " + "stay more at the surface of the water and will submerge slower."), water2D_Sim.waterDensity); water2D_Sim.showPolygon = EditorGUILayout.Toggle(new GUIContent("Show Polygon Shape", "When enabled will show in the Scene View the shape of the polygon that is below the waterline."), water2D_Sim.showPolygon); water2D_Sim.showForces = EditorGUILayout.Toggle(new GUIContent("Show Forces", "When enabled will show in the Scene View the velocity direction, drag direction, " + "lift direction and the normal of a leading edge."), water2D_Sim.showForces); } } }); EditorGUI.indentLevel = 0; showFlow = EditorGUILayout.Foldout(showFlow, "Flow"); if (showFlow) { EditorGUI.indentLevel = 1; InspectorBox(10, () => { water2D_Sim.waterFlow = EditorGUILayout.Toggle(new GUIContent("Water Flow", "When enabled, the water flow will affect the objects in the water."), water2D_Sim.waterFlow); if (water2D_Sim.waterFlow) { water2D_Sim.useAngles = EditorGUILayout.Toggle(new GUIContent("Use Angles", "Enable this if you want to control the direction of the water flow using custom angle values."), water2D_Sim.useAngles); if (!water2D_Sim.useAngles) { water2D_Sim.flowDirection = (Water2D_FlowDirection)EditorGUILayout.EnumPopup(new GUIContent("Flow Direction", "The direction of the water flow."), water2D_Sim.flowDirection); } if (water2D_Sim.useAngles) { water2D_Sim.flowAngle = EditorGUILayout.FloatField(new GUIContent("Flow Angle", "The angle of the water flow. " + "When set to 0 degrees the objects will be pushed to the left, " + "when set to 90 degrees the objects will be pushed down, when set to 180 degrees the objects will " + "be pushed to the right, when set to 270 degrees the objects will be pushed up."), water2D_Sim.flowAngle); } water2D_Sim.waterFlowForce = EditorGUILayout.FloatField(new GUIContent("Flow Force", "The force of the water flow."), water2D_Sim.waterFlowForce); } }); } } EditorGUI.indentLevel = 0; } showAnimation = EditorGUILayout.Foldout(showAnimation, "Animation"); if (showAnimation) { EditorGUI.indentLevel = 1; InspectorBox(10, () => { water2D_Sim.animationMethod = (Water2D_AnimationMethod)EditorGUILayout.EnumPopup(new GUIContent("Animation Method", "Determines the animation method for the handles position."), water2D_Sim.animationMethod); if (water2D_Sim.animationMethod != Water2D_AnimationMethod.None) { water2D_Sim.animateWaterArea = EditorGUILayout.Toggle(new GUIContent("Animate Water Area", "Enable this " + "if you want to animate the increase or decrease of the total water area."), water2D_Sim.animateWaterArea); if (!water2D_Sim.animateWaterArea) { water2D_Sim.topEdge = EditorGUILayout.ObjectField(new GUIContent("Top Edge", "Place here an animated object " + "you want the water line (the top of the water) to follow."), water2D_Sim.topEdge, typeof(Transform), true) as Transform; } water2D_Sim.bottomEdge = EditorGUILayout.ObjectField(new GUIContent("Bottom Edge", "Place here an animated object " + "you want the bottom edge of the water to follow."), water2D_Sim.bottomEdge, typeof(Transform), true) as Transform; water2D_Sim.leftEdge = EditorGUILayout.ObjectField(new GUIContent("Left Edge", "Place here an animated object you " + " want the left edge of the water to follow."), water2D_Sim.leftEdge, typeof(Transform), true) as Transform; water2D_Sim.rightEdge = EditorGUILayout.ObjectField(new GUIContent("Right Edge", "Place here an animated object " + "you want the right edge of the water to follow."), water2D_Sim.rightEdge, typeof(Transform), true) as Transform; if (water2D_Sim.animationMethod == Water2D_AnimationMethod.Snap) { if (!water2D_Sim.animateWaterArea) { water2D_Sim.topEdgeYOffset = EditorGUILayout.FloatField(new GUIContent("Top Edge Y Offset", "The offset on the Y axis from the position of a referenced object."), water2D_Sim.topEdgeYOffset); } water2D_Sim.bottomEdgeYOffset = EditorGUILayout.FloatField(new GUIContent("Bottom Edge Y Offset", "The offset on the Y axis from the position of a referenced object."), water2D_Sim.bottomEdgeYOffset); water2D_Sim.leftEdgeXOffset = EditorGUILayout.FloatField(new GUIContent("Left Edge X Offset", "The offset on the X axis from the position of a referenced object."), water2D_Sim.leftEdgeXOffset); water2D_Sim.rightEdgeXOffset = EditorGUILayout.FloatField(new GUIContent("Right Edge X Offset", "The offset on the X axis from the position of a referenced object."), water2D_Sim.rightEdgeXOffset); } if (water2D_Sim.animateWaterArea && water2D_Sim.topEdge != null) { water2D_Sim.topEdge = null; } } }); } EditorGUI.indentLevel = 0; showSurfaceWaves = EditorGUILayout.Foldout(showSurfaceWaves, "Surface Waves"); if (showSurfaceWaves) { EditorGUI.indentLevel = 1; InspectorBox(10, () => { water2D_Sim.surfaceWaves = (Water2D_SurfaceWaves)EditorGUILayout.EnumPopup(new GUIContent("Surface Waves", "List of methods to generate surface waves. Random" + " method generates small random splashes. Sine wave method overlaps a number of sine waves to get a final wave that changes the velocity of the surface vertices."), water2D_Sim.surfaceWaves); if (water2D_Sim.surfaceWaves != Water2D_SurfaceWaves.None) { if (water2D_Sim.surfaceWaves == Water2D_SurfaceWaves.SineWaves) { water2D_Sim.sineWavesType = (Water2D_SineWaves)EditorGUILayout.EnumPopup(new GUIContent("Sine Waves", "The type of sine waves to use. If you want to animate the amplitude and stretch of the sine wave use the Single Sine Wave option."), water2D_Sim.sineWavesType); if (water2D_Sim.springSimulation) { water2D_Sim.useControlPoints = EditorGUILayout.Toggle(new GUIContent("Control Points", "When enabled only the velocity of the control point will be affected by the sine wave."), water2D_Sim.useControlPoints); } if (water2D_Sim.useControlPoints && water2D_Sim.springSimulation) { water2D_Sim.controlPointPos = (Water2D_ControlPointPosition)EditorGUILayout.EnumPopup(new GUIContent("Control Point Position", "Sets the position of the control point. " + "The vertex whose velocity will be controlled by the animator or a script."), water2D_Sim.controlPointPos); } if (water2D_Sim.sineWavesType == Water2D_SineWaves.MultipleSineWaves) { water2D_Sim.randomValues = EditorGUILayout.Toggle(new GUIContent("Random Values", "When enabled, the amplitude, stretch and phase offset will be random values for each sine wave."), water2D_Sim.randomValues); } if (water2D_Sim.sineWavesType == Water2D_SineWaves.MultipleSineWaves) { water2D_Sim.sineWaves = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Sine Waves Number", "The number of individual sine waves."), water2D_Sim.sineWaves), 1, 100); if (water2D_Sim.randomValues) { water2D_Sim.maxAmplitude = EditorGUILayout.FloatField(new GUIContent("Max Amplitude", "The constant is used to generate a random amplitude value between a Max and a Min. Controls the height of the sine wave."), water2D_Sim.maxAmplitude); water2D_Sim.minAmplitude = EditorGUILayout.FloatField(new GUIContent("Min Amplitude", "The constant is used to generate a random amplitude value between a Max and a Min. Controls the height of the sine wave."), water2D_Sim.minAmplitude); water2D_Sim.maxStretch = EditorGUILayout.FloatField(new GUIContent("Max Stretch", "The constant is used to generate a random sine wave stretch value between a Max and a Min. " + "The bigger the value of the stretch the more compact the waves are."), water2D_Sim.maxStretch); water2D_Sim.minStretch = EditorGUILayout.FloatField(new GUIContent("Min Stretch", "The constant is used to generate a random sine wave stretch value between a Max and a Min. " + "The bigger the value of the stretch the more compact the waves are."), water2D_Sim.minStretch); water2D_Sim.maxPhaseOffset = EditorGUILayout.FloatField(new GUIContent("Max Phase Offset", "The constant is used to generate a random phase offset value between a Max and a Min. " + "The bigger the value of the phase offset the faster the waves move to the left (right)."), water2D_Sim.maxPhaseOffset); water2D_Sim.minPhaseOffset = EditorGUILayout.FloatField(new GUIContent("Min Phase Offset", "The constant is used to generate a random phase offset value between a Max and a Min. " + "The bigger the value of the phase offset the faster the waves move to the left (right)."), water2D_Sim.minPhaseOffset); } else { if (water2D_Sim.sineAmplitudes.Count != water2D_Sim.sineWaves) { water2D_Sim.sineAmplitudes.Clear(); water2D_Sim.sineStretches.Clear(); water2D_Sim.phaseOffset.Clear(); for (int i = 0; i < water2D_Sim.sineWaves; i++) { water2D_Sim.sineAmplitudes.Add(Random.Range(water2D_Sim.minAmplitude, water2D_Sim.maxAmplitude)); water2D_Sim.sineStretches.Add(Random.Range(water2D_Sim.minStretch, water2D_Sim.maxStretch)); water2D_Sim.phaseOffset.Add(Random.Range(water2D_Sim.minPhaseOffset, water2D_Sim.maxPhaseOffset)); } } else { int n = 0; for (int i = 0; i < water2D_Sim.sineWaves; i++) { n = i + 1; EditorGUILayout.Foldout(true, "Sine Wave " + n); water2D_Sim.sineAmplitudes[i] = EditorGUILayout.FloatField(new GUIContent("Amplitude", "The amplitude of the wave. This value controls the height of the sine wave."), water2D_Sim.sineAmplitudes[i]); water2D_Sim.sineStretches[i] = EditorGUILayout.FloatField(new GUIContent("Stretch", "The bigger the value of the stretch the more compact the waves are."), water2D_Sim.sineStretches[i]); water2D_Sim.phaseOffset[i] = EditorGUILayout.FloatField(new GUIContent("Phase Offset", "The bigger the value of the phase offset the faster the waves move to the left (right). " + " A negative value will make the sine wave move to the right."), water2D_Sim.phaseOffset[i]); } } } } else { water2D_Sim.waveAmplitude = EditorGUILayout.FloatField(new GUIContent("Wave Amplitude", "The amplitude of the wave. This value controls the height of the sine wave."), water2D_Sim.waveAmplitude); water2D_Sim.waveStretch = EditorGUILayout.FloatField(new GUIContent("Wave Stretch", "The bigger the value of the stretch the more compact the waves are."), water2D_Sim.waveStretch); water2D_Sim.wavePhaseOffset = EditorGUILayout.FloatField(new GUIContent("Wave Phase Offset", "The bigger the value of the phase offset the faster the waves move to the left (right)." + " A negative value will make the sine wave move to the right."), water2D_Sim.wavePhaseOffset); } water2D_Sim.sineWaveVelocityScale = EditorGUILayout.FloatField(new GUIContent("Sine Wave Velocity Scale", "Will scale down (up) the velocity that is applied to a vertex from a sine wave."), water2D_Sim.sineWaveVelocityScale); } if (water2D_Sim.surfaceWaves == Water2D_SurfaceWaves.RandomSplashes) { water2D_Sim.timeStep = EditorGUILayout.FloatField(new GUIContent("Wave Time Step", "The time between splashes."), water2D_Sim.timeStep); water2D_Sim.maxVelocity = EditorGUILayout.FloatField(new GUIContent("Max Velocity", "The constant is used to generate a random velocity between a Max and a Min."), water2D_Sim.maxVelocity); water2D_Sim.minVelocity = EditorGUILayout.FloatField(new GUIContent("Min Velocity", "The constant is used to generate a random velocity between a Max and a Min."), water2D_Sim.minVelocity); water2D_Sim.neighborVertVelocityScale = EditorGUILayout.FloatField(new GUIContent("Neighbor Vertex Velocity Scale", "Will scale down (up) the velocity that " + "is applied to the neighbor vertices when RandomWave method is called."), water2D_Sim.neighborVertVelocityScale); } if (water2D_Sim.surfaceWaves == Water2D_SurfaceWaves.ControlPoint && water2D_Sim.springSimulation) { water2D_Sim.controlPointPos = (Water2D_ControlPointPosition)EditorGUILayout.EnumPopup(new GUIContent("Control Point Position", "Sets the position of the control point. " + "The vertex whose velocity will be controlled by the animator or a script."), water2D_Sim.controlPointPos); } if (water2D_Sim.surfaceWaves == Water2D_SurfaceWaves.ControlPoint && !water2D_Sim.springSimulation) { EditorGUILayout.HelpBox("The waves will not be generated if the spring simulation is disabled!", MessageType.Warning); } } }); EditorGUI.indentLevel = 0; } EditorGUI.indentLevel = 0; showMiscellaneous = EditorGUILayout.Foldout(showMiscellaneous, "Miscellaneous"); if (showMiscellaneous) { EditorGUI.indentLevel = 1; InspectorBox(10, () => { water2D_Sim.waterType = (Water2D_Type)EditorGUILayout.EnumPopup(new GUIContent("Water Type", "A list of water types. " + "A dynamic water can be animated and reacts to objects. A decorative water can be animated, but will not react " + " to objects and will not influence their position."), water2D_Sim.waterType); if (water2D_Sim.waterType == Water2D_Type.Decorative) { Water2D_Tool water2D_Tool = water2D_Sim.GetComponent <Water2D_Tool>(); if (water2D_Tool.createCollider) { water2D_Tool.createCollider = false; water2D_Tool.RecreateWaterMesh(); } } else { Water2D_Tool water2D_Tool = water2D_Sim.GetComponent <Water2D_Tool>(); if (!water2D_Tool.createCollider) { water2D_Tool.createCollider = true; water2D_Tool.RecreateWaterMesh(); } } if (water2D_Sim.waterType == Water2D_Type.Dynamic) { water2D_Sim.velocityFilter = EditorGUILayout.FloatField(new GUIContent("Velocity Filter", "An object with a velocity on the Y axis " + " greater than the value of Velocity Filter will not create splashes."), water2D_Sim.velocityFilter); water2D_Sim.interactionRegion = EditorGUILayout.FloatField(new GUIContent("Interaction Region", "The bottom region of a colliders bounding box " + "that can affect the velocity of a vertex. This value is used to limit the ability of the objects with big bounding boxes to affect the " + "velocity of the surface vertices. A value of 1 means that only the first 1m of the bottom of the bounding box will affect the velocity " + "of the surface vertices. "), water2D_Sim.interactionRegion); water2D_Sim.playerBoundingBoxSize = EditorGUILayout.Vector2Field(new GUIContent("Player BBox Size", "The size for the players bounding box. In most cases the player character will have more than one collider. " + "So to simplify the things, Water2D uses this variable to set the size for an imaginary bounding box that will be used when applying buoyant force. "), water2D_Sim.playerBoundingBoxSize); water2D_Sim.playerBoundingBoxCenter = EditorGUILayout.Vector2Field(new GUIContent("Player BBox Center", "By default the center of the bounding box will be " + "the transform.position of the object. Use this variable to offset the players bounding box center."), water2D_Sim.playerBoundingBoxCenter); water2D_Sim.playerBuoyantForceScale = EditorGUILayout.FloatField(new GUIContent("Player Buoyant Force Scale", "Depending on what character controller you are using, you may have a big character " + "that must have a small mass. As a result the Player will not submerge in the water because of its low mass that results in low density. To resolve this problem use this variable to scale " + "down the buoyant force applied to the Player."), water2D_Sim.playerBuoyantForceScale); water2D_Sim.waterDisplacement = EditorGUILayout.Toggle(new GUIContent("Water Displacement", "Floating objects will influence the final water area."), water2D_Sim.waterDisplacement); } water2D_Sim.constantWaterArea = EditorGUILayout.Toggle(new GUIContent("Constant Water Area", "If the width of the water changes, the height will " + " change too, to keep a constant water Area."), water2D_Sim.constantWaterArea); if (water2D_Sim.waterType == Water2D_Type.Dynamic) { water2D_Sim.particleSystemInstantiation = (Water2D_ParticleSystem)EditorGUILayout.EnumPopup(new GUIContent("PS Instantiation", "Controls how the particle systems are instantiated. " + "When Per Object option is selected, a single particle system will be instantiated per object. When Per Vertex option is selected, a particle system object will " + "be instantiated for every vertex that is overlapping the interaction region of the object in the water."), water2D_Sim.particleSystemInstantiation); water2D_Sim.particleS = EditorGUILayout.ObjectField(new GUIContent("PS Prefab", "A particle system prefab used to simulate the water splash effect."), water2D_Sim.particleS, typeof(GameObject), true) as GameObject; water2D_Sim.particleSystemPosOffset = EditorGUILayout.Vector3Field(new GUIContent("PS Position Offset", "Offsets the position where the particle systems are created on the Z axis."), water2D_Sim.particleSystemPosOffset); water2D_Sim.particleSystemSorting = EditorGUILayout.Toggle(new GUIContent("PS Sorting", "Enable this toggle if you want to set the sorting layer and order in layer of the particle system when it is instantiated."), water2D_Sim.particleSystemSorting); if (water2D_Sim.particleSystemSorting) { water2D_Sim.particleSystemSortingLayerName = EditorGUILayout.TextField(new GUIContent("PS Sorting Layer Name", "Insert here the sorting layer name for the particle system."), water2D_Sim.particleSystemSortingLayerName); water2D_Sim.particleSystemOrderInLayer = EditorGUILayout.IntField(new GUIContent("PS Order In Layer", "Insert here the order in layer for the particle system."), water2D_Sim.particleSystemOrderInLayer); } water2D_Sim.splashSound = EditorGUILayout.ObjectField(new GUIContent("Sound Effect", "A sound effect generated when an object hits the water surface."), water2D_Sim.splashSound, typeof(AudioClip), true) as AudioClip; } }); } EditorGUI.indentLevel = 0; }
private void CustomInspector(Water2D_Ripple water2D_Ripple) { Water2D_Tool water2D = water2D_Ripple.GetComponent <Water2D_Tool>(); Water2D_Simulation water2DSim = water2D_Ripple.GetComponent <Water2D_Simulation>(); BoldFontStyle(() => { water2D_Ripple.showWaterRipple = EditorGUILayout.Foldout(water2D_Ripple.showWaterRipple, "Water Properties"); }); if (water2D_Ripple.showWaterRipple) { InspectorBox(10, () => { EditorGUI.BeginChangeCheck(); water2D_Ripple.rippleSimulationUpdate = (Water2D_RippleSimulationUpdate)EditorGUILayout.EnumPopup(new GUIContent("Run Simulation In"), water2D_Ripple.rippleSimulationUpdate); if (water2D_Ripple.rippleSimulationUpdate == Water2D_RippleSimulationUpdate.FixedUpdateMethod) { EditorGUILayout.HelpBox("For smooth looking wave movement it is recommended to use Fixed Update Method with physics based character controllers.", MessageType.Info); } if (water2D_Ripple.rippleSimulationUpdate == Water2D_RippleSimulationUpdate.UpdateMethod) { EditorGUILayout.HelpBox("For smooth looking wave movement it is recommended to use Update Method with raycast based character controllers.", MessageType.Info); } if (EditorGUI.EndChangeCheck() && Application.isPlaying) { water2D_Ripple.rainTimeCounter = 0; water2D_Ripple.heightMapTimeCounter = 0; } if (water2D_Ripple.rippleSimulationUpdate == Water2D_RippleSimulationUpdate.UpdateMethod) { EditorGUI.BeginChangeCheck(); water2D_Ripple.rippleWaterFPSCap = EditorGUILayout.Slider(new GUIContent("Simulation Speed", "Determines how many times per second should the height map be processed through the shader that simulates ripple propagation."), water2D_Ripple.rippleWaterFPSCap, 1, 120); if (EditorGUI.EndChangeCheck()) { water2D_Ripple.heightUpdateMapTimeStep = 1f / water2D_Ripple.rippleWaterFPSCap; water2D_Ripple.heightMapTimeCounter = 0; water2D_Ripple.interactionsTimeCounter = 0; } } EditorGUI.BeginChangeCheck(); water2D_Ripple.waterDamping = EditorGUILayout.Slider(new GUIContent("Damping", "Damping parameter for the water propagation simulation."), water2D_Ripple.waterDamping, 0, 1); if (EditorGUI.EndChangeCheck() && Application.isPlaying) { water2D_Ripple.UpdateRippleShaderParameters(); } EditorGUI.BeginChangeCheck(); water2D_Ripple.rtPixelsToUnits = EditorGUILayout.IntField(new GUIContent("RT Pixels To Units", "The number of Render Texture pixels that should fit in 1 unit of Unity space."), water2D_Ripple.rtPixelsToUnits); if (EditorGUI.EndChangeCheck()) { water2D.RecreateWaterMesh(); } water2D_Ripple.bicubicResampling = EditorGUILayout.Toggle(new GUIContent("Bicubic Resampling", "Applies a smoothing effect to the heightmap." + " Eliminates pixelation artifacts. This makes the generated normal map look smoother."), water2D_Ripple.bicubicResampling); EditorGUI.BeginChangeCheck(); water2D_Ripple.drawBothSides = EditorGUILayout.Toggle(new GUIContent("Draw Both Sides", "Enabling this will make both sides of the top mesh to be drawn when the camera is below the water line."), water2D_Ripple.drawBothSides); if (EditorGUI.EndChangeCheck() && Application.isPlaying) { water2D_Ripple.SetTopMeshCulling(); } EditorGUI.BeginChangeCheck(); water2D_Ripple.waveHeightScale = EditorGUILayout.FloatField(new GUIContent("Wave Height Scale", "The scale of the ripples created by objects or rain."), water2D_Ripple.waveHeightScale); if (EditorGUI.EndChangeCheck()) { if (Application.isPlaying) { water2D_Ripple.SetWaveHeightScale(); } else { water2D.GetComponent <Renderer>().sharedMaterial.SetFloat("_WaveHeightScale", water2D_Ripple.waveHeightScale); water2D.topMeshGameObject.GetComponent <Renderer>().sharedMaterial.SetFloat("_WaveHeightScale", water2D_Ripple.waveHeightScale); } } EditorGUI.BeginChangeCheck(); water2D_Ripple.obstructionType = (Water2D_ObstructionType)EditorGUILayout.EnumPopup(new GUIContent("Obstruction Type", "List of obstruction methods."), water2D_Ripple.obstructionType); if (EditorGUI.EndChangeCheck() && Application.isPlaying) { water2D_Ripple.UpdateRippleShaderParameters(); } if (water2D_Ripple.obstructionType == Water2D_ObstructionType.DynamicObstruction && !water2D.use3DCollider) { EditorGUILayout.HelpBox("Dynamic Obstruction only works with objects that have a Box Collider or a Sphere Collider", MessageType.Warning); } if (water2D_Ripple.obstructionType == Water2D_ObstructionType.DynamicObstruction) { water2D_Ripple.obstructionLayers = (LayerMask)EditorGUILayout.MaskField("Obstruction Layers", water2D_Ripple.obstructionLayers, InternalEditorUtility.layers); } if (water2D_Ripple.obstructionType == Water2D_ObstructionType.TextureObstruction) { water2D_Ripple.obstructionTexture = EditorGUILayout.ObjectField(new GUIContent("Obstruction Texture"), water2D_Ripple.obstructionTexture, typeof(Texture2D), true) as Texture2D; } }); } BoldFontStyle(() => { water2D_Ripple.showDynamicObjects = EditorGUILayout.Foldout(water2D_Ripple.showDynamicObjects, "Dynamic Objects"); }); if (water2D_Ripple.showDynamicObjects) { InspectorBox(10, () => { if (water2D.use3DCollider) { water2D_Ripple.fixedRadius = EditorGUILayout.Toggle(new GUIContent("Fixed Radius", "When enabled, the radius of the ripple created by dynamic objects will be the same for all objects. " + "When disabled the radius of the ripple depends on the collider of that object."), water2D_Ripple.fixedRadius); } if (!water2D.use3DCollider && !water2D_Ripple.fixedRadius) { water2D_Ripple.fixedRadius = true; } if (water2D_Ripple.fixedRadius) { water2D_Ripple.objectRippleRadius = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Radius", "The radius of the ripple created by a dynamic object."), water2D_Ripple.objectRippleRadius), 0.000001f, 100f); } if (!water2D_Ripple.fixedRadius) { water2D_Ripple.objectRadiusScale = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Radius Scale", "Scales up or down the ripple radius. " + "The radius of the ripple created by dynamic objects depends on the size of that objects collider."), water2D_Ripple.objectRadiusScale), 0.000001f, 1000f); } water2D_Ripple.objectRippleStrength = EditorGUILayout.FloatField(new GUIContent("Strength", "The strength of the ripple created by dynamic objects."), water2D_Ripple.objectRippleStrength); water2D_Ripple.strengthScale = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Y Axis Strength Scale", "Used to scale up or down the strength of the ripples " + "created by dynamic objects when the Abs value of the velocity on the Y axis is greater than the Abs value of the velocity on the X axis."), water2D_Ripple.strengthScale), 0.000001f, 1000f); water2D_Ripple.objectVelocityFilter = EditorGUILayout.FloatField(new GUIContent("Velocity Filter", "If the Abs value of a dynamic object velocity on the X and Y axis is smaller than the value of this field, no ripples will be generated by that object."), water2D_Ripple.objectVelocityFilter); water2D_Ripple.objectXAxisRippleOffset = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("X Axis Relative Offset", "Offsets the ripple position on the X axis based on the width of the colliders bounding box. A value of 0 means that the ripple will be generated at the center of the collider. " + " A value of 0.5f means that the ripple will be positioned at the left or right edge of the colliders bounding box."), water2D_Ripple.objectXAxisRippleOffset), 0, 100f); }); } EditorGUI.indentLevel = 0; BoldFontStyle(() => { water2D_Ripple.showPlayer = EditorGUILayout.Foldout(water2D_Ripple.showPlayer, "Player"); }); if (water2D_Ripple.showPlayer) { InspectorBox(10, () => { water2D_Ripple.playerRippleRadius = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Radius", "The radius of the ripple created by the player."), water2D_Ripple.playerRippleRadius), 0.0000001f, 1000f); water2D_Ripple.playerRippleStrength = EditorGUILayout.FloatField(new GUIContent("Strength", "The strength of the ripple created by the player."), water2D_Ripple.playerRippleStrength); if (water2DSim.characterControllerType == Water2D_CharacterControllerType.PhysicsBased) { water2D_Ripple.playerVelocityFilter = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Velocity Filter", "If the Abs value of the player velocity on the X and Y axis is smaller than the value of this field, no ripples will be generated by the player."), water2D_Ripple.playerVelocityFilter), 0.0000001f, 100f); } water2D_Ripple.playerRippleXOffset = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("X Axis Position Offset", "Offsets the position of the ripple created by the player on the X axis."), water2D_Ripple.playerRippleXOffset), 0, 1000f); }); } EditorGUI.indentLevel = 0; BoldFontStyle(() => { water2D_Ripple.showRain = EditorGUILayout.Foldout(water2D_Ripple.showRain, "Rain"); }); if (water2D_Ripple.showRain) { InspectorBox(10, () => { water2D_Ripple.rainDrops = EditorGUILayout.Toggle(new GUIContent("Enable Rain", "Enables the simulation of rain."), water2D_Ripple.rainDrops); if (water2D_Ripple.rainDrops) { water2D_Ripple.rainDropRadius = EditorGUILayout.FloatField(new GUIContent("Drop Radius", "The radius of a rain drop in Unity space."), water2D_Ripple.rainDropRadius); water2D_Ripple.rainDropStrength = EditorGUILayout.FloatField(new GUIContent("Drop Strength", "The strength of a rain drop."), water2D_Ripple.rainDropStrength); water2D_Ripple.rainDropFrequency = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Drop Frequency", "The number of water drops that should fall in a second."), water2D_Ripple.rainDropFrequency), 0.0001f, 1000f); } }); } BoldFontStyle(() => { water2D_Ripple.showRippleSourcesList = EditorGUILayout.Foldout(water2D_Ripple.showRippleSourcesList, "Ripple Sources"); }); if (water2D_Ripple.showRippleSourcesList) { InspectorBox(10, () => { water2D_Ripple.rippleSources = EditorGUILayout.Toggle(new GUIContent("Enable Ripple Sources"), water2D_Ripple.rippleSources); if (water2D_Ripple.rippleSources) { water2D_Ripple.rippleSourcesSize = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Size"), water2D_Ripple.rippleSourcesSize), 1, 200); if (water2D_Ripple.rippleSourcesList == null) { water2D_Ripple.rippleSourcesList.Add(null); } if (water2D_Ripple.rippleSourcesSize != water2D_Ripple.rippleSourcesList.Count) { if (water2D_Ripple.rippleSourcesSize > water2D_Ripple.rippleSourcesList.Count) { while (water2D_Ripple.rippleSourcesSize > water2D_Ripple.rippleSourcesList.Count) { water2D_Ripple.rippleSourcesList.Add(null); } } else { while (water2D_Ripple.rippleSourcesSize < water2D_Ripple.rippleSourcesList.Count) { int last = water2D_Ripple.rippleSourcesList.Count - 1; water2D_Ripple.rippleSourcesList.RemoveAt(last); } } } for (int i = 0; i < water2D_Ripple.rippleSourcesList.Count; i++) { water2D_Ripple.rippleSourcesList[i] = EditorGUILayout.ObjectField(new GUIContent("Element " + i), water2D_Ripple.rippleSourcesList[i], typeof(RippleSource), true) as RippleSource; } } }); } if (water2D.use3DCollider) { BoldFontStyle(() => { water2D_Ripple.showMouse = EditorGUILayout.Foldout(water2D_Ripple.showMouse, "Mouse Interaction"); }); if (water2D_Ripple.showMouse) { InspectorBox(10, () => { water2D_Ripple.mouseInteraction = EditorGUILayout.Toggle(new GUIContent("Enable Mouse Interaction", "Enables the ability to interact with the water using the mouse arrow."), water2D_Ripple.mouseInteraction); if (water2D_Ripple.mouseInteraction) { water2D_Ripple.mouseRadius = EditorGUILayout.FloatField(new GUIContent("Mouse Radius", "The radius of the ripple created by the mouse arrow, in Unity space."), water2D_Ripple.mouseRadius); water2D_Ripple.mouseStregth = EditorGUILayout.FloatField(new GUIContent("Mouse Strength", "The strength of the ripple created by the mouse arrow."), water2D_Ripple.mouseStregth); } }); } } BoldFontStyle(() => { water2D_Ripple.showAmbiantWaves = EditorGUILayout.Foldout(water2D_Ripple.showAmbiantWaves, "Ambient Waves"); }); if (water2D_Ripple.showAmbiantWaves) { InspectorBox(10, () => { EditorGUI.BeginChangeCheck(); water2D_Ripple.ambientWaves = EditorGUILayout.Toggle(new GUIContent("Enable Ambient Waves", "Enable this to simulate waves created by the wind."), water2D_Ripple.ambientWaves); if (water2D_Ripple.ambientWaves) { water2D_Ripple.amplitudeZAxisFade = EditorGUILayout.Toggle(new GUIContent("Z Axis Amplitude Fade", "When enabled the amplitude of the sine waves will fade along the Z axis."), water2D_Ripple.amplitudeZAxisFade); if (water2D_Ripple.amplitudeZAxisFade) { water2D_Ripple.amplitudeFadeStart = EditorGUILayout.Slider(new GUIContent("Fade Start", "The start point of the amplitude fade. Can also be used to set the direction of the amplitude fade. If the start point value is greater than the end point, the amplitude will fade from back to front."), water2D_Ripple.amplitudeFadeStart, 0, 1.0f); water2D_Ripple.amplitudeFadeEnd = EditorGUILayout.Slider(new GUIContent("Fade End", "The end point of the amplitude fade. Can also be used to set the direction of the amplitude fade. If the end point value is greater than the start point, the amplitude will fade towards the back of the water."), water2D_Ripple.amplitudeFadeEnd, 0, 1.0f); } EditorGUILayout.LabelField(new GUIContent("Wave 1"), EditorStyles.boldLabel); water2D_Ripple.amplitude1 = EditorGUILayout.FloatField(new GUIContent("Amplitude", "Sine wave amplitude. The bigger the value the higher the wave top will be."), water2D_Ripple.amplitude1); water2D_Ripple.waveLength1 = EditorGUILayout.FloatField(new GUIContent("Wave Length", "The distance between 2 consecutive points of a sine wave."), water2D_Ripple.waveLength1); water2D_Ripple.phaseOffset1 = EditorGUILayout.FloatField(new GUIContent("Phase Offset", "Sine wave phase offset. The bigger the value of the phase offset the faster the waves move to the left (right)."), water2D_Ripple.phaseOffset1); EditorGUILayout.LabelField(new GUIContent("Wave 2"), EditorStyles.boldLabel); water2D_Ripple.amplitude2 = EditorGUILayout.FloatField(new GUIContent("Amplitude", "Sine wave amplitude. The bigger the value the higher the wave top will be."), water2D_Ripple.amplitude2); water2D_Ripple.waveLength2 = EditorGUILayout.FloatField(new GUIContent("Wave Length", "The distance between 2 consecutive points of a sine wave."), water2D_Ripple.waveLength2); water2D_Ripple.phaseOffset2 = EditorGUILayout.FloatField(new GUIContent("Phase Offset", "Sine wave phase offset. The bigger the value of the phase offset the faster the waves move to the left (right)."), water2D_Ripple.phaseOffset2); EditorGUILayout.LabelField(new GUIContent("Wave 3"), EditorStyles.boldLabel); water2D_Ripple.amplitude3 = EditorGUILayout.FloatField(new GUIContent("Amplitude", "Sine wave amplitude. The bigger the value the higher the wave top will be."), water2D_Ripple.amplitude3); water2D_Ripple.waveLength3 = EditorGUILayout.FloatField(new GUIContent("Wave Length", "The distance between 2 consecutive points of a sine wave."), water2D_Ripple.waveLength3); water2D_Ripple.phaseOffset3 = EditorGUILayout.FloatField(new GUIContent("Phase Offset", "Sine wave phase offset. The bigger the value of the phase offset the faster the waves move to the left (right)."), water2D_Ripple.phaseOffset3); } if (EditorGUI.EndChangeCheck() && Application.isPlaying) { water2D_Ripple.SetAmbientWavesShaderParameters(); } }); } }