Beispiel #1
0
 public static void OnWillCreateAsset(string path)
 {
     if (path == null || !path.EndsWith(".asset"))
     {
         return;
     }
     if (path.EndsWith("Entity Type.asset") || path.Contains("EntityType.asset"))
     {
         AssetInfoLists.RefreshList(typeof(EntityType));
     }
     else if (path.EndsWith("Faction.asset"))
     {
         AssetInfoLists.RefreshList(typeof(Faction));
     }
     else if (path.EndsWith("Drive.asset"))
     {
         AssetInfoLists.RefreshList(typeof(Drive));
     }
     else if (path.EndsWith("Urgency Function.asset") || path.Contains("UrgencyFunction.asset"))
     {
         AssetInfoLists.RefreshList(typeof(UrgencyFunction));
     }
     else if (path.EndsWith("Action.asset"))
     {
         AssetInfoLists.RefreshList(typeof(PixelCrushers.QuestMachine.Action));
     }
     else if (path.EndsWith("Entity Specifier.asset") || path.Contains("EntitySpecifier.asset"))
     {
         AssetInfoLists.RefreshList(typeof(EntitySpecifier));
     }
     else if (path.EndsWith("Domain Specifier.asset") || path.Contains("DomainSpecifier.asset"))
     {
         AssetInfoLists.RefreshList(typeof(DomainSpecifier));
     }
 }
        private void OnUrgencyFunctionListAddDropdown(Rect buttonRect, ReorderableList list)
        {
            var menu   = new GenericMenu();
            var assets = AssetInfoLists.GetList(typeof(UrgencyFunction));

            if (assets == null)
            {
                return;
            }
            for (int i = 0; i < assets.Count; i++)
            {
                if (assets[i] == null)
                {
                    continue;
                }
                var asset = EditorUtility.InstanceIDToObject(assets[i].instanceID) as UrgencyFunction;
                if (asset == null)
                {
                    continue;
                }
                var isInList = (target as EntityType).urgencyFunctions.Contains(asset);
                if (isInList)
                {
                    continue;
                }
                menu.AddItem(new GUIContent(assets[i].pathAndName), false, OnClickAddUrgencyFunctionList, asset);
            }
            menu.ShowAsContext();
        }
        private void OnAddDropdown(Rect buttonRect, ReorderableList list)
        {
            var menu        = new GenericMenu();
            var factionList = AssetInfoLists.GetList(typeof(Faction));

            if (factionList == null)
            {
                return;
            }
            for (int i = 0; i < factionList.Count; i++)
            {
                if (factionList[i] == null)
                {
                    continue;
                }
                var faction = EditorUtility.InstanceIDToObject(factionList[i].instanceID) as Faction;
                if (faction == null)
                {
                    continue;
                }
                var isInList = (target as Faction).relationships.Find(x => x != null && x.faction == faction) != null;
                if (isInList)
                {
                    continue;
                }
                menu.AddItem(new GUIContent(factionList[i].pathAndName), false, OnClickAdd, faction);
            }
            menu.ShowAsContext();
        }
        private void OnDriveValueListAddDropdown(Rect buttonRect, ReorderableList list)
        {
            var menu   = new GenericMenu();
            var assets = AssetInfoLists.GetList(typeof(Drive));

            if (assets == null)
            {
                return;
            }
            for (int i = 0; i < assets.Count; i++)
            {
                if (assets[i] == null)
                {
                    continue;
                }
                var asset = EditorUtility.InstanceIDToObject(assets[i].instanceID) as Drive;
                if (asset == null)
                {
                    continue;
                }
                var isInList = (target as EntityType).driveValues.Find(x => x != null && x.drive == asset) != null;
                if (isInList)
                {
                    continue;
                }
                menu.AddItem(new GUIContent(assets[i].pathAndName), false, OnClickAddDriveValueList, asset);
            }
            menu.ShowAsContext();
        }
        private void OnParentListAddDropdown(Rect buttonRect, ReorderableList list)
        {
            var menu           = new GenericMenu();
            var entityTypeList = AssetInfoLists.GetList(typeof(EntityType));

            if (entityTypeList == null)
            {
                return;
            }
            for (int i = 0; i < entityTypeList.Count; i++)
            {
                if (entityTypeList[i] == null)
                {
                    continue;
                }
                var entityType = EditorUtility.InstanceIDToObject(entityTypeList[i].instanceID) as EntityType;
                if (entityType == null)
                {
                    continue;
                }
                var myEntityType = target as EntityType;
                var isInList     = myEntityType != null && myEntityType.parents != null && myEntityType.parents.Contains(entityType);
                if (isInList)
                {
                    continue;
                }
                menu.AddItem(new GUIContent(entityTypeList[i].pathAndName), false, OnClickAddParentList, entityType);
            }
            menu.ShowAsContext();
        }
