Exemple #1
0
 private void OnEnable()
 {
     if (!Application.isPlaying)
     {
         return;
     }
     if (this._FastEnableDisable && this._ComponentsCreated)
     {
         return;
     }
     Water._IsPlaying = Application.isPlaying;
     this.CreateWaterComponents();
     if (!this._ComponentsCreated)
     {
         return;
     }
     this._ProfilesManager.OnEnable();
     this._Geometry.OnEnable();
     this._Modules.ForEach(delegate(WaterModule x)
     {
         x.Enable();
     });
     if (this._RenderingEnabled)
     {
         WaterSystem.Register(this);
     }
 }
Exemple #2
0
 public void UpdateMovement()
 {
     if (!this.isSinking)
     {
         float height = WaterSystem.GetHeight(base.transform.position);
         base.transform.position = new Vector3(base.transform.position.x, height, base.transform.position.z);
         if (this.buoyancyPoints != null && (int)this.buoyancyPoints.Length >= 3)
         {
             Vector3 vector3  = base.transform.position;
             Vector3 vector31 = this.buoyancyPoints[0].localPosition;
             Vector3 vector32 = this.buoyancyPoints[1].localPosition;
             Vector3 vector33 = this.buoyancyPoints[2].localPosition;
             Vector3 height1  = vector31 + vector3;
             Vector3 height2  = vector32 + vector3;
             Vector3 height3  = vector33 + vector3;
             height1.y = WaterSystem.GetHeight(height1);
             height2.y = WaterSystem.GetHeight(height2);
             height3.y = WaterSystem.GetHeight(height3);
             base.transform.position = new Vector3(vector3.x, height1.y - vector31.y, vector3.z);
             Vector3    vector34   = height2 - height1;
             Vector3    vector35   = Vector3.Cross(height3 - height1, vector34);
             Quaternion quaternion = Quaternion.LookRotation(new Vector3(vector35.x, vector35.z, vector35.y));
             Vector3    vector36   = quaternion.eulerAngles;
             quaternion = Quaternion.Euler(-vector36.x, 0f, -vector36.y);
             if (this.first)
             {
                 Quaternion quaternion1 = base.transform.rotation;
                 this.baseRotation = Quaternion.Euler(0f, quaternion1.eulerAngles.y, 0f);
                 this.first        = false;
             }
             base.transform.rotation = quaternion * this.baseRotation;
         }
     }
 }
Exemple #3
0
        private Task HandleMessageReceived(MqttApplicationMessage message)
        {
            Logger.LogTrace("Message received");
            Match match = CommandTopicRegex.Match(message.Topic);

            if (match.Success)
            {
                string waterControllerId = match.Groups[WATER_CONTROLLER_ID_REGEX_GROUP].Value;
                string command           = match.Groups[COMMAND_NAME_REGEX_GROUP].Value;
                string payload           = message.ConvertPayloadToString();
                if (!WaterSystem.TryGet(waterControllerId, out IWaterController waterController))
                {
                    Logger.LogWarning($"Water controller: '{waterControllerId}' not found");
                    return(Task.CompletedTask);
                }
                switch (command)
                {
                case FLOW_TOPIC:
                    break;

                default:
                    Logger.LogWarning($"Unknown command topic '{command}'");
                    return(SendCommandResponseAsync(waterControllerId, COMMAND_UNKNOWN_PAYLOAD));
                }
                switch (payload)
                {
                case ON_PAYLOAD:
                    if (!waterController.IsOn)
                    {
                        waterController.TurnOn();
                    }
                    else
                    {
                        Logger.LogTrace($"Water controller: '{waterControllerId}' is already on");
                    }
                    return(SendCommandResponseAsync(waterControllerId, COMMAND_FLOW_ON_PAYLOAD));

                case OFF_PAYLOAD:
                    if (waterController.IsOn)
                    {
                        waterController.TurnOff();
                    }
                    else
                    {
                        Logger.LogTrace($"Water controller: '{waterControllerId}' is already off");
                    }
                    return(SendCommandResponseAsync(waterControllerId, COMMAND_FLOW_OFF_PAYLOAD));

                default:
                    Logger.LogWarning($"Unknown payload '{payload}'");
                    return(Task.CompletedTask);
                }
            }
            else
            {
                Logger.LogTrace("Topic does not match expectation");
            }
            return(Task.CompletedTask);
        }
Exemple #4
0
 public void CheckForWake()
 {
     if (!((double)WaterSystem.GetHeight(((Component)this).get_transform().get_position()) > Vector3.op_Subtraction(((Component)this).get_transform().get_position(), Vector3.op_Multiply(Vector3.get_up(), 0.2f)).y & !this.rigidBody.IsSleeping()))
     {
         return;
     }
     this.Wake();
 }
Exemple #5
0
    public static float GetHeight(Vector3 pos, out float terrainHeight)
    {
        Vector2 posUV;

        posUV.x = (pos.x - TerrainMeta.Position.x) * TerrainMeta.OneOverSize.x;
        posUV.y = (pos.z - TerrainMeta.Position.z) * TerrainMeta.OneOverSize.z;
        return(WaterSystem.GetHeight(pos, posUV, out terrainHeight));
    }
    public static float GetHeight(Vector3 pos, out float terrainHeight)
    {
        Vector2 vector2 = new Vector2();

        vector2.x = (pos.x - TerrainMeta.Position.x) * TerrainMeta.OneOverSize.x;
        vector2.y = (pos.z - TerrainMeta.Position.z) * TerrainMeta.OneOverSize.z;
        return(WaterSystem.GetHeight(pos, vector2, out terrainHeight));
    }
Exemple #7
0
 private void cboWaterSystem_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cboWaterSystem.SelectedItem != null)
     {
         WaterSystem ws = cboWaterSystem.SelectedItem as WaterSystem;
         cboResearchArea.DataSource = raRepository.GetByWaterSystem(ws);
     }
 }
    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;
            }
        }
    }
        public IEnumerable <ResearchArea> GetByWaterSystem(WaterSystem ws)
        {
            using (MySqlCommand cmd = Connection.CreateCommand()) {
                cmd.CommandText = "SELECT * FROM tutkimusalueet WHERE vesisto_id = @id";
                cmd.Parameters.AddWithValue("id", ws.Id);

                return(ToList(cmd));
            }
        }
Exemple #10
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);
            }
        }
    }
Exemple #11
0
            public static WaterSystem FromVeins(ClayVein[] veins)
            {
                int width  = veins.Max(vein => vein.X.End.Value) + 1;
                int height = veins.Max(vein => vein.Y.End.Value);
                int minY   = veins.Max(vein => vein.Y.Start.Value);

                var result = new WaterSystem(width, height, minY);

                foreach (var vein in veins)
                {
                    result[vein.X, vein.Y] = GroundType.Clay;
                }

                return(result);
            }
Exemple #12
0
        // objektien sidonta vastaaviin kenttiin
        private void cbEditItem_Click(object sender, EventArgs e)
        {
            int    selectedItemType = cboItemTypeSelector.SelectedIndex;
            object selectedItem     = dgvItems.SelectedRows[0].DataBoundItem;

            FormHelper.ClearFields(currentLayout);
            SetEditMode(!editMode);

            switch (selectedItemType)
            {
            case 0:
            case 1:
            case 2:
                Resource r = (Resource)selectedItem;
                tbResourceName.Text = r.Name;
                break;

            case 3:
                User u = (User)selectedItem;
                tbUserName.Text    = u.Name;
                tbUserAddress.Text = u.Address;
                tbUserCity.Text    = u.City;
                tbUserKey.Text     = u.Key;
                tbUserZip.Text     = u.Zip;
                cboUserResearchArea.SelectedValue = u.ResearchAreaId;
                break;

            case 4:
                WaterSystem ws = (WaterSystem)selectedItem;
                tbResourceName.Text = ws.Name;
                break;

            case 5:
                FishingArea fa = (FishingArea)selectedItem;
                tbFishingAreaName.Text = fa.Name;
                cboFishingAreaResearchArea.SelectedValue = fa.ResearchAreaId;
                break;

            case 6:
                ResearchArea ra = (ResearchArea)selectedItem;
                tbResearchAreaName.Text = ra.Name;
                cboResearchAreaWaterSystem.SelectedValue = ra.WaterSystemId;
                break;
            }
        }
