Search Unity

I want a list of all command like...

Discussion in 'Getting Started' started by Tempest74, Sep 5, 2017.

  1. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    130
    there is a list of all command like [Random(,)],[HideInInspector] etc...? I see some of those in tutorials and I will be so happy if I can find more command like this and what they do
     
  2. vertex001

    vertex001

    Joined:
    Sep 3, 2017
    Posts:
    1
    SarfaraazAlladin and Kiwasi like this.
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,532
    If you want to search for more, try to use the term 'attribute' (that's how they are called in C#).
    There are plenty of them, you could actually find every single one by either inspecting the assemblies or writing a program that does it for you.

    Haven't seen an official list of the most common though.
     
    Kiwasi likes this.
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,093
    Moved to getting started.
     
  5. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    130
    Thanks
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,608
    MSDN is also a good place to look, for any attributes that are part of .NET and not Unity.

    However since you can easily write your own attributes, its not possible to provide a single list with every possible attribute.
     
    Xepherys likes this.
  7. Xepherys

    Xepherys

    Joined:
    Sep 9, 2012
    Posts:
    178
    And writing your own is not only easy, but incredibly useful. Once I figured out the simple mechanics of this, it's saved me so much grief!
     
  8. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    130
    do you know any tutorial about how to make an atribute?
     
  9. Xepherys

    Xepherys

    Joined:
    Sep 9, 2012
    Posts:
    178
    Not off hand, but here's a very basic one that I did (from another post somewhere) for a readonly property in the inspector. In this case I wanted it to show in the inspector (so it had to be public) but I didn't want to be able to change it in the inspector.

    ReadOnlyAttribute.cs
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ReadOnlyAttribute : PropertyAttribute
    4. {
    5.  
    6. }
    This is just an empty class so that we can apply it in an editor script.

    Editor_DoReadOnlyDrawer.cs
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
    5. public class Editor_DoReadOnlyDrawer : PropertyDrawer
    6. {
    7.     public override float GetPropertyHeight(SerializedProperty property,
    8.                                             GUIContent label)
    9.     {
    10.         return EditorGUI.GetPropertyHeight(property, label, true);
    11.     }
    12.  
    13.     public override void OnGUI(Rect position,
    14.                                SerializedProperty property,
    15.                                GUIContent label)
    16.     {
    17.         GUI.enabled = false;
    18.         EditorGUI.PropertyField(position, property, label, true);
    19.         GUI.enabled = true;
    20.     }
    21. }
    This is the PropertyDrawer that reads the attribute tag and simply disabled the EditorGUI pushes the value, the reenables the EditorGUI.

    Other.cs
    Code (CSharp):
    1.         [Tooltip("Patrol path has been randomly reversed.")]
    2.         [ReadOnly]
    3.         public bool reverse = false;
    This is where I've added it in my code. This bool gets randomly assigned on Awake() for each object. But to help test and debug, I needed to be able to see this value on each object without having to throw a break point in the code. In the inspector, it looks like this:



    The value is properly reflected (in this case `true`), but the variable is greyed out and cannot be modified.

    As I said, this is a pretty simple use-case, and you can actually get pretty crazy with things.
     
    Ryiah likes this.
unityunity