Update
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using Invector.vCharacterController;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
public class vCreateInventoryEditor : EditorWindow
|
||||
{
|
||||
GUISkin skin;
|
||||
GameObject inventoryPrefab;
|
||||
vItemListData itemListData;
|
||||
Vector2 rect = new Vector2(500, 240);
|
||||
Texture2D m_Logo;
|
||||
|
||||
[MenuItem("Invector/Inventory/ItemManager (Player Only)", false, 3)]
|
||||
public static void CreateNewInventory()
|
||||
{
|
||||
EditorWindow.GetWindow(typeof(vCreateInventoryEditor), true, "Item Manager Creator", true);
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if (!skin) skin = Resources.Load("vSkin") as GUISkin;
|
||||
GUI.skin = skin;
|
||||
|
||||
this.minSize = rect;
|
||||
m_Logo = Resources.Load("icon_v2") as Texture2D;
|
||||
GUILayout.BeginVertical("ITEM MANAGER CREATOR", "window", GUILayout.MaxHeight(100), GUILayout.MaxWidth(490));
|
||||
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
|
||||
|
||||
GUILayout.BeginVertical("box");
|
||||
EditorGUILayout.HelpBox("Go to the folder Invector/ItemManager/Prefabs to select a Inventory prefab", MessageType.Info);
|
||||
inventoryPrefab = EditorGUILayout.ObjectField("Inventory Prefab: ", inventoryPrefab, typeof(GameObject), false) as GameObject;
|
||||
EditorGUILayout.HelpBox("Go to the folder Invector/ItemManager/ItemListData to select a ItemListData or create a new one in the Inventory menu", MessageType.Info);
|
||||
itemListData = EditorGUILayout.ObjectField("Item List Data: ", itemListData, typeof(vItemListData), false) as vItemListData;
|
||||
|
||||
if (inventoryPrefab != null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Please select a Inventory Prefab, you can find one at the Inventory/Prefabs Folder", MessageType.Warning);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginHorizontal("box");
|
||||
EditorGUILayout.LabelField("Need to know how it works?");
|
||||
if (GUILayout.Button("Video Tutorial"))
|
||||
{
|
||||
Application.OpenURL("https://www.youtube.com/watch?v=1aA_PU9-G-0&index=3&list=PLvgXGzhT_qehtuCYl2oyL-LrWoT7fhg9d");
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
if (inventoryPrefab != null && itemListData != null)
|
||||
{
|
||||
if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent<vThirdPersonController>() != null)
|
||||
{
|
||||
if (GUILayout.Button("Create"))
|
||||
Create();
|
||||
}
|
||||
else
|
||||
EditorGUILayout.HelpBox("Please select the Player to add this component", MessageType.Warning);
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Created the ItemManager
|
||||
/// </summary>
|
||||
void Create()
|
||||
{
|
||||
if (Selection.activeGameObject != null)
|
||||
{
|
||||
var itemManager = Selection.activeGameObject.AddComponent<vItemManager>();
|
||||
if (inventoryPrefab != null)
|
||||
{
|
||||
var _inventory = PrefabUtility.InstantiatePrefab(inventoryPrefab.gameObject) as GameObject;
|
||||
_inventory.transform.SetParent(Selection.activeTransform);
|
||||
}
|
||||
|
||||
itemManager.itemListData = itemListData;
|
||||
vItemManagerUtilities.CreateDefaultEquipPoints(itemManager);
|
||||
}
|
||||
else
|
||||
Debug.Log("Please select the Player to add this component.");
|
||||
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dac8721713c231f4b84e1141164b6b3d
|
||||
timeCreated: 1486639442
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using System.Linq.Expressions;
|
||||
using System;
|
||||
namespace Invector
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(vHandler))]
|
||||
public class vHandlerDrawer : PropertyDrawer
|
||||
{
|
||||
vHandler handler = new vHandler();
|
||||
public int _mHeght;
|
||||
public GUISkin skin;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (skin == null)
|
||||
{
|
||||
skin = Resources.Load("vSkin") as GUISkin;
|
||||
if (skin == null)
|
||||
skin = GUI.skin;
|
||||
}
|
||||
|
||||
GUI.skin = skin;
|
||||
GUI.Box(position, "");
|
||||
var rect = position;
|
||||
rect.y += 2f;
|
||||
rect.x += 2.5f;
|
||||
rect.width -= 5;
|
||||
rect.height = 15;
|
||||
property.isExpanded = GUI.Toggle(rect, property.isExpanded, label, EditorStyles.miniButton);
|
||||
|
||||
if (property.isExpanded)
|
||||
{
|
||||
rect.y += GetBaseHeight();
|
||||
rect.width -= 5;
|
||||
rect.height = 16;
|
||||
handler.customHandlers = null;
|
||||
EditorGUI.PropertyField(rect, property.FindPropertyRelative(vEditorHelper.GetPropertyName(() => handler.defaultHandler)));
|
||||
var customHandlers = property.FindPropertyRelative(vEditorHelper.GetPropertyName(() => handler.customHandlers));
|
||||
rect.y += GetBaseHeight();
|
||||
EditorGUI.PropertyField(rect, customHandlers, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var height = 20f;
|
||||
if (property.isExpanded)
|
||||
{
|
||||
height += 40f;
|
||||
|
||||
var customHanglersName = vEditorHelper.GetPropertyName(() => handler.customHandlers);
|
||||
if (property.FindPropertyRelative(customHanglersName).isExpanded)
|
||||
{
|
||||
height += 20f + (GetBaseHeight() * property.FindPropertyRelative(customHanglersName).arraySize);
|
||||
}
|
||||
}
|
||||
return height + _mHeght;
|
||||
}
|
||||
|
||||
float GetBaseHeight()
|
||||
{
|
||||
return 18f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e09097d06fd910345a2918f0795f853a
|
||||
timeCreated: 1484053968
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,269 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(vItemCollection))]
|
||||
public class vItemCollectionEditor : vEditorBase
|
||||
{
|
||||
vItemCollection manager;
|
||||
SerializedProperty itemReferenceList;
|
||||
bool inAddItem;
|
||||
int selectedItem;
|
||||
List<vItem> filteredItems;
|
||||
Vector2 scroll;
|
||||
Rect buttonRect;
|
||||
List<vItemType> filter = new List<vItemType>();
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
manager = (vItemCollection)target;
|
||||
skin = Resources.Load("vSkin") as GUISkin;
|
||||
itemReferenceList = serializedObject.FindProperty("items");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var oldSkin = GUI.skin;
|
||||
|
||||
serializedObject.Update();
|
||||
if (skin)
|
||||
{
|
||||
GUI.skin = skin;
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
GUI.skin = oldSkin;
|
||||
base.OnInspectorGUI();
|
||||
if (skin)
|
||||
{
|
||||
GUI.skin = skin;
|
||||
}
|
||||
|
||||
bool usingToolbar = toolbars.Count > 1;
|
||||
string selectedToolbarName = toolbars[selectedToolBar].title;
|
||||
if (manager.itemListData && ((usingToolbar && selectedToolbarName.Equals("Item Collection")) || !usingToolbar))
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
//if (itemReferenceList.arraySize > manager.itemListData.items.Count)
|
||||
//{
|
||||
// manager.items.Resize(manager.itemListData.items.Count);
|
||||
//}
|
||||
GUILayout.Box("Item Collection " + manager.items.Count);
|
||||
if (GUILayout.Button("Add Item", EditorStyles.miniButton))
|
||||
{
|
||||
PopupWindow.Show(buttonRect, new vItemSelector
|
||||
(manager.itemListData.items, ref filter, (vItem item) =>//OnSelectItem
|
||||
{
|
||||
itemReferenceList.arraySize++;
|
||||
itemReferenceList.GetArrayElementAtIndex(itemReferenceList.arraySize - 1).FindPropertyRelative("id").intValue = item.id;
|
||||
itemReferenceList.GetArrayElementAtIndex(itemReferenceList.arraySize - 1).FindPropertyRelative("amount").intValue = 1;
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
));
|
||||
}
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
buttonRect = GUILayoutUtility.GetLastRect();
|
||||
}
|
||||
|
||||
GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
|
||||
scroll = GUILayout.BeginScrollView(scroll, GUILayout.MinHeight(200), GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false));
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < manager.items.Count; i++)
|
||||
{
|
||||
var item = manager.itemListData.items.Find(t => t.id.Equals(manager.items[i].id));
|
||||
if (item)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
var rect = GUILayoutUtility.GetRect(50, 50);
|
||||
|
||||
if (item.icon != null)
|
||||
{
|
||||
DrawTextureGUI(rect, item.icon, new Vector2(50, 50));
|
||||
}
|
||||
|
||||
var name = " ID " + item.id.ToString("00") + "\n - " + item.name + "\n - " + item.type.ToString();
|
||||
var content = new GUIContent(name, null, "Click to Open");
|
||||
GUILayout.Label(content, EditorStyles.miniLabel);
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Add to EquipArea", EditorStyles.miniLabel);
|
||||
manager.items[i].addToEquipArea = EditorGUILayout.Toggle("", manager.items[i].addToEquipArea, GUILayout.Width(30));
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
if (manager.items[i].addToEquipArea)
|
||||
{
|
||||
GUILayout.Label("EquipArea", EditorStyles.miniLabel);
|
||||
manager.items[i].indexArea = EditorGUILayout.IntField("", manager.items[i].indexArea, GUILayout.Width(30));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (manager.items[i].addToEquipArea)
|
||||
{
|
||||
GUILayout.Label("AutoEquip", EditorStyles.miniLabel);
|
||||
manager.items[i].autoEquip = EditorGUILayout.Toggle("", manager.items[i].autoEquip, GUILayout.Width(30));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Amount", EditorStyles.miniLabel);
|
||||
manager.items[i].amount = EditorGUILayout.IntField(manager.items[i].amount, GUILayout.Width(30));
|
||||
|
||||
if (manager.items[i].amount < 1)
|
||||
{
|
||||
manager.items[i].amount = 1;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
if (item.attributes.Count > 0)
|
||||
{
|
||||
manager.items[i].changeAttributes = GUILayout.Toggle(manager.items[i].changeAttributes, new GUIContent("Change Attributes", "This is a override of the original item attributes"), EditorStyles.miniButton, GUILayout.ExpandWidth(true));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (GUILayout.Button("x", GUILayout.Width(25), GUILayout.Height(25)))
|
||||
{
|
||||
itemReferenceList.DeleteArrayElementAtIndex(i);
|
||||
EditorUtility.SetDirty(target);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
break;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
Color backgroundColor = GUI.backgroundColor;
|
||||
GUI.backgroundColor = Color.clear;
|
||||
var _rec = GUILayoutUtility.GetLastRect();
|
||||
_rec.width -= 100;
|
||||
|
||||
EditorGUIUtility.AddCursorRect(_rec, MouseCursor.Link);
|
||||
|
||||
if (GUI.Button(_rec, ""))
|
||||
{
|
||||
if (manager.itemListData.inEdition)
|
||||
{
|
||||
if (vItemListWindow.Instance != null)
|
||||
{
|
||||
vItemListWindow.SetCurrentSelectedItem(manager.itemListData.items.IndexOf(item));
|
||||
}
|
||||
else
|
||||
{
|
||||
vItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item));
|
||||
}
|
||||
}
|
||||
GUILayout.Space(7);
|
||||
GUI.backgroundColor = backgroundColor;
|
||||
if (item.attributes != null && item.attributes.Count > 0)
|
||||
{
|
||||
|
||||
if (manager.items[i].changeAttributes)
|
||||
{
|
||||
if (GUILayout.Button("Reset", EditorStyles.miniButton))
|
||||
{
|
||||
manager.items[i].attributes = null;
|
||||
|
||||
}
|
||||
if (manager.items[i].attributes == null)
|
||||
{
|
||||
manager.items[i].attributes = item.attributes.CopyAsNew();
|
||||
}
|
||||
else if (manager.items[i].attributes.Count != item.attributes.Count)
|
||||
{
|
||||
manager.items[i].attributes = item.attributes.CopyAsNew();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int a = 0; a < manager.items[i].attributes.Count; a++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(manager.items[i].attributes[a].name.ToString());
|
||||
manager.items[i].attributes[a].value = EditorGUILayout.IntField(manager.items[i].attributes[a].value, GUILayout.MaxWidth(60));
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
else
|
||||
{
|
||||
itemReferenceList.DeleteArrayElementAtIndex(i);
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
GUI.skin.box = boxStyle;
|
||||
|
||||
GUILayout.EndVertical();
|
||||
if (GUI.changed)
|
||||
{
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
if (GUI.changed)
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
GUI.skin = oldSkin;
|
||||
}
|
||||
|
||||
GUIContent[] GetItemContents(List<vItem> items)
|
||||
{
|
||||
GUIContent[] names = new GUIContent[items.Count];
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
var texture = items[i].icon != null ? items[i].icon.texture : null;
|
||||
names[i] = new GUIContent(items[i].name, texture, items[i].description);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
List<vItem> GetItemByFilter(List<vItem> items, List<vItemType> filter)
|
||||
{
|
||||
return items.FindAll(i => filter.Contains(i.type));
|
||||
}
|
||||
|
||||
void DrawTextureGUI(Rect position, Sprite sprite, Vector2 size)
|
||||
{
|
||||
Rect spriteRect = new Rect(sprite.rect.x / sprite.texture.width, sprite.rect.y / sprite.texture.height,
|
||||
sprite.rect.width / sprite.texture.width, sprite.rect.height / sprite.texture.height);
|
||||
Vector2 actualSize = size;
|
||||
|
||||
actualSize.y *= (sprite.rect.height / sprite.rect.width);
|
||||
GUI.DrawTextureWithTexCoords(new Rect(position.x, position.y + (size.y - actualSize.y) / 2, actualSize.x, actualSize.y), sprite.texture, spriteRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac69c1404ff5bf248953affa91ab5248
|
||||
timeCreated: 1471979785
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
/// <summary>
|
||||
/// This attribute is used to draw aditional custom editor like a ToolBar for <see cref="vItem"/> in partial classes of the <see cref="vItemDrawer"/> using <see cref="vItemDrawer.OnDrawItem"/>
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public class vItemDrawerToolBarAttribute : Attribute
|
||||
{
|
||||
public string title;
|
||||
public vItemDrawerToolBarAttribute(string title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa5629b19d02aa7498d8a161883cefe2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
[CustomEditor(typeof(vItem), true)]
|
||||
public class vItemEditor : UnityEditor.Editor
|
||||
{
|
||||
protected virtual string[] excludedProperties => new string[] { "m_Script" };
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
DrawPropertiesExcluding(serializedObject, excludedProperties);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public partial class vItemDrawer
|
||||
{
|
||||
public vItem item;
|
||||
protected bool inAddAttribute;
|
||||
protected vItemAttributes attribute;
|
||||
protected int attributeValue;
|
||||
protected int indexToolbar;
|
||||
protected bool inEditName;
|
||||
protected string currentName;
|
||||
protected vItemEditor defaultEditor;
|
||||
public List<ToolBars> itemToolBars;
|
||||
public delegate void OnDrawItem(ref List<vItem> items, bool showObject = true, bool editName = false);
|
||||
|
||||
[Serializable]
|
||||
public class ToolBars
|
||||
{
|
||||
public string title;
|
||||
public OnDrawItem onDraw;
|
||||
public ToolBars(string title, OnDrawItem onDraw)
|
||||
{
|
||||
this.title = title;
|
||||
this.onDraw = onDraw;
|
||||
}
|
||||
}
|
||||
|
||||
public vItemDrawer(vItem item)
|
||||
{
|
||||
this.item = item;
|
||||
defaultEditor = (vItemEditor)Editor.CreateEditor(this.item, typeof(vItemEditor));
|
||||
FindDrawers();
|
||||
}
|
||||
|
||||
void FindDrawers()
|
||||
{
|
||||
var methods = this.GetType().GetMethods().Where(m => m.GetCustomAttributes(typeof(vItemDrawerToolBarAttribute), true).Length > 0).ToArray();
|
||||
itemToolBars = new List<ToolBars>();
|
||||
itemToolBars.Add(new ToolBars("Properties", new OnDrawItem(DrawAllProperties)));
|
||||
for (int i = 0; i < methods.Length; i++)
|
||||
{
|
||||
string title = (methods[i].GetCustomAttributes(typeof(vItemDrawerToolBarAttribute), true)[0] as vItemDrawerToolBarAttribute).title;
|
||||
OnDrawItem onDraw = (OnDrawItem)Delegate.CreateDelegate(typeof(OnDrawItem), this, methods[i]);
|
||||
itemToolBars.Add(new ToolBars(title, onDraw));
|
||||
}
|
||||
}
|
||||
|
||||
private string[] titles = new string[] { "Properties" };
|
||||
|
||||
public string[] ToolBarTitles()
|
||||
{
|
||||
if (titles == null || titles.Length != itemToolBars.Count)
|
||||
{
|
||||
titles = new string[itemToolBars.Count];
|
||||
for (int i = 0; i < itemToolBars.Count; i++)
|
||||
{
|
||||
titles[i] = itemToolBars[i].title;
|
||||
}
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
public virtual void DrawItem(ref List<vItem> items, bool showObject = true, bool editName = false)
|
||||
{
|
||||
if (!item) return;
|
||||
|
||||
SerializedObject _item = new SerializedObject(item);
|
||||
_item.Update();
|
||||
|
||||
try
|
||||
{
|
||||
if (itemToolBars.Count > 1) indexToolbar = GUILayout.Toolbar(indexToolbar, ToolBarTitles());
|
||||
itemToolBars[indexToolbar].onDraw(ref items, showObject, editName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
FindDrawers();
|
||||
}
|
||||
if (GUI.changed || _item.ApplyModifiedProperties())
|
||||
{
|
||||
EditorUtility.SetDirty(item);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawAllProperties(ref List<vItem> items, bool showObject, bool editName)
|
||||
{
|
||||
DrawItemHeader(ref items, showObject, editName);
|
||||
DrawItemProperties();
|
||||
DrawDefaultProperties();
|
||||
}
|
||||
|
||||
public virtual void DrawItemHeader(ref List<vItem> items, bool showObject, bool editName)
|
||||
{
|
||||
if (showObject)
|
||||
EditorGUILayout.ObjectField(item, typeof(vItem), false);
|
||||
|
||||
if (editName)
|
||||
item.name = EditorGUILayout.TextField("Item name", item.name);
|
||||
else
|
||||
{
|
||||
GUILayout.BeginHorizontal("box");
|
||||
GUILayout.Label(item.name, GUILayout.ExpandWidth(true));
|
||||
if (!inEditName && GUILayout.Button("EditName", EditorStyles.miniButton))
|
||||
{
|
||||
currentName = item.name;
|
||||
inEditName = true;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
if (inEditName)
|
||||
{
|
||||
var sameItemName = items.Find(i => i.name == currentName && i != item);
|
||||
currentName = EditorGUILayout.TextField("New Name", currentName);
|
||||
|
||||
GUILayout.BeginHorizontal("box");
|
||||
if (sameItemName == null && !string.IsNullOrEmpty(currentName) && GUILayout.Button("OK", EditorStyles.miniButton, GUILayout.MinWidth(60)))
|
||||
{
|
||||
item.name = currentName;
|
||||
inEditName = false;
|
||||
}
|
||||
if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.MinWidth(60)))
|
||||
{
|
||||
inEditName = false;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
if (sameItemName != null)
|
||||
EditorGUILayout.HelpBox("This name already exist", MessageType.Error);
|
||||
if (string.IsNullOrEmpty(currentName))
|
||||
EditorGUILayout.HelpBox("This name can not be empty", MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawItemProperties()
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
EditorGUILayout.LabelField("Description");
|
||||
|
||||
item.description = EditorGUILayout.TextArea(item.description);
|
||||
item.type = (vItemType)EditorGUILayout.EnumPopup("Item Type", item.type);
|
||||
item.stackable = EditorGUILayout.Toggle("Stackable", item.stackable);
|
||||
|
||||
if (item.stackable)
|
||||
{
|
||||
if (item.maxStack <= 0) item.maxStack = 1;
|
||||
item.createNewItem = true;
|
||||
item.maxStack = EditorGUILayout.IntField("Max Stack", item.maxStack);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("True: Add a new item creating multiple items of the same id \nFalse: Do not create a new item but call the OnCollectItemRef if you already have one.", MessageType.Info);
|
||||
item.createNewItem = EditorGUILayout.Toggle(new GUIContent("Create new Item"), item.createNewItem);
|
||||
item.maxStack = 1;
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Icon");
|
||||
item.icon = (Sprite)EditorGUILayout.ObjectField(item.icon, typeof(Sprite), false);
|
||||
var rect = GUILayoutUtility.GetRect(40, 40);
|
||||
|
||||
if (item.icon != null)
|
||||
{
|
||||
DrawTextureGUI(rect, item.icon, new Vector2(40, 40));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Label("Spawn Object");
|
||||
item.originalObject = (GameObject)EditorGUILayout.ObjectField(item.originalObject, typeof(GameObject), false);
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Label("Drop Object");
|
||||
item.dropObject = (GameObject)EditorGUILayout.ObjectField(item.dropObject, typeof(GameObject), false);
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
|
||||
DrawAttributes();
|
||||
}
|
||||
|
||||
public virtual void DrawDefaultProperties()
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Box(new GUIContent("Custom Settings", "This area is used for additional properties\n in vItem Properties in defaultInspector region"));
|
||||
defaultEditor.OnInspectorGUI();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
public virtual void DrawAttributes()
|
||||
{
|
||||
try
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Box("Attributes", GUILayout.ExpandWidth(true));
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (!inAddAttribute && GUILayout.Button("Add Attribute", EditorStyles.miniButton))
|
||||
inAddAttribute = true;
|
||||
|
||||
if (inAddAttribute)
|
||||
{
|
||||
GUILayout.BeginHorizontal("box");
|
||||
attribute = (vItemAttributes)EditorGUILayout.EnumPopup(attribute);
|
||||
|
||||
EditorGUILayout.LabelField("Value", GUILayout.MinWidth(60));
|
||||
attributeValue = EditorGUILayout.IntField(attributeValue);
|
||||
GUILayout.EndHorizontal();
|
||||
if (item.attributes != null && item.attributes.Contains(attribute))
|
||||
{
|
||||
EditorGUILayout.HelpBox("This attribute already exist ", MessageType.Error);
|
||||
if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.MinWidth(60)))
|
||||
{
|
||||
inAddAttribute = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.BeginHorizontal("box");
|
||||
if (GUILayout.Button("Add", EditorStyles.miniButton, GUILayout.MinWidth(60)))
|
||||
{
|
||||
item.attributes.Add(new vItemAttribute(attribute, attributeValue));
|
||||
|
||||
attributeValue = 0;
|
||||
inAddAttribute = false;
|
||||
|
||||
}
|
||||
if (GUILayout.Button("Cancel", EditorStyles.miniButton, GUILayout.MinWidth(60)))
|
||||
{
|
||||
attributeValue = 0;
|
||||
inAddAttribute = false;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space();
|
||||
for (int i = 0; i < item.attributes.Count; i++)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
item.attributes[i].isOpen = EditorGUILayout.Foldout(item.attributes[i].isOpen, item.attributes[i].name.ToString());
|
||||
item.attributes[i].value = EditorGUILayout.IntField(item.attributes[i].value);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (GUILayout.Button("x", GUILayout.MaxWidth(30)))
|
||||
{
|
||||
item.attributes.RemoveAt(i);
|
||||
GUILayout.EndHorizontal();
|
||||
break;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
if (item.attributes[i].isOpen)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Open the ItemEnumsEditor to edit this format", MessageType.Info);
|
||||
string format = item.attributes[i].displayFormat;
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Display format");
|
||||
GUILayout.Label(format, EditorStyles.whiteBoldLabel);
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("ERROR");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawTextureGUI(Rect position, Sprite sprite, Vector2 size)
|
||||
{
|
||||
Rect spriteRect = new Rect(sprite.rect.x / sprite.texture.width, sprite.rect.y / sprite.texture.height,
|
||||
sprite.rect.width / sprite.texture.width, sprite.rect.height / sprite.texture.height);
|
||||
Vector2 actualSize = size;
|
||||
|
||||
actualSize.y *= (sprite.rect.height / sprite.rect.width);
|
||||
GUI.DrawTextureWithTexCoords(new Rect(position.x, position.y + (size.y - actualSize.y) / 2, actualSize.x, actualSize.y), sprite.texture, spriteRect);
|
||||
}
|
||||
|
||||
public static List<T> FindAssetsByType<T>() where T : UnityEngine.Object
|
||||
{
|
||||
List<T> assets = new List<T>();
|
||||
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
|
||||
for (int i = 0; i < guids.Length; i++)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||
T asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
|
||||
if (asset != null)
|
||||
{
|
||||
assets.Add(asset);
|
||||
}
|
||||
}
|
||||
|
||||
return assets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93696df1569046e4782f040352266978
|
||||
timeCreated: 1468544068
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,231 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
//public static class vItemEnumHelper
|
||||
//{
|
||||
// public static string GetEnumDescription(this Enum value)
|
||||
// {
|
||||
// FieldInfo fi = value.GetType().GetField(value.ToString());
|
||||
|
||||
// DescriptionAttribute[] attributes = fi.GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[];
|
||||
|
||||
// if (attributes != null && attributes.Any())
|
||||
// {
|
||||
// return attributes.First().Description;
|
||||
// }
|
||||
|
||||
// return value.ToString();
|
||||
// }
|
||||
//}
|
||||
public class vItemEnumsWindow : EditorWindow
|
||||
{
|
||||
public vItemEnumsList[] datas;
|
||||
public List<string> _itemTypeNames = new List<string>();
|
||||
public List<string> _itemAttributeNames = new List<string>();
|
||||
public List<string> _itemTypeEnumFormats = new List<string>();
|
||||
public List<string> _itemAttributesEnumFormats = new List<string>();
|
||||
public List<DynamicEnum.vItemEnumsListEditor> itemEnumEditorList = new List<DynamicEnum.vItemEnumsListEditor>();
|
||||
public GUISkin skin;
|
||||
public Vector2 scrollTypes,scrollAttributes;
|
||||
public Vector2 scrollList;
|
||||
public static vItemEnumsWindow instance;
|
||||
[MenuItem("Invector/Inventory/ItemEnums/Open ItemEnums Editor")]
|
||||
public static void CreateWindow()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
var window = vItemEnumsWindow.GetWindow<vItemEnumsWindow>("Item Enums", true);
|
||||
instance = window;
|
||||
window.skin = Resources.Load("vSkin") as GUISkin;
|
||||
#region Get all vItemType values of current Enum
|
||||
try
|
||||
{
|
||||
window._itemTypeNames = Enum.GetNames(typeof(vItemType)).vToList();
|
||||
for (int i = 0; i < window._itemTypeNames.Count; i++)
|
||||
{
|
||||
vItemType att = (vItemType)Enum.Parse(typeof(vItemType), (window._itemTypeNames[i]));
|
||||
window._itemTypeEnumFormats.Add(att.DisplayFormat());
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Get all vItemAttributes values of current Enum
|
||||
try
|
||||
{
|
||||
window._itemAttributeNames = Enum.GetNames(typeof(vItemAttributes)).vToList();
|
||||
for(int i = 0;i<window._itemAttributeNames.Count;i++)
|
||||
{
|
||||
vItemAttributes att = (vItemAttributes)Enum.Parse(typeof(vItemAttributes),(window._itemAttributeNames[i]));
|
||||
window._itemAttributesEnumFormats.Add(att.DisplayFormat());
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
window.datas = Resources.LoadAll<vItemEnumsList>("");
|
||||
for(int i=0;i<window.datas.Length;i++)
|
||||
{
|
||||
window.itemEnumEditorList.Add(DynamicEnum.vItemEnumsListEditor.CreateEditor(window.datas[i]) as DynamicEnum.vItemEnumsListEditor);
|
||||
}
|
||||
window.minSize = new Vector2(460, 600);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if (skin) GUI.skin = skin;
|
||||
this.minSize = new Vector2(460, 600);
|
||||
GUILayout.BeginVertical("box");
|
||||
DrawEnums();
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Box("Edit Enums");
|
||||
scrollList = GUILayout.BeginScrollView(scrollList, GUILayout.ExpandWidth(true), GUILayout.MinHeight(100), GUILayout.MaxHeight(600));
|
||||
EditorGUILayout.HelpBox("**Format : Rich Text Format usage to create custom text format to display the Item Enums in the inventory like a\n" +
|
||||
" Special Tags : (NAME) : dipllay name of the Enum\n" +
|
||||
" (VALUE): display value of the Attribute (only for Item Attribute Enum)\n" +
|
||||
"Keep Format empty to use Default display", MessageType.Info);
|
||||
for (int i = 0; i < itemEnumEditorList.Count; i++)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
EditorGUILayout.ObjectField(itemEnumEditorList[i].serializedObject.targetObject, typeof(vItemEnumsList), false);
|
||||
itemEnumEditorList[i].serializedObject.Update();
|
||||
itemEnumEditorList[i].DrawEnumList();
|
||||
if (GUI.changed)
|
||||
{
|
||||
itemEnumEditorList[i].serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(10);
|
||||
GUILayout.Box("", GUILayout.Height(5));
|
||||
GUILayout.Space(10);
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Refresh ItemEnums", "Save and refesh changes to vItemEnums")))
|
||||
{
|
||||
vItemEnumsBuilder.RefreshItemEnums();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawEnums()
|
||||
{
|
||||
GUILayout.Box("vItemEnums");
|
||||
int size = _itemTypeNames.Count > _itemAttributeNames.Count ? _itemTypeNames.Count : _itemAttributeNames.Count;
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
|
||||
GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
|
||||
|
||||
#region Item Type current
|
||||
GUILayout.BeginVertical("box",GUILayout.ExpandWidth(true));
|
||||
GUILayout.Box("Item Types (" + (_itemTypeNames.Count) + ")", GUILayout.ExpandWidth(true));
|
||||
scrollTypes = GUILayout.BeginScrollView(scrollTypes, GUILayout.MinHeight(Mathf.Clamp(size * EditorGUIUtility.singleLineHeight, 10, 500)));
|
||||
for (int i = 0; i < _itemTypeNames.Count; i++)
|
||||
{
|
||||
GUILayout.Label(_itemTypeNames[i], EditorStyles.miniBoldLabel, GUILayout.ExpandWidth(true));
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndVertical();
|
||||
#endregion
|
||||
#region Item Attribute current
|
||||
GUILayout.BeginVertical("box", GUILayout.ExpandWidth(true));
|
||||
GUILayout.Box("Item Attributes ("+(_itemAttributeNames.Count)+")", GUILayout.ExpandWidth(true));
|
||||
scrollAttributes = GUILayout.BeginScrollView(scrollAttributes, GUILayout.MinHeight(Mathf.Clamp(size * EditorGUIUtility.singleLineHeight, 10, 500)));
|
||||
|
||||
for (int i = 0; i < _itemAttributeNames.Count; i++)
|
||||
{
|
||||
GUILayout.Label(_itemAttributeNames[i], EditorStyles.miniBoldLabel,GUILayout.ExpandWidth(true));
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndVertical();
|
||||
#endregion
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
}
|
||||
|
||||
void DrawItemEnumListData(vItemEnumsList data)
|
||||
{
|
||||
SerializedObject _data = new SerializedObject(data);
|
||||
_data.Update();
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Box(data.name, GUILayout.ExpandWidth(true));
|
||||
EditorGUILayout.ObjectField(data, typeof(vItemEnumsList), false);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
#region Item Types
|
||||
var itemTypeEnumValueList = _data.FindProperty("itemTypeEnumValues");
|
||||
GUILayout.BeginVertical("box", GUILayout.Width(200));
|
||||
GUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true));
|
||||
GUILayout.Label("Item Types", EditorStyles.miniBoldLabel);
|
||||
EditorGUILayout.PropertyField(itemTypeEnumValueList.FindPropertyRelative("Array.size"), GUIContent.none);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var labelWidht = EditorGUIUtility.labelWidth;
|
||||
|
||||
EditorGUIUtility.labelWidth = 30f;
|
||||
var color = GUI.color;
|
||||
for (int i = 0; i < itemTypeEnumValueList.arraySize; i++)
|
||||
{
|
||||
if (_itemTypeNames.Contains(itemTypeEnumValueList.GetArrayElementAtIndex(i).stringValue))
|
||||
GUI.color = Color.gray;
|
||||
else GUI.color = color;
|
||||
EditorGUILayout.PropertyField(itemTypeEnumValueList.GetArrayElementAtIndex(i), new GUIContent(i.ToString()));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
#endregion
|
||||
#region Item Attributes
|
||||
GUI.color = color;
|
||||
var itemAttributesEnumValuesList = _data.FindProperty("itemAttributesEnumValues");
|
||||
GUILayout.BeginVertical("box", GUILayout.Width(200));
|
||||
GUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true));
|
||||
GUILayout.Label("Item Attributes", EditorStyles.miniBoldLabel);
|
||||
EditorGUILayout.PropertyField(itemAttributesEnumValuesList.FindPropertyRelative("Array.size"), GUIContent.none);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
for (int i = 0; i < itemAttributesEnumValuesList.arraySize; i++)
|
||||
{
|
||||
|
||||
if (_itemAttributeNames.Contains(itemAttributesEnumValuesList.GetArrayElementAtIndex(i).stringValue))
|
||||
GUI.color = Color.gray;
|
||||
else GUI.color = color;
|
||||
EditorGUILayout.PropertyField(itemAttributesEnumValuesList.GetArrayElementAtIndex(i), new GUIContent(i.ToString()));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
#endregion
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
_data.ApplyModifiedProperties();
|
||||
if (_data.ApplyModifiedProperties())
|
||||
EditorUtility.SetDirty(data);
|
||||
EditorGUIUtility.labelWidth = labelWidht;
|
||||
GUI.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85863c3560870534f844abd8fc976b34
|
||||
timeCreated: 1488575551
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
[CustomEditor(typeof(vItemListData))]
|
||||
public class vItemListEditor : UnityEditor.Editor
|
||||
{
|
||||
[SerializeField]
|
||||
protected GUISkin skin;
|
||||
[SerializeField]
|
||||
protected vItemListData itemList;
|
||||
protected Texture2D m_Logo = null;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
itemList = (vItemListData)target;
|
||||
skin = Resources.Load("vSkin") as GUISkin;
|
||||
m_Logo = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D));
|
||||
}
|
||||
|
||||
[MenuItem("Invector/Inventory/Create New ItemListData")]
|
||||
|
||||
static void CreateNewListData()
|
||||
{
|
||||
vItemListData listData = ScriptableObject.CreateInstance<vItemListData>();
|
||||
AssetDatabase.CreateAsset(listData, "Assets/ItemListData.asset");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (skin) GUI.skin = skin;
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
GUI.enabled = !Application.isPlaying;
|
||||
|
||||
GUILayout.BeginVertical("Item List", "window");
|
||||
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
|
||||
|
||||
OpenCloseItemWindow();
|
||||
|
||||
GUILayout.Space(20);
|
||||
if (GUILayout.Button(itemList.itemsHidden ? "Show items in Hierarchy" : "Hide items in Hierarchy"))
|
||||
{
|
||||
ShowAllItems();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
if (GUI.changed || serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OpenCloseItemWindow()
|
||||
{
|
||||
if (itemList.itemsHidden && !itemList.inEdition && GUILayout.Button("Edit Items in List"))
|
||||
{
|
||||
vItemListWindow.CreateWindow(itemList);
|
||||
}
|
||||
else if (itemList.inEdition)
|
||||
{
|
||||
if (vItemListWindow.Instance != null)
|
||||
{
|
||||
if (vItemListWindow.Instance.itemList == null)
|
||||
{
|
||||
vItemListWindow.Instance.Close();
|
||||
}
|
||||
else
|
||||
EditorGUILayout.HelpBox("The Item List Window is open", MessageType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemList.inEdition = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ShowAllItems()
|
||||
{
|
||||
if (itemList.itemsHidden)
|
||||
{
|
||||
foreach (vItem item in itemList.items)
|
||||
{
|
||||
item.hideFlags = HideFlags.None;
|
||||
EditorUtility.SetDirty(item);
|
||||
}
|
||||
itemList.itemsHidden = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (vItem item in itemList.items)
|
||||
{
|
||||
item.hideFlags = HideFlags.HideInHierarchy;
|
||||
EditorUtility.SetDirty(item);
|
||||
}
|
||||
itemList.itemsHidden = true;
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(target);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e39f3edbefc2eb4a8494c1e82ee083b
|
||||
timeCreated: 1468593419
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,570 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
public class vItemListWindow : EditorWindow
|
||||
{
|
||||
public static vItemListWindow Instance;
|
||||
public vItemListData itemList;
|
||||
[SerializeField]
|
||||
public GUISkin skin;
|
||||
public SerializedObject serializedObject;
|
||||
public vItem addItem;
|
||||
public vItemDrawer addItemDrawer;
|
||||
public vItemDrawer currentItemDrawer;
|
||||
public bool inAddItem;
|
||||
public bool inDragItens;
|
||||
public bool openAttributeList;
|
||||
public bool inCreateAttribute;
|
||||
public string attributeName;
|
||||
public int indexSelected;
|
||||
public Vector2 scroolView;
|
||||
public Vector2 attributesScroll;
|
||||
public Texture2D m_Logo = null;
|
||||
public System.Action<int> OnSelectItem;
|
||||
public Vector2 addItemScroolView;
|
||||
public List<vItemType> filter = new List<vItemType>();
|
||||
public string search = "";
|
||||
bool isOpenFilter;
|
||||
public List<vItem> newItems = new List<vItem>();
|
||||
public Vector2 newItemsScrool;
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
m_Logo = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D));
|
||||
}
|
||||
|
||||
public static void CreateWindow(vItemListData itemList)
|
||||
{
|
||||
vItemListWindow window = (vItemListWindow)EditorWindow.GetWindow(typeof(vItemListWindow), false, "ItemList Editor");
|
||||
Instance = window;
|
||||
window.itemList = itemList;
|
||||
LoadSkin(window);
|
||||
Instance.Init();
|
||||
}
|
||||
|
||||
protected static void LoadSkin(vItemListWindow window)
|
||||
{
|
||||
window.skin = Resources.Load("vSkin") as GUISkin;
|
||||
}
|
||||
|
||||
public static void CreateWindow(vItemListData itemList, int firtItemSelected)
|
||||
{
|
||||
vItemListWindow window = (vItemListWindow)EditorWindow.GetWindow(typeof(vItemListWindow), false, "ItemList Editor");
|
||||
Instance = window;
|
||||
window.itemList = itemList;
|
||||
LoadSkin(window);
|
||||
Instance.Init(firtItemSelected);
|
||||
}
|
||||
|
||||
public static void CreateWindow(vItemListData itemList, System.Action<int> OnSelectItem)
|
||||
{
|
||||
vItemListWindow window = (vItemListWindow)EditorWindow.CreateInstance<vItemListWindow>();
|
||||
// Instance = window;
|
||||
window.itemList = itemList;
|
||||
LoadSkin(window);
|
||||
window.OnSelectItem = OnSelectItem;
|
||||
window.titleContent = new GUIContent("ItemList Selector");
|
||||
window.Show();
|
||||
window.Init();
|
||||
}
|
||||
|
||||
public virtual void Init()
|
||||
{
|
||||
serializedObject = new SerializedObject(itemList);
|
||||
var subAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(itemList));
|
||||
skin = Resources.Load("vSkin") as GUISkin;
|
||||
if (subAssets.Length > 1)
|
||||
{
|
||||
for (int i = subAssets.Length - 1; i >= 0; i--)
|
||||
{
|
||||
var item = subAssets[i] as vItem;
|
||||
|
||||
if (item && !itemList.items.Contains(item))
|
||||
{
|
||||
item.id = GetUniqueID();
|
||||
itemList.items.Add(item);
|
||||
}
|
||||
}
|
||||
EditorUtility.SetDirty(itemList);
|
||||
OrderByID(ref itemList.items);
|
||||
}
|
||||
itemList.inEdition = true;
|
||||
this.Show();
|
||||
}
|
||||
|
||||
public virtual void Init(int firtItemSelected)
|
||||
{
|
||||
Init();
|
||||
SetCurrentSelectedItem(firtItemSelected);
|
||||
}
|
||||
|
||||
public virtual void OnGUI()
|
||||
{
|
||||
if (skin) GUI.skin = skin;
|
||||
var _color = GUI.color;
|
||||
if (OnSelectItem != null)
|
||||
GUI.color = Color.red;
|
||||
GUILayout.BeginVertical("Item List", "window");
|
||||
GUI.color = _color;
|
||||
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
|
||||
|
||||
GUILayout.BeginVertical("box");
|
||||
|
||||
GUI.enabled = !Application.isPlaying;
|
||||
itemList = EditorGUILayout.ObjectField("ItemListData", itemList, typeof(vItemListData), false) as vItemListData;
|
||||
this.minSize = new Vector2(250, minSize.y);
|
||||
if (serializedObject == null && itemList != null)
|
||||
{
|
||||
serializedObject = new SerializedObject(itemList);
|
||||
}
|
||||
else if (itemList == null)
|
||||
{
|
||||
GUILayout.EndVertical();
|
||||
return;
|
||||
}
|
||||
|
||||
serializedObject.Update();
|
||||
if (OnSelectItem == null)
|
||||
{
|
||||
if (!inDragItens && GUILayout.Button("Add Items"))
|
||||
{
|
||||
inDragItens = true;
|
||||
}
|
||||
if (!inAddItem && GUILayout.Button("Create New Item"))
|
||||
{
|
||||
addItem = ScriptableObject.CreateInstance<vItem>();
|
||||
addItem.name = "New Item";
|
||||
|
||||
currentItemDrawer = null;
|
||||
inAddItem = true;
|
||||
}
|
||||
if (inDragItens)
|
||||
{
|
||||
GUILayout.BeginVertical("window");
|
||||
EditorGUILayout.HelpBox("You can add items from other lists by selecting other lists in the ProjectWindow, click on 'Show items in Hierarchy' and drag & drop the item to the field bellow", MessageType.Info);
|
||||
EditorGUILayout.HelpBox("New items will have their IDs modified if Same ID exits in Items List", MessageType.Warning);
|
||||
DrawDragBox(ref newItems);
|
||||
GUILayout.BeginVertical();
|
||||
newItemsScrool = GUILayout.BeginScrollView(newItemsScrool, false, false, GUILayout.MaxHeight(Mathf.Clamp(newItems.Count * 25, 0, 500)));
|
||||
OrderByID(ref newItems);
|
||||
for (int i = 0; i < newItems.Count; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
if (itemList.items.Find(it => it.name.ToClearUpper().Equals(newItems[i].name.ToClearUpper())))
|
||||
{
|
||||
GUI.color = Color.red;
|
||||
GUILayout.Label("EXIST"); EditorGUILayout.ObjectField(newItems[i], typeof(vItem), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.color = Color.white;
|
||||
EditorGUILayout.ObjectField(newItems[i], typeof(vItem), false);
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
if (GUILayout.Button("x", EditorStyles.miniButton, GUILayout.Width(20)))
|
||||
{
|
||||
newItems.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginHorizontal();
|
||||
GUI.enabled = newItems.Count > 0;
|
||||
if (GUILayout.Button("ADD", GUILayout.MinWidth(50), GUILayout.MaxWidth(100)))
|
||||
{
|
||||
AddItem(newItems);
|
||||
newItems.Clear();
|
||||
inDragItens = false;
|
||||
}
|
||||
GUI.enabled = true;
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("CLEAR", GUILayout.MinWidth(50), GUILayout.MaxWidth(100)))
|
||||
{
|
||||
newItems.Clear();
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("CANCEL", GUILayout.MinWidth(50), GUILayout.MaxWidth(100)))
|
||||
{
|
||||
inDragItens = false;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
if (inAddItem)
|
||||
{
|
||||
DrawAddItem();
|
||||
}
|
||||
if (GUILayout.Button("Open ItemEnums Editor"))
|
||||
{
|
||||
vItemEnumsWindow.CreateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.Box(itemList.items.Count.ToString("00") + " Items");
|
||||
DrawFilter();
|
||||
scroolView = GUILayout.BeginScrollView(scroolView, GUILayout.ExpandWidth(true));
|
||||
int count = 0;
|
||||
for (int i = 0; i < itemList.items.Count; i++)
|
||||
{
|
||||
if (itemList.items[i] != null && FilterItems(itemList.items[i]))
|
||||
{
|
||||
Color color = GUI.color;
|
||||
GUI.color = currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? Color.green : color;
|
||||
GUILayout.BeginVertical("box");
|
||||
{
|
||||
GUI.color = color;
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
var texture = itemList.items[i].iconTexture;
|
||||
var name = " ID " + itemList.items[i].id.ToString("00") + "\n - " + itemList.items[i].name + "\n - " + itemList.items[i].type.ToString();
|
||||
var content = new GUIContent(name, texture, currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] ? "Click to Close" : "Click to Open");
|
||||
GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
|
||||
GUI.skin.box.alignment = TextAnchor.UpperLeft;
|
||||
GUI.skin.box.fontStyle = FontStyle.Italic;
|
||||
GUI.skin.box.fontSize = 11;
|
||||
|
||||
if (GUILayout.Button(content, "label", GUILayout.Height(60), GUILayout.MinWidth(60)))
|
||||
{
|
||||
if (OnSelectItem != null)
|
||||
{
|
||||
OnSelectItem.Invoke(i);
|
||||
OnSelectItem = null;
|
||||
this.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.FocusControl("clearFocus");
|
||||
scroolView.y = 1 + count * 60;
|
||||
GetItemDrawer(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (OnSelectItem == null)
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
|
||||
|
||||
GUI.skin.box = boxStyle;
|
||||
var duplicateImage = Resources.Load("duplicate") as Texture;
|
||||
if (GUILayout.Button(new GUIContent("", duplicateImage, "Duplicate Item"), GUILayout.MaxWidth(45), GUILayout.Height(45)))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Duplicate the " + itemList.items[i].name,
|
||||
"Are you sure you want to duplicate this item? ", "Duplicate", "Cancel"))
|
||||
{
|
||||
DuplicateItem(itemList.items[i]);
|
||||
GUILayout.EndHorizontal();
|
||||
Repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("x", "Delete Item"), GUILayout.MaxWidth(20), GUILayout.Height(45)))
|
||||
{
|
||||
|
||||
if (EditorUtility.DisplayDialog("Delete the " + itemList.items[i].name,
|
||||
"Are you sure you want to delete this item? ", "Delete", "Cancel"))
|
||||
{
|
||||
|
||||
var item = itemList.items[i];
|
||||
itemList.items.RemoveAt(i);
|
||||
DestroyImmediate(item, true);
|
||||
OrderByID(ref itemList.items);
|
||||
AssetDatabase.SaveAssets();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(itemList);
|
||||
GUILayout.EndHorizontal();
|
||||
Repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUI.color = color;
|
||||
if (currentItemDrawer != null && currentItemDrawer.item == itemList.items[i] && itemList.items.Contains(currentItemDrawer.item))
|
||||
{
|
||||
currentItemDrawer.DrawItem(ref itemList.items, false);
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
if (GUI.changed || serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
EditorUtility.SetDirty(itemList);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawDragBox<T>(ref List<T> list) where T : Object
|
||||
{
|
||||
//var dragAreaGroup = GUILayoutUtility.GetRect(0f, 35f, GUILayout.ExpandWidth(true));
|
||||
GUI.skin.box.alignment = TextAnchor.MiddleCenter;
|
||||
GUI.skin.box.normal.textColor = Color.white;
|
||||
//GUILayout.BeginVertical("window");
|
||||
GUILayout.Box("Drag yours Items here!", "box", GUILayout.MinHeight(50), GUILayout.ExpandWidth(true));
|
||||
var dragAreaGroup = GUILayoutUtility.GetLastRect();
|
||||
//GUILayout.EndVertical();
|
||||
switch (Event.current.type)
|
||||
{
|
||||
case EventType.DragUpdated:
|
||||
case EventType.DragPerform:
|
||||
if (list == null) list = new List<T>();
|
||||
if (!dragAreaGroup.Contains(Event.current.mousePosition))
|
||||
break;
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||
|
||||
if (Event.current.type == EventType.DragPerform)
|
||||
{
|
||||
DragAndDrop.AcceptDrag();
|
||||
|
||||
foreach (var dragged in DragAndDrop.objectReferences)
|
||||
{
|
||||
try
|
||||
{
|
||||
var newObject = (T)dragged;
|
||||
if (newObject == null || list.Contains(newObject) || list.Exists(l => l.name.ToClearUpper().Equals(newObject.name.ToClearUpper())))
|
||||
continue;
|
||||
list.Add(newObject);
|
||||
}
|
||||
catch { };
|
||||
}
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
Event.current.Use();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawFilter()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.BeginHorizontal();
|
||||
isOpenFilter = EditorGUILayout.Foldout(isOpenFilter, "Filters (" + filter.Count + ")");
|
||||
if (GUILayout.Button("+", GUILayout.Width(20), GUILayout.Height(15)))
|
||||
{
|
||||
isOpenFilter = true;
|
||||
filter.Add((vItemType)0);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
if (isOpenFilter)
|
||||
{
|
||||
for (int i = 0; i < filter.Count; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
filter[i] = (vItemType)EditorGUILayout.EnumPopup(filter[i]);
|
||||
if (GUILayout.Button("-", GUILayout.Width(20), GUILayout.Height(15)))
|
||||
{
|
||||
filter.RemoveAt(i);
|
||||
GUILayout.EndHorizontal();
|
||||
break;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginHorizontal();
|
||||
search = GUILayout.TextField(search, GUILayout.Width(this.position.width - 50));
|
||||
GUILayout.Label(EditorGUIUtility.IconContent("Search Icon"), GUILayout.Height(20));
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public virtual bool FilterItems(vItem item)
|
||||
{
|
||||
return ((filter.Count == 0 || filter.Contains(item.type)) && (string.IsNullOrEmpty(search) || item.name.ToLower().Contains(search.ToLower())));
|
||||
}
|
||||
|
||||
protected virtual void GetItemDrawer(int itemListIndex)
|
||||
{
|
||||
currentItemDrawer = currentItemDrawer != null ? currentItemDrawer.item == itemList.items[itemListIndex] ? null : new vItemDrawer(itemList.items[itemListIndex]) : new vItemDrawer(itemList.items[itemListIndex]);
|
||||
}
|
||||
|
||||
public static void SetCurrentSelectedItem(int index)
|
||||
{
|
||||
if (Instance != null && Instance.itemList != null && Instance.itemList.items != null && Instance.itemList.items.Count > 0 && index < Instance.itemList.items.Count)
|
||||
{
|
||||
Instance.currentItemDrawer = Instance.currentItemDrawer != null ? Instance.currentItemDrawer.item == Instance.itemList.items[index] ? null : new vItemDrawer(Instance.itemList.items[index]) : new vItemDrawer(Instance.itemList.items[index]);
|
||||
Instance.scroolView.y = 1 + index * 60;
|
||||
Instance.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
if (itemList)
|
||||
{
|
||||
itemList.inEdition = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void DrawAddItem()
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
|
||||
if (addItem != null)
|
||||
{
|
||||
addItemScroolView = EditorGUILayout.BeginScrollView(addItemScroolView, false, false);
|
||||
if (addItemDrawer == null || addItemDrawer.item == null || addItemDrawer.item != addItem)
|
||||
addItemDrawer = new vItemDrawer(addItem);
|
||||
bool isValid = true;
|
||||
if (addItemDrawer != null)
|
||||
{
|
||||
GUILayout.Box("Create Item Window");
|
||||
addItemDrawer.DrawItem(ref itemList.items, false, true);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(addItem.name))
|
||||
{
|
||||
isValid = false;
|
||||
EditorGUILayout.HelpBox("This item name cant be null or empty,please type a name", MessageType.Error);
|
||||
}
|
||||
|
||||
if (itemList.items.FindAll(item => item.name.Equals(addItemDrawer.item.name)).Count > 0)
|
||||
{
|
||||
isValid = false;
|
||||
EditorGUILayout.HelpBox("This item name already exists", MessageType.Error);
|
||||
}
|
||||
EditorGUILayout.EndScrollView();
|
||||
GUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(false));
|
||||
|
||||
if (isValid && GUILayout.Button("Create"))
|
||||
{
|
||||
AddItemCreated();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Cancel"))
|
||||
{
|
||||
addItem = null;
|
||||
inAddItem = false;
|
||||
addItemDrawer = null;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(itemList);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("Error", MessageType.Error);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
private void AddItem(List<vItem> items)
|
||||
{
|
||||
OrderByID(ref items);
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
items[i] = Instantiate(items[i]);
|
||||
items[i].name = items[i].name.Replace("(Clone)", string.Empty);
|
||||
}
|
||||
List<vItem> itemsWithSameID = new List<vItem>();
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
for (int z = 0; z < i; z++)
|
||||
{
|
||||
var itemA = items[i];
|
||||
var itemB = items[z];
|
||||
if (itemA != itemB && itemA.id.Equals(itemB.id) && !itemsWithSameID.Contains(itemA))
|
||||
{
|
||||
itemsWithSameID.Add(itemA);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < itemsWithSameID.Count; i++)
|
||||
{
|
||||
itemsWithSameID[i].id = GetUniqueID(items, itemsWithSameID[i].id);
|
||||
}
|
||||
OrderByID(ref items);
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
AddItem(items[i]);
|
||||
}
|
||||
}
|
||||
private void AddItem(vItem item)
|
||||
{
|
||||
if (item.name.Contains("(Clone)"))
|
||||
{
|
||||
item.name = item.name.Replace("(Clone)", string.Empty);
|
||||
}
|
||||
|
||||
if (item && !itemList.items.Find(it => it.name.ToClearUpper().Equals(item.name.ToClearUpper())))
|
||||
{
|
||||
|
||||
AssetDatabase.AddObjectToAsset(item, AssetDatabase.GetAssetPath(itemList));
|
||||
item.hideFlags = HideFlags.HideInHierarchy;
|
||||
|
||||
if (itemList.items.Exists(it => it.id.Equals(item.id)))
|
||||
item.id = GetUniqueID();
|
||||
itemList.items.Add(item);
|
||||
OrderByID(ref itemList.items);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(itemList);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void AddItemCreated()
|
||||
{
|
||||
AddItem(addItem);
|
||||
addItem = null;
|
||||
inAddItem = false;
|
||||
addItemDrawer = null;
|
||||
}
|
||||
|
||||
protected virtual void DuplicateItem(vItem targetItem)
|
||||
{
|
||||
addItem = Instantiate(targetItem);
|
||||
AssetDatabase.AddObjectToAsset(addItem, AssetDatabase.GetAssetPath(itemList));
|
||||
addItem.hideFlags = HideFlags.HideInHierarchy;
|
||||
addItem.id = GetUniqueID();
|
||||
itemList.items.Add(addItem);
|
||||
OrderByID(ref itemList.items);
|
||||
addItem = null;
|
||||
inAddItem = false;
|
||||
addItemDrawer = null;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(itemList);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
protected virtual int GetUniqueID(List<vItem> items, int value = 0)
|
||||
{
|
||||
var result = value;
|
||||
|
||||
for (int i = 0; i < items.Count + 1; i++)
|
||||
{
|
||||
var item = items.Find(t => t.id == i);
|
||||
if (item == null)
|
||||
{
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
protected virtual int GetUniqueID(int value = 0)
|
||||
{
|
||||
|
||||
return GetUniqueID(itemList.items);
|
||||
}
|
||||
|
||||
protected virtual void OrderByID(ref List<vItem> items)
|
||||
{
|
||||
if (items != null && items.Count > 0)
|
||||
{
|
||||
items = items.OrderBy(i => i.id).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b08ad65e7a229f4fb8762a7e4ac4ee4
|
||||
timeCreated: 1486563976
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,600 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
[CustomEditor(typeof(vItemManager), true)]
|
||||
[System.Serializable]
|
||||
public class vItemManagerEditor : vEditorBase
|
||||
{
|
||||
#region Variables
|
||||
|
||||
protected vItemManager manager;
|
||||
protected SerializedProperty itemReferenceList;
|
||||
protected GUISkin oldSkin;
|
||||
protected Vector2 scroll;
|
||||
protected bool showManagerEvents;
|
||||
protected bool[] inEdition;
|
||||
protected string[] newPointNames;
|
||||
protected Transform parentBone;
|
||||
protected Animator animator;
|
||||
protected Rect buttonRect;
|
||||
protected SerializedProperty[] events;
|
||||
#endregion
|
||||
|
||||
protected virtual string[] ignoreProperties => new string[] { "equipPoints", "applyAttributeEvents", "items", "startItems", "onStartItemUsage", "onUseItem", "onUseItemFail", "onAddItem", "onAddItemID", "onRemoveItemID", "onChangeItemAmount", "onDestroyItem", "onDropItem", "onOpenCloseInventory", "onEquipItem", "onUnequipItem", "onFinishEquipItem", "onFinishUnequipItem", "onSetLockedToEquip", "onSaveItems", "onLoadItems", "onCollectItem" };
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_Logo = (Texture2D)Resources.Load("itemManagerIcon", typeof(Texture2D));
|
||||
manager = (vItemManager)target;
|
||||
itemReferenceList = serializedObject.FindProperty("startItems");
|
||||
skin = Resources.Load("vSkin") as GUISkin;
|
||||
|
||||
vItemManagerUtilities.CreateDefaultEquipPoints(manager);
|
||||
animator = manager.GetComponent<Animator>();
|
||||
if (manager.equipPoints != null)
|
||||
{
|
||||
inEdition = new bool[manager.equipPoints.Count];
|
||||
newPointNames = new string[manager.equipPoints.Count];
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
manager.equipPoints = new List<EquipPoint>();
|
||||
}
|
||||
|
||||
events = new SerializedProperty[]
|
||||
{
|
||||
serializedObject.FindProperty("onStartItemUsage"),
|
||||
serializedObject.FindProperty("onUseItem"),
|
||||
serializedObject.FindProperty("onUseItemFail"),
|
||||
serializedObject.FindProperty("onAddItem"),
|
||||
serializedObject.FindProperty("onAddItemID"),
|
||||
serializedObject.FindProperty("onRemoveItemID"),
|
||||
serializedObject.FindProperty("onChangeItemAmount"),
|
||||
serializedObject.FindProperty("onDestroyItem"),
|
||||
serializedObject.FindProperty("onDropItem"),
|
||||
serializedObject.FindProperty("onOpenCloseInventory"),
|
||||
serializedObject.FindProperty("onEquipItem"),
|
||||
serializedObject.FindProperty("onUnequipItem"),
|
||||
serializedObject.FindProperty("onFinishEquipItem"),
|
||||
serializedObject.FindProperty("onFinishUnequipItem"),
|
||||
serializedObject.FindProperty("onSetLockedToEquip"),
|
||||
serializedObject.FindProperty("onSaveItems"),
|
||||
serializedObject.FindProperty("onLoadItems"),
|
||||
serializedObject.FindProperty("onCollectItem"),
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
oldSkin = GUI.skin;
|
||||
serializedObject.Update();
|
||||
if (skin)
|
||||
{
|
||||
GUI.skin = skin;
|
||||
}
|
||||
|
||||
GUILayout.BeginVertical("ITEM MANAGER", "window");
|
||||
GUILayout.Label(m_Logo, GUILayout.MaxHeight(25));
|
||||
|
||||
openCloseWindow = GUILayout.Toggle(openCloseWindow, openCloseWindow ? "Close" : "Open", EditorStyles.toolbarButton);
|
||||
if (openCloseWindow)
|
||||
{
|
||||
GUI.skin = oldSkin;
|
||||
DrawPropertiesExcluding(serializedObject, ignoreProperties.Append(ignore_vMono));
|
||||
GUI.skin = skin;
|
||||
GUI.enabled = Application.isPlaying && ((vItemManager)target).GetItems().Count > 0;
|
||||
GUILayout.BeginHorizontal("box");
|
||||
if (GUILayout.Button("Drop All Items"))
|
||||
{
|
||||
((vItemManager)target).DropAllItens();
|
||||
}
|
||||
if (GUILayout.Button("Destroy All Items"))
|
||||
{
|
||||
((vItemManager)target).DestroyAllItems();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUI.enabled = true;
|
||||
if (GUILayout.Button("Open Item List"))
|
||||
{
|
||||
ShowItemListWindow();
|
||||
}
|
||||
|
||||
if (manager.itemListData)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
//if (itemReferenceList.arraySize > manager.itemListData.items.Count)
|
||||
//{
|
||||
// manager.startItems.Resize(manager.itemListData.items.Count);
|
||||
//}
|
||||
GUILayout.Box("Start Items " + manager.startItems.Count);
|
||||
|
||||
if (GUILayout.Button("Add Item", EditorStyles.miniButton))
|
||||
{
|
||||
PopupWindow.Show(buttonRect, new vItemSelector
|
||||
(manager.itemListData.items, ref manager.itemsFilter,
|
||||
(vItem item) =>//OnSelectItem
|
||||
{
|
||||
itemReferenceList.arraySize++;
|
||||
itemReferenceList.GetArrayElementAtIndex(itemReferenceList.arraySize - 1).FindPropertyRelative("id").intValue = item.id;
|
||||
itemReferenceList.GetArrayElementAtIndex(itemReferenceList.arraySize - 1).FindPropertyRelative("amount").intValue = 1;
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
));
|
||||
}
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
buttonRect = GUILayoutUtility.GetLastRect();
|
||||
}
|
||||
GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
|
||||
scroll = GUILayout.BeginScrollView(scroll, GUILayout.MinHeight(200), GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false));
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < manager.startItems.Count; i++)
|
||||
{
|
||||
var item = manager.itemListData.items.Find(t => t.id.Equals(manager.startItems[i].id));
|
||||
if (item)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
var rect = GUILayoutUtility.GetRect(50, 50);
|
||||
|
||||
if (item.icon != null)
|
||||
{
|
||||
DrawTextureGUI(rect, item.icon, new Vector2(50, 50));
|
||||
}
|
||||
|
||||
var name = " ID " + item.id.ToString("00") + "\n - " + item.name + "\n - " + item.type.ToString();
|
||||
var content = new GUIContent(name, null, "Click to Open");
|
||||
GUILayout.Label(content, EditorStyles.miniLabel);
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Add to EquipArea", EditorStyles.miniLabel);
|
||||
manager.startItems[i].addToEquipArea = EditorGUILayout.Toggle("", manager.startItems[i].addToEquipArea, GUILayout.Width(30));
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
if (manager.startItems[i].addToEquipArea)
|
||||
{
|
||||
GUILayout.Label("EquipArea", EditorStyles.miniLabel);
|
||||
manager.startItems[i].indexArea = EditorGUILayout.IntField("", manager.startItems[i].indexArea, GUILayout.Width(30));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (manager.startItems[i].addToEquipArea)
|
||||
{
|
||||
GUILayout.Label("AutoEquip", EditorStyles.miniLabel);
|
||||
manager.startItems[i].autoEquip = EditorGUILayout.Toggle("", manager.startItems[i].autoEquip, GUILayout.Width(30));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Amount", EditorStyles.miniLabel);
|
||||
manager.startItems[i].amount = EditorGUILayout.IntField(manager.startItems[i].amount, GUILayout.Width(30));
|
||||
|
||||
if (manager.startItems[i].amount < 1)
|
||||
{
|
||||
manager.startItems[i].amount = 1;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
if (item.attributes.Count > 0)
|
||||
{
|
||||
manager.startItems[i].changeAttributes = GUILayout.Toggle(manager.startItems[i].changeAttributes, new GUIContent("Change Attributes", "This is a override of the original item attributes"), EditorStyles.miniButton, GUILayout.ExpandWidth(true));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (GUILayout.Button("x", GUILayout.Width(25), GUILayout.Height(25)))
|
||||
{
|
||||
itemReferenceList.DeleteArrayElementAtIndex(i);
|
||||
EditorUtility.SetDirty(target);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
break;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
Color backgroundColor = GUI.backgroundColor;
|
||||
GUI.backgroundColor = Color.clear;
|
||||
var _rec = GUILayoutUtility.GetLastRect();
|
||||
_rec.width -= 100;
|
||||
|
||||
EditorGUIUtility.AddCursorRect(_rec, MouseCursor.Link);
|
||||
|
||||
if (GUI.Button(_rec, ""))
|
||||
{
|
||||
ShowItemListWindow(item);
|
||||
}
|
||||
GUILayout.Space(7);
|
||||
GUI.backgroundColor = backgroundColor;
|
||||
if (item.attributes != null && item.attributes.Count > 0)
|
||||
{
|
||||
|
||||
if (manager.startItems[i].changeAttributes)
|
||||
{
|
||||
if (GUILayout.Button("Reset", EditorStyles.miniButton))
|
||||
{
|
||||
manager.startItems[i].attributes = null;
|
||||
|
||||
}
|
||||
if (manager.startItems[i].attributes == null)
|
||||
{
|
||||
manager.startItems[i].attributes = item.attributes.CopyAsNew();
|
||||
}
|
||||
else if (manager.startItems[i].attributes.Count != item.attributes.Count)
|
||||
{
|
||||
manager.startItems[i].attributes = item.attributes.CopyAsNew();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int a = 0; a < manager.startItems[i].attributes.Count; a++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(manager.startItems[i].attributes[a].name.ToString());
|
||||
manager.startItems[i].attributes[a].value = EditorGUILayout.IntField(manager.startItems[i].attributes[a].value, GUILayout.MaxWidth(60));
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
else
|
||||
{
|
||||
itemReferenceList.DeleteArrayElementAtIndex(i);
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
GUI.skin.box = boxStyle;
|
||||
|
||||
GUILayout.EndVertical();
|
||||
if (GUI.changed)
|
||||
{
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
var equipPoints = serializedObject.FindProperty("equipPoints");
|
||||
var applyAttributeEvents = serializedObject.FindProperty("applyAttributeEvents");
|
||||
|
||||
if (equipPoints.arraySize != inEdition.Length)
|
||||
{
|
||||
inEdition = new bool[equipPoints.arraySize];
|
||||
newPointNames = new string[manager.equipPoints.Count];
|
||||
}
|
||||
if (equipPoints != null)
|
||||
{
|
||||
DrawEquipPoints(equipPoints);
|
||||
}
|
||||
|
||||
if (applyAttributeEvents != null)
|
||||
{
|
||||
DrawAttributeEvents(applyAttributeEvents);
|
||||
}
|
||||
|
||||
GUILayout.BeginVertical("box");
|
||||
showManagerEvents = GUILayout.Toggle(showManagerEvents, showManagerEvents ? "Close Events" : "Open Events", EditorStyles.miniButton);
|
||||
GUI.skin = oldSkin;
|
||||
if (showManagerEvents)
|
||||
{
|
||||
for (int i = 0; i < events.Length; i++)
|
||||
{
|
||||
if (events[i] != null) EditorGUILayout.PropertyField(events[i]);
|
||||
}
|
||||
}
|
||||
GUI.skin = skin;
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
if (GUI.changed)
|
||||
{
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
GUI.skin = oldSkin;
|
||||
}
|
||||
|
||||
protected virtual void ShowItemListWindow(vItem item = null)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
vItemListWindow.CreateWindow(manager.itemListData);
|
||||
}
|
||||
else if (manager.itemListData.inEdition)
|
||||
{
|
||||
if (vItemListWindow.Instance == null)
|
||||
{
|
||||
vItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item));
|
||||
}
|
||||
|
||||
if (item)
|
||||
{
|
||||
vItemListWindow.SetCurrentSelectedItem(manager.itemListData.items.IndexOf(item));
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void DrawTextureGUI(Rect position, Sprite sprite, Vector2 size)
|
||||
{
|
||||
Rect spriteRect = new Rect(sprite.rect.x / sprite.texture.width, sprite.rect.y / sprite.texture.height,
|
||||
sprite.rect.width / sprite.texture.width, sprite.rect.height / sprite.texture.height);
|
||||
Vector2 actualSize = size;
|
||||
actualSize.y *= (sprite.rect.height / sprite.rect.width);
|
||||
GUI.DrawTextureWithTexCoords(new Rect(position.x, position.y + (size.y - actualSize.y) / 2, actualSize.x, actualSize.y), sprite.texture, spriteRect);
|
||||
|
||||
}
|
||||
|
||||
protected virtual GUIContent GetItemContent(vItem item)
|
||||
{
|
||||
var texture = item.icon != null ? item.icon.texture : null;
|
||||
return new GUIContent(item.name, texture, item.description);
|
||||
}
|
||||
|
||||
protected virtual List<vItem> GetItemByFilter(List<vItem> items, List<vItemType> filter)
|
||||
{
|
||||
return items.FindAll(i => filter.Contains(i.type));
|
||||
}
|
||||
|
||||
protected virtual GUIContent[] GetItemContents(List<vItem> items)
|
||||
{
|
||||
GUIContent[] names = new GUIContent[items.Count];
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
var texture = items[i].icon != null ? items[i].icon.texture : null;
|
||||
names[i] = new GUIContent(items[i].name, texture, items[i].description);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
protected virtual void DrawEquipPoints(SerializedProperty prop)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
prop.isExpanded = GUILayout.Toggle(prop.isExpanded, prop.isExpanded ? "Close Equip Points" : "Open Equip Points", EditorStyles.miniButton);
|
||||
if (prop.isExpanded)
|
||||
{
|
||||
prop.arraySize = EditorGUILayout.IntField("Points", prop.arraySize);
|
||||
for (int i = 0; i < prop.arraySize; i++)
|
||||
{
|
||||
var handler = prop.GetArrayElementAtIndex(i).FindPropertyRelative("handler");
|
||||
var equipPointName = prop.GetArrayElementAtIndex(i).FindPropertyRelative("equipPointName");
|
||||
var defaultPoint = handler.FindPropertyRelative("defaultHandler");
|
||||
var points = handler.FindPropertyRelative("customHandlers");
|
||||
var onInstantiateEquiment = prop.GetArrayElementAtIndex(i).FindPropertyRelative("onInstantiateEquiment");
|
||||
|
||||
try
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PropertyField(equipPointName);
|
||||
if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
|
||||
{
|
||||
prop.DeleteArrayElementAtIndex(i);
|
||||
GUILayout.EndHorizontal();
|
||||
break;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
EditorGUILayout.PropertyField(defaultPoint);
|
||||
GUILayout.BeginVertical("box");
|
||||
points.isExpanded = GUILayout.Toggle(points.isExpanded, "Custom Handles", EditorStyles.miniButton);
|
||||
if (points.isExpanded)
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (!inEdition[i] && GUILayout.Button("New Handler", EditorStyles.miniButton))
|
||||
{
|
||||
inEdition[i] = true;
|
||||
if (equipPointName.stringValue.Contains("Left") || equipPointName.stringValue.Contains("left"))
|
||||
{
|
||||
if (animator)
|
||||
{
|
||||
parentBone = animator.GetBoneTransform(HumanBodyBones.LeftHand);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (animator)
|
||||
{
|
||||
parentBone = animator.GetBoneTransform(HumanBodyBones.RightHand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!inEdition[i] && GUILayout.Button("Add Handler", EditorStyles.miniButton))
|
||||
{
|
||||
//points.arraySize++;
|
||||
Undo.RecordObject(manager, "Insert Point");
|
||||
points.InsertArrayElementAtIndex(points.arraySize);
|
||||
points.GetArrayElementAtIndex(points.arraySize - 1).objectReferenceValue = null;
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (inEdition[i])
|
||||
{
|
||||
GUILayout.Box("New Custom Handler");
|
||||
|
||||
parentBone = (Transform)EditorGUILayout.ObjectField("Parent Bone", parentBone, typeof(Transform), true);
|
||||
newPointNames[i] = EditorGUILayout.TextField("Custom Handler Name", newPointNames[i]);
|
||||
bool valid = true;
|
||||
if (string.IsNullOrEmpty(newPointNames[i]))
|
||||
{
|
||||
valid = false;
|
||||
EditorGUILayout.HelpBox("Custom Handler Name is empty", MessageType.Error);
|
||||
}
|
||||
var array = ConvertToArray<Transform>(points);
|
||||
if (Array.Exists<Transform>(array, point => point.gameObject.name.Equals(newPointNames[i])))
|
||||
{
|
||||
valid = false;
|
||||
EditorGUILayout.HelpBox("Custom Handler Name already exist", MessageType.Error);
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Cancel", EditorStyles.miniButton))
|
||||
{
|
||||
inEdition[i] = false;
|
||||
}
|
||||
GUI.enabled = parentBone && valid;
|
||||
|
||||
if (GUILayout.Button("Create", EditorStyles.miniButton))
|
||||
{
|
||||
var customPoint = new GameObject(newPointNames[i]);
|
||||
|
||||
customPoint.transform.parent = parentBone;
|
||||
customPoint.transform.localPosition = Vector3.zero;
|
||||
customPoint.transform.forward = manager.transform.forward;
|
||||
points.arraySize++;
|
||||
points.GetArrayElementAtIndex(points.arraySize - 1).objectReferenceValue = customPoint.transform;
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
inEdition[i] = false;
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
for (int a = 0; a < points.arraySize; a++)
|
||||
{
|
||||
var remove = false;
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PropertyField(points.GetArrayElementAtIndex(a), true);
|
||||
if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
if (remove)
|
||||
{
|
||||
Undo.RecordObject(manager, "Delete Point");
|
||||
var obj = (Transform)points.GetArrayElementAtIndex(a).objectReferenceValue;
|
||||
if (obj)
|
||||
{
|
||||
points.GetArrayElementAtIndex(a).objectReferenceValue = null;
|
||||
//points.DeleteArrayElementAtIndex(a);
|
||||
//DestroyImmediate(obj.gameObject);
|
||||
}
|
||||
points.DeleteArrayElementAtIndex(a);
|
||||
EditorUtility.SetDirty(manager);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _array = ConvertToArray<Transform>(points);
|
||||
bool _valid = true;
|
||||
for (int a = 0; a < _array.Length; a++)
|
||||
{
|
||||
if (_array[a] != null)
|
||||
{
|
||||
var name = _array[a].gameObject.name;
|
||||
if (Array.FindAll<Transform>(_array, point => point != null && point.gameObject.name.Equals(name)).Length > 1)
|
||||
{
|
||||
_valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_valid == false)
|
||||
{
|
||||
EditorGUILayout.HelpBox("You can't use two handles with the same name", MessageType.Error);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUI.skin = oldSkin;
|
||||
if (onInstantiateEquiment != null)
|
||||
{
|
||||
EditorGUILayout.PropertyField(onInstantiateEquiment);
|
||||
}
|
||||
|
||||
GUI.skin = skin;
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
catch { }
|
||||
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
protected virtual T[] ConvertToArray<T>(SerializedProperty prop)
|
||||
{
|
||||
T[] value = new T[prop.arraySize];
|
||||
for (int i = 0; i < prop.arraySize; i++)
|
||||
{
|
||||
object element = prop.GetArrayElementAtIndex(i).objectReferenceValue;
|
||||
value[i] = (T)element;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected virtual void DrawAttributeEvents(SerializedProperty prop)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
prop.isExpanded = GUILayout.Toggle(prop.isExpanded, prop.isExpanded ? "Close Attribute Events" : "Open Attribute Events", EditorStyles.miniButton);
|
||||
if (prop.isExpanded)
|
||||
{
|
||||
prop.arraySize = EditorGUILayout.IntField("Attributes", prop.arraySize);
|
||||
for (int i = 0; i < prop.arraySize; i++)
|
||||
{
|
||||
|
||||
var attributeName = prop.GetArrayElementAtIndex(i).FindPropertyRelative("attribute");
|
||||
var onApplyAttribute = prop.GetArrayElementAtIndex(i).FindPropertyRelative("onApplyAttribute");
|
||||
try
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PropertyField(attributeName);
|
||||
if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)))
|
||||
{
|
||||
prop.DeleteArrayElementAtIndex(i);
|
||||
GUILayout.EndHorizontal();
|
||||
break;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUI.skin = oldSkin;
|
||||
EditorGUILayout.PropertyField(onApplyAttribute);
|
||||
GUI.skin = skin;
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
catch { }
|
||||
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14d43100a9cef7b44a4b2b7515ed0759
|
||||
timeCreated: 1471533215
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
public static class vItemManagerUtilities
|
||||
{
|
||||
public static void CreateDefaultEquipPoints(vItemManager itemManager)
|
||||
{
|
||||
|
||||
var animator = itemManager.GetComponent<Animator>();
|
||||
if (itemManager.equipPoints == null)
|
||||
itemManager.equipPoints = new List<EquipPoint>();
|
||||
|
||||
#region LeftEquipPoint
|
||||
var equipPointL = itemManager.equipPoints.Find(p => p.equipPointName == "LeftArm");
|
||||
if (equipPointL == null)
|
||||
{
|
||||
EquipPoint pointL = new EquipPoint();
|
||||
pointL.equipPointName = "LeftArm";
|
||||
itemManager.equipPoints.Add(pointL);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RightEquipPoint
|
||||
var equipPointR = itemManager.equipPoints.Find(p => p.equipPointName == "RightArm");
|
||||
if (equipPointR == null)
|
||||
{
|
||||
EquipPoint pointR = new EquipPoint();
|
||||
pointR.equipPointName = "RightArm";
|
||||
itemManager.equipPoints.Add(pointR);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64b79846d17ef34479c2be366a15a2da
|
||||
timeCreated: 1486667692
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
namespace Invector.vItemManager
|
||||
{
|
||||
public class vItemSelector : PopupWindowContent
|
||||
{
|
||||
public UnityEngine.Events.UnityAction<vItem> onSelect;
|
||||
public List<vItem> items;
|
||||
public GUIContent[] contents;
|
||||
GUIStyle boxStyle;
|
||||
public List<vItemType> filter = new List<vItemType>();
|
||||
public string search = "";
|
||||
bool isOpenFilter;
|
||||
Vector2 scroll;
|
||||
public override Vector2 GetWindowSize()
|
||||
{
|
||||
return new Vector2(200, Mathf.Clamp(items.Count * 50, 50, 500));
|
||||
}
|
||||
public vItemSelector(List<vItem> items,ref List<vItemType> filter, UnityEngine.Events.UnityAction<vItem> onSelect)
|
||||
{
|
||||
this.items = items;
|
||||
this.filter = filter;
|
||||
this.onSelect = onSelect; CreateContent();
|
||||
|
||||
}
|
||||
void CreateContent()
|
||||
{
|
||||
boxStyle = new GUIStyle(GUI.skin.box);
|
||||
boxStyle.alignment = TextAnchor.UpperLeft;
|
||||
boxStyle.fontStyle = FontStyle.Italic;
|
||||
boxStyle.fontSize = 11;
|
||||
contents = new GUIContent[items.Count];
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
var name = " ID " + items[i].id.ToString("00") + "\n - " + items[i].name + "\n - " + items[i].type.ToString();
|
||||
var texture = items[i].iconTexture;
|
||||
var tooltip = items[i].description;
|
||||
contents[i] = new GUIContent(name, texture, tooltip);
|
||||
}
|
||||
}
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
if (contents == null) return;
|
||||
GUILayout.Label("ItemSelector", EditorStyles.boldLabel);
|
||||
|
||||
DrawFilter();
|
||||
|
||||
scroll = GUILayout.BeginScrollView(scroll, "box");
|
||||
|
||||
for (int i = 0; i < contents.Length; i++)
|
||||
{
|
||||
if ((filter.Count == 0 || filter.Contains(items[i].type)) && (string.IsNullOrEmpty(search) || items[i].name.ToLower().Contains(search.ToLower())))
|
||||
if (GUILayout.Button(contents[i], boxStyle, GUILayout.Height(50), GUILayout.MinWidth(50)))
|
||||
{
|
||||
onSelect(items[i]);
|
||||
editorWindow.Close();
|
||||
}
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
void DrawFilter()
|
||||
{
|
||||
GUILayout.BeginVertical();
|
||||
GUILayout.BeginHorizontal();
|
||||
isOpenFilter = EditorGUILayout.Foldout(isOpenFilter, "Filters (" + filter.Count + ")");
|
||||
if (GUILayout.Button("+", GUILayout.Width(20), GUILayout.Height(15)))
|
||||
{
|
||||
isOpenFilter = true;
|
||||
filter.Add((vItemType)0);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
if (isOpenFilter)
|
||||
{
|
||||
for (int i = 0; i < filter.Count; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
filter[i] = (vItemType)EditorGUILayout.EnumPopup(filter[i]);
|
||||
if (GUILayout.Button("-", GUILayout.Width(20), GUILayout.Height(15)))
|
||||
{
|
||||
filter.RemoveAt(i);
|
||||
GUILayout.EndHorizontal();
|
||||
break;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginHorizontal();
|
||||
search = GUILayout.TextField(search, GUILayout.Width(170));
|
||||
GUILayout.Label(EditorGUIUtility.IconContent("Search Icon"), GUILayout.Height(20));
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 629a88c6a5c593643a3a163bae2296f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user