ITargetController - jimdroberts/FishMMO GitHub Wiki
ITargetController is an interface for FishMMO that defines the contract for a character's target controller, handling targeting logic and related events. It provides events for target changes, updates, and clearing, as well as methods and properties for managing and updating the current target.
-
TargetInfo Current { get; }
The current target information.
-
TargetInfo UpdateTarget(Vector3 origin, Vector3 direction, float maxDistance)
Updates the target based on the given origin, direction, and max distance. Parameters: - Vector3 origin: The origin point for target detection. - Vector3 direction: The direction to check for a target. - float maxDistance: The maximum distance to check for a target. Returns: TargetInfo. The updated target information. No exceptions are thrown.
-
event Action OnChangeTarget
Event triggered when the target changes.
-
event Action OnUpdateTarget
Event triggered when the target is updated.
-
event Action OnClearTarget
Event triggered when the target is cleared.
- Implement the ITargetController interface in your character controller class.
- Provide logic for handling target changes, updates, and clearing.
- Use the UpdateTarget method to update the current target based on player input or game logic.
// Example 1: Implementing ITargetController in a custom controller
public class MyTargetController : MonoBehaviour, ITargetController
{
public event Action<Transform> OnChangeTarget;
public event Action<Transform> OnUpdateTarget;
public event Action<Transform> OnClearTarget;
public TargetInfo Current { get; private set; }
public TargetInfo UpdateTarget(Vector3 origin, Vector3 direction, float maxDistance)
{
// Custom targeting logic
return Current;
}
}
// Example 2: Subscribing to target events
myTargetController.OnChangeTarget += (target) => { Debug.Log($"Target changed: {target}"); };
- Always implement all events and methods defined by the interface for consistent behavior.
- Use the Current property to access the latest target information.
- Trigger events appropriately to notify other systems of target changes.
- Document the intended targeting logic and event usage for maintainability.