Home Game Development c# – How to determine lessons with their namespace within the Unity editor?

c# – How to determine lessons with their namespace within the Unity editor?

0
c# – How to determine lessons with their namespace within the Unity editor?

[ad_1]

Here’s a cheeky workaround you should utilize.

First we outline an empty struct, so it would not really enhance the reminiscence allocation of our parts:

[System.Serializable]
public struct NamespaceHint 
{
}

Then we give it a PropertyDrawer (positioned in a folder referred to as “Editor”) that prints out the fully-qualified title of the part it is hooked up to:

[CustomPropertyDrawer(typeof(NamespaceHint))]
public class NamespaceHintDrawer : PropertyDrawer
{
    public override void OnGUI(Rect place, SerializedProperty property, GUIContent label)
    {
        var t = property.serializedObject.targetObject.GetType();        
        EditorGUI.LabelField(place, t.FullName);
    }
}

Then for any kind that is ambiguous, we will add just a little trace on the prime of the inspector:

namespace Player
{
    public class Controller : MonoBehaviour
    {
        [SerializeField] NamespaceHint _ns;

        // ... different members...
    }
}

And now two similar parts in numerous namespaces are distinguishable within the Inspector – although you continue to need to guess and examine when choosing them from the Add Component menu:

Two controller components, one labelled "Enemy.Controller", one "Player.Controller"

You may additionally do that manually with a [Header("Player.Controller")] attribute for those who do not want it to robotically adapt to call modifications.


But be aware how significantly better this appears if we simply give lessons distinctive names to start with:

Same example, but with classes named EnemyController and PlayerController

Boom. We can inform them aside within the part choice menu and we do not want this boilerplate on the prime of the script, so it is even much less to kind!

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here