protected void RenderPlacementHelpers() { StructureComponent structureToPlacePrefab = base.datablock.structureToPlacePrefab; this._master = null; this._placePos = Vector3.zero; this._placeRot = Quaternion.identity; this.validLocation = false; float axis = Input.GetAxis("Mouse ScrollWheel"); if (axis > 0f) { this.desiredRotation *= Quaternion.AngleAxis(90f, Vector3.up); } else if (axis < 0f) { this.desiredRotation *= Quaternion.AngleAxis(-90f, Vector3.up); } Character character = base.character; if (character != null) { RaycastHit hit; Ray eyesRay = character.eyesRay; float distance = (structureToPlacePrefab.type != StructureComponent.StructureComponentType.Ceiling) ? 8f : 4f; Vector3 zero = Vector3.zero; Vector3 up = Vector3.up; Vector3 vector3 = Vector3.zero; bool flag = false; if (Physics.Raycast(eyesRay, out hit, distance)) { vector3 = zero = hit.point; up = hit.normal; flag = true; } else { flag = false; vector3 = zero = eyesRay.origin + ((Vector3)(eyesRay.direction * distance)); } switch (structureToPlacePrefab.type) { case StructureComponent.StructureComponentType.Ceiling: case StructureComponent.StructureComponentType.Foundation: case StructureComponent.StructureComponentType.Ramp: zero.y -= 3.5f; break; } bool flag2 = false; bool flag3 = false; Vector3 vector4 = zero; Quaternion quaternion = TransformHelpers.LookRotationForcedUp(character.eyesAngles.forward, Vector3.up) * this.desiredRotation; foreach (StructureMaster master in StructureMaster.RayTestStructures(eyesRay)) { if (master != null) { int num4; int num5; int num6; master.GetStructureSize(out num4, out num5, out num6); this._placePos = StructureMaster.SnapToGrid(master.transform, zero, true); this._placeRot = TransformHelpers.LookRotationForcedUp(master.transform.forward, master.transform.transform.up) * this.desiredRotation; if (!flag3) { vector4 = this._placePos; quaternion = this._placeRot; flag3 = true; } if (structureToPlacePrefab.CheckLocation(master, this._placePos, this._placeRot)) { this._master = master; flag2 = true; break; } } } if (flag2) { this.validLocation = true; } else if (structureToPlacePrefab.type != StructureComponent.StructureComponentType.Foundation) { this._placePos = vector4; this._placeRot = quaternion; this.validLocation = false; } else if (!flag || !(hit.collider is TerrainCollider)) { this._placePos = vector4; this._placeRot = quaternion; this.validLocation = false; } else { bool flag4 = false; foreach (StructureMaster master2 in StructureMaster.AllStructuresWithBounds) { if (master2.containedBounds.Intersects(new Bounds(zero, new Vector3(5f, 5f, 4f)))) { flag4 = true; break; } } if (!flag4) { this._placePos = zero; this._placeRot = TransformHelpers.LookRotationForcedUp(character.eyesAngles.forward, Vector3.up) * this.desiredRotation; this.validLocation = true; } } if (!base.datablock.CheckBlockers(this._placePos)) { this.validLocation = false; } Color red = Color.red; if (this.validLocation) { red = Color.green; } red.a = 0.5f + (Mathf.Abs(Mathf.Sin(Time.time * 8f)) * 0.25f); if (this._materialProps != null) { this._materialProps.Clear(); this._materialProps.AddColor("_EmissionColor", red); this._materialProps.AddVector("_MainTex_ST", new Vector4(1f, 1f, 0f, Mathf.Repeat(Time.time, 30f))); } if (!this.validLocation) { this._placePos = zero; } this.RenderDeployPreview(this._placePos, this._placeRot); } }
protected void RenderPlacementHelpers() { RaycastHit raycastHit; int num; int num1; int num2; StructureComponent structureComponent = this.datablock.structureToPlacePrefab; this._master = null; this._placePos = Vector3.zero; this._placeRot = Quaternion.identity; this.validLocation = false; float axis = Input.GetAxis("Mouse ScrollWheel"); if (axis > 0f) { this.desiredRotation = this.desiredRotation * Quaternion.AngleAxis(90f, Vector3.up); } else if (axis < 0f) { this.desiredRotation = this.desiredRotation * Quaternion.AngleAxis(-90f, Vector3.up); } Character character = base.character; if (character == null) { return; } Ray ray = character.eyesRay; float single = (structureComponent.type != StructureComponent.StructureComponentType.Ceiling ? 8f : 4f); Vector3 vector3 = Vector3.zero; Vector3 vector31 = Vector3.up; Vector3 vector32 = Vector3.zero; bool flag = false; if (!Physics.Raycast(ray, out raycastHit, single)) { flag = false; Vector3 vector33 = ray.origin + (ray.direction * single); vector3 = vector33; vector32 = vector33; } else { Vector3 vector34 = raycastHit.point; vector3 = vector34; vector32 = vector34; vector31 = raycastHit.normal; flag = true; } switch (structureComponent.type) { case StructureComponent.StructureComponentType.Ceiling: case StructureComponent.StructureComponentType.Foundation: case StructureComponent.StructureComponentType.Ramp: { vector3.y = vector3.y - 3.5f; goto case StructureComponent.StructureComponentType.WindowWall; } case StructureComponent.StructureComponentType.Stairs: case StructureComponent.StructureComponentType.WindowWall: { bool flag1 = false; bool flag2 = false; Vector3 vector35 = vector3; Angle2 angle2 = character.eyesAngles; Quaternion quaternion = TransformHelpers.LookRotationForcedUp(angle2.forward, Vector3.up) * this.desiredRotation; StructureMaster[] structureMasterArray = StructureMaster.RayTestStructures(ray); for (int i = 0; i < (int)structureMasterArray.Length; i++) { StructureMaster structureMaster = structureMasterArray[i]; if (structureMaster) { structureMaster.GetStructureSize(out num, out num1, out num2); this._placePos = StructureMaster.SnapToGrid(structureMaster.transform, vector3, true); this._placeRot = TransformHelpers.LookRotationForcedUp(structureMaster.transform.forward, structureMaster.transform.transform.up) * this.desiredRotation; if (!flag2) { vector35 = this._placePos; quaternion = this._placeRot; flag2 = true; } if (structureComponent.CheckLocation(structureMaster, this._placePos, this._placeRot)) { this._master = structureMaster; flag1 = true; break; } } } if (flag1) { this.validLocation = true; } else if (structureComponent.type != StructureComponent.StructureComponentType.Foundation) { this._placePos = vector35; this._placeRot = quaternion; this.validLocation = false; } else if (!flag || !(raycastHit.collider is TerrainCollider)) { this._placePos = vector35; this._placeRot = quaternion; this.validLocation = false; } else { bool flag3 = false; foreach (StructureMaster allStructuresWithBound in StructureMaster.AllStructuresWithBounds) { if (!allStructuresWithBound.containedBounds.Intersects(new Bounds(vector3, new Vector3(5f, 5f, 4f)))) { continue; } flag3 = true; break; } if (!flag3) { this._placePos = vector3; Angle2 angle21 = character.eyesAngles; this._placeRot = TransformHelpers.LookRotationForcedUp(angle21.forward, Vector3.up) * this.desiredRotation; this.validLocation = true; } } if (!this.datablock.CheckBlockers(this._placePos)) { this.validLocation = false; } Color color = Color.red; if (this.validLocation) { color = Color.green; } color.a = 0.5f + Mathf.Abs(Mathf.Sin(Time.time * 8f)) * 0.25f; if (this._materialProps != null) { this._materialProps.Clear(); this._materialProps.AddColor("_EmissionColor", color); this._materialProps.AddVector("_MainTex_ST", new Vector4(1f, 1f, 0f, Mathf.Repeat(Time.time, 30f))); } if (!this.validLocation) { this._placePos = vector3; } this.RenderDeployPreview(this._placePos, this._placeRot); return; } default: { goto case StructureComponent.StructureComponentType.WindowWall; } } }