This component implements a selector that allows the player to target and use a usable object. More...
Classes | |
class | Reticle |
This class defines the textures and size of the targeting reticle. More... | |
Public Types | |
enum | SelectAt { CenterOfScreen , MousePosition , CustomPosition } |
Specifies how to target: center of screen or under the mouse cursor. More... | |
enum | DistanceFrom { Camera , GameObject , ActorTransform } |
Specifies whether to compute range from the targeted object (distance to the camera or distance to the selector's game object). More... | |
enum | Dimension { In2D , In3D } |
Specifies whether to do 2D or 3D raycasts. More... | |
Public Member Functions | |
virtual void | Start () |
virtual void | UseCurrentSelection () |
Calls OnUse on the current selection. | |
virtual void | SetCurrentUsable (Usable usable) |
virtual void | OnGUI () |
If useDefaultGUI is true and a usable object has been targeted, this method draws a selection message and targeting reticle. | |
virtual void | OnDrawGizmos () |
Draws raycast result gizmos. | |
Public Attributes | |
SelectAt | selectAt = SelectAt.CenterOfScreen |
How to target (center of screen or under mouse cursor). | |
LayerMask | layerMask = DefaultLayer |
The layer mask to use when targeting objects. | |
DistanceFrom | distanceFrom = DistanceFrom.Camera |
How to compute range to targeted object. | |
float | maxSelectionDistance = 30f |
The max selection distance. | |
Dimension | runRaycasts = Dimension.In3D |
Specifies whether to run 2D or 3D raycasts. | |
bool | raycastAll = false |
Set true to check all objects within the raycast range for usables. | |
bool | useDefaultGUI = true |
If true , uses a default OnGUI to display a selection message and targeting reticle. | |
GUISkin | guiSkin |
The GUI skin to use for the target's information (name and use message). | |
string | guiStyleName = "label" |
The name of the GUI style in the skin. | |
TextAnchor | alignment = TextAnchor.UpperCenter |
The text alignment. | |
TextStyle | textStyle = TextStyle.Shadow |
The text style for the text. | |
Color | textStyleColor = Color.black |
The color of the text style's outline or shadow. | |
Color | inRangeColor = Color.yellow |
The color of the information labels when the target is in range. | |
Color | outOfRangeColor = Color.gray |
The color of the information labels when the target is out of range. | |
Reticle | reticle |
The reticle images. | |
KeyCode | useKey = KeyCode.Space |
The key that sends an OnUse message. | |
string | useButton = "Fire2" |
The button that sends an OnUse message. | |
string | defaultUseMessage = "(spacebar to interact)" |
The default use message. | |
bool | broadcastToChildren = true |
If ticked, the OnUse message is broadcast to the usable object's children. | |
Transform | actorTransform = null |
The actor transform to send with OnUse. | |
string | tooFarMessage = string.Empty |
If set, show this alert message if attempt to use something beyond its usable range. | |
UsableUnityEvent | onSelectedUsable = new UsableUnityEvent() |
UsableUnityEvent | onDeselectedUsable = new UsableUnityEvent() |
UnityEvent | tooFarEvent = new UnityEvent() |
The too far event handler. | |
bool | debug = false |
If true , draws gizmos. | |
Protected Member Functions | |
virtual void | Reset () |
virtual void | OnEnable () |
virtual void | OnDisable () |
virtual void | Update () |
Runs a raycast to see what's under the selection point. | |
virtual void | Run2DRaycast () |
virtual void | Run3DRaycast () |
void | OnSelectedUsableObject (Usable usable) |
void | OnDeselectedUsableObject (Usable usable) |
virtual void | DeselectTarget () |
virtual void | OnUsableDisabled (Usable usable) |
virtual bool | IsUseButtonDown () |
virtual bool | IsUsingDefaultInputManager () |
virtual Vector3 | GetSelectionPoint () |
void | SetGuiStyle () |
Protected Attributes | |
GameObject | selection = null |
Usable | usable = null |
GameObject | clickedDownOn = null |
string | heading = string.Empty |
string | useMessage = string.Empty |
float | distance = 0 |
GUIStyle | guiStyle = null |
float | guiStyleLineHeight = 16f |
Ray | lastRay = new Ray() |
RaycastHit | lastHit = new RaycastHit() |
RaycastHit[] | lastHits = null |
int | numLastHits = 0 |
RaycastHit2D[] | lastHits2D = null |
bool | hasReportedInvalidCamera = false |
bool | hasCheckedDefaultInputManager = false |
bool | isUsingDefaultInputManager = true |
Static Protected Attributes | |
const int | MaxHits = 100 |
Properties | |
Vector3 | CustomPosition [get, set] |
Gets or sets the custom position used when the selectAt is set to SelectAt.CustomPosition. | |
Usable | CurrentUsable [get, set] |
Gets the current selection. | |
float | CurrentDistance [get] |
Gets the distance from the current usable. | |
GUIStyle | GuiStyle [get] |
Gets the GUI style. | |
UnityEngine.EventSystems.EventSystem | eventSystem [get, set] |
Properties inherited from PixelCrushers.IEventSystemUser |
Events | |
SelectedUsableObjectDelegate | SelectedUsableObject = null |
Occurs when the selector has targeted a usable object. | |
DeselectedUsableObjectDelegate | DeselectedUsableObject = null |
Occurs when the selector has untargeted a usable object. | |
System.Action | Enabled = null |
System.Action | Disabled = null |
This component implements a selector that allows the player to target and use a usable object.
To mark an object usable, add the Usable component and a collider to it. The object's layer should be in the layer mask specified on the Selector component.
The selector can be configured to target items under the mouse cursor or the middle of the screen. When a usable object is targeted, the selector displays a targeting reticle and information about the object. If the target is in range, the inRange reticle texture is displayed; otherwise the outOfRange texture is displayed.
If the player presses the use button (which defaults to spacebar and Fire2), the targeted object will receive an "OnUse" message.
You can hook into SelectedUsableObject and DeselectedUsableObject to get notifications when the current target has changed and Enabled and Disabled when the component is enabled or disabled.
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
inlineprotected |
|
inlineprotectedvirtual |
|
inlinevirtual |
Draws raycast result gizmos.
|
inlineprotectedvirtual |
|
inlinevirtual |
If useDefaultGUI is true
and a usable object has been targeted, this method draws a selection message and targeting reticle.
|
inlineprotected |
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
|
inlinevirtual |
|
inlineprotected |
|
inlinevirtual |
|
inlineprotectedvirtual |
Runs a raycast to see what's under the selection point.
Updates the selection and calls the selection delegates if the selection has changed. If the player hits the use button, sends an OnUse message to the selection.
|
inlinevirtual |
Calls OnUse on the current selection.
Transform PixelCrushers.DialogueSystem.Selector.actorTransform = null |
The actor transform to send with OnUse.
Defaults to this transform.
TextAnchor PixelCrushers.DialogueSystem.Selector.alignment = TextAnchor.UpperCenter |
The text alignment.
bool PixelCrushers.DialogueSystem.Selector.broadcastToChildren = true |
If ticked, the OnUse message is broadcast to the usable object's children.
|
protected |
bool PixelCrushers.DialogueSystem.Selector.debug = false |
If true
, draws gizmos.
string PixelCrushers.DialogueSystem.Selector.defaultUseMessage = "(spacebar to interact)" |
The default use message.
This can be overridden in the target's Usable component.
|
protected |
DistanceFrom PixelCrushers.DialogueSystem.Selector.distanceFrom = DistanceFrom.Camera |
How to compute range to targeted object.
Default is from the camera.
GUISkin PixelCrushers.DialogueSystem.Selector.guiSkin |
The GUI skin to use for the target's information (name and use message).
|
protected |
|
protected |
string PixelCrushers.DialogueSystem.Selector.guiStyleName = "label" |
The name of the GUI style in the skin.
|
protected |
|
protected |
|
protected |
Color PixelCrushers.DialogueSystem.Selector.inRangeColor = Color.yellow |
The color of the information labels when the target is in range.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
LayerMask PixelCrushers.DialogueSystem.Selector.layerMask = DefaultLayer |
The layer mask to use when targeting objects.
Objects on others layers are ignored.
|
staticprotected |
float PixelCrushers.DialogueSystem.Selector.maxSelectionDistance = 30f |
The max selection distance.
The selector won't target objects farther than this.
|
protected |
UsableUnityEvent PixelCrushers.DialogueSystem.Selector.onDeselectedUsable = new UsableUnityEvent() |
UsableUnityEvent PixelCrushers.DialogueSystem.Selector.onSelectedUsable = new UsableUnityEvent() |
Color PixelCrushers.DialogueSystem.Selector.outOfRangeColor = Color.gray |
The color of the information labels when the target is out of range.
bool PixelCrushers.DialogueSystem.Selector.raycastAll = false |
Set true
to check all objects within the raycast range for usables.
If false
, the check stops on the first hit, even if it's not a usable. This prevents selection through walls.
Reticle PixelCrushers.DialogueSystem.Selector.reticle |
The reticle images.
Dimension PixelCrushers.DialogueSystem.Selector.runRaycasts = Dimension.In3D |
Specifies whether to run 2D or 3D raycasts.
SelectAt PixelCrushers.DialogueSystem.Selector.selectAt = SelectAt.CenterOfScreen |
How to target (center of screen or under mouse cursor).
Default is center of screen.
|
protected |
TextStyle PixelCrushers.DialogueSystem.Selector.textStyle = TextStyle.Shadow |
The text style for the text.
Color PixelCrushers.DialogueSystem.Selector.textStyleColor = Color.black |
The color of the text style's outline or shadow.
UnityEvent PixelCrushers.DialogueSystem.Selector.tooFarEvent = new UnityEvent() |
The too far event handler.
string PixelCrushers.DialogueSystem.Selector.tooFarMessage = string.Empty |
If set, show this alert message if attempt to use something beyond its usable range.
|
protected |
string PixelCrushers.DialogueSystem.Selector.useButton = "Fire2" |
The button that sends an OnUse message.
bool PixelCrushers.DialogueSystem.Selector.useDefaultGUI = true |
If true
, uses a default OnGUI to display a selection message and targeting reticle.
KeyCode PixelCrushers.DialogueSystem.Selector.useKey = KeyCode.Space |
The key that sends an OnUse message.
|
protected |
|
get |
Gets the distance from the current usable.
The current distance.
|
getset |
Gets the current selection.
The selection.
|
getset |
Gets or sets the custom position used when the selectAt is set to SelectAt.CustomPosition.
You can use, for example, to slide around a targeting icon onscreen using a gamepad.
The custom position.
|
getset |
Implements PixelCrushers.IEventSystemUser.
|
get |
Gets the GUI style.
The GUI style.
DeselectedUsableObjectDelegate PixelCrushers.DialogueSystem.Selector.DeselectedUsableObject = null |
Occurs when the selector has untargeted a usable object.
System.Action PixelCrushers.DialogueSystem.Selector.Disabled = null |
System.Action PixelCrushers.DialogueSystem.Selector.Enabled = null |
SelectedUsableObjectDelegate PixelCrushers.DialogueSystem.Selector.SelectedUsableObject = null |
Occurs when the selector has targeted a usable object.