コード例 #1
0
        private string decode_state(state_enum State)
        {
            switch (State)
            {
            case state_enum.Wait: return("Ожидание");

            case state_enum.Run: return("Выполняется");

            case state_enum.Success: return("Успешно");

            case state_enum.Error: return("Ошибка");

            case state_enum.Canceled: return("Отменено");

            default: return("");
            }
        }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (inventory_size != player_pickup.Inventory_items.Count)
        {
            updateUI();
            inventory_size = player_pickup.Inventory_items.Count;
        }



        /*  4 states
         *  1. Inventory.Count == 0
         *      don't display anything, all the children should be disabled
         *  2. Inventory.Count == 1
         *      display icon at children[i], do not allow Q and E movement of the wheel
         *          - play the sound that says "you can't spin any further"
         *  3. Inventory.Count == 2
         *      display icons at children[1] and children[2], allow Q and E movement of the wheel
         *          - but ONLY between them, and play "you can't spin any further" sound
         *  4. Inventory.Count >= 3
         *      enable all the icons and stuff
         *      do everything normally
         */


        if (inventory_size == 0)
        {
            if (!setup0)
            {
                int converted = goal_orientation % 8;
                if (converted < 0)
                {
                    converted += 8;
                }

                // set enabled
                children[converted].SetActive(false);
                children[converted + 1].SetActive(false);
                children[converted + 2].SetActive(false);
                setup0 = true;

                setup1 = false;
                setup2 = false;
                setup3 = false;
            }
        }
        else if (inventory_size == 1)
        {
            if (!setup1)
            {
                int converted = goal_orientation % 8;
                if (converted < 0)
                {
                    converted += 8;
                }

                int c1_index = converted;
                int c2_index = converted + 1;
                if (c2_index > 7)
                {
                    c2_index -= 8;
                }
                int c3_index = converted + 2;
                if (c3_index > 7)
                {
                    c3_index -= 8;
                }

                // set enabled
                //print("inventory_i.Count == 1, and converted = " + converted);
                children[c1_index].SetActive(false);
                children[c2_index].SetActive(true);
                children[c3_index].SetActive(false);

                oneItemSetup();

                setup1 = true;
                setup0 = false;
                setup2 = false;
                setup3 = false;
            }
        }
        else if (inventory_size == 2)
        {
            if (!setup2)
            {
                int converted = goal_orientation % 8;
                if (converted < 0)
                {
                    converted += 8;
                }

                //print("converted = " + converted);
                // set disabled on all the kiddos
                for (int i = 0; i < children.Count; i++)
                {
                    children[i].SetActive(false);
                }

                // and be sure to loop around!
                if (converted + 1 >= children.Count)
                {
                    children[converted + 1 - children.Count].SetActive(true);
                }
                else
                {
                    children[converted + 1].SetActive(true);
                }


                if (selected == 0)
                {
                    if (converted + 2 >= children.Count)
                    {
                        children[converted + 2 - children.Count].SetActive(true);
                    }
                    else
                    {
                        children[converted + 2].SetActive(true);
                    }
                }
                else if (selected == 1)
                {
                    children[converted].SetActive(true);
                }

                twoItemSetup();

                setup2 = true;
                setup0 = false;
                setup1 = false;
                setup3 = false;
            }

            // handle input
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (selected == 0)
                {
                    goal_orientation++;
                    selected        = 1;
                    goal_rot_change = new Vector3(0, 0, 45 * goal_orientation);
                    w_state         = state_enum.spinning;
                }
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                if (selected == 1)
                {
                    goal_orientation--;
                    selected        = 0;
                    goal_rot_change = new Vector3(0, 0, 45 * goal_orientation);
                    w_state         = state_enum.spinning;
                }
            }

            // loop 'selected' around the length of the Inventory_n
            if (selected == Inventory_n.Count)
            {
                selected = selected % Inventory_n.Count;
            }
            if (selected < 0)
            {
                selected += Inventory_n.Count;
            }


            //int converted = goal_orientation % 8;
            //if (converted < 0) converted += 8;

            if (w_state == state_enum.spinning)
            {
                Quaternion quat = Quaternion.identity;
                quat.eulerAngles   = goal_rot_change;
                transform.rotation = Quaternion.Lerp(transform.rotation, quat, wheel_turn_speed * Time.deltaTime);

                foreach (Transform child in transform)
                {
                    child.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                }

                int converted = goal_orientation % 8;
                if (converted < 0)
                {
                    converted += 8;
                }
                // converted is now the index of the child at the bottom of the visible wheel

                int c1, c2;
                if (selected == 1)
                {
                    c1 = converted;
                    c2 = converted + 1;
                    if (c2 > 7)
                    {
                        c2 -= 8;
                    }
                    children[c1].transform.localScale = new Vector3(0.2f, 0.2f, 1);
                    children[c2].transform.localScale = new Vector3(item_pop, item_pop, 1);
                }
                else
                {
                    c1 = converted + 1;
                    if (c1 > 7)
                    {
                        c1 -= 8;
                    }
                    c2 = converted + 2;
                    if (c2 > 7)
                    {
                        c2 -= 8;
                    }
                    children[c1].transform.localScale = new Vector3(item_pop, item_pop, 1);
                    children[c2].transform.localScale = new Vector3(0.2f, 0.2f, 1);
                }


                player_throw.changeObjectHolding(Inventory_i[selected]);

                if (Mathf.Abs(quat.eulerAngles.z - transform.rotation.eulerAngles.z) < snapping_threshold)
                {
                    transform.rotation = quat;
                    w_state            = state_enum.stationary;
                }
            }
        }
        // INVENTORY_SIZE == 3
        else
        {
            if (!setup3)
            {
                for (int i = 0; i < children.Count; i++)
                {
                    children[i].SetActive(true);
                }
                threeItemSetup();

                setup3 = true;
                setup0 = false;
                setup1 = false;
                setup2 = false;
            }

            /*for(int i=0; i<Inventory_i.Count; i++)
             * {
             *  print("[" + i.ToString() + "] - " + Inventory_n[i]);
             * }*/


            // handle input
            if (Input.GetKeyDown(KeyCode.E))
            {
                goal_orientation++;
                selected++;
                goal_rot_change = new Vector3(0, 0, 45 * goal_orientation);
                w_state         = state_enum.spinning;
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                goal_orientation--;
                selected--;
                goal_rot_change = new Vector3(0, 0, 45 * goal_orientation);
                w_state         = state_enum.spinning;
            }

            // loop 'selected' around the length of the Inventory_n
            if (selected == Inventory_n.Count)
            {
                selected = selected % Inventory_n.Count;
            }
            if (selected < 0)
            {
                selected += Inventory_n.Count;
            }

            // converted is now the index of the child at the bottom of the visible wheel
            int converted = goal_orientation % 8;
            if (converted < 0)
            {
                converted += 8;
            }

            if (w_state == state_enum.spinning)
            {
                Quaternion quat = Quaternion.identity;
                quat.eulerAngles   = goal_rot_change;
                transform.rotation = Quaternion.Lerp(transform.rotation, quat, wheel_turn_speed * Time.deltaTime);

                foreach (Transform child in transform)
                {
                    child.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                }

                // strings of the 3 inventory items around the currently selected one
                string c1_name = getNameAtInventoryIndex(selected - 1);
                string c2_name = getNameAtInventoryIndex(selected);
                string c3_name = getNameAtInventoryIndex(selected + 1);

                // load up the images on the UI with the names of
                int c1_index = converted;
                int c2_index = converted + 1;
                if (c2_index > 7)
                {
                    c2_index -= 8;
                }
                int c3_index = converted + 2;
                if (c3_index > 7)
                {
                    c3_index -= 8;
                }

                children[c1_index].GetComponent <UnityEngine.UI.Image>().sprite = icon_map[c1_name];
                children[c2_index].GetComponent <UnityEngine.UI.Image>().sprite = icon_map[c2_name];
                children[c3_index].GetComponent <UnityEngine.UI.Image>().sprite = icon_map[c3_name];

                children[c1_index].transform.localScale = new Vector3(0.2f, 0.2f, 1);
                children[c2_index].transform.localScale = new Vector3(item_pop, item_pop, 1);
                children[c3_index].transform.localScale = new Vector3(0.2f, 0.2f, 1);

                // NOW call the function to change held_item_ in Throw.cs
                // convert to the size of the inventory
                c2_index = c2_index % Inventory_i.Count;
                player_throw.changeObjectHolding(Inventory_i[selected]);

                if (Mathf.Abs(quat.eulerAngles.z - transform.rotation.eulerAngles.z) < snapping_threshold)
                {
                    transform.rotation = quat;
                    w_state            = state_enum.stationary;
                }
            }
        }
    }