private void FinishConstruction(UtilityConnections connections) { Rotatable component = GetComponent <Rotatable>(); Orientation orientation = ((UnityEngine.Object)component != (UnityEngine.Object)null) ? component.GetOrientation() : Orientation.Neutral; int num = Grid.PosToCell(base.transform.GetLocalPosition()); UnmarkArea(); BuildingDef def = building.Def; int cell = num; Orientation orientation2 = orientation; Storage resource_storage = storage; Tag[] selected_elements = selectedElementsTags; float temperature = initialTemperature; float time = GameClock.Instance.GetTime(); GameObject gameObject = def.Build(cell, orientation2, resource_storage, selected_elements, temperature, true, time); gameObject.transform.rotation = base.transform.rotation; Rotatable component2 = gameObject.GetComponent <Rotatable>(); if ((UnityEngine.Object)component2 != (UnityEngine.Object)null) { component2.SetOrientation(orientation); } KAnimGraphTileVisualizer component3 = GetComponent <KAnimGraphTileVisualizer>(); if ((UnityEngine.Object)component3 != (UnityEngine.Object)null) { KAnimGraphTileVisualizer component4 = gameObject.GetComponent <KAnimGraphTileVisualizer>(); component4.Connections = connections; component3.skipCleanup = true; } KSelectable component5 = GetComponent <KSelectable>(); if ((UnityEngine.Object)component5 != (UnityEngine.Object)null && component5.IsSelected && (UnityEngine.Object)gameObject.GetComponent <KSelectable>() != (UnityEngine.Object)null) { component5.Unselect(); if (PlayerController.Instance.ActiveTool.name == "SelectTool") { ((SelectTool)PlayerController.Instance.ActiveTool).SelectNextFrame(gameObject.GetComponent <KSelectable>(), false); } } storage.ConsumeAllIgnoringDisease(); finished = true; this.DeleteObject(); }
private void TryBuild(int cell) { if (!((Object)visualizer == (Object)null) && (cell != lastDragCell || buildingOrientation != lastDragOrientation)) { int num = Grid.PosToCell(visualizer); if (num == cell || (!(bool)def.BuildingComplete.GetComponent <LogicPorts>() && !(bool)def.BuildingComplete.GetComponent <LogicGateBase>())) { lastDragCell = cell; lastDragOrientation = buildingOrientation; ClearTilePreview(); Vector3 vector = Grid.CellToPosCBC(cell, Grid.SceneLayer.Building); GameObject gameObject = null; if (DebugHandler.InstantBuildMode || (Game.Instance.SandboxModeActive && SandboxToolParameterMenu.instance.settings.InstantBuild)) { if (def.IsValidBuildLocation(visualizer, vector, buildingOrientation) && def.IsValidPlaceLocation(visualizer, vector, buildingOrientation, out string _)) { gameObject = def.Build(cell, buildingOrientation, null, selectedElements, 293.15f, false, GameClock.Instance.GetTime()); if ((Object)source != (Object)null) { source.DeleteObject(); } } } else { gameObject = def.TryPlace(visualizer, vector, buildingOrientation, selectedElements, 0); if ((Object)gameObject == (Object)null && def.ReplacementLayer != ObjectLayer.NumLayers) { GameObject replacementCandidate = def.GetReplacementCandidate(cell); if ((Object)replacementCandidate != (Object)null && !def.IsReplacementLayerOccupied(cell)) { BuildingComplete component = replacementCandidate.GetComponent <BuildingComplete>(); if ((Object)component != (Object)null && component.Def.Replaceable && def.CanReplace(replacementCandidate) && ((Object)component.Def != (Object)def || selectedElements[0] != replacementCandidate.GetComponent <PrimaryElement>().Element.tag)) { gameObject = def.TryReplaceTile(visualizer, vector, buildingOrientation, selectedElements, 0); Grid.Objects[cell, (int)def.ReplacementLayer] = gameObject; } } } if ((Object)gameObject != (Object)null) { Prioritizable component2 = gameObject.GetComponent <Prioritizable>(); if ((Object)component2 != (Object)null) { if ((Object)BuildMenu.Instance != (Object)null) { component2.SetMasterPriority(BuildMenu.Instance.GetBuildingPriority()); } if ((Object)PlanScreen.Instance != (Object)null) { component2.SetMasterPriority(PlanScreen.Instance.GetBuildingPriority()); } } if ((Object)source != (Object)null) { source.Trigger(2121280625, gameObject); } } } if ((Object)gameObject != (Object)null) { if (def.MaterialsAvailable(selectedElements) || DebugHandler.InstantBuildMode) { placeSound = GlobalAssets.GetSound("Place_Building_" + def.AudioSize, false); if (placeSound != null) { buildingCount = buildingCount % 14 + 1; EventInstance instance = SoundEvent.BeginOneShot(placeSound, vector); if (def.AudioSize == "small") { instance.setParameterValue("tileCount", (float)buildingCount); } SoundEvent.EndOneShot(instance); } } else { PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, UI.TOOLTIPS.NOMATERIAL, null, vector, 1.5f, false, false); } Rotatable component3 = gameObject.GetComponent <Rotatable>(); if ((Object)component3 != (Object)null) { component3.SetOrientation(buildingOrientation); } } } } }