private void Restore(SerializedProperty property, FieldInfo field, CyberAttrribute cyberAttribute) { AutoLoadAttribute attribute = cyberAttribute as AutoLoadAttribute; var component = (CyberEdit.Current.Target as Component); if (attribute.WithChildren == false) { property.objectReferenceValue = component.gameObject.GetComponent(field.FieldType); } else { property.objectReferenceValue = component.gameObject.GetComponentInChildren(field.FieldType); } }
public void DrawOnEnable(CyberAttrribute cyberAttribute, SerializedProperty property, FieldInfo field) { AutoLoadAttribute attribute = cyberAttribute as AutoLoadAttribute; if (CyberEdit.Current.Target is SceneAsset) { return; } if ((CyberEdit.Current.Target is Component && (field.FieldType.IsInterface || field.FieldType.IsSubclassOf(typeof(UnityEngine.Component))))) { if (attribute.AngryPutIfNull && property.objectReferenceValue == null) { Restore(property, field, cyberAttribute); } } else { throw new CyberAttributeException(typeof(AutoLoadAttribute), "It can be attached only to component and can only needs a component"); } }