This commit is contained in:
2026-05-30 09:16:35 +07:00
parent 2f87ce19a7
commit 1c0ee6efb7
4001 changed files with 3363438 additions and 1738 deletions

View File

@@ -0,0 +1,216 @@
using UnityEditor;
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Collections.Generic;
namespace Invector.vItemManager
{
public static class Helper
{
public static bool NameEquals(this vItemEnumsBuilder.ItemEnumObject a, vItemEnumsBuilder.ItemEnumObject b)
{
return a.name.Equals(b.name);
}
public static bool FormatEquals(this vItemEnumsBuilder.ItemEnumObject a, vItemEnumsBuilder.ItemEnumObject b)
{
return a.format.Equals(b.format);
}
}
public class vItemEnumsBuilder
{
public class ItemEnumObject
{
public string name;
public string format;
public ItemEnumObject (string name,string format)
{
this.name = name;
this.format = format;
}
}
public static void RefreshItemEnums()
{
string name = "vItemEnums";
string copyPath = "Assets/Invector-3rdPersonController/ItemManager/Scripts/vItemEnumsBuilder/" + name + ".cs";
vItemEnumsList[] datas = Resources.LoadAll<vItemEnumsList>("");
List<string> defaultItemTypeNames = new List<string>();
List<string> defaultItemAttributesNames = new List<string>();
List<string> _itemTypeNames = new List<string>();
List<string> _itemAttributeNames = new List<string>();
List<string> _itemTypeFormats = new List<string>();
List<string> _itemAttributeFormats = new List<string>();
#region Get all vItemType values of current Enum
try
{
_itemTypeNames = Enum.GetNames(typeof(vItemType)).vToList();
}
catch
{
}
#endregion
#region Get all vItemAttributes values of current Enum
try
{
_itemAttributeNames = Enum.GetNames(typeof(vItemAttributes)).vToList();
}
catch
{
}
#endregion
if (datas != null)
{
#region Get all enum of ItemEnumList
for (int i = 0; i < datas.Length; i++)
{
if (datas[i].itemTypeEnumValues != null)
{
for (int a = 0; a < datas[i].itemTypeEnumValues.Count; a++)
{
if (!string.IsNullOrEmpty(datas[i].itemTypeEnumValues[a]) && !defaultItemTypeNames.Contains(datas[i].itemTypeEnumValues[a]))
{
defaultItemTypeNames.Add(datas[i].itemTypeEnumValues[a]);
}
}
}
if (datas[i].itemAttributesEnumValues != null)
{
for (int a = 0; a < datas[i].itemAttributesEnumValues.Count; a++)
{
if (!string.IsNullOrEmpty(datas[i].itemAttributesEnumValues[a]) && !defaultItemAttributesNames.Contains(datas[i].itemAttributesEnumValues[a]))
{
defaultItemAttributesNames.Add(datas[i].itemAttributesEnumValues[a]);
}
}
}
}
foreach (string value in defaultItemTypeNames)
{
if (!_itemTypeNames.Contains(value))
{
bool replace = false;
for (int i = 0; i < _itemTypeNames.Count; i++)
{
if (!defaultItemTypeNames.Contains(_itemTypeNames[i]))
{
replace = true;
_itemTypeNames[i] = value;
break;
}
}
if (!replace)
_itemTypeNames.Add(value);
}
}
#endregion
#region Remove enum that not exist
var typesToRemove = _itemTypeNames.FindAll(x => !defaultItemTypeNames.Contains(x));
foreach (string value in typesToRemove)
_itemTypeNames.Remove(value);
foreach (string value in defaultItemAttributesNames)
{
if (!_itemAttributeNames.Contains(value))
{
bool replace = false;
for (int i = 0; i < _itemAttributeNames.Count; i++)
{
if (!defaultItemAttributesNames.Contains(_itemAttributeNames[i]))
{
replace = true;
_itemAttributeNames[i] = value;
break;
}
}
if (!replace)
_itemAttributeNames.Add(value);
}
}
var attributesToRemove = _itemAttributeNames.FindAll(x => !defaultItemAttributesNames.Contains(x));
foreach (string value in attributesToRemove)
_itemAttributeNames.Remove(value);
#endregion
#region Get Enum Text Formats
for(int i =0;i< _itemTypeNames.Count;i++)
{
vItemEnumsList data = datas.vToList().Find(d => d.itemTypeEnumValues.Contains(_itemTypeNames[i]));
if(data!=null)
{
var index = data.itemTypeEnumValues.IndexOf(_itemTypeNames[i]);
if(index<data.itemTypeEnumFormats.Count)
{
_itemTypeFormats.Add(data.itemTypeEnumFormats[index]);
}
else
_itemTypeFormats.Add("");
}
else _itemTypeFormats.Add("");
}
for (int i = 0; i < _itemAttributeNames.Count; i++)
{
vItemEnumsList data = datas.vToList().Find(d => d.itemAttributesEnumValues.Contains(_itemAttributeNames[i]));
if (data != null)
{
var index = data.itemAttributesEnumValues.IndexOf(_itemAttributeNames[i]);
if (index < data.itemAttributesEnumFormats.Count)
{
_itemAttributeFormats.Add(data.itemAttributesEnumFormats[index]);
}
else
_itemAttributeFormats.Add("");
}
else _itemAttributeFormats.Add("");
}
#endregion
}
CreateEnumClass(copyPath, _itemTypeNames, _itemAttributeNames,_itemTypeFormats,_itemAttributeFormats);
}
static void CreateEnumClass(string copyPath, List<string> itemTypes = null, List<string> itemAttributes = null,
List<string> itemTypesFormat = null, List<string> itemAttributesFormat = null)
{
if (File.Exists(copyPath)) File.Delete(copyPath);
using (StreamWriter outfile = new StreamWriter(copyPath))
{
outfile.WriteLine("using System.ComponentModel;");
outfile.WriteLine("namespace Invector.vItemManager {");
outfile.WriteLine(" public enum vItemType {");
if (itemTypes != null)
{
for (int i = 0; i < itemTypes.Count; i++)
{
outfile.WriteLine(" "+string.Format("[Description(\"{0}\")] ",itemTypesFormat[i]) + itemTypes[i] + "=" + i + (i == itemTypes.Count - 1 ? "" : ","));
}
}
outfile.WriteLine(" }");
outfile.WriteLine(" public enum vItemAttributes {");
if (itemAttributes != null)
{
for (int i = 0; i < itemAttributes.Count; i++)
{
outfile.WriteLine(" " + string.Format("[Description(\"{0}\")] ", itemAttributesFormat[i]) + itemAttributes[i] + "=" + i + (i == itemAttributes.Count - 1 ? "" : ","));
}
}
outfile.WriteLine(" }");
outfile.WriteLine("}");
}
AssetDatabase.Refresh();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2100ee3b5c97dd84dbadcc20c6a285fc
timeCreated: 1487717080
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,243 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using UnityEditor;
using UnityEngine;
using System.Linq;
namespace Invector.vItemManager.DynamicEnum
{
[CustomEditor(typeof(vItemEnumsList))]
public class vItemEnumsListEditor : UnityEditor.Editor
{
public GUISkin skin;
public float fieldWidht = 0;
public GUIStyle placeholderTextStyle;
void OnEnable()
{
skin = Resources.Load("vSkin") as GUISkin;
vItemEnumsList list = (vItemEnumsList)target;
serializedObject.FindProperty("itemTypeEnumFormats").arraySize = serializedObject.FindProperty("itemTypeEnumValues").arraySize;
for (int i=0;i<list.itemTypeEnumValues.Count;i++)
{
vItemType t;
if(Enum.TryParse<vItemType>(list.itemTypeEnumValues[i],out t))
{
list.itemTypeEnumFormats[i] = t.DisplayFormat();
}
}
serializedObject.FindProperty("itemAttributesEnumFormats").arraySize = serializedObject.FindProperty("itemAttributesEnumValues").arraySize;
for (int i = 0; i < list.itemAttributesEnumValues.Count; i++)
{
vItemAttributes t;
if (Enum.TryParse<vItemAttributes>(list.itemAttributesEnumValues[i], out t))
{
list.itemAttributesEnumFormats[i] = t.DisplayFormat();
}
}
}
public override void OnInspectorGUI()
{
if (skin) GUI.skin = skin;
serializedObject.Update();
var assetPath = AssetDatabase.GetAssetPath(target);
GUILayout.BeginVertical("vItemEnums List", "window");
GUILayout.Space(30);
if (assetPath.Contains("Resources"))
{
GUILayout.BeginVertical("box");
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);
DrawEnumList();
GUILayout.EndHorizontal();
EditorGUILayout.Space();
if (GUILayout.Button("Open ItemEnums Editor"))
{
vItemEnumsWindow.CreateWindow();
}
EditorGUILayout.Space();
if (GUILayout.Button("Refresh ItemEnums"))
{
vItemEnumsBuilder.RefreshItemEnums();
}
EditorGUILayout.HelpBox("-This list will be merged with other lists and create the enums.\n- The Enum Generator will ignore equal values.\n- If our change causes errors, check which enum value is missing and adds to the list and press the refresh button.", MessageType.Info);
}
else
{
EditorGUILayout.HelpBox("Please put this list in Resources folder", MessageType.Warning);
}
GUILayout.EndVertical();
serializedObject.ApplyModifiedProperties();
}
public delegate bool NameCompare(string compare);
public delegate bool DescriptionCompare(string name,string compare);
public void DrawEnumList()
{
var typeNameCompare = new NameCompare(CompareItemTypeName);
var typeDescriptionCompare = new DescriptionCompare(CompareItemTypeDescription);
var attrNameCompare = new NameCompare(CompareItemAttbiuteName);
var attrDescriptionCompare = new DescriptionCompare(CompareItemAttributeDescription);
DrawList(serializedObject.FindProperty("itemTypeEnumValues"), serializedObject.FindProperty("itemTypeEnumFormats"),typeNameCompare,typeDescriptionCompare);
DrawList(serializedObject.FindProperty("itemAttributesEnumValues"), serializedObject.FindProperty("itemAttributesEnumFormats"),attrNameCompare,attrDescriptionCompare);
}
bool CompareItemTypeName(string compare)
{
vItemType t;
if (Enum.TryParse<vItemType>(compare, out t)) return true;
else return false;
}
bool CompareItemTypeDescription(string name, string compare)
{
vItemType t;
if (Enum.TryParse<vItemType>(name, out t))
{
return string.IsNullOrEmpty(t.DisplayFormat())&& string.IsNullOrEmpty(compare)|| t.DisplayFormat().Equals(compare);
}
else return false;
}
bool CompareItemAttbiuteName(string compare)
{
vItemAttributes t;
if (Enum.TryParse<vItemAttributes>(compare, out t)) return true;
else return false;
}
bool CompareItemAttributeDescription(string name, string compare)
{
vItemAttributes t;
if (Enum.TryParse<vItemAttributes>(name, out t))
{
return string.IsNullOrEmpty(t.DisplayFormat()) && string.IsNullOrEmpty(compare) || t.DisplayFormat().Equals(compare);
}
else return false;
}
public override bool UseDefaultMargins()
{
return false;
}
void DrawList(SerializedProperty nameList,SerializedProperty nameFormatList,NameCompare compareName,DescriptionCompare compareDescription)
{
GUILayout.BeginVertical("box");
{
GUILayout.Box(nameList.displayName, GUILayout.ExpandWidth(true));
GUILayout.BeginHorizontal();
{
GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
{
GUI.color = Color.white;
GUILayout.Box("Name", GUILayout.ExpandWidth(true));
for (int i = 0; i < nameList.arraySize; i++)
{
SerializedProperty name = nameList.GetArrayElementAtIndex(i);
GUI.color = compareName(name.stringValue)? Color.grey: Color.white;
EditorGUILayout.PropertyField(name, GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight));
InsertPlaceHolder(name.stringValue, new GUIContent("...Enum Name"));
}
}
GUILayout.EndVertical();
GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
{
if (nameList.arraySize != nameFormatList.arraySize) nameFormatList.arraySize = nameList.arraySize;
GUI.color = Color.white;
GUILayout.Box("Format", GUILayout.ExpandWidth(true));
for (int i = 0; i < nameFormatList.arraySize; i++)
{
SerializedProperty format = nameFormatList.GetArrayElementAtIndex(i);
string name = nameList.GetArrayElementAtIndex(i).stringValue;
GUI.color = compareDescription(name, format.stringValue) ? Color.grey : Color.white;
EditorGUILayout.PropertyField(format, GUIContent.none,GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight));
InsertPlaceHolder(format.stringValue, new GUIContent("... Rich Text Format"));
GUI.color=Color.white;
}
}
GUILayout.EndVertical();
GUILayout.BeginVertical(GUILayout.Width(20));
{
if (GUILayout.Button("+", "box", GUILayout.Width(20)))
{
Undo.RecordObject(serializedObject.targetObject, "ChangeArraySize");
nameList.arraySize++;
nameFormatList.arraySize++;
}
for (int i = 0; i < nameList.arraySize; i++)
{
if (GUILayout.Button("x", EditorStyles.miniButton, GUILayout.Width(20), GUILayout.Height(EditorGUIUtility.singleLineHeight)))
{
Undo.RecordObject(serializedObject.targetObject, "RemoveElement");
nameList.DeleteArrayElementAtIndex(i);
nameFormatList.DeleteArrayElementAtIndex(i);
i--;
}
}
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
bool ItemTypesContainsDescription(string enumName,string description)
{
vItemType e = enumName.ToEnum<vItemType>();
return e.DisplayFormat().Equals(description);
}
bool ItemAttributesContainsDescription(string enumName, string description)
{
vItemAttributes e = enumName.ToEnum<vItemAttributes>();
return e.DisplayFormat().Equals(description);
}
void InsertPlaceHolder(string originalText,GUIContent placeHolderText)
{
if(placeholderTextStyle==null)
{
placeholderTextStyle = new GUIStyle(EditorStyles.label);
placeholderTextStyle.fontStyle = FontStyle.Italic;
placeholderTextStyle.wordWrap = true;
}
if (string.IsNullOrEmpty(originalText))
{
GUILayout.Space(-(EditorGUIUtility.singleLineHeight+ 2.5f));
EditorGUI.BeginDisabledGroup(true);
GUILayout.Label(placeHolderText, placeholderTextStyle, GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight));
EditorGUI.EndDisabledGroup();
}
}
[MenuItem("Invector/Inventory/ItemEnums/Create New vItemEnumsList")]
internal static void CreateDefaultItemEnum()
{
vScriptableObjectUtility.CreateAsset<vItemEnumsList>();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f82d672b18876b545aa4f1d8a7f24215
timeCreated: 1487687754
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: