PixelCrushers.DialogueSystem.ProximitySelector Class Reference

This component implements a proximity-based selector that allows the player to move into range and use a usable object. More...

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

Classes

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

Public Member Functions

virtual void Start ()
 
virtual void OnConversationStart (Transform actor)
 
virtual void OnConversationEnd (Transform actor)
 
virtual void UseCurrentSelection ()
 Calls OnUse on the current selection.
 
virtual void RemoveGameObjectFromDetectedList (GameObject other)
 
virtual void RemoveUsableFromDetectedList (Usable usable)
 
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.
 

Public Attributes

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.
 
Color color = Color.yellow
 The color of the information labels when the target is in range.
 
TextStyle textStyle = TextStyle.Shadow
 The text style for the text.
 
Color textStyleColor = Color.black
 The color of the text style's outline or shadow.
 
string defaultUseMessage = "(spacebar to interact)"
 The default use message.
 
KeyCode useKey = KeyCode.Space
 The key that sends an OnUse message.
 
string useButton = "Fire2"
 The button that sends an OnUse message.
 
bool enableTouch = false
 Tick to enable touch triggering.
 
ScaledRect touchArea = new ScaledRect(ScaledRect.empty)
 If touch triggering is enabled and there's a touch in this area, the selector triggers.
 
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.
 
UsableUnityEvent onSelectedUsable = new UsableUnityEvent()
 
UsableUnityEvent onDeselectedUsable = new UsableUnityEvent()
 
List< UsableusablesInRange = new List<Usable>()
 Keeps track of which usable objects' triggers the selector is currently inside.
 

Protected Member Functions

virtual void Reset ()
 
virtual void OnEnable ()
 
virtual void OnDisable ()
 
virtual void Update ()
 Sends an OnUse message to the current selection if the player presses the use button.
 
void OnSelectedUsableObject (Usable usable)
 
void OnDeselectedUsableObject (Usable usable)
 
virtual bool IsUseButtonDown ()
 Checks whether the player has just pressed the use button.
 
bool IsTouchDown ()
 
void OnTriggerEnter (Collider other)
 If we entered a trigger, check if it's a usable object.
 
void OnTriggerExit (Collider other)
 If we just left a trigger, check if it's the current selection.
 
void OnTriggerEnter2D (Collider2D other)
 If we entered a 2D trigger, check if it's a usable object.
 
void OnTriggerExit2D (Collider2D other)
 If we just left a 2D trigger, check if it's the current selection.
 
virtual void CheckTriggerEnter (GameObject other)
 
virtual void CheckTriggerExit (GameObject other)
 
virtual void OnUsableDisabled (Usable usable)
 
void SetGuiStyle ()
 

Protected Attributes

Usable currentUsable = null
 The current usable that will receive an OnUse message if the player hits the use button.
 
string currentHeading = string.Empty
 
string currentUseMessage = string.Empty
 
bool toldListenersHaveUsable = false
 
GUIStyle guiStyle = null
 Caches the GUI style to use when displaying the selection message in OnGUI.
 
float guiStyleLineHeight = 16f
 
float timeToEnableUseButton = 0
 

Static Protected Attributes

const float MinTimeBetweenUseButton = 0.5f
 

Properties

Usable CurrentUsable [get, set]
 Gets the current usable.
 
GUIStyle GuiStyle [get]
 Gets the GUI style.
 

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
 

Detailed Description

This component implements a proximity-based selector that allows the player to move into range 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 proximity selector tracks the most recent usable object whose trigger the player has entered. It 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.

Member Function Documentation

◆ CheckTriggerEnter()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.CheckTriggerEnter ( GameObject  other)
inlineprotectedvirtual

◆ CheckTriggerExit()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.CheckTriggerExit ( GameObject  other)
inlineprotectedvirtual

◆ IsTouchDown()

bool PixelCrushers.DialogueSystem.ProximitySelector.IsTouchDown ( )
inlineprotected

