Ejemplo n.º 1
0
    public static Crafting.Recipe Create()
    {
        Crafting.Recipe asset = ScriptableObject.CreateInstance <Crafting.Recipe>();

        AssetDatabase.CreateAsset(asset, "Assets/Recipe.asset");
        AssetDatabase.SaveAssets();
        return(asset);
    }
Ejemplo n.º 2
0
 public void SetRecipe(Crafting.Recipe recipe)
 {
     _recipe        = recipe;
     _sprite.sprite = _recipe.OutputObject.Sprite;
 }
Ejemplo n.º 3
0
    Craftable GetCraftableForResource(ResourcePickup anchorResource, out Vector3 spawnPos)
    {
        ResourceInfo.ResourceType tileType        = tm.tiles[anchorResource.position].resourceType;
        List <Crafting.Recipe>    possibleRecipes = GetPossibleRecipes(new Stack(anchorResource.info.type, tileType, anchorResource.gameObjects.Count));

        bool hasRecipe = false;

        Crafting.Recipe       confirmedRecipe   = new Crafting.Recipe();
        List <ResourcePickup> affectedResources = new List <ResourcePickup> ();

        foreach (var recipe in possibleRecipes)
        {
            int correct = 0;
            for (int y = 0; y < recipe.resources.GetLength(1); y++)
            {
                for (int x = 0; x < recipe.resources.GetLength(0); x++)
                {
                    Vector2 posToCheck = new Vector2(anchorResource.position.x + x, anchorResource.position.y + y);
                    if (ResourcePickup.IsAtPosition(posToCheck) && tm.PadAtPosition(posToCheck) == null)
                    {
                        ResourcePickup resourceAtPos = ResourcePickup.GetAtPosition(posToCheck);
                        if (resourceAtPos.island.buildable)
                        {
                            if (resourceAtPos.info.type == recipe.resources [x, y].resourceType && resourceAtPos.gameObjects.Count == recipe.resources [x, y].count)
                            {
                                // check tile
                                ResourceInfo.ResourceType curTileType = tm.tiles [posToCheck].resourceType;
                                if (curTileType == recipe.resources [x, y].tileType)
                                {
                                    affectedResources.Add(resourceAtPos);
                                    correct++;
                                }
                            }
                        }
                    }
                }
            }

            if (correct >= recipe.resources.Length)
            {
                hasRecipe       = true;
                confirmedRecipe = recipe;
                break;
            }
        }

        if (hasRecipe)
        {
            Craftable craftableInfo = craftableInfos [confirmedRecipe.name];
            spawnPos = anchorResource.gameObjects[0].transform.position + new Vector3(craftableInfo.anchorOffset.x, 0, craftableInfo.anchorOffset.y);

            if (confirmedRecipe.type != Recipe.RecipeType.Building)
            {
                tm.ConsumeResources(affectedResources);
            }

            return(craftableInfo);
        }
        else
        {
            spawnPos = Vector3.zero;
            return(null);
        }
    }