private void AddActionPointButton(Base.ActionPoint actionPoint) { ActionButton btn = Instantiate(Base.GameManager.Instance.ButtonPrefab, ActionPointsList.transform).GetComponent <ActionButton>(); btn.transform.localScale = new Vector3(1, 1, 1); btn.SetLabel(actionPoint.Data.Name); btn.Button.onClick.AddListener(() => ShowActionPoint(actionPoint)); btn.ObjectId = actionPoint.Data.Id; // Add EventTrigger OnPointerEnter and OnPointerExit - to be able to highlight corresponding AP when hovering over button OutlineOnClick APoutline = actionPoint.GetComponent <OutlineOnClick>(); EventTrigger eventTrigger = btn.gameObject.AddComponent <EventTrigger>(); // Create OnPointerEnter entry EventTrigger.Entry OnPointerEnter = new EventTrigger.Entry { eventID = EventTriggerType.PointerEnter }; OnPointerEnter.callback.AddListener((eventData) => APoutline.Highlight()); eventTrigger.triggers.Add(OnPointerEnter); // Create OnPointerExit entry EventTrigger.Entry OnPointerExit = new EventTrigger.Entry { eventID = EventTriggerType.PointerExit }; OnPointerExit.callback.AddListener((eventData) => APoutline.UnHighlight()); eventTrigger.triggers.Add(OnPointerExit); }
public async void UpdateMenu() { scrollableContent.GetComponent <VerticalLayoutGroup>().enabled = true; Base.ActionPoint actionPoint; if (CurrentActionPoint == null) { return; } else { actionPoint = CurrentActionPoint.GetComponent <Base.ActionPoint>(); } foreach (RectTransform o in dynamicContent.GetComponentsInChildren <RectTransform>()) { if (o.gameObject.tag != "Persistent") { Destroy(o.gameObject); } } SetHeader(actionPoint.Data.Name); if (actionPoint.Parent != null) { ActionObjectType.text = actionPoint.Parent.GetName(); } else { ActionObjectType.text = "Global action point"; } Dictionary <IActionProvider, List <Base.ActionMetadata> > actionsMetadata; if (actionPoint.Parent == null) { actionsMetadata = Base.ActionsManager.Instance.GetAllFreeActions(); } else { Base.ActionObject parentActionObject = actionPoint.Parent.GetActionObject(); if (parentActionObject == null) { actionsMetadata = Base.ActionsManager.Instance.GetAllFreeActions(); } else { actionsMetadata = Base.ActionsManager.Instance.GetAllActionsOfObject(parentActionObject); } } foreach (KeyValuePair <IActionProvider, List <Base.ActionMetadata> > keyval in actionsMetadata) { CollapsableMenu collapsableMenu = Instantiate(CollapsablePrefab, dynamicContent.transform).GetComponent <CollapsableMenu>(); collapsableMenu.SetLabel(keyval.Key.GetProviderName()); collapsableMenu.Collapsed = true; foreach (Base.ActionMetadata am in keyval.Value) { ActionButton btn = Instantiate(Base.GameManager.Instance.ButtonPrefab, collapsableMenu.Content.transform).GetComponent <ActionButton>(); btn.transform.localScale = new Vector3(1, 1, 1); btn.SetLabel(am.Name); if (am.Disabled) { CreateTooltip(am.Problem, btn); btn.Button.interactable = false; } else if (!string.IsNullOrEmpty(am.Description)) { CreateTooltip(am.Description, btn); } btn.Button.onClick.AddListener(() => ShowAddNewActionDialog(am.Name, keyval.Key)); } } UpdateLockedBtns(CurrentActionPoint.Locked); if (CurrentActionPoint.Parent == null) { UntieBtn.onClick.RemoveAllListeners(); UntieBtn.onClick.AddListener(() => AssignToParent()); UntieBtnTooltip.ShowAlternativeDescription(); } else { UntieBtn.onClick.RemoveAllListeners(); UntieBtn.onClick.AddListener(() => ShowUntieActionPointDialog()); UntieBtnTooltip.ShowDefaultDescription(); } RemoveBtn.SetInteractivity(await GameManager.Instance.RemoveActionPoint(CurrentActionPoint.Data.Id, true)); ExpandBtn.gameObject.SetActive(CurrentActionPoint.ActionsCollapsed); CollapseBtn.gameObject.SetActive(!CurrentActionPoint.ActionsCollapsed); }