Inheritance: MonoBehaviour
コード例 #1
0
ファイル: GameManager.cs プロジェクト: NachoDevs/OneGameAWeek
    void InstantiateBoxes()
    {
        foreach (Transform child in boxesParent)
        {
            Destroy(child.gameObject);
        }

        int index = 0;

        foreach (Transform t in boxSpawns)
        {
            IngredientSpawner iSpawner = Instantiate(boxPrefab, t.position, t.rotation, boxesParent).GetComponent <IngredientSpawner>();

            if (index < m_recipeUIList.Count)
            {
                iSpawner.ingredientSprite.sprite = m_recipeUIList[index].GetComponentsInChildren <Image>()[1].sprite;
                iSpawner.ingredient = m_recipeUIList[index].GetComponentsInChildren <Image>()[1].sprite;;
            }
            else
            {
                while (true)
                {
                    int rnd = Random.Range(0, ingredients.Length - 1);

                    if (!roundRecipe.ContainsKey(ingredients[rnd]))
                    {
                        iSpawner.ingredientSprite.sprite = ingredients[rnd];
                        iSpawner.ingredient = ingredients[rnd];
                        break;
                    }
                }
            }
            ++index;
        }
    }
コード例 #2
0
    public PlantEffect.Ingredient[] GenerateRandomRecipe()
    {
        ingredientSpawner = FindObjectOfType <IngredientSpawner>();
        ingredientSpawner.InitIngredientLists(currentRecipeSize);
        PlantEffect.Ingredient[] recipe = new PlantEffect.Ingredient[currentRecipeSize];
        for (int i = 0; i < currentRecipeSize; i++)
        {
            ingredientSpawner.currentBatch = i;
            recipe[i] = GenerateRandomIngredient();
            AddRecipeToDropList(recipe[i], 0);
            for (int j = 1; j < ingredientSpawner.ingredientsByBatch; j++)
            {
                AddRecipeToDropList(GenerateRandomIngredient(), j);
            }
        }
        ingredientSpawner.currentBatch = 0;

        var timePerRecipe     = PlayerPrefs.HasKey(recipeTime) ? PlayerPrefs.GetFloat(recipeTime) : defaultRecipeTime;
        var timePerIngredient = PlayerPrefs.HasKey(ingredientTime) ? PlayerPrefs.GetFloat(ingredientTime) : defaultIngredientTime;
        var newTime           = timePerRecipe + timePerIngredient * recipe.Length; // divide by number of player

        TimerManager.instance.SetNewTime(newTime);

        return(recipe);
    }
コード例 #3
0
 void Start()
 {
     ingredientSpawner = GetComponent <IngredientSpawner>();
     CreateSandwich();
     if (backgroundMusic.isPlaying)
     {
         backgroundMusic.Stop();
         backgroundMusic.Play();
     }
 }
コード例 #4
0
 public void MarkSpawnerAvailableAndSpawnIngredientAtRandomSpawner(IngredientSpawner pSpawner, string strIngredientID)
 {
     if (pSpawner.PlayerID == 0)
     {
         m_lst_pIngredientSpawnersAvailable_Left.Add(pSpawner.gameObject);
         SpawnIngredientAtRandomSpawnerLeft(IngredientsIDs_To_IngredientPrefab[strIngredientID]);
     }
     else
     {
         m_lst_pIngredientSpawnersAvailable_Right.Add(pSpawner.gameObject);
         SpawnIngredientAtRandomSpawnerRight(IngredientsIDs_To_IngredientPrefab[strIngredientID]);
     }
 }
