Ejemplo n.º 1
0
 public static WaterLevel.WaterInfo GetBuoyancyWaterInfo(
     Vector3 pos,
     Vector2 posUV,
     float terrainHeight,
     float waterHeight)
 {
     using (TimeWarning.New("WaterLevel.GetWaterInfo", 0.1f))
     {
         WaterLevel.WaterInfo waterInfo = new WaterLevel.WaterInfo();
         if (pos.y > (double)waterHeight)
         {
             return(waterInfo);
         }
         bool flag = pos.y < (double)terrainHeight - 1.0;
         if (flag)
         {
             waterHeight = 0.0f;
             if (pos.y > (double)waterHeight)
             {
                 return(waterInfo);
             }
         }
         int num = Object.op_Implicit((Object)TerrainMeta.TopologyMap) ? TerrainMeta.TopologyMap.GetTopologyFast(posUV) : 0;
         if ((flag || (num & 246144) == 0) && (Object.op_Implicit((Object)WaterSystem.Collision) && WaterSystem.Collision.GetIgnore(pos, 0.01f)))
         {
             return(waterInfo);
         }
         waterInfo.isValid      = true;
         waterInfo.currentDepth = Mathf.Max(0.0f, waterHeight - (float)pos.y);
         waterInfo.overallDepth = Mathf.Max(0.0f, waterHeight - terrainHeight);
         waterInfo.surfaceLevel = waterHeight;
         return(waterInfo);
     }
 }
Ejemplo n.º 2
0
 public static WaterLevel.WaterInfo GetWaterInfo(Vector3 pos)
 {
     using (TimeWarning.New("WaterLevel.GetWaterInfo", 0.1f))
     {
         WaterLevel.WaterInfo waterInfo = new WaterLevel.WaterInfo();
         float num1 = Object.op_Implicit((Object)TerrainMeta.WaterMap) ? TerrainMeta.WaterMap.GetHeight(pos) : 0.0f;
         if (pos.y > (double)num1)
         {
             return(waterInfo);
         }
         float num2 = Object.op_Implicit((Object)TerrainMeta.HeightMap) ? TerrainMeta.HeightMap.GetHeight(pos) : 0.0f;
         if (pos.y < (double)num2 - 1.0)
         {
             num1 = 0.0f;
             if (pos.y > (double)num1)
             {
                 return(waterInfo);
             }
         }
         if (Object.op_Implicit((Object)WaterSystem.Collision) && WaterSystem.Collision.GetIgnore(pos, 0.01f))
         {
             return(waterInfo);
         }
         waterInfo.isValid      = true;
         waterInfo.currentDepth = Mathf.Max(0.0f, num1 - (float)pos.y);
         waterInfo.overallDepth = Mathf.Max(0.0f, num1 - num2);
         waterInfo.surfaceLevel = num1;
         return(waterInfo);
     }
 }
    public void SpawnOnRay(Ray ray, int mask, float length = 0.5f, Vector3 forward = null, float speed = 0f)
    {
        RaycastHit raycastHit;

        if (!GamePhysics.Trace(ray, 0f, out raycastHit, length, mask, QueryTriggerInteraction.UseGlobal))
        {
            Effect.client.Run(this.DefaultEffect.resourcePath, ray.origin, ray.direction * -1f, forward);
            if (this.DefaultSoundDefinition != null)
            {
                this.PlaySound(this.DefaultSoundDefinition, raycastHit.point, speed);
            }
            return;
        }
        WaterLevel.WaterInfo waterInfo = WaterLevel.GetWaterInfo(ray.origin);
        if (waterInfo.isValid)
        {
            Vector3 vector3 = new Vector3(ray.origin.x, WaterSystem.GetHeight(ray.origin), ray.origin.z);
            MaterialEffect.Entry waterEntry = this.GetWaterEntry();
            if (this.submergedWaterDepth > 0f && waterInfo.currentDepth >= this.submergedWaterDepth)
            {
                waterEntry = this.submergedWaterEntry;
            }
            else if (this.deepWaterDepth > 0f && waterInfo.currentDepth >= this.deepWaterDepth)
            {
                waterEntry = this.deepWaterEntry;
            }
            if (waterEntry == null)
            {
                return;
            }
            Effect.client.Run(waterEntry.Effect.resourcePath, vector3, Vector3.up, new Vector3());
            if (waterEntry.SoundDefinition != null)
            {
                this.PlaySound(waterEntry.SoundDefinition, vector3, speed);
            }
            return;
        }
        PhysicMaterial materialAt = raycastHit.collider.GetMaterialAt(raycastHit.point);

        MaterialEffect.Entry entryFromMaterial = this.GetEntryFromMaterial(materialAt);
        if (entryFromMaterial != null)
        {
            Effect.client.Run(entryFromMaterial.Effect.resourcePath, raycastHit.point, raycastHit.normal, forward);
            if (entryFromMaterial.SoundDefinition != null)
            {
                this.PlaySound(entryFromMaterial.SoundDefinition, raycastHit.point, speed);
            }
        }
        else
        {
            Effect.client.Run(this.DefaultEffect.resourcePath, raycastHit.point, raycastHit.normal, forward);
            if (this.DefaultSoundDefinition != null)
            {
                this.PlaySound(this.DefaultSoundDefinition, raycastHit.point, speed);
                return;
            }
        }
    }
