Exemplo n.º 1
0
        public void DrawDebugGUI()
        {
            string label = "Debug";
            string id    = "debug" + water.GetInstanceID().ToString();

            PEditorCommon.Foldout(label, false, id, () =>
            {
                Camera[] cams = water.GetComponentsInChildren <Camera>();
                for (int i = 0; i < cams.Length; ++i)
                {
                    if (!cams[i].name.StartsWith("~"))
                    {
                        continue;
                    }
                    if (cams[i].targetTexture == null)
                    {
                        continue;
                    }
                    EditorGUILayout.LabelField(cams[i].name);
                    Rect r = GUILayoutUtility.GetAspectRect(1);
                    EditorGUI.DrawPreviewTexture(r, cams[i].targetTexture);
                    EditorGUILayout.Space();
                }
            });
        }
Exemplo n.º 2
0
        private void DrawMeshSettingsGUI()
        {
            string      label = "Mesh";
            string      id    = "water-profile-mesh";
            GenericMenu menu  = new GenericMenu();

            menu.AddItem(
                new GUIContent("Generate"),
                false,
                () => { water.GenerateMesh(); });

            PEditorCommon.Foldout(label, true, id, () =>
            {
                if (water.MeshType == PWaterMeshType.TileablePlane)
                {
                    DrawTilableMeshGUI();
                }
                else if (water.MeshType == PWaterMeshType.Area)
                {
                    DrawAreaMeshGUI();
                }
                else if (water.MeshType == PWaterMeshType.Spline)
                {
                    DrawSplineMeshGUI();
                }
                else if (water.MeshType == PWaterMeshType.CustomMesh)
                {
                    DrawCustomMeshGUI();
                }
            }, menu);
        }
Exemplo n.º 3
0
 public static void ShowSupportEmailEditor()
 {
     PEditorCommon.OpenEmailEditor(
         PCommon.SUPPORT_EMAIL,
         "[Poseidon] SHORT_QUESTION_HERE",
         "YOUR_QUESTION_IN_DETAIL");
 }
Exemplo n.º 4
0
 public static void ShowBusinessEmailEditor()
 {
     PEditorCommon.OpenEmailEditor(
         PCommon.BUSINESS_EMAIL,
         "[Poseidon] SHORT_MESSAGE_HERE",
         "YOUR_MESSAGE_IN_DETAIL");
 }
 public static void OpenSupportLink()
 {
     PEditorCommon.OpenEmailEditor(
         "*****@*****.**",
         "Griffin Extension - Poseidon",
         "YOUR_MESSAGE_HERE");
 }
Exemplo n.º 6
0
        private void DrawSelectedSegmentGUI()
        {
            int segmentIndex = splineEditingGUIDrawer.selectedSegmentIndex;

            if (segmentIndex < 0 ||
                segmentIndex >= water.Spline.Anchors.Count)
            {
                return;
            }
            string label = "Selected Segment";
            string id    = "poseidon-selected-segment";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                EditorGUI.indentLevel -= 1;
                EditorGUI.BeginChangeCheck();
                PSplineSegment s                    = water.Spline.Segments[segmentIndex];
                GUI.enabled                         = !PSplineToolConfig.Instance.AutoTangent;
                s.StartTangent                      = PEditorCommon.InlineVector3Field("Start Tangent", s.StartTangent);
                s.EndTangent                        = PEditorCommon.InlineVector3Field("End Tangent", s.EndTangent);
                GUI.enabled                         = true;
                s.ResolutionMultiplierY             = EditorGUILayout.Slider("Resolution Multiplier Y", s.ResolutionMultiplierY, 0f, 2f);
                water.Spline.Segments[segmentIndex] = s;
                if (EditorGUI.EndChangeCheck())
                {
                    water.GenerateSplineMeshAtSegment(segmentIndex);
                }
                EditorGUI.indentLevel += 1;
            });
        }
