private WallArchitect.Edge CalcEdge(Vector3 p1, Vector3 p2) { int num = 0; Vector3 a = p1; WallArchitect.Edge edge = new WallArchitect.Edge { _p1 = p1, _p2 = p2 }; bool aboveTerrain = p1.y - Terrain.activeTerrain.SampleHeight(p1) > -1f; edge._hlength = Vector3.Scale(p2 - p1, new Vector3(1f, 0f, 1f)).magnitude; edge._segments = new WallArchitect.HorizontalSegment[Mathf.CeilToInt(edge._hlength / this._maxSegmentHorizontalLength)]; float d = edge._hlength / (float)edge._segments.Length; float num2 = this._logWidth / 2f * 0.98f; Vector3 b = (p2 - p1).normalized * d; Vector3 vector = p1; for (int i = 0; i < edge._segments.Length; i++) { bool flag = false; WallArchitect.HorizontalSegment horizontalSegment = new WallArchitect.HorizontalSegment(); horizontalSegment._p1 = vector; horizontalSegment._p2 = ((i + 1 != edge._segments.Length) ? this.GetSegmentPointFloorPosition(aboveTerrain, vector + b, out flag) : p2); horizontalSegment._axis = (horizontalSegment._p2 - horizontalSegment._p1).normalized * d; horizontalSegment._length = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2); if (num == 1 && !flag) { Vector3 vector2 = Vector3.Lerp(a, horizontalSegment._p2, 0.5f); vector2.y += this.SegmentPointTestOffset / 2f; horizontalSegment._p1 = vector2; vector2.y += num2; edge._segments[i - 1]._p2 = vector2; } if (flag && edge._segments.Length == 2) { num++; } else { num = 0; a = horizontalSegment._p2; } vector = horizontalSegment._p2; WallArchitect.HorizontalSegment horizontalSegment2 = horizontalSegment; horizontalSegment2._p1.y = horizontalSegment2._p1.y + num2; WallArchitect.HorizontalSegment horizontalSegment3 = horizontalSegment; horizontalSegment3._p2.y = horizontalSegment3._p2.y + num2; edge._segments[i] = horizontalSegment; } return(edge); }
private IStructureSupport GetSegmentSupport(WallArchitect.HorizontalSegment hs) { RaycastHit raycastHit; IStructureSupport structureSupport; if (Physics.SphereCast(Vector3.Lerp(hs._p1, hs._p2, 0.5f) + new Vector3(0f, 0.5f, 0f), 0.5f, Vector3.down, out raycastHit, 1f, this._caster._anchorLayers)) { structureSupport = raycastHit.collider.GetComponentInParent <IStructureSupport>(); } else { structureSupport = null; } return((structureSupport == null) ? this.CurrentSupport : structureSupport); }
private bool CheckForDoubledUpGhost(WallArchitect.HorizontalSegment hs) { float maxDistance = 1f; Vector3 vector = Vector3.Cross((hs._p2 - hs._p1).normalized, Vector3.up) * 0.75f; Vector3 origin = Vector3.Lerp(hs._p1, hs._p2, 0.5f) + Vector3.up - vector; origin.y += 0.1f; int mask = LayerMask.GetMask(new string[] { "PickUp", "Prop" }); int num = 1 << LayerMask.NameToLayer("PickUp") | 1 << LayerMask.NameToLayer("Prop"); RaycastHit raycastHit; if (Physics.SphereCast(origin, 0.25f, vector, out raycastHit, maxDistance, mask)) { Collider collider = raycastHit.collider; if (collider.transform.parent) { WallChunkArchitect component = collider.transform.parent.GetComponent <WallChunkArchitect>(); if (component) { Vector3 normalized = (component.P1 - component.P2).normalized; float num2 = Vector3.Dot(normalized, (hs._p1 - hs._p2).normalized); if (Mathf.Abs(num2) > 0.98f) { float num3 = Vector3.Dot(normalized, (hs._p1 - component.P1).normalized); float num4 = Vector3.Dot(-normalized, (hs._p2 - component.P2).normalized); if (num2 > 0f) { if (num3 <= 0f || num4 <= 0f) { return(false); } } else if (-num3 <= 0f || -num4 <= 0f) { return(false); } } } } } return(true); }
protected override Transform SpawnEdge(WallArchitect.Edge edge) { Transform transform = new GameObject("RockPathEdge").transform; transform.transform.position = edge._p1; transform.LookAt(edge._p2); for (int i = 0; i < edge._segments.Length; i++) { WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i]; Vector3 a = horizontalSegment._p2 - horizontalSegment._p1; Vector3 normalized = Vector3.Scale(a, new Vector3(1f, 0f, 1f)).normalized; Transform transform2 = new GameObject("S" + i).transform; transform2.parent = transform; transform2.position = horizontalSegment._p1; transform2.LookAt(horizontalSegment._p2); horizontalSegment._root = transform2; Vector3 vector = horizontalSegment._p1 + transform2.right * (float)this._width; Vector3 vector2 = horizontalSegment._p1 - transform2.right * (float)this._width; float num = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2); int num2 = Mathf.RoundToInt(num / this._logWidth) + 1; if (num2 < 1) { num2 = 1; } Vector3 vector3 = normalized * (num / (float)num2); vector += vector3 / 2f; vector2 += vector3 / 2f; Terrain activeTerrain = Terrain.activeTerrain; for (int j = 0; j < num2; j++) { vector.y = activeTerrain.SampleHeight(vector); Transform transform3 = base.NewLog(vector, transform2.rotation); transform3.localScale = Vector3.one; transform3.parent = transform2; this._newPool.Enqueue(transform3); vector += vector3; vector2.y = activeTerrain.SampleHeight(vector2); Transform transform4 = base.NewLog(vector2, transform2.rotation); transform4.localScale = Vector3.one; transform4.parent = transform2; this._newPool.Enqueue(transform4); vector2 += vector3; } } return(transform); }
protected override Transform SpawnEdge(WallArchitect.Edge edge) { Transform transform = new GameObject("RockFenceEdge").transform; transform.transform.position = edge._p1; transform.LookAt(edge._p2); for (int i = 0; i < edge._segments.Length; i++) { WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i]; Vector3 vector = horizontalSegment._p1; Vector3 vector2 = horizontalSegment._p2 - horizontalSegment._p1; Vector3 normalized = Vector3.Scale(vector2, new Vector3(1f, 0f, 1f)).normalized; float y = Mathf.Tan(Vector3.Angle(vector2, normalized) * 0.0174532924f) * this._offset; Quaternion rotation = Quaternion.LookRotation(-vector2); Transform transform2 = new GameObject("S" + i).transform; transform2.parent = transform; transform2.position = horizontalSegment._p1; transform2.LookAt(horizontalSegment._p2); horizontalSegment._root = transform2; bool flag = horizontalSegment._p1.y < horizontalSegment._p2.y; float num = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2); int j = Mathf.RoundToInt(num / this._offset); if (j < 1) { j = 1; } Vector3 a = normalized * this._offset; a.y = y; if (!flag) { a.y *= -1f; } vector.y -= 0.15f; while (j > 0) { int num2 = Mathf.Min(j, 5); j -= num2; Transform transform3 = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.RockFenceChunksGhostPrefabs[num2 - 1], vector, rotation); transform3.GetComponentInChildren <Renderer>().sharedMaterial = Create.CurrentGhostMat; transform3.parent = transform2; vector += a * (float)num2; } } return(transform); }
protected override Transform SpawnEdge(WallArchitect.Edge edge) { Transform transform = new GameObject("WallDefensiveEdge").transform; transform.transform.position = edge._p1; Vector3 vector = edge._p2 - edge._p1; Vector3 normalized = Vector3.Scale(vector, new Vector3(1f, 0f, 1f)).normalized; float y = Mathf.Tan(Vector3.Angle(vector, normalized) * 0.0174532924f) * this._logWidth; Quaternion rotation = Quaternion.LookRotation(Vector3.forward); for (int i = 0; i < edge._segments.Length; i++) { WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i]; Vector3 vector2 = horizontalSegment._p1; Transform transform2 = new GameObject("Segment" + i).transform; transform2.parent = transform; horizontalSegment._root = transform2; transform2.position = horizontalSegment._p1; float num = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2); int num2 = Mathf.RoundToInt(num / this._logWidth); Vector3 b = normalized * num / (float)num2; b.y = y; if (vector.y < 0f) { b.y *= -1f; } for (int j = 0; j < num2; j++) { Transform transform3 = base.NewLog(vector2, rotation); transform3.parent = transform2; this._newPool.Enqueue(transform3); vector2 += b; } } return(transform); }
protected virtual Transform SpawnEdge(WallArchitect.Edge edge) { Transform transform = new GameObject("WallEdge").transform; transform.transform.position = edge._p1; Vector3 vector = edge._p2 - edge._p1; int num = Mathf.RoundToInt(this._currentHeight); if (this._autofillmode || Vector3.Distance(edge._p1, edge._p2) > this._logWidth * 3.5f) { Vector3 b = new Vector3(0f, this._logWidth * 0.95f, 0f); for (int i = 0; i < edge._segments.Length; i++) { WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i]; Quaternion rotation = Quaternion.LookRotation(horizontalSegment._axis); Vector3 vector2 = horizontalSegment._p1; Transform transform2 = new GameObject("Segment" + i).transform; transform2.parent = transform; transform2.LookAt(horizontalSegment._axis); horizontalSegment._root = transform2; transform2.position = horizontalSegment._p1; Vector3 localScale = new Vector3(1f, 1f, horizontalSegment._length / this._logLength); Vector3 vector3 = new Vector3(1f, 1f, 0.31f + (localScale.z - 1f) / 2f); float num2 = 1f - vector3.z / localScale.z; for (int j = 0; j < num; j++) { Transform transform3 = this.NewLog(vector2, rotation); transform3.parent = transform2; this._newPool.Enqueue(transform3); transform3.localScale = localScale; vector2 += b; } } } else { Vector3 normalized = Vector3.Scale(vector, new Vector3(1f, 0f, 1f)).normalized; float y = Mathf.Tan(Vector3.Angle(vector, normalized) * 0.0174532924f) * this._logWidth; Quaternion rotation2 = Quaternion.LookRotation(Vector3.up); Vector3 localScale2 = new Vector3(1f, 1f, (float)num * 0.95f * this._logWidth / this._logLength); float num3 = this._logWidth / 2f * 0.98f; for (int k = 0; k < edge._segments.Length; k++) { WallArchitect.HorizontalSegment horizontalSegment2 = edge._segments[k]; Vector3 vector4 = horizontalSegment2._p1; vector4.y -= num3; Transform transform4 = new GameObject("Segment" + k).transform; transform4.parent = transform; horizontalSegment2._root = transform4; transform4.position = horizontalSegment2._p1; float num4 = Vector3.Distance(horizontalSegment2._p1, horizontalSegment2._p2); int num5 = Mathf.Max(Mathf.RoundToInt((num4 - this._logWidth * 0.96f / 2f) / this._logWidth), 1); Vector3 vector5 = normalized * this._logWidth * 0.98f; vector5.y = y; vector4 += vector5 / 2f; if (vector.y < 0f) { vector5.y *= -1f; } for (int l = 0; l < num5; l++) { Transform transform5 = this.NewLog(vector4, rotation2); transform5.parent = transform4; this._newPool.Enqueue(transform5); vector4 += vector5; transform5.localScale = localScale2; } } } return(transform); }
private IEnumerator OnPlaced() { base.enabled = false; yield return(null); if (!this._autofillmode && this.CanLock && this._multiPointsPositions.Last <Vector3>() != this._multiPointsPositions.First <Vector3>()) { this.LockCurrentPoint(); } if (Scene.HudGui) { Scene.HudGui.WallConstructionIcons.Shutdown(); } if (this._tmpEdge != null && this._tmpEdge._root) { this._tmpEdge._root.parent = null; UnityEngine.Object.Destroy(this._tmpEdge._root.gameObject); } LocalPlayer.Create.Grabber.ClosePlace(); int chunkCount = 0; float lengthCount = 0f; for (int i = 0; i < this._edges.Count; i++) { WallArchitect.Edge edge = this._edges[i]; float height = (!this._autofillmode) ? edge._height : this._currentHeight; lengthCount += edge._hlength; for (int j = 0; j < edge._segments.Length; j++) { WallArchitect.HorizontalSegment horizontalSegment = edge._segments[j]; if (this.CheckForDoubledUpGhost(horizontalSegment)) { IStructureSupport segmentSupport = this.GetSegmentSupport(horizontalSegment); if (BoltNetwork.isRunning) { PlaceWallChunk placeWallChunk = PlaceWallChunk.Create(GlobalTargets.OnlyServer); CoopWallChunkToken coopWallChunkToken = new CoopWallChunkToken(); coopWallChunkToken.P1 = horizontalSegment._p1; coopWallChunkToken.P2 = horizontalSegment._p2; coopWallChunkToken.PointsPositions = this.MultiPointsPositions.ToArray(); coopWallChunkToken.Additions = WallChunkArchitect.Additions.Wall; coopWallChunkToken.Height = height; placeWallChunk.parent = ((segmentSupport == null) ? base.transform.GetComponentInParent <BoltEntity>() : (segmentSupport as Component).GetComponentInParent <BoltEntity>()); placeWallChunk.token = coopWallChunkToken; placeWallChunk.prefab = this.ChunkPrefab.GetComponent <BoltEntity>().prefabId; placeWallChunk.support = null; placeWallChunk.Send(); } else { WallChunkArchitect wallChunkArchitect = UnityEngine.Object.Instantiate <WallChunkArchitect>(this.ChunkPrefab); wallChunkArchitect.transform.parent = ((segmentSupport == null) ? base.transform.parent : (segmentSupport as Component).transform); wallChunkArchitect.transform.position = horizontalSegment._p1; wallChunkArchitect.transform.LookAt(horizontalSegment._p2); wallChunkArchitect.MultipointPositions = this._multiPointsPositions; wallChunkArchitect.P1 = horizontalSegment._p1; wallChunkArchitect.P2 = horizontalSegment._p2; wallChunkArchitect.CurrentSupport = segmentSupport; wallChunkArchitect.Height = height; } chunkCount++; } } } if (!base.GetType().IsSubclassOf(typeof(WallArchitect))) { EventRegistry.Achievements.Publish(TfEvent.Achievements.PlacedWall, Mathf.FloorToInt(lengthCount)); } if (!BoltNetwork.isRunning) { yield return(null); yield return(null); yield return(null); yield return(null); UnityEngine.Object.Destroy(base.gameObject); } else { CoopDestroyPredictedGhost coopDestroyPredictedGhost = base.gameObject.AddComponent <CoopDestroyPredictedGhost>(); coopDestroyPredictedGhost.count = (float)chunkCount; coopDestroyPredictedGhost.delay = 0.005f; base.gameObject.AddComponent <destroyAfter>().destroyTime = 2f; } yield break; }
protected override Transform SpawnEdge(WallArchitect.Edge edge) { Transform transform = new GameObject("StickFenceEdge").transform; transform.transform.position = edge._p1; transform.LookAt(edge._p2); Quaternion rotation = Quaternion.LookRotation(Vector3.forward); Quaternion rhs = Quaternion.FromToRotation(Vector3.up, Vector3.forward); for (int i = 0; i < edge._segments.Length; i++) { WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i]; Vector3 vector = horizontalSegment._p1; Vector3 vector2 = horizontalSegment._p2 - horizontalSegment._p1; Vector3 normalized = Vector3.Scale(vector2, new Vector3(1f, 0f, 1f)).normalized; float y = Mathf.Tan(Vector3.Angle(vector2, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread; Transform transform2 = new GameObject("S" + i).transform; transform2.parent = transform; transform2.position = horizontalSegment._p1; transform2.LookAt(horizontalSegment._p2); horizontalSegment._root = transform2; bool flag = horizontalSegment._p1.y < horizontalSegment._p2.y; float num = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2); int num2 = Mathf.RoundToInt(num / (this._logWidth * (float)this._spread)); if (num2 > 1) { num2--; } else { num2 = 1; } Vector3 vector3 = normalized * (num / (float)num2); vector3.y = y; if (!flag) { vector3.y *= -1f; } vector += vector3 / 2f; for (int j = 0; j < num2; j++) { Transform transform3 = base.NewLog(vector, rotation); transform3.localScale = Vector3.one; transform3.parent = transform2; this._newPool.Enqueue(transform3); vector += vector3; } Vector3 vector4 = new Vector3(0f, this._logLength * 0.45f, this._logWidth / 2f); Vector3 vector5 = new Vector3(0f, this._logLength * 0.8f, this._logWidth / 2f); vector4 += vector3 / 2f; vector5 += vector3 / 2f; Vector3 localScale = new Vector3(1f, num * 0.335f, 1f); Quaternion rotation2 = Quaternion.LookRotation(transform2.forward) * rhs; Debug.DrawRay(horizontalSegment._p1 + vector4, -transform2.up, Color.red); Transform transform4 = base.NewLog(horizontalSegment._p1 + vector4, rotation2); transform4.parent = transform2; transform4.localScale = localScale; this._newPool.Enqueue(transform4); transform4 = base.NewLog(horizontalSegment._p1 + vector5, rotation2); transform4.parent = transform2; transform4.localScale = localScale; this._newPool.Enqueue(transform4); } return(transform); }
protected override Transform SpawnEdge(WallArchitect.Edge edge) { Transform transform = new GameObject("StickFenceEdge").transform; transform.transform.position = edge._p1; transform.LookAt(edge._p2); Quaternion quaternion = Quaternion.LookRotation(Vector3.forward); Quaternion rhs = Quaternion.FromToRotation(Vector3.up, Vector3.forward); for (int i = 0; i < edge._segments.Length; i++) { WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i]; Vector3 position = horizontalSegment._p1; Vector3 vector = Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.5f); Vector3 vector2 = new Vector3(0f, this._logLength, 0f); Vector3 vector3 = horizontalSegment._p2 - horizontalSegment._p1; Vector3 normalized = Vector3.Scale(vector3, new Vector3(1f, 0f, 1f)).normalized; float y = Mathf.Tan(Vector3.Angle(vector3, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread; Transform transform2 = new GameObject("S" + i).transform; transform2.parent = transform; transform2.position = horizontalSegment._p1; transform2.LookAt(horizontalSegment._p2); horizontalSegment._root = transform2; bool flag = horizontalSegment._p1.y < horizontalSegment._p2.y; float num = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2); int num2 = 4; Vector3 vector4 = normalized * (num / (float)num2); vector4.y = y; if (!flag) { vector4.y *= -1f; } for (int j = 0; j < num2; j++) { Transform transform3; switch (j) { case 0: transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.1f) + vector2 - horizontalSegment._p1) * rhs); Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.1f) + vector2, horizontalSegment._p1, Color.red); break; case 1: position = vector; transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.35f) + vector2 - vector) * rhs); Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.35f) + vector2, vector, Color.blue); break; case 2: position = vector; transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.7f) + vector2 - vector) * rhs); Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.7f) + vector2, vector, Color.green); break; default: position = horizontalSegment._p2; transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.9f) + vector2 - horizontalSegment._p2) * rhs); Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.9f) + vector2, horizontalSegment._p2, Color.yellow); break; } transform3.name = "v" + j; transform3.parent = transform2; this._newPool.Enqueue(transform3); } Vector3 vector5 = new Vector3(0f, this._logLength * 0.4f, this._logWidth / 2f); Vector3 b = vector5 + (horizontalSegment._p2 - horizontalSegment._p1) / 2f; Quaternion rotation = Quaternion.LookRotation(vector + vector2 * 0.6f - (horizontalSegment._p1 + vector5)) * rhs; Transform transform4 = base.NewLog(horizontalSegment._p1 + vector5, rotation); transform4.name = "h1"; transform4.parent = transform2; this._newPool.Enqueue(transform4); transform4 = base.NewLog(horizontalSegment._p1 + b, rotation); transform4.name = "h2"; transform4.parent = transform2; this._newPool.Enqueue(transform4); Quaternion rotation2 = Quaternion.LookRotation(horizontalSegment._p1 + vector2 * 0.8f - vector) * rhs; Transform transform5 = base.NewLog(vector, rotation2); transform5.name = "d1"; transform5.parent = transform2; this._newPool.Enqueue(transform5); transform5 = base.NewLog(horizontalSegment._p2, rotation2); transform5.name = "d2"; transform5.parent = transform2; this._newPool.Enqueue(transform5); } return(transform); }
private WallArchitect.Edge CalcEdge(Vector3 p1, Vector3 p2) { WallArchitect.Edge edge = new WallArchitect.Edge { _p1 = p1, _p2 = p2 }; edge._hlength = Vector3.Scale(p2 - p1, new Vector3(1f, 0f, 1f)).magnitude; edge._segments = new WallArchitect.HorizontalSegment[Mathf.CeilToInt(edge._hlength / this._maxSegmentHorizontalLength)]; float d = edge._hlength / (float)edge._segments.Length; float num = this._logWidth / 2f * 0.98f; Vector3 b = (p2 - p1).normalized * d; Vector3 vector = p1; for (int i = 0; i < edge._segments.Length; i++) { WallArchitect.HorizontalSegment horizontalSegment = new WallArchitect.HorizontalSegment(); horizontalSegment._p1 = vector; horizontalSegment._p2 = ((i + 1 != edge._segments.Length) ? this.GetSegmentPointFloorPosition(vector + b) : p2); horizontalSegment._axis = (horizontalSegment._p2 - horizontalSegment._p1).normalized * d; horizontalSegment._length = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2); vector = horizontalSegment._p2; WallArchitect.HorizontalSegment expr_13C_cp_0 = horizontalSegment; expr_13C_cp_0._p1.y = expr_13C_cp_0._p1.y + num; WallArchitect.HorizontalSegment expr_150_cp_0 = horizontalSegment; expr_150_cp_0._p2.y = expr_150_cp_0._p2.y + num; edge._segments[i] = horizontalSegment; } return edge; }