◆ IsUseButtonDown()

virtual bool PixelCrushers.DialogueSystem.ProximitySelector.IsUseButtonDown ( )
inlineprotectedvirtual

Checks whether the player has just pressed the use button.

Returns
true if the use button/key is down; otherwise, false.

◆ OnConversationEnd()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.OnConversationEnd ( Transform  actor)
inlinevirtual

◆ OnConversationStart()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.OnConversationStart ( Transform  actor)
inlinevirtual

◆ OnDeselectedUsableObject()

void PixelCrushers.DialogueSystem.ProximitySelector.OnDeselectedUsableObject ( Usable  usable)
inlineprotected

◆ OnDisable()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.OnDisable ( )
inlineprotectedvirtual

◆ OnEnable()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.OnEnable ( )
inlineprotectedvirtual

◆ OnGUI()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.OnGUI ( )
inlinevirtual

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

◆ OnSelectedUsableObject()

void PixelCrushers.DialogueSystem.ProximitySelector.OnSelectedUsableObject ( Usable  usable)
inlineprotected

◆ OnTriggerEnter()

void PixelCrushers.DialogueSystem.ProximitySelector.OnTriggerEnter ( Collider  other)
inlineprotected

If we entered a trigger, check if it's a usable object.

If so, update the selection and raise the SelectedUsableObject event.

Parameters
otherThe trigger collider.

◆ OnTriggerEnter2D()

void PixelCrushers.DialogueSystem.ProximitySelector.OnTriggerEnter2D ( Collider2D  other)
inlineprotected

If we entered a 2D trigger, check if it's a usable object.

If so, update the selection and raise the SelectedUsableObject event.

Parameters
otherThe 2D trigger collider.

◆ OnTriggerExit()

void PixelCrushers.DialogueSystem.ProximitySelector.OnTriggerExit ( Collider  other)
inlineprotected

If we just left a trigger, check if it's the current selection.

If so, clear the selection and raise the DeselectedUsableObject event. If we're still in range of any other usables, select one of them.

Parameters
otherThe trigger collider.

◆ OnTriggerExit2D()

void PixelCrushers.DialogueSystem.ProximitySelector.OnTriggerExit2D ( Collider2D  other)
inlineprotected

If we just left a 2D trigger, check if it's the current selection.

If so, clear the selection and raise the DeselectedUsableObject event. If we're still in range of any other usables, select one of them.

Parameters
otherThe 2D trigger collider.

◆ OnUsableDisabled()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.OnUsableDisabled ( Usable  usable)
inlineprotectedvirtual

◆ RemoveGameObjectFromDetectedList()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.RemoveGameObjectFromDetectedList ( GameObject  other)
inlinevirtual

◆ RemoveUsableFromDetectedList()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.RemoveUsableFromDetectedList ( Usable  usable)
inlinevirtual

◆ Reset()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.Reset ( )
inlineprotectedvirtual

◆ SetCurrentUsable()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.SetCurrentUsable ( Usable  usable)
inlinevirtual

◆ SetGuiStyle()

void PixelCrushers.DialogueSystem.ProximitySelector.SetGuiStyle ( )
inlineprotected

◆ Start()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.Start ( )
inlinevirtual

◆ Update()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.Update ( )
inlineprotectedvirtual

Sends an OnUse message to the current selection if the player presses the use button.

◆ UseCurrentSelection()

virtual void PixelCrushers.DialogueSystem.ProximitySelector.UseCurrentSelection ( )
inlinevirtual

Calls OnUse on the current selection.

Member Data Documentation

◆ actorTransform

Transform PixelCrushers.DialogueSystem.ProximitySelector.actorTransform = null

The actor transform to send with OnUse.

Defaults to this transform.

◆ alignment

TextAnchor PixelCrushers.DialogueSystem.ProximitySelector.alignment = TextAnchor.UpperCenter

The text alignment.

◆ broadcastToChildren

bool PixelCrushers.DialogueSystem.ProximitySelector.broadcastToChildren = true

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

◆ color

Color PixelCrushers.DialogueSystem.ProximitySelector.color = Color.yellow

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

◆ currentHeading

string PixelCrushers.DialogueSystem.ProximitySelector.currentHeading = string.Empty
protected

◆ currentUsable

Usable PixelCrushers.DialogueSystem.ProximitySelector.currentUsable = null
protected

The current usable that will receive an OnUse message if the player hits the use button.

◆ currentUseMessage

string PixelCrushers.DialogueSystem.ProximitySelector.currentUseMessage = string.Empty
protected

◆ defaultUseMessage

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

The default use message.

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

◆ enableTouch

bool PixelCrushers.DialogueSystem.ProximitySelector.enableTouch = false

Tick to enable touch triggering.

◆ guiSkin

GUISkin PixelCrushers.DialogueSystem.ProximitySelector.guiSkin

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

◆ guiStyle

GUIStyle PixelCrushers.DialogueSystem.ProximitySelector.guiStyle = null
protected

Caches the GUI style to use when displaying the selection message in OnGUI.

◆ guiStyleLineHeight

float PixelCrushers.DialogueSystem.ProximitySelector.guiStyleLineHeight = 16f
protected

◆ guiStyleName

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

The name of the GUI style in the skin.

◆ MinTimeBetweenUseButton

const float PixelCrushers.DialogueSystem.ProximitySelector.MinTimeBetweenUseButton = 0.5f
staticprotected

◆ onDeselectedUsable

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

◆ onSelectedUsable

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

◆ textStyle

TextStyle PixelCrushers.DialogueSystem.ProximitySelector.textStyle = TextStyle.Shadow

The text style for the text.

◆ textStyleColor

Color PixelCrushers.DialogueSystem.ProximitySelector.textStyleColor = Color.black

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

◆ timeToEnableUseButton

float PixelCrushers.DialogueSystem.ProximitySelector.timeToEnableUseButton = 0
protected

◆ toldListenersHaveUsable

bool PixelCrushers.DialogueSystem.ProximitySelector.toldListenersHaveUsable = false
protected

◆ touchArea

ScaledRect PixelCrushers.DialogueSystem.ProximitySelector.touchArea = new ScaledRect(ScaledRect.empty)

If touch triggering is enabled and there's a touch in this area, the selector triggers.

◆ usablesInRange

List<Usable> PixelCrushers.DialogueSystem.ProximitySelector.usablesInRange = new List<Usable>()

Keeps track of which usable objects' triggers the selector is currently inside.

◆ useButton

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

The button that sends an OnUse message.

◆ useDefaultGUI

bool PixelCrushers.DialogueSystem.ProximitySelector.useDefaultGUI = true

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

◆ useKey

KeyCode PixelCrushers.DialogueSystem.ProximitySelector.useKey = KeyCode.Space

The key that sends an OnUse message.

Property Documentation

◆ CurrentUsable

Usable PixelCrushers.DialogueSystem.ProximitySelector.CurrentUsable
getset

Gets the current usable.

The usable.

◆ GuiStyle

GUIStyle PixelCrushers.DialogueSystem.ProximitySelector.GuiStyle
get

Gets the GUI style.

The GUI style.

Event Documentation

◆ DeselectedUsableObject

DeselectedUsableObjectDelegate PixelCrushers.DialogueSystem.ProximitySelector.DeselectedUsableObject = null

Occurs when the selector has untargeted a usable object.

◆ Disabled

System.Action PixelCrushers.DialogueSystem.ProximitySelector.Disabled = null

◆ Enabled

System.Action PixelCrushers.DialogueSystem.ProximitySelector.Enabled = null

◆ SelectedUsableObject

SelectedUsableObjectDelegate PixelCrushers.DialogueSystem.ProximitySelector.SelectedUsableObject = null

Occurs when the selector has targeted a usable object.


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