public static void Unregister(gridObjectBlocker gob) { if (gridObjectBlockerManager.Instance._callbacks.Contains(gob)) { gridObjectBlockerManager.Instance._callbacks.Remove(gob); } }
public static void Register(gridObjectBlocker gob) { if (!gridObjectBlockerManager.Instance._callbacks.Contains(gob)) { gridObjectBlockerManager.Instance._callbacks.Add(gob); if (!gridObjectBlockerManager.Instance._running) { gridObjectBlockerManager.Instance.StartCoroutine(gridObjectBlockerManager.Instance.NavCutRountine()); } } }
public void CreateStructure(bool isRepair = false) { if (this._wasBuilt && isRepair) { if (this._bridgeRoot) { UnityEngine.Object.Destroy(this._bridgeRoot.gameObject); } this._bridgeRoot = null; base.StartCoroutine(this.DelayedAwake(true)); } GameObject gameObject = (!this._bridgeRoot) ? null : this._bridgeRoot.gameObject; this._bridgeRoot = this.CreateBridge(this._anchor1.transform.position, this._anchor2.transform.position); this._bridgeRoot.name = "BridgeRoot" + ((!this._wasBuilt) ? "Ghost" : "Built"); this._bridgeRoot.parent = base.transform; if (gameObject) { UnityEngine.Object.Destroy(gameObject); } if (this._wasBuilt) { base.transform.position = this._anchor1.transform.position; this._bridgeRoot.parent = base.transform; LOD_GroupToggle lod_GroupToggle = this._bridgeRoot.gameObject.AddComponent <LOD_GroupToggle>(); lod_GroupToggle.enabled = false; lod_GroupToggle._levels = new LOD_GroupToggle.LodLevel[2]; lod_GroupToggle._levels[0] = new LOD_GroupToggle.LodLevel { Renderers = this._bridgeRoot.GetComponentsInChildren <Renderer>(), VisibleDistance = Vector3.Distance(this._anchor1.transform.position, this._anchor2.transform.position) + 20f }; lod_GroupToggle._levels[1] = new LOD_GroupToggle.LodLevel { VisibleDistance = 10000f }; List <Renderer> list = new List <Renderer>(); Vector3 vector = this._bridgeRoot.GetChild(0).position; int num = Mathf.CeilToInt(Vector3.Distance(this._anchor1.transform.position, this._anchor2.transform.position) / this._maxColliderLength); int num2 = Mathf.CeilToInt((float)this._bridgeRoot.childCount / (float)num); for (int i = 1; i <= num; i++) { int num3 = num2 * i; if (num3 >= this._bridgeRoot.childCount) { num3 = this._bridgeRoot.childCount - 1; } Transform child = this._bridgeRoot.GetChild(num3); Vector3 position = child.position; Transform transform = new GameObject("Floor" + i).transform; transform.gameObject.layer = 21; transform.parent = base.transform; transform.position = vector; transform.LookAt(position); BoxCollider boxCollider = transform.gameObject.AddComponent <BoxCollider>(); boxCollider.center = transform.InverseTransformPoint(Vector3.Lerp(vector, position, 0.5f)); boxCollider.size = new Vector3(4.5f, this._logWidth * 0.65f, Vector3.Distance(vector, position) + ((i != num) ? 0f : (this._logWidth / 2f))); transform.tag = "UnderfootWood"; MeshRenderer meshRenderer = transform.gameObject.AddComponent <MeshRenderer>(); meshRenderer.sharedMaterial = Prefabs.Instance.LogBridgeBuiltPrefabLOD1.sharedMaterial; MeshFilter meshFilter = transform.gameObject.AddComponent <MeshFilter>(); meshFilter.sharedMesh = Prefabs.Instance.LogBridgeBuiltPrefabLOD1.GetComponent <MeshFilter>().sharedMesh; list.Add(meshRenderer); getStructureStrength getStructureStrength = null; if (!getStructureStrength) { getStructureStrength = transform.gameObject.AddComponent <getStructureStrength>(); getStructureStrength._type = getStructureStrength.structureType.floor; getStructureStrength._strength = getStructureStrength.strength.weak; } transform.gameObject.AddComponent <BuildingHealthHitRelay>(); gridObjectBlocker exists = null; if (!exists) { transform.gameObject.AddComponent <gridObjectBlocker>(); } vector = position; } lod_GroupToggle._levels[1].Renderers = list.ToArray(); lod_GroupToggle.enabled = true; } if (this._wasBuilt && isRepair) { this._bridgeRoot.parent = base.transform; } }
protected virtual void CreateStructure(bool isRepair = false) { if (isRepair) { this.Clear(); base.StartCoroutine(this.DelayedAwake(true)); } int num = LayerMask.NameToLayer("Prop"); this._wallRoot = this.SpawnStructure(); this._wallRoot.parent = base.transform; if (this._wasBuilt) { this._gridToken = InsideCheck.AddWallChunk(this._p1, this._p2, 4.75f * this._logWidth + 1f); if (this._lods) { UnityEngine.Object.Destroy(this._lods.gameObject); } this._lods = new GameObject("lods").AddComponent <WallChunkLods>(); this._lods.transform.parent = base.transform; this._lods.DefineChunk(this._p1, this._p2, 4.44f * this._logWidth, this._wallRoot, this.Addition); if (!this._wallCollision) { GameObject gameObject = new GameObject("collision"); gameObject.transform.parent = this._wallRoot.parent; gameObject.transform.position = this._wallRoot.position; gameObject.transform.rotation = this._wallRoot.rotation; gameObject.tag = "structure"; this._wallCollision = gameObject.transform; GameObject gameObject2 = this._wallRoot.gameObject; int layer = num; gameObject.layer = layer; gameObject2.layer = layer; float num3; float num4; Vector3 size; Vector3 vector; if (this.UseHorizontalLogs) { float num2 = Vector3.Distance(this._p1, this._p2) / this._logLength; num3 = 7.4f * num2; num4 = 6.75f * (0.31f + (num2 - 1f) / 2f); size = new Vector3(1.75f, 0.9f * this._height * this._logWidth, num3 * 1f); vector = Vector3.Lerp(this._p1, this._p2, 0.5f); vector = this._wallRoot.InverseTransformPoint(vector); vector.y = size.y / 2f - this._logWidth / 2f; } else { num3 = this._logWidth * (float)(this._wallRoot.childCount - 1) + 1.5f; num4 = 0f; vector = Vector3.zero; IEnumerator enumerator = this._wallRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; vector += transform.position; } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } size = new Vector3(1.75f, 0.92f * this._height * this._logWidth, num3); vector /= (float)this._wallRoot.childCount; vector = this._wallRoot.InverseTransformPoint(vector); vector.y = size.y / 2f - this._logWidth / 2f; } getStructureStrength getStructureStrength = gameObject.AddComponent <getStructureStrength>(); getStructureStrength._strength = getStructureStrength.strength.strong; BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>(); boxCollider.center = vector; boxCollider.size = size; boxCollider.isTrigger = true; BuildingHealth component = base.GetComponent <BuildingHealth>(); if (component) { component._renderersRoot = this._wallRoot.gameObject; } WallChunkArchitect.Additions addition = this._addition; if (addition != WallChunkArchitect.Additions.Wall) { BoxCollider boxCollider2 = null; if (this._height > 4f) { vector.y += this._logWidth * 2f; size.y = 1f * this._logWidth; boxCollider2 = gameObject.AddComponent <BoxCollider>(); boxCollider2.center = vector; boxCollider2.size = size; } FMOD_StudioEventEmitter.CreateAmbientEmitter(gameObject.transform, gameObject.transform.TransformPoint(vector), "event:/ambient/wind/wind_moan_structures"); size.y = Mathf.Clamp(this._height, 0f, 4f) * this._logWidth; size.z = num4; vector.y = size.y / 2f - this._logWidth / 2f; vector.z = num3 - num4 / 2f; BoxCollider boxCollider3 = gameObject.AddComponent <BoxCollider>(); boxCollider3.center = vector; boxCollider3.size = size; vector.z = num4 / 2f; BoxCollider boxCollider4 = gameObject.AddComponent <BoxCollider>(); boxCollider4.center = vector; boxCollider4.size = size; if (this._addition == WallChunkArchitect.Additions.Window) { size.y = this._logWidth * 1.9f; size.z = num3 - num4 * 2f; vector.z += num4 / 2f + size.z / 2f; vector.y = size.y / 2f - this._logWidth / 2f; BoxCollider boxCollider5 = gameObject.AddComponent <BoxCollider>(); boxCollider5.center = vector; boxCollider5.size = size; GameObject gameObject3 = new GameObject("PerchTarget"); SphereCollider sphereCollider = gameObject3.AddComponent <SphereCollider>(); sphereCollider.isTrigger = true; sphereCollider.radius = 0.145f; gameObject3.transform.parent = this._wallRoot; vector.y += size.y / 2f; gameObject3.transform.localPosition = vector; if (BoltNetwork.isRunning) { if (boxCollider2) { component.SetMpRandomDistortColliders(new Collider[] { boxCollider2, boxCollider4, boxCollider3, boxCollider5 }); } else { component.SetMpRandomDistortColliders(new Collider[] { boxCollider4, boxCollider3, boxCollider5 }); } } } else if (BoltNetwork.isRunning) { component.SetMpRandomDistortColliders(new Collider[] { boxCollider2, boxCollider4, boxCollider3 }); } } else { BoxCollider boxCollider6 = gameObject.AddComponent <BoxCollider>(); boxCollider6.center = vector; boxCollider6.size = size; if (BoltNetwork.isRunning) { component.SetMpRandomDistortColliders(new Collider[] { boxCollider6 }); } } gridObjectBlocker gridObjectBlocker = gameObject.AddComponent <gridObjectBlocker>(); gridObjectBlocker.ignoreOnDisable = true; addToBuilt addToBuilt = gameObject.AddComponent <addToBuilt>(); addToBuilt.addToStructures = true; BuildingHealthHitRelay buildingHealthHitRelay = gameObject.AddComponent <BuildingHealthHitRelay>(); } if (this.Addition >= WallChunkArchitect.Additions.Door1 && this._addition <= WallChunkArchitect.Additions.LockedDoor2 && !isRepair) { Vector3 position = Vector3.Lerp(this._p1, this._p2, 0.5f); position.y -= this._logWidth / 2f; Vector3 worldPosition = (this._addition != WallChunkArchitect.Additions.Door1 && this._addition != WallChunkArchitect.Additions.LockedDoor1) ? this._p1 : this._p2; worldPosition.y = position.y; Transform transform2 = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.DoorPrefab, position, this._wallRoot.rotation); transform2.LookAt(worldPosition); transform2.parent = base.transform; } } }
public IEnumerator doGlobalStructureBoundsNavRemove(Transform root, Bounds startBounds) { if (BoltNetwork.isClient) { yield break; } if (this.globalNavStructures.Contains(root.gameObject)) { yield break; } this.globalNavStructures.Add(root.gameObject); if (this.doingGlobalNavUpdate) { yield break; } this.doingGlobalNavUpdate = true; yield return(new WaitForSeconds(0.5f)); while (!this.waitForLoadSequence) { yield return(null); } if (!AstarPath.active) { yield break; } if (!root) { yield break; } int globalNavStructureCount = this.globalNavStructures.Count; for (int i = 0; i < globalNavStructureCount; i++) { Transform transform = this.globalNavStructures[i].transform; globalNavId globalNavId = transform.GetComponent <globalNavId>(); if (!globalNavId) { globalNavId = transform.gameObject.AddComponent <globalNavId>(); globalNavId.navId = i; for (int j = i + 1; j < globalNavStructureCount; j++) { globalNavId globalNavId2 = this.globalNavStructures[j].GetComponent <globalNavId>(); if (!globalNavId2 && (transform.position - this.globalNavStructures[j].transform.position).sqrMagnitude < 10000f) { globalNavId2 = this.globalNavStructures[j].AddComponent <globalNavId>(); globalNavId2.navId = i; } } } } int countUpdates = 0; List <GameObject> processedStructures = new List <GameObject>(); for (int k = 0; k < globalNavStructureCount; k++) { globalNavId component = this.globalNavStructures[k].GetComponent <globalNavId>(); int navId = component.navId; if (!processedStructures.Contains(this.globalNavStructures[k])) { List <Collider> list = new List <Collider>(); for (int l = 0; l < globalNavStructureCount; l++) { globalNavId component2 = this.globalNavStructures[l].GetComponent <globalNavId>(); if (component2.navId == navId) { processedStructures.Add(this.globalNavStructures[l]); Collider[] componentsInChildren = this.globalNavStructures[l].GetComponentsInChildren <Collider>(); for (int m = 0; m < componentsInChildren.Length; m++) { gridObjectBlocker component3 = componentsInChildren[m].transform.GetComponent <gridObjectBlocker>(); if (component3) { list.Add(componentsInChildren[m]); } } Collider component4 = this.globalNavStructures[l].GetComponent <Collider>(); if (component4 && component4.GetComponent <gridObjectBlocker>()) { list.Add(component4); } } } Bounds bounds = list[0].bounds; for (int n = 1; n < list.Count; n++) { bounds.Encapsulate(list[n].bounds); } countUpdates++; GraphUpdateObject graphUpdateObject = new GraphUpdateObject(bounds); this.graphsBeingUpdated = true; AstarPath.active.astarData.recastGraph.rasterizeColliders = false; int graphIndex = (int)AstarPath.active.astarData.recastGraph.graphIndex; graphUpdateObject.nnConstraint.graphMask = 1 << graphIndex; AstarPath.active.UpdateGraphs(graphUpdateObject, 0f); } } float startNavTime = Time.realtimeSinceStartup; this.astarGuo.GetComponent <TileHandlerHelper>().ForceUpdate(); AstarPath.active.FlushWorkItems(); this.doingGlobalNavUpdate = false; foreach (GameObject gameObject in this.globalNavStructures) { if (gameObject) { globalNavId component5 = gameObject.GetComponent <globalNavId>(); if (component5) { UnityEngine.Object.Destroy(component5); } } } this.globalNavStructures.Clear(); Scene.MutantControler.calculateMainNavArea(); Debug.Log("startup nav cut structures time = " + (Time.realtimeSinceStartup - startNavTime)); yield break; }
public IEnumerator doStructureBoundsNavRemove(Transform root, Bounds startBounds, float delay) { if (BoltNetwork.isClient) { yield break; } if (this.currentNavStructures.Contains(root.gameObject)) { yield break; } this.currentNavStructures.Add(root.gameObject); if (!AstarPath.active) { yield break; } if (this.doingNavUpdate) { yield break; } this.doingNavUpdate = true; yield return(new WaitForSeconds(delay)); if (!root) { yield break; } Bounds combinedBounds = startBounds; List <Collider> allCol = new List <Collider>(); for (int i = 0; i < this.currentNavStructures.Count; i++) { Collider[] componentsInChildren = this.currentNavStructures[i].GetComponentsInChildren <Collider>(); for (int j = 0; j < componentsInChildren.Length; j++) { gridObjectBlocker component = componentsInChildren[j].transform.GetComponent <gridObjectBlocker>(); if (component) { allCol.Add(componentsInChildren[j]); } } } Collider rootCol = root.GetComponent <Collider>(); if (rootCol) { allCol.Add(rootCol); } for (int k = 0; k < allCol.Count; k++) { combinedBounds.Encapsulate(allCol[k].bounds); } GraphUpdateObject guo = new GraphUpdateObject(combinedBounds); while (this.graphsBeingUpdated) { yield return(null); } this.graphsBeingUpdated = true; AstarPath.active.astarData.recastGraph.rasterizeColliders = false; int indexOfGraph = (int)AstarPath.active.astarData.recastGraph.graphIndex; guo.nnConstraint.graphMask = 1 << indexOfGraph; AstarPath.active.UpdateGraphs(guo, 0f); this.doingNavUpdate = false; this.currentNavStructures.Clear(); base.StartCoroutine(this.validateClimbingWalls(true)); while (this.graphsBeingUpdated) { AstarPath.active.astarData.recastGraph.rasterizeColliders = false; yield return(null); } Scene.MutantControler.calculateMainNavArea(); yield break; }
protected override void CreateStructure(bool isRepair = false) { if (isRepair) { base.Clear(); base.StartCoroutine(base.DelayedAwake(true)); } int num = LayerMask.NameToLayer("Prop"); this._wallRoot = this.SpawnStructure(); this._wallRoot.parent = base.transform; if (this._wasBuilt) { this._gridToken = InsideCheck.AddWallChunk(this._p1, this._p2, 4.75f * this._logWidth + 1f); BuildingHealth component = base.GetComponent <BuildingHealth>(); if (component) { component._renderersRoot = this._wallRoot.gameObject; } if (!this._wallCollision) { GameObject gameObject = new GameObject("collision"); gameObject.transform.parent = this._wallRoot.parent; gameObject.transform.position = this._wallRoot.position; gameObject.transform.rotation = this._wallRoot.rotation; gameObject.tag = "structure"; this._wallCollision = gameObject.transform; GameObject gameObject2 = this._wallRoot.gameObject; int layer = num; gameObject.layer = layer; gameObject2.layer = layer; Vector3 vector; Vector3 size; if (this.UseHorizontalLogs) { float num2 = Vector3.Distance(this._p1, this._p2) / this._logLength; float num3 = 7.4f * num2; float num4 = 6.75f * (0.31f + (num2 - 1f) / 2f); vector = Vector3.Lerp(this._p1, this._p2, 0.5f); vector.y += this._logWidth * 0.9f; vector = this._wallRoot.InverseTransformPoint(vector); size = new Vector3(1.75f, 1.8f * this._logWidth, num3 * 1f); } else { float num3 = this._logWidth * (float)(this._wallRoot.childCount - 1) + 1.5f; vector = Vector3.zero; IEnumerator enumerator = this._wallRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; vector += transform.position; } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } vector /= (float)this._wallRoot.childCount; vector.y += this.GetHeight() / 2f; vector = this._wallRoot.InverseTransformPoint(vector); size = new Vector3(1.75f, this.GetHeight(), num3); } getStructureStrength getStructureStrength = gameObject.AddComponent <getStructureStrength>(); getStructureStrength._strength = getStructureStrength.strength.strong; BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>(); boxCollider.center = vector; boxCollider.size = size; boxCollider.isTrigger = true; BoxCollider boxCollider2 = gameObject.AddComponent <BoxCollider>(); boxCollider2.center = vector; boxCollider2.size = size; gridObjectBlocker gridObjectBlocker = gameObject.AddComponent <gridObjectBlocker>(); gridObjectBlocker.ignoreOnDisable = true; addToBuilt addToBuilt = gameObject.AddComponent <addToBuilt>(); addToBuilt.addToStructures = true; BuildingHealthHitRelay buildingHealthHitRelay = gameObject.AddComponent <BuildingHealthHitRelay>(); } } }
public Transform SpawnStructure() { Transform transform = new GameObject("CoasterRoot").transform; transform.position = this.GetWorldPoint(0); Stack <Transform> stack = new Stack <Transform>(); if (this._logPool == null) { this._logPool = new Stack <Transform>(); } int i = 1; int num = 1; while (i < this._multiPointsPositions.Count) { Vector3 worldPoint = this.GetWorldPoint(i); Vector3 worldPoint2 = this.GetWorldPoint(i - num); Vector3 vector = worldPoint2; Vector3 a = worldPoint; Vector3 forward = a - vector; int num2 = Mathf.CeilToInt(forward.magnitude / this._logWidth); Vector3 b = forward.normalized * this._logWidth; Transform transform2 = new GameObject("CoasterEdge" + i).transform; transform2.parent = transform; Vector3 vector2 = vector; forward = a - vector2; transform2.rotation = Quaternion.LookRotation(forward); transform2.position = vector2; this.SpawnVerticalStilt(vector, transform2); Transform transform3 = UnityEngine.Object.Instantiate <Transform>(this._stiltPrefab); transform3.parent = transform2; transform3.localPosition = new Vector3(0f, -0.75f, 0f); transform3.localEulerAngles = new Vector3(-90f, 0f, 0f); transform3.localScale = new Vector3(1f, Mathf.Abs(forward.magnitude) / 4.68f, 1f); if (!this._wasBuilt && !this._wasPlaced) { Create.ApplyGhostMaterial(transform3, false); } else { transform3.gameObject.SetActive(true); } for (int j = 0; j < num2; j++) { Transform transform4 = this.NewLog(vector2, transform2.rotation * Quaternion.Euler(0f, 90f, 0f)); transform4.parent = transform2; stack.Push(transform4); vector2 += b; } if (this._wasBuilt) { for (int k = 0; k < this._colliderSource.Length; k++) { GameObject gameObject = new GameObject(string.Format("Collider_{0:000}", k)); gameObject.transform.parent = transform2; gameObject.transform.localPosition = this._colliderSource[k].transform.localPosition; gameObject.transform.localScale = this._colliderSource[k].transform.localScale; gameObject.transform.localRotation = this._colliderSource[k].transform.localRotation; BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>(); boxCollider.sharedMaterial = this._colliderSource[k].sharedMaterial; gameObject.tag = this._colliderSource[k].gameObject.tag; gameObject.layer = this._colliderSource[k].gameObject.layer; float num3 = forward.magnitude + 0.5f; boxCollider.size = new Vector3(this._colliderSource[k].size.x, this._colliderSource[k].size.y, num3); gameObject.transform.localPosition += new Vector3(0f, 0f, num3 / 2f); } transform2.tag = "UnderfootWood"; transform2.gameObject.AddComponent <BuildingHealthHitRelay>(); transform2.gameObject.layer = 21; getStructureStrength getStructureStrength = transform2.gameObject.AddComponent <getStructureStrength>(); getStructureStrength._strength = getStructureStrength.strength.normal; getStructureStrength._type = getStructureStrength.structureType.wall; gridObjectBlocker gridObjectBlocker = transform2.gameObject.AddComponent <gridObjectBlocker>(); gridObjectBlocker.GatherChildColliders = true; FoundationArchitect.CreateWindSFX(transform3); } i += num; } if (!this._wasPlaced && !this._wasBuilt) { this._logPool = stack; } return(transform); }