public static Object ValidateObjectFieldAssignment(Object[] references, System.Type objType, RuntimeSerializedProperty property, EasyGUI.ObjectFieldValidatorOptions options) { if (references.Length > 0) { bool dragAssignment = DragAndDrop.objectReferences.Length > 0; bool isTextureRef = (references[0] != null && references[0] is Texture2D); if (objType == typeof(Sprite) && isTextureRef && dragAssignment) { return(SpriteUtilityHelper.TextureToSprite(references[0] as Texture2D)); } if (property != null) { if (references[0] != null && ValidateObjectReferenceValue(property, references[0], options)) { if (EditorSceneManager.preventCrossSceneReferences && EasyGUI.CheckForCrossSceneReferencing(references[0], property.RuntimeSerializedObject.TargetObject)) { return(null); } if (objType != null) { if (references[0] is GameObject && typeof(Component).IsAssignableFrom(objType)) { GameObject go = (GameObject)references[0]; references = go.GetComponents(typeof(Component)); } foreach (Object i in references) { if (i != null && objType.IsAssignableFrom(i.GetType())) { return(i); } } } else { return(references[0]); } } // If array, test against the target arrayElementType, if not test against the target Type. var type = property.PropertyType; if (property.IsArray) { type = property.ArrayElementType; } if (type == RuntimeSerializedPropertyType.Sprite && isTextureRef && dragAssignment) { return(SpriteUtilityHelper.TextureToSprite(references[0] as Texture2D)); } } else { if (references[0] != null && references[0] is GameObject && typeof(Component).IsAssignableFrom(objType)) { GameObject gameObject = (GameObject)references[0]; references = gameObject.GetComponents(typeof(Component)); } foreach (Object i in references) { if (i != null && objType.IsAssignableFrom(i.GetType())) { return(i); } } } } return(null); }
public static bool ValidateObjectReferenceValue(RuntimeSerializedProperty property, Object obj, EasyGUI.ObjectFieldValidatorOptions options) { if ((options & EasyGUI.ObjectFieldValidatorOptions.ExactObjectTypeValidation) == EasyGUI.ObjectFieldValidatorOptions.ExactObjectTypeValidation) { return(property.ValidateObjectReferenceValueExact(obj)); } return(property.ValidateObjectReferenceValue(obj)); }