Ejemplo n.º 4
0
    public void SpawnOnRay(Ray ray, int mask, float length = 0.5f, Vector3 forward = default(Vector3), float speed = 0f)
    {
        RaycastHit hitInfo;

        if (!GamePhysics.Trace(ray, 0f, out hitInfo, length, mask))
        {
            Effect.client.Run(DefaultEffect.resourcePath, ray.origin, ray.direction * -1f, forward);
            if (DefaultSoundDefinition != null)
            {
                PlaySound(DefaultSoundDefinition, hitInfo.point, speed);
            }
            return;
        }
        WaterLevel.WaterInfo waterInfo = WaterLevel.GetWaterInfo(ray.origin);
        if (waterInfo.isValid)
        {
            Vector3 vector     = new Vector3(ray.origin.x, WaterSystem.GetHeight(ray.origin), ray.origin.z);
            Entry   waterEntry = GetWaterEntry();
            if (submergedWaterDepth > 0f && waterInfo.currentDepth >= submergedWaterDepth)
            {
                waterEntry = submergedWaterEntry;
            }
            else if (deepWaterDepth > 0f && waterInfo.currentDepth >= deepWaterDepth)
            {
                waterEntry = deepWaterEntry;
            }
            if (waterEntry != null)
            {
                Effect.client.Run(waterEntry.Effect.resourcePath, vector, Vector3.up);
                if (waterEntry.SoundDefinition != null)
                {
                    PlaySound(waterEntry.SoundDefinition, vector, speed);
                }
            }
            return;
        }
        PhysicMaterial materialAt        = ColliderEx.GetMaterialAt(hitInfo.collider, hitInfo.point);
        Entry          entryFromMaterial = GetEntryFromMaterial(materialAt);

        if (entryFromMaterial == null)
        {
            Effect.client.Run(DefaultEffect.resourcePath, hitInfo.point, hitInfo.normal, forward);
            if (DefaultSoundDefinition != null)
            {
                PlaySound(DefaultSoundDefinition, hitInfo.point, speed);
            }
        }
        else
        {
            Effect.client.Run(entryFromMaterial.Effect.resourcePath, hitInfo.point, hitInfo.normal, forward);
            if (entryFromMaterial.SoundDefinition != null)
            {
                PlaySound(entryFromMaterial.SoundDefinition, hitInfo.point, speed);
            }
        }
    }
Ejemplo n.º 5
0
 public static float Factor(Bounds bounds)
 {
     using (TimeWarning.New("WaterLevel.Factor", 0.1f))
     {
         if (Vector3.op_Equality(((Bounds) ref bounds).get_size(), Vector3.get_zero()))
         {
             ((Bounds) ref bounds).set_size(new Vector3(0.1f, 0.1f, 0.1f));
         }
         WaterLevel.WaterInfo waterInfo = WaterLevel.GetWaterInfo(bounds);
         return(waterInfo.isValid ? Mathf.InverseLerp((float)((Bounds) ref bounds).get_min().y, (float)((Bounds) ref bounds).get_max().y, waterInfo.surfaceLevel) : 0.0f);
     }
 }
