Skip to main content

BasicTouchScreenButton

An abstract class in Root.Township, the global namespace.

Base for a button on an in-world touch screen (such as the camera or menus): tracks pressed state, changes the renderer alpha and plays sounds. Pressed by TouchScreenMenuBase.

Constructors​

MemberWhat it is
protected BasicTouchScreenButton()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
Renderer[] allRenderersRenderers that share the button's material.
Vector2 buttonSizeBacking value for ButtonSize.
float idleAlphaMaterial alpha when not pressed.
Renderer mainRendererMain renderer whose material alpha changes.
float pressedAlphaMaterial alpha when pressed.
protected static readonly int _AlphaShader property id for _Alpha.
protected static Logger loggerShared logger.
4 private and internal fields
MemberWhat it is
private Material materialInstance of the main renderer's material, shared by all its renderers, whose _Alpha shows pressed or idle.
private AltaEvent onPressedEvent behind Pressed, invoked by Press.
private AltaEvent onReleasedEvent behind Released, invoked by Release.
private ButtonSoundSettings soundsOptional press and release sounds, hooked up in Awake.

Properties​

MemberWhat it is
virtual Vector2 ButtonSize { get; }Size of the touch area.
virtual bool IsEnabled { get; set; }Whether the button can be pressed.
bool State { get; private set; }Whether the button is pressed.

Events​

MemberWhat it is
event Action PressedRaised when the button is pressed.
event Action ReleasedRaised when the button is released.

Methods​

MemberWhat it is
void Press()Marks the button pressed and raises Pressed.
void Release()Marks the button released and raises Released.
protected virtual void Awake()Makes a material copy for the renderers and hooks the press and release sounds.
protected virtual void InternalPress()Hook for subclasses, called after Pressed.
protected virtual void InternalRelease()Hook for subclasses, called after Released.
protected void SetAlpha(bool isPressed)Sets the material alpha to the pressed or idle value.
protected void SetPressedAlpha()Sets the material alpha to the pressed value.
1 private and internal method
MemberWhat it is
private void OnDrawGizmos()Editor: draws the button's touch area as a wire rectangle.