PixelCrushers.DialogueSystem.Selector Class Reference

This component implements a selector that allows the player to target and use a usable object. More...

Inheritance diagram for PixelCrushers.DialogueSystem.Selector:
Collaboration diagram for PixelCrushers.DialogueSystem.Selector:

Classes

class  Reticle
 This class defines the textures and size of the targeting reticle. More...
 

Public Types

enum  SelectAt { SelectAt.CenterOfScreen, SelectAt.MousePosition, SelectAt.CustomPosition }
 Specifies how to target: center of screen or under the mouse cursor. More...
 
enum  DistanceFrom { DistanceFrom.Camera, DistanceFrom.GameObject }
 Specifies whether to compute range from the targeted object (distance to the camera or distance to the selector's game object). More...
 
enum  Dimension { Dimension.In2D, Dimension.In3D }
 Specifies whether to do 2D or 3D raycasts. More...
 

Public Member Functions

virtual void Start ()
 
void UseCurrentSelection ()
 
virtual void OnGUI ()
 If useDefaultGUI is true and a usable object has been targeted, this method draws a selection message and targeting reticle. More...
 
virtual void OnDrawGizmos ()
 Draws raycast result gizmos. More...
 

Public Attributes

LayerMask layerMask = DefaultLayer
 The layer mask to use when targeting objects. More...
 
SelectAt selectAt = SelectAt.CenterOfScreen
 How to target (center of screen or under mouse cursor). More...
 
DistanceFrom distanceFrom = DistanceFrom.Camera
 How to compute range to targeted object. More...
 
float maxSelectionDistance = 30f
 The max selection distance. More...
 
Dimension runRaycasts = Dimension.In3D
 Specifies whether to run 2D or 3D raycasts. More...
 
bool raycastAll = false
 Set true to check all objects within the raycast range for usables. More...
 
bool useDefaultGUI = true
 If true, uses a default OnGUI to display a selection message and targeting reticle. More...
 
GUISkin guiSkin
 The GUI skin to use for the target's information (name and use message). More...
 
string guiStyleName = "label"
 The name of the GUI style in the skin. More...
 
TextAnchor alignment = TextAnchor.UpperCenter
 The text alignment. More...
 
TextStyle textStyle = TextStyle.Shadow
 The text style for the text. More...
 
Color textStyleColor = Color.black
 The color of the text style's outline or shadow. More...
 
Color inRangeColor = Color.yellow
 The color of the information labels when the target is in range. More...
 
Color outOfRangeColor = Color.gray
 The color of the information labels when the target is out of range. More...
 
Reticle reticle
 The reticle images. More...
 
KeyCode useKey = KeyCode.Space
 The key that sends an OnUse message. More...
 
string useButton = "Fire2"
 The button that sends an OnUse message. More...
 
string defaultUseMessage = "(spacebar to interact)"
 The default use message. More...
 
bool broadcastToChildren = true
 If ticked, the OnUse message is broadcast to the usable object's children. More...
 
Transform actorTransform = null
 The actor transform to send with OnUse. More...
 
string tooFarMessage = string.Empty
 If set, show this alert message if attempt to use something beyond its usable range. More...
 
UsableUnityEvent onSelectedUsable = new UsableUnityEvent()
 
UsableUnityEvent onDeselectedUsable = new UsableUnityEvent()
 
UnityEvent tooFarEvent = new UnityEvent()
 The too far event handler. More...
 
bool debug = false
 If true, draws gizmos. More...
 

Protected Member Functions

virtual void Update ()
 Runs a raycast to see what's under the selection point. More...
 
virtual void Run2DRaycast ()
 
virtual void Run3DRaycast ()
 
void OnSelectedUsableObject (Usable usable)
 
virtual void DeselectTarget ()
 
virtual bool IsUseButtonDown ()
 
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
 
Ray lastRay = new Ray()
 
RaycastHit lastHit = new RaycastHit()
 
RaycastHit[] lastHits = new RaycastHit[0]
 

Properties

Vector3 CustomPosition [get, set]
 Gets or sets the custom position used when the selectAt is set to SelectAt.CustomPosition. More...
 
Usable CurrentUsable [get]
 Gets the current selection. More...
 
float CurrentDistance [get]
 Gets the distance from the current usable. More...
 
GUIStyle GuiStyle [get]
 Gets the GUI style. More...
 

Events

SelectedUsableObjectDelegate SelectedUsableObject = delegate { }
 Occurs when the selector has targeted a usable object. More...
 
DeselectedUsableObjectDelegate DeselectedUsableObject = delegate { }
 Occurs when the selector has untargeted a usable object. More...
 

Detailed Description

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.

Member Enumeration Documentation

◆ Dimension

Specifies whether to do 2D or 3D raycasts.

Enumerator
In2D 
In3D 

◆ DistanceFrom

Specifies whether to compute range from the targeted object (distance to the camera or distance to the selector's game object).

Enumerator
Camera 
GameObject 

◆ SelectAt

Specifies how to target: center of screen or under the mouse cursor.

Enumerator
CenterOfScreen 
MousePosition 
CustomPosition 

Member Function Documentation

◆ DeselectTarget()

virtual void PixelCrushers.DialogueSystem.Selector.DeselectTarget ( )
protectedvirtual

◆ GetSelectionPoint()

virtual Vector3 PixelCrushers.DialogueSystem.Selector.GetSelectionPoint ( )
protectedvirtual

◆ IsUseButtonDown()

virtual bool PixelCrushers.DialogueSystem.Selector.IsUseButtonDown ( )
protectedvirtual

◆ OnDrawGizmos()

virtual void PixelCrushers.DialogueSystem.Selector.OnDrawGizmos ( )
virtual

Draws raycast result gizmos.

◆ OnGUI()

virtual void PixelCrushers.DialogueSystem.Selector.OnGUI ( )
virtual

If useDefaultGUI is true and a usable object has been targeted, this method draws a selection message and targeting reticle.

◆ OnSelectedUsableObject()

void PixelCrushers.DialogueSystem.Selector.OnSelectedUsableObject ( Usable  usable)
protected

◆ Run2DRaycast()

virtual void PixelCrushers.DialogueSystem.Selector.Run2DRaycast ( )
protectedvirtual

◆ Run3DRaycast()

virtual void PixelCrushers.DialogueSystem.Selector.Run3DRaycast ( )
protectedvirtual

◆ SetGuiStyle()

void PixelCrushers.DialogueSystem.Selector.SetGuiStyle ( )
protected

◆ Start()

virtual void PixelCrushers.DialogueSystem.Selector.Start ( )
virtual

◆ Update()

virtual void PixelCrushers.DialogueSystem.Selector.Update ( )
protectedvirtual

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.

◆ UseCurrentSelection()

void PixelCrushers.DialogueSystem.Selector.UseCurrentSelection ( )

Member Data Documentation

◆ actorTransform

Transform PixelCrushers.DialogueSystem.Selector.actorTransform = null

The actor transform to send with OnUse.

Defaults to this transform.

◆ alignment

TextAnchor PixelCrushers.DialogueSystem.Selector.alignment = TextAnchor.UpperCenter

The text alignment.

◆ broadcastToChildren

bool PixelCrushers.DialogueSystem.Selector.broadcastToChildren = true

If ticked, the OnUse message is broadcast to the usable object's children.

◆ clickedDownOn

GameObject PixelCrushers.DialogueSystem.Selector.clickedDownOn = null
protected

◆ debug

bool PixelCrushers.DialogueSystem.Selector.debug = false

If true, draws gizmos.

◆ defaultUseMessage

string PixelCrushers.DialogueSystem.Selector.defaultUseMessage = "(spacebar to interact)"

The default use message.

This can be overridden in the target's Usable component.

◆ distance

float PixelCrushers.DialogueSystem.Selector.distance = 0
protected

◆ distanceFrom

DistanceFrom PixelCrushers.DialogueSystem.Selector.distanceFrom = DistanceFrom.Camera

How to compute range to targeted object.

Default is from the camera.

◆ guiSkin

GUISkin PixelCrushers.DialogueSystem.Selector.guiSkin

The GUI skin to use for the target's information (name and use message).

◆ guiStyle

GUIStyle PixelCrushers.DialogueSystem.Selector.guiStyle = null
protected

◆ guiStyleName

string PixelCrushers.DialogueSystem.Selector.guiStyleName = "label"

The name of the GUI style in the skin.

◆ heading

string PixelCrushers.DialogueSystem.Selector.heading = string.Empty
protected

◆ inRangeColor

Color PixelCrushers.DialogueSystem.Selector.inRangeColor = Color.yellow

The color of the information labels when the target is in range.

◆ lastHit

RaycastHit PixelCrushers.DialogueSystem.Selector.lastHit = new RaycastHit()
protected

◆ lastHits

RaycastHit [] PixelCrushers.DialogueSystem.Selector.lastHits = new RaycastHit[0]
protected

◆ lastRay

Ray PixelCrushers.DialogueSystem.Selector.lastRay = new Ray()
protected

◆ layerMask

LayerMask PixelCrushers.DialogueSystem.Selector.layerMask = DefaultLayer

The layer mask to use when targeting objects.

Objects on others layers are ignored.

◆ maxSelectionDistance

float PixelCrushers.DialogueSystem.Selector.maxSelectionDistance = 30f

The max selection distance.

The selector won't target objects farther than this.

◆ onDeselectedUsable

UsableUnityEvent PixelCrushers.DialogueSystem.Selector.onDeselectedUsable = new UsableUnityEvent()

◆ onSelectedUsable

UsableUnityEvent PixelCrushers.DialogueSystem.Selector.onSelectedUsable = new UsableUnityEvent()

◆ outOfRangeColor

Color PixelCrushers.DialogueSystem.Selector.outOfRangeColor = Color.gray

The color of the information labels when the target is out of range.

◆ raycastAll

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

Reticle PixelCrushers.DialogueSystem.Selector.reticle

The reticle images.

◆ runRaycasts

Dimension PixelCrushers.DialogueSystem.Selector.runRaycasts = Dimension.In3D

Specifies whether to run 2D or 3D raycasts.

◆ selectAt

SelectAt PixelCrushers.DialogueSystem.Selector.selectAt = SelectAt.CenterOfScreen

How to target (center of screen or under mouse cursor).

Default is center of screen.

◆ selection

GameObject PixelCrushers.DialogueSystem.Selector.selection = null
protected

◆ textStyle

TextStyle PixelCrushers.DialogueSystem.Selector.textStyle = TextStyle.Shadow

The text style for the text.

◆ textStyleColor

Color PixelCrushers.DialogueSystem.Selector.textStyleColor = Color.black

The color of the text style's outline or shadow.

◆ tooFarEvent

UnityEvent PixelCrushers.DialogueSystem.Selector.tooFarEvent = new UnityEvent()

The too far event handler.

◆ tooFarMessage

string PixelCrushers.DialogueSystem.Selector.tooFarMessage = string.Empty

If set, show this alert message if attempt to use something beyond its usable range.

◆ usable

Usable PixelCrushers.DialogueSystem.Selector.usable = null
protected

◆ useButton

string PixelCrushers.DialogueSystem.Selector.useButton = "Fire2"

The button that sends an OnUse message.

◆ useDefaultGUI

bool PixelCrushers.DialogueSystem.Selector.useDefaultGUI = true

If true, uses a default OnGUI to display a selection message and targeting reticle.

◆ useKey

KeyCode PixelCrushers.DialogueSystem.Selector.useKey = KeyCode.Space

The key that sends an OnUse message.

◆ useMessage

string PixelCrushers.DialogueSystem.Selector.useMessage = string.Empty
protected

Property Documentation

◆ CurrentDistance

float PixelCrushers.DialogueSystem.Selector.CurrentDistance
get

Gets the distance from the current usable.

The current distance.

◆ CurrentUsable

Usable PixelCrushers.DialogueSystem.Selector.CurrentUsable
get

Gets the current selection.

The selection.

◆ CustomPosition

Vector3 PixelCrushers.DialogueSystem.Selector.CustomPosition
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.

◆ GuiStyle

GUIStyle PixelCrushers.DialogueSystem.Selector.GuiStyle
get

Gets the GUI style.

The GUI style.

Event Documentation

◆ DeselectedUsableObject

DeselectedUsableObjectDelegate PixelCrushers.DialogueSystem.Selector.DeselectedUsableObject = delegate { }

Occurs when the selector has untargeted a usable object.

◆ SelectedUsableObject

SelectedUsableObjectDelegate PixelCrushers.DialogueSystem.Selector.SelectedUsableObject = delegate { }

Occurs when the selector has targeted a usable object.


The documentation for this class was generated from the following file: