private string[] MakeSpeciesOptions(DatabaseAsset data)
        {
            int    i = 2;
            int    count;
            string firstInArray;

            if (data != null)
            {
                count        = data.Species.Count;
                firstInArray = Strings.AssignSpeciesOptionToAgentLabel;
            }
            else
            {
                count        = 0;
                firstInArray = "Something went wrong loading a database.";
                Debug.LogWarning("No default database present!");
            }

            string[] temp = new string[count + i];
            temp[0] = firstInArray;
            temp[1] = Simulation.Strings.None;

            if (data != null)
            {
                foreach (Species species in data.Species)
                {
                    temp[i] = species.speciesName;
                    i++;
                }
            }
            return(temp);
        }
示例#2
0
        public static void ChangeItemsIndex(Database database, int itemIndex, int setIndex)
        {
            DatabaseAsset item = database.Get(itemIndex);

            if (item == null)
            {
                //TODO Log an Error!
                return;
            }

            if (database.Assets.Any(t => t.Index == setIndex))
            {
                DatabaseAsset changeItem = database.Assets.First(t => t.Index == setIndex);

                switch (database.Settings.IndexBehaviour)
                {
                case DatabaseIndexBehaviour.SwitchEntrys:
                    changeItem.Index = item.Index;
                    break;

                case DatabaseIndexBehaviour.IncreseBelow:
                    ChangeItemsIndex(database, changeItem.Index, setIndex + 1);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            item.Index = setIndex;
        }
        private string[] MakeInteractionOptions(DatabaseAsset data)
        {
            int    i = 1;
            int    count;
            string firstInArray;

            if (data != null)
            {
                count        = data.Interactions.Count;
                firstInArray = Strings.None;
            }
            else
            {
                count        = 0;
                firstInArray = "Something went wrong loading a database.";
                Debug.LogWarning("No default database!");
            }

            string[] temp = new string[count + i];
            temp[0] = firstInArray;

            if (data != null)
            {
                foreach (InteractionData interaction in data.Interactions)
                {
                    temp[i] = interaction.interactionName;
                    i++;
                }
            }

            return(temp);
        }
示例#4
0
        private static void AddAssetToDatabase(DatabaseAsset asset, Database database)
        {
            AssetDatabase.AddObjectToAsset(asset, database);
            EditorUtility.SetDirty(database);

            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(asset));

            database.Assets.Add(asset);
        }
 private string[] MakeNeedsArray(DatabaseAsset data)
 {
     if (data != null)
     {
         return(data.GetNeedNames());
     }
     else
     {
         return(null);
     }
 }
示例#6
0
        public static void RemoveAssetFromDatabase(int assetId, Database database)
        {
            DatabaseAsset asset = database.Assets[assetId];

            UnityEngine.Object.DestroyImmediate(asset, true);

            EditorUtility.SetDirty(database);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(database));

            database.Assets.RemoveAt(assetId);
        }
示例#7
0
        public static void AddNewAssetToDatabase(Type type, Database database)
        {
            if (!typeof(DatabaseAsset).IsAssignableFrom(type))
            {
                Debug.LogWarning("You cant assigne a not-databaseasset-type to a database");
                return;
            }

            DatabaseAsset asset = ScriptableObject.CreateInstance(type) as DatabaseAsset;

            //TODO if(asset == null) -> Type not allowed exception (?)

            asset.name  = type.Name + "_Asset";
            asset.Name  = GetItteratedValidString("NewEntry", database.Assets.Select(t => t.Name).ToArray(), 2);
            asset.Index = GetFirstUniqueIndex(database);

            AddAssetToDatabase(asset, database);
        }
