Exemple #1
0
        private void PopulateRecipeIDs(IntListSO target)
        {
            var recipes = AssetsUtility.FindAllAssets <Recipe>();

            target.ints = new System.Collections.Generic.List <int>();

            for (int i = 0; i < recipes.Length; i++)
            {
                target.ints.Add(recipes[i].id);
            }
        }
Exemple #2
0
        // [MenuItem("Generate ScriptableDatabase", false, -2), MenuItem("Assets/Create/ScriptableDatabase", false, -11)]
        /// <summary>
        /// Generates or regenerates a <c cref="ScriptableDatabase">ScriptableDatabase</c> asset.
        /// </summary>
        /// <remarks>
        /// Use with the <c>MenuItem</c> attribute or other editor scripts.
        /// </remarks>
        public static void GenerateDatabase <TDatabase, TElement>()
            where TDatabase : ScriptableDatabase <TElement>
            where TElement : ScriptableObject
        {
            var db = GetDatabase <TDatabase, TElement>();

            if (db == null)
            {
                return;
            }

            db.Initialise(AssetsUtility.FindAllAssets <TElement>());

            EditorUtility.SetDirty(db);
            AssetsUtility.SaveRefreshAndFocus();
            Selection.activeObject = db;
        }
Exemple #3
0
        private void OnGUI()
        {
            // Only change what should be drawn (for the next frame?) during `Layout` event.
            if (Event.current.rawType == EventType.Layout)
            {
                //! Should probably only run this line if an Item asset was created or deleted.
                itemAssets = AssetsUtility.FindAllAssets <Item>().OrderBy(i => i.id).ToArray();
            }

            EditorGUILayout.BeginHorizontal();
            selectedItem = DrawItemsSidebar(itemAssets);
            DrawSelectedItem();
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("Generate ItemDatabase"))
            {
                ItemDatabaseUtility.GenerateItemDatabase();
            }
        }
Exemple #4
0
        /// <summary>
        /// Attempts to find an instance of a <c cref="ScriptableDatabase">ScriptableDatabase</c> from the Assets folder, creating one if none exist.
        /// </summary>
        /// <remarks>
        /// Returns <c>null</c> if multiple instances exist, logging a warning in the console.
        /// </remarks>
        private static TDatabase GetDatabase <TDatabase, TElement>()
            where TDatabase : ScriptableDatabase <TElement>
            where TElement : ScriptableObject
        {
            var databases = AssetsUtility.FindAllAssets <TDatabase>();

            if (databases.Length < 1)
            {
                Debug.Log($"Creating a new {typeof(TDatabase).Name} since none exist.");
                return(ScriptableObjectUtility.CreateAsset <TDatabase>());
            }
            else if (databases.Length > 1)
            {
                Debug.LogError($"Multiple `{typeof(TDatabase).Name}` exist. Please delete the extra(s) and try again.");
                return(null);
            }
            else
            {
                return(databases[0]);
            }
        }
        private static ItemDatabase GetItemDatabase()
        {
            var databases = AssetsUtility.FindAllAssets <ItemDatabase>();

            ItemDatabase itemDB = null;

            if (databases.Length < 1)
            {
                Debug.Log("Creating a new ItemDatabase since none exist.");
                itemDB = ScriptableObjectUtility.CreateAsset <ItemDatabase>();
            }
            else if (databases.Length > 1)
            {
                Debug.LogError("Multiple ItemDatabases exist. Please delete the extra(s) and try again.");
            }
            else
            {
                itemDB = databases[0];
            }

            return(itemDB);
        }
        private static List <Item> GetAllItemAssets()
        {
            var result = new List <Item>();

            var instances   = AssetsUtility.FindAllAssets <Item>();
            var gatheredIDs = new List <int>();

            for (int i = 0; i < instances.Length; i++)
            {
                if (gatheredIDs.Contains(instances[i].id))
                {
                    var sharedID = result[gatheredIDs.IndexOf(instances[i].id)].name;
                    Debug.LogWarning("'" + instances[i].name + "' was excluded from the ItemDatabase because it shares its ID (" + instances[i].id + ") with '" + sharedID + "'.");
                }
                else
                {
                    result.Add(instances[i]);
                    gatheredIDs.Add(instances[i].id);
                }
            }

            result = result.OrderBy(i => i.id).ToList();
            return(result);
        }
