public override void UpdateAddition(WallChunkArchitect.Additions addition) { this._addition = addition; if (!this._wasBuilt) { if (!base.IsDoor(this._addition) && !BoltNetwork.isClient) { base.gameObject.GetComponent <WallDefensiveGateAddition>().Start(); } else { UnityEngine.Object.Destroy(this._wallRoot.gameObject); this._wallRoot = this.SpawnStructure(); this._wallRoot.parent = base.transform; Craft_Structure.BuildIngredients buildIngredients = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this._logItemId); if (buildIngredients == null) { buildIngredients = new Craft_Structure.BuildIngredients(); buildIngredients._itemID = this._logItemId; buildIngredients._amount = 0; buildIngredients._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, buildIngredients); } else { buildIngredients._subIngredients.Clear(); } buildIngredients._amount = this.GetLogCost(); List <GameObject> builtRenderers = this.GetBuiltRenderers(this._wallRoot); buildIngredients.AddRuntimeObjects(builtRenderers, this.BuiltLogPrefab.GetComponentInChildren <Renderer>().sharedMaterial); } } }
public void AddIngrendient_Actual(int ingredientNum, bool local, BoltConnection from = null) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientNum]; ReceipeIngredient receipeIngredient = this._presentIngredients[ingredientNum]; int num = 0; for (int i = 0; i < this._requiredIngredients.Count; i++) { num += this._requiredIngredients[i]._amount - this._presentIngredients[i]._amount; } if (receipeIngredient._amount >= buildIngredients._amount || (num == 1 && (this._lockBuild || (this.CustomLockCheck != null && this.CustomLockCheck())))) { if (BoltNetwork.isRunning && from && !Cheats.Creative) { PlayerAddItem playerAddItem = PlayerAddItem.Create(from); playerAddItem.ItemId = buildIngredients._itemID; playerAddItem.Amount = 1; playerAddItem.Send(); } this.UpdateNetworkIngredients(); return; } receipeIngredient._amount++; this.UpdateNeededRenderers(); BuildMission.AddNeededToBuildMission(receipeIngredient._itemID, -1, false); if (BoltNetwork.isRunning) { this.UpdateNetworkIngredients(); } this.CheckNeeded(); }
public virtual void UpdateAddition(WallChunkArchitect.Additions addition) { this._addition = addition; UnityEngine.Object.Destroy(this._wallRoot.gameObject); this._wallRoot = this.SpawnStructure(); this._wallRoot.parent = base.transform; Craft_Structure.BuildIngredients buildIngredients = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this._logItemId); if (buildIngredients == null) { buildIngredients = new Craft_Structure.BuildIngredients(); buildIngredients._itemID = this._logItemId; buildIngredients._amount = 0; this._craftStructure._requiredIngredients.Insert(0, buildIngredients); } buildIngredients._subIngredients.Clear(); buildIngredients._renderers = null; buildIngredients._amount = this.GetLogCost(); List <GameObject> builtRenderers = this.GetBuiltRenderers(this._wallRoot); buildIngredients.AddRuntimeObjects(builtRenderers, this.BuiltLogPrefab.GetComponentInChildren <Renderer>().sharedMaterial); this._craftStructure.UpdateNeededRenderers(); if (!this._wasBuilt && this._addition >= WallChunkArchitect.Additions.Door1 && this._addition <= WallChunkArchitect.Additions.LockedDoor2) { Vector3 position = Vector3.Lerp(this._p1, this._p2, 0.5f); position.y -= this._logWidth / 2f; Vector3 worldPosition = (this._addition != WallChunkArchitect.Additions.Door1) ? this._p1 : this._p2; worldPosition.y = position.y; Transform transform = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.DoorGhostPrefab, position, this._wallRoot.rotation); transform.LookAt(worldPosition); transform.parent = this._wallRoot; } }
private void SetUpIcons() { if (Application.isPlaying) { if (this._requiredIngredients != null) { float num = 1f / ((float)Screen.width / 70f); Vector3 position = new Vector3(0.5f - num * ((float)this._requiredIngredients.Count - 0.5f), 0.15f, 0f); for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; if (buildIngredients._icon.transform.parent != base.transform) { buildIngredients._icon = UnityEngine.Object.Instantiate <GameObject>(buildIngredients._icon); buildIngredients._icon.transform.parent = base.transform; buildIngredients._icon.transform.position = position; buildIngredients._text = UnityEngine.Object.Instantiate <GameObject>(buildIngredients._text); buildIngredients._text.transform.parent = base.transform; position.z += 1f; buildIngredients._text.transform.position = position; position.z -= 1f; position.x += num; } buildIngredients._icon.SetActive(false); buildIngredients._text.SetActive(false); } } else { UnityEngine.Object.Destroy(base.gameObject); } } }
private void UpdateBuildingIngredients() { Dictionary <int, Craft_Structure.BuildIngredients> dictionary = new Dictionary <int, Craft_Structure.BuildIngredients>(); Dictionary <int, float> dictionary2 = new Dictionary <int, float>(); foreach (Craft_Structure.BuildIngredients buildIngredients in this._craftStructure._requiredIngredients) { dictionary.Add(buildIngredients._itemID, buildIngredients); dictionary2.Add(buildIngredients._itemID, 0f); } foreach (IngredientInfo ingredientInfo in this._coasterRoot.GetComponentsInChildren <IngredientInfo>()) { if (ingredientInfo.ItemId != 0) { Craft_Structure.BuildIngredients buildIngredients2; if (!dictionary.TryGetValue(ingredientInfo.ItemId, out buildIngredients2)) { buildIngredients2 = new Craft_Structure.BuildIngredients(); buildIngredients2._subIngredients = new List <Craft_Structure.BuildIngredients.SubIngredient>(); buildIngredients2._itemID = ingredientInfo.ItemId; dictionary.Add(ingredientInfo.ItemId, buildIngredients2); dictionary2.Add(ingredientInfo.ItemId, 0f); this._craftStructure._requiredIngredients.Add(buildIngredients2); } buildIngredients2.AddRuntimeObjects(ingredientInfo.Objects, ingredientInfo.Material); Dictionary <int, float> dictionary3; int itemId; (dictionary3 = dictionary2)[itemId = ingredientInfo.ItemId] = dictionary3[itemId] + ingredientInfo.CostMultiplier; buildIngredients2._amount = Mathf.CeilToInt(dictionary2[ingredientInfo.ItemId]); } } }
public void SetGhostMaterial(Material mat) { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; buildIngredients.SetGhostMaterial(mat); } }
public void UpdateNeededRenderers() { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; buildIngredients.SetBuilt(receipeIngredient._amount); } }
private void CheckText() { if (Application.isPlaying) { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; HudGui.BuildingIngredient icons = this.GetIcons(buildIngredients._itemID); if (buildIngredients != null && receipeIngredient != null && receipeIngredient._amount != buildIngredients._amount) { if (!icons._iconGo.activeSelf || !icons._label.gameObject.activeSelf) { icons._iconGo.SetActive(true); icons._label.gameObject.SetActive(true); Scene.HudGui.BuildingIngredientsGrid.repositionNow = true; if (!Scene.HudGui.BuildingIngredientsFollow.gameObject.activeSelf) { Scene.HudGui.BuildingIngredientsFollow.gameObject.SetActive(true); } } Craft_Structure.BuildIngredients.TextOptions textDisplayMode = buildIngredients._textDisplayMode; if (textDisplayMode != Craft_Structure.BuildIngredients.TextOptions.PresentOverTotal) { if (textDisplayMode != Craft_Structure.BuildIngredients.TextOptions.Present) { if (textDisplayMode == Craft_Structure.BuildIngredients.TextOptions.Total) { icons._label.text = buildIngredients._amount.ToString(); } } else { icons._label.text = receipeIngredient._amount.ToString(); } } else if (icons.DisplayedPresent != receipeIngredient._amount || icons.DisplayedNeeded != buildIngredients._amount) { icons.DisplayedPresent = receipeIngredient._amount; icons.DisplayedNeeded = buildIngredients._amount; icons._label.text = receipeIngredient._amount + "/" + buildIngredients._amount; } } else if (icons._iconGo.activeSelf || icons._label.gameObject.activeSelf) { icons._iconGo.SetActive(false); icons._label.gameObject.SetActive(false); } } } }
public void Initialize() { if (!this._initialized) { if (this._presentIngredients == null) { this._presentIngredients = new ReceipeIngredient[this._requiredIngredients.Count]; } this.SetUpIcons(); if (this._presentIngredients.Length != this._requiredIngredients.Count) { this._presentIngredients = new ReceipeIngredient[this._requiredIngredients.Count]; } for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; if (this._presentIngredients[i] == null) { this._presentIngredients[i] = new ReceipeIngredient { _itemID = buildIngredients._itemID }; } ReceipeIngredient receipeIngredient = this._presentIngredients[i]; int amount = buildIngredients._amount - receipeIngredient._amount; BuildMission.AddNeededToBuildMission(buildIngredients._itemID, amount); for (int j = 0; j < receipeIngredient._amount; j++) { if (j >= buildIngredients._renderers.Length) { break; } buildIngredients._renderers[j].SetActive(true); } } this._initialized = true; if (BoltNetwork.isRunning) { base.gameObject.AddComponent <CoopConstruction>(); if (BoltNetwork.isServer && this.entity.isAttached) { this.UpdateNetworkIngredients(); } } if (!BoltNetwork.isClient) { this.CheckNeeded(); } } }
public void UpdateNeededRenderers() { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; int num = 0; while (num < receipeIngredient._amount && num < buildIngredients._renderers.Length) { if (!buildIngredients._renderers[num].activeSelf) { buildIngredients._renderers[num].SetActive(true); } num++; } } }
public void AddIngrendient_Actual(int ingredientNum, bool local) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientNum]; ReceipeIngredient receipeIngredient = this._presentIngredients[ingredientNum]; if (receipeIngredient._amount >= buildIngredients._amount) { this.UpdateNetworkIngredients(); return; } receipeIngredient._amount++; this.UpdateNeededRenderers(); BuildMission.AddNeededToBuildMission(receipeIngredient._itemID, -1); if (BoltNetwork.isRunning) { this.UpdateNetworkIngredients(); } this.CheckNeeded(); }
private void AddIngredient(int ingredientNum) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientNum]; if (LocalPlayer.Inventory.RemoveItem(buildIngredients._itemID, 1, false) || Cheats.Creative) { LocalPlayer.Sfx.PlayHammer(); Scene.HudGui.AddIcon.SetActive(false); if (BoltNetwork.isRunning) { AddIngredient addIngredient = global::AddIngredient.Raise(GlobalTargets.OnlyServer); addIngredient.IngredientNum = ingredientNum; addIngredient.Construction = base.GetComponentInParent <BoltEntity>(); addIngredient.Send(); } else { this.AddIngrendient_Actual(ingredientNum, true); } } }
private void AllOff() { try { Scene.HudGui.AddIcon.SetActive(false); Scene.HudGui.DestroyIcon.SetActive(false); if (Application.isPlaying) { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; buildIngredients._text.SetActive(false); buildIngredients._icon.SetActive(false); } } LocalPlayer.Inventory.DontShowDrop = false; } catch { } }
private void AddIngredient(int ingredientNum) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientNum]; if (LocalPlayer.Inventory.RemoveItem(buildIngredients._itemID, 1, false, true) || Cheats.Creative) { LocalPlayer.Sfx.PlayHammer(); if (!Cheats.Creative || Time.frameCount % 3 == 0) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(false); } if (BoltNetwork.isRunning) { if (BoltNetwork.isClient) { bool flag = true; for (int i = 0; i < this._requiredIngredients.Count; i++) { if (this._presentIngredients[i]._amount < this._requiredIngredients[i]._amount && (i != ingredientNum || this._presentIngredients[i]._amount + 1 < this._requiredIngredients[i]._amount)) { flag = false; break; } } if (flag) { this.Build(); } } AddIngredient addIngredient = global::AddIngredient.Create(GlobalTargets.OnlyServer); addIngredient.IngredientNum = ingredientNum; addIngredient.ItemId = buildIngredients._itemID; addIngredient.Construction = base.GetComponentInParent <BoltEntity>(); addIngredient.Send(); } else { this.AddIngrendient_Actual(ingredientNum, true, null); } } }
private void Update() { if (this._initialized) { this.CheckText(); this.CheckNeeded(); Scene.HudGui.DestroyIcon.gameObject.SetActive(true); if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.5f)) { this.CancelBlueprint(); return; } for (int i = 0; i < this._requiredIngredients.Count; i++) { if (this._requiredIngredients[i]._amount != this._presentIngredients[i]._amount) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; if (buildIngredients._amount > receipeIngredient._amount) { if (!LocalPlayer.Inventory.Owns(this._requiredIngredients[i]._itemID) && !Cheats.Creative) { buildIngredients._icon.GetComponent <GUITexture>().color = this.ColorRed; } else { buildIngredients._icon.GetComponent <GUITexture>().color = this.ColorGrey; Scene.HudGui.AddIcon.SetActive(true); if (TheForest.Utils.Input.GetButtonDown("Take") || (Cheats.Creative && TheForest.Utils.Input.GetButton("Take"))) { this.AddIngredient(i); break; } } } } } } }
private void CheckText() { if (Application.isPlaying) { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; if (buildIngredients != null && receipeIngredient != null && receipeIngredient._amount != buildIngredients._amount) { if (!buildIngredients._text.activeSelf) { buildIngredients._text.SetActive(true); buildIngredients._icon.SetActive(true); } switch (buildIngredients._textDisplayMode) { case Craft_Structure.BuildIngredients.TextOptions.PresentOverTotal: buildIngredients._text.GetComponent <GUIText>().text = receipeIngredient._amount + "/" + buildIngredients._amount; break; case Craft_Structure.BuildIngredients.TextOptions.Present: buildIngredients._text.GetComponent <GUIText>().text = receipeIngredient._amount.ToString(); break; case Craft_Structure.BuildIngredients.TextOptions.Total: buildIngredients._text.GetComponent <GUIText>().text = buildIngredients._amount.ToString(); break; } } else if (buildIngredients._text.activeSelf) { buildIngredients._text.SetActive(false); buildIngredients._icon.SetActive(false); } } } }
private void AllOff(bool destroy = false) { try { if (Scene.HudGui) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(false); Scene.HudGui.DestroyIcon.SetActive(false); Scene.HudGui.ToggleVariationIcon.SetActive(false); Scene.HudGui.CantPlaceIcon.SetActive(false); if (Scene.HudGui.BuildingIngredientsFollow.gameObject.activeSelf) { Scene.HudGui.BuildingIngredientsFollow.gameObject.SetActive(false); } } if (Application.isPlaying) { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; HudGui.BuildingIngredient icons = this.GetIcons(buildIngredients._itemID); if (icons._iconGo.activeSelf || icons._label.gameObject.activeSelf) { icons._iconGo.SetActive(false); icons._label.gameObject.SetActive(false); } } } if (LocalPlayer.Inventory) { LocalPlayer.Inventory.DontShowDrop = false; } } catch { } }
private IEnumerator OnPlaced() { this._wasPlaced = true; base.enabled = false; this._craftStructure.GetComponent <Collider>().enabled = false; Scene.HudGui.RoofConstructionIcons.Shutdown(); yield return(null); if (this._craftStructure) { UnityEngine.Object.Destroy(base.GetComponent <Rigidbody>()); UnityEngine.Object.Destroy(base.GetComponent <Collider>()); UnityEngine.Object.Destroy(base.GetComponent <Renderer>()); Transform newStairs = this.SpawnStairs(); if (this._stairsRoot) { UnityEngine.Object.Destroy(this._stairsRoot.gameObject); } this._stairsRoot = newStairs; Transform ghostRoot = this._stairsRoot; Transform transform = ghostRoot; transform.name += "Ghost"; this._logPool.Clear(); Transform logGhostPrefab = this._logPrefabs[0]; Transform StiltGhostPrefab = this._stiltPrefab; this._logPrefabs[0] = Prefabs.Instance.LogStairsBuiltPrefab; this._stiltPrefab = Prefabs.Instance.LogStiltStairsGhostBuiltPrefab; this._stairsRoot = this.SpawnStairs(); this._stairsRoot.name = "StairsRootBuilt"; this._logPool = null; this._newPool = null; Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); List <GameObject> logStacks = new List <GameObject>(); IEnumerator enumerator = this._stairsRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform2 = (Transform)obj; IEnumerator enumerator2 = transform2.GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj2 = enumerator2.Current; Transform transform3 = (Transform)obj2; transform3.gameObject.SetActive(false); logStacks.Add(transform3.gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator2 as IDisposable)) != null) { disposable.Dispose(); } } } } finally { IDisposable disposable2; if ((disposable2 = (enumerator as IDisposable)) != null) { disposable2.Dispose(); } } ri._renderers = logStacks.ToArray(); ri._amount += logStacks.Count; this._logPrefabs[0] = logGhostPrefab; this._stiltPrefab = StiltGhostPrefab; ghostRoot.transform.parent = null; base.transform.position = this._multiPointsPositions.First <Vector3>(); base.transform.LookAt(this._multiPointsPositions.Last <Vector3>()); this._stairsRoot.transform.parent = base.transform; ghostRoot.transform.parent = base.transform; BoxCollider bc; if (this._craftStructure.GetComponent <Collider>() is BoxCollider) { bc = (BoxCollider)this._craftStructure.GetComponent <Collider>(); } else { bc = this._craftStructure.gameObject.AddComponent <BoxCollider>(); bc.isTrigger = true; } Bounds b = default(Bounds); foreach (Vector3 position in this._multiPointsPositions) { b.Encapsulate(this._craftStructure.transform.InverseTransformPoint(position)); } b.Encapsulate(this._craftStructure.transform.InverseTransformPoint(this.GetPointFloorPosition(this._craftStructure.transform.position))); Vector3 localSize = b.size; localSize.x = Mathf.Max(localSize.x, 6f); localSize.y = Mathf.Max(localSize.y, 3f); localSize.z = Mathf.Max(localSize.z, 3f); bc.size = localSize; bc.center = b.center; bc.enabled = true; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); yield return(null); bc.enabled = false; bc.enabled = true; if (!this._craftStructure.gameObject.GetComponent <getStructureStrength>()) { getStructureStrength getStructureStrength = this._craftStructure.gameObject.AddComponent <getStructureStrength>(); getStructureStrength._strength = getStructureStrength.strength.normal; getStructureStrength._type = getStructureStrength.structureType.floor; } } yield break; }
private IEnumerator OnPlaced() { base.enabled = false; this._wasPlaced = true; yield return(null); yield return(null); if (!this._craftStructure) { this._craftStructure = base.GetComponentInChildren <Craft_Structure>(); } this._craftStructure.GetComponent <Collider>().enabled = false; Scene.HudGui.FoundationConstructionIcons.Shutdown(); if (this._tmpEdgeGo) { this._tmpEdgeGo.transform.parent = null; UnityEngine.Object.Destroy(this._tmpEdgeGo); } if (this._craftStructure) { Transform ghostRoot = this._gardenRoot; Transform transform = ghostRoot; transform.name += "Ghost"; int totalLogs = this._gardenRoot.childCount; Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); if (ri == null) { ri = new Craft_Structure.BuildIngredients(); ri._itemID = this._logItemId; ri._amount = 0; ri._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, ri); } List <GameObject> logs = new List <GameObject>(); IEnumerator enumerator = this._gardenRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform2 = (Transform)obj; logs.Add(transform2.GetComponentInChildren <Renderer>().gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } ri._amount += logs.Count; ri.AddRuntimeObjects(logs.AsEnumerable <GameObject>(), Prefabs.Instance.LogFloorBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial); this._gardenRoot.transform.parent = base.transform; ghostRoot.transform.parent = base.transform; this._craftStructure.GetComponent <Collider>().enabled = true; this._craftStructure.transform.localPosition = this._dirtCube.localPosition; BoxCollider bc = this._craftStructure.gameObject.GetComponent <BoxCollider>(); bc.size = this._dirtCube.localScale; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); yield return(null); this._logPool = null; this._newPool = null; } yield break; }
private IEnumerator OnPlaced(bool readyMp = false) { Debug.Log("Bridge - OnPlaced()"); this._wasPlaced = true; base.enabled = false; this._craftStructure.GetComponent <Collider>().enabled = false; Scene.HudGui.RoofConstructionIcons.Shutdown(); this._bridgeRoot.transform.parent = null; if (!this._anchor2 && this._tmpAnchor) { this._anchor2 = this._tmpAnchor; this._anchor2._hookedInStructure = this; this._tmpAnchor = null; } yield return(null); if (this._craftStructure) { UnityEngine.Object.Destroy(base.GetComponent <Rigidbody>()); UnityEngine.Object.Destroy(base.GetComponent <Collider>()); Transform ghostRoot = this._bridgeRoot; Transform transform = ghostRoot; transform.name += "Ghost"; this._logPool.Clear(); this._logPool = null; int totalLogs = this._bridgeRoot.childCount; Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); if (ri == null) { ri = new Craft_Structure.BuildIngredients(); ri._itemID = this._logItemId; ri._amount = 0; ri._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, ri); } ri._amount += totalLogs; List <GameObject> logs = new List <GameObject>(); IEnumerator enumerator = this._bridgeRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform2 = (Transform)obj; IEnumerator enumerator2 = transform2.GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj2 = enumerator2.Current; Transform transform3 = (Transform)obj2; logs.Add(transform3.GetComponentInChildren <Renderer>().gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator2 as IDisposable)) != null) { disposable.Dispose(); } } } } finally { IDisposable disposable2; if ((disposable2 = (enumerator as IDisposable)) != null) { disposable2.Dispose(); } } ri.AddRuntimeObjects(logs.AsEnumerable <GameObject>().Reverse <GameObject>(), Prefabs.Instance.LogBridgeBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial); ghostRoot.transform.parent = null; base.transform.position = this._anchor1.transform.position; base.transform.LookAt(this._anchor2.transform.position); this._bridgeRoot.transform.parent = base.transform; ghostRoot.transform.parent = base.transform; BoxCollider bc; if (this._craftStructure.GetComponent <Collider>() is BoxCollider) { bc = (BoxCollider)this._craftStructure.GetComponent <Collider>(); } else { bc = this._craftStructure.gameObject.AddComponent <BoxCollider>(); bc.isTrigger = true; } bc.size = new Vector3(4.5f, 30f, Vector3.Distance(this._anchor1.transform.position, this._anchor2.transform.position)); bc.center = new Vector3(0f, 0f, bc.size.z / 2f); bc.enabled = true; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); yield return(null); bc.enabled = false; bc.enabled = true; } yield break; }
private IEnumerator OnPlaced() { base.enabled = false; if (!this._craftStructure) { this._craftStructure = base.GetComponentInChildren <Craft_Structure>(); } try { this._craftStructure.GetComponent <Collider>().enabled = false; } catch (Exception message) { Debug.LogError(message); } yield return(null); if (this._craftStructure) { Transform ghostRoot = this._wallRoot; Transform transform = ghostRoot; transform.name += "Ghost"; this.InitAdditionTrigger(); Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); if (ri == null) { ri = new Craft_Structure.BuildIngredients(); ri._itemID = this._logItemId; ri._amount = 0; ri._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, ri); } else { ri._subIngredients.Clear(); } ri._amount = this.GetLogCost(); List <GameObject> builtRenderers = this.GetBuiltRenderers(this._wallRoot); ri.AddRuntimeObjects(builtRenderers, this.BuiltLogPrefab.GetComponentInChildren <Renderer>().sharedMaterial); this._craftStructure.GetComponent <Collider>().enabled = true; BoxCollider bc; if (this._craftStructure.GetComponent <Collider>() is BoxCollider) { bc = (BoxCollider)this._craftStructure.GetComponent <Collider>(); } else { bc = this._craftStructure.gameObject.AddComponent <BoxCollider>(); bc.isTrigger = true; } Vector3 axis = base.transform.InverseTransformVector(this._p2 - this._p1); bc.size = new Vector3(Mathf.Abs(axis.x), 4.5f, Mathf.Abs(axis.z)); this._craftStructure.transform.localPosition = bc.size / 2f; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); base.GetComponent <Renderer>().enabled = false; base.enabled = false; yield return(null); bc.enabled = false; bc.enabled = true; } yield break; }
private IEnumerator OnPlaced() { this._wasPlaced = true; UnityEngine.Object.Destroy(base.GetComponent <Rigidbody>()); UnityEngine.Object.Destroy(base.GetComponent <Collider>()); base.enabled = false; if (!this._craftStructure) { this._craftStructure = base.GetComponentInChildren <Craft_Structure>(); } try { this._craftStructure.GetComponent <Collider>().enabled = false; } catch (Exception message) { Debug.LogError(message); } yield return(null); if (this._craftStructure) { base.transform.parent = this._chunk.transform; if (!BoltNetwork.isRunning) { base.transform.position = Vector3.Lerp(this._chunk.P2, this._chunk.P1, 0.5f); } Transform ghostRoot = this._wallRoot; Transform transform = ghostRoot; transform.name += "Ghost"; Craft_Structure.BuildIngredients sri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._stickItemId); if (sri == null) { sri = new Craft_Structure.BuildIngredients(); sri._itemID = this._stickItemId; sri._amount = 0; sri._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, sri); } sri._amount += this.GetStickCost(); Craft_Structure.BuildIngredients rri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._rockItemId); if (rri == null) { rri = new Craft_Structure.BuildIngredients(); rri._itemID = this._stickItemId; rri._amount = 0; rri._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, rri); } rri._amount += this.GetRockCost(); List <GameObject> builtStickRenderers = new List <GameObject>(20); List <GameObject> builtRockRenderers = new List <GameObject>(20); foreach (Renderer renderer in this._wallRoot.GetComponentsInChildren <Renderer>()) { if (renderer.name.Equals("s")) { builtStickRenderers.Add(renderer.gameObject); } else { builtRockRenderers.Add(renderer.gameObject); } } sri.AddRuntimeObjects(builtStickRenderers, Prefabs.Instance.PerLogWDReinforcementBuiltPrefab.Find("s").GetComponent <Renderer>().sharedMaterial); rri.AddRuntimeObjects(builtRockRenderers, Prefabs.Instance.PerLogWDReinforcementBuiltPrefab.Find("r").GetComponent <Renderer>().sharedMaterial); this._craftStructure.GetComponent <Collider>().enabled = true; Collider c = this._craftStructure.GetComponent <Collider>(); yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); base.GetComponent <Renderer>().enabled = false; base.enabled = false; yield return(null); c.enabled = false; c.enabled = true; } yield break; }
private void Update() { if (this._initialized) { this.CheckText(); this.CheckNeeded(); Scene.HudGui.DestroyIcon.gameObject.SetActive(true); if (this._swapTo) { if (!Scene.HudGui.ToggleVariationIcon.activeSelf) { Scene.HudGui.ToggleVariationIcon.SetActive(true); } if (TheForest.Utils.Input.GetButtonDown("Rotate")) { this.SwapToNextGhost(); return; } } if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.5f, false)) { this.CancelBlueprint(); return; } if (this._lockBuild || (this.CustomLockCheck != null && this.CustomLockCheck())) { int num = 0; for (int i = 0; i < this._requiredIngredients.Count; i++) { num += this._requiredIngredients[i]._amount - this._presentIngredients[i]._amount; } if (num == 1) { this.AllOff(false); Scene.HudGui.CantPlaceIcon.SetActive(true); return; } } Scene.HudGui.CantPlaceIcon.SetActive(false); bool flag = false; for (int j = 0; j < this._requiredIngredients.Count; j++) { HudGui.BuildingIngredient icons = this.GetIcons(this._requiredIngredients[j]._itemID); if (this._requiredIngredients[j]._amount != this._presentIngredients[j]._amount) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[j]; ReceipeIngredient receipeIngredient = this._presentIngredients[j]; if (buildIngredients._amount > receipeIngredient._amount) { if (!LocalPlayer.Inventory.Owns(this._requiredIngredients[j]._itemID, true) && !Cheats.Creative) { icons.SetMissingIngredientColor(); } else { icons.SetAvailableIngredientColor(); if (this._nextAddItem < Time.time && !flag) { flag = true; if (!Scene.HudGui.AddBuildingIngredientIcon.activeSelf) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(true); } Scene.HudGui.AddBuildingIngredientIcon.transform.localPosition = icons._iconGo.transform.localPosition + new Vector3(0f, -50f, 0f); Scene.HudGui.AddBuildingIngredientIcon.transform.rotation = icons._iconGo.transform.rotation; if (this.GetBuildInputDown() || (Cheats.Creative && TheForest.Utils.Input.GetButton("Build"))) { if (Cheats.Creative) { this._nextAddItem = Time.time + 0.065f; } this.AddIngredient(j); break; } } } } } } if (!flag && Scene.HudGui.AddBuildingIngredientIcon.activeSelf) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(false); } if (Vector3.Dot(LocalPlayer.Transform.forward, this._uiFollowTarget.forward) < 0.75f || LocalPlayer.Transform.InverseTransformPoint(this._uiFollowTarget.position).z < 0f) { this.SetUpIcons(); } else if (SteamClientDSConfig.isDedicatedClient) { bool flag2 = LocalPlayer.Transform.InverseTransformPoint(this._uiFollowTarget.position).z >= 0f; float num2 = Vector3.Dot(LocalPlayer.Transform.forward, this._uiFollowTarget.forward); bool flag3 = num2 > 0.35f && num2 < 0.8f; if (flag2 && flag3) { this.SetUpIcons(); } } } }
private IEnumerator OnPlaced() { this._wasPlaced = true; base.enabled = false; this._craftStructure.GetComponent <Collider>().enabled = false; Scene.HudGui.RoofConstructionIcons.Shutdown(); yield return(null); if (this._craftStructure) { UnityEngine.Object.Destroy(base.GetComponent <Rigidbody>()); UnityEngine.Object.Destroy(base.GetComponent <Collider>()); Transform newDock = this.SpawnStructure(); if (this._dockRoot) { UnityEngine.Object.Destroy(this._dockRoot.gameObject); } this._dockRoot = newDock; Transform ghostRoot = this._dockRoot; Transform transform = ghostRoot; transform.name += "Ghost"; this._logPool = null; this._newPool = null; Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); List <GameObject> stairsLogs = new List <GameObject>(); List <GameObject> stiltsLogs = new List <GameObject>(); Material stiltMat = Prefabs.Instance.LogStiltStairsGhostBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial; IEnumerator enumerator = this._dockRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform2 = (Transform)obj; IEnumerator enumerator2 = transform2.GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj2 = enumerator2.Current; Transform transform3 = (Transform)obj2; IEnumerator enumerator3 = transform3.GetEnumerator(); try { while (enumerator3.MoveNext()) { object obj3 = enumerator3.Current; Transform transform4 = (Transform)obj3; Renderer componentInChildren = transform4.GetComponentInChildren <Renderer>(); if (componentInChildren.sharedMaterial == stiltMat) { stiltsLogs.Add(componentInChildren.gameObject); } else { stairsLogs.Add(componentInChildren.gameObject); } } } finally { IDisposable disposable; if ((disposable = (enumerator3 as IDisposable)) != null) { disposable.Dispose(); } } } } finally { IDisposable disposable2; if ((disposable2 = (enumerator2 as IDisposable)) != null) { disposable2.Dispose(); } } } } finally { IDisposable disposable3; if ((disposable3 = (enumerator as IDisposable)) != null) { disposable3.Dispose(); } } ri._amount = stiltsLogs.Count <GameObject>() + stairsLogs.Count <GameObject>() / 2; ri.AddRuntimeObjects(stairsLogs.AsEnumerable <GameObject>().Reverse <GameObject>(), Prefabs.Instance.LogStairsBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial); ri.AddRuntimeObjects(stiltsLogs.AsEnumerable <GameObject>().Reverse <GameObject>(), Prefabs.Instance.LogStiltStairsGhostBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial); ghostRoot.transform.parent = null; base.transform.position = this._multiPointsPositions.First <Vector3>(); base.transform.LookAt(this._multiPointsPositions.Last <Vector3>()); this._dockRoot.transform.parent = base.transform; ghostRoot.transform.parent = base.transform; BoxCollider bc; if (this._craftStructure.GetComponent <Collider>() is BoxCollider) { bc = (BoxCollider)this._craftStructure.GetComponent <Collider>(); } else { bc = this._craftStructure.gameObject.AddComponent <BoxCollider>(); bc.isTrigger = true; } Bounds b = default(Bounds); for (int j = 1; j < this._multiPointsPositions.Count; j++) { Vector3 a = this._multiPointsPositions[j]; Vector3 normalized = (a - this._multiPointsPositions[j - 1]).normalized; Vector3 b2 = Vector3.Cross(Vector3.up, normalized) * 3.5f; b.Encapsulate(base.transform.InverseTransformPoint(a + b2)); b.Encapsulate(base.transform.InverseTransformPoint(a - b2)); } bc.size = new Vector3(b.size.x, 6f, b.size.z); bc.center = b.center; bc.enabled = true; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); yield return(null); bc.enabled = false; bc.enabled = true; } yield break; }
private IEnumerator OnPlaced() { base.enabled = false; this._wasPlaced = true; yield return(null); yield return(null); if (!this._craftStructure) { this._craftStructure = base.GetComponentInChildren <Craft_Structure>(); } if (this._multiPointsPositions.Count > 0) { this._craftStructure.TriggerOffset = this.SupportCenter - this._craftStructure.transform.position; } this._craftStructure.GetComponent <Collider>().enabled = false; base.transform.localScale = Vector3.one; Scene.HudGui.FoundationConstructionIcons.Shutdown(); if (this._tmpEdgeGo) { this._tmpEdgeGo.transform.parent = null; UnityEngine.Object.Destroy(this._tmpEdgeGo); } if (this._craftStructure) { if (this._edges.Count == 0) { if (this._mode == FoundationArchitect.Modes.Auto) { this.RecalcPointsFromAutoBounds(); } this.CreateStructure(false); } GameObject ghostRoot = this._foundationRoot; GameObject gameObject = ghostRoot; gameObject.name += "Ghost"; int totalLogs = this._edges.Sum((FoundationArchitect.Edge e) => e._totalLogs); Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); if (ri == null) { ri = new Craft_Structure.BuildIngredients(); ri._itemID = this._logItemId; ri._amount = 0; ri._renderers = new GameObject[0]; this._craftStructure._requiredIngredients.Insert(0, ri); } List <GameObject> logs = new List <GameObject>(); foreach (GameObject gameObject2 in this._edgesGo) { IEnumerator enumerator2 = gameObject2.transform.GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj = enumerator2.Current; Transform transform = (Transform)obj; IEnumerator enumerator3 = transform.GetEnumerator(); try { while (enumerator3.MoveNext()) { object obj2 = enumerator3.Current; Transform transform2 = (Transform)obj2; ri._amount++; IEnumerator enumerator4 = transform2.GetEnumerator(); try { while (enumerator4.MoveNext()) { object obj3 = enumerator4.Current; Transform transform3 = (Transform)obj3; Renderer componentInChildren = transform3.GetComponentInChildren <Renderer>(); componentInChildren.sharedMaterial = Prefabs.Instance.GhostClear; logs.Add(componentInChildren.gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator4 as IDisposable)) != null) { disposable.Dispose(); } } } } finally { IDisposable disposable2; if ((disposable2 = (enumerator3 as IDisposable)) != null) { disposable2.Dispose(); } } } } finally { IDisposable disposable3; if ((disposable3 = (enumerator2 as IDisposable)) != null) { disposable3.Dispose(); } } } ri.AddRuntimeObjects(logs.AsEnumerable <GameObject>().Reverse <GameObject>(), Prefabs.Instance.LogBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial); if (this._mode == FoundationArchitect.Modes.Manual) { base.transform.position = this._multiPointsPositions[0]; base.transform.rotation = Quaternion.identity; } this._foundationRoot.transform.rotation = Quaternion.identity; this._foundationRoot.transform.parent = base.transform; ghostRoot.transform.rotation = Quaternion.identity; ghostRoot.transform.parent = base.transform; this._craftStructure.GetComponent <Collider>().enabled = true; BoxCollider bc = this._craftStructure.gameObject.AddComponent <BoxCollider>(); bc.isTrigger = true; Bounds b = new Bounds(base.transform.position, Vector3.zero); for (int j = 1; j < this._multiPointsPositions.Count; j++) { b.Encapsulate(this._multiPointsPositions[j]); } Vector3 bottom = base.transform.position; bottom.y -= this._edges.Max((FoundationArchitect.Edge e) => e._segments.Max((FoundationArchitect.HorizontalSegment s) => s._height)); b.Encapsulate(bottom); bc.center = this._craftStructure.transform.InverseTransformPoint(b.center); Vector3 finalColliderSize = this._craftStructure.transform.InverseTransformPoint(b.size + this._craftStructure.transform.position); float alpha = 0f; while (alpha < 1f) { bc.size = Vector3.Lerp(Vector3.zero, finalColliderSize, alpha += Time.deltaTime * 5f); yield return(null); } bc.size = finalColliderSize; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } if (this._mode != FoundationArchitect.Modes.ManualSlave) { this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); } if (this._mode == FoundationArchitect.Modes.Manual) { base.GetComponent <Renderer>().enabled = false; } yield return(null); this._logPool = null; this._newPool = null; this._edges = null; this._edgesGo = null; } yield break; }
private void SetUpIcons() { if (Application.isPlaying) { if (this._requiredIngredients != null) { if (!this._uiFollowTarget) { this._uiFollowTarget = new GameObject("UiFollowTarget").transform; this._uiFollowTarget.parent = base.transform; } if (this._bounds.size.sqrMagnitude == 0f) { this._bounds.center = base.transform.position; this._requiredIngredients.ForEach(delegate(Craft_Structure.BuildIngredients ri) { ri._subIngredients.ForEach(delegate(Craft_Structure.BuildIngredients.SubIngredient si) { si._renderers.ForEach(delegate(GameObject go) { if (go.activeSelf) { Renderer component = go.GetComponent <Renderer>(); if (component) { this._bounds.Encapsulate(component.bounds.center); } else if (go.transform.childCount > 0) { Transform child = go.transform.GetChild(0); component = child.GetComponent <Renderer>(); if (component) { this._bounds.Encapsulate(component.bounds.center); } else { this._bounds.Encapsulate(child.position); } } } this._bounds.Encapsulate(go.transform.position); }); }); }); } Vector3 position = LocalPlayer.MainCamTr.position; position.y = this._bounds.center.y; Vector3 forward = this._bounds.center + this.TriggerOffset - LocalPlayer.MainCamTr.position; float num = forward.magnitude * 0.9f; Vector3 vector = LocalPlayer.MainCamTr.position + forward.normalized * Mathf.Clamp(10f, 1f, num); vector.y = Mathf.Lerp(vector.y, LocalPlayer.MainCamTr.position.y, 0.5f); this._uiFollowTarget.position = vector; if (!this._bounds.Contains(position)) { Ray ray = new Ray(LocalPlayer.MainCamTr.position, (this._uiFollowTarget.position - LocalPlayer.MainCamTr.position).normalized); float a; if (this._bounds.IntersectRay(ray, out a)) { Vector3 point = ray.GetPoint(Mathf.Clamp(10f, 1f, Mathf.Min(a, num))); if (Vector3.Dot(LocalPlayer.Transform.forward, point - LocalPlayer.MainCamTr.position) > 0.35f) { this._uiFollowTarget.position = point; } } forward = this._uiFollowTarget.position - LocalPlayer.MainCamTr.position; } else if (Vector3.Dot(LocalPlayer.Transform.forward, vector - LocalPlayer.MainCamTr.position) < 0.1f) { this._uiFollowTarget.position = LocalPlayer.MainCamTr.position + LocalPlayer.MainCamTr.forward * Mathf.Clamp(10f, 1f, num); forward = this._uiFollowTarget.position - LocalPlayer.MainCamTr.position; } this._uiFollowTarget.rotation = Quaternion.LookRotation(forward); Scene.HudGui.BuildingIngredientsFollow._target = this._uiFollowTarget; for (int i = this._requiredIngredients.Count - 1; i >= 0; i--) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; HudGui.BuildingIngredient icons = this.GetIcons(buildIngredients._itemID); icons._iconGo.transform.SetAsFirstSibling(); } Scene.HudGui.BuildingIngredientsGrid.Reposition(); } else { UnityEngine.Object.Destroy(base.gameObject); } } }
private IEnumerator OnPlaced() { if (Vector3.Distance(this._multiPointsPositions[this._multiPointsPositions.Count - 1], this._multiPointsPositions[0]) >= this._closureSnappingDistance) { this._multiPointsPositions.Add(this._multiPointsPositions[0]); this.RefreshCurrentFloor(); } base.enabled = false; this._wasPlaced = true; yield return(null); if (!this._craftStructure) { this._craftStructure = base.GetComponentInChildren <Craft_Structure>(); } UnityEngine.Object.Destroy(base.GetComponent <Collider>()); UnityEngine.Object.Destroy(base.GetComponent <Rigidbody>()); this._craftStructure.GetComponent <Collider>().enabled = false; if (Scene.HudGui) { Scene.HudGui.RoofConstructionIcons.Shutdown(); } if (this._craftStructure) { Transform ghostRoot = this._raftRoot; Transform transform = ghostRoot; transform.name += "Ghost"; Transform logGhostPrefab = this._logPrefab; this._logPrefab = Prefabs.Instance.LogFloorBuiltPrefab; this._logPool = new Stack <Transform>(); this._newPool = new Stack <Transform>(); this._raftRoot = new GameObject("RaftRootBuilt").transform; this._raftRoot.position = this._multiPointsPositions[0]; this.SpawnFloor(); Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); List <GameObject> logStacks = new List <GameObject>(); IEnumerator enumerator = this._raftRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform2 = (Transform)obj; transform2.gameObject.SetActive(false); logStacks.Add(transform2.gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } if (ri._renderers != null) { ri._renderers = logStacks.Union(ri._renderers).ToArray <GameObject>(); } else { ri._renderers = logStacks.ToArray(); } ri._amount += this._raftRoot.childCount; this._logPrefab = logGhostPrefab; this._raftRoot.transform.parent = base.transform; ghostRoot.transform.parent = base.transform; this._craftStructure.GetComponent <Collider>().enabled = true; BoxCollider bc; if (this._craftStructure.GetComponent <Collider>() is BoxCollider) { bc = (BoxCollider)this._craftStructure.GetComponent <Collider>(); } else { bc = this._craftStructure.gameObject.AddComponent <BoxCollider>(); bc.isTrigger = true; } Bounds b = new Bounds(base.transform.position, Vector3.zero); for (int j = 1; j < this._multiPointsPositions.Count; j++) { b.Encapsulate(this._multiPointsPositions[j]); } Vector3 bottom = base.transform.position; bottom.y -= 5f; b.Encapsulate(bottom); bc.center = base.transform.InverseTransformPoint(b.center); Vector3 finalColliderSize = base.transform.InverseTransformVector(b.size); float alpha = 0f; while (alpha < 1f) { bc.size = Vector3.Lerp(Vector3.zero, finalColliderSize, alpha += Time.deltaTime * 5f); yield return(null); } bc.size = finalColliderSize; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); base.GetComponent <Renderer>().enabled = false; yield return(null); if (bc != null) { bc.enabled = false; bc.enabled = true; } this._logPool = null; this._newPool = null; this._rowPointsBuffer = null; } yield break; }
public void SpawnBackIngredients(int ingredientId) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientId]; ReceipeIngredient receipeIngredient = this._presentIngredients[ingredientId]; if (buildIngredients != null && receipeIngredient != null) { int num = buildIngredients._amount - receipeIngredient._amount; BuildMission.AddNeededToBuildMission(receipeIngredient._itemID, -num, true); int amount = this._presentIngredients[ingredientId]._amount; if (amount > 0) { Transform transform = BoltNetwork.isRunning ? ItemDatabase.ItemById(this._presentIngredients[ingredientId]._itemID)._pickupPrefabMP : ItemDatabase.ItemById(this._presentIngredients[ingredientId]._itemID)._pickupPrefab; if (transform) { Craft_Structure.PickupAxis pickupAxis = this._requiredIngredients[ingredientId]._pickupAxis; float f = (float)amount * 0.428571433f + 1f; int num2 = Mathf.Min(Mathf.RoundToInt(f), 10); int i = 0; while (i < num2) { int num3 = Mathf.RoundToInt((float)i / (float)num2 * (float)amount); int j; for (j = 0; j < this._requiredIngredients[ingredientId]._subIngredients.Count; j++) { if (this._requiredIngredients[ingredientId]._subIngredients[j]._renderers.Length > num3) { Transform transform2 = this._requiredIngredients[ingredientId]._subIngredients[j]._renderers[num3].transform; Transform transform3 = BoltNetwork.isRunning ? BoltNetwork.Instantiate(transform.gameObject).transform : UnityEngine.Object.Instantiate <Transform>(transform); transform3.position = transform2.position; if (pickupAxis != Craft_Structure.PickupAxis.X) { if (pickupAxis != Craft_Structure.PickupAxis.Y) { if (pickupAxis == Craft_Structure.PickupAxis.Z) { transform3.rotation = transform2.rotation; } } else { transform3.rotation = Quaternion.LookRotation(transform2.up); } } else { transform3.rotation = Quaternion.LookRotation(transform2.right); } i++; if (i >= num2) { break; } } else { num3 -= this._requiredIngredients[ingredientId]._subIngredients[j]._renderers.Length; } } if (j >= this._requiredIngredients[ingredientId]._subIngredients.Count) { break; } } } } } }
private IEnumerator OnPlaced() { if (!this._wasPlaced && !this._wasBuilt && !BoltNetwork.isClient) { base.transform.position = this._multiPointsPositions.First <Vector3>(); base.transform.LookAt(this._multiPointsPositions.Last <Vector3>()); this._multiPointsPositions = (from p in this._multiPointsPositions select this.$this.transform.InverseTransformPoint(p)).ToList <Vector3>(); } this.WasPlaced = true; base.enabled = false; this._craftStructure.GetComponent <Collider>().enabled = false; Scene.HudGui.RoofConstructionIcons.Shutdown(); Scene.HudGui.RotateIcon.SetActive(false); yield return(null); if (this._craftStructure) { UnityEngine.Object.Destroy(base.GetComponent <Rigidbody>()); UnityEngine.Object.Destroy(base.GetComponent <Collider>()); Transform newStairs = this.SpawnStructure(); if (this._stairsRoot) { UnityEngine.Object.Destroy(this._stairsRoot.gameObject); } this._stairsRoot = newStairs; Transform ghostRoot = this._stairsRoot; Transform transform = ghostRoot; transform.name += "Ghost"; this._logPool = null; this._newPool = null; Craft_Structure.BuildIngredients ri = this._craftStructure._requiredIngredients.FirstOrDefault((Craft_Structure.BuildIngredients i) => i._itemID == this.$this._logItemId); int amount = 0; List <GameObject> stairsLogs = new List <GameObject>(); List <GameObject> stiltsLogs = new List <GameObject>(); Material stiltMat = Prefabs.Instance.LogStiltStairsGhostBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial; IEnumerator enumerator = this._stairsRoot.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform2 = (Transform)obj; IEnumerator enumerator2 = transform2.GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj2 = enumerator2.Current; Transform transform3 = (Transform)obj2; amount++; IEnumerator enumerator3 = transform3.GetEnumerator(); try { while (enumerator3.MoveNext()) { object obj3 = enumerator3.Current; Transform transform4 = (Transform)obj3; Renderer componentInChildren = transform4.GetComponentInChildren <Renderer>(); if (componentInChildren.sharedMaterial == stiltMat) { stiltsLogs.Add(componentInChildren.gameObject); } else { stairsLogs.Add(componentInChildren.gameObject); } } } finally { IDisposable disposable; if ((disposable = (enumerator3 as IDisposable)) != null) { disposable.Dispose(); } } } } finally { IDisposable disposable2; if ((disposable2 = (enumerator2 as IDisposable)) != null) { disposable2.Dispose(); } } } } finally { IDisposable disposable3; if ((disposable3 = (enumerator as IDisposable)) != null) { disposable3.Dispose(); } } ri.AddRuntimeObjects(stiltsLogs.AsEnumerable <GameObject>().Reverse <GameObject>(), Prefabs.Instance.LogStiltStairsGhostBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial); ri.AddRuntimeObjects(stairsLogs.AsEnumerable <GameObject>().Reverse <GameObject>(), Prefabs.Instance.LogStairsBuiltPrefab.GetComponentInChildren <Renderer>().sharedMaterial); ri._amount += amount; ghostRoot.transform.parent = null; this._stairsRoot.transform.parent = base.transform; ghostRoot.transform.parent = base.transform; BoxCollider bc; if (this._craftStructure.GetComponent <Collider>() is BoxCollider) { bc = (BoxCollider)this._craftStructure.GetComponent <Collider>(); } else { bc = this._craftStructure.gameObject.AddComponent <BoxCollider>(); bc.isTrigger = true; } Bounds b = default(Bounds); foreach (Vector3 position in this._multiPointsPositions) { b.Encapsulate(this._craftStructure.transform.InverseTransformPoint(base.transform.TransformPoint(position))); } b.Encapsulate(this._craftStructure.transform.InverseTransformPoint(this.GetPointFloorPosition(this._craftStructure.transform.position))); Vector3 localSize = b.size; localSize.x = Mathf.Max(localSize.x, 6f); localSize.y = Mathf.Max(localSize.y, 3f); localSize.z = Mathf.Max(localSize.z, 3f); bc.size = localSize; bc.center = b.center; bc.enabled = true; yield return(null); this._craftStructure.manualLoading = true; while (LevelSerializer.IsDeserializing && !this._craftStructure.WasLoaded) { yield return(null); } this._craftStructure.Initialize(); this._craftStructure.gameObject.SetActive(true); yield return(null); bc.enabled = false; bc.enabled = true; if (!this._craftStructure.gameObject.GetComponent <getStructureStrength>()) { getStructureStrength getStructureStrength = this._craftStructure.gameObject.AddComponent <getStructureStrength>(); getStructureStrength._strength = getStructureStrength.strength.normal; getStructureStrength._type = getStructureStrength.structureType.floor; } } yield break; }
private bool TryAddTarget(PrefabIdentifier pi, Collider c) { if (pi) { IHoleStructure holeStructure = (IHoleStructure)pi.GetComponent(typeof(IHoleStructure)); if (holeStructure != null) { if (!this._targets.Contains(holeStructure) && holeStructure.HoleCount < 20) { Hole item; if (holeStructure is FloorArchitect) { if (!this._previewFloor || !(holeStructure as FloorArchitect).WasBuilt) { return false; } FloorArchitect floorArchitect = holeStructure as FloorArchitect; FloorArchitect floorArchitect2 = UnityEngine.Object.Instantiate<FloorArchitect>(this._previewFloor, floorArchitect.transform.position, floorArchitect.transform.rotation); floorArchitect.OnBuilt(floorArchitect2.gameObject); floorArchitect2._wasBuilt = false; this._previews.Add(floorArchitect2); item = floorArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } else if (holeStructure is RoofArchitect) { if (!this._previewRoof || !(holeStructure as RoofArchitect).WasBuilt) { return false; } RoofArchitect roofArchitect = holeStructure as RoofArchitect; RoofArchitect roofArchitect2 = UnityEngine.Object.Instantiate<RoofArchitect>(this._previewRoof, roofArchitect.transform.position, roofArchitect.transform.rotation); roofArchitect.OnBuilt(roofArchitect2.gameObject); roofArchitect2._wasBuilt = false; this._previews.Add(roofArchitect2); item = roofArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } else { if (holeStructure is CraneArchitect) { return false; } if (!(holeStructure is RaftArchitect) || !(holeStructure as RaftArchitect).WasBuilt) { UnityEngine.Debug.LogError("Trying to cut IHS '" + pi.name + "' which isn't roof, floor or raft. Please report this to guillaume."); return false; } if (!this._previewRaft || !(base.transform.root != pi.transform.root)) { return false; } RaftArchitect raftArchitect = holeStructure as RaftArchitect; RaftArchitect raftArchitect2 = UnityEngine.Object.Instantiate<RaftArchitect>(this._previewRaft, raftArchitect.transform.position, raftArchitect.transform.rotation); raftArchitect.OnBuilt(raftArchitect2.gameObject); this._previews.Add(raftArchitect2); item = raftArchitect2.AddSquareHole(base.transform.position, base.transform.rotation.y, this._holeSize); } this._targets.Add(holeStructure); this._holes.Add(item); this.CheckCanPlace(); return true; } } else { BuildingBlueprint blueprintByPrefabId = Prefabs.Instance.Constructions.GetBlueprintByPrefabId(pi.ClassId); if (blueprintByPrefabId != null && !blueprintByPrefabId._preventHoleCutting) { FloorHoleArchitect.DestroyTarget destroyTarget; if (!this._destroyTargets.TryGetValue(pi.gameObject, out destroyTarget)) { destroyTarget = new FloorHoleArchitect.DestroyTarget(); destroyTarget._go = pi.gameObject; destroyTarget._bh = pi.GetComponent<BuildingHealth>(); ICoopStructure component = pi.GetComponent<ICoopStructure>(); if (component != null) { IProceduralStructure component2 = pi.GetComponent<IProceduralStructure>(); if (component2 == null) { return false; } destroyTarget._ghost = component2.SpawnStructure().gameObject; } else { destroyTarget._ghost = UnityEngine.Object.Instantiate<GameObject>(blueprintByPrefabId._ghostPrefab, pi.transform.position, pi.transform.rotation); } destroyTarget._ghost.transform.parent = pi.transform; int layer = LayerMask.NameToLayer("TransparentFX"); Renderer component3 = destroyTarget._ghost.GetComponent<Renderer>(); if (component3) { destroyTarget._ghost.layer = layer; component3.sharedMaterial = this._overlayMaterial; } else { Craft_Structure componentInChildren = destroyTarget._ghost.GetComponentInChildren<Craft_Structure>(); if (componentInChildren && componentInChildren._requiredIngredients.Count > 0) { for (int i = 0; i < componentInChildren._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = componentInChildren._requiredIngredients[i]; buildIngredients.SetGhostMaterial(this._overlayMaterial); } } else { Renderer[] componentsInChildren = destroyTarget._ghost.GetComponentsInChildren<Renderer>(); foreach (Renderer renderer in componentsInChildren) { renderer.gameObject.layer = layer; renderer.sharedMaterial = this._overlayMaterial; } } } Transform transform = destroyTarget._ghost.transform.Find("Trigger"); if (transform) { UnityEngine.Object.Destroy(transform.gameObject); } LastBuiltLocation component4 = destroyTarget._ghost.GetComponent<LastBuiltLocation>(); if (component4) { UnityEngine.Object.Destroy(component4.gameObject); } LastBuiltLocation component5 = destroyTarget._ghost.GetComponent<LastBuiltLocation>(); if (component5) { UnityEngine.Object.Destroy(component5.gameObject); } UnityEngine.Object.Destroy(destroyTarget._ghost.GetComponent<PrefabIdentifier>()); UnityEngine.Object.Destroy(destroyTarget._ghost.GetComponent<SingleAnchorStructure>()); this._destroyTargets.Add(pi.gameObject, destroyTarget); } if (c && !destroyTarget._colliders.Contains(c)) { destroyTarget._colliders.Add(c); } this.CheckCanPlace(); return true; } } } return false; }