Exemple #1
0
    public void BuoyancyFixedUpdate()
    {
        if (TerrainMeta.WaterMap == null)
        {
            return;
        }
        EnsurePointsInitialized();
        if (rigidBody == null)
        {
            return;
        }
        if (buoyancyScale == 0f)
        {
            Invoke(Sleep, 0f);
            return;
        }
        float     time = Time.time;
        float     x    = TerrainMeta.Position.x;
        float     z    = TerrainMeta.Position.z;
        float     x2   = TerrainMeta.OneOverSize.x;
        float     z2   = TerrainMeta.OneOverSize.z;
        Matrix4x4 localToWorldMatrix = base.transform.localToWorldMatrix;

        for (int i = 0; i < pointData.Length; i++)
        {
            BuoyancyPoint buoyancyPoint2 = points[i];
            Vector3       position       = localToWorldMatrix.MultiplyPoint3x4(pointData[i].rootToPoint);
            pointData[i].position = position;
            float x3 = (position.x - x) * x2;
            float y  = (position.z - z) * z2;
            pointPositionArray[i]   = new Vector2(position.x, position.z);
            pointPositionUVArray[i] = new Vector2(x3, y);
        }
        WaterSystem.GetHeightArray(pointPositionArray, pointPositionUVArray, pointShoreVectorArray, pointTerrainHeightArray, pointWaterHeightArray);
        int num = 0;

        for (int j = 0; j < points.Length; j++)
        {
            BuoyancyPoint        buoyancyPoint     = points[j];
            Vector3              position2         = pointData[j].position;
            Vector3              localPosition     = pointData[j].localPosition;
            Vector2              posUV             = pointPositionUVArray[j];
            float                terrainHeight     = pointTerrainHeightArray[j];
            float                waterHeight       = pointWaterHeightArray[j];
            WaterLevel.WaterInfo buoyancyWaterInfo = WaterLevel.GetBuoyancyWaterInfo(position2, posUV, terrainHeight, waterHeight, forEntity);
            bool flag = false;
            if (position2.y < buoyancyWaterInfo.surfaceLevel && buoyancyWaterInfo.isValid)
            {
                flag = true;
                num++;
                float   currentDepth  = buoyancyWaterInfo.currentDepth;
                float   num2          = Mathf.InverseLerp(0f, buoyancyPoint.size, currentDepth);
                float   num3          = 1f + Mathf.PerlinNoise(buoyancyPoint.randomOffset + time * buoyancyPoint.waveFrequency, 0f) * buoyancyPoint.waveScale;
                float   num4          = buoyancyPoint.buoyancyForce * buoyancyScale;
                Vector3 force         = new Vector3(0f, num3 * num2 * num4, 0f);
                Vector3 flowDirection = GetFlowDirection(posUV);
                if (flowDirection.y < 0.9999f && flowDirection != Vector3.up)
                {
                    num4    *= 0.25f;
                    force.x += flowDirection.x * num4 * flowMovementScale;
                    force.y += flowDirection.y * num4 * flowMovementScale;
                    force.z += flowDirection.z * num4 * flowMovementScale;
                }
                rigidBody.AddForceAtPosition(force, position2, ForceMode.Force);
            }
            if (buoyancyPoint.doSplashEffects && ((!buoyancyPoint.wasSubmergedLastFrame && flag) || (!flag && buoyancyPoint.wasSubmergedLastFrame)) && doEffects && rigidBody.GetRelativePointVelocity(localPosition).magnitude > 1f)
            {
                string  strName = ((waterImpacts != null && waterImpacts.Length != 0 && waterImpacts[0].isValid) ? waterImpacts[0].resourcePath : DefaultWaterImpact());
                Vector3 vector  = new Vector3(UnityEngine.Random.Range(-0.25f, 0.25f), 0f, UnityEngine.Random.Range(-0.25f, 0.25f));
                Effect.server.Run(strName, position2 + vector, Vector3.up);
                buoyancyPoint.nexSplashTime = Time.time + 0.25f;
            }
            buoyancyPoint.wasSubmergedLastFrame = flag;
        }
        if (points.Length != 0)
        {
            submergedFraction = (float)num / (float)points.Length;
        }
        if (submergedFraction > requiredSubmergedFraction)
        {
            timeInWater   += Time.fixedDeltaTime;
            timeOutOfWater = 0f;
        }
        else
        {
            timeOutOfWater += Time.fixedDeltaTime;
            timeInWater     = 0f;
        }
    }
