Ejemplo n.º 1
0
        private void AddFoam()
        {
            if (this.duration <= 0f || Ocean.Instance == null)
            {
                this.m_lastPosition = base.transform.position;
                return;
            }
            this.spacing = Mathf.Max(1f, this.spacing);
            this.size    = Mathf.Max(1f, this.size);
            Vector3 position = base.transform.position;
            float   num      = position.y;

            if (this.mustBeBelowWater)
            {
                num = Ocean.Instance.QueryWaves(position.x, position.z);
            }
            if (num < position.y)
            {
                this.m_lastPosition = position;
                return;
            }
            position.y            = 0f;
            this.m_lastPosition.y = 0f;
            Vector3 vector     = this.m_lastPosition - position;
            Vector3 normalized = vector.normalized;
            float   num2       = vector.magnitude;

            if (num2 < this.MIN_MOVEMENT)
            {
                return;
            }
            num2 = Mathf.Min(this.MAX_MOVEMENT, num2);
            Vector3 vector2 = normalized * this.momentum;

            this.m_remainingDistance += num2;
            float num3 = 0f;

            while (this.m_remainingDistance > this.spacing)
            {
                Vector3     pos         = position + normalized * num3;
                FoamOverlay foamOverlay = this.NewFoamOverlay(pos, this.Rotation(), this.size, this.duration, this.foamTexture);
                foamOverlay.FoamTex.alpha       = 0f;
                foamOverlay.FoamTex.textureFoam = this.textureFoam;
                foamOverlay.Momentum            = vector2;
                foamOverlay.Spin      = ((UnityEngine.Random.value <= 0.5f) ? this.spin : (-this.spin));
                foamOverlay.Expansion = this.expansion;
                if (this.jitter > 0f)
                {
                    foamOverlay.Spin      *= 1f + UnityEngine.Random.Range(-1f, 1f) * this.jitter;
                    foamOverlay.Expansion *= 1f + UnityEngine.Random.Range(-1f, 1f) * this.jitter;
                }
                this.m_overlays.Add(foamOverlay);
                Ocean.Instance.OverlayManager.Add(foamOverlay);
                this.m_remainingDistance -= this.spacing;
                num3 += this.spacing;
            }
            this.m_lastPosition = position;
        }
Ejemplo n.º 2
0
        private void AddFoam()
        {
            if (this.duration <= 0f || Ocean.Instance == null)
            {
                this.m_lastTime = Time.time;
                return;
            }
            this.size = Mathf.Max(1f, this.size);
            float   num      = base.transform.position.y;
            Vector3 position = base.transform.position;
            Vector3 a        = base.transform.forward;

            if (this.mustBeBelowWater)
            {
                num = Ocean.Instance.QueryWaves(position.x, position.z);
            }
            if (num < position.y || (a.x == 0f && a.z == 0f))
            {
                this.m_lastTime = Time.time;
                return;
            }
            float num2 = Time.time - this.m_lastTime;

            a          = a.normalized;
            position.y = 0f;
            Vector3 vector = a * this.momentum;

            this.m_remainingTime += num2;
            float num3 = this.rate / 1000f;
            float num4 = 0f;

            while (this.m_remainingTime > num3)
            {
                Vector3     pos         = position + a * num4;
                FoamOverlay foamOverlay = this.NewFoamOverlay(pos, this.Rotation(), this.size, this.duration, this.foamTexture);
                foamOverlay.FoamTex.alpha       = 0f;
                foamOverlay.FoamTex.textureFoam = this.textureFoam;
                foamOverlay.Momentum            = vector;
                foamOverlay.Spin      = ((UnityEngine.Random.value <= 0.5f) ? this.spin : (-this.spin));
                foamOverlay.Expansion = this.expansion;
                if (this.jitter > 0f)
                {
                    foamOverlay.Spin      *= 1f + UnityEngine.Random.Range(-1f, 1f) * this.jitter;
                    foamOverlay.Expansion *= 1f + UnityEngine.Random.Range(-1f, 1f) * this.jitter;
                }
                this.m_overlays.Add(foamOverlay);
                Ocean.Instance.OverlayManager.Add(foamOverlay);
                this.m_remainingTime -= num3;
                num4 += num3;
            }
            this.m_lastTime = Time.time;
        }
