public void LinkStatsToAction(string type) { foreach (var stat in _stats) { var actions = _objectManager.MainPlanet.MainRadial.Elements.FindAll(x => x.Type == type); RadialButton button = null; foreach (UserAction act in actions) { if (act.AssociatedAction == stat.AssociatedAction) { button = act.RadialButton; button.Type = act.Type; button.SubMenu.Type = button.Type; break; } } if (button == null) { continue; } stat.Parent = button.SubMenu.transform; stat.transform.SetParent(stat.Parent, false); button.SubMenu.Elements.Add(stat); stat.RadialButton = button; if (stat.Image != null) { stat.Image.color = button.Image.color; } } foreach (UserAction action in _objectManager.MainPlanet.MainRadial.Elements) { action.RadialButton.SubMenu?.Arrange(); } }
// Needs an instance of where the custom class Action() is located (in this case in the Player Controller Script.). public void SpawnButtons(PlayerController obj) { // Slows down time while the menu is active. Time.timeScale = 0.0f; Time.fixedDeltaTime = 0.02F * Time.timeScale; // Creates a button around the circumference of a circle depending on how many buttons we defined. for (int i = 0; i < obj.elements.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); // Finds how many buttons need to be created and divides the circumference of the circle accordingly. float tetha = (2 * Mathf.PI / obj.elements.Length) * i; float xPos = Mathf.Sin(tetha); float yPos = Mathf.Cos(tetha); // Sets the position and information of every button. newButton.transform.localPosition = new Vector2(xPos, yPos) * 100f; newButton.circle.color = obj.elements[i].colour; newButton.icon.sprite = obj.elements[i].sprite; newButton.index = obj.elements[i].index; // Sets the menu to this current instance of the script. newButton.myMenu = this; } }
void Start() { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); newButton.transform.localPosition = new Vector3(0f, 100f); }
IEnumerator AnimateButtons(Interactable obj) { for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * 50f; newButton.actionCost = obj.options[i].actionCost; newButton.costText.text = obj.options[i].actionCost.ToString(); if (obj.options[i].actionCost > FindObjectOfType <LevelConfig>().gold) { newButton.circle.color = new Color(0.20f, 0.20f, 0.20f); newButton.costText.color = new Color(0.9f, 0.2f, 0.2f); } else { newButton.circle.color = new Color(1f, 1f, 1f); newButton.costText.color = new Color(0.2f, 0.2f, 0.2f); } newButton.circle.sprite = obj.options[i].buttonSprite; newButton.icon.sprite = obj.options[i].iconSprite; newButton.title = obj.options[i].title; newButton.buttonAction = obj.options[i].action; newButton.myMenu = this; newButton.Anim(); yield return(new WaitForSeconds(0.12f)); } }
public void SpawnButtons(List <RightClickMenuItem> menus, int menudepth, int startingAngle, int topLevelParent = -1) { int range = 360; //is the range that the buttons will be on in degrees int minimumAngle = 0; //The initial offset Of the buttons in degrees int maximumAngle = 360; //Linked to range if (menudepth > 100) { range = menus.Count * (360 / density[menudepth]); //Try and keep the icons nicely spaced on the outer rings minimumAngle = (int)(startingAngle - ((range / 2) - (0.5f * (360 / density[menudepth])))); maximumAngle = startingAngle + range; } for (var i = 0; i < menus.Count; i++) { RadialButton newButton = Instantiate(ButtonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); //Magic maths float theta = (float)(((range * Mathf.Deg2Rad) / menus.Count) * i); theta = (theta + (minimumAngle * Mathf.Deg2Rad)); float xpos = Mathf.Sin(theta); float ypos = Mathf.Cos(theta); if (menudepth == 100) { topLevelButtons.Add(newButton); newButton.SetButton(new Vector2(xpos, ypos) * menudepth, this, menus[i], true); } else if (menudepth == 200) { newButton.SetButton(new Vector2(xpos, ypos) * menudepth, this, menus[i], false); topLevelButtons[topLevelParent].childButtons.Add(newButton); } else { //TODO: What to do with higher depths ?!?! probably just keep it at 2 layers for time being } if (menus[i].SubMenus != null) { if (menus[i].SubMenus.Count != 0) { Vector2 targetDir = newButton.transform.position - transform.position; var angle = Vector2.Angle(targetDir, transform.up); if (targetDir.x < 0) { angle *= -1; } SpawnButtons(menus[i].SubMenus, menudepth + 100, (int)angle, i); } } foreach (var btn in newButton.childButtons) { btn.gameObject.SetActive(false); } } }
public void SetButtonAsLastSibling(RadialButton radialButton) { int index = topLevelButtons.IndexOf(radialButton); for (int i = index; i >= 0; i--) { topLevelButtons[i].transform.SetAsFirstSibling(); } for (int i = topLevelButtons.Count - 1; i > index; i--) { topLevelButtons[i].transform.SetAsFirstSibling(); } }
public void SpawnButtons(Interactable obj) { for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * 2f; //newButton.GetComponent<SpriteRenderer>().sprite = obj.options [i].sprite1; //newButton.GetComponent<SpriteRenderer>().sprite = obj.options [i].sprite2; newButton.SpawnSprites(obj); } }
// Use this for initialization public void SpawnButtons(Interactable obj) { for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * 100f; newButton.Circle.color = obj.options[i].color; newButton.Icon.sprite = obj.options[i].sprite; newButton.title = obj.options[i].title; newButton.myMenu = this; // newButton.transform.localPosition = new Vector3(0f, 100f, 0f); } }
//animate buttons in around a circle, one at a time IEnumerator AnimateButtons(Interactable obj) { for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * 50f; newButton.circle.color = obj.options[i].color; newButton.icon.sprite = obj.options[i].sprite; newButton.title = obj.options[i].title; newButton.myMenu = this; newButton.Anim(); yield return(new WaitForSeconds(0.12f)); } }
public void SpawnButtons(WandController wand) { for (int i = 0; i < wand.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / wand.options.Length) * i; float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * 0.1f; newButton.gameController = gameController; newButton.sprite = wand.options[i].sprite; newButton.activeSprite = wand.options[i].activeSprite; newButton.title = wand.options[i].title; newButton.id = wand.options.Length - i - 1; newButton.myMenu = this; } }
public void SpawnButtons(Interactable obj) { for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * radius; newButton.circle.color = obj.options [i].color; newButton.icon.sprite = obj.options [i].sprite; newButton.title.text = obj.options [i].title; newButton.action = obj.options [i].action; newButton.myMenu = this; NetworkServer.Spawn(newButton.gameObject); } }
void ButtonSelection() { if (Input.mouseScrollDelta.y > 0) { if (SelectionCounter >= buttonsList.Length - 1) { SelectionCounter = 0; } else { SelectionCounter += 1; } } if (Input.mouseScrollDelta.y < 0) { if (SelectionCounter <= 0) { SelectionCounter = buttonsList.Length - 1; } else { SelectionCounter -= 1; } } selected = buttonsList[SelectionCounter]; if (prevSelected == null) { prevSelected = buttonsList[buttonsList.Length - 1]; defaultColor = prevSelected.background.color; defaultScale = prevSelected.transform.localScale; } if (selected != prevSelected) { prevSelected.background.color = defaultColor; prevSelected.transform.localScale = defaultScale; defaultColor = selected.background.color; defaultScale = selected.transform.localScale; selected.background.color = Color.white; selected.transform.localScale = new Vector3(1.25f, 1.25f, 1.25f); prevSelected = selected; } }
IEnumerator AnimateButtons(Interactable obj) { interactable = obj.GetComponent <Interactable>(); //This might break stuff in the future I have no idea :/ for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); float YPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, YPos, 0f) * 125f; newButton.circle.color = obj.options[i].colour; newButton.icon.sprite = obj.options[i].sprite; newButton.title = obj.options[i].title; newButton.func = obj.options[i].func; newButton.menu = this; newButton.Anim(); yield return(new WaitForSeconds(0.06f)); } }
IEnumerator AnimateButtons(Interactable obj) { for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); // Calcul la circonférence du cercle et le divise par le nombre d'option disponible float theta = (2 * Mathf.PI / obj.options.Length) * i; //Calcul la position en x et y float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * 75f; newButton.circle.color = obj.options[i].color; newButton.icon.sprite = obj.options[i].sprite; newButton.title = obj.options[i].title; newButton.myMenu = this; newButton.Anim(); yield return(new WaitForSeconds(0.06f)); } }
// Start is called before the first frame update public void SpawnButtons(Interactable obj) { myInteractable = obj; buttonsList = new RadialButton[obj.options.Count]; for (int i = 0; i < obj.options.Count; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Count) * i; float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * 75; newButton.background.color = obj.options[i].color; newButton.icon.sprite = obj.options[i].icon; newButton.title = obj.options[i].title; newButton.myMenu = this; buttonsList[i] = newButton; //newButton.transform.localPosition = new Vector3(0f, 100f, 0f); } }
IEnumerator AnimateButtons(Interactable obj) { for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); float Ypos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, Ypos, 0f) * 100f; //posicion respecto al centro// newButton.circle.color = obj.options[i].color; newButton.icon.sprite = obj.options[i].sprite; newButton.title = obj.options[i].title; newButton.myMenu = this; //caracterisiticas de las opciones// newButton.Anim(); yield return(new WaitForSeconds(0.06f)); //animacion de salida// } }
void Update() { GameObject flystick = GameObject.Find("Flystick"); RaycastHit hit; if (Physics.Raycast(flystick.transform.position, flystick.transform.forward, out hit, 10)) { if (hit.collider.gameObject.name == "Button(Clone)") { GameObject hitObj = hit.collider.gameObject; RadialButton hitButton = hitObj.GetComponent <RadialButton> (); selected = hitButton; } } else { selected = null; } }
public void SelectTopLevelButton(RadialButton button) { var index = -1; if (button != null) { index = topLevelButtons.IndexOf(button); } for (int i = 0; i < topLevelButtons.Count; i++) { if (i == index) { topLevelButtons[i].TopLevelSelectToggle(true); } else { topLevelButtons[i].TopLevelSelectToggle(false); } } }
/// ************** /// Zis is ze button-spawning method /// ************** public void SpawnButtons(ClickToUpgrade obj) { //ClickToUpgrade is the reference (ie obj refers to ClickToUpgrade) for (int i = 0; i < obj.options.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); //Calculation of angle of rotation (360 degrees / no of buttons) for each button placement float theta = (2 * Mathf.PI / obj.options.Length) * i; float xPos = Mathf.Sin(theta); //oh look jolly more math float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * radius; //set position based on calculations made //Setting button elements as listed in ClickToUpgrade's options newButton.circle.color = obj.options[i].color; newButton.icon.sprite = obj.options[i].iconSprite; newButton.actionName = obj.options[i].actionName; newButton.menu = this; //reference to where and what is ze menu } }
public void ActivateMenu(List <Action> actions) { if (actions != null) { options = actions; } for (int i = 0; i < options.Count; ++i) { RadialButton button = Instantiate(prefab); button.transform.SetParent(transform); //can change to variable number of buttons float theta = (2 * Mathf.PI / 7) * i; float x = Mathf.Sin(-theta - offset); float y = Mathf.Cos(-theta - offset); button.transform.localPosition = new Vector3(x, y, 0f) * menuSize; button.icon.sprite = options[i].image; button.frame.color = options[i].color; button.actionName = options[i].title; button.transform.localRotation = Quaternion.identity; button.menu = this; } }
void PlaceButtons() { if (textTipObj != null) { textTip = textTipObj.GetComponent <TextMeshProUGUI>() ?? textTipObj.AddComponent <TextMeshProUGUI>(); textTipObj.transform.localPosition = new Vector2(0, 0); } else { Debug.Log("Radial menu '" + this.name + "' is missing a text field"); } foreach (Button button in buttons) { if (button == null) { Debug.Log("Cannot place buttons without objects!"); return; } RadialButton buttonScript = button.gameObject.GetComponent <RadialButton>() ?? button.gameObject.AddComponent <RadialButton>(); buttonScript.setMenuParent(this.gameObject); } if (variant == Type.Alpha) { float thetap = theta / 2; for (int i = 0; i < buttons.Length; i++) { buttons[i].transform.localPosition = new Vector2(radius * Mathf.Sin((theta * (i + 1)) - thetap), radius * Mathf.Cos((theta * (i + 1)) - thetap)); } } else { for (int i = 0; i < buttons.Length; i++) { buttons[i].transform.localPosition = new Vector2(radius * Mathf.Sin(theta * i), radius * Mathf.Cos(theta * i)); } } }
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; } }
// Use this for initialization public void SpawnButtons(MenuOpener opener) { tile = opener.gameObject.GetComponent <Tile> (); for (int i = 0; i < opener.options.Length; i++) { RadialButton button = (RadialButton)Instantiate(ButtonPrefab); button.transform.SetParent(transform); float theta = (2 * Mathf.PI / opener.options.Length) * i; float x = Mathf.Sin(theta); float y = Mathf.Cos(theta); Vector3 position = new Vector3(x, y, 0f) * 100; button.transform.localPosition = position; button.Icon.sprite = opener.options [i].icon; button.Title = opener.options [i].title; button.Tower = opener.options [i].tower; button.Circle.color = opener.options [i].color; button.Menu = this; } }
//public void SpawnButton(MaterialChange obj) public void SpawnButton(MenuController obj) { for (int i = 0; i < obj.menus.Length; i++) { RadialButton newButton = Instantiate(buttonPrefab) as RadialButton; newButton.transform.SetParent(transform.GetChild(0)); newButton.transform.localScale = Vector3.one; newButton.transform.localEulerAngles = Rotate; newButtonRect = newButton.gameObject.GetComponent <RectTransform>(); newButtonRect.sizeDelta = new Vector2(buttonSize, buttonSize); newButton.title = obj.menus[i].title; newButton.Event_Button = obj.menus[i].Event_Button; newButton.material = obj.icons[i].icon; newButton.obj = obj; /* Old Version * float theta = (2 * Mathf.PI / obj.materials.Length) * i; * float xPos = Mathf.Sin(theta); * float yPos = Mathf.Cos(theta); * newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * distanceFromCenter; */ float theta = 0; if (autoSpaceButton == true) { theta = (2 * Mathf.PI / obj.menus.Length) * i; } else { theta = (2 * Mathf.PI / numberOfbutton) * i; } float xPos = Mathf.Sin(theta); float yPos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector3(xPos, yPos, 0f) * distanceFromCenter; } }
public void Update(Player player) { _visible = false; if (player.SelectedUnits.Count != 1) { _selectedUnit = null; return; } var selectedUnit = player.SelectedUnits.First(); if (selectedUnit.Owner != player || selectedUnit.IsBeingConstructed() || !selectedUnit.Definition.KindOf.Get(ObjectKinds.Structure) || selectedUnit.Definition.CommandSet == null) { _selectedUnit = null; return; } var playerTemplate = selectedUnit.Owner.Template; _visible = true; var screenPosition = _game.Scene3D.Camera.WorldToScreenPoint(selectedUnit.Collider.WorldBounds.Center); _center = new Point2D((int)screenPosition.X, (int)screenPosition.Y); _commandSet = selectedUnit.Definition.CommandSet.Value; if (_selectedUnit != selectedUnit && _commandSet != null) { //Update button list var heroIndex = 0; var commandButtons = new List <CommandButton>(); foreach (var button in _commandSet.Buttons.Values) { if (button.Value.Command == CommandType.Revive) { if (heroIndex < playerTemplate.BuildableHeroesMP.Count()) { var heroDefinition = playerTemplate.BuildableHeroesMP[heroIndex++]; commandButtons.Add(new CommandButton(CommandType.UnitBuild, heroDefinition)); } } else { commandButtons.Add(button.Value); } } _buttons.Clear(); foreach (var commandButton in commandButtons) { var isHeroButton = commandButton.Object?.Value?.KindOf.Get(ObjectKinds.Hero) ?? false; var radialButton = new RadialButton(_game, selectedUnit, commandButton, isHeroButton); _buttons.Add(radialButton); } _selectedUnit = selectedUnit; } var isProducing = selectedUnit.ProductionUpdate?.IsProducing ?? false; foreach (var radialButton in _buttons) { radialButton.IsVisible = true; if (radialButton.IsRecruitHeroButton) { var definition = radialButton.CommandButton.Object.Value; radialButton.IsVisible = selectedUnit.CanRecruitHero(definition); } var(count, progress) = isProducing ? selectedUnit.ProductionUpdate.GetCountAndProgress(radialButton.CommandButton) : (0, 0.0f); radialButton.Update(progress, count, selectedUnit.CanEnqueue(radialButton.CommandButton)); } }
public void SpawnButtons(List <Rightclick.Menu> Menus, int Menudepth, int StartingAngle) { Initialised = false; CurrentMenuDepth = Menudepth; int Range = 360; //is the range that the buttons will be on in degrees int MinimumAngle = 0; //The initial offset Of the buttons in degrees int MaximumAngle = 360; //Linked to range if (Menudepth > 100) { Range = Menus.Count * (360 / Density [Menudepth]); //Try and keep the icons nicely spaced on the outer rings MinimumAngle = (int)(StartingAngle - ((Range / 2) - (0.5f * (360 / Density [Menudepth])))); MaximumAngle = StartingAngle + Range; if (Range < (SelectionRange [Menudepth - 100] [0] / SelectionRange [Menudepth - 100] [3])) { Range = (int)(SelectionRange [Menudepth - 100] [0] / SelectionRange [Menudepth - 100] [3]); //Try and keep the icons nicely spaced on the outer rings MinimumAngle = (int)(StartingAngle - ((Range / 2) - (0.5f * (Range / Menus.Count)))); MaximumAngle = StartingAngle + Range; } } for (int i = 0; i < Menus.Count; i++) { RadialButton newButton = Instantiate(ButtonPrefab) as RadialButton; newButton.transform.SetParent(transform, false); //Magic maths float theta = (float)(((Range * Mathf.Deg2Rad) / Menus.Count) * i); theta = (theta + (MinimumAngle * Mathf.Deg2Rad)); float xpos = Mathf.Sin(theta); float ypos = Mathf.Cos(theta); newButton.transform.localPosition = new Vector2(xpos, ypos) * Menudepth; newButton.Circle.color = Menus[i].colour; newButton.Icon.sprite = Menus[i].sprite; newButton.Item = Menus [i].Item; newButton.MenuDepth = Menudepth; newButton.Mono = Menus[i].Mono; newButton.Method = Menus[i].Method; newButton.Hiddentitle = Menus[i].title; if (Menus [i].BackgroundSprite != null) { newButton.Circle.sprite = Menus[i].BackgroundSprite; } newButton.MyMenu = this; // Annoying dictionary not containing list when Initialised if (CurrentOptionsDepth.ContainsKey(Menudepth)) { CurrentOptionsDepth[Menudepth].Add(newButton); } else { CurrentOptionsDepth[Menudepth] = new List <RadialButton>(); CurrentOptionsDepth[Menudepth].Add(newButton); } if (DepthMenus.ContainsKey(Menudepth)) { DepthMenus [Menudepth].Add(Menus [i]); } else { DepthMenus [Menudepth] = new List <Rightclick.Menu>(); DepthMenus [Menudepth].Add(Menus [i]); } } //Pushes the parameters to the selection system List <float> QuickList = new List <float> { Range, MinimumAngle, MaximumAngle, Menus.Count }; SelectionRange [Menudepth] = QuickList; Initialised = true; }
void Update() { if (Initialised) { List <RadialButton> CurrentOptions = CurrentOptionsDepth [CurrentMenuDepth]; MousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); toVector2M = new Vector2(Input.mousePosition.x, Input.mousePosition.y); double IndividualItemDegrees = 0; Vector2 Relativecentre = toVector2M - centercirlce; //Logger.Log (Relativecentre.ToString ()+ " Relativecentre" , Category.RightClick); double Angle = (Mathf.Atan2(Relativecentre.y, Relativecentre.x) * Mathf.Rad2Deg); //off sets the Angle because it starts as -180 to 180 Angle += -90; Angle = Angle + SelectionRange[CurrentMenuDepth][1]; if (Angle > 0) { Angle += -360; } Angle = Angle * -1; //Turns it from negative to positive //Logger.Log (Angle.ToString () + " old Angle", Category.RightClick); //Logger.Log (((int)((Angle) / (SelectionRange[CurrentMenuDepth][0] / CurrentOptions.Count))).ToString () + " old MenuItem", Category.RightClick); //Logger.Log (Angle.ToString ()+ " Angle" , Category.RightClick); IndividualItemDegrees = SelectionRange[CurrentMenuDepth][0] / CurrentOptions.Count; Angle = Angle + ((IndividualItemDegrees) / 2); //Offsets by half a menu so So the different selection areas aren't in the middle of the menu if (Angle > 360) //Makes sure it's 360 { Angle += -360; } MenuItem = (int)((Angle) / (IndividualItemDegrees)); //Logger.Log ((IndividualItemDegrees).ToString () + " Density", Category.RightClick); //Logger.Log (Angle.ToString () + " Angle", Category.RightClick); //Logger.Log (SelectionRange[CurrentMenuDepth][0].ToString () + " Range", Category.RightClick); //Logger.Log (SelectionRange[CurrentMenuDepth][1].ToString () + " MinimumAngle", Category.RightClick); //Logger.Log (MenuItem.ToString () + "MenuItem", Category.RightClick); //Logger.Log (CurrentOptions.Count.ToString () + "CurrentOptions.Count", Category.RightClick); if (!(MenuItem > (CurrentOptions.Count - 1)) && !(MenuItem < 0)) //Ensures its in range Of selection { LastInRangeSubMenu = Time.time; Selected = CurrentOptions [MenuItem]; if (!(LastSelected == Selected)) { if (LastSelectedset) { if (LastSelected.MenuDepth == CurrentMenuDepth) { LastSelected.title.text = ""; LastSelected.transform.SetSiblingIndex(LastSelected.DefaultPosition); LastSelected.SetColour(LastSelected.DefaultColour); } else { ResetDepthOnDestroy [CurrentMenuDepth] = LastSelected; } } CurrentOptions [MenuItem].title.text = CurrentOptions [MenuItem].Hiddentitle; CurrentOptions [MenuItem].DefaultColour = CurrentOptions [MenuItem].ReceiveCurrentColour(); CurrentOptions [MenuItem].DefaultPosition = CurrentOptions[MenuItem].transform.GetSiblingIndex(); CurrentOptions [MenuItem].SetColour(CurrentOptions [MenuItem].DefaultColour + (Color.white / 3f)); CurrentOptions [MenuItem].transform.SetAsLastSibling(); LastSelected = CurrentOptions [MenuItem]; LastSelectedset = true; LastSelectedTime = Time.time; //Logger.Log (LastSelectedTime.ToString (), Category.RightClick); } if (LastSelectedset) { if ((Time.time - LastSelectedTime) > 0.4f) //How long it takes to make a menu { if ((!(DepthMenus [CurrentMenuDepth] [MenuItem].SubMenus == null)) && DepthMenus [CurrentMenuDepth] [MenuItem].SubMenus.Count > 0) { Logger.Log(MenuItem.ToString() + " Selected", Category.RightClick); int NewMenuDepth = CurrentMenuDepth; LastSelectedTime = Time.time; NewMenuDepth = NewMenuDepth + 100; int InitialAngle = MenuItem * (360 / CurrentOptions.Count); SpawnButtons(DepthMenus [CurrentMenuDepth] [MenuItem].SubMenus, NewMenuDepth, InitialAngle); } } } } else { if ((Time.time - LastInRangeSubMenu) > 0.3f && (CurrentMenuDepth > 100)) //How long it takes to exit a menu //Logger.Log ("yo am Destroying", Category.UI); { if (ResetDepthOnDestroy.ContainsKey(CurrentMenuDepth)) { ResetDepthOnDestroy [CurrentMenuDepth].title.text = ""; ResetDepthOnDestroy [CurrentMenuDepth].transform.SetSiblingIndex(ResetDepthOnDestroy [CurrentMenuDepth].DefaultPosition); ResetDepthOnDestroy [CurrentMenuDepth].SetColour(ResetDepthOnDestroy [CurrentMenuDepth].DefaultColour); } else { LastSelected.transform.SetSiblingIndex(LastSelected.DefaultPosition); LastSelected.SetColour(LastSelected.DefaultColour); LastSelected.title.text = ""; LastSelected = null; LastSelectedset = false; } List <RadialButton> Acopy = CurrentOptions; for (int i = 0; i < Acopy.Count; i++) { Destroy(CurrentOptions[i].gameObject); } //Cleans up the dictionarys SelectionRange.Remove(CurrentMenuDepth); CurrentOptionsDepth.Remove(CurrentMenuDepth); DepthMenus.Remove(CurrentMenuDepth); ResetDepthOnDestroy.Remove(CurrentMenuDepth); CurrentMenuDepth = CurrentMenuDepth - 100; LastSelectedset = false; } } } if (Input.GetMouseButtonUp(1)) { if (Selected) { if (!(Selected.Mono == null)) { //The magic function Selected.Method.Invoke(Selected.Mono, new object[] { }); } //Logger.Log ("yo this "+Selected.title.text , Category.RightClick); } LastSelectedset = false; Destroy(gameObject); } }
// Update is called once per frame void Update() { Vector3 mousePos = Input.mousePosition; if (currentInputMode == inputModes.TILESELECT || currentInputMode == inputModes.ACTIONTARGET) { if (mousePos.x > 0 && mousePos.y > 0 && mousePos.x < Screen.width && mousePos.y < Screen.height) { if (mousePos.x < Screen.width * 0.05) { transform.Translate(-0.1f, 0, 0); } else if (mousePos.x > Screen.width * 0.95) { transform.Translate(0.1f, 0, 0); } if (mousePos.y < Screen.height * 0.05) { transform.Translate(0, -0.1f, 0); } else if (mousePos.y > Screen.height * 0.95) { transform.Translate(0, 0.1f, 0); } } } if (!(currentInputMode == inputModes.TEXTENTRY)) { Vector2 mouseScroll = Input.mouseScrollDelta; transform.Translate(0, 0, mouseScroll.y); mousePos.Set(mousePos.x, mousePos.y, 1); mousePos = GetComponent <Camera>().ScreenToWorldPoint(mousePos); Vector3 mouseTouchPoint = mousePos; mouseTouchPoint = transform.position - mouseTouchPoint; mouseTouchPoint.Normalize(); RaycastHit hit; if (Physics.Raycast(transform.position, mouseTouchPoint * -1, out hit, 50)) { GameObject currentlySelected = hit.collider.gameObject; Tile newSelectedTile = currentlySelected.GetComponent <Tile>(); if (newSelectedTile == null) { selectedTile = null; tileInfoTab.gameObject.SetActive(false); selectedButton = currentlySelected.GetComponent <RadialButton>(); } else { if (newSelectedTile == selectedTile) { hoverCount++; if (hoverCount > 45) { tileInfoTab.transform.position = mousePos; tileInfoTab.transform.Find("TileStats").GetComponent <Text>().text = "Wealth: " + selectedTile.wealth + "\n" + "Food: " + selectedTile.food;; tileInfoTab.gameObject.SetActive(true); } } else { selectedTile = newSelectedTile; tileInfoTab.gameObject.SetActive(false); hoverCount = 0; } } //If the currently selected mesh is hit again, don't update the texture if (currentlySelected != previouslySelected) { //Add on a highlight to the selected tile to show it got hit /*Material[] newMaterials = new Material[2]; * newMaterials[0] = currentMesh.material; * newMaterials[1] = (Material)Resources.Load("Models/Materials/Highlight"); * currentMesh.materials = newMaterials; * newMaterials = new Material[1]; * newMaterials[0] = previousMesh.materials[0]; * previousMesh.materials = newMaterials; */ previouslySelected = currentlySelected; } } if (Input.GetMouseButtonDown(0)) { if (currentInputMode == inputModes.TILESELECT) { if (selectedTile != null && openMenu != null) { Destroy(openMenu.gameObject); selectedButton = null; } else if (selectedTile == null && selectedButton != null) { selectedButton.onClick(); } else { startTile = selectedTile; startTile.onMouseButtonDown(); } } else if (currentInputMode == inputModes.ACTIONTARGET) { if (selectedTile != null && onActionTarget != null) { onActionTarget(selectedTile); } } else if (currentInputMode == inputModes.INMENU) { if (Input.mousePosition.x < Screen.width / 2) { Destroy(GameObject.Find("CityMenu")); changeMode(inputModes.TILESELECT); } } } if (Input.GetMouseButtonUp(0)) { } if (Input.GetKeyDown("s")) { GameObject InputPanel = Instantiate((GameObject)Resources.Load("Prefabs/InputPanel")); InputPanel.name = "InputPanel"; InputPanel.transform.SetParent(GameObject.Find("MapHUD").transform, false); TextInput.stringFunction saveCallback = new TextInput.stringFunction(BoardManager.Instance.saveBoardState); InputPanel.GetComponent <TextInput>().setCallback(saveCallback); changeMode(inputModes.TEXTENTRY); } else if (Input.GetKeyDown("l")) { GameObject fileSelect = Instantiate((GameObject)Resources.Load("Prefabs/FileSelect")); fileSelect.name = "FileSelect"; fileSelect.transform.SetParent(GameObject.Find("Canvas").transform, false); FileSelect.fileSubmit submitCallback = new FileSelect.fileSubmit(BoardManager.Instance.loadBoardState); fileSelect.GetComponent <FileSelect>().setFileSelectFunction(submitCallback); fileSelect.GetComponent <FileSelect>().loadDirectoryOptions(System.IO.Directory.GetCurrentDirectory()); changeMode(inputModes.TEXTENTRY); } if (Input.GetKeyDown("-")) { } else if (Input.GetKeyDown("+")) { } } }
private void Start() { RadialButton newButton = Instantiate(buttonPrefab, transform); }