public void GenerateMenu() { if (Canvas.transform.childCount > 4) { for (int i = 4; i < Canvas.transform.childCount; i++) { Destroy(Canvas.transform.GetChild(i).gameObject); } } MaxSelectedThing = PlaceableObjectTypes.Count; for (int i = 0; i < PlaceableObjectTypes.Count; i++) { // create it and make it a child of the menu GameObject reference = Prefabs.ComponentTypeToPrefab(PlaceableObjectTypes[i]); GameObject boob = Instantiate(reference, Canvas.transform); // set its position RectTransform RectTransform = boob.AddComponent <RectTransform>(); RectTransform.anchorMax = Vector2.zero; RectTransform.anchorMin = Vector2.zero; RectTransform.pivot = Vector2.zero; RectTransform.anchoredPosition = new Vector2(StartingPosition.x + DistanceBetweenPositions + i * DistanceBetweenPositions, 70) + PlaceableObjectOffsets[i]; // set its scale RectTransform.localScale *= PlaceableObjectScaleFactor; // set its rotation RectTransform.rotation = Quaternion.Euler(0, 90, 0); // give it a label GameObject label = Instantiate(LabelPrefab, Canvas.transform); label.GetComponent <RectTransform>().anchoredPosition = new Vector2(StartingPosition.x + DistanceBetweenPositions + i * DistanceBetweenPositions, 40); label.GetComponent <TMPro.TMP_Text>().text = reference.name; } if (AllowModdedComponents) { CustomComponentButton.SetActive(true); MaxSelectedThing++; } // put the menu and everything in it on the UI layer so they can be seen by the UI camera Transform[] allChildren = Canvas.GetComponentsInChildren <Transform>(); foreach (Transform child in allChildren) { child.gameObject.layer = 5; } // get rid of components that are a problem in the selection menu MegaMeshComponent[] MegaMeshComponents = Canvas.GetComponentsInChildren <MegaMeshComponent>(); foreach (MegaMeshComponent mmc in MegaMeshComponents) { Destroy(mmc); } }
public static GameObject LoadSavedObject(SavedObjectV2 save, Transform parent = null) { ComponentType componenttype = SavedObjectTypeToObjectType[save.GetType()]; GameObject LoadedObject = null; if (componenttype == ComponentType.CustomObject) { LoadedObject = GetCustomPrefab((SavedCustomObject)save); } else { LoadedObject = UnityEngine.Object.Instantiate(Prefabs.ComponentTypeToPrefab(componenttype), parent); } LoadedObject.transform.localPosition = save.LocalPosition; LoadedObject.transform.localEulerAngles = save.LocalEulerAngles; LoadedObject.AddComponent <ObjectInfo>().ComponentType = componenttype; switch (componenttype) { // there is no case for objects with no special data to load case ComponentType.CustomObject: LoadCustomObject(LoadedObject, (SavedCustomObject)save); break; case ComponentType.CircuitBoard: LoadCircuitBoard(LoadedObject, (SavedCircuitBoard)save); break; case ComponentType.Wire: LoadWire(LoadedObject, (SavedWire)save); break; case ComponentType.Delayer: LoadDelayer(LoadedObject, (SavedDelayer)save); break; case ComponentType.PanelDisplay: case ComponentType.Display: LoadDisplay(LoadedObject, (SavedDisplay)save); break; case ComponentType.Inverter: LoadInverter(LoadedObject, (SavedInverter)save); break; case ComponentType.PanelLabel: case ComponentType.Label: LoadLabel(LoadedObject, (SavedLabel)save); break; case ComponentType.PanelSwitch: case ComponentType.Switch: // SWITCH-F*****G-CEPTION LoadSwitch(LoadedObject, (SavedSwitch)save); break; case ComponentType.ThroughBlotter: case ComponentType.Blotter: LoadBlotter(LoadedObject, (SavedBlotter)save); break; case ComponentType.Noisemaker: LoadNoisemaker(LoadedObject, (SavedNoisemaker)save); break; case ComponentType.Mount: LoadMount(LoadedObject); break; } if (save.CanHaveChildren) { foreach (SavedObjectV2 child in save.Children) { LoadSavedObject(child, LoadedObject.transform); } } return(LoadedObject); }