示例#8
0
        //Called by Unity
        // ReSharper disable once InconsistentNaming
        // ReSharper disable once UnusedMember.Local
        private void OnGUI()
        {
            Color defaultColor = GUI.contentColor;

            if (CurrentDatabase == null)
            {
                EditorGUILayout.LabelField("No database selected");
                return;
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Label("", GUILayout.Width(16));
                Rect lastRect = GUILayoutUtility.GetLastRect();
                if (GUI.Button(new Rect(lastRect.x, lastRect.y + 4, lastRect.width, lastRect.width), "", "AC LeftArrow"))
                {
                    DatabasesOverview.Initialize();
                }
                GUILayout.Label(CurrentDatabase.Name, EditorStyles.boldLabel);

                if (GUILayout.Button("", new GUIStyle(GUI.skin.FindStyle("OL Plus")), GUILayout.Width(20)))
                {
                    DatabaseSettingWindow.Initialize(ref _currentDatabase);
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
            {
                DatabaseAsset[] sortedDbAssets = CurrentDatabase.Assets.ToArray();

                switch (CurrentDatabase.Settings.SortingBehaviour)
                {
                case DatabaseSortingBehaviour.OrderByIndex:
                    sortedDbAssets = sortedDbAssets.OrderBy(t => t.Index).ToArray();
                    break;

                case DatabaseSortingBehaviour.OrderByName:
                    sortedDbAssets = sortedDbAssets.OrderBy(t => t.Name).ToArray();
                    break;
                }

                for (int i = 0; i < sortedDbAssets.Length; i++)
                {
                    DatabaseAsset asset = sortedDbAssets[i];

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (_currentlySelectedIndex == i)
                        {
                            int oldIndex = asset.Index;
                            int newIndex = EditorGUILayout.DelayedIntField(oldIndex, GUILayout.Width(40));

                            if (newIndex > 0 && newIndex != oldIndex)
                            {
                                DatabaseWriter.ChangeItemsIndex(CurrentDatabase, asset.Index, newIndex);
                            }

                            if (oldIndex != asset.Index)
                            {
                                _currentlySelectedIndex = -1;
                                _currentlySelected      = asset.Index;
                            }
                        }
                        else
                        {
                            if (GUILayout.Button(string.Format("#{0:000}", asset.Index), GUILayout.Width(40)))
                            {
                                _currentlySelected      = -1;
                                _currentlySelectedIndex = i;
                            }
                        }

                        if (!AssetNameIsValid(asset) || !AssetNameIsUnique(asset))
                        {
                            GUI.backgroundColor = ErrorColor;
                        }

                        if (GUILayout.Button(asset.Name))
                        {
                            //TODO This error-managemant causes unexpected behaviour : Refactor
                            bool nameFieldSelected = GUI.GetNameOfFocusedControl() == "nameField";
                            GUI.FocusControl(null);
                            if (nameFieldSelected)
                            {
                                return;
                            }
                            // -----

                            if (_currentlySelected == asset.Index)
                            {
                                _currentlySelected = -1;
                            }
                            else
                            {
                                _currentlySelected      = asset.Index;
                                _currentlySelectedIndex = -1;
                            }
                        }
                        GUI.backgroundColor = defaultColor;

                        if (GUILayout.Button("X", GUILayout.Width(40)) &&
                            EditorUtility.DisplayDialog("Detete " + asset.Name,
                                                        string.Format("Do you want to delete the asset: #{0:000} {1} " +
                                                                      "from the Database: {2}?", asset.Index, asset.Name,
                                                                      CurrentDatabase.Name),
                                                        "Yes", "Cancel"))
                        {
                            DatabaseWriter.RemoveAssetFromDatabase(i, CurrentDatabase);
                            if (_currentlySelected == asset.Index)
                            {
                                _currentlySelected = -1;
                            }

                            if (_currentDatabase.Settings.AutoUpdateEnum)
                            {
                                DatabaseWriter.CreateDatabaseEnum(_currentDatabase);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    if (_currentlySelected == asset.Index)
                    {
                        EditorGUILayout.BeginVertical("Box");
                        {
                            EditorGUIUtility.labelWidth = 100;

                            EditorGUILayout.LabelField("< " + asset.GetType().Name + " >");

                            bool nameInvalid   = !AssetNameIsValid(asset);
                            bool nameNotUnique = !AssetNameIsUnique(asset);
                            if (nameInvalid || nameNotUnique)
                            {
                                GUI.backgroundColor = ErrorColor;
                            }

                            string oldName = asset.Name;

                            GUI.SetNextControlName("nameField");
                            string newName = EditorGUILayout.DelayedTextField("Name", oldName);

                            asset.Name = newName;

                            if (oldName != newName && _currentDatabase.Settings.AutoUpdateEnum &&
                                AssetNameIsValid(asset) && AssetNameIsUnique(asset))
                            {
                                DatabaseWriter.CreateDatabaseEnum(_currentDatabase);
                            }

                            GUI.backgroundColor = defaultColor;

                            MessageType mType = CurrentDatabase.Settings.AutoUpdateEnum
                                ? MessageType.Warning
                                : MessageType.Info;

                            if (nameInvalid)
                            {
                                EditorGUILayout.HelpBox("This name is invalid for enum-generation", mType);
                            }

                            if (nameNotUnique)
                            {
                                EditorGUILayout.HelpBox("This name is not unique for enum-generation", mType);
                            }

                            SerializedObject sObj = new SerializedObject(asset);

                            //if (GUILayout.Button("Select in assets")) //Does work ... place elsewhere
                            //    Selection.activeObject = sObj.targetObject;

                            SerializedProperty sProp = sObj.GetIterator();
                            while (sProp.NextVisible(true))
                            {
                                //Dont display "Name" cause its displayed before
                                if (sProp.displayName == "Name")
                                {
                                    continue;
                                }

                                //Dont display "Index" cause its displayed in list
                                if (sProp.displayName == "Index")
                                {
                                    continue;
                                }

                                //Dont display "Script"-Referenc
                                if (sProp.displayName == "Script")
                                {
                                    continue;
                                }

                                //Dont display in-Array-Propertys (again)
                                if (sProp.propertyPath.Contains("Array"))
                                {
                                    continue;
                                }

                                //Display current property as default (or by attribute set) field
                                EditorGUILayout.PropertyField(sProp, true);
                            }

                            sObj.ApplyModifiedProperties();
                        }
                        EditorGUILayout.EndVertical();
                    }
                }
            }
            EditorGUILayout.EndScrollView();

            if (CurrentDatabase.Settings.HasMultipleChoices)
            {
                EditorGUILayout.LabelField(string.Empty, GUILayout.Height(18));
                Rect r = GUILayoutUtility.GetLastRect();

                int  optionPanelWidth = 20;
                Rect addButtonRect    = GUILayoutUtility.GetLastRect();
                addButtonRect.x    += addButtonRect.width - optionPanelWidth;
                addButtonRect.width = optionPanelWidth;

                if (GUI.Button(addButtonRect, string.Empty))
                {
                    GenericMenu gMenu = new GenericMenu();

                    foreach (Type t in CurrentDatabase.GetAssignableTypes())
                    {
                        if (CurrentDatabase.Settings.DefaultType == t)
                        {
                            continue;
                        }

                        Type temp = t;
                        gMenu.AddItem(new GUIContent(t.Name), false, () => AddItemOfType(temp));
                    }
                    gMenu.ShowAsContext();
                }

                if (GUI.Button(r, "Create new " + CurrentDatabase.Settings.DefaultType.Name, "DropDownButton"))
                {
                    AddItemOfType(CurrentDatabase.Settings.DefaultType);
                }
            }
            else
            {
                if (CurrentDatabase.Settings.DefaultType != null)
                {
                    if (GUILayout.Button("Create new " + CurrentDatabase.Settings.DefaultType.Name))
                    {
                        AddItemOfType(CurrentDatabase.Settings.DefaultType);
                    }
                }
                else
                {
                    if (GUILayout.Button("No default type set"))
                    {
                        EditorPrefs.SetBool("typeFoldout", true);
                        DatabaseSettingWindow.Initialize(ref _currentDatabase);
                    }
                }
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_currentDatabase);
            }

            GUI.backgroundColor = defaultColor;
        }
示例#9
0
        private string AsEnumName(DatabaseAsset asset)
        {
            int zeros = CurrentDatabase.Assets.Max(t => t.Index).ToString().Length;

            return(DatabaseWriter.GetEnumEntryString(CurrentDatabase.Settings, asset, zeros));
        }
示例#10
0
 private bool AssetNameIsValid(DatabaseAsset asset)
 {
     return(EnumGenerator.IsEnumValid(AsEnumName(asset)));
 }
示例#11
0
 private bool AssetNameIsUnique(DatabaseAsset asset)
 {
     string[] enumNames = CurrentDatabase.Assets.Select(AsEnumName).ToArray();
     return(enumNames.Count(t => t == AsEnumName(asset)) == 1);
 }
示例#12
0
 public static string GetEnumEntryString(DatabaseSettings settings, DatabaseAsset item, int maxIndexLenght = -1)
 {
     return(GetEnumEntryString(settings, item.Name, item.Index, maxIndexLenght));
 }