private void DrawOverlapSphereGizmo(Water2D_Tool water)
        {
            UnityEditor.Handles.color = Color.blue;
            Vector3[]          vertices    = water.GetComponent <MeshFilter>().sharedMesh.vertices;
            Water2D_Simulation water2D_Sim = water.GetComponent <Water2D_Simulation>();
            int surfaceVertsCount          = water.frontMeshVertsCount / 2;

            for (int i = 0; i < surfaceVertsCount; i++)
            {
                Vector3 vertexGlobalPos = water.transform.TransformPoint(vertices[i + surfaceVertsCount]);
                UnityEditor.Handles.DrawWireDisc(new Vector3(vertexGlobalPos.x, vertexGlobalPos.y, vertexGlobalPos.z + water.overlapingSphereZOffset), Vector3.up, water2D_Sim.overlapSphereRadius);
                UnityEditor.Handles.DrawWireDisc(new Vector3(vertexGlobalPos.x, vertexGlobalPos.y, vertexGlobalPos.z + water.overlapingSphereZOffset), Vector3.forward, water2D_Sim.overlapSphereRadius);
            }
        }
        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();
            }
        }
Beispiel #3
0
        private void DrawFlowDirection(Water2D_Tool water)
        {
            Handles.color = Color.white;
            Water2D_Simulation sim = water.GetComponent <Water2D_Simulation>();
            float angleInDeg       = 0;

            if (sim.waterFlow)
            {
                if (sim.useAngles)
                {
                    angleInDeg = sim.flowAngle;
                    Handles.ArrowCap(0, water.transform.position, Quaternion.Euler(new Vector3(angleInDeg, 90f, 0)), 1.5f);
                }
            }
        }
        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_Tool water)
        {
            BoldFontStyle(() =>
            {
                water.showVisuals = EditorGUILayout.Foldout(water.showVisuals, "Mesh Properties");
            });

            if (water.showVisuals)
            {
                InspectorBox(10, () =>
                {
                    water.showMesh = EditorGUILayout.Toggle(new GUIContent("Show Mesh", "Shows or hides the mesh of the water in the scene view"), water.showMesh);



                    if (!water.water2DRippleScript)
                    {
                        water.pixelsPerUnit = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Pixels To Units", "The number of pixels in 1 Unity unit."), water.pixelsPerUnit), 1, 768);
                    }

                    water.useHandles = EditorGUILayout.Toggle(new GUIContent("Use Handles", "The water size is changed using handles."), water.useHandles);
                    if (water.useHandles)
                    {
                        water.handleScale = EditorGUILayout.Slider(new GUIContent("Handle Scale", "Sets the scale of the water handles."), water.handleScale, 0.1f, 10f);
                        pathScale         = water.handleScale;
                    }

                    if (!water.useHandles)
                    {
                        water.waterHeight = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Water Height", "Water height."), water.waterHeight), 0, 5000);
                        water.waterWidth  = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Water Width", "Water width."), water.waterWidth), 0, 5000);


                        float pos = water.waterHeight / 2f;
                        water.handlesPosition[0] = new Vector2(0, pos);
                        water.handlesPosition[1] = new Vector2(0, -pos);

                        pos = water.waterWidth / 2f;

                        water.handlesPosition[2] = new Vector2(-pos, 0);
                        water.handlesPosition[3] = new Vector2(pos, 0);

                        if (water.cubeWater)
                        {
                            water.zSize = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Water Z Length", "The size of the water on the Z axis."), water.zSize), 0, 5000);
                            water.handlesPosition[4] = new Vector3(0, water.handlesPosition[0].y, water.zSize);
                        }
                    }

                    if (!water.quadMesh)
                    {
                        water.segmentsPerUnit = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Segments To Units", "The number of horizontal segments "
                                                                                                      + "that should fit in 1 Unity unit."), water.segmentsPerUnit), 0.00001f, 500f);
                    }
                    water.quadMesh = EditorGUILayout.Toggle(new GUIContent("Single Quad Mesh", "What Enabled, the front mesh and top mesh will always be a quad and have only 4 vertices each."), water.quadMesh);


                    Type utility = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor");
                    GUILayout.Space(5);
                    EditorGUILayout.LabelField(new GUIContent("Front Mesh"), EditorStyles.boldLabel);
                    if (utility != null)
                    {
                        PropertyInfo sortingLayerNames = utility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                        if (sortingLayerNames != null)
                        {
                            string[] layerNames = sortingLayerNames.GetValue(null, null) as string[];
                            string currName     = water.GetComponent <Renderer>().sortingLayerName == "" ? "Default" : water.GetComponent <Renderer>().sortingLayerName;
                            int nameID          = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(layerNames, currName), layerNames);

                            water.GetComponent <Renderer>().sortingLayerName = layerNames[nameID];
                        }
                        else
                        {
                            water.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.GetComponent <Renderer>().sortingLayerID);
                        }
                    }
                    else
                    {
                        water.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.GetComponent <Renderer>().sortingLayerID);
                    }
                    water.GetComponent <Renderer>().sortingOrder = EditorGUILayout.IntField("Order in Layer", water.GetComponent <Renderer>().sortingOrder);

                    if (water.cubeWater)
                    {
                        GUILayout.Space(5);
                        EditorGUILayout.LabelField(new GUIContent("Top Mesh"), EditorStyles.boldLabel);
                        if (utility != null)
                        {
                            PropertyInfo sortingLayerNames = utility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                            if (sortingLayerNames != null)
                            {
                                string[] layerNames = sortingLayerNames.GetValue(null, null) as string[];
                                string currName     = water.topMeshGameObject.GetComponent <Renderer>().sortingLayerName == "" ? "Default" : water.topMeshGameObject.GetComponent <Renderer>().sortingLayerName;
                                int nameID          = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(layerNames, currName), layerNames);

                                water.topMeshGameObject.GetComponent <Renderer>().sortingLayerName = layerNames[nameID];
                            }
                            else
                            {
                                water.topMeshGameObject.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.topMeshGameObject.GetComponent <Renderer>().sortingLayerID);
                            }
                        }
                        else
                        {
                            water.topMeshGameObject.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.topMeshGameObject.GetComponent <Renderer>().sortingLayerID);
                        }
                        water.topMeshGameObject.GetComponent <Renderer>().sortingOrder = EditorGUILayout.IntField("Order in Layer", water.topMeshGameObject.GetComponent <Renderer>().sortingOrder);
                    }
                });
            }


            EditorGUI.indentLevel = 0;
            BoldFontStyle(() =>
            {
                water.showCubeWater = EditorGUILayout.Foldout(water.showCubeWater, "2.5D Water");
            });

            if (water.showCubeWater)
            {
                InspectorBox(10, () =>
                {
                    water.cubeWater = EditorGUILayout.Toggle(new GUIContent("Enable 2.5D Water", "Adds a horizontal mesh at the top of the vertical water mesh."), water.cubeWater);

                    if (water.cubeWater && !water.quadMesh)
                    {
                        if (!water.quadMesh)
                        {
                            water.squareSegments = EditorGUILayout.Toggle(new GUIContent("TM Square Segments", "When enabled, the top mesh quads will have the same width and length."), water.squareSegments);
                        }


                        if (water.squareSegments)
                        {
                            water.zSegmentsCap = EditorGUILayout.Toggle(new GUIContent("Z Segments Limit", "Limits the number of segments the top mesh has on the Z axis."), water.zSegmentsCap);
                        }


                        if (!water.squareSegments || (water.squareSegments && water.zSegmentsCap))
                        {
                            water.zSegmentsSize = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Z Segments", "The number of segments, the top water mesh will have."), water.zSegmentsSize), 1, 500);
                        }
                    }

                    if (water.cubeWater && water.handlesPosition.Count == 4)
                    {
                        water.handlesPosition.Add(new Vector3(water.handlesPosition[0].x, water.handlesPosition[0].y, water.zSize));
                    }

                    if (!water.cubeWater && water.topMeshGameObject)
                    {
                        DestroyImmediate(water.topMeshGameObject.gameObject);
                    }

                    if (water.cubeWater)
                    {
                        CreateTopMeshObject(water);
                    }

                    if (!water.cubeWater && water.handlesPosition.Count > 4)
                    {
                        water.handlesPosition.RemoveAt(4);
                    }
                });
            }

            Water2D_Simulation water2D_Sim = water.GetComponent <Water2D_Simulation>();

            if (water2D_Sim.waterType == Water2D_Type.Dynamic)
            {
                BoldFontStyle(() =>
                {
                    water.showCollider = EditorGUILayout.Foldout(water.showCollider, "Collider");
                });

                if (water.showCollider && water.createCollider)
                {
                    InspectorBox(10, () =>
                    {
                        if (water.createCollider)
                        {
                            water.colliderYAxisOffset = EditorGUILayout.FloatField(new GUIContent("Collider Top Offset", "Offsets the position of the top edge of the water collider. "
                                                                                                  + "This is done so that objects that are a little above the waterline are detected."), water.colliderYAxisOffset);

                            if (water.use3DCollider)
                            {
                                water.boxColliderCenterOffset = EditorGUILayout.Vector3Field(new GUIContent("BC Center Offset", "Info."), water.boxColliderCenterOffset);
                                water.boxColliderSizeOffset   = EditorGUILayout.Vector3Field(new GUIContent("BC Size Offset", "Info."), water.boxColliderSizeOffset);

                                if (!water.cubeWater)
                                {
                                    water.boxColliderZSize = EditorGUILayout.FloatField(new GUIContent("Box Collider Z Size", "The size of the box collider on the Z axis."), water.boxColliderZSize);
                                }

                                if (!water.water2DRippleScript)
                                {
                                    water.overlapingSphereZOffset = EditorGUILayout.FloatField(new GUIContent("Overlaping Sphere Z Offset", "Info."), water.overlapingSphereZOffset);
                                }
                            }
                        }
                    });
                }
            }

            BoldFontStyle(() =>
            {
                water.showInfo = EditorGUILayout.Foldout(water.showInfo, "Mesh Info");
            });

            if (water.showInfo)
            {
                InspectorBox(10, () =>
                {
                    water.showMeshInfo = EditorGUILayout.Toggle("Show Mesh Info", water.showMeshInfo);

                    if (water.showMeshInfo)
                    {
                        if (water.cubeWater)
                        {
                            EditorGUILayout.LabelField(new GUIContent("Top Mesh"), EditorStyles.boldLabel);
                            EditorGUILayout.LabelField(new GUIContent("Mesh Grid"), new GUIContent(water.xVerts.ToString() + " x " + water.zVerts.ToString()));
                            EditorGUILayout.LabelField(new GUIContent("Mesh Vertices", "The number of vertices the top mesh currently has."), new GUIContent((water.zVerts * water.xVerts).ToString()));
                            GUILayout.Space(5);
                            EditorGUILayout.LabelField(new GUIContent("Front Mesh"), EditorStyles.boldLabel);
                            EditorGUILayout.LabelField(new GUIContent("Mesh Grid"), new GUIContent(water.xVerts.ToString() + " x " + 2));
                            EditorGUILayout.LabelField(new GUIContent("Mesh Vertices", "The number of vertices the front mesh currently has."), new GUIContent((water.xVerts * 2).ToString()));

                            if (water.GetComponent <Water2D_Ripple>())
                            {
                                GUILayout.Space(5);
                                EditorGUILayout.LabelField(new GUIContent("Render Texture"), EditorStyles.boldLabel);
                                EditorGUILayout.LabelField(new GUIContent("Resolution", "The resolution of the Render Texture that will be created when the game starts."), new GUIContent(water.renderTextureWidth.ToString() + " x " + water.renderTextureHeight.ToString()));
                            }
                        }
                        else
                        {
                            EditorGUILayout.LabelField(new GUIContent("Front Mesh"), EditorStyles.boldLabel);
                            EditorGUILayout.LabelField(new GUIContent("Mesh Grid"), new GUIContent(water.xVerts.ToString() + " x " + 2));
                            EditorGUILayout.LabelField(new GUIContent("Mesh Vertices", "The number of vertices the front mesh currently has."), new GUIContent((water.xVerts * 2).ToString()));
                        }
                    }
                });
            }
        }
        //------------------------------------------------------------------------------

        private void CustomInspector(Water2D_Tool water)
        {
            showVisuals = EditorGUILayout.Foldout(showVisuals, "Visual Properties");

            if (showVisuals)
            {
                EditorGUI.indentLevel = 1;
                InspectorBox(10, () =>
                {
                    water.showMesh = !EditorGUILayout.Toggle(new GUIContent("Show Mesh", "Shows or hides the mesh of the water in the scene view"), !water.showMesh);

                    water.verticalTiling = EditorGUILayout.Toggle(new GUIContent("Vertical Tiling", "When enabled will tile the texture horizontally "
                        + "if the water height is greater than the max water height that can be created with the current texture."), water.verticalTiling);

                    water.pixelsPerUnit = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Pixels To Units", "The number of pixels in 1 Unity unit."), water.pixelsPerUnit), 1, 768);

                    water.segmentsPerUnit = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Segments To Units", "The number of horizontal segments "
                        + "that should fit in 1 Unity unit."), water.segmentsPerUnit), 0, 100);

                    Type utility = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor");
                    if (utility != null)
                    {
                        PropertyInfo sortingLayerNames = utility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                        if (sortingLayerNames != null)
                        {
                            string[] layerNames = sortingLayerNames.GetValue(null, null) as string[];
                            string currName = water.GetComponent<Renderer>().sortingLayerName == "" ? "Default" : water.GetComponent<Renderer>().sortingLayerName;
                            int nameID = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(layerNames, currName), layerNames);

                            water.GetComponent<Renderer>().sortingLayerName = layerNames[nameID];

                        }
                        else
                        {
                            water.GetComponent<Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.GetComponent<Renderer>().sortingLayerID);
                        }
                    }
                    else
                    {
                        water.GetComponent<Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.GetComponent<Renderer>().sortingLayerID);
                    }
                    water.GetComponent<Renderer>().sortingOrder = EditorGUILayout.IntField("Order in Layer", water.GetComponent<Renderer>().sortingOrder);

                    water.handleScale = EditorGUILayout.Slider(new GUIContent("Handle Scale", "Sets the scale of the water handles."), water.handleScale, 0.1f, 10f);
                    pathScale = water.handleScale;

                    water.cubeWater = EditorGUILayout.Toggle(new GUIContent("2.5D Water", "Adds a horizontal mesh at the top of the vertical water mesh."), water.cubeWater);
                    if (water.cubeWater)
                    {
                        water.zSegments = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Z Segments", "The number of segments, the horizontal water mesh will have."), water.zSegments), 1, 100);

                        if (water.handlesPosition.Count == 4)
                        {
                            water.handlesPosition.Add(new Vector3(water.handlesPosition[0].x, water.handlesPosition[0].y, water.zSize));
                        }
                    }

                    if (!water.cubeWater && water.handlesPosition.Count > 4)
                        water.handlesPosition.RemoveAt(4);

                    EditorGUILayout.LabelField(new GUIContent("Current Water Area", "The value of this field is not used in any calculations. "
                        + "When creating an animation that animates the area of the water, use this value as a guide to see how the water area changes between two positions."), new GUIContent(water.curentWaterArea.ToString()));

                });
            }

            EditorGUI.indentLevel = 0;

            Water2D_Simulation water2D_Sim = water.GetComponent<Water2D_Simulation>();

            if (water2D_Sim.waterType == Water2D_Type.Dynamic)
            {
                showCollider = EditorGUILayout.Foldout(showCollider, "Collider");

                if (showCollider && water.createCollider)
                {
                    EditorGUI.indentLevel = 1;
                    InspectorBox(10, () =>
                    {
                        if (water.createCollider)
                        {
                            water.colliderOffset = EditorGUILayout.FloatField(new GUIContent("Collider Top Offset", "Offsets the position of the top edge of the water collider. "
                                + "This is done so that objects that are a little above the waterline are detected."), water.colliderOffset);

                            if (water.use3DCollider)
                            {
                                water.boxColliderZOffset = EditorGUILayout.FloatField(new GUIContent("Box Collider Z Offset", "Offsets the center of the box collider on the Z axis."), water.boxColliderZOffset);
                                water.boxColliderZSize = EditorGUILayout.FloatField(new GUIContent("Box Collider Z Size", "The size of the box collider on the Z axis."), water.boxColliderZSize);
                            }
                        }

                    });
                }

                EditorGUI.indentLevel = 0;
            }
        }
        private void DrawOverlapSphereGizmo(Water2D_Tool water)
        {
            UnityEditor.Handles.color = Color.blue;
            Vector3[] vertices = water.GetComponent<MeshFilter>().sharedMesh.vertices;
            Water2D_Simulation water2D_Sim = water.GetComponent<Water2D_Simulation>();
            int surfaceVertsCount = water.surfaceVertsCount / 2; ;

            for (int i = 0; i < surfaceVertsCount; i++)
            {
                Vector3 vertexGlobalPos = water.transform.TransformPoint(vertices[i + surfaceVertsCount]);
                UnityEditor.Handles.DrawWireDisc(new Vector3(vertexGlobalPos.x, vertexGlobalPos.y, vertexGlobalPos.z + water.boxColliderZOffset), Vector3.up, water2D_Sim.overlapSphereRadius);
                UnityEditor.Handles.DrawWireDisc(new Vector3(vertexGlobalPos.x, vertexGlobalPos.y, vertexGlobalPos.z + water.boxColliderZOffset), Vector3.forward, water2D_Sim.overlapSphereRadius);
            }
        }
        private void DrawFlowDirection(Water2D_Tool water)
        {
            Handles.color = Color.white;
            Water2D_Simulation sim = water.GetComponent<Water2D_Simulation>();
            float angleInDeg = 0;

            if (sim.waterFlow)
            {
                if (sim.useAngles)
                {
                    angleInDeg = sim.flowAngle;
                    Handles.ArrowCap(0, water.transform.position, Quaternion.Euler(new Vector3(angleInDeg, 90f, 0)), 1.5f);
                }
            }
        }
