コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }