void Start() { if (SelectableMesh == null) { SelectableMesh = new Mesh(); } if (_SelectableMeshBorder == null) { _SelectableMeshBorder = new BorderPointSet[0]; } Border = GetComponent <BorderRenderer>(); Border.Points = SelectableMeshBorder; AlphaShaderID = Shader.PropertyToID("_Alpha"); if (_GroundMaterialSource != null) { GroundMaterial = new Material(_GroundMaterialSource); } if (GroundAlpha != LastGroundAlpha && GroundMaterial != null) { GroundMaterial.SetFloat(AlphaShaderID, GroundAlpha); LastGroundAlpha = GroundAlpha; } #if UNITY_EDITOR UnityEditor.SceneView.RepaintAll(); #endif }
/// <summary> /// Check point against the provided material /// </summary> /// <param name="x">X Coord</param> /// <param name="z">Y Coord</param> /// <param name="groundMaterial">Material to check against</param> /// <returns>true if the Materials are the same</returns> public bool IsGroundMaterialAt(int x, int z, GroundMaterial groundMaterial) { if ((x >= 0 && x < GroundMaterial.GetLength(0)) && (z >= 0 && z < GroundMaterial.GetLength(1))) { return(GroundMaterial[x, z] == groundMaterial); } return(false); }
/// <summary> /// Update the GroundMaterial on this point /// </summary> /// <param name="x">X Coord</param> /// <param name="z">Z Coord</param> /// <param name="groundMaterial">New Material</param> /// <returns></returns> public bool UpdateGroundMapAt(int x, int z, GroundMaterial groundMaterial) { if ((x >= 0 && x < GroundMaterial.GetLength(0)) && (z >= 0 && z < GroundMaterial.GetLength(1))) { GroundMaterial[x, z] = groundMaterial; return(true); } return(false); }
void Update() { // We have to detect changes this way instead of using properties because // we want to be able to animate the alpha value with a Unity animator. if (GroundAlpha != LastGroundAlpha && GroundMaterial != null) { GroundMaterial.SetFloat(AlphaShaderID, GroundAlpha); LastGroundAlpha = GroundAlpha; } }
public void Demolish() { for (int i = 0; i < foundations.Length; i++) { foundations[i].FlattenTo(height); foundations[i].BuildingOnSquare = null; GroundMaterial tempPass = foundations[i].Tile; GroundMaterial.SetToMud(foundations[i], ref tempPass); } Destroy(this); }
public GroundMaterial.Type Detect() { if (Physics.Raycast(transform.position, transform.rotation * raycastLocalDir, out RaycastHit hit, raycastMaxDist, raycastLayerMask, raycastTriggerInteraction)) { GroundMaterial groundMaterial = hit.collider.GetComponent <GroundMaterial>(); if (groundMaterial != null) { return(groundMaterial.type); } } return(defaultType); }
public void SetToPrevious(SquareCell caller) { tileTypeName = previousMaterial.tileTypeName; color = previousMaterial.color; blendEdge = previousMaterial.blendEdge; decays = previousMaterial.decays; lifetime = previousMaterial.lifetime; previousMaterial = previousMaterial.previousMaterial; if (decays) { CallCountDown(caller); } }
public void ChangeVertexElevation(GridDirection vertex, int value) { if (value == 0 && ((HasRoadThroughEdge(vertex.Next()) && (GetElevationDifference(vertex.Next()) > 3 || HasCliff(vertex.Next()))) || (HasRoadThroughEdge(vertex.Previous()) && (GetElevationDifference(vertex.Previous()) > 3 || HasCliff(vertex.Previous()))) )) { Debug.Log("Could not change elevation"); } else { vertexElevations[vertex] += value; GroundMaterial.SetToMud(this, ref tile); } }
bool[] roads = new bool[8]; // includes diagonals public void Demolish() { urbanLevel = 0; plantLevel = 0; farmLevel = 0; scenaryObject = 0; industry = 0; if (buildingOnSquare != null) { buildingOnSquare.Demolish(); } GroundMaterial.SetToMud(this, ref tile); Explosion(); }
/// <summary> /// Sets the ground material to the one with the highest material /// </summary> private void SetGroundMaterial() { GroundMaterial groundMaterial = null; int priority = -1; foreach (Collider2D collider in this.onGroundCollider.colliders) { ObjectMaterial material = collider.gameObject.GetComponent <ObjectMaterial>(); if (material.groundMaterial.priority > priority) { groundMaterial = material.groundMaterial; } } this.groundMaterial = groundMaterial; }
public static void SetToMud(SquareCell caller, ref GroundMaterial material) //temporary mud for construction/destruction { GroundMaterial newMaterial = Instantiate(material); newMaterial.tileTypeName = "Mud"; newMaterial.color = new Color32(0x44, 0x20, 0x0A, 0xFF); newMaterial.blendEdge = true; newMaterial.decays = true; newMaterial.lifetime = 5f + Random.Range(1f, 1f); if (material.previousMaterial == null) // stops building long chains of mud decaying to mud { newMaterial.previousMaterial = material; } material = newMaterial; caller.Tile = material; caller.Refresh(); caller.StartCoroutine(material.CallCountDown(caller)); }
public void RemoveIncomingRivers() { if (!hasIncomingRivers.Any()) { return; } GridDirection[] neighbors = IncomingRivers; for (int i = 0; i < hasIncomingRivers.Length; i++) { hasIncomingRivers[i] = false; } GroundMaterial.SetToMud(this, ref tile); RefreshChunkOnly(); foreach (GridDirection direction in neighbors) { SquareCell neighbor = GetNeighbor(direction); hasOutgoingRivers[(int)direction.Opposite()] = false; neighbor.RefreshChunkOnly(); } }
public void SelectMaterial(int index) { activeTileMaterial = materials[index]; }
public void changeState(GroundMaterial state) { currentGround = state; }
public void SmokeWeedEveryday (GroundMaterial ground) { for(int i = 0; i < allWheelColliders.Length; i++){ WheelHit CorrespondingGroundHit; allWheelColliders[i].GetGroundHit(out CorrespondingGroundHit); if(_wheelSlipAsphalt.Count > 0 && ground == GroundMaterial.Asphalt){ if(Mathf.Abs(CorrespondingGroundHit.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHit.forwardSlip) > .5f){ if(!_wheelSlipAsphalt[i].enableEmission && speed > 1) _wheelSlipAsphalt[i].enableEmission = true; }else{ if(_wheelSlipAsphalt[i].enableEmission) _wheelSlipAsphalt[i].enableEmission = false; } }else if(_wheelSlipAsphalt.Count > 0){ if(_wheelSlipAsphalt[i].enableEmission) _wheelSlipAsphalt[i].enableEmission = false; } if(_wheelSlipSand.Count > 0 && ground == GroundMaterial.Sand){ if(Mathf.Abs(CorrespondingGroundHit.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHit.forwardSlip) > .5f){ if(!_wheelSlipSand[i].enableEmission && speed > 1) _wheelSlipSand[i].enableEmission = true; }else{ if(_wheelSlipSand[i].enableEmission) _wheelSlipSand[i].enableEmission = false; } }else if(_wheelSlipSand.Count > 0){ if(_wheelSlipSand[i].enableEmission) _wheelSlipSand[i].enableEmission = false; } } if(exhaustGas.Length > 0 && engineRunning){ foreach(ParticleSystem p in exhaustGas){ if(speed < 20){ if(!p.enableEmission) p.enableEmission = true; if(gasInput > .05f) p.emissionRate = 15; else p.emissionRate = 4; }else{ if(p.enableEmission) p.enableEmission = false; } } }else if(exhaustGas.Length > 0){ foreach(ParticleSystem p in exhaustGas){ if(p.enableEmission) p.enableEmission = false; } } }
public void SmokeWeedEveryday (GroundMaterial ground){ for(int i = 0; i < allWheelColliders.Length; i++){ WheelHit CorrespondingGroundHit; allWheelColliders[i].GetGroundHit(out CorrespondingGroundHit); if(_wheelSlipAsphalt.Count > 0 && ground == GroundMaterial.Asphalt){ if(Mathf.Abs(CorrespondingGroundHit.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHit.forwardSlip) > .35f){ if(!_wheelSlipAsphalt[i].enableEmission && speed > 1) _wheelSlipAsphalt[i].enableEmission = true; }else{ if(_wheelSlipAsphalt[i].enableEmission) _wheelSlipAsphalt[i].enableEmission = false; } }else if(_wheelSlipAsphalt.Count > 0){ if(_wheelSlipAsphalt[i].enableEmission) _wheelSlipAsphalt[i].enableEmission = false; } if(_wheelSlipSand.Count > 0 && ground == GroundMaterial.Sand && CorrespondingGroundHit.point != Vector3.zero){ if(Mathf.Abs(CorrespondingGroundHit.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHit.forwardSlip) > .35f || speed > 20){ if(!_wheelSlipSand[i].enableEmission && speed > 1) _wheelSlipSand[i].enableEmission = true; }else{ if(_wheelSlipSand[i].enableEmission) _wheelSlipSand[i].enableEmission = false; } }else if(_wheelSlipSand.Count > 0){ if(_wheelSlipSand[i].enableEmission) _wheelSlipSand[i].enableEmission = false; } } if(exhaustGas.Length > 0 && engineRunning){ for(int i = 0; i < exhaustGas.Length; i++){ if(speed < 30){ if(!exhaustGas[i].enableEmission) exhaustGas[i].enableEmission = true; if(gasInput > .05f){ exhaustGas[i].emissionRate = 25; exhaustGas[i].startSpeed = 5; exhaustGas[i].startSize = 5; }else{ exhaustGas[i].emissionRate = 5; exhaustGas[i].startSpeed = 1; exhaustGas[i].startSize = 3; } }else{ if(exhaustGas[i].enableEmission) exhaustGas[i].enableEmission = false; } } }else if(exhaustGas.Length > 0){ for(int i = 0; i < exhaustGas.Length; i++){ if(exhaustGas[i].enableEmission) exhaustGas[i].enableEmission = false; } } }
public void SetSkidVolume(AudioClip clip, GroundMaterial ground, float minSpeed){ WheelHit CorrespondingGroundHitF; FrontRightWheelCollider.GetGroundHit( out CorrespondingGroundHitF ); WheelHit CorrespondingGroundHitR; RearRightWheelCollider.GetGroundHit( out CorrespondingGroundHitR ); if(skidSound.clip != clip){ skidSound.clip = clip; skidSound.Play(); } if(ground == GroundMaterial.Asphalt){ if(Mathf.Abs(CorrespondingGroundHitF.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHitR.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHitF.forwardSlip) > .7f || Mathf.Abs(CorrespondingGroundHitR.forwardSlip) > .7f){ if(rigid.velocity.magnitude > 1f) skidSound.volume = Mathf.Clamp((Mathf.Abs(CorrespondingGroundHitF.sidewaysSlip) + Mathf.Abs(CorrespondingGroundHitR.sidewaysSlip) / 10f) + (Mathf.Abs(CorrespondingGroundHitF.forwardSlip) + Mathf.Abs(CorrespondingGroundHitR.forwardSlip) / 2f), 0f, 1f); else skidSound.volume -= Time.deltaTime * 1.5f; }else{ skidSound.volume -= Time.deltaTime * 1.5f; } } if(ground == GroundMaterial.Sand){ if(Mathf.Abs(CorrespondingGroundHitF.sidewaysSlip) > .2f || Mathf.Abs(CorrespondingGroundHitR.sidewaysSlip) > .2f || Mathf.Abs(CorrespondingGroundHitF.forwardSlip) > .7f || Mathf.Abs(CorrespondingGroundHitR.forwardSlip) > .7f || rigid.velocity.magnitude > 5f){ if(rigid.velocity.magnitude > 1f) skidSound.volume = Mathf.Clamp(((Mathf.Abs(CorrespondingGroundHitF.sidewaysSlip) + Mathf.Abs(CorrespondingGroundHitR.sidewaysSlip)) / 10f) + (Mathf.Abs(CorrespondingGroundHitF.forwardSlip) + Mathf.Abs(CorrespondingGroundHitR.forwardSlip) / 2f), minSpeed, 1f); else skidSound.volume -= Time.deltaTime * 1.25f; }else{ skidSound.volume -= Time.deltaTime * 1.25f; } } if(ground == GroundMaterial.Grass){ if(Mathf.Abs(CorrespondingGroundHitF.sidewaysSlip) > .2f || Mathf.Abs(CorrespondingGroundHitR.sidewaysSlip) > .2f || Mathf.Abs(CorrespondingGroundHitF.forwardSlip) > .7f || Mathf.Abs(CorrespondingGroundHitR.forwardSlip) > .7f || rigid.velocity.magnitude > 5f){ if(rigid.velocity.magnitude > 1f) skidSound.volume = Mathf.Clamp(((Mathf.Abs(CorrespondingGroundHitF.sidewaysSlip) + Mathf.Abs(CorrespondingGroundHitR.sidewaysSlip)) / 10f) + (Mathf.Abs(CorrespondingGroundHitF.forwardSlip) + Mathf.Abs(CorrespondingGroundHitR.forwardSlip) / 2f), minSpeed, 1f); else skidSound.volume -= Time.deltaTime * 1.25f; }else{ skidSound.volume -= Time.deltaTime * 1.25f; } } }
public void GroundPhysicsMaterial (){ if(!skidSound) return; WheelHit CorrespondingGroundHitF; FrontRightWheelCollider.GetGroundHit( out CorrespondingGroundHitF ); WheelHit CorrespondingGroundHitR; RearRightWheelCollider.GetGroundHit( out CorrespondingGroundHitR ); RaycastHit hit; float minimumSpeedForSkid = 0f; if(Physics.Raycast(FrontRightWheelCollider.transform.position, -FrontRightWheelCollider.transform.up, out hit)){ if(UseTerrainSplatMapForGroundPhysic && hit.transform.gameObject.GetComponent<TerrainCollider>()){ if(TerrainSurface.GetTextureMix(transform.position)[0] > .5f){ _groundMaterial = GroundMaterial.Asphalt; SetSkidVolume(asphaltSkidClip, _groundMaterial, 0f); }else if(TerrainSurface.GetTextureMix(transform.position)[1] > .5f){ minimumSpeedForSkid = Mathf.Lerp (0f, .35f, speed / 35f); _groundMaterial = GroundMaterial.Sand; SetSkidVolume(sandSkidClip, _groundMaterial, minimumSpeedForSkid); }else if(TerrainSurface.GetTextureMix(transform.position)[2] > .5f){ minimumSpeedForSkid = Mathf.Lerp (0f, .35f, speed / 35f); _groundMaterial = GroundMaterial.Grass; SetSkidVolume(grassSkidClip, _groundMaterial, minimumSpeedForSkid); } return; } if(hit.collider.material.name == grassPhysicsMaterial.name + " (Instance)"){ minimumSpeedForSkid = Mathf.Lerp (0f, .35f, speed / 35f); _groundMaterial = GroundMaterial.Grass; SetSkidVolume(grassSkidClip, _groundMaterial, minimumSpeedForSkid); }else if(hit.collider.material.name == sandPhysicsMaterial.name + " (Instance)"){ minimumSpeedForSkid = Mathf.Lerp (0f, .35f, speed / 35f); _groundMaterial = GroundMaterial.Sand; SetSkidVolume(sandSkidClip, _groundMaterial, minimumSpeedForSkid); }else{ _groundMaterial = GroundMaterial.Asphalt; SetSkidVolume(asphaltSkidClip, _groundMaterial, 0f); } }else{ _groundMaterial = GroundMaterial.Asphalt; SetSkidVolume(asphaltSkidClip, _groundMaterial, 0f); } }
public void GroundPhysicsMaterial (){ if(sleepingRigid) return; WheelHit wheelhit; RearLeftWheelCollider.GetGroundHit(out wheelhit); if(RearLeftWheelCollider.GetGroundHit(out wheelhit)){ if(asphaltPhysicsMaterial){ if(wheelhit.collider.material.name == asphaltPhysicsMaterial.name + " (Instance)") _groundMaterial = GroundMaterial.Asphalt; }if(grassPhysicsMaterial){ if(wheelhit.collider.material.name == grassPhysicsMaterial.name + " (Instance)") _groundMaterial = GroundMaterial.Grass; }if(sandPhysicsMaterial){ if(wheelhit.collider.material.name == sandPhysicsMaterial.name + " (Instance)") _groundMaterial = GroundMaterial.Sand; }if(UseTerrainSplatMapForGroundPhysics){ if(wheelhit.collider.material.name == terrainPhysicsMaterial.name + " (Instance)"){ if(TerrainSurface.GetTextureMix(RearLeftWheelCollider.transform.position)[terrainSplatMapAsphaltIndex] > .5f){ _groundMaterial = GroundMaterial.Asphalt; }else if(TerrainSurface.GetTextureMix(RearLeftWheelCollider.transform.position)[terrainSplatMapGrassIndex] > .5f){ _groundMaterial = GroundMaterial.Grass; }else if(TerrainSurface.GetTextureMix(RearLeftWheelCollider.transform.position)[terrainSplatMapSandIndex] > .5f){ _groundMaterial = GroundMaterial.Sand; }else{ _groundMaterial = GroundMaterial.Asphalt; } }else{ _groundMaterial = GroundMaterial.Asphalt; } }else{ _groundMaterial = GroundMaterial.Asphalt; } } if(_groundMaterial == GroundMaterial.Asphalt) SkidSound(asphaltSkidClip); else if(_groundMaterial == GroundMaterial.Grass) SkidSound(grassSkidClip); else if(_groundMaterial == GroundMaterial.Sand) SkidSound(sandSkidClip); }
void SetRoad(int direction, bool state) { roads[direction] = state; GroundMaterial.SetToMud(this, ref tile); Refresh(); }