Esempio n. 1
0
        public int CostlyUpdate(WaveParticlesQuadtree quadtree, float deltaTime)
        {
            float num;

            if (this.Frequency < 0.025f)
            {
                float x = this._Position.x + this.Direction.x / this.Frequency;
                float z = this._Position.y + this.Direction.y / this.Frequency;
                num = Mathf.Max(StaticWaterInteraction.GetTotalDepthAt(this._Position.x, this._Position.y), StaticWaterInteraction.GetTotalDepthAt(x, z));
            }
            else
            {
                num = StaticWaterInteraction.GetTotalDepthAt(this._Position.x, this._Position.y);
            }
            if (num <= 0.001f)
            {
                this.Destroy();
                return(0);
            }
            this.UpdateWaveParameters(deltaTime, num);
            int result = 0;

            if (quadtree != null && !this.DisallowSubdivision)
            {
                if (this.LeftNeighbour != null)
                {
                    this.Subdivide(quadtree, this.LeftNeighbour, this, ref result);
                }
                if (this.RightNeighbour != null)
                {
                    this.Subdivide(quadtree, this, this.RightNeighbour, ref result);
                }
            }
            return(result);
        }
        private void CreateShoalingSpawnPoints()
        {
            Bounds bounds = new Bounds(base.transform.position, new Vector3(this._BoundsSize.x, 0f, this._BoundsSize.y));
            float  x      = bounds.min.x;
            float  z      = bounds.min.z;
            float  x2     = bounds.max.x;
            float  z2     = bounds.max.z;
            float  num    = Mathf.Sqrt(this._SpawnPointsDensity);
            float  num2   = Mathf.Max(35f, bounds.size.x / 256f) / num;
            float  num3   = Mathf.Max(35f, bounds.size.z / 256f) / num;

            bool[,] array = new bool[32, 32];
            List <ComplexWavesEmitter.SpawnPoint> list = new List <ComplexWavesEmitter.SpawnPoint>();

            GerstnerWave[] array2 = this._WindWaves.SpectrumResolver.SelectShorelineWaves(50, 0f, 360f);
            if (array2.Length == 0)
            {
                this._SpawnPoints = new ComplexWavesEmitter.SpawnPoint[0];
                return;
            }
            float num4 = this._SpawnDepth * 0.85f;
            float num5 = this._SpawnDepth * 1.18f;

            for (float num6 = z; num6 < z2; num6 += num3)
            {
                for (float num7 = x; num7 < x2; num7 += num2)
                {
                    int num8 = Mathf.FloorToInt(32f * (num7 - x) / (x2 - x));
                    int num9 = Mathf.FloorToInt(32f * (num6 - z) / (z2 - z));
                    if (!array[num8, num9])
                    {
                        float totalDepthAt = StaticWaterInteraction.GetTotalDepthAt(num7, num6);
                        if (totalDepthAt > num4 && totalDepthAt < num5 && UnityEngine.Random.value < 0.06f)
                        {
                            array[num8, num9] = true;
                            Vector2 vector;
                            vector.x = StaticWaterInteraction.GetTotalDepthAt(num7 - 3f, num6) - StaticWaterInteraction.GetTotalDepthAt(num7 + 3f, num6);
                            vector.y = StaticWaterInteraction.GetTotalDepthAt(num7, num6 - 3f) - StaticWaterInteraction.GetTotalDepthAt(num7, num6 + 3f);
                            vector.Normalize();
                            GerstnerWave gerstnerWave = array2[0];
                            float        num10        = Vector2.Dot(vector, array2[0].Direction);
                            for (int i = 1; i < array2.Length; i++)
                            {
                                float num11 = Vector2.Dot(vector, array2[i].Direction);
                                if (num11 > num10)
                                {
                                    num10        = num11;
                                    gerstnerWave = array2[i];
                                }
                            }
                            list.Add(new ComplexWavesEmitter.SpawnPoint(new Vector2(num7, num6), vector, gerstnerWave.Frequency, Mathf.Abs(gerstnerWave.Amplitude), gerstnerWave.Speed));
                        }
                    }
                }
            }
            this._SpawnPoints = list.ToArray();
        }
        public static StaticWaterInteraction AttachTo(GameObject target, float shoreSmoothness, bool hasBottomFaces, StaticWaterInteraction.UnderwaterAreasMode underwaterAreasMode, int mapResolution, float waveDampingThreshold = 4f, float depthScale = 1f)
        {
            StaticWaterInteraction staticWaterInteraction = target.AddComponent <StaticWaterInteraction>();

            staticWaterInteraction._ShoreSmoothness      = shoreSmoothness;
            staticWaterInteraction._HasBottomFaces       = hasBottomFaces;
            staticWaterInteraction._UnderwaterAreasMode  = underwaterAreasMode;
            staticWaterInteraction._MapResolution        = mapResolution;
            staticWaterInteraction._WaveDampingThreshold = waveDampingThreshold;
            staticWaterInteraction._DepthScale           = depthScale;
            return(staticWaterInteraction);
        }
        private void PrepareRenderers()
        {
            bool flag = false;

            this._Bounds = default(Bounds);
            List <GameObject> list = new List <GameObject>();

            Renderer[] componentsInChildren = base.GetComponentsInChildren <Renderer>(false);
            for (int i = 0; i < componentsInChildren.Length; i++)
            {
                if (!(componentsInChildren[i].name == "Shoreline Mask"))
                {
                    StaticWaterInteraction component = componentsInChildren[i].GetComponent <StaticWaterInteraction>();
                    if (component == null || component == this)
                    {
                        list.Add(componentsInChildren[i].gameObject);
                        if (flag)
                        {
                            this._Bounds.Encapsulate(componentsInChildren[i].bounds);
                        }
                        else
                        {
                            this._Bounds = componentsInChildren[i].bounds;
                            flag         = true;
                        }
                    }
                }
            }
            this._Terrains = base.GetComponentsInChildren <Terrain>(false);
            this._OriginalTerrainPixelErrors = new float[this._Terrains.Length];
            this._OriginalDrawTrees          = new bool[this._Terrains.Length];
            for (int j = 0; j < this._Terrains.Length; j++)
            {
                this._OriginalTerrainPixelErrors[j] = this._Terrains[j].heightmapPixelError;
                this._OriginalDrawTrees[j]          = this._Terrains[j].drawTreesAndFoliage;
                StaticWaterInteraction component2 = this._Terrains[j].GetComponent <StaticWaterInteraction>();
                if (component2 == null || component2 == this)
                {
                    list.Add(this._Terrains[j].gameObject);
                    this._Terrains[j].heightmapPixelError = 1f;
                    this._Terrains[j].drawTreesAndFoliage = false;
                    if (flag)
                    {
                        this._Bounds.Encapsulate(this._Terrains[j].transform.position);
                        this._Bounds.Encapsulate(this._Terrains[j].transform.position + this._Terrains[j].terrainData.size);
                    }
                    else
                    {
                        this._Bounds = new Bounds(this._Terrains[j].transform.position + this._Terrains[j].terrainData.size * 0.5f, this._Terrains[j].terrainData.size);
                        flag         = true;
                    }
                }
            }
            this._GameObjects            = list.ToArray();
            this._OriginalRendererLayers = new int[this._GameObjects.Length];
            for (int k = 0; k < this._GameObjects.Length; k++)
            {
                this._OriginalRendererLayers[k] = this._GameObjects[k].layer;
                this._GameObjects[k].layer      = WaterProjectSettings.Instance.WaterTempLayer;
            }
        }
 private void RenderShorelineIntensityMask()
 {
     try
     {
         this.PrepareRenderers();
         float num = 1f / this._ShoreSmoothness;
         this._TotalBounds = this._Bounds;
         if (this._UnderwaterAreasMode == StaticWaterInteraction.UnderwaterAreasMode.Generate)
         {
             float num2 = 80f / num;
             this._TotalBounds.Expand(new Vector3(num2, 0f, num2));
         }
         float         y             = base.transform.position.y;
         RenderTexture renderTexture = this.RenderHeightMap(this._MapResolution, this._MapResolution);
         RenderTexture intensityMask = this.IntensityMask;
         this._OffsetX = -this._TotalBounds.min.x;
         this._OffsetZ = -this._TotalBounds.min.z;
         this._ScaleX  = (float)this._MapResolution / this._TotalBounds.size.x;
         this._ScaleZ  = (float)this._MapResolution / this._TotalBounds.size.z;
         this._Width   = this._MapResolution;
         this._Height  = this._MapResolution;
         RenderTexture temporary  = RenderTexture.GetTemporary(this._MapResolution, this._MapResolution, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
         RenderTexture temporary2 = RenderTexture.GetTemporary(this._MapResolution, this._MapResolution, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
         Material      material   = new Material(this._MaskGenerateShader);
         material.SetVector("_ShorelineExtendRange", new Vector2(this._TotalBounds.size.x / this._Bounds.size.x - 1f, this._TotalBounds.size.z / this._Bounds.size.z - 1f));
         material.SetFloat("_TerrainMinPoint", y);
         material.SetFloat("_Steepness", Mathf.Max(this._TotalBounds.size.x, this._TotalBounds.size.z) * num);
         material.SetFloat("_Offset1", 1f / (float)this._MapResolution);
         material.SetFloat("_Offset2", 1.41421354f / (float)this._MapResolution);
         RenderTexture renderTexture2 = null;
         if (this._UnderwaterAreasMode == StaticWaterInteraction.UnderwaterAreasMode.Generate)
         {
             RenderTexture temporary3 = RenderTexture.GetTemporary(this._MapResolution, this._MapResolution, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
             renderTexture2 = RenderTexture.GetTemporary(this._MapResolution, this._MapResolution, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
             Graphics.Blit(renderTexture, temporary3, material, 2);
             StaticWaterInteraction.ComputeDistanceMap(material, temporary3, renderTexture2);
             RenderTexture.ReleaseTemporary(temporary3);
             renderTexture2.filterMode = FilterMode.Bilinear;
             material.SetTexture("_DistanceMap", renderTexture2);
             material.SetFloat("_GenerateUnderwaterAreas", 1f);
         }
         else
         {
             material.SetFloat("_GenerateUnderwaterAreas", 0f);
         }
         material.SetFloat("_DepthScale", this._DepthScale);
         Graphics.Blit(renderTexture, temporary, material, 0);
         RenderTexture.ReleaseTemporary(renderTexture);
         if (renderTexture2 != null)
         {
             RenderTexture.ReleaseTemporary(renderTexture2);
         }
         Graphics.Blit(temporary, temporary2);
         this.ReadBackHeightMap(temporary);
         Graphics.Blit(temporary, intensityMask, material, 1);
         RenderTexture.ReleaseTemporary(temporary2);
         RenderTexture.ReleaseTemporary(temporary);
         UnityEngine.Object.Destroy(material);
     }
     finally
     {
         this.RestoreRenderers();
     }
 }