Exemple #2
0
 public void BuoyancyFixedUpdate()
 {
     if (Object.op_Equality((Object)TerrainMeta.WaterMap, (Object)null))
     {
         return;
     }
     this.EnsurePointsInitialized();
     if (Object.op_Equality((Object)this.rigidBody, (Object)null))
     {
         return;
     }
     if (this.rigidBody.IsSleeping())
     {
         this.Sleep();
     }
     else if ((double)this.buoyancyScale == 0.0)
     {
         this.Sleep();
     }
     else
     {
         float     time = Time.get_time();
         float     x1   = (float)TerrainMeta.Position.x;
         float     z1   = (float)TerrainMeta.Position.z;
         float     x2   = (float)TerrainMeta.OneOverSize.x;
         float     z2   = (float)TerrainMeta.OneOverSize.z;
         Matrix4x4 localToWorldMatrix = ((Component)this).get_transform().get_localToWorldMatrix();
         for (int index = 0; index < this.pointData.Length; ++index)
         {
             BuoyancyPoint point   = this.points[index];
             Vector3       vector3 = ((Matrix4x4) ref localToWorldMatrix).MultiplyPoint3x4(this.pointData[index].rootToPoint);
             this.pointData[index].position = vector3;
             float num1 = ((float)vector3.x - x1) * x2;
             float num2 = ((float)vector3.z - z1) * z2;
             this.pointPositionArray[index]   = new Vector2((float)vector3.x, (float)vector3.z);
             this.pointPositionUVArray[index] = new Vector2(num1, num2);
         }
         WaterSystem.GetHeight(this.pointPositionArray, this.pointPositionUVArray, this.pointTerrainHeightArray, this.pointWaterHeightArray);
         int num3 = 0;
         for (int index = 0; index < this.points.Length; ++index)
         {
             BuoyancyPoint        point              = this.points[index];
             Vector3              position           = this.pointData[index].position;
             Vector3              localPosition      = this.pointData[index].localPosition;
             Vector2              pointPositionUv    = this.pointPositionUVArray[index];
             float                pointTerrainHeight = this.pointTerrainHeightArray[index];
             float                pointWaterHeight   = this.pointWaterHeightArray[index];
             WaterLevel.WaterInfo buoyancyWaterInfo  = WaterLevel.GetBuoyancyWaterInfo(position, pointPositionUv, pointTerrainHeight, pointWaterHeight);
             bool flag = false;
             if (position.y < (double)buoyancyWaterInfo.surfaceLevel)
             {
                 flag = true;
                 ++num3;
                 float   currentDepth = buoyancyWaterInfo.currentDepth;
                 float   num1         = Mathf.InverseLerp(0.0f, point.size, currentDepth);
                 float   num2         = (float)(1.0 + (double)Mathf.PerlinNoise(point.randomOffset + time * point.waveFrequency, 0.0f) * (double)point.waveScale);
                 float   num4         = point.buoyancyForce * this.buoyancyScale;
                 Vector3 vector3;
                 ((Vector3) ref vector3).\u002Ector(0.0f, num2 * num1 * num4, 0.0f);
                 Vector3 flowDirection = this.GetFlowDirection(pointPositionUv);
                 if (flowDirection.y < 0.999899983406067 && Vector3.op_Inequality(flowDirection, Vector3.get_up()))
                 {
                     float      num5   = num4 * 0.25f;
                     ref __Null local1 = ref vector3.x;
Exemple #3
0
    public void BuoyancyFixedUpdate()
    {
        if (TerrainMeta.WaterMap == null)
        {
            return;
        }
        this.EnsurePointsInitialized();
        if (this.rigidBody == null)
        {
            return;
        }
        if (this.rigidBody.IsSleeping())
        {
            this.Sleep();
            return;
        }
        if (this.buoyancyScale == 0f)
        {
            this.Sleep();
            return;
        }
        float     single       = Time.time;
        float     position     = TerrainMeta.Position.x;
        float     position1    = TerrainMeta.Position.z;
        float     oneOverSize  = TerrainMeta.OneOverSize.x;
        float     oneOverSize1 = TerrainMeta.OneOverSize.z;
        Matrix4x4 matrix4x4    = base.transform.localToWorldMatrix;

        for (int i = 0; i < (int)this.pointData.Length; i++)
        {
            BuoyancyPoint buoyancyPoint = this.points[i];
            Vector3       vector3       = matrix4x4.MultiplyPoint3x4(this.pointData[i].rootToPoint);
            this.pointData[i].position = vector3;
            float single1 = (vector3.x - position) * oneOverSize;
            float single2 = (vector3.z - position1) * oneOverSize1;
            this.pointPositionArray[i]   = new Vector2(vector3.x, vector3.z);
            this.pointPositionUVArray[i] = new Vector2(single1, single2);
        }
        WaterSystem.GetHeight(this.pointPositionArray, this.pointPositionUVArray, this.pointShoreVectorArray, this.pointTerrainHeightArray, this.pointWaterHeightArray);
        int num = 0;

        for (int j = 0; j < (int)this.points.Length; j++)
        {
            BuoyancyPoint        buoyancyPoint1    = this.points[j];
            Vector3              vector31          = this.pointData[j].position;
            Vector3              vector32          = this.pointData[j].localPosition;
            Vector2              vector2           = this.pointPositionUVArray[j];
            float                single3           = this.pointTerrainHeightArray[j];
            float                single4           = this.pointWaterHeightArray[j];
            WaterLevel.WaterInfo buoyancyWaterInfo = WaterLevel.GetBuoyancyWaterInfo(vector31, vector2, single3, single4);
            bool flag = false;
            if (vector31.y < buoyancyWaterInfo.surfaceLevel)
            {
                flag = true;
                num++;
                float   single5       = buoyancyWaterInfo.currentDepth;
                float   single6       = Mathf.InverseLerp(0f, buoyancyPoint1.size, single5);
                float   single7       = 1f + Mathf.PerlinNoise(buoyancyPoint1.randomOffset + single * buoyancyPoint1.waveFrequency, 0f) * buoyancyPoint1.waveScale;
                float   single8       = buoyancyPoint1.buoyancyForce * this.buoyancyScale;
                Vector3 vector33      = new Vector3(0f, single7 * single6 * single8, 0f);
                Vector3 flowDirection = this.GetFlowDirection(vector2);
                if (flowDirection.y < 0.9999f && flowDirection != Vector3.up)
                {
                    single8 *= 0.25f;
                    ref float singlePointer = ref vector33.x;
                    singlePointer = singlePointer + flowDirection.x * single8;
                    ref float singlePointer1 = ref vector33.y;
                    singlePointer1 = singlePointer1 + flowDirection.y * single8;
                    ref float singlePointer2 = ref vector33.z;
                    singlePointer2 = singlePointer2 + flowDirection.z * single8;
                }