Exemple #13
0
 private void OnDisable()
 {
     if (!Application.isPlaying)
     {
         return;
     }
     if (this._FastEnableDisable)
     {
         return;
     }
     this._Modules.ForEach(delegate(WaterModule x)
     {
         x.Disable();
     });
     this._Geometry.OnDisable();
     this._ProfilesManager.OnDisable();
     WaterSystem.Unregister(this);
 }
Exemple #14
0
        public void RunMain()
        {
            var serviceProvider = ConfigureServices(new ServiceCollection());

            var logger = serviceProvider.GetService <ILoggerFactory>()
                         .CreateLogger <Program>();

            logger.LogDebug("Service setup complete");
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
            WaterSystem = serviceProvider.GetService <IWaterSystem>();
            WaterSystem.Initialize();
            MqttClient = serviceProvider.GetService <ITrexWaterMqttClient>();
            MqttClient.StartAsync().Wait();
            while (Console.ReadLine() != "exit")
            {
            }
            Dispose();
        }
    public override void VehicleFixedUpdate()
    {
        if (this.isClient)
        {
            return;
        }
        if (!this.EngineOn())
        {
            this.gasPedal = 0.0f;
            this.steering = 0.0f;
        }
        base.VehicleFixedUpdate();
        if (!((double)this.gasPedal != 0.0 & (double)WaterSystem.GetHeight(this.thrustPoint.get_position()) >= this.thrustPoint.get_position().y) || (double)this.buoyancy.submergedFraction <= 0.300000011920929)
        {
            return;
        }
        Vector3 vector3 = Vector3.op_Addition(((Component)this).get_transform().get_forward(), Vector3.op_Multiply(Vector3.op_Multiply(((Component)this).get_transform().get_right(), this.steering), this.steeringScale));

        this.myRigidBody.AddForceAtPosition(Vector3.op_Multiply(Vector3.op_Multiply(((Vector3) ref vector3).get_normalized(), this.gasPedal), this.engineThrust), this.thrustPoint.get_position(), (ForceMode)0);
    }
    public override void VehicleFixedUpdate()
    {
        if (base.isClient)
        {
            return;
        }
        if (!this.EngineOn())
        {
            this.gasPedal = 0f;
            this.steering = 0f;
        }
        base.VehicleFixedUpdate();
        bool height = WaterSystem.GetHeight(this.thrustPoint.position) >= this.thrustPoint.position.y;

        if (this.gasPedal != 0f & height && this.buoyancy.submergedFraction > 0.3f)
        {
            Vector3 vector3  = base.transform.forward + ((base.transform.right * this.steering) * this.steeringScale);
            Vector3 vector31 = (vector3.normalized * this.gasPedal) * this.engineThrust;
            this.myRigidBody.AddForceAtPosition(vector31, this.thrustPoint.position, ForceMode.Force);
        }
    }
