void Awake() { instance = this; if (!PartDatabase.InitialLoadDone) { PartDatabase.ReloadPartsList(); } cam = Camera.main; }
private void OnGUI() { // On button press, we start the creation of a new button // We need to instantiate a new game object in the editor, assign it the if (GUILayout.Button("Create New Item")) { isCreated = true; } if (GUILayout.Button("Reset")) { isCreated = false; } if (isCreated) { // Item Core info EditorGUILayout.LabelField("CORE", EditorStyles.boldLabel); EditorGUI.indentLevel++; name = EditorGUILayout.TextField(new GUIContent("Name", "The name of the item."), name); description = EditorGUILayout.TextField(new GUIContent("Description", "The description of the item."), description); EditorGUI.indentLevel--; // Item Script reference EditorGUILayout.LabelField("SCRIPT", EditorStyles.boldLabel); EditorGUI.indentLevel++; origin = (Item)EditorGUILayout.ObjectField(new GUIContent("Item", "A reference to the script that will be used to create the prefab (must be an Item inheriting from MonoBehaviour)."), origin, typeof(Item), false); EditorGUI.indentLevel--; // Button that will open the "Crafting Bench" // This new popup window is used to define the crafting options for the item if (GUILayout.Button("Open Crafting Bench")) { CraftEditor.ShowWindow(origin); } //* Item Export to Prefab >> Item folder (button) if (GUILayout.Button("Export to Prefab")) { // We define the path to save the prefab (needs to be specific to each type of item) string path = GetItemExportPath(); // We create a new GameObject (template) to base the prefab off of it template = new GameObject(name); // We save the template as a prefab asset to the specified location PrefabUtility.SaveAsPrefabAsset(template, path); // We finally destroy the game object in the inspector Destroy(template); } //* Create instance and give to any entity } }