Exemplo n.º 7
0
        private void DrawCausticSettings()
        {
            string label = "Caustic";
            string id    = "water-profile-caustic";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                bool valid = profile.EnableLightAbsorption && (profile.EnableRefraction || water.MeshType == PWaterMeshType.Spline);
                if (!valid)
                {
                    EditorGUILayout.LabelField("Requires Light Absorbtion and Refraction.", PEditorCommon.WordWrapItalicLabel);
                    profile.EnableCaustic = false;
                }

                GUI.enabled           = valid;
                profile.EnableCaustic = EditorGUILayout.Toggle("Enable", profile.EnableCaustic);
                if (profile.EnableCaustic)
                {
                    profile.CausticTexture            = PEditorCommon.InlineTextureField("Texture", profile.CausticTexture, -1);
                    profile.CausticSize               = EditorGUILayout.FloatField("Size", profile.CausticSize);
                    profile.CausticStrength           = EditorGUILayout.Slider("Strength", profile.CausticStrength, 0f, 5f);
                    profile.CausticDistortionStrength = EditorGUILayout.FloatField("Distortion", profile.CausticDistortionStrength);
                }
                GUI.enabled = true;
            });
        }
Exemplo n.º 8
0
        private void DrawEffectsGUI()
        {
            if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Universal)
            {
                return;
            }
            PWaterFX fx = water.GetComponent <PWaterFX>();

            if (fx != null)
            {
                return;
            }

            string label = "Effects";
            string id    = "effects" + water.GetInstanceID();

            PEditorCommon.Foldout(label, false, id, () =>
            {
                bool isStackV2Installed = false;
#if UNITY_POST_PROCESSING_STACK_V2
                isStackV2Installed = true;
#endif
                if (!isStackV2Installed)
                {
                    EditorGUILayout.LabelField("Water effect need the Post Processing Stack V2 to work. Please install it using the Package Manager", PEditorCommon.WordWrapItalicLabel);
                }
                GUI.enabled = isStackV2Installed;
                if (GUILayout.Button("Add Effects"))
                {
                    fx       = water.gameObject.AddComponent <PWaterFX>();
                    fx.Water = water;
                }
                GUI.enabled = true;
            });
        }
Exemplo n.º 9
0
        public override void OnInspectorGUI()
        {
            if (water.transform.rotation != Quaternion.identity)
            {
                string warning = "The water object is designed to work without rotation. Some features may not work correctly.";
                EditorGUILayout.LabelField(warning, PEditorCommon.WarningLabel);
            }

            water.Profile = PEditorCommon.ScriptableObjectField <PWaterProfile>("Profile", water.Profile);
            profile       = water.Profile;
            if (water.Profile == null)
            {
                return;
            }
            so = new SerializedObject(profile);
            reflectionLayersSO = so.FindProperty("reflectionLayers");
            refractionLayersSO = so.FindProperty("refractionLayers");

            EditorGUI.BeginChangeCheck();
            DrawMeshSettingsGUI();
            DrawRenderingSettingsGUI();
            DrawColorsSettingsGUI();
            DrawFresnelSettingsGUI();
            DrawRippleSettingsGUI();
            DrawWaveSettingsGUI();
            DrawLightAbsorbtionSettingsGUI();
            DrawFoamSettingsGUI();
            DrawReflectionSettings();
            DrawRefractionSettings();
            DrawCausticSettings();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(profile);
                water.UpdateMaterial();
            }

            DrawEffectsGUI();
            if (willDrawDebugGUI)
            {
                DrawDebugGUI();
            }

            if (so != null)
            {
                so.Dispose();
            }

            if (reflectionLayersSO != null)
            {
                reflectionLayersSO.Dispose();
            }

            if (refractionLayersSO != null)
            {
                refractionLayersSO.Dispose();
            }
        }
Exemplo n.º 10
0
        public override void OnInspectorGUI()
        {
            bool   willDrawGUI = false;
            string msg         = null;

            if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Builtin)
            {
#if UNITY_POST_PROCESSING_STACK_V2
                willDrawGUI = true;
#else
                msg = "Please install Post Processing Stack V2 to setup water effect";
#endif
            }
            else if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Universal)
            {
#if POSEIDON_URP
                willDrawGUI = true;
#endif
            }
            else
            {
                willDrawGUI = false;
                msg         = "Water effect doesn't support custom render pipeline.";
            }

            if (!willDrawGUI)
            {
                EditorGUILayout.LabelField(msg, PEditorCommon.WordWrapItalicLabel);
                return;
            }