Exemple #7
0
    private static void RefreshReferences(ScriptableObjectPersistence sop)
    {
        Undo.RecordObject(sop, "Refresh Scriptable Object References");

        var itemDB = AssetsUtility.FindFirstAsset <ItemDatabase>("");

        ReflectionUtility.SetPrivateField(sop, "_itemDatabase", itemDB);

        var skinTexDBs = AssetsUtility.FindAllAssets <SkinTexturesDatabase>();

        ReflectionUtility.SetPrivateField(sop, "_skinTexturesDatabases", skinTexDBs);

        var name = AssetsUtility.FindFirstAsset <StringValue>("Save");

        ReflectionUtility.SetPrivateField(sop, "_saveName", name);

        var pos = AssetsUtility.FindFirstAsset <VectorValue>("Player");

        ReflectionUtility.SetPrivateField(sop, "_playerPosition", pos);

        var health = AssetsUtility.FindFirstAsset <ConstrainedFloat>("Health");

        ReflectionUtility.SetPrivateField(sop, "_health", health);

        var mana = AssetsUtility.FindFirstAsset <ConstrainedFloat>("Mana");

        ReflectionUtility.SetPrivateField(sop, "_mana", mana);

        var lumen = AssetsUtility.FindFirstAsset <ConstrainedFloat>("Lumen");

        ReflectionUtility.SetPrivateField(sop, "_lumen", lumen);

        var xp = AssetsUtility.FindFirstAsset <XPSystem>("Player");

        ReflectionUtility.SetPrivateField(sop, "_xpSystem", xp);

        var time = AssetsUtility.FindFirstAsset <FloatValue>("TimeOfDay");

        ReflectionUtility.SetPrivateField(sop, "_timeOfDay", time);

        var appearance = AssetsUtility.FindFirstAsset <CharacterAppearance>("Player");

        ReflectionUtility.SetPrivateField(sop, "_characterAppearance", appearance);

        var inv = AssetsUtility.FindFirstAsset <Inventory>("Player");

        ReflectionUtility.SetPrivateField(sop, "_playerInventory", inv);

        var bools          = AssetsUtility.FindAllAssets <BoolValue>();
        var strings        = AssetsUtility.FindAllAssets <StringValue>();
        var chests         = new List <BoolValue>();
        var stashes        = new List <BoolValue>();
        var doors          = new List <BoolValue>();
        var bosses         = new List <BoolValue>();
        var healthCrystals = new List <BoolValue>();
        var manaCrystals   = new List <BoolValue>();
        var cutscenes      = new List <BoolValue>();
        var quests         = new List <BoolValue>();

        for (int i = 0; i < bools.Length; i++)
        {
            var path = AssetDatabase.GetAssetPath(bools[i]);
            if (path.Contains("Chest"))
            {
                chests.Add(bools[i]);
            }
            if (path.Contains("Stashes"))
            {
                stashes.Add(bools[i]);
            }
            else if (path.Contains("Doors"))
            {
                doors.Add(bools[i]);
            }
            else if (path.Contains("Bosses"))
            {
                bosses.Add(bools[i]);
            }
            else if (path.Contains("HealthCrystals"))
            {
                healthCrystals.Add(bools[i]);
            }
            else if (path.Contains("ManaCrystals"))
            {
                manaCrystals.Add(bools[i]);
            }
            else if (path.Contains("Cutscenes"))
            {
                cutscenes.Add(bools[i]);
            }
            else if (path.Contains("QuestsBools"))
            {
                quests.Add(bools[i]);
            }
        }

        ReflectionUtility.SetPrivateField(sop, "_chests", chests.ToArray());
        ReflectionUtility.SetPrivateField(sop, "_stashes", stashes.ToArray());
        ReflectionUtility.SetPrivateField(sop, "_doors", doors.ToArray());
        ReflectionUtility.SetPrivateField(sop, "_bosses", bosses.ToArray());
        ReflectionUtility.SetPrivateField(sop, "_healthCrystals", healthCrystals.ToArray());
        ReflectionUtility.SetPrivateField(sop, "_manaCrystals", manaCrystals.ToArray());
        ReflectionUtility.SetPrivateField(sop, "_cutscenes", cutscenes.ToArray());
        ReflectionUtility.SetPrivateField(sop, "_quests", quests.ToArray());

        var inventories       = AssetsUtility.FindAllAssets <Inventory>();
        var vendorInventories = new List <ScriptableObjectPersistence.VendorInventorySet>();

        for (int i = 0; i < inventories.Length; i++)
        {
            var path = AssetDatabase.GetAssetPath(inventories[i]);
            if (path.Contains("Vendor") && !path.Contains("Default"))
            {
                var search = path.Split('/').Last();        // Remove anything before the last `/` in the path (i.e. folder names).
                search = search.Split('.').First();         // Remove file extension.
                search = search.Replace("Vendor", "");
                search = search.Replace("Inventory", "");
                var initial = AssetsUtility.FindFirstAsset <Inventory>(search);

                // Only accept inventories with "Default" in the path.
                if (initial != null && !AssetDatabase.GetAssetPath(initial).Contains("Default"))
                {
                    initial = null;
                }

                vendorInventories.Add(new ScriptableObjectPersistence.VendorInventorySet(inventories[i], initial));
            }
        }
        ReflectionUtility.SetPrivateField(sop, "_vendorInventories", vendorInventories.ToArray());

        PrefabUtility.RecordPrefabInstancePropertyModifications(sop);

        Debug.Log("SOP: Refreshed references.");
    }