Ejemplo n.º 3
0
        private FoamOverlay NewFoamOverlay(Vector3 pos, float rotation, float size, float duration, Texture texture)
        {
            FoamOverlay foamOverlay;

            if (this.m_pool.Count > 0)
            {
                foamOverlay = this.m_pool.First.Value;
                foamOverlay.Reset(pos, this.Rotation(), size, duration, this.foamTexture);
                this.m_pool.RemoveFirst();
            }
            else
            {
                foamOverlay = new FoamOverlay(pos, this.Rotation(), size, duration, this.foamTexture);
            }
            return(foamOverlay);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returans a new FoamOverlay object. Will take from the pool
        /// if not empty and reset to new values. If pool empty it will
        /// create a new object. Used to reduce memory allocations.
        /// </summary>
        FoamOverlay NewFoamOverlay(Vector3 pos, float rotation, float size, float duration, Texture texture)
        {
            FoamOverlay overlay = null;

            if (m_pool.Count > 0)
            {
                overlay = m_pool.First.Value;
                overlay.Reset(pos, Rotation(), size, duration, foamTexture);
                m_pool.RemoveFirst();
            }
            else
            {
                overlay = new FoamOverlay(pos, Rotation(), size, duration, foamTexture);
            }

            return(overlay);
        }
Ejemplo n.º 5
0
 private void RemoveOverlays()
 {
     this.m_remove.Clear();
     for (int i = 0; i < this.m_overlays.Count; i++)
     {
         FoamOverlay foamOverlay = this.m_overlays[i] as FoamOverlay;
         if (foamOverlay.Age >= foamOverlay.Duration)
         {
             this.m_remove.Add(foamOverlay);
             foamOverlay.Kill = true;
         }
     }
     for (int j = 0; j < this.m_remove.Count; j++)
     {
         this.m_overlays.Remove(this.m_remove[j]);
         this.m_pool.AddLast(this.m_remove[j]);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Remove any overlays that have a age longer that there duration.
        /// </summary>
        void RemoveOverlays()
        {
            m_remove.Clear();

            for (int i = 0; i < m_overlays.Count; i++)
            {
                FoamOverlay overlay = m_overlays[i] as FoamOverlay;

                if (overlay.Age >= overlay.Duration)
                {
                    m_remove.Add(overlay);
                    //Set kill to true to remove from oceans overlay manager.
                    overlay.Kill = true;
                }
            }

            for (int i = 0; i < m_remove.Count; i++)
            {
                m_overlays.Remove(m_remove[i]);
                m_pool.AddLast(m_remove[i]);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates new overlays based on the movement from the last position.
        /// </summary>
        void AddFoam()
        {
            //If there is no ocean in scene or if the overlays
            //duration is less than 0 dont do anything
            if (duration <= 0.0f || Ocean.Instance == null)
            {
                m_lastTime = Time.time;
                return;
            }

            //Clamp size.
            size = Mathf.Max(1.0f, size);

            float h = transform.position.y;
            Vector3 pos = transform.position;
            Vector3 dir = transform.forward;

            //If the overlays are only to be added if the position
            //is below the water line get the wave height.
            if (mustBeBelowWater)
                h = Ocean.Instance.QueryWaves(pos.x, pos.z);

            //If the waves are below the position do nothing.
            //If the forward dir is straight up or down do nothing.
            if (h < pos.y || (dir.x == 0.0f && dir.z == 0.0f))
            {
                m_lastTime = Time.time;
                return;
            }

            float delta = Time.time - m_lastTime;
            dir = dir.normalized;
            pos.y = 0.0f;

            Vector3 momentumDir = dir * momentum;

            m_remainingTime += delta;

            //rate in seconds
            float r = rate / 1000.0f;

            float d = 0.0f;
            while (m_remainingTime > r)
            {
                //Find the next overlay pos.
                Vector3 overlayPos = pos + dir * d;

                //Create a new overlay and set is starting values.
                FoamOverlay overlay = new FoamOverlay(overlayPos, Rotation(), size, duration, foamTexture);

                overlay.FoamTex.alpha = 0.0f;
                overlay.FoamTex.textureFoam = textureFoam;
                overlay.Momentum = momentumDir;
                overlay.Spin = (Random.value > 0.5f) ? -spin : spin;
                overlay.Expansion = expansion;

                if (jitter > 0.0f)
                {
                    overlay.Spin *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                    overlay.Expansion *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                }

                //Add to list and add to ocean overlay manager.
                //The overlay manager will render the overlay into the buffer.
                m_overlays.Add(overlay);
                Ocean.Instance.OverlayManager.Add(overlay);

                //Decrement remaining distance by the rate.
                m_remainingTime -= r;
                d += r;
            }

            m_lastTime = Time.time;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates new overlays based on the movement from the last position.
        /// </summary>
        void AddFoam()
        {
            //If there is no ocean in scene or if the overlays
            //duration is less than 0 dont do anything
            if (duration <= 0.0f || Ocean.Instance == null)
            {
                m_lastPosition = transform.position;
                return;
            }

            //Clamp spacing and size to 1.
            spacing = Mathf.Max(1.0f, spacing);
            size    = Mathf.Max(1.0f, size);

            Vector3 pos = transform.position;
            float   h   = pos.y;

            //If the overlays are only to be added if the position
            //is below the water line get the wave height.
            if (mustBeBelowWater)
            {
                h = Ocean.Instance.QueryWaves(pos.x, pos.z);
            }

            //If the waves are below the position do nothing.
            if (h < pos.y)
            {
                m_lastPosition = pos;
                return;
            }

            //From here on the position is presumed to be on a flat plane.
            pos.y            = 0.0f;
            m_lastPosition.y = 0.0f;

            //Find the distance travel and the direction
            Vector3 distance  = m_lastPosition - pos;
            Vector3 direction = distance.normalized;
            float   length    = distance.magnitude;

            //Only start adding new overlays if there has
            //been a minimum amount of movement.
            if (length < MIN_MOVEMENT)
            {
                return;
            }

            length = Mathf.Min(MAX_MOVEMENT, length);

            Vector3 momentumDir = direction * momentum;

            //Append the amount move to remaining
            //distance from last frame
            m_remainingDistance += length;

            float d = 0.0f;

            while (m_remainingDistance > spacing)
            {
                //Find the next overlay pos.
                Vector3 overlayPos = pos + direction * d;

                //Create a new overlay and set is starting values.
                FoamOverlay overlay = NewFoamOverlay(overlayPos, Rotation(), size, duration, foamTexture);

                overlay.FoamTex.alpha       = 0.0f;
                overlay.FoamTex.textureFoam = textureFoam;
                overlay.Momentum            = momentumDir;
                overlay.Spin      = (Random.value > 0.5f) ? -spin : spin;
                overlay.Expansion = expansion;

                if (jitter > 0.0f)
                {
                    overlay.Spin      *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                    overlay.Expansion *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                }

                //Add to list and add to ocean overlay manager.
                //The overlay manager will render the overlay into the buffer.
                m_overlays.Add(overlay);
                Ocean.Instance.OverlayManager.Add(overlay);

                //Decrement remaining distance by the spacing.
                m_remainingDistance -= spacing;
                d += spacing;
            }

            m_lastPosition = pos;
        }
Ejemplo n.º 9
0
 private FoamOverlay NewFoamOverlay(Vector3 pos, float rotation, float size, float duration, Texture texture)
 {
     FoamOverlay foamOverlay;
     if (this.m_pool.Count > 0)
     {
         foamOverlay = this.m_pool.First.Value;
         foamOverlay.Reset(pos, this.Rotation(), size, duration, this.foamTexture);
         this.m_pool.RemoveFirst();
     }
     else
     {
         foamOverlay = new FoamOverlay(pos, this.Rotation(), size, duration, this.foamTexture);
     }
     return foamOverlay;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates new overlays based on the movement from the last position.
        /// </summary>
        void AddFoam()
        {
            //If there is no ocean in scene or if the overlays
            //duration is less than 0 dont do anything
            if (duration <= 0.0f || Ocean.Instance == null)
            {
                m_lastTime = Time.time;
                return;
            }

            //Clamp size.
            size = Mathf.Max(1.0f, size);

            float   h   = transform.position.y;
            Vector3 pos = transform.position;
            Vector3 dir = transform.forward;

            //If the overlays are only to be added if the position
            //is below the water line get the wave height.
            if (mustBeBelowWater)
            {
                h = Ocean.Instance.QueryWaves(pos.x, pos.z);
            }

            //If the waves are below the position do nothing.
            //If the forward dir is straight up or down do nothing.
            if (h < pos.y || (dir.x == 0.0f && dir.z == 0.0f))
            {
                m_lastTime = Time.time;
                return;
            }

            float delta = Time.time - m_lastTime;

            dir   = dir.normalized;
            pos.y = 0.0f;

            Vector3 momentumDir = dir * momentum;

            m_remainingTime += delta;

            //rate in seconds
            float r = rate / 1000.0f;

            float d = 0.0f;

            while (m_remainingTime > r)
            {
                //Find the next overlay pos.
                Vector3 overlayPos = pos + dir * d;

                //Create a new overlay and set is starting values.
                FoamOverlay overlay = NewFoamOverlay(overlayPos, Rotation(), size, duration, foamTexture);

                overlay.FoamTex.alpha       = 0.0f;
                overlay.FoamTex.textureFoam = textureFoam;
                overlay.Momentum            = momentumDir;
                overlay.Spin      = (Random.value > 0.5f) ? -spin : spin;
                overlay.Expansion = expansion;

                if (jitter > 0.0f)
                {
                    overlay.Spin      *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                    overlay.Expansion *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                }

                //Add to list and add to ocean overlay manager.
                //The overlay manager will render the overlay into the buffer.
                m_overlays.Add(overlay);
                Ocean.Instance.OverlayManager.Add(overlay);

                //Decrement remaining distance by the rate.
                m_remainingTime -= r;
                d += r;
            }

            m_lastTime = Time.time;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates new overlays based on the movement from the last position.
        /// </summary>
        void AddFoam()
        {
            //If there is no ocean in scene or if the overlays
            //duration is less than 0 dont do anything
            if (duration <= 0.0f || Ocean.Instance == null)
            {
                m_lastPosition = transform.position;
                return;
            }

            //Clamp spacing and size to 1.
            spacing = Mathf.Max(1.0f, spacing);
            size = Mathf.Max(1.0f, size);

            Vector3 pos = transform.position;
            float h = pos.y;

            //If the overlays are only to be added if the position
            //is below the water line get the wave height.
            if(mustBeBelowWater)
                h = Ocean.Instance.QueryWaves(pos.x, pos.z);

            //If the waves are below the position do nothing.
            if (h < pos.y)
            {
                m_lastPosition = pos;
                return;
            }

            //From here on the position is presumed to be on a flat plane.
            pos.y = 0.0f;
            m_lastPosition.y = 0.0f;

            //Find the distance travel and the direction
            Vector3 distance = m_lastPosition - pos;
            Vector3 direction = distance.normalized;
            float length = distance.magnitude;

            //Only start adding new overlays if there has
            //been a minimum amount of movement.
            if(length < MIN_MOVEMENT) return;

            length = Mathf.Min(MAX_MOVEMENT, length);

            Vector3 momentumDir = direction * momentum;

            //Append the amount move to remaining
            //distance from last frame
            m_remainingDistance += length;

            float d = 0.0f;
            while(m_remainingDistance > spacing)
            {
                //Find the next overlay pos.
                Vector3 overlayPos = pos + direction * d;

                //Create a new overlay and set is starting values.
                FoamOverlay overlay = new FoamOverlay(overlayPos, Rotation(), size, duration, foamTexture);

                overlay.FoamTex.alpha = 0.0f;
                overlay.FoamTex.textureFoam = textureFoam;
                overlay.Momentum = momentumDir;
                overlay.Spin = (Random.value > 0.5f) ? -spin : spin;
                overlay.Expansion = expansion;

                if (jitter > 0.0f)
                {
                    overlay.Spin *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                    overlay.Expansion *= 1.0f + Random.Range(-1.0f, 1.0f) * jitter;
                }

                //Add to list and add to ocean overlay manager.
                //The overlay manager will render the overlay into the buffer.
                m_overlays.Add(overlay);
                Ocean.Instance.OverlayManager.Add(overlay);

                //Decrement remaining distance by the spacing.
                m_remainingDistance -= spacing;
                d += spacing;
            }

            m_lastPosition = pos;
        }