#if POSEIDON_URP
            if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Universal)
            {
                if (!CheckRendererFeatureConfig())
                {
                    EditorGUILayout.LabelField("Please add a Water Effect Renderer Feature to the current URP Asset to setup water effect.", PEditorCommon.WordWrapItalicLabel);
                    return;
                }
            }
#endif

            instance.Water   = EditorGUILayout.ObjectField("Water", instance.Water, typeof(PWater), true) as PWater;
            instance.Profile = PEditorCommon.ScriptableObjectField <PWaterFXProfile>("Profile", instance.Profile);

            if (instance.Water == null || instance.Profile == null)
            {
                return;
            }
            DrawVolumesGUI();
            EditorGUI.BeginChangeCheck();
            PWaterFXProfileInspectorDrawer.Create(instance.Profile, instance.Water).DrawGUI();
            if (EditorGUI.EndChangeCheck())
            {
                instance.UpdatePostProcessOrVolumeProfile();
            }
            DrawEventsGUI();
        }
Exemplo n.º 11
0
        private void DrawTilableMeshGUI()
        {
            if (!isEditingTileIndices)
            {
                EditorGUI.BeginChangeCheck();
                //water.MeshType = (PWaterMeshType)EditorGUILayout.EnumPopup("Mesh Type", water.MeshType);
                water.MeshType       = (PWaterMeshType)EditorGUILayout.IntPopup("Mesh Type", (int)water.MeshType, meshTypeLabels, meshTypes);
                water.PlanePattern   = (PPlaneMeshPattern)EditorGUILayout.EnumPopup("Pattern", water.PlanePattern);
                water.MeshResolution = EditorGUILayout.DelayedIntField("Resolution", water.MeshResolution);
                if (EditorGUI.EndChangeCheck())
                {
                    water.GenerateMesh();
                    water.ReCalculateBounds();
                }
                water.MeshNoise = EditorGUILayout.FloatField("Noise", water.MeshNoise);

                EditorGUI.BeginChangeCheck();
                water.TileSize = PEditorCommon.InlineVector2Field("Tile Size", water.TileSize);
                water.TilesFollowMainCamera = EditorGUILayout.Toggle("Follow Main Camera", water.TilesFollowMainCamera);
                SerializedObject   so = new SerializedObject(water);
                SerializedProperty sp = so.FindProperty("tileIndices");

                if (sp != null)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(sp, true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        so.ApplyModifiedProperties();
                    }
                }

                sp.Dispose();
                so.Dispose();

                if (EditorGUI.EndChangeCheck())
                {
                    water.ReCalculateBounds();
                }
            }

            if (!isEditingTileIndices)
            {
                if (GUILayout.Button("Edit Tiles"))
                {
                    isEditingTileIndices = true;
                }
            }
            else
            {
                EditorGUILayout.LabelField("Edit water tiles in Scene View.", PEditorCommon.WordWrapItalicLabel);
                if (GUILayout.Button("End Editing Tiles"))
                {
                    isEditingTileIndices = false;
                }
            }
        }
Exemplo n.º 12
0
        private void DrawVolumesGUI()
        {
            string label = "Volumes";
            string id    = "volumes" + instance.GetInstanceID();

            PEditorCommon.Foldout(label, false, id, () =>
            {
                instance.VolumeExtent = PEditorCommon.InlineVector3Field("Extent", instance.VolumeExtent);
                instance.VolumeLayer  = EditorGUILayout.LayerField("Layer", instance.VolumeLayer);
            });
        }
Exemplo n.º 13
0
        private void DrawFresnelSettingsGUI()
        {
            string label = "Fresnel";
            string id    = "water-profile-fresnel";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                profile.FresnelStrength = EditorGUILayout.Slider("Strength", profile.FresnelStrength, 0f, 10f);
                profile.FresnelBias     = EditorGUILayout.Slider("Bias", profile.FresnelBias, 0f, 1f);
            });
        }
Exemplo n.º 14
0
        private void DrawLightAbsorbtionSettingsGUI()
        {
            string label = "Light Absorption";
            string id    = "water-profile-absorption";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                profile.EnableLightAbsorption = EditorGUILayout.Toggle("Enable", profile.EnableLightAbsorption);
                if (profile.EnableLightAbsorption)
                {
                    profile.DepthColor = EditorGUILayout.ColorField("Depth Color", profile.DepthColor);
                    profile.MaxDepth   = EditorGUILayout.FloatField("Max Depth", profile.MaxDepth);
                }
            });
        }
