private void InitGrid() { this._offset = new Vector3((float)(-(float)this._gridSize / 2 * this._gridWorldSize), 0f, (float)(-(float)this._gridSize / 2 * this._gridWorldSize)); this._treeGrid = new int[this._gridSize, this._gridSize]; this._lodGrid = new int[this._gridSize, this._gridSize]; int num = 32; float num2 = 360f / (float)num; this._rayDirections = new Vector3[32]; for (int i = 0; i < num; i++) { this._rayDirections[i] = Quaternion.Euler(0f, (float)i * num2, 0f) * Vector3.forward * (float)(this._maxDistance / this._gridWorldSize); } this._highestCellTreeCount = 1; LOD_Trees[] array = UnityEngine.Object.FindObjectsOfType <LOD_Trees>(); LOD_Trees[] array2 = array; for (int j = 0; j < array2.Length; j++) { LOD_Trees lOD_Trees = array2[j]; Vector3 position = lOD_Trees.transform.position; int num3 = this.WorldToGridX(position.x); int num4 = this.WorldToGridX(position.z); if (num3 >= 0 && num3 < this._gridSize && num4 >= 0 && num4 < this._gridSize) { int num5 = ++this._treeGrid[num3, num4]; if (num5 > this._highestCellTreeCount) { this._highestCellTreeCount = num5; } } } this._highestCellTreeCount = Mathf.RoundToInt((float)this._highestCellTreeCount * 0.9f); }
public override void Attached() { this.chunks = (from x in base.GetComponentsInChildren <TreeCutChunk>() orderby int.Parse(x.transform.parent.gameObject.name) select x).ToArray <TreeCutChunk>(); base.state.AddCallback("TreeId", delegate { CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId x) => x.Id == base.state.TreeId); if (coopTreeId) { LOD_Trees component = coopTreeId.GetComponent <LOD_Trees>(); if (component) { component.enabled = false; component.DontSpawn = true; if (component.CurrentView) { component.Pool.Despawn(component.CurrentView.transform); component.CurrentView = null; component.CurrentLodTransform = null; } } } }); base.state.AddCallback("Damage", delegate { if (base.entity.isOwner && base.state.Damage == 16f) { base.entity.DestroyDelayed(10f); BoltEntity boltEntity = BoltNetwork.Instantiate(this.CoopTree.NetworkFallPrefab, base.entity.transform.position, base.entity.transform.rotation); boltEntity.GetState <ITreeFallState>().CutTree = base.entity; boltEntity.GetComponent <Rigidbody>().AddForce(new Vector3(UnityEngine.Random.value * 0.01f, 0f, UnityEngine.Random.value * 0.01f), ForceMode.VelocityChange); } }); }
private void lookAtExplosion(Vector3 position) { Vector3 b = new Vector3(1f, 0f, 1f); if (!this._idleIfPresent && Vector3.Distance(Vector3.Scale(position, b), Vector3.Scale(base.transform.position, b)) < 3.5f) { if (LocalPlayer.Sfx) { LocalPlayer.Sfx.PlayBreakWood(base.gameObject); } LOD_Stump componentInParent = base.GetComponentInParent <LOD_Stump>(); LOD_Trees lod_Trees = (!componentInParent) ? base.GetComponentInParent <LOD_Trees>() : componentInParent.transform.parent.GetComponent <LOD_Trees>(); if (lod_Trees) { if (componentInParent && componentInParent.Pool.IsSpawned(base.transform)) { base.transform.parent = componentInParent.Pool.transform; componentInParent.Pool.Despawn(base.transform); } if (!BoltNetwork.isRunning) { this.Finalize(lod_Trees, (!componentInParent) ? base.gameObject : componentInParent.gameObject); } else { RemoveStump removeStump = RemoveStump.Create(GlobalTargets.OnlyServer); removeStump.TargetTree = lod_Trees.GetComponent <BoltEntity>(); if (this._blownUpStump) { removeStump.Position = base.transform.position; removeStump.Rotation = base.transform.rotation; removeStump.CutUpStumpPrefabId = this._blownUpStump.GetComponent <BoltEntity>().prefabId; } removeStump.Send(); this.Finalize((!BoltNetwork.isServer) ? null : lod_Trees, (!componentInParent) ? base.gameObject : componentInParent.gameObject); } } else { TreeHealth componentInParent2 = base.GetComponentInParent <TreeHealth>(); if (componentInParent2 && componentInParent2.LodTree) { if (BoltNetwork.isRunning) { CoopTreeId component = componentInParent2.LodTree.GetComponent <CoopTreeId>(); if (component) { component.Goto_Removed(); } } this.Finalize(componentInParent2.LodTree, componentInParent2.gameObject); } } } }
private void Update() { base.enabled = false; Debug.Log("Turning off " + this.CutDownTreeIds.Length + " trees that were cut down"); Dictionary <int, CoopTreeId> dictionary = UnityEngine.Object.FindObjectsOfType <CoopTreeId>().ToDictionary((CoopTreeId t) => t.Id); for (int i = 0; i < this.CutDownTreeIds.Length; i++) { CoopTreeId coopTreeId; if (dictionary.TryGetValue(Mathf.Abs(this.CutDownTreeIds[i]), out coopTreeId)) { if (this.CutDownTreeIds[i] >= 0) { LOD_Trees component = coopTreeId.GetComponent <LOD_Trees>(); if (component) { if (component.CurrentLodTransform) { UnityEngine.Object.Destroy(component.CurrentLodTransform.gameObject); } if (this.StumpPrefab && component.transform.localScale.x >= 1f) { Transform transform = component.transform; GameObject original = (!component.StumpPrefab) ? this.StumpPrefab : component.StumpPrefab; GameObject gameObject = UnityEngine.Object.Instantiate(original, transform.position, transform.rotation) as GameObject; if (this.MatchTreeScale) { gameObject.transform.localScale = component.High.transform.localScale; } gameObject.transform.parent = coopTreeId.transform; } TreeHealth.OnTreeCutDown.Invoke(component.transform.position); component.enabled = false; } } else { if (coopTreeId) { UnityEngine.Object.Instantiate(Resources.Load("stumpGridBlocker"), coopTreeId.transform.position, coopTreeId.transform.rotation); } UnityEngine.Object.Destroy(coopTreeId.GetComponent <LOD_Base>()); if (BoltNetwork.isServer) { coopTreeId.Goto_Removed(); } } } } }
private void OnDisable() { if (Scene.SceneTracker && Scene.SceneTracker.closeTrees.Contains(base.gameObject)) { Scene.SceneTracker.closeTrees.Remove(base.gameObject); } if (this.SpawnedCutTree) { this.LodEntity = null; this.Trunk = null; this.TrunkUpperSpawn = null; this.PerchTargets = null; this.LodTree = null; } }
private void Finalize(LOD_Trees lt, GameObject go) { if (this._blownUpStump && !BoltNetwork.isRunning) { this.NavCheck(); UnityEngine.Object.Instantiate <GameObject>(this._blownUpStump, base.transform.position, base.transform.rotation); } if (lt) { UnityEngine.Object.Destroy(lt); } if (go) { UnityEngine.Object.Destroy(go); } }
public override IEnumerator OnDeserialized() { if (BoltNetwork.isRunning) { while (!base.entity.isAttached) { yield return(null); } } if (!BoltNetwork.isRunning || base.entity.isAttached) { yield return(null); if (this._treeId >= 0) { CoopTreeId tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId); if (!tid) { yield return(YieldPresets.WaitThreeSeconds); tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId); } if (tid) { LOD_Trees component = tid.GetComponent <LOD_Trees>(); component.AddTreeCutDownTarget(base.gameObject); } } if (this._treeId2 >= 0) { CoopTreeId tid2 = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId2); if (!tid2) { yield return(YieldPresets.WaitThreeSeconds); tid2 = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId2); } if (tid2) { LOD_Trees component2 = tid2.GetComponent <LOD_Trees>(); component2.AddTreeCutDownTarget(base.gameObject); } } } yield break; }
private void Finalize(LOD_Trees lt, GameObject go) { if (this._blownUpStump) { if (!BoltNetwork.isRunning) { this.navCheck(); UnityEngine.Object.Instantiate(this._blownUpStump, base.transform.position, base.transform.rotation); } else if (BoltNetwork.isServer) { this.navCheck(); BoltNetwork.Instantiate(this._blownUpStump, base.transform.position, base.transform.rotation); } } UnityEngine.Object.Destroy(lt); UnityEngine.Object.Destroy(go); }
private void lookAtExplosion(Vector3 position) { Vector3 b = new Vector3(1f, 0f, 1f); if (!this._idleIfPresent && !BoltNetwork.isClient && Vector3.Distance(Vector3.Scale(position, b), Vector3.Scale(base.transform.position, b)) < 3.5f) { LocalPlayer.Sfx.PlayBreakWood(base.gameObject); LOD_Stump componentInParent = base.GetComponentInParent <LOD_Stump>(); if (componentInParent) { LOD_Trees component = componentInParent.transform.parent.GetComponent <LOD_Trees>(); if (component.Pool.IsSpawned(base.transform)) { base.transform.parent = component.Pool.transform; component.Pool.Despawn(base.transform); } if (BoltNetwork.isRunning) { CoopTreeId component2 = component.GetComponent <CoopTreeId>(); if (component2) { component2.Goto_Removed(); } } this.Finalize(component, componentInParent.gameObject); } else { TreeHealth componentInParent2 = base.GetComponentInParent <TreeHealth>(); if (componentInParent2 && componentInParent2.LodTree) { if (BoltNetwork.isRunning) { CoopTreeId component3 = componentInParent2.LodTree.GetComponent <CoopTreeId>(); if (component3) { component3.Goto_Removed(); } } this.Finalize(componentInParent2.LodTree, componentInParent2.gameObject); } } } }
private void OnDestroy() { if (this._tsl) { UnityEngine.Object.Destroy(this._tsl); this._tsl = null; } if (CoopPlayerCallbacks.AllTrees != null) { CoopTreeId coopTreeId = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this._treeId); if (coopTreeId) { LOD_Trees component = coopTreeId.GetComponent <LOD_Trees>(); if (component) { component.RemoveTreeCutDownTarget(base.gameObject); } } } }
private IEnumerator validateCurrentTree(GameObject tree) { TreeHealth th = tree.GetComponent <TreeHealth>(); if (!th) { yield break; } if (th.LodTree) { LOD_Trees lt = th.LodTree.GetComponent <LOD_Trees>(); while (lt.CurrentLodTransform != null && lt.enabled) { yield return(null); } this.pmBase.SendEvent("cancelTreeClimb"); } yield return(null); yield break; }
public virtual IEnumerator OnDeserialized() { if (BoltNetwork.isRunning) { while (!base.entity.isAttached) { yield return(null); } } if (this._treeId >= 0 && !this._tsl && (!BoltNetwork.isRunning || base.entity.isAttached)) { yield return(null); if (!this._tsl) { if (BoltNetwork.isRunning && base.entity.isAttached && base.entity.isOwner && base.entity.StateIs <ITreeHouseState>()) { base.entity.GetState <ITreeHouseState>().TreeId = this._treeId; } CoopTreeId tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId); if (!tid) { yield return(YieldPresets.WaitThreeSeconds); tid = CoopPlayerCallbacks.AllTrees.FirstOrDefault((CoopTreeId i) => i.Id == this.$this._treeId); } if (tid && !this._tsl) { LOD_Trees component = tid.GetComponent <LOD_Trees>(); component.AddTreeCutDownTarget(base.gameObject); if (this._cutLeaves) { this._tsl = component.gameObject.AddComponent <TreeStructureLod>(); this._tsl._lod = component; } } } } yield break; }
public void SetLodBase(LOD_Base lb) { this.LodTree = (LOD_Trees)lb; this.LodTree.CurrentView = this; }
private void Awake() { this.lod = base.GetComponent <LOD_Trees>(); base.enabled = false; }