예제 #1
0
        public static void AddCustomRecipe(GameObject prefab, Items.RecipesConfig recipes, bool craftingMode)
        {
            var recipe = ScriptableObject.CreateInstance <Recipe>();

            recipe.m_item = prefab.GetComponent <ItemDrop>();
            var neededResources = new List <Piece.Requirement>();

            foreach (var rec in recipes.recipes)
            {
                if (rec.name == prefab.name)
                {
                    foreach (var component in rec.resources)
                    {
                        neededResources.Add(MockRequirement.Create(component.item, component.amount));
                    }
                    if (rec.craftingStation != null && craftingMode != true)
                    {
                        recipe.m_craftingStation = Mock <CraftingStation> .Create(rec.craftingStation);
                    }
                    if (rec.repairStation != null)
                    {
                        recipe.m_repairStation = Mock <CraftingStation> .Create(rec.repairStation);
                    }
                    recipe.m_amount          = rec.amount;
                    recipe.m_minStationLevel = rec.minStationLevel;
                    recipe.m_resources       = neededResources.ToArray();
                }
            }
            CustomRecipe newRecipe = new CustomRecipe(recipe, fixReference: true, true);

            ObjectDBHelper.Add(newRecipe);
        }
예제 #2
0
        public static void Init(string assetbundle, string recipejson, bool craftingMode)
        {
            assetBundle = Tools.LoadAssetBundle(assetbundle);
            recipes     = Tools.LoadJsonFile <Items.RecipesConfig>(recipejson);

            foreach (var recipe in recipes.recipes)
            {
                if (recipe.enabled)
                {
                    if (assetBundle.Contains(recipe.item))
                    {
                        var prefab = assetBundle.LoadAsset <GameObject>(recipe.item);
                        PrefabHelper.AddCustomItem(prefab, recipes);
                        PrefabHelper.AddCustomRecipe(prefab, recipes, craftingMode);
                    }
                }
            }
            ObjectDBHelper.OnAfterInit += () =>
            {
                foreach (var rec in recipes.recipes)
                {
                    if (rec.enabled && rec.projectilePrefab != null)
                    {
                        var projectile = Prefab.Cache.GetPrefab <Projectile>(rec.projectilePrefab);
                        if (projectile)
                        {
                            var        prefab           = assetBundle.LoadAsset <GameObject>(rec.item);
                            GameObject projectilePrefab = Prefab.InstantiateClone(projectile.gameObject, rec.projectilePrefabName);
                            prefab.GetComponent <ItemDrop>().m_itemData.m_shared.m_attack.m_attackProjectile = projectilePrefab;
                        }
                    }
                }
            };
        }
예제 #3
0
        public static void AddCustomItem(GameObject prefab, Items.RecipesConfig recipes)
        {
            CustomItem customItem = new CustomItem(prefab, fixReference: true);

            ObjectDBHelper.Add(customItem);

            foreach (var rec in recipes.recipes)
            {
                if (rec.name == prefab.name)
                {
                    AddCustomToken(rec.tokenName, rec.tokenValue, rec.tokenDescription, rec.tokenDescriptionValue);
                }
            }
        }