コード例 #5
0
    /*public IEnumerator MoveCauldron (Vector3 targetPos)
     * {
     *      do
     *      {
     *              Vector3 dir = targetPos - transform.position;
     *              dir.y = 0f;
     *              transform.Translate(dir * 500f * Time.deltaTime);
     *              yield return null;
     *      }
     *      while (Vector3.Distance(transform.position, targetPos) > 0.1f);
     *
     *      StartCoroutine(NewBatchs());
     * }*/

    public IEnumerator NewBatchs()
    {
        Debug.Log("new batch");
        var secondsBetweenBatch = TimerManager.instance.GetTime() / recipe.Length;

        for (int i = 0; i < recipe.Length; i++)
        {
            IngredientSpawner spawner = FindObjectOfType <IngredientSpawner>();
            spawner.SpawnIngredients();
            for (int j = 0; j < spawner.ingredientsByBatch; j++)
            {
                spawner.ThrowPickup();
                yield return(new WaitForSeconds(secondsBetweenSpawn));
            }
            yield return(new WaitForSeconds(secondsBetweenBatch));
        }
    }
コード例 #6
0
 private void Awake()
 {
     instance = this;
 }
コード例 #7
0
    // Use this for initialization
    void Start()
    {
        //Finds pause button in the scene by its tag
        pauseButton = GameObject.FindGameObjectWithTag("PauseButton");

        // 0 games completed on startup
        minigamesComplete = 0;

        //Finds the main camera
        sceneCam = GameObject.FindGameObjectWithTag("MainCamera");

        //Sets up tiles, stations and other objects
        kitchen = GetComponent <SetupKitchen>();
        kitchen.Initialize();

        //Spawns a player object
        player = Instantiate <GameObject>(playerObject);

        //Gets player script
        playerScript = player.GetComponent <PlayerScript>();


        //Set ingredientspawner object as an instantiated copy and gets its script
        ingSpawnerObject  = Instantiate <GameObject>(ingSpawnerObjectPublic);
        ingredientSpawner = ingSpawnerObject.GetComponent <IngredientSpawner>();

        //Set messSpawner object as an instantiated copy and gets its script
        messSpawnerObject = Instantiate <GameObject>(messSpawnerObjectPublic);
        messSpawner       = messSpawnerObject.GetComponent <messScript>();

        //Chooses a dish from the menu script at random
        //Later this could possibly be chosen by the player
        ingredientSpawner.SelectDish();

        //Sets up stations for first time use
        GetStations(true);

        //Instantiates and sets a completed dish and sets it as inactive for now
        completeDish = Instantiate <GameObject>(dishObject);
        completeDish.GetComponent <Item>().Type = MenuScript.IngredientType.dish;
        completeDish.SetActive(false);

        //Finds the cover object in the scene and deactivates it
        cover = GameObject.FindGameObjectWithTag("Cover");
        cover.SetActive(false);

        //sets game state to playing
        state         = stateEnum.playing;
        isScenePaused = false;

        //Finds cube object and gets its script
        cube = GameObject.FindGameObjectWithTag("Cube").GetComponent <CubeScript>();

        //initailises score variable
        scoreCurrent = 0;

        //Allows MinigameScore script to set the number of dishes to make based on difficulty
        dishesCurrent = 0;
        if (dishesGoal <= 0)
        {
            dishesGoal = MinigameScores.DishTarget;
        }

        //Gets the attached ticketmanager script
        ticketManager = GetComponent <TicketManager>();

        //Gets the ticket onject in the scene
        ticketObject = GameObject.FindGameObjectWithTag("Ticket");

        //Initialises all the sprites for the ticket
        SetupTicket();

        //Locks any station that wont be used for the first round
        if (oven.targetIngredients.Count <= 0)
        {
            oven.locked = true;
        }
        if (chopping.targetIngredients.Count <= 0)
        {
            chopping.locked = true;
        }
        if (blender.targetIngredients.Count <= 0)
        {
            blender.locked = true;
        }

        //ticket = GameObject.FindGameObjectWithTag("Ticket");

        //Ticket start as open so ticket paues is true
        ticketPause = true;
        buttonPause = false;

        //Initialises all scores
        MinigameScores.ResetScores();

        //new list to hold the currently spawned ingredients
        ingredientObjects = new List <GameObject>();
        foreach (GameObject g in GameObject.FindGameObjectsWithTag("Holdable"))
        {
            ingredientObjects.Add(g);
            g.GetComponentInChildren <GlowScript>().SetGlowing(true);
        }
    }
