mirror of
https://github.com/maxartz15/UnitySerializedReferenceUI.git
synced 2025-06-15 09:16:09 +02:00
organize into upm directory structure
This commit is contained in:
8
DefaultAttributes/SerializeReferenceButtonAttribute.meta
Normal file
8
DefaultAttributes/SerializeReferenceButtonAttribute.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 827f3a2847b39a94eb6fcbdb0d73d6ca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class SerializeReferenceButtonAttribute : PropertyAttribute
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c64e0f68b41b48939c9b98cc29a19b20
|
||||
timeCreated: 1579584059
|
@ -0,0 +1,31 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomPropertyDrawer(typeof(SerializeReferenceButtonAttribute))]
|
||||
public class SerializeReferenceButtonAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUI.GetPropertyHeight(property, true);
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
var labelPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(labelPosition, label);
|
||||
|
||||
var typeRestrictions = SerializedReferenceUIDefaultTypeRestrictions.GetAllBuiltInTypeRestrictions(fieldInfo);
|
||||
property.DrawSelectionButtonForManagedReference(position, typeRestrictions);
|
||||
|
||||
EditorGUI.PropertyField(position, property, GUIContent.none, true);
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a07638044724309b6088c28a11a15af
|
||||
timeCreated: 1579584059
|
8
DefaultAttributes/SerializeReferenceMenuAttribute.meta
Normal file
8
DefaultAttributes/SerializeReferenceMenuAttribute.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff8136ca43f822642adfa6388b137133
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class SerializeReferenceMenuAttribute : PropertyAttribute
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f1c372fa681cf146973df30a0d969fd
|
||||
timeCreated: 1579584059
|
@ -0,0 +1,26 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomPropertyDrawer(typeof(SerializeReferenceMenuAttribute))]
|
||||
public class SerializeReferenceMenuAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUI.GetPropertyHeight(property, true);
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
var typeRestrictions = SerializedReferenceUIDefaultTypeRestrictions.GetAllBuiltInTypeRestrictions(fieldInfo);
|
||||
property.ShowContextMenuForManagedReferenceOnMouseMiddleButton(position, typeRestrictions);
|
||||
|
||||
EditorGUI.PropertyField(position, property, true);
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaa31b1c39ee9424abe12fa0034d9d1b
|
||||
timeCreated: 1579584059
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fbe55d72b5fd59459fdb52e0f301ea1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
/// None of this types or interface types are valid.
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class SerializeReferenceUIRestrictionExcludeTypes : PropertyAttribute
|
||||
{
|
||||
public readonly Type[] Types;
|
||||
public SerializeReferenceUIRestrictionExcludeTypes(params Type[] types) => Types = types;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff5f6060287437048acba59e670cd000
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0c77910f7962a14cb85132596cb8d24
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
/// Any of this types or interface types are valid. And only this types can be presented.
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class SerializeReferenceUIRestrictionIncludeTypes : PropertyAttribute
|
||||
{
|
||||
public readonly Type[] Types;
|
||||
public SerializeReferenceUIRestrictionIncludeTypes(params Type[] types) => Types = types;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d10fb8315984ef458e4129191b17931
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
public static class SerializedReferenceUIDefaultTypeRestrictions
|
||||
{
|
||||
public static IEnumerable<Func<Type, bool>> GetAllBuiltInTypeRestrictions(FieldInfo fieldInfo)
|
||||
{
|
||||
var result = new List<Func<Type, bool>>();
|
||||
|
||||
var attributeObjects = fieldInfo.GetCustomAttributes(false);
|
||||
foreach (var attributeObject in attributeObjects)
|
||||
{
|
||||
switch (attributeObject)
|
||||
{
|
||||
case SerializeReferenceUIRestrictionIncludeTypes includeTypes:
|
||||
result.Add(SerializeReferenceTypeRestrictionFilters.TypeIsSubclassOrEqualOrHasInterface(includeTypes.Types));
|
||||
continue;
|
||||
case SerializeReferenceUIRestrictionExcludeTypes excludeTypes:
|
||||
result.Add(SerializeReferenceTypeRestrictionFilters.TypeIsNotSubclassOrEqualOrHasInterface(excludeTypes.Types));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95f44dc0cd315cf4988029eb8618aa02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user