Hex Terrains Framework
Search Results for

    Show / Hide Table of Contents

    Class BrushUserToolState<TBrushTarget>

    Base class for managing the state and configuration of a terrain brush user tool, including brush size, opacity, input controls, and timing constraints for terrain editing operations.

    Inheritance
    object
    SmState
    UserToolStateBase
    HexTerrainUserToolStateBase
    BrushUserToolState<TBrushTarget>
    BrushUserToolState<TBrushTarget, TSettings>
    Implements
    ISmState
    Inherited Members
    HexTerrainUserToolStateBase.TerrainAPI
    HexTerrainUserToolStateBase.HexTerrainUserToolSettings
    HexTerrainUserToolStateBase.PreviousViewMode
    HexTerrainUserToolStateBase.Init(HexTerrainUserToolStateSettings)
    HexTerrainUserToolStateBase.Init(IHexTerrainAPI)
    HexTerrainUserToolStateBase.Init<TInitArgs>(IHexTerrainAPI, TInitArgs)
    HexTerrainUserToolStateBase.ShowSettingsScreen<TViewData, TScreen>(TViewData)
    HexTerrainUserToolStateBase.GetUIScreen<TScreen>()
    HexTerrainUserToolStateBase.HideSettingsScreen<TScreen>()
    HexTerrainUserToolStateBase.SetupTerrainCursor(bool, int)
    HexTerrainUserToolStateBase.SetupTerrainCursor(bool, int, Color32)
    HexTerrainUserToolStateBase.SetupTerrainCursor(bool, int, Color32, bool)
    HexTerrainUserToolStateBase.SetupTerrainCursor(bool)
    HexTerrainUserToolStateBase.GetTerrainLayer<TLayerGroup, TLayer>(HexTerrainLayerReference)
    HexTerrainUserToolStateBase.TrySetViewMode()
    HexTerrainUserToolStateBase.SetViewMode(SetViewModeRequest)
    HexTerrainUserToolStateBase.TryRestoreViewMode()
    UserToolStateBase.Settings
    UserToolStateBase.Parent
    UserToolStateBase.ParentStateMachine
    UserToolStateBase.UserToolType
    UserToolStateBase.Init(UserToolStateSettings)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Fwt.HexTerrains.UserTools.SM
    Assembly: fwt.hexterrains.dll
    Syntax
    public abstract class BrushUserToolState<TBrushTarget> : HexTerrainUserToolStateBase, ISmState where TBrushTarget : class
    Type Parameters
    Name Description
    TBrushTarget

    The type of object that serves as the target for brush operations. Must be a reference type.

    Remarks

    This class defines common properties and methods for brush-based terrain editing tools, such as input key bindings, brush application logic, and timing restrictions to prevent rapid consecutive changes. Derived classes should implement the brush application logic specific to their target type by overriding the abstract and virtual members. The class supports customization of user interactions, including brush size and opacity adjustments, and provides mechanisms to synchronize brush state with user input in real time.

    Constructors

    BrushUserToolState(ISmState)

    Declaration
    protected BrushUserToolState(ISmState parent)
    Parameters
    Type Name Description
    ISmState parent

    Fields

    PrevChangeTimeStamp

    Used to prevent applying brush too fast (next change will be applied at least after this amount of seconds after previous change)

    Declaration
    [NonSerialized]
    public float PrevChangeTimeStamp
    Field Value
    Type Description
    float

    Properties

    AllowRightMouseButton

    If true, applies brush by right mouse click

    Declaration
    public virtual bool AllowRightMouseButton { get; set; }
    Property Value
    Type Description
    bool

    BrushOpacity

    Gets the current opacity level applied to the terrain brush.

    Declaration
    public virtual float BrushOpacity { get; }
    Property Value
    Type Description
    float
    Remarks

    If the terrain API is not accessible, the property defaults to 0. The brush opacity

    BrushSize

    Gets the current brush size used for terrain editing operations.

    Declaration
    public virtual int BrushSize { get; }
    Property Value
    Type Description
    int
    Remarks

    If the underlying terrain API is unavailable, the property returns 0. The brush size determines the area affected by editing actions such as painting or sculpting terrain.

    CanChangeBrushSize

    Indicates whether the brush size can be increased or decreased.

    Declaration
    public virtual bool CanChangeBrushSize { get; set; }
    Property Value
    Type Description
    bool

    ChangeBrushSizeKey

    When this key is pressed, mouse wheel changes brush size

    Declaration
    public virtual KeyCode ChangeBrushSizeKey { get; set; }
    Property Value
    Type Description
    KeyCode

    ChangeModeKey

    When this key is pressed, the brush mode will be 1 instead of default 0

    Declaration
    public virtual KeyCode ChangeModeKey { get; set; }
    Property Value
    Type Description
    KeyCode

    ChangeOpacityKey

    When this key is pressed, mouse wheel changes brush opacity

    Declaration
    public virtual KeyCode ChangeOpacityKey { get; set; }
    Property Value
    Type Description
    KeyCode

    ChangeOpacityMultiplier

    Gets or sets the multiplier applied to opacity changes.

    Declaration
    public virtual float ChangeOpacityMultiplier { get; set; }
    Property Value
    Type Description
    float
    Remarks

    Use this property to control the rate at which opacity is adjusted. Larger values result in more significant changes per operation.

    CursorColor

    Gets or sets the color used to render the cursor.

    Declaration
    public virtual Color32 CursorColor { get; set; }
    Property Value
    Type Description
    Color32

    DecreaseBrushSizeKey

    Decreases brush size/opacity key

    Declaration
    public virtual KeyCode DecreaseBrushSizeKey { get; set; }
    Property Value
    Type Description
    KeyCode

    DecreaseBrushSizeKey2

    Alternative key to decrease brush size/opacity

    Declaration
    public virtual KeyCode DecreaseBrushSizeKey2 { get; set; }
    Property Value
    Type Description
    KeyCode

    IncreaseBrushSizeKey

    When this key is pressed, increases brush size/opacity

    Declaration
    public virtual KeyCode IncreaseBrushSizeKey { get; set; }
    Property Value
    Type Description
    KeyCode

    IncreaseBrushSizeKey2

    Increases brush size/opacity key alternative

    Declaration
    public virtual KeyCode IncreaseBrushSizeKey2 { get; set; }
    Property Value
    Type Description
    KeyCode

    IsTimeTresholdPassed

    True if Time Treshold is already passed after previous change has been applied. True means we can apply next brush change

    Declaration
    public bool IsTimeTresholdPassed { get; }
    Property Value
    Type Description
    bool

    TimeTreshold

    Specifies the minimum time interval, in seconds, that must elapse between consecutive terrain changes.

    Declaration
    public virtual float TimeTreshold { get; set; }
    Property Value
    Type Description
    float
    Remarks

    Use this value to prevent terrain modifications from occurring too frequently. Adjusting this threshold can help control performance and responsiveness in scenarios where terrain changes are triggered rapidly.

    Methods

    ApplyBrush(int, int2, int, TBrushTarget, int)

    Applies brush to the brushView. Returns true if changes were applied

    Declaration
    public abstract bool ApplyBrush(int brushMode, int2 cellCoord, int cellIndex, TBrushTarget brushTarget, int mouseButton)
    Parameters
    Type Name Description
    int brushMode
    int2 cellCoord
    int cellIndex
    TBrushTarget brushTarget
    int mouseButton
    Returns
    Type Description
    bool

    ApplyBrushToAllBrushPoints(int, int2, int, HexTerrainSettings, TBrushTarget, int)

    Applies the brush effect to all valid brush points within the specified range on the terrain, using the given brush mode and target.

    Declaration
    protected virtual bool ApplyBrushToAllBrushPoints(int brushMode, int2 centerCellCoord, int centerCellIndex, HexTerrainSettings terrainSettings, TBrushTarget brushTarget, int mouseButton)
    Parameters
    Type Name Description
    int brushMode

    The mode that determines how the brush effect is applied to each cell. The value should correspond to a supported brush operation.

    int2 centerCellCoord

    The coordinates of the center cell from which the brush range is calculated.

    int centerCellIndex

    The index of the center cell in the terrain data structure.

    HexTerrainSettings terrainSettings

    The terrain settings that define layout, rotation, and cell validation for brush application. Cannot be null.

    TBrushTarget brushTarget

    The target object that receives the brush effect. Cannot be null.

    int mouseButton

    The mouse button identifier used to trigger the brush action. The value should match the expected input mapping.

    Returns
    Type Description
    bool

    true if the brush was successfully applied to at least one cell; otherwise, false.

    Remarks

    Cells outside the terrain or excluded by brush opacity are not affected. The method returns false if no valid cells are found or if the brush target is null.

    ApplyBrushToAllCells(int, HexTerrainSettings, TBrushTarget, int)

    Attempts to apply the brush operation to all cells in the terrain using the specified settings and brush target.

    Declaration
    protected virtual bool ApplyBrushToAllCells(int brushMode, HexTerrainSettings settings, TBrushTarget brushTarget, int mouseButton)
    Parameters
    Type Name Description
    int brushMode

    The brush mode to use when applying the operation. Determines the type of brush effect applied to each cell.

    HexTerrainSettings settings

    The terrain settings that define cell layout and configuration. Must not be null.

    TBrushTarget brushTarget

    The target object that receives the brush operation. Must not be null.

    int mouseButton

    The mouse button identifier used to trigger the brush operation. Typically corresponds to a specific user input.

    Returns
    Type Description
    bool

    true if the brush was applied to at least one cell; otherwise, false.

    Remarks

    The brush is applied to each cell based on the current brush opacity, which may result in some cells being skipped. The method returns false if the brush target is null or if no cells are affected.

    ApplyToSingleCell(int, int2, int, TBrushTarget, int)

    Attempts to apply the brush effect to a single cell using the specified parameters and brush opacity.

    Declaration
    protected virtual bool ApplyToSingleCell(int brushMode, int2 cellCoord, int cellIndex, TBrushTarget brushTarget, int mouseButton)
    Parameters
    Type Name Description
    int brushMode

    The brush mode to use when applying the effect. Determines the type of operation performed on the cell.

    int2 cellCoord

    The coordinates of the cell to which the brush is applied.

    int cellIndex

    The index of the cell within the target structure.

    TBrushTarget brushTarget

    The target object that receives the brush effect.

    int mouseButton

    The mouse button used to trigger the brush action. Typically indicates the type of user interaction.

    Returns
    Type Description
    bool

    true if the brush effect was successfully applied to the cell; otherwise, false.

    Remarks

    The brush is only applied if a random check based on the current brush opacity passes. This method can be overridden to customize how the brush is applied to individual cells.

    CanBeAppliedToManyPoints(int)

    Determines whether the brush operation can be applied to multiple points based on the specified brush mode.

    Declaration
    public virtual bool CanBeAppliedToManyPoints(int brushMode)
    Parameters
    Type Name Description
    int brushMode

    An integer representing the brush mode. The value determines whether the operation supports multiple points.

    Returns
    Type Description
    bool

    true if the operation can be applied to many points for the specified brush mode; otherwise, false.

    GetBrushTarget()

    Declaration
    public virtual TBrushTarget GetBrushTarget()
    Returns
    Type Description
    TBrushTarget

    Init<TInitArgs>(TInitArgs)

    Initializes the tool using the specified initialization arguments.

    Declaration
    public override void Init<TInitArgs>(TInitArgs args)
    Parameters
    Type Name Description
    TInitArgs args

    The initialization arguments used to configure the tool. If the argument implements IUserToolStateConfig, its ToolSettings are used; otherwise, default settings are applied.

    Type Parameters
    Name Description
    TInitArgs

    The type of the initialization arguments used to configure the tool. If the type implements IUserToolStateConfig, its ToolSettings will be used; otherwise, default settings are applied.

    Overrides
    HexTerrainUserToolStateBase.Init<TInitArgs>(TInitArgs)

    IsAppliedToEveryCellOnMap(int)

    Determines whether the specified brush mode applies to every cell on the map.

    Declaration
    public virtual bool IsAppliedToEveryCellOnMap(int brushMode)
    Parameters
    Type Name Description
    int brushMode

    The brush mode to evaluate. Typically, a value of 1 indicates that the brush is applied to all cells.

    Returns
    Type Description
    bool

    true if the brush mode applies to every cell on the map; otherwise, false.

    PrepareToRun()

    Performs any necessary initialization or setup required before executing the main operation. Called by state machine once when state becomes active. If state is disabled and then enabled again, this method will be called again.

    Declaration
    public override void PrepareToRun()
    Overrides
    HexTerrainUserToolStateBase.PrepareToRun()
    Remarks

    Override this method to implement preparation logic specific to the derived class. This method should be called prior to running the core functionality to ensure all prerequisites are met.

    PrepareToStop()

    Performs any necessary actions to prepare the object for stopping or shutdown. Called when the state is about to be deactivated.

    Declaration
    public override void PrepareToStop()
    Overrides
    HexTerrainUserToolStateBase.PrepareToStop()
    Remarks

    Implementations should ensure that all resources are released and any ongoing operations are safely terminated before the object is stopped. This method is typically called prior to disposing or shutting down the object to ensure a clean transition.

    SetNewTimestamp()

    Saves current unscaled time as a new PrevChangeTimeStamp, which allows to prevent applying brush too often (see TimeTreshold)

    Declaration
    public void SetNewTimestamp()

    Tick()

    Advances the state of the object by one tick, performing any periodic updates required.

    Declaration
    public override void Tick()
    Overrides
    UserToolStateBase.Tick()

    TryApplyBrush()

    Attempts to apply the brush operation to the terrain based on the current input state and brush settings.

    Declaration
    protected virtual void TryApplyBrush()
    Remarks

    This method checks for user input, pointer position, and brush configuration before performing the brush action. It does not apply the brush if the pointer is over a UI element, the required mouse button is not pressed, or other preconditions are not met. Override this method to customize brush application behavior in derived classes.

    UpdateBrush()

    Updates the terrain brush's appearance and behavior based on the current input state and configuration. This includes setting brush visibility, color, size, and opacity according to user interactions and allowed changes.

    Declaration
    protected virtual void UpdateBrush()
    Remarks

    This method responds to user input to adjust the brush size or opacity, depending on the active mode and configuration flags. It is typically called to synchronize the brush's properties with the user's actions in real time. Override this method to customize how brush updates are handled in derived classes.

    Implements

    ISmState

    Extension Methods

    HashExtensions.GetHashCode_RefType<TValue>(TValue, int)
    Extensions_UnityObject.SmartDestroy(object)
    Extensions_UnityObject.SmartGetComponent<TComponent>(object)
    Extensions_UnityObject.SmartGetGameGameObject(object)
    In this article
    Back to top Generated by DocFX