Heroic Engine
  • Welcome
  • Getting Started
    • Quickstart
    • Example Games
      • Tic Tac Toe
      • Turn based duel
  • Basics
    • Injection Manager
    • Engine Systems
      • Core Systems
        • Events Manager
        • Input Manager
        • Localization Manager
          • LangText component
        • Music Player
        • Sounds Manager
        • Time Manager
        • Scenes Loader
        • Day Time Controller
        • Weather Controller
      • Gameplay Systems
        • Currencies Manager
        • Player Progression Manager
        • Quest Manager
        • Random Events Manager
        • Hittables Manager
        • Dungeon Generator
      • UI Systems
        • UI Controller
        • Countdown Controller
    • Editor Tools
      • Clear Saves
      • Mobile Build Optimizer
      • Create System
      • Icon from Prefab Generator
    • Engine Utilities
      • PoolSystem
      • DataSaver
      • ComponentExtensions
      • MaterialExtensions
      • SpriteUtils
      • SlowUpdate
      • StringUtils
      • TypeUtility
      • MathHelper
      • VectorUtils
      • TransformUtils
      • MeshUtils
    • Useful Components
      • Floating Item
      • Fly Up Text
      • Label Scaler
      • Ragdoll
      • Rotate To Camera
      • Orbital Camera
      • Rotator
      • Texture Mover
      • Hittable
      • Projectile
      • Projectile2D
      • LifetimeObject
      • Spawner
      • Colorized Particles
      • Draggable2D
      • SaveableTransform
    • Useful Attributes
Powered by GitBook
On this page
  • ConditionalHide
  • How to use:
  • ReadonlyField
  • How to use:
  1. Basics

Useful Attributes

PreviousSaveableTransform

Last updated 4 months ago

ConditionalHide

This attribute allows to make your class field visible or invisible in inspector depending on value of another field.

How to use:

Add ConditionalHide attribute in the next format:

[ConditionalHide("conditionFieldName", hideInInspector, neededFieldValue)]

The first parameter (conditionFieldName) is the name of class field that will be checked.

If second parameter is true, your conditional field will be hidden from inspector in case if checked field value equals to neededFieldValue. Otherwise, your field will be visible, but not editable in inspector.

Example #1:

public class MyClass : MonoBehaviour
{
    [SerializeField] private bool firstField = false;
    [ConditionalHide("firstField", true, true)]
    [SerializeField] private int secondField;
}

In this case, secondField will be visible in inspector only if firstField value will be true.

Example #2

Let's change the second parameter in ConditionalHide attribute and see what happens.

public class MyClass : MonoBehaviour
{
    [SerializeField] private bool firstField = false;
    //This time we just disable editing for secondField field
    [ConditionalHide("firstField", false, true)]
    [SerializeField] private int secondField;
}

As result, we can always see secondField in inspector, but it can be editable or not:


ReadonlyField

This attribute makes class field not editable, but visible in inspector.

How to use:

Add [ReadonlyField] attribute to your class field. Good job, that's all!

Example:

public class MyClass : MonoBehaviour
{
    //id field will be visible in inspector, but not editable
    [SerializeField] [ReadonlyField] private string id = "0123";
    [SerializeField] private int someNumber;
}
First field is false
First field is true
Second Field is locked for editing
Second Field is unlocked for editing
[ReadonlyField] attribute blocks field editing in inspector