Exemplo n.º 15
0
        private void DrawInstruction()
        {
            string s = string.Format(
                "{0}" +
                "{1}" +
                "{2}" +
                "{3}",
                "Click to select,",
                "\nShift+Click to add,",
                "\nCtrl+Click to remove anchor.",
                "\nClick End Editing Spline when done.");

            GUIContent mouseMessage = new GUIContent(s);

            PEditorCommon.SceneViewMouseMessage(mouseMessage);
        }
Exemplo n.º 16
0
        private void DrawRippleSettingsGUI()
        {
            string label = "Ripple";
            string id    = "water-profile-ripple";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                //instance.EnableRipple = EditorGUILayout.Toggle("Enable", instance.EnableRipple);
                if (profile.EnableRipple)
                {
                    profile.RippleHeight     = EditorGUILayout.Slider("Height", profile.RippleHeight, 0f, 1f);
                    profile.RippleNoiseScale = EditorGUILayout.FloatField("Scale", profile.RippleNoiseScale);
                    profile.RippleSpeed      = EditorGUILayout.FloatField("Speed", profile.RippleSpeed);
                }
            });
        }
Exemplo n.º 17
0
        private void DrawRefractionSettings()
        {
            string label = "Refraction";
            string id    = "water-profile-refraction";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                if (water.MeshType != PWaterMeshType.Spline)
                {
                    profile.EnableRefraction = EditorGUILayout.Toggle("Enable", profile.EnableRefraction);
                }
                if (profile.EnableRefraction || water.MeshType == PWaterMeshType.Spline)
                {
                    profile.RefractionDistortionStrength = EditorGUILayout.FloatField("Distortion", profile.RefractionDistortionStrength);
                }
            });
        }
        private void DrawWetLensGUI()
        {
            string label = "Wet Lens";
            string id    = "wet-lens" + instance.GetInstanceID();

            PEditorCommon.Foldout(label, false, id, () =>
            {
                instance.EnableWetLens = EditorGUILayout.Toggle("Enable", instance.EnableWetLens);
                if (instance.EnableWetLens)
                {
                    instance.WetLensNormalMap = PEditorCommon.InlineTextureField("Normal Map", instance.WetLensNormalMap, -1);
                    instance.WetLensStrength  = EditorGUILayout.Slider("Strength", instance.WetLensStrength, 0f, 1f);
                    instance.WetLensDuration  = EditorGUILayout.FloatField("Duration", instance.WetLensDuration);
                    instance.WetLensFadeCurve = EditorGUILayout.CurveField("Fade", instance.WetLensFadeCurve, Color.red, new Rect(0, 0, 1, 1));
                }
            });
        }
Exemplo n.º 19
0
        private void DrawRenderingSettingsGUI()
        {
            string label = "Rendering";
            string id    = "water-profile-general";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                GUI.enabled = false;
                EditorGUILayout.ObjectField("Material", water.MaterialToRender, typeof(Material), false);
                if (water.MeshType == PWaterMeshType.TileablePlane && water.ShouldRenderBackface)
                {
                    EditorGUILayout.ObjectField("Material Back Face", water.MaterialBackFace, typeof(Material), false);
                }
                GUI.enabled = true;

                if (PCommon.CurrentRenderPipeline == PRenderPipelineType.Builtin)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Light Model");
                    Rect r = EditorGUILayout.GetControlRect();
                    if (GUI.Button(r, "Physical Based", EditorStyles.popup))
                    {
                        GenericMenu menu = new GenericMenu();
                        menu.AddItem(new GUIContent("Physical Based"), false, () => { });
                        menu.AddDisabledItem(new GUIContent("Blinn Phong (SRP)"));
                        menu.AddDisabledItem(new GUIContent("Lambert (SRP)"));
                        menu.DropDown(r);
                    }
                    EditorGUILayout.EndHorizontal();
                    profile.LightingModel = PLightingModel.PhysicalBased;
                }
                else
                {
                    profile.LightingModel = (PLightingModel)EditorGUILayout.EnumPopup("Light Model", profile.LightingModel);
                }

                profile.RenderQueueIndex = EditorGUILayout.IntField("Queue Index", profile.RenderQueueIndex);
                if (water.MeshType == PWaterMeshType.TileablePlane)
                {
                    water.ShouldRenderBackface = EditorGUILayout.Toggle("Render Back Face", water.ShouldRenderBackface);
                }
            });
        }
