Пример #1
0
    /// <summary>
    /// Creates a radial menu with the parameters set in the interactable object
    /// </summary>
    public void SpawnMenu(RadialMenu_ObjectInteractable obj, string[] display_options = null)
    { //Instanciates the menu prefab
        RadialMenu menu = Instantiate(menu_prefab) as RadialMenu;

        menu.transform.SetParent(transform, false);

        menu.transform.position = RectTransformUtility.WorldToScreenPoint(Camera.main, obj.transform.position);  //Position of the menu in Canvas coordinates
        menu.obj = obj;

        menu.SpawnButtons(obj, display_options);
    }
Пример #2
0
    public RadialMenu_ObjectInteractable obj; //Object to follow

    public void SpawnButtons(RadialMenu_ObjectInteractable obj, string[] display_options = null)
    {
        //Creates all the buttons in the menu with the interactable object information
        for (int i = 0; i < obj.options.Length; i++)
        {
            if (display_options != null)
            {
                bool valid_option = false; //Find if button has to be displayed or not

                for (int j = 0; j < display_options.Length; j++)
                {
                    if (display_options[j] == obj.options[i].title)
                    {
                        valid_option = true;
                        break;
                    }
                }
                if (valid_option == false)
                {
                    continue;
                }
            }
            RadialButton new_button = Instantiate(button_prefab) as RadialButton;
            new_button.transform.SetParent(transform, false);

            float theta = (2 * Mathf.PI / obj.options.Length) * i;
            float x_pos = Mathf.Sin(theta);
            float y_pos = Mathf.Cos(theta);
            new_button.transform.localPosition = new Vector3(x_pos, y_pos, 0) * button_local_distance;

            new_button.background.color    = obj.options[i].color;
            new_button.icon.sprite         = obj.options[i].sprite;
            new_button.title               = obj.options[i].title;
            new_button.main_menu           = this;
            new_button.function            = obj.options[i].function;
            new_button.interactable_object = obj.gameObject;
        }
    }