public override void FixedSimulate(bool selected) { var pc = player; // If this player is no longer selected, automatically deselect if (!selected) { if (focus) { focus.Deselect(pc); focus = null; } return; } IReadOnlyCollection <Interactive> list; Interactive act = null; float actDist = float.MaxValue; float temp; // Instead of doing collision-based checks based on their layer. // We do the collison checks based on class. foreach (var type in interactTargets.Keys) { if (interactTargets[type] != 0) { continue; } list = GlobalTypeList <Interactive> .GetTypeList(type); if (list == null) { continue; } foreach (var entity in list) { if (entity.IsPlayerInteractable && entity.Bounds.Intersect(interactiveBounds, out temp)) { if (temp < actDist) { act = entity; actDist = temp; } } } } // Deselect if we found a new focus if (focus != null && focus != act) { focus.Deselect(pc); } focus = act; // Select if (focus != null) { focus.Select(pc); } // Control UI ControlUI.Instance.ControlReset(); }
private void FixedUpdate() { if (disabled) { return; } IWeight act = null; float actDist = float.MaxValue; float temp; // Check collisions foreach (Item item in GlobalTypeList <Interactive> .GetTypeList(typeof(Item))) { if (item.Bounds.Intersect(CylinderBounds, out temp)) { if (temp < actDist) { act = item; actDist = temp; } } } // Items have priority if (act == null) { foreach (var player in GlobalList <PlayerController> .GetList) { if (player.interactiveBounds.Intersect(CylinderBounds, out temp)) { if (temp < actDist) { act = player; actDist = temp; } } } } if (focus != null && focus != act) { focus.Exit(this); } focus = act; if (focus != null) { focus.Enter(this); } var statusEvent = focus != null; if (statusEvent ^ selected) { selected = statusEvent; if (bevent) { bevent.Interact(null, this); } } }