Exemplo n.º 20
0
        private void DrawWaveSettingsGUI()
        {
            string label = "Wave";
            string id    = "water-profile-ripple";

            PEditorCommon.Foldout(label, false, id, () =>
            {
                profile.EnableWave = EditorGUILayout.Toggle("Enable", profile.EnableWave);
                if (profile.EnableWave)
                {
                    profile.WaveDirection = EditorGUILayout.Slider("Direction", profile.WaveDirection, 0f, 360f);
                    profile.WaveSpeed     = EditorGUILayout.FloatField("Speed", profile.WaveSpeed);
                    profile.WaveHeight    = EditorGUILayout.FloatField("Height", profile.WaveHeight);
                    profile.WaveLength    = EditorGUILayout.FloatField("Length", profile.WaveLength);
                    profile.WaveSteepness = EditorGUILayout.Slider("Steepness", profile.WaveSteepness, 0f, 1f);
                    profile.WaveDeform    = EditorGUILayout.Slider("Deform", profile.WaveDeform, 0f, 1f);
                }
            });
        }
Exemplo n.º 21
0
        private void DrawColorsSettingsGUI()
        {
            string label = "Colors";
            string id    = "water-profile-colors";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                profile.Color = EditorGUILayout.ColorField("Color", profile.Color);
                if (profile.EnableLightAbsorption)
                {
                    profile.DepthColor = EditorGUILayout.ColorField("Depth Color", profile.DepthColor);
                }
                if (profile.LightingModel == PLightingModel.PhysicalBased || profile.LightingModel == PLightingModel.BlinnPhong)
                {
                    //instance.SpecColor = EditorGUILayout.ColorField("Specular Color", instance.SpecColor);
                    profile.SpecColor  = EditorGUILayout.ColorField(new GUIContent("Specular Color"), profile.SpecColor, true, false, true);
                    profile.Smoothness = EditorGUILayout.Slider("Smoothness", profile.Smoothness, 0f, 1f);
                }
            });
        }
Exemplo n.º 22
0
        private void DrawEventsGUI()
        {
            string label = "Events";
            string id    = "events" + instance.GetInstanceID();

            PEditorCommon.Foldout(label, false, id, () =>
            {
                SerializedObject so    = new SerializedObject(instance);
                SerializedProperty sp0 = so.FindProperty("onEnterWater");
                if (sp0 != null)
                {
                    EditorGUILayout.PropertyField(sp0);
                }

                SerializedProperty sp1 = so.FindProperty("onExitWater");
                if (sp1 != null)
                {
                    EditorGUILayout.PropertyField(sp1);
                }
                so.ApplyModifiedProperties();
            });
        }
Exemplo n.º 23
0
        private void DrawReflectionSettings()
        {
            if (water.MeshType == PWaterMeshType.Spline)
            {
                return;
            }

            bool stereoEnable = false;

            if (Camera.main != null)
            {
                stereoEnable = Camera.main.stereoEnabled;
            }

            string label = "Reflection" + (stereoEnable ? " (Not support for VR)" : "");
            string id    = "water-profile-reflection";

            GUI.enabled = !stereoEnable;
            PEditorCommon.Foldout(label, true, id, () =>
            {
                profile.EnableReflection = EditorGUILayout.Toggle("Enable", profile.EnableReflection);
                if (profile.EnableReflection)
                {
                    profile.ReflectCustomSkybox        = EditorGUILayout.Toggle("Custom Skybox", profile.ReflectCustomSkybox);
                    profile.EnableReflectionPixelLight = EditorGUILayout.Toggle("Pixel Light", profile.EnableReflectionPixelLight);
                    profile.ReflectionClipPlaneOffset  = EditorGUILayout.FloatField("Clip Plane Offset", profile.ReflectionClipPlaneOffset);

                    if (reflectionLayersSO != null)
                    {
                        EditorGUILayout.PropertyField(reflectionLayersSO);
                    }
                    so.ApplyModifiedProperties();

                    profile.ReflectionTextureResolution  = EditorGUILayout.IntPopup("Resolution", profile.ReflectionTextureResolution, renderTextureSizeLabels, renderTextureSizes);
                    profile.ReflectionDistortionStrength = EditorGUILayout.FloatField("Distortion", profile.ReflectionDistortionStrength);
                }
            });
            GUI.enabled = true;
        }