Beispiel #6
0
        protected virtual void DrawAssetList(List <AssetInfo> assetInfoList, float width)
        {
            var fieldWidth = (width - ButtonWidth) / 2;

            // Heading:
            try
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent("Name", "Sort by name."), GUILayout.Width(fieldWidth)))
                {
                    AssetInfoLists.SortList(AssetType, AssetInfoLists.SortBy.Name);
                }
                if (GUILayout.Button(new GUIContent("Folder Path", "Sort by folder path."), GUILayout.Width(fieldWidth)))
                {
                    AssetInfoLists.SortList(AssetType, AssetInfoLists.SortBy.Path);
                }
                GUILayout.Label(string.Empty, GUILayout.Width(ButtonWidth));
            }
            finally
            {
                EditorGUILayout.EndHorizontal();
            }
            // Rows:
            if (assetInfoList == null)
            {
                return;
            }
            var indexToDelete = -1;

            for (int i = 0; i < assetInfoList.Count; i++)
            {
                var assetInfo = assetInfoList[i];
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(assetInfo.name, EditorStyles.textField, GUILayout.Width(fieldWidth)))
                {
                    Selection.activeObject = EditorUtility.InstanceIDToObject(assetInfo.instanceID);
                    EditorGUIUtility.PingObject(assetInfo.instanceID);
                }
                EditorGUI.BeginDisabledGroup(true);
                GUILayout.TextField(assetInfo.path, GUILayout.Width(fieldWidth));
                EditorGUI.EndDisabledGroup();
                if (GUILayout.Button(new GUIContent("Delete", "Delete " + assetInfo.name + "."), GUILayout.Width(ButtonWidth)))
                {
                    if (EditorUtility.DisplayDialog("Delete " + AssetType.Name + "?", assetInfo.name + "\n\nYou cannot undo this action.", "Delete", "Cancel"))
                    {
                        indexToDelete = i;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            if (indexToDelete != -1)
            {
                DeleteAsset(assetInfoList, indexToDelete);
            }
        }
Beispiel #7
0
        public virtual void Draw(float width)
        {
            var assetInfoList = AssetInfoLists.GetList(AssetType);

            if (assetInfoList == null)
            {
                return;
            }
            DrawTopInfo(assetInfoList);
            DrawAssetList(assetInfoList, width);
        }
Beispiel #8
0
        protected virtual void DeleteAsset(List <AssetInfo> assetInfoList, int indexToDelete)
        {
            if (!(assetInfoList != null && 0 <= indexToDelete && indexToDelete < assetInfoList.Count))
            {
                return;
            }
            var assetInfo = assetInfoList[indexToDelete];

            AssetDatabase.DeleteAsset(assetInfo.assetPath);
            AssetInfoLists.RefreshList(AssetType);
        }
Beispiel #9
0
        public static AssetMoveResult OnWillMoveAsset(string oldPath, string newPath)
        {
            if (!oldPath.EndsWith(".asset"))
            {
                return(AssetMoveResult.DidNotMove);
            }
            var asset = AssetDatabase.LoadAssetAtPath(oldPath, typeof(UnityEngine.Object));

            if (asset != null)
            {
                AssetInfoLists.RefreshList(asset.GetType());
            }
            return(AssetMoveResult.DidNotMove);
        }
Beispiel #10
0
        public static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions removeAssetOptions)
        {
            if (!path.EndsWith(".asset"))
            {
                return(AssetDeleteResult.DidNotDelete);
            }
            var asset = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));

            if (asset != null)
            {
                AssetInfoLists.RefreshList(asset.GetType());
            }
            return(AssetDeleteResult.DidNotDelete);
        }
Beispiel #11
0
        protected virtual void DrawTopInfo(List <AssetInfo> assetInfoList)
        {
            var createNew = false;

            try
            {
                GUILayout.BeginHorizontal();
                if (Icon != null)
                {
                    GUILayout.Box(Icon, GUILayout.Width(48), GUILayout.Height(48));
                }
                EditorGUILayout.HelpBox(HelpText, MessageType.None, true);
                try
                {
                    GUILayout.BeginVertical(GUILayout.Width(ButtonWidth));
                    if (GUILayout.Button(new GUIContent("Refresh", "Rescan the project for " + AssetType.Name + " assets."), GUILayout.Width(ButtonWidth)))
                    {
                        AssetInfoLists.RefreshList(AssetType);
                    }
                    if (GUILayout.Button(new GUIContent("New", "Create a new " + AssetType.Name + "."), GUILayout.Width(ButtonWidth)))
                    {
                        createNew = true;
                    }
                }
                finally
                {
                    GUILayout.EndVertical();
                }
            }
            finally
            {
                GUILayout.EndHorizontal();
            }
            if (createNew)
            {
                CreateNewAsset(assetInfoList);
            }
        }
        private void OnClickNewUrgencyFunction(object data)
        {
            var type = data as System.Type;

            if (type == null)
            {
                return;
            }
            var assetInfoList = AssetInfoLists.GetList(AssetType);

            if (assetInfoList == null)
            {
                return;
            }
            var wrapperType = QuestEditorUtility.GetWrapperType(type);

            if (wrapperType != null)
            {
                type = wrapperType;
            }
            var newAsset = AssetUtility.CreateAsset(type, AssetType.Name, true);

            assetInfoList.Add(new AssetInfo(newAsset));
        }