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 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; }
private IEnumerator PlaceGhostRoutine(bool chain) { BuildingTypes bType = this.CurrentBlueprint._type; yield return(null); if (this.CreateMode) { this.ShownPlace = false; this.CreateMode = false; if (!this.ToolsShown) { base.SendMessage("BuildToolsTut"); this.ToolsShown = true; } TreeStructure ts = this._currentGhost.GetComponentInChildren <TreeStructure>(); if (ts && this.TargetTree) { if (this.TargetTree.CompareTag("conTree")) { ts.TreeId = this.TargetTree.parent.GetComponent <TreeHealth>().LodTree.GetComponentInChildren <CoopTreeId>().Id; } else { ts.TreeId = this.TargetTree.GetComponent <TreeHealth>().LodTree.GetComponentInChildren <CoopTreeId>().Id; } ts.enabled = true; if (!BoltNetwork.isRunning) { Scene.ActiveMB.StartCoroutine(ts.OnDeserialized()); } } CoopConstructionEx coopEx = this._currentGhost.GetComponent <CoopConstructionEx>(); WallArchitect wallArch = this.CurrentGhost.GetComponent <WallArchitect>(); ICoopTokenConstruction tokenConstruction = this._currentGhost.GetComponent <ICoopTokenConstruction>(); this.ParentEntity = this.GetParentEntity(this._currentGhost); if (BoltNetwork.isRunning && !wallArch) { BoltEntity component = this._currentGhost.GetComponent <BoltEntity>(); if (tokenConstruction != null) { PlaceFoundationEx placeFoundationEx = PlaceFoundationEx.Create(GlobalTargets.OnlyServer); placeFoundationEx.Position = this._currentGhost.transform.position; placeFoundationEx.Rotation = this._currentGhost.transform.rotation; placeFoundationEx.Prefab = component.prefabId; placeFoundationEx.Token = tokenConstruction.CustomToken; placeFoundationEx.Parent = this.ParentEntity; placeFoundationEx.Send(); UnityEngine.Object.Destroy(this._currentGhost); } else if (coopEx) { coopEx.SendMessage("OnSerializing"); CoopConstructionExToken coopConstructionExToken = this.GetCoopConstructionExToken(coopEx, this.ParentEntity); PlaceFoundationEx placeFoundationEx2 = PlaceFoundationEx.Create(GlobalTargets.OnlyServer); placeFoundationEx2.Parent = this.ParentEntity; placeFoundationEx2.Position = this._currentGhost.transform.position; placeFoundationEx2.Rotation = this._currentGhost.transform.rotation; placeFoundationEx2.Prefab = component.prefabId; placeFoundationEx2.Token = coopConstructionExToken; placeFoundationEx2.Send(); UnityEngine.Object.Destroy(this._currentGhost); } else if (!this._currentGhost.GetComponent(typeof(IAnchorableStructure)) && component) { this._currentGhost.AddComponent <CoopDestroyPredictedGhost>(); this._currentGhost.AddComponent <destroyAfter>().destroyTime = 2f; PlaceConstruction placeConstruction = PlaceConstruction.Create(GlobalTargets.OnlyServer); placeConstruction.Parent = this.ParentEntity; placeConstruction.PrefabId = component.prefabId; placeConstruction.Position = this._currentGhost.transform.position; placeConstruction.Rotation = this._currentGhost.transform.rotation; if (ts) { placeConstruction.TreeIndex = ts.TreeId; } placeConstruction.Send(); this._currentGhost.SendMessage("OnPlacingRemotely", SendMessageOptions.DontRequireReceiver); } else { this._currentGhost.SendMessage("OnPlaced", false, SendMessageOptions.DontRequireReceiver); } } else { this._currentGhost.SendMessage("OnPlaced", false, SendMessageOptions.DontRequireReceiver); this._currentGhost.transform.Find("Trigger").gameObject.SetActive(true); Transform transform = this._currentGhost.transform.Find("LastBuiltLocation"); if (transform) { transform.gameObject.SetActive(true); } if (this.ParentEntity) { DynamicBuilding component2 = this.ParentEntity.GetComponent <DynamicBuilding>(); this._currentGhost.transform.parent = ((!component2 || !component2._parentOverride) ? this.ParentEntity.transform : component2._parentOverride); } } this.ClearReferences(!chain); LocalPlayer.Sfx.PlayPlaceGhost(); this.RefreshGrabber(); yield return(YieldPresets.WaitPointFiveSeconds); if (chain) { this.MultiPlaceAction(bType); } } 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 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; }
protected virtual Transform SpawnEdge(WallArchitect.Edge edge) { Transform transform = new GameObject("WallEdge").transform; transform.transform.position = edge._p1; 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 vector = 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 vector2 = new Vector3(1f, 1f, 0.31f + (localScale.z - 1f) / 2f); float num = 1f - vector2.z / localScale.z; for (int j = 0; j < 5; j++) { Transform transform3 = this.NewLog(vector, rotation); transform3.parent = transform2; this._newPool.Enqueue(transform3); transform3.localScale = localScale; vector += b; } } return transform; }