Exemple #17
0
	public void UpdateMovement()
	{
		if ((float)nextPlayerCheck <= 0f)
		{
			nextPlayerCheck = Random.Range(0.5f, 1f);
			junkpileWaterWorkQueue.Add(this);
		}
		if (isSinking || !hasPlayersNearby)
		{
			return;
		}
		float height = WaterSystem.GetHeight(base.transform.position);
		base.transform.position = new Vector3(base.transform.position.x, height, base.transform.position.z);
		if (buoyancyPoints != null && buoyancyPoints.Length >= 3)
		{
			Vector3 position = base.transform.position;
			Vector3 localPosition = buoyancyPoints[0].localPosition;
			Vector3 localPosition2 = buoyancyPoints[1].localPosition;
			Vector3 localPosition3 = buoyancyPoints[2].localPosition;
			Vector3 vector = localPosition + position;
			Vector3 vector2 = localPosition2 + position;
			Vector3 vector3 = localPosition3 + position;
			vector.y = WaterSystem.GetHeight(vector);
			vector2.y = WaterSystem.GetHeight(vector2);
			vector3.y = WaterSystem.GetHeight(vector3);
			Vector3 position2 = new Vector3(position.x, vector.y - localPosition.y, position.z);
			Vector3 rhs = vector2 - vector;
			Vector3 vector4 = Vector3.Cross(vector3 - vector, rhs);
			Vector3 eulerAngles = Quaternion.LookRotation(new Vector3(vector4.x, vector4.z, vector4.y)).eulerAngles;
			Quaternion quaternion = Quaternion.Euler(0f - eulerAngles.x, 0f, 0f - eulerAngles.y);
			if (first)
			{
				baseRotation = Quaternion.Euler(0f, base.transform.rotation.eulerAngles.y, 0f);
				first = false;
			}
			base.transform.SetPositionAndRotation(position2, quaternion * baseRotation);
		}
	}
    public void UpdateMovement()
    {
        if (this.isSinking)
        {
            return;
        }
        ((Component)this).get_transform().set_position(new Vector3((float)((Component)this).get_transform().get_position().x, WaterSystem.GetHeight(((Component)this).get_transform().get_position()), (float)((Component)this).get_transform().get_position().z));
        if (this.buoyancyPoints == null || this.buoyancyPoints.Length < 3)
        {
            return;
        }
        Vector3 position       = ((Component)this).get_transform().get_position();
        Vector3 localPosition1 = this.buoyancyPoints[0].get_localPosition();
        Vector3 localPosition2 = this.buoyancyPoints[1].get_localPosition();
        Vector3 localPosition3 = this.buoyancyPoints[2].get_localPosition();
        Vector3 pos1           = Vector3.op_Addition(localPosition1, position);
        Vector3 pos2           = Vector3.op_Addition(localPosition2, position);
        Vector3 vector3_1      = position;
        Vector3 pos3           = Vector3.op_Addition(localPosition3, vector3_1);

        pos1.y = (__Null)(double)WaterSystem.GetHeight(pos1);
        pos2.y = (__Null)(double)WaterSystem.GetHeight(pos2);
        pos3.y = (__Null)(double)WaterSystem.GetHeight(pos3);
        ((Component)this).get_transform().set_position(new Vector3((float)position.x, (float)(pos1.y - localPosition1.y), (float)position.z));
        Vector3    vector3_2   = Vector3.op_Subtraction(pos2, pos1);
        Vector3    vector3_3   = Vector3.Cross(Vector3.op_Subtraction(pos3, pos1), vector3_2);
        Quaternion quaternion1 = Quaternion.LookRotation(new Vector3((float)vector3_3.x, (float)vector3_3.z, (float)vector3_3.y));
        Vector3    eulerAngles = ((Quaternion) ref quaternion1).get_eulerAngles();
        Quaternion quaternion2 = Quaternion.Euler((float)-eulerAngles.x, 0.0f, (float)-eulerAngles.y);

        if (this.first)
        {
            Quaternion rotation = ((Component)this).get_transform().get_rotation();
            this.baseRotation = Quaternion.Euler(0.0f, (float)((Quaternion) ref rotation).get_eulerAngles().y, 0.0f);
            this.first        = false;
        }
        ((Component)this).get_transform().set_rotation(Quaternion.op_Multiply(quaternion2, this.baseRotation));
    }
    private void Update()
    {
        Vector3 position     = ((Component)this).get_transform().get_position();
        Vector3 vector3      = Vector3.op_Subtraction(position, this.prevPosition);
        float   sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude();
        float   num          = this.minScale;
        bool    flag         = (double)WaterSystem.GetHeight(position) > position.y - (double)this.submergedThickness;

        if ((double)sqrMagnitude > 9.99999974737875E-05)
        {
            num = Mathf.Lerp(this.minScale, this.maxScale, Mathf.Clamp01(Mathf.Clamp(Mathf.Sqrt(sqrMagnitude), this.minSpeed, this.maxSpeed) / (this.maxSpeed - this.minSpeed)));
            if (Object.op_Inequality((Object)this.component, (Object)null) && this.toggleComponent)
            {
                ((Behaviour)this.component).set_enabled(flag);
            }
        }
        else if (Object.op_Inequality((Object)this.component, (Object)null) && this.toggleComponent)
        {
            ((Behaviour)this.component).set_enabled(false);
        }
        ((Component)this).get_transform().set_localScale(new Vector3(num, num, num));
        this.prevPosition = position;
    }
    private void Update()
    {
        Vector3 vector3 = base.transform.position;
        float   single  = (vector3 - this.prevPosition).sqrMagnitude;
        float   single1 = this.minScale;
        bool    height  = WaterSystem.GetHeight(vector3) > vector3.y - this.submergedThickness;

        if (single > 0.0001f)
        {
            single = Mathf.Sqrt(single);
            float single2 = Mathf.Clamp(single, this.minSpeed, this.maxSpeed) / (this.maxSpeed - this.minSpeed);
            single1 = Mathf.Lerp(this.minScale, this.maxScale, Mathf.Clamp01(single2));
            if (this.component != null && this.toggleComponent)
            {
                this.component.enabled = height;
            }
        }
        else if (this.component != null && this.toggleComponent)
        {
            this.component.enabled = false;
        }
        base.transform.localScale = new Vector3(single1, single1, single1);
        this.prevPosition         = vector3;
    }
