/// <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); } }
// 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); }
/// <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); }
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); }
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>(); }
/// <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); }
/// <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); }
/// <summary> /// Remove an item from the UI item list. /// </summary> /// <param name="button"></param> public void RemoveItem(UIChoiceButton button) { buttons.Remove(button); }