示例#1
0
 /// <summary>
 /// Add an item to the UI item list.
 /// </summary>
 /// <param name="button"></param>
 public void AddItem(UIChoiceButton button)
 {
     if (button != null && !buttons.Contains(button))
     {
         buttons.Add(button);
     }
 }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        // Calculate the angular space requirements
        int   count             = buttons.Count;
        int   spacingCount      = count + 1;
        float totalAngleSpacing = (anglePerButton * count) + (spacingPerButton * spacingCount);

        // Empty UI will have some fitting space
        if (count == 0)
        {
            totalAngleSpacing = 60;
        }

        // Update the limits on the circular UI to match the angular requirements
        circularUI.AngularLimit = totalAngleSpacing * 0.5f;

        // Calculate an offset value to move the start direction by
        float offset = -(totalAngleSpacing * 0.5f) + spacingPerButton;

        // Create the start direction
        Vector3 centreDir = circularUI.CircleForward;
        Vector3 startDir  = Quaternion.AngleAxis(offset, Vector3.up) * centreDir;

        // Create some running values for the iteration
        int   totalCount    = count + spacingCount - 1;
        int   runningIndex  = 0;
        float runningOffset = 0.0f;

        // Iterate over the total number of items + spaces
        for (int i = 0; i < totalCount; i++)
        {
            if (i % 2 == 0) // Even entries are ui elements
            {
                // Get the button and produce a final angle to use
                UIChoiceButton button   = buttons[runningIndex];
                float          finalAng = runningOffset + (anglePerButton * 0.5f);

                // Apply the position to the object
                Vector3 dir = Quaternion.AngleAxis(finalAng, Vector3.up) * startDir;
                button.transform.position = (circularUI.transform.position + dir.normalized * 8.0f) + new Vector3(0.0f, -buttonYOffsetBelow, 0.0f);

                button.transform.LookAt(transform.position);

                // Increment the running values
                runningOffset += anglePerButton;
                runningIndex++;
            }
            else // Odd entries are spacing elements
            {
                runningOffset += spacingPerButton;
            }
        }

        // Draw some values in the editor.
        Vector3 pos = circularUI.transform.position;

        Debug.DrawLine(pos, pos + centreDir * 5.0f, Color.yellow);
        Debug.DrawLine(pos, pos + startDir * 5.0f, Color.cyan);
    }
示例#3
0
    /// <summary>
    /// Called when a new button needs to be created for the pool.
    /// </summary>
    /// <returns></returns>
    private UIChoiceButton CreateButtonInstance()
    {
        UIChoiceButton buttonInstance = GameObject.Instantiate <UIChoiceButton>(prefab);

        // TODO: Init stuff here...

        return(buttonInstance);
    }
示例#4
0
    public void PlaceButton(int decisionChoice, string decisionText)
    {
        decisionText = TextWrapUtils.GetWrappedText(decisionText, titleWordCharacterLimit);

        UIChoiceButton button = choiceButtonPool.Get();

        activeButtons.Add(button);

        // Populate data entries
        button.SetSelectionChoice(decisionChoice);
        button.SetButtonText(decisionText);

        uiFitter.AddItem(button);
    }
示例#5
0
    public UIController(SimulationController controller) : base(controller)
    {
        // Get the central display text and set some default values
        centralDisplayText = GameObject.Find("CENTRAL_DISPLAY_TEXT").GetComponent <TextMesh>();
        SetCentralDisplayText("");
        SetCentralDisplayTextVisibility(false);

        prefab     = Resources.Load <UIChoiceButton>("UIChoiceButton");
        circularUI = GameObject.FindObjectOfType <CircularUI>();
        uiFitter   = GameObject.FindObjectOfType <UIFitter>();

        choiceButtonPool = new Pool <UIChoiceButton>(CreateButtonInstance, ButtonStored, ButtonReleased);
        decisionChoices  = new List <int>();
        activeButtons    = new List <UIChoiceButton>();
    }
示例#6
0
 /// <summary>
 /// Called whenever a button is stored in the pool.
 /// </summary>
 /// <param name="button"></param>
 private void ButtonStored(UIChoiceButton button)
 {
     // Reset the button and disable it.
     button.SetButtonText("");
     button.gameObject.SetActive(false);
 }
示例#7
0
 /// <summary>
 /// Called whenever a button is released from the pool.
 /// </summary>
 /// <param name="button"></param>
 private void ButtonReleased(UIChoiceButton button)
 {
     // Enable released buttons.
     button.gameObject.SetActive(true);
 }
示例#8
0
 /// <summary>
 /// Remove an item from the UI item list.
 /// </summary>
 /// <param name="button"></param>
 public void RemoveItem(UIChoiceButton button)
 {
     buttons.Remove(button);
 }