Exemple #21
0
    public static float GetHeight(Vector3 pos)
    {
        float terrainHeight;

        return(WaterSystem.GetHeight(pos, out terrainHeight));
    }
 public void BuildWaterSystem()
 {
     var waterSystem = new WaterSystem();
     AddHousePart(waterSystem);
 }
Exemple #23
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 #24
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;
        }
    }
    public static float GetHeight(Vector3 pos)
    {
        float single;

        return(WaterSystem.GetHeight(pos, out single));
    }
Exemple #26
0
 protected override void LoadState()
 {
     system = WaterSystem.FromVeins(ParsedFileLines(ClayVein.Parse));
 }
 private void CheckInstance()
 {
     WaterSystem.instance  = (WaterSystem.instance != null ? WaterSystem.instance : this);
     WaterSystem.Collision = (WaterSystem.Collision != null ? WaterSystem.Collision : base.GetComponent <WaterCollision>());
     WaterSystem.Dynamics  = (WaterSystem.Dynamics != null ? WaterSystem.Dynamics : base.GetComponent <WaterDynamics>());
 }
Exemple #28
0
 protected override void ResetState()
 {
     system = null;
 }
Exemple #29
0
 void Awake()
 {
     WaterSystem.instance = this;
 }
Exemple #30
0
 public void Dispose()
 {
     MqttClient.Dispose();
     WaterSystem.Dispose();
 }
Exemple #31
0
 private void CheckInstance()
 {
     WaterSystem.instance  = Object.op_Inequality((Object)WaterSystem.instance, (Object)null) ? WaterSystem.instance : this;
     WaterSystem.Collision = Object.op_Inequality((Object)WaterSystem.Collision, (Object)null) ? WaterSystem.Collision : (WaterCollision)((Component)this).GetComponent <WaterCollision>();
     WaterSystem.Dynamics  = Object.op_Inequality((Object)WaterSystem.Dynamics, (Object)null) ? WaterSystem.Dynamics : (WaterDynamics)((Component)this).GetComponent <WaterDynamics>();
 }