Beispiel #9
0
        //------------------------------------------------------------------------------

        private void CustomInspector(Water2D_Tool water)
        {
            showVisuals = EditorGUILayout.Foldout(showVisuals, "Visual Properties");

            if (showVisuals)
            {
                EditorGUI.indentLevel = 1;
                InspectorBox(10, () =>
                {
                    water.showMesh = !EditorGUILayout.Toggle(new GUIContent("Show Mesh", "Shows or hides the mesh of the water in the scene view"), !water.showMesh);

                    water.verticalTiling = EditorGUILayout.Toggle(new GUIContent("Vertical Tiling", "When enabled will tile the texture horizontally "
                                                                                 + "if the water height is greater than the max water height that can be created with the current texture."), water.verticalTiling);

                    water.pixelsPerUnit = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Pixels To Units", "The number of pixels in 1 Unity unit."), water.pixelsPerUnit), 1, 768);

                    water.segmentsPerUnit = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Segments To Units", "The number of horizontal segments "
                                                                                                  + "that should fit in 1 Unity unit."), water.segmentsPerUnit), 0, 100);

                    Type utility = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor");
                    if (utility != null)
                    {
                        PropertyInfo sortingLayerNames = utility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                        if (sortingLayerNames != null)
                        {
                            string[] layerNames = sortingLayerNames.GetValue(null, null) as string[];
                            string currName     = water.GetComponent <Renderer>().sortingLayerName == "" ? "Default" : water.GetComponent <Renderer>().sortingLayerName;
                            int nameID          = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(layerNames, currName), layerNames);

                            water.GetComponent <Renderer>().sortingLayerName = layerNames[nameID];
                        }
                        else
                        {
                            water.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.GetComponent <Renderer>().sortingLayerID);
                        }
                    }
                    else
                    {
                        water.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", water.GetComponent <Renderer>().sortingLayerID);
                    }
                    water.GetComponent <Renderer>().sortingOrder = EditorGUILayout.IntField("Order in Layer", water.GetComponent <Renderer>().sortingOrder);

                    water.handleScale = EditorGUILayout.Slider(new GUIContent("Handle Scale", "Sets the scale of the water handles."), water.handleScale, 0.1f, 10f);
                    pathScale         = water.handleScale;

                    water.cubeWater = EditorGUILayout.Toggle(new GUIContent("2.5D Water", "Adds a horizontal mesh at the top of the vertical water mesh."), water.cubeWater);

                    if (water.cubeWater)
                    {
                        water.zSegments = Mathf.Clamp(EditorGUILayout.IntField(new GUIContent("Z Segments", "The number of segments, the horizontal water mesh will have."), water.zSegments), 1, 100);

                        if (water.handlesPosition.Count == 4)
                        {
                            water.handlesPosition.Add(new Vector3(water.handlesPosition[0].x, water.handlesPosition[0].y, water.zSize));
                        }
                    }

                    water.useHandles = EditorGUILayout.Toggle(new GUIContent("Use Handles", "The water size is changed using handles."), water.useHandles);

                    if (!water.useHandles)
                    {
                        water.waterHeight = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Water Height", "Water height."), water.waterHeight), 0, 1000);
                        water.waterWidth  = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Water Width", "Water width."), water.waterWidth), 0, 1000);


                        float pos = water.waterHeight / 2f;
                        water.handlesPosition[0] = new Vector2(0, pos);
                        water.handlesPosition[1] = new Vector2(0, -pos);

                        pos = water.waterWidth / 2f;

                        water.handlesPosition[2] = new Vector2(-pos, 0);
                        water.handlesPosition[3] = new Vector2(pos, 0);

                        if (water.cubeWater)
                        {
                            water.zSize = Mathf.Clamp(EditorGUILayout.FloatField(new GUIContent("Water Z Length", "The size of the water on the Z axis."), water.zSize), 0, 1000);
                            water.handlesPosition[4] = new Vector3(0, water.handlesPosition[0].y, water.zSize);
                        }
                    }

                    if (!water.cubeWater && water.handlesPosition.Count > 4)
                    {
                        water.handlesPosition.RemoveAt(4);
                    }

                    EditorGUILayout.LabelField(new GUIContent("Current Water Area", "The value of this field is not used in any calculations. "
                                                              + "When creating an animation that animates the area of the water, use this value as a guide to see how the water area changes between two positions."), new GUIContent(water.curentWaterArea.ToString()));
                });
            }

            EditorGUI.indentLevel = 0;

            Water2D_Simulation water2D_Sim = water.GetComponent <Water2D_Simulation>();

            if (water2D_Sim.waterType == Water2D_Type.Dynamic)
            {
                showCollider = EditorGUILayout.Foldout(showCollider, "Collider");

                if (showCollider && water.createCollider)
                {
                    EditorGUI.indentLevel = 1;
                    InspectorBox(10, () =>
                    {
                        if (water.createCollider)
                        {
                            water.colliderOffset = EditorGUILayout.FloatField(new GUIContent("Collider Top Offset", "Offsets the position of the top edge of the water collider. "
                                                                                             + "This is done so that objects that are a little above the waterline are detected."), water.colliderOffset);

                            if (water.use3DCollider)
                            {
                                water.boxColliderZOffset = EditorGUILayout.FloatField(new GUIContent("Box Collider Z Offset", "Offsets the center of the box collider on the Z axis."), water.boxColliderZOffset);
                                water.boxColliderZSize   = EditorGUILayout.FloatField(new GUIContent("Box Collider Z Size", "The size of the box collider on the Z axis."), water.boxColliderZSize);
                            }
                        }
                    });
                }

                EditorGUI.indentLevel = 0;
            }
        }
Beispiel #10
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();
                    }
                });
            }
        }