Exemplo n.º 24
0
        private void DrawFoamSettingsGUI()
        {
            string label = "Foam";
            string id    = "water-profile-foam";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                profile.EnableFoam = EditorGUILayout.Toggle("Enable", profile.EnableFoam);
                if (profile.EnableFoam)
                {
                    profile.EnableFoamHQ = EditorGUILayout.Toggle("High Quality", profile.EnableFoamHQ);
                    if (profile.EnableFoamHQ)
                    {
                        profile.FoamNoiseScaleHQ = EditorGUILayout.FloatField("Scale", profile.FoamNoiseScaleHQ);
                        profile.FoamNoiseSpeedHQ = EditorGUILayout.FloatField("Speed", profile.FoamNoiseSpeedHQ);
                    }
                    profile.FoamColor = EditorGUILayout.ColorField(new GUIContent("Color"), profile.FoamColor, true, true, true);

                    PEditorCommon.Header("Shoreline");
                    profile.FoamDistance          = EditorGUILayout.FloatField("Distance", profile.FoamDistance);
                    profile.ShorelineFoamStrength = EditorGUILayout.Slider("Strength", profile.ShorelineFoamStrength, 0f, 1f);

                    if (profile.EnableWave)
                    {
                        PEditorCommon.Header("Crest");
                        profile.CrestMaxDepth     = EditorGUILayout.FloatField("Max Depth", profile.CrestMaxDepth);
                        profile.CrestFoamStrength = EditorGUILayout.Slider("Strength", profile.CrestFoamStrength, 0f, 1f);
                    }

                    if (water.MeshType == PWaterMeshType.Spline)
                    {
                        PEditorCommon.Header("Slope");
                        profile.SlopeFoamDistance  = EditorGUILayout.FloatField("Distance", profile.SlopeFoamDistance);
                        profile.SlopeFoamFlowSpeed = EditorGUILayout.FloatField("Flow Speed", profile.SlopeFoamFlowSpeed);
                        profile.SlopeFoamStrength  = EditorGUILayout.Slider("Strength", profile.SlopeFoamStrength, 0f, 1f);
                    }
                }
            });
        }
Exemplo n.º 25
0
        private void DrawSelectedAnchorGUI()
        {
            int anchorIndex = splineEditingGUIDrawer.selectedAnchorIndex;

            if (anchorIndex < 0 ||
                anchorIndex >= water.Spline.Anchors.Count)
            {
                return;
            }
            string label = "Selected Anchor";
            string id    = "poseidon-selected-anchor";

            PEditorCommon.Foldout(label, true, id, () =>
            {
                EditorGUI.indentLevel -= 1;
                PSplineAnchor a        = water.Spline.Anchors[anchorIndex];
                EditorGUI.BeginChangeCheck();
                a.Position = PEditorCommon.InlineVector3Field("Position", a.Position);
                a.Rotation = Quaternion.Euler(PEditorCommon.InlineVector3Field("Rotation", a.Rotation.eulerAngles));
                a.Scale    = PEditorCommon.InlineVector3Field("Scale", a.Scale);
                water.Spline.Anchors[anchorIndex] = a;
                if (EditorGUI.EndChangeCheck())
                {
                    if (PSplineToolConfig.Instance.AutoTangent)
                    {
                        int[] segmentIndices = water.Spline.SmoothTangents(anchorIndex);
                        water.GenerateSplineMeshAtSegments(segmentIndices);
                    }
                    else
                    {
                        List <int> segmentIndices = water.Spline.FindSegments(anchorIndex);
                        water.GenerateSplineMeshAtSegments(segmentIndices);
                    }
                }
                EditorGUI.indentLevel += 1;
            });
        }
