public void Add(Interact3dItem item) { EnsureUi(item); if (!items.Contains(item)) { items.Add(item); } UpdateItems(); }
private void OnTriggerExit(Collider other) { Interact3dItem item = other.GetComponentInChildren <Interact3dItem>(); if (item && !item.internalState.alwaysOn) { ui.Remove(item); } }
private void OnTriggerEnter(Collider other) { Interact3dItem item = other.GetComponentInChildren <Interact3dItem>(); if (item) { ui.Add(item); } }
public void EnsureUi(Interact3dItem item) { if (item.screenUi == null) { item.screenUi = Instantiate(prefab_interactButton).GetComponent <RectTransform>(); item.screenUi.SetParent(uiArea); item.screenUi.transform.localScale = prefab_interactButton.transform.localScale * item.internalState.size; item.fontSize = item.fontSize * item.internalState.fontCoefficient; item.onInteractVisible?.Invoke(); } }
public void UpdateItems() { for (int i = 0; i < items.Count; ++i) { Interact3dItem item = items[i]; if (item == null) { items.RemoveAt(i--); continue; } if (!UpdateItem(item)) { --i; } } }
public void Remove(Interact3dItem item) { if (item.internalState.alwaysOn) { return; } if (item.screenUi != null) { Destroy(item.screenUi.gameObject); } if (items.Remove(item)) { item.onInteractHidden?.Invoke(); } UpdateItems(); }
public bool UpdateItem(Interact3dItem item) { if (item.screenUi == null) { Remove(item); Add(item); return(false); } if (item.showing) { item.screenUi.gameObject.SetActive(true); Vector3 screenP = cam.WorldToScreenPoint(item.transform.position + item.internalState.worldOffset); item.screenUi.position = screenP; } else { item.screenUi.gameObject.SetActive(false); } return(true); }