コード例 #8
0
    private void ApplyAction(Action a)
    {
        if (a is SpawnAction)
        {
            SpawnAction       spawn   = a as SpawnAction;
            IngredientSpawner spawner = IM.IngredientSpawners.Find(x => x.SpawnedIngredients.Exists(y => !y.IsSpawned && y.MyIngredientType == spawn.spawnType));
            HighlightedObject = spawner.gameObject;
        }
        if (a is PickUpAction)
        {
            PickUpAction pickup = a as PickUpAction;
            HighlightedObject = IM.ItemList[pickup.id].gameObject;
        }
        if (a is DropOffAction)
        {
            DropOffAction dropOff = a as DropOffAction;
            HighlightedObject = IM.ItemList[dropOff.id].gameObject;
        }
        if (a is TransferAction)
        {
            TransferAction transfer = a as TransferAction;
            HighlightedObject = IM.ItemList[transfer.id].gameObject;
        }
        if (a is PrepareAction)
        {
            PrepareAction prep = a as PrepareAction;
            HighlightedObject = IM.ItemList[prep.id].gameObject;
        }
        if (a is SubmitOrderAction)
        {
            HighlightedObject = IM.SubmittedTableRef.gameObject;
        }

        if (a is IdleAction)
        {
            HighlightedObject = PlayerStartLocation;
            Highlighter.transform.position = new Vector3(
                HighlightedObject.transform.position.x,
                Highlighter.transform.position.y,
                HighlightedObject.transform.position.z);
            PlayerRef.transform.position = Vector3.right * Highlighter.transform.position.x
                                           + Vector3.forward * Highlighter.transform.position.z;
        }
        else
        {
            Highlighter.transform.position = new Vector3(
                HighlightedObject.transform.position.x,
                Highlighter.transform.position.y,
                HighlightedObject.transform.position.z);
            PlayerRef.transform.position = Vector3.right * Highlighter.transform.position.x
                                           + Vector3.forward * (Highlighter.transform.position.z + 1);
        }


        Debug.Log("Applying action: " + a.ToString(CurrentState));
        if (!a.isValid(CurrentState))
        {
            Debug.LogError("Action is not valid. Ignoring.");
            return;
        }

        CurrentState = a.ApplyAction(CurrentState);
        IM.LoadWorldState(CurrentState);
        Debug.Log("Action applied. History size: " + observedStates.Count);
        Debug.Log(CurrentHeuristic + " = " + CurrentHeuristic.GetHeuristic(CurrentState));
    }
コード例 #9
0
 void Awake()
 {
     instance = this;
     ClearIngredients();
 }
コード例 #10
0
 public void RegisterIngredientSpawner(IngredientSpawner spawner)
 {
     IngredientSpawners.Add(spawner);
 }
