public static void NewBoardBeingPlaced(GameObject NewBoard) { if (NewBoard == null) { return; } DestroyBoardBeingPlaced(); BoardBeingPlaced = NewBoard; NewBoard.transform.parent = ReferenceObject.transform; CircuitBoardBeingPlaced = NewBoard.GetComponent <CircuitBoard>(); SetRotationState(); CapPlacingOffset(); StuffPlacer.BoardRotationLockAngle = Mathf.Round(StuffPlacer.BoardRotationLockAngle / 90f) * 90; // fixes being able to place boards at non-right angles by locking rotation beforehand StuffPlacer.RotationAboutUpVector = Mathf.RoundToInt(StuffPlacer.RotationAboutUpVector / 90) * 90f; if (!BoardBeingPlaced.GetComponent <ObjectInfo>()) { BoardBeingPlaced.AddComponent <ObjectInfo>().ComponentType = ComponentType.CircuitBoard; } BoardFunctions.DestroyAllWiresConnectedToBoardButNotPartOfIt(NewBoard); StuffPlacer.NewThingBeingPlaced(ReferenceObject); }
public bool LoadedMount = false; // set in LoadSaveObject private void Start() { if (!LoadedMount)// only do this for new mounts. This is uncomfortably hacky { GameObject TheBoardPart = Instantiate(References.Prefabs.CircuitBoard, transform); TheBoardPart.transform.localPosition = new Vector3(-0.15f, 0.65f, -0.15f); TheBoardPart.transform.localEulerAngles = new Vector3(0, 90, 90); TheBoardPart.AddComponent <ObjectInfo>().ComponentType = ComponentType.CircuitBoard; TheBoardPart.tag = "PlaceOnlyCircuitBoard"; Destroy(TheBoardPart.GetComponent <MegaMeshComponent>()); CircuitBoard board = TheBoardPart.GetComponent <CircuitBoard>(); board.CreateCuboid(); board.SetBoardColor(Color.white); // necessary for the board to appear in the selection menu MegaMeshManager.RemoveComponentImmediatelyOf(TheBoardPart); if (gameObject.layer == 5) { TheBoardPart.layer = 5; } if (StuffPlacer.GetThingBeingPlaced == gameObject) { StuffPlacer.NewThingBeingPlaced(gameObject); } // holy shit this is a terrible line of code. God damn. } else { transform.GetChild(1).tag = "PlaceOnlyCircuitBoard"; // this tag is applied to prevent actions like board moving and painting } Destroy(this); }
private static void MakeSureThingBeingPlacedIsCorrect() { if (SelectionMenu.Instance.CustomComponentSelected) { DoFancyModdedComponentThings(); return; } // replace ThingBeingPlaced when it should be replaced - when you switch selected things or when something was just placed if (SelectionMenu.Instance.SelectedThing != 0 && (SelectionMenu.Instance.SelectedThingJustChanged || StuffPlacer.GetThingBeingPlaced == null)) { StuffPlacer.NewThingBeingPlaced(Object.Instantiate(SelectionMenu.SelectedComponent)); DoThingsForNewComponents(StuffPlacer.GetThingBeingPlaced); } else if (SelectionMenu.Instance.SelectedThing == 0) { StuffPlacer.DeleteThingBeingPlaced(); } // switching to nothing selected deletes the thing being placed }