public int GetChunkIndex(FoundationChunkTier chunk) { for (int i = 0; i < this._chunks.Count; i++) { if (object.ReferenceEquals(this._chunks[i], chunk)) { return(i); } } return(-1); }
private GameObject SpawnEdge(FoundationArchitect.Edge edge, int edgeNum) { GameObject gameObject = new GameObject("Edge" + edgeNum); Transform transform = gameObject.transform; gameObject.transform.position = edge._p1; float num = edge._hlength / (float)edge._segments.Length; Vector3 localScale = new Vector3(1f, 1f, num / this._logLength); Vector3 localScale2 = new Vector3(1f, 1f, this.CalcDiagonalLength(1f, localScale.z)); Vector3 vector = edge._axis / 2f; Vector3 b = new Vector3(0f, this._logLength / 2f, 0f); Vector3 b2 = new Vector3(0f, this._logLength, 0f); Quaternion rotation = Quaternion.Euler(90f, 0f, 0f); Quaternion rotation2 = Quaternion.LookRotation(edge._axis); Vector3 forward = vector - b; Quaternion rotation3 = Quaternion.LookRotation(forward); float logStackScaleRatio = (this._maxScaleLogCost <= 0f) ? 0f : (this._maxLogScale / this._maxScaleLogCost); float num2 = 0f; Transform transform2 = transform; edge._totalLogs = 0; int num3 = this._edges.Take(edgeNum).Sum((FoundationArchitect.Edge e) => e._segments.Length); string[] array = new string[] { "SLTier1", "SLTier2", "SLTier3" }; float num4 = b2.y * (float)Mathf.CeilToInt(this.MaxHeight / b2.y / 3f) - 0.4f; for (int i = 0; i < edge._segments.Length; i++) { FoundationArchitect.HorizontalSegment horizontalSegment = edge._segments[i]; Vector3 vector2 = Vector3.zero; num2 = 0f; Transform transform3 = new GameObject(i.ToString()).transform; transform3.parent = transform; int j = 0; bool flag = this._wasBuilt; for (int k = 0; k < horizontalSegment._segments.Length; k++) { if (this.SegmentTierValidation(num3 + i, j)) { FoundationArchitect.VerticalSegment verticalSegment = horizontalSegment._segments[k]; if (flag) { flag = false; transform2 = new GameObject("t").transform; transform2.parent = transform3; transform2.position = horizontalSegment._p1 - vector2 + vector - new Vector3(0f, num4 / 2f, 0f); transform2.rotation = rotation2; transform2.tag = array[j]; BoxCollider boxCollider = transform2.gameObject.AddComponent <BoxCollider>(); boxCollider.size = new Vector3(1.1f, num4 + 0.4f, 4.8f * localScale.z); FoundationChunkTier foundationChunkTier = transform2.gameObject.AddComponent <FoundationChunkTier>(); foundationChunkTier._edgeNum = edgeNum; foundationChunkTier._segmentNum = i; foundationChunkTier._tierNum = j; this._chunks.Add(foundationChunkTier); transform2.gameObject.AddComponent <gridObjectBlocker>(); getStructureStrength getStructureStrength = transform2.gameObject.AddComponent <getStructureStrength>(); getStructureStrength._strength = getStructureStrength.strength.strong; } if (edge._isFirst && i == 0) { edge._totalLogs++; Transform transform4 = this.NewLog(edge._p1 - vector2 - b, rotation); if (!this._wasBuilt) { this.StackLogsByScale(ref num2, logStackScaleRatio, 1f, ref transform2, transform4, transform3); } else { transform4.parent = transform2; } transform4.localScale = Vector3.one; this._newPool.Push(transform4); } if (!edge._isClosing || i + 1 < edge._segments.Length) { edge._totalLogs++; Transform transform5 = this.NewLog(horizontalSegment._p2 - vector2 - b, rotation); if (!this._wasBuilt) { this.StackLogsByScale(ref num2, logStackScaleRatio, 1f, ref transform2, transform5, transform3); } else { transform5.parent = transform2; } transform5.localScale = Vector3.one; this._newPool.Push(transform5); } edge._totalLogs++; Transform transform6 = this.NewLog(horizontalSegment._p1 - vector2 + vector, rotation2); if (!this._wasBuilt) { this.StackLogsByScale(ref num2, logStackScaleRatio, localScale.z, ref transform2, transform6, transform3); } else { transform6.parent = transform2; } transform6.localScale = localScale; this._newPool.Push(transform6); if (verticalSegment._diag) { edge._totalLogs++; transform6 = this.NewLog(transform6.position - b, rotation3); if (!this._wasBuilt) { this.StackLogsByScale(ref num2, logStackScaleRatio, localScale.z, ref transform2, transform6, transform3); } else { transform6.parent = transform2; } transform6.localScale = localScale2; this._newPool.Push(transform6); } } vector2 += b2; if (this._wasBuilt && j < 2 && vector2.y > num4 * (float)(1 + j)) { j++; flag = true; } } if (!flag) { j++; } while (j <= 2) { this._chunks.Add(null); j++; } } if (edge._isFirst) { this._foundationRoot.transform.position = edge._p1; } gameObject.transform.parent = this._foundationRoot.transform; return(gameObject); }
public void doNavCut() { if (BoltNetwork.isClient) { return; } if (this.blockNav) { return; } if (!AstarPath.active || this.coolDown) { return; } this.go = base.gameObject; if (this.oneTimeOnly) { this.blockNav = true; } if (!this.col) { this.col = this.go.GetComponent <Collider>(); } if (!this.col) { return; } if (base.transform.root.GetComponent <raftOnLand>()) { return; } Bounds bounds = this.col.bounds; this.diff = bounds.center.y + bounds.extents.y; bounds.center.y = this.diff; float num = Terrain.activeTerrain.SampleHeight(bounds.center) + Terrain.activeTerrain.transform.position.y; this.diff -= num; bool flag = false; if (this.diff < 0f) { flag = true; } this.storeBounds = bounds; if (this.disableColliderForUpdate) { this.col.enabled = false; } FoundationChunkTier component = base.gameObject.GetComponent <FoundationChunkTier>(); if (component) { this.isStructure = true; } if (this.diff < 25f && this.diff > 2f && !this.planeCollision && component) { if (!Scene.SceneTracker.climbableStructures.Contains(base.gameObject)) { Scene.SceneTracker.climbableStructures.Add(base.gameObject); } if (Scene.SceneTracker.isActiveAndEnabled) { Scene.SceneTracker.StartCoroutine(Scene.SceneTracker.validateClimbingWalls(false)); } } if (flag) { base.enabled = false; return; } if (component) { } if (base.gameObject.name.Contains("StairsBuilt")) { this.isStructure = true; } if (!base.transform.GetComponent <setupNavRemoveRoot>() && !this.planeCollision) { base.transform.gameObject.AddComponent <setupNavRemoveRoot>(); } getStructureStrength component2 = this.go.GetComponent <getStructureStrength>(); if (component2) { if (component2._type == getStructureStrength.structureType.floor) { this.isFloor = true; this.isStructure = true; } if (component2._type == getStructureStrength.structureType.wall) { this.isWall = true; } if (component2._type == getStructureStrength.structureType.foundation) { this.isFoundation = true; } if (component2._type == getStructureStrength.structureType.wall || component2._type == getStructureStrength.structureType.foundation || component2._type == getStructureStrength.structureType.floor || this.isStructure) { if (this.isFloor) { this.recastObjSetup(true); } else { this.recastObjSetup(false); } if (base.transform.root) { if (this.doingOnGameStartCheck) { Scene.SceneTracker.StartCoroutine(Scene.SceneTracker.doGlobalStructureBoundsNavRemove(base.transform.root, this.storeBounds)); return; } if (Scene.SceneTracker.gameObject.activeSelf) { Scene.SceneTracker.StartCoroutine(Scene.SceneTracker.doStructureBoundsNavRemove(base.transform.root, this.storeBounds, this.updateGraphDelay)); return; } } return; } } if (this.isStructure && base.transform.root) { if (this.doingOnGameStartCheck) { Scene.SceneTracker.StartCoroutine(Scene.SceneTracker.doGlobalStructureBoundsNavRemove(base.transform.root, this.storeBounds)); return; } if (Scene.SceneTracker.gameObject.activeSelf) { Scene.SceneTracker.StartCoroutine(Scene.SceneTracker.doStructureBoundsNavRemove(base.transform.root, this.storeBounds, this.updateGraphDelay)); return; } } if (!this.planeCollision && !this.cutGo && !this.disableColliderForUpdate) { this.cutGo = UnityEngine.Object.Instantiate <GameObject>((GameObject)Resources.Load("navCubeCutter"), base.transform.position, base.transform.rotation); if (this.col.GetType() == typeof(BoxCollider)) { BoxCollider component3 = this.col.transform.GetComponent <BoxCollider>(); Vector3 size = component3.size; this.cutGo.transform.parent = this.col.transform; this.cutGo.transform.localScale = size; this.cutGo.transform.localPosition = component3.center; this.cutGo.transform.localRotation = Quaternion.identity; } else if (this.col.GetType() == typeof(SphereCollider)) { SphereCollider component4 = this.col.transform.GetComponent <SphereCollider>(); Vector3 localScale = this.cutGo.transform.localScale; this.cutGo.transform.parent = this.col.transform; localScale.x = component4.radius * 1.3f; localScale.y = component4.radius * 1.3f; localScale.z = component4.radius * 1.3f; this.cutGo.transform.localScale = localScale; } else if (this.col.GetType() == typeof(CapsuleCollider)) { CapsuleCollider component5 = this.col.transform.GetComponent <CapsuleCollider>(); this.cutGo.transform.parent = this.col.transform; Vector3 localScale2 = this.cutGo.transform.localScale; localScale2.x = component5.radius * 1.3f; localScale2.y = component5.height; localScale2.z = component5.radius * 1.3f; this.cutGo.transform.localScale = localScale2; } this.cutGo.GetComponent <RecastMeshObj>().enabled = true; } if (!base.transform.GetComponent <navCutterSetup>()) { if (this.doingOnGameStartCheck && !this.planeCollision) { Scene.SceneTracker.StartCoroutine(Scene.SceneTracker.doGlobalStructureBoundsNavRemove(base.transform.root, this.storeBounds)); return; } if (Scene.SceneTracker.gameObject.activeSelf) { Scene.SceneTracker.StartCoroutine(Scene.SceneTracker.doStructureBoundsNavRemove(base.transform, this.storeBounds, this.updateGraphDelay)); } } if (!this.updateOnEnable) { base.enabled = false; } }