コード例 #11
0
    void Update()
    {
        float horizontalMovement = Input.GetAxis("Horizontal");
        float verticalMovement   = Input.GetAxis("Vertical");

        moveTo = new Vector3(horizontalMovement, 0, verticalMovement);

        if (moveTo != Vector3.zero)
        {
            animator.SetBool("Walking", true);
            animator.SetBool("IDLE", false);
            animator.SetBool("Pulling", false);
            animator.SetBool("Cutting", false);
        }
        else
        {
            if (isChopping)
            {
                animator.SetBool("IDLE", false);
                animator.SetBool("Walking", false);
                animator.SetBool("Pulling", false);
                animator.SetBool("Cutting", true);
            }
            else
            {
                animator.SetBool("IDLE", true);
                animator.SetBool("Walking", false);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Furniture currentFurniture = furnitureDetection.GetSelected();
            if (currentFurniture != null)
            {
                Holder currentFurnitureHolder = currentFurniture.GetComponent <Holder>();
                //Give
                if (currentFurnitureHolder != null)
                {
                    //Si el jugador tiene un objeto
                    if (PlayerHolder.HasMovable())
                    {
                        //Si ambos tienen objeto no lo cambia, se queda igual
                        if (PlayerHolder.HasMovable() && currentFurnitureHolder.HasMovable())
                        {
                            MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                            MovableObject playerMovable    = PlayerHolder.GetMovable();

                            PlayerHolder.SetMovable(playerMovable);
                            currentFurnitureHolder.SetMovable(furnitureMovable);
                        }
                        //Si solo uno tiene objeto
                        else
                        {
                            MovableObject movable = PlayerHolder.GetMovable();
                            Trash         trash   = currentFurniture.GetComponent <Trash>();
                            Cooker        cooker  = currentFurniture.GetComponent <Cooker>();
                            Chopper       chopper = currentFurniture.GetComponent <Chopper>();
                            //Si el mueble es el basurero
                            if (trash != null && movable.GetComponent <Food>())
                            {
                                PlayerHolder.RemoveMovable();
                                Destroy(movable.gameObject);

                                /*Food food = movable.GetComponent<Food>();
                                 * if (food!= null)
                                 * {
                                 *  food.Delete();
                                 * }*/
                            }
                            //Solo acepta basura en el basurero
                            if (trash != null && movable.GetComponent <Food>() == false)
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                MovableObject playerMovable    = PlayerHolder.GetMovable();

                                PlayerHolder.SetMovable(playerMovable);
                                currentFurnitureHolder.SetMovable(furnitureMovable);
                            }
                            //Solo acepta la olla en los hornos
                            if (cooker != null && movable.GetComponent <Container>() == false)
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                MovableObject playerMovable    = PlayerHolder.GetMovable();

                                PlayerHolder.SetMovable(playerMovable);
                                currentFurnitureHolder.SetMovable(furnitureMovable);
                            }
                            if (chopper != null && movable.GetComponent <Food>() == false)
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                MovableObject playerMovable    = PlayerHolder.GetMovable();

                                PlayerHolder.SetMovable(playerMovable);
                                currentFurnitureHolder.SetMovable(furnitureMovable);
                            }
                            //Si tiene el objeto y lo que tiene en frente tiene la olla
                            else
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                if (furnitureMovable != null)
                                {
                                    Container furnitureContainer = furnitureMovable.GetComponent <Container>();
                                    if (furnitureContainer != null)
                                    {
                                        Food food = movable.GetComponent <Food>();
                                        if (food != null)
                                        {
                                            if (furnitureContainer.CanAccept(food))
                                            {
                                                PlayerHolder.RemoveMovable();
                                            }
                                        }
                                    }
                                }
                                currentFurnitureHolder.SetMovable(movable);
                                PlayerHolder.RemoveMovable();
                            }
                        }
                    }
                    //Pick
                    else
                    {
                        if (currentFurnitureHolder.HasMovable())
                        {
                            MovableObject movable = currentFurnitureHolder.GetMovable();
                            PlayerHolder.SetMovable(movable);
                            currentFurnitureHolder.RemoveMovable();
                        }
                        else
                        {
                            IngredientSpawner ingred = currentFurniture.GetComponent <IngredientSpawner>();
                            if (ingred != null)
                            {
                                MovableObject movable = ingred.GetIngredient();
                                PlayerHolder.SetMovable(movable);
                            }
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            Furniture currentFurniture = furnitureDetection.GetSelected();
            if (currentFurniture != null)
            {
                Chopper currentChopper = currentFurniture.GetComponent <Chopper>();
                //Comienza a cortar
                if (currentChopper != null)
                {
                    isChopping = currentChopper.StartChopping(this);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            tempForce = force;
            Debug.Log("La fuerza temporal es");
            Debug.Log(tempForce);
            timer += Time.deltaTime;
            while (timer < 10.0f)
            {
                timer += Time.deltaTime;
                force  = forceBoost;
                Debug.Log("La fuerza es");
                Debug.Log(force);
            }
            force = tempForce;
            Debug.Log("La fuerza es");
            Debug.Log(force);
        }
    }