Exemplo n.º 26
0
        private void HandleAddRemoveTiles()
        {
            Plane plane    = new Plane(Vector3.up, water.transform.position);
            Ray   r        = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            float distance = -1;

            if (plane.Raycast(r, out distance))
            {
                Vector3  hitWorldPos = r.origin + r.direction * distance;
                Vector3  hitLocalPos = water.transform.InverseTransformPoint(hitWorldPos);
                PIndex2D index       = new PIndex2D(
                    Mathf.FloorToInt(hitLocalPos.x / water.TileSize.x),
                    Mathf.FloorToInt(hitLocalPos.z / water.TileSize.y));

                Vector3 rectCenter = water.transform.TransformPoint(new Vector3(
                                                                        (index.X + 0.5f) * water.TileSize.x,
                                                                        hitLocalPos.y,
                                                                        (index.Z + 0.5f) * water.TileSize.y));
                Vector3 rectSize = water.transform.TransformVector(new Vector3(
                                                                       water.TileSize.x,
                                                                       0,
                                                                       water.TileSize.y));

                if (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseUp)
                {
                    if (Event.current.button != 0)
                    {
                        return;
                    }
                    if (Event.current.control)
                    {
                        water.TileIndices.Remove(index);
                        water.ReCalculateBounds();
                    }
                    else if (Event.current.shift)
                    {
                        if (!water.TileIndices.Contains(index))
                        {
                            water.TileIndices.Add(index);
                            water.ReCalculateBounds();
                        }
                    }
                    PUtilities.MarkCurrentSceneDirty();
                    EditorUtility.SetDirty(water);
                }

                Handles.color = Handles.selectedColor;
                Handles.DrawWireCube(rectCenter, rectSize);

                string s = string.Format(
                    "{0}" +
                    "{1}" +
                    "{2}",
                    index.ToString(),
                    "\nShift+Click to pin, Ctrl+Click to unpin water planes.",
                    "\nClick End Editing Tiles when done.");

                GUIContent mouseMessage = new GUIContent(s);
                PEditorCommon.SceneViewMouseMessage(mouseMessage);
            }
        }
        private static void DrawWaterConfigGUI(PWater water)
        {
            DrawTemplateSelectionGUI(water);

            PWaterQuickSetupConfig config = PWaterQuickSetupConfig.Instance;
            bool changed     = false;
            bool meshChanged = false;

            EditorGUI.BeginChangeCheck();
            config.WaterLevel = EditorGUILayout.FloatField("Water Level", config.WaterLevel);
            if (EditorGUI.EndChangeCheck())
            {
                changed = true;
            }

            EditorGUI.BeginChangeCheck();
            config.MeshResolution = EditorGUILayout.DelayedIntField("Resolution", config.MeshResolution);
            if (EditorGUI.EndChangeCheck())
            {
                meshChanged = true;
            }

            EditorGUI.BeginChangeCheck();
            config.MeshNoise        = EditorGUILayout.FloatField("Noise", config.MeshNoise);
            config.ApproximateSizeX = EditorGUILayout.FloatField("Approx. Size X", config.ApproximateSizeX);
            config.ApproximateSizeZ = EditorGUILayout.FloatField("Approx. Size Z", config.ApproximateSizeZ);
            config.TileSize         = PEditorCommon.InlineVector2Field("Tile Size", config.TileSize);
            if (EditorGUI.EndChangeCheck())
            {
                changed = true;
            }

            if (meshChanged)
            {
                water.GeneratePlaneMesh();
            }

            if (changed || meshChanged)
            {
                water.MeshNoise = config.MeshNoise;
                water.TileSize  = config.TileSize;
                water.UpdateMaterial();
                MatchWaterLevel(water);
                MatchWaterSize(water);
            }

            EditorUtility.SetDirty(config);

            GEditorCommon.Separator();
            if (GUILayout.Button("Center To Level Bounds"))
            {
                CenterToLevel(water);
            }
            if (GUILayout.Button("Fill Level Bounds"))
            {
                Bounds levelBounds = GCommon.GetLevelBounds();
                config.ApproximateSizeX = levelBounds.size.x;
                config.ApproximateSizeZ = levelBounds.size.z;
                CenterToLevel(water);
                MatchWaterSize(water);
            }
            if (GUILayout.Button("Done"))
            {
                Done(water);
            }
        }
        private void DrawUnderwaterGUI()
        {
            string label = "Underwater";
            string id    = "underwater" + instance.GetInstanceID();

            PEditorCommon.Foldout(label, false, id, () =>
            {
                instance.EnableUnderwater = EditorGUILayout.Toggle("Enable", instance.EnableUnderwater);
                if (instance.EnableUnderwater)
                {
                    PEditorCommon.SpacePixel(0);
                    EditorGUILayout.LabelField("Water Body", PEditorCommon.BoldHeader);
                    instance.UnderwaterWaterLevel        = EditorGUILayout.FloatField("Water Level", instance.UnderwaterWaterLevel);
                    instance.UnderwaterMaxDepth          = EditorGUILayout.FloatField("Max Depth", instance.UnderwaterMaxDepth);
                    instance.UnderwaterSurfaceColorBoost = EditorGUILayout.Slider("Surface Color Boost", instance.UnderwaterSurfaceColorBoost, 1f, 3f);

                    PEditorCommon.SpacePixel(0);
                    EditorGUILayout.LabelField("Fog", PEditorCommon.BoldHeader);
                    instance.UnderwaterShallowFogColor = EditorGUILayout.ColorField("Shallow Fog Color", instance.UnderwaterShallowFogColor);
                    instance.UnderwaterDeepFogColor    = EditorGUILayout.ColorField("Deep Fog Color", instance.UnderwaterDeepFogColor);
                    instance.UnderwaterViewDistance    = EditorGUILayout.FloatField("View Distance", instance.UnderwaterViewDistance);

                    PEditorCommon.SpacePixel(0);
                    EditorGUILayout.LabelField("Caustic", PEditorCommon.BoldHeader);
                    instance.UnderwaterEnableCaustic = EditorGUILayout.Toggle("Enable", instance.UnderwaterEnableCaustic);
                    if (instance.UnderwaterEnableCaustic)
                    {
                        instance.UnderwaterCausticTexture  = PEditorCommon.InlineTextureField("Texture", instance.UnderwaterCausticTexture, -1);
                        instance.UnderwaterCausticSize     = EditorGUILayout.FloatField("Size", instance.UnderwaterCausticSize);
                        instance.UnderwaterCausticStrength = EditorGUILayout.Slider("Strength", instance.UnderwaterCausticStrength, 0f, 1f);
                    }

                    PEditorCommon.SpacePixel(0);
                    EditorGUILayout.LabelField("Distortion", PEditorCommon.BoldHeader);
                    instance.UnderwaterEnableDistortion = EditorGUILayout.Toggle("Enable", instance.UnderwaterEnableDistortion);
                    if (instance.UnderwaterEnableDistortion)
                    {
                        instance.UnderwaterDistortionTexture  = PEditorCommon.InlineTextureField("Normal Map", instance.UnderwaterDistortionTexture, -1);
                        instance.UnderwaterDistortionStrength = EditorGUILayout.FloatField("Strength", instance.UnderwaterDistortionStrength);
                        instance.UnderwaterWaterFlowSpeed     = EditorGUILayout.FloatField("Water Flow Speed", instance.UnderwaterWaterFlowSpeed);
                    }
                    PEditorCommon.Separator();
                }

                if (water != null && instance.EnableUnderwater)
                {
                    GUI.enabled = water.Profile != null;
                    if (GUILayout.Button("Inherit Parameters"))
                    {
                        instance.UnderwaterWaterLevel      = water.transform.position.y;
                        instance.UnderwaterMaxDepth        = water.Profile.MaxDepth;
                        instance.UnderwaterShallowFogColor = water.Profile.Color;
                        instance.UnderwaterDeepFogColor    = water.Profile.DepthColor;
                        instance.UnderwaterEnableCaustic   = water.Profile.EnableCaustic;
                        instance.UnderwaterCausticTexture  = water.Profile.CausticTexture;
                        instance.UnderwaterCausticSize     = water.Profile.CausticSize;
                        instance.UnderwaterCausticStrength = water.Profile.CausticStrength;
                    }
                    GUI.enabled = true;
                }
            });
        }