forked from UnityRPGv2/RPG
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created InventoryItemEditor/boilerplate
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
RPG Project/Assets/Scripts/Inventories/Editor/InventoryItemEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEditor.Callbacks; | ||
using UnityEngine; | ||
|
||
namespace GameDevTV.Inventories.Editor | ||
{ | ||
public class InventoryItemEditor : EditorWindow | ||
{ | ||
[NonSerialized] InventoryItem selected = null; | ||
|
||
|
||
|
||
/// <summary> | ||
/// This is the boilerplate code that all EditorWindows need to have in order to function. | ||
/// The MenuItem directive adds an item to the Editor Menu system. | ||
/// </summary> | ||
[MenuItem("Window/InventoryItem Editor")] | ||
public static void ShowEditorWindow() | ||
{ | ||
GetWindow(typeof(InventoryItemEditor), false, "InventoryItem"); | ||
} | ||
|
||
/// <summary> | ||
/// This is a special version of ShowEditorWindow that takes a parameter InventoryItem candidate. | ||
/// This makes it so that when you double click on an InventoryItem to "open" it, the window will automatically | ||
/// have the correct file selected. | ||
/// </summary> | ||
/// <param name="candidate"></param> | ||
public static void ShowEditorWindow(InventoryItem candidate) { | ||
InventoryItemEditor window = GetWindow(typeof(InventoryItemEditor), false, "Dialogue Editor") as InventoryItemEditor; | ||
if (candidate) | ||
{ | ||
window.OnSelectionChange(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The tag [OnOpenAsset(1)] hooks the OnOpenAsset method into the list of methods to check if | ||
/// an asset is the type of asset we should open. Since we want to open any child of InventoryItem | ||
/// we're checking to see if the asset can be cast as an InventoryItem. | ||
/// </summary> | ||
/// <param name="instanceID"></param> | ||
/// <param name="line"></param> | ||
/// <returns></returns> | ||
[OnOpenAsset(1)] | ||
public static bool OnOpenAsset(int instanceID, int line) | ||
{ | ||
InventoryItem candidate = EditorUtility.InstanceIDToObject(instanceID) as InventoryItem; | ||
if (candidate != null) | ||
{ | ||
ShowEditorWindow(candidate); //pass | ||
|
||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void OnSelectionChange() | ||
{ | ||
var candidate = EditorUtility.InstanceIDToObject(Selection.activeInstanceID) as InventoryItem; | ||
if (candidate == null) return; | ||
selected = candidate; | ||
Repaint(); | ||
} | ||
|
||
void OnGUI() | ||
{ | ||
if (!selected) | ||
{ | ||
EditorGUILayout.HelpBox("No Dialogue Selected", MessageType.Error); | ||
return; | ||
} | ||
EditorGUILayout.HelpBox($"{selected.name}/{selected.GetDisplayName()}", MessageType.Info); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
RPG Project/Assets/Scripts/Inventories/Editor/InventoryItemEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.