Ejemplo n.º 6
0
    public static float Factor(Bounds bounds)
    {
        float single;

        using (TimeWarning timeWarning = TimeWarning.New("WaterLevel.Factor", 0.1f))
        {
            if (bounds.size == Vector3.zero)
            {
                bounds.size = new Vector3(0.1f, 0.1f, 0.1f);
            }
            WaterLevel.WaterInfo waterInfo = WaterLevel.GetWaterInfo(bounds);
            single = (waterInfo.isValid ? Mathf.InverseLerp(bounds.min.y, bounds.max.y, waterInfo.surfaceLevel) : 0f);
        }
        return(single);
    }
Ejemplo n.º 7
0
 public static WaterLevel.WaterInfo GetWaterInfo(Vector3 pos)
 {
     WaterLevel.WaterInfo waterInfo;
     using (TimeWarning timeWarning = TimeWarning.New("WaterLevel.GetWaterInfo", 0.1f))
     {
         WaterLevel.WaterInfo waterInfo1 = new WaterLevel.WaterInfo();
         float single = (TerrainMeta.WaterMap ? TerrainMeta.WaterMap.GetHeight(pos) : 0f);
         if (pos.y <= single)
         {
             float single1 = (TerrainMeta.HeightMap ? TerrainMeta.HeightMap.GetHeight(pos) : 0f);
             if (pos.y < single1 - 1f)
             {
                 single = 0f;
                 if (pos.y > single)
                 {
                     waterInfo = waterInfo1;
                     return(waterInfo);
                 }
             }
             if (!WaterSystem.Collision || !WaterSystem.Collision.GetIgnore(pos, 0.01f))
             {
                 waterInfo1.isValid      = true;
                 waterInfo1.currentDepth = Mathf.Max(0f, single - pos.y);
                 waterInfo1.overallDepth = Mathf.Max(0f, single - single1);
                 waterInfo1.surfaceLevel = single;
                 waterInfo = waterInfo1;
             }
             else
             {
                 waterInfo = waterInfo1;
             }
         }
         else
         {
             waterInfo = waterInfo1;
         }
     }
     return(waterInfo);
 }
Ejemplo n.º 8
0
 public static WaterLevel.WaterInfo GetBuoyancyWaterInfo(Vector3 pos, Vector2 posUV, float terrainHeight, float waterHeight)
 {
     WaterLevel.WaterInfo waterInfo;
     using (TimeWarning timeWarning = TimeWarning.New("WaterLevel.GetWaterInfo", 0.1f))
     {
         WaterLevel.WaterInfo waterInfo1 = new WaterLevel.WaterInfo();
         if (pos.y <= waterHeight)
         {
             bool flag = pos.y < terrainHeight - 1f;
             if (flag)
             {
                 waterHeight = 0f;
                 if (pos.y > waterHeight)
                 {
                     waterInfo = waterInfo1;
                     return(waterInfo);
                 }
             }
             int num = (TerrainMeta.TopologyMap ? TerrainMeta.TopologyMap.GetTopologyFast(posUV) : 0);
             if ((flag || (num & 246144) == 0) && WaterSystem.Collision && WaterSystem.Collision.GetIgnore(pos, 0.01f))
             {
                 waterInfo = waterInfo1;
             }
             else
             {
                 waterInfo1.isValid      = true;
                 waterInfo1.currentDepth = Mathf.Max(0f, waterHeight - pos.y);
                 waterInfo1.overallDepth = Mathf.Max(0f, waterHeight - terrainHeight);
                 waterInfo1.surfaceLevel = waterHeight;
                 waterInfo = waterInfo1;
             }
         }
         else
         {
             waterInfo = waterInfo1;
         }
     }
     return(waterInfo);
 }
Ejemplo n.º 9
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;
Ejemplo n.º 10
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;
        }
    }
Ejemplo n.º 11
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;
                }