Exemple #1
0
        public static void SetKeywords(LowPolyWaterScript _target)
        {
            var mat = _target.material;

            if (mat == null || !mat.shader.name.Contains("LowPolyWater"))
            {
                return;
            }

            bool isCustom = _target.gridType == LowPolyWaterScript.GridType.Custom;

            if (isCustom)
            {
                mat.EnableKeyword("_CUSTOM_SHAPE");
                mat.DisableKeyword("_USE_LOD");
            }
            else if (_target.gridType == LowPolyWaterScript.GridType.HexagonalLOD)
            {
                mat.DisableKeyword("_CUSTOM_SHAPE");
                mat.EnableKeyword("_USE_LOD");
            }
            else
            {
                mat.DisableKeyword("_CUSTOM_SHAPE");
                mat.DisableKeyword("_USE_LOD");
            }

            if (_target.enableReflection)
            {
                mat.EnableKeyword("WATER_REFLECTIVE");
            }
            else
            {
                mat.DisableKeyword("WATER_REFLECTIVE");
            }

            if (_target.enableRefraction)
            {
                mat.EnableKeyword("WATER_REFRACTIVE");
            }
            else
            {
                mat.DisableKeyword("WATER_REFRACTIVE");
            }

            if (_target.receiveShadows && SystemInfo.graphicsShaderLevel >= 30)
            {
                mat.EnableKeyword("LPW_SHADOWS");
                mat.renderQueue = (int)RenderQueue.AlphaTest + 50;
                if (mat.HasProperty("_ZWrite"))
                {
                    mat.SetFloat("_ZWrite", 1);
                }
            }
            else
            {
                mat.DisableKeyword("LPW_SHADOWS");
                mat.renderQueue = (int)RenderQueue.AlphaTest + 51;
            }
        }
Exemple #2
0
        void OnEnable()
        {
            _target = (LowPolyWaterScript)target;
            //SetKeywords();

            if (_target.material != null)
            {
                // Create an instance of the default MaterialEditor
                _materialEditor = (MaterialEditor)CreateEditor(_target.material);
            }

            if (bannerTex == null)
            {
                bannerTex = Resources.Load <Texture2D>("banner");
            }

            if (rateTxt == null)
            {
                rateTxt = new GUIStyle();
                //rateTxt.alignment = TextAnchor.LowerCenter;
                rateTxt.alignment        = TextAnchor.LowerRight;
                rateTxt.normal.textColor = new Color(0.9f, 0.9f, 0.9f);
                rateTxt.fontSize         = 9;
                rateTxt.padding          = new RectOffset(0, 0, 0, 0);
            }

            if (title == null)
            {
                title = new GUIStyle(rateTxt);
                //title.alignment = TextAnchor.UpperCenter;
                title.normal.textColor = new Color(1f, 1f, 1f);
                title.alignment        = TextAnchor.MiddleCenter;
                title.fontSize         = 19;
                title.padding          = new RectOffset(0, 0, 0, 3);
            }

            linkStyle = new GUIStyle();

            LPWHiddenProps.Scale(_target);

            if (_target.material != null)
            {
                serializedObject.Update();
                serializedObject.ApplyModifiedProperties();

                if (_target.material.HasProperty("_EnableShadows"))
                {
                    _target.receiveShadows = _target.material.GetFloat("_EnableShadows") > .5f;
                }
                var oldRefl = _target.enableReflection;
                var oldRefr = _target.enableRefraction;
                _target.enableRefraction = _target.material.IsKeywordEnabled("WATER_REFRACTIVE");
                _target.enableReflection = _target.material.IsKeywordEnabled("WATER_REFLECTIVE");
                if (oldRefl != _target.enableReflection || oldRefr != _target.enableRefraction)
                {
                    _target.Generate();
                }
            }
            LPWHiddenProps.SetKeywords(_target);
        }
Exemple #3
0
        public static void Scale(LowPolyWaterScript _target)
        {
            // don't scale prefabs
            if (PrefabUtility.GetCorrespondingObjectFromSource(_target) == null && PrefabUtility.GetPrefabObject(_target) != null)
            {
                return;
            }
            if (_target.material == null || !_target.material.HasProperty("_TransformScale_"))
            {
                return;
            }

            // scale everything when scaling transform's localscale
            var   locScale = _target.transform.localScale;
            var   scale    = _target.material.GetFloat("_TransformScale_");
            float newScale = 1;

            if (_target.gridType != LowPolyWaterScript.GridType.Custom)
            {
                newScale = Mathf.Min(locScale.x, locScale.z);
                if (!Mathf.Approximately(scale, newScale))
                {
                    _target.material.SetFloat("_TransformScale_", newScale);
                    Calculate(_target.material);
                }
            }
        }
Exemple #4
0
        public static void Scale(LowPolyWaterScript _target)
        {
            // don't scale prefabs
#pragma warning disable CS0618 // Le type ou le membre est obsolète
            if (PrefabUtility.GetPrefabParent(_target) == null && PrefabUtility.GetPrefabObject(_target) != null)
            {
                return;
            }
#pragma warning restore CS0618 // Le type ou le membre est obsolète
            if (_target.material == null || !_target.material.HasProperty("_TransformScale_"))
            {
                return;
            }

            // scale everything when scaling transform's localscale
            var   locScale = _target.transform.localScale;
            var   scale    = _target.material.GetFloat("_TransformScale_");
            float newScale = 1;
            if (_target.gridType != LowPolyWaterScript.GridType.Custom)
            {
                newScale = Mathf.Min(locScale.x, locScale.z);
                if (!Mathf.Approximately(scale, newScale))
                {
                    _target.material.SetFloat("_TransformScale_", newScale);
                    Calculate(_target.material);
                }
            }
        }