Esempio n. 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            RequiredInHierarchyAttribute reqAttr = attribute as RequiredInHierarchyAttribute;

            if (!FindRequiredComponent(reqAttr))
            {
                position.height = EditorGUIUtility.singleLineHeight * 2.0f;
                EditorGUI.HelpBox(position, string.Format("Can't find a {0} component in the scene, but it is required.",
                                                          reqAttr.requiredType.Name), MessageType.Error);
                position.y     += EditorGUIUtility.singleLineHeight * 2.0f + 2;
                position.height = EditorGUIUtility.singleLineHeight;
            }
            EditorGUI.PropertyField(position, property, label, true);
        }
Esempio n. 2
0
 static UnityEngine.Object FindRequiredComponent(RequiredInHierarchyAttribute reqAttr)
 {
     return(GameObject.FindObjectOfType(reqAttr.requiredType));
 }