UIAdvancedLabel - jimdroberts/FishMMO GitHub Wiki
UIAdvancedLabel
is a UI component in the FishMMO client that displays a label on the screen with advanced features such as fading, movement, and bouncing effects. It supports dynamic text, color, font, and position, and can be used for notifications, floating text, and other visual feedback.
-
public string Text
The text displayed by the label.
-
public Vector2 Size
The size of the label in pixels.
-
public GUIStyle Style
The GUIStyle used to render the label.
-
public Vector2 Center
The center offset for the label.
-
public Vector2 PixelOffset
Pixel offset for label placement on screen.
-
public bool FadeColor
If true, the label color will fade over its lifetime.
-
public float RemainingLife
Remaining lifetime of the label in seconds.
-
public float FadeTime
Total fade time for the label in seconds.
-
public Color TargetColor
Target color to fade to.
-
public bool IncreaseY
If true, the label will move upward over its lifetime.
-
public float OldY
The starting Y position for upward movement.
-
public float YIncreaseValue
The target Y position for upward movement.
-
public float Bounce
Bounce effect value for the label.
-
public float BounceDecay
Decay rate for the bounce effect.
-
void Update()
Per-frame update for label visibility, fading, and movement effects.
-
void OnGUI()
Renders the label on the screen using GUI.Label.
-
public static IReference Create(string text, FontStyle style, Font font, int fontSize, Color color, float lifeTime, bool fadeColor, bool increaseY, Vector2 pixelOffset)
Creates a new UIAdvancedLabel instance and initializes it with the provided parameters.
-
public void Initialize(string text, FontStyle fontStyle, Font font, int fontSize, Color color, float lifeTime, bool fadeColor, bool increaseY, Vector2 pixelOffset)
Initializes the label with the provided parameters.
-
public void SetPosition(Vector3 position)
Sets the world position of the label's transform.
-
public void ChangeFont(int fontSize)
Changes the font size of the label and recalculates its size and center.
-
public void SetText(string text)
Sets the label's text and recalculates its size and center.
-
public void SetColor(Color color)
Sets the label's color.
- Attach
UIAdvancedLabel
to a GameObject in the Unity Editor or create it dynamically using theCreate
method. - Set the desired text, style, color, and effects (fade, movement, bounce).
- Use
Initialize
to configure the label or set properties directly.
// Example: Creating a floating label with fade and upward movement
UIAdvancedLabel label = (UIAdvancedLabel)UIAdvancedLabel.Create(
"+100 XP",
FontStyle.Bold,
myFont,
24,
Color.yellow,
2.0f,
true, // fadeColor
true, // increaseY
new Vector2(0, 0)
);
label.SetPosition(new Vector3(0, 0, 0));
- Use the
Create
method for dynamic labels and notifications. - Adjust
FadeTime
,YIncreaseValue
, andBounce
for desired visual effects. - Use
SetText
,SetColor
, andChangeFont
to update label appearance at runtime.