Beispiel #1
0
        private void PrecomputeSamples()
        {
            List <Vector3> list      = new List <Vector3>();
            float          num       = 0.5f;
            float          num2      = 1f;
            int            num3      = this._SampleCount * 18;
            Transform      transform = base.transform;
            Vector3        vector;
            Vector3        vector2;

            ColliderExtensions.GetLocalMinMax(this._LocalCollider, out vector, out vector2);
            int num4 = 0;

            while (num4 < 4 && list.Count < num3)
            {
                for (float num5 = num; num5 <= 1f; num5 += num2)
                {
                    for (float num6 = num; num6 <= 1f; num6 += num2)
                    {
                        for (float num7 = num; num7 <= 1f; num7 += num2)
                        {
                            Vector3 vector3 = new Vector3(Mathf.Lerp(vector.x, vector2.x, num5), Mathf.Lerp(vector.y, vector2.y, num6), Mathf.Lerp(vector.z, vector2.z, num7));
                            if (this._LocalCollider.IsPointInside(transform.TransformPoint(vector3)))
                            {
                                list.Add(vector3);
                            }
                        }
                    }
                }
                num2 = num;
                num *= 0.5f;
                num4++;
            }
            this._CachedSamplePositions = list.ToArray();
            this._CachedSampleCount     = this._CachedSamplePositions.Length;
            WaterPhysics.Shuffle <Vector3>(this._CachedSamplePositions);
        }
Beispiel #2
0
        private void ImprovedFixedUpdate()
        {
            Water affectingWater = this.AffectingWater;

            if (affectingWater == null || this._RigidBody.isKinematic)
            {
                return;
            }
            float     time               = affectingWater.Time;
            float     improvedDragPart   = this._ImprovedDragPart;
            Matrix4x4 localToWorldMatrix = base.transform.localToWorldMatrix;
            Vector4   row    = localToWorldMatrix.GetRow(1);
            Vector3   center = this._LocalCollider.bounds.center;

            this._AverageWaterElevation = 0f;
            int num = 0;

            for (int i = 0; i < this._DragNormals.Length; i++)
            {
                Vector3 vector        = localToWorldMatrix.MultiplyPoint3x4(this._DragCenters[i]);
                Vector3 pointVelocity = this._RigidBody.GetPointVelocity(vector);
                Vector3 vector2       = localToWorldMatrix.MultiplyVector(this._DragNormals[i]);
                float   num2;
                Vector3 lhs;
                this._ImprovedDragSamples[i].GetAndResetFast(vector.x, vector.z, time, out num2, out lhs);
                this._AverageWaterElevation += num2;
                float num3 = Vector3.Dot(vector2, pointVelocity);
                float num4 = Vector3.Dot(lhs, vector2) * this._ImprovedFlowPart;
                float num11;
                if (num3 > 0f || num4 > 0f)
                {
                    float num5  = WaterPhysics.SingleComponentTransform(ref this._DragVertices[num++], ref row);
                    float num6  = WaterPhysics.SingleComponentTransform(ref this._DragVertices[num++], ref row);
                    float num7  = WaterPhysics.SingleComponentTransform(ref this._DragVertices[num++], ref row);
                    float num8  = num2 - num5;
                    float num9  = num2 - num6;
                    float num10 = num2 - num7;
                    if (num8 > 0f)
                    {
                        if (num9 > 0f)
                        {
                            num11 = ((num10 < 0f) ? ((num8 + num9) / (num8 + num9 - num10)) : 1f);
                        }
                        else
                        {
                            num11 = ((num10 < 0f) ? (num8 / (num8 - num9 - num10)) : ((num8 + num10) / (num8 - num9 + num10)));
                        }
                    }
                    else if (num9 > 0f)
                    {
                        num11 = ((num10 < 0f) ? (num9 / (num9 - num10 - num8)) : ((num9 + num10) / (num9 + num10 - num8)));
                    }
                    else
                    {
                        num11 = ((num10 < 0f) ? 0f : (num10 / (num10 - num8 - num9)));
                    }
                    if (num11 <= 0f || num11 > 1.02f)
                    {
                        num11 = 0f;
                    }
                }
                else
                {
                    num11 = 0f;
                    num  += 3;
                }
                float num12     = this._DragAreas[i] * num11;
                float num13     = (num3 <= 0f) ? 0f : (improvedDragPart * num3 * num3 * num12);
                float magnitude = pointVelocity.magnitude;
                num13 = ((magnitude == 0f) ? 0f : (num13 / magnitude));
                Vector3 force = pointVelocity * num13;
                if (center.y > vector.y)
                {
                    if (num2 > center.y)
                    {
                        num11    = this._PolygonVolumes[i];
                        force.x += this._ImprovedBuoyancyPart.x * num11;
                        force.y += this._ImprovedBuoyancyPart.y * num11;
                        force.z += this._ImprovedBuoyancyPart.z * num11;
                    }
                    else if (num2 > vector.y)
                    {
                        num11    = this._PolygonVolumes[i] * (num2 - vector.y) / (center.y - vector.y);
                        force.x += this._ImprovedBuoyancyPart.x * num11;
                        force.y += this._ImprovedBuoyancyPart.y * num11;
                        force.z += this._ImprovedBuoyancyPart.z * num11;
                    }
                }
                else if (num2 > vector.y)
                {
                    num11    = this._PolygonVolumes[i];
                    force.x += this._ImprovedBuoyancyPart.x * num11;
                    force.y += this._ImprovedBuoyancyPart.y * num11;
                    force.z += this._ImprovedBuoyancyPart.z * num11;
                }
                else if (num2 > center.y)
                {
                    num11    = this._PolygonVolumes[i] * (num2 - center.y) / (vector.y - center.y);
                    force.x += this._ImprovedBuoyancyPart.x * num11;
                    force.y += this._ImprovedBuoyancyPart.y * num11;
                    force.z += this._ImprovedBuoyancyPart.z * num11;
                }
                if (num4 > 0f)
                {
                    magnitude = lhs.magnitude;
                    float num14 = (magnitude == 0f) ? 0f : (num4 * num12 / magnitude);
                    force.x += lhs.x * num14;
                    force.y += lhs.y * num14;
                    force.z += lhs.z * num14;
                }
                this._RigidBody.AddForceAtPosition(force, vector, ForceMode.Force);
            }
            this._AverageWaterElevation /= (float)this._DragNormals.Length;
        }