示例#1
0
        public static object GetFromTarget(GameObject targ, System.Type restrictionType, EntityRelativity relativity)
        {
            switch (relativity)
            {
            case EntityRelativity.Entity:
            {
                targ = targ.FindRoot();

                var obj = ObjUtil.GetAsFromSource(restrictionType, targ);
                if (object.ReferenceEquals(obj, null) && ComponentUtil.IsAcceptableComponentType(restrictionType))
                {
                    obj = targ.GetComponentInChildren(restrictionType);
                }
                return(obj);
            }

            case EntityRelativity.Self:
            {
                return(ObjUtil.GetAsFromSource(restrictionType, targ));
            }

            case EntityRelativity.SelfAndChildren:
            {
                var obj = ObjUtil.GetAsFromSource(restrictionType, targ);
                if (object.ReferenceEquals(targ, null) && ComponentUtil.IsAcceptableComponentType(restrictionType))
                {
                    obj = targ.GetComponentInChildren(restrictionType);
                }
                return(obj);
            }

            default:
                return(null);
            }
        }
        public System.Collections.IEnumerable GetTargets(System.Type tp, object triggerArg)
        {
            foreach (var obj in this.ReduceTargets(triggerArg))
            {
                if (obj == null)
                {
                    continue;
                }

                var result = ObjUtil.GetAsFromSource(tp, obj);
                if (result == null && !_configured && obj == triggerArg && ComponentUtil.IsAcceptableComponentType(tp))
                {
                    //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                    var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                    if (go == null)
                    {
                        continue;
                    }
                    result = go.FindComponent(tp);
                }
                if (result != null)
                {
                    yield return(result);
                }
            }
        }
        public object GetTarget(System.Type tp, object triggerArg)
        {
            if (tp == null)
            {
                throw new System.ArgumentNullException("tp");
            }

            var obj = this.ReduceTarget(triggerArg);

            if (obj == null)
            {
                return(null);
            }

            var result = ObjUtil.GetAsFromSource(tp, obj);

            if (result == null && this.ImplicityReducesEntireEntity && ComponentUtil.IsAcceptableComponentType(tp))
            {
                //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }
                result = go.FindComponent(tp);
            }
            return(result);
        }
        public IEnumerable <T> GetTargets <T>(object triggerArg) where T : class
        {
            foreach (var obj in this.ReduceTargets(triggerArg))
            {
                if (obj == null)
                {
                    continue;
                }

                var result = ObjUtil.GetAsFromSource <T>(obj);
                if (result == null && !_configured && obj == triggerArg && ComponentUtil.IsAcceptableComponentType(typeof(T)))
                {
                    //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                    var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                    if (go == null)
                    {
                        continue;
                    }
                    result = go.FindComponent <T>();
                }
                if (result != null)
                {
                    yield return(result);
                }
            }
        }
        public static object GetAsFromSource(System.Type tp, object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var otp = obj.GetType();

            if (TypeUtil.IsType(otp, tp))
            {
                return(obj);
            }
            if (obj is IComponent)
            {
                var c = (obj as IComponent).component;
                if (!object.ReferenceEquals(c, null) && TypeUtil.IsType(c.GetType(), tp))
                {
                    return(c);
                }
            }

            var go = GameObjectUtil.GetGameObjectFromSource(obj);

            if (tp == typeof(UnityEngine.GameObject))
            {
                return(go);
            }

            if (go != null)
            {
                if (typeof(SPEntity).IsAssignableFrom(tp))
                {
                    return(SPEntity.GetEntityFromSource(tp, go));
                }
                else if (ComponentUtil.IsAcceptableComponentType(tp))
                {
                    return(go.GetComponent(tp));
                }
            }

            return(null);
        }
        public static T GetAsFromSource <T>(object obj) where T : class
        {
            if (obj == null)
            {
                return(null);
            }
            if (obj is T)
            {
                return(obj as T);
            }
            if (obj is IComponent)
            {
                var c = (obj as IComponent).component;
                if (c is T)
                {
                    return(c as T);
                }
            }
            var go = GameObjectUtil.GetGameObjectFromSource(obj);

            if (go is T)
            {
                return(go as T);
            }

            //if (go != null && ComponentUtil.IsAcceptableComponentType(typeof(T))) return go.GetComponentAlt<T>();
            if (go != null)
            {
                var tp = typeof(T);
                if (typeof(SPEntity).IsAssignableFrom(tp))
                {
                    return(SPEntity.GetEntityFromSource(tp, go) as T);
                }
                else if (ComponentUtil.IsAcceptableComponentType(tp))
                {
                    return(go.GetComponent(tp) as T);
                }
            }

            return(null);
        }
        public T GetTarget <T>(object triggerArg) where T : class
        {
            var obj = this.ReduceTarget(triggerArg);

            if (obj == null)
            {
                return(null);
            }

            var result = ObjUtil.GetAsFromSource <T>(obj);

            if (result == null && this.ImplicityReducesEntireEntity && ComponentUtil.IsAcceptableComponentType(typeof(T)))
            {
                //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }
                result = go.FindComponent <T>();
            }
            return(result);
        }
示例#8
0
        public static Component[] GetComponentsFromSerializedProperty(SerializedProperty property, System.Type restrictionType, bool forceSelfOnly, bool searchChildren)
        {
            if (!ComponentUtil.IsAcceptableComponentType(restrictionType))
            {
                return(ArrayUtil.Empty <Component>());
            }

            var go = GetGameObjectFromSource(property, forceSelfOnly);

            if (go == null)
            {
                return(ArrayUtil.Empty <Component>());
            }

            if (searchChildren)
            {
                return(go.GetComponentsInChildren(restrictionType));
            }
            else
            {
                return(go.GetComponents(restrictionType));
            }
        }
        public static Component[] GetComponentsFromSerializedProperty(SerializedProperty property, System.Type restrictionType, bool forceSelfOnly, bool searchChildren, bool allowProxy)
        {
            if (!ComponentUtil.IsAcceptableComponentType(restrictionType))
            {
                return(ArrayUtil.Empty <Component>());
            }

            var go = GetGameObjectFromSource(property, forceSelfOnly);

            if (go == null)
            {
                return(ArrayUtil.Empty <Component>());
            }

            if (allowProxy)
            {
                if (searchChildren)
                {
                    return((from c in go.GetComponentsInChildren <Component>() where ObjUtil.IsType(c, restrictionType) || c is IProxy select c).ToArray());
                }
                else
                {
                    return((from c in go.GetComponents <Component>() where ObjUtil.IsType(c, restrictionType) || c is IProxy select c).ToArray());
                }
            }
            else
            {
                if (searchChildren)
                {
                    return(go.GetComponentsInChildren(restrictionType));
                }
                else
                {
                    return(go.GetComponents(restrictionType));
                }
            }
        }
        private void DrawValueFieldInValueMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper)
        {
            if (helper.Target == null)
            {
                return;
            }
            var variant = helper.Target;

            if (this.RestrictVariantType && helper._type != this.VariantTypeRestrictedTo)
            {
                helper.PrepareForValueTypeChange(this.VariantTypeRestrictedTo);
                GUI.changed = true; //force change
            }

            var r0 = new Rect(position.xMin, position.yMin, 90.0f, EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(r0.xMax, position.yMin, position.xMax - r0.xMax, EditorGUIUtility.singleLineHeight);

            var cache = SPGUI.DisableIf(this.RestrictVariantType);

            EditorGUI.BeginChangeCheck();
            var valueType = (VariantType)EditorGUI.EnumPopup(r0, GUIContent.none, variant.ValueType);

            if (EditorGUI.EndChangeCheck())
            {
                helper.PrepareForValueTypeChange(valueType);
            }
            cache.Reset();

            if (_typeRestrictedTo.IsEnum)
            {
                variant.IntValue = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(_typeRestrictedTo, variant.IntValue)));
            }
            else
            {
                switch (valueType)
                {
                case VariantType.Null:
                    cache = SPGUI.Disable();
                    EditorGUI.TextField(r1, "Null");
                    cache.Reset();
                    break;

                case VariantType.String:
                    variant.StringValue = EditorGUI.TextField(r1, variant.StringValue);
                    break;

                case VariantType.Boolean:
                    variant.BoolValue = EditorGUI.Toggle(r1, variant.BoolValue);
                    break;

                case VariantType.Integer:
                    variant.IntValue = EditorGUI.IntField(r1, variant.IntValue);
                    break;

                case VariantType.Float:
                    variant.FloatValue = EditorGUI.FloatField(r1, variant.FloatValue);
                    break;

                case VariantType.Double:
                    variant.DoubleValue = ConvertUtil.ToDouble(EditorGUI.TextField(r1, variant.DoubleValue.ToString()));
                    break;

                case VariantType.Vector2:
                    variant.Vector2Value = EditorGUI.Vector2Field(r1, GUIContent.none, variant.Vector2Value);
                    break;

                case VariantType.Vector3:
                    variant.Vector3Value = EditorGUI.Vector3Field(r1, GUIContent.none, variant.Vector3Value);
                    break;

                case VariantType.Vector4:
                    variant.Vector4Value = EditorGUI.Vector4Field(r1, (string)null, variant.Vector4Value);
                    break;

                case VariantType.Quaternion:
                    variant.QuaternionValue = SPEditorGUI.QuaternionField(r1, GUIContent.none, variant.QuaternionValue);
                    break;

                case VariantType.Color:
                    variant.ColorValue = EditorGUI.ColorField(r1, variant.ColorValue);
                    break;

                case VariantType.DateTime:
                    variant.DateValue = ConvertUtil.ToDate(EditorGUI.TextField(r1, variant.DateValue.ToString()));
                    break;

                case VariantType.GameObject:
                    variant.GameObjectValue = EditorGUI.ObjectField(r1, variant.GameObjectValue, typeof(GameObject), true) as GameObject;
                    break;

                case VariantType.Component:
                {
                    _selectComponentDrawer.AllowNonComponents = false;
                    _selectComponentDrawer.RestrictionType    = _forcedObjectType;
                    _selectComponentDrawer.ShowXButton        = true;
                    var targProp = property.FindPropertyRelative("_unityObjectReference");
                    EditorGUI.BeginChangeCheck();
                    _selectComponentDrawer.OnGUI(r1, targProp);
                    if (EditorGUI.EndChangeCheck())
                    {
                        variant.ComponentValue = targProp.objectReferenceValue as Component;
                    }
                }
                break;

                case VariantType.Object:
                {
                    var obj = variant.ObjectValue;
                    if (ComponentUtil.IsAcceptableComponentType(_forcedObjectType))
                    {
                        if (obj is GameObject || obj is Component)
                        {
                            _selectComponentDrawer.AllowNonComponents = false;
                            _selectComponentDrawer.RestrictionType    = _forcedObjectType;
                            _selectComponentDrawer.ShowXButton        = true;
                            var targProp = property.FindPropertyRelative("_unityObjectReference");
                            EditorGUI.BeginChangeCheck();
                            _selectComponentDrawer.OnGUI(r1, targProp);
                            if (EditorGUI.EndChangeCheck())
                            {
                                variant.ObjectValue = targProp.objectReferenceValue as Component;
                            }
                        }
                        else
                        {
                            EditorGUI.BeginChangeCheck();
                            obj = EditorGUI.ObjectField(r1, obj, typeof(UnityEngine.Object), true);
                            if (EditorGUI.EndChangeCheck())
                            {
                                if (obj == null)
                                {
                                    variant.ObjectValue = null;
                                }
                                else if (TypeUtil.IsType(obj.GetType(), _forcedObjectType))
                                {
                                    variant.ObjectValue = obj;
                                }
                                else
                                {
                                    var go = GameObjectUtil.GetGameObjectFromSource(obj);
                                    if (go != null)
                                    {
                                        variant.ObjectValue = go.GetComponent(_forcedObjectType);
                                    }
                                    else
                                    {
                                        variant.ObjectValue = null;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        variant.ObjectValue = EditorGUI.ObjectField(r1, obj, _forcedObjectType, true);
                    }
                }
                break;

                case VariantType.LayerMask:
                {
                    variant.LayerMaskValue = SPEditorGUI.LayerMaskField(r1, GUIContent.none, (int)variant.LayerMaskValue);
                }
                break;

                case VariantType.Rect:
                {
                    variant.RectValue = EditorGUI.RectField(r1, variant.RectValue);
                }
                break;
                }
            }
        }
示例#11
0
 private void DrawObjectRefField(Rect position, SerializedProperty property)
 {
     if (ComponentUtil.IsAcceptableComponentType(_restrictionType))
     {
         var fieldObjType = (!this.SearchChildren && TypeUtil.IsType(_restrictionType, typeof(UnityEngine.Component))) ? _restrictionType : typeof(UnityEngine.GameObject);
         var obj          = EditorGUI.ObjectField(position, property.objectReferenceValue, fieldObjType, this.AllowSceneObject);
         if (this.ForceOnlySelf)
         {
             var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
             var ngo    = GameObjectUtil.GetGameObjectFromSource(obj);
             if (targGo == ngo ||
                 (this.SearchChildren && targGo.IsParentOf(ngo)))
             {
                 //property.objectReferenceValue = obj;
                 var o = obj;
                 if (this.SearchChildren && o == null)
                 {
                     o = ngo.GetComponentInChildren(_restrictionType);
                 }
                 property.objectReferenceValue = o;
             }
         }
         else
         {
             //property.objectReferenceValue = obj;
             //property.objectReferenceValue = ObjUtil.GetAsFromSource(_restrictionType, obj) as UnityEngine.Object;
             var o = ObjUtil.GetAsFromSource(_restrictionType, obj) as UnityEngine.Object;
             if (this.SearchChildren && o == null && GameObjectUtil.GetGameObjectFromSource(obj) != null)
             {
                 o = GameObjectUtil.GetGameObjectFromSource(obj).GetComponentInChildren(_restrictionType);
             }
             property.objectReferenceValue = o;
         }
     }
     else if (this.AllowNonComponents)
     {
         var fieldObjType = (TypeUtil.IsType(_restrictionType, typeof(UnityEngine.Object))) ? _restrictionType : typeof(UnityEngine.Object);
         var obj          = EditorGUI.ObjectField(position, property.objectReferenceValue, fieldObjType, this.AllowSceneObject);
         if (this.ForceOnlySelf)
         {
             var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
             var ngo    = GameObjectUtil.GetGameObjectFromSource(obj);
             if (targGo == ngo ||
                 (this.SearchChildren && targGo.IsParentOf(ngo)))
             {
                 //property.objectReferenceValue = obj;
                 //property.objectReferenceValue = ObjUtil.GetAsFromSource(_restrictionType, obj) as UnityEngine.Object;
                 var o = ObjUtil.GetAsFromSource(_restrictionType, obj) as UnityEngine.Object;
                 if (this.SearchChildren && o == null)
                 {
                     o = ngo.GetComponentInChildren(_restrictionType);
                 }
                 property.objectReferenceValue = o;
             }
         }
         else
         {
             //property.objectReferenceValue = obj;
             //property.objectReferenceValue = ObjUtil.GetAsFromSource(_restrictionType, obj) as UnityEngine.Object;
             var o = ObjUtil.GetAsFromSource(_restrictionType, obj) as UnityEngine.Object;
             if (this.SearchChildren && o == null && GameObjectUtil.GetGameObjectFromSource(obj) != null)
             {
                 o = GameObjectUtil.GetGameObjectFromSource(obj).GetComponentInChildren(_restrictionType);
             }
             property.objectReferenceValue = o;
         }
     }
     else
     {
         var ogo = GameObjectUtil.GetGameObjectFromSource(property.objectReferenceValue);
         var ngo = EditorGUI.ObjectField(position, ogo, typeof(GameObject), this.AllowSceneObject) as GameObject;
         if (ogo != ngo)
         {
             if (this.ForceOnlySelf)
             {
                 var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                 if (targGo == ngo ||
                     (this.SearchChildren && targGo.IsParentOf(ngo)))
                 {
                     //property.objectReferenceValue = ngo.GetComponent(_restrictionType);
                     //property.objectReferenceValue = ObjUtil.GetAsFromSource(_restrictionType, ngo) as UnityEngine.Object;
                     var o = ObjUtil.GetAsFromSource(_restrictionType, ngo) as UnityEngine.Object;
                     if (this.SearchChildren && o == null)
                     {
                         o = ngo.GetComponentInChildren(_restrictionType);
                     }
                     property.objectReferenceValue = o;
                 }
             }
             else
             {
                 //property.objectReferenceValue = (ngo == null) ? null : ngo.GetComponent(_restrictionType);
                 //property.objectReferenceValue = ObjUtil.GetAsFromSource(_restrictionType, ngo) as UnityEngine.Object;
                 var o = ObjUtil.GetAsFromSource(_restrictionType, ngo) as UnityEngine.Object;
                 if (this.SearchChildren && o == null)
                 {
                     o = ngo.GetComponentInChildren(_restrictionType);
                 }
                 property.objectReferenceValue = o;
             }
         }
     }
 }
        private static void ApplyDefaultAsSingle(SerializedProperty property, System.Type fieldType, System.Type restrictionType, EntityRelativity relativity)
        {
            if (fieldType == null)
            {
                return;
            }

            if (TypeUtil.IsType(fieldType, typeof(VariantReference)))
            {
                var variant = EditorHelper.GetTargetObjectOfProperty(property) as VariantReference;
                if (variant == null)
                {
                    return;
                }
                if (variant.Value != null)
                {
                    return;
                }

                var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                if (targ == null)
                {
                    var obj = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject);
                    if (obj != null)
                    {
                        variant.Value = obj;
                        property.serializedObject.Update();
                        GUI.changed = true;
                    }
                    return;
                }

                switch (relativity)
                {
                case EntityRelativity.Entity:
                {
                    targ = targ.FindRoot();

                    var obj = ObjUtil.GetAsFromSource(restrictionType, targ);
                    if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType))
                    {
                        obj = targ.GetComponentInChildren(restrictionType);
                    }
                    if (obj != null)
                    {
                        variant.Value = obj;
                        property.serializedObject.Update();
                    }
                }
                break;

                case EntityRelativity.Self:
                {
                    var obj = ObjUtil.GetAsFromSource(restrictionType, targ);
                    if (obj != null)
                    {
                        variant.Value = obj;
                        property.serializedObject.Update();
                    }
                }
                break;

                case EntityRelativity.SelfAndChildren:
                {
                    var obj = ObjUtil.GetAsFromSource(restrictionType, targ);
                    if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType))
                    {
                        obj = targ.GetComponentInChildren(restrictionType);
                    }
                    if (obj != null)
                    {
                        variant.Value = obj;
                        property.serializedObject.Update();
                    }
                }
                break;
                }
            }
            else if (property.propertyType == SerializedPropertyType.ObjectReference)
            {
                if (property.objectReferenceValue != null)
                {
                    return;
                }

                var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                if (targ == null)
                {
                    property.objectReferenceValue = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject) as UnityEngine.Object;
                    return;
                }

                switch (relativity)
                {
                case EntityRelativity.Entity:
                {
                    targ = targ.FindRoot();

                    var obj = ObjUtil.GetAsFromSource(restrictionType, targ) as UnityEngine.Object;
                    if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType))
                    {
                        obj = targ.GetComponentInChildren(restrictionType);
                    }
                    if (obj != null)
                    {
                        property.objectReferenceValue = obj;
                        GUI.changed = true;
                    }
                }
                break;

                case EntityRelativity.Self:
                {
                    var obj = ObjUtil.GetAsFromSource(restrictionType, targ) as UnityEngine.Object;
                    if (obj != null)
                    {
                        property.objectReferenceValue = obj;
                        GUI.changed = true;
                    }
                }
                break;

                case EntityRelativity.SelfAndChildren:
                {
                    var obj = ObjUtil.GetAsFromSource(restrictionType, targ) as UnityEngine.Object;
                    if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType))
                    {
                        obj = targ.GetComponentInChildren(restrictionType);
                    }
                    if (obj != null)
                    {
                        property.objectReferenceValue = obj;
                        GUI.changed = true;
                    }
                }
                break;
                }
            }
        }
示例#13
0
 private void DrawObjectRefField(Rect position, SerializedProperty property)
 {
     if (ComponentUtil.IsAcceptableComponentType(this.RestrictionType))
     {
         var fieldObjType = (!this.SearchChildren && !this.AllowProxy && TypeUtil.IsType(this.RestrictionType, typeof(UnityEngine.Component))) ? this.RestrictionType : typeof(UnityEngine.GameObject);
         var obj          = EditorGUI.ObjectField(position, property.objectReferenceValue, fieldObjType, this.AllowSceneObjects);
         if (this.ForceOnlySelf)
         {
             var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
             var ngo    = GameObjectUtil.GetGameObjectFromSource(obj);
             if (targGo == ngo ||
                 (this.SearchChildren && targGo.IsParentOf(ngo)))
             {
                 property.objectReferenceValue = this.GetTargetFromSource(obj);
             }
         }
         else
         {
             property.objectReferenceValue = this.GetTargetFromSource(obj);
         }
     }
     else if (this.AllowNonComponents)
     {
         var fieldObjType = (!this.AllowProxy && TypeUtil.IsType(this.RestrictionType, typeof(UnityEngine.Object))) ? this.RestrictionType : typeof(UnityEngine.Object);
         var obj          = EditorGUI.ObjectField(position, property.objectReferenceValue, fieldObjType, this.AllowSceneObjects);
         if (this.ForceOnlySelf)
         {
             var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
             var ngo    = GameObjectUtil.GetGameObjectFromSource(obj);
             if (targGo == ngo ||
                 (this.SearchChildren && targGo.IsParentOf(ngo)))
             {
                 property.objectReferenceValue = this.GetTargetFromSource(obj);
             }
         }
         else
         {
             property.objectReferenceValue = this.GetTargetFromSource(obj);
         }
     }
     else
     {
         var ogo = GameObjectUtil.GetGameObjectFromSource(property.objectReferenceValue);
         var ngo = EditorGUI.ObjectField(position, ogo, typeof(GameObject), this.AllowSceneObjects) as GameObject;
         if (ogo != ngo)
         {
             if (this.ForceOnlySelf)
             {
                 var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                 if (targGo == ngo ||
                     (this.SearchChildren && targGo.IsParentOf(ngo)))
                 {
                     property.objectReferenceValue = this.GetTargetFromSource(ngo);
                 }
             }
             else
             {
                 property.objectReferenceValue = this.GetTargetFromSource(ngo);
             }
         }
     }
 }
示例#14
0
        public void OnGUI(Rect position, SerializedProperty property)
        {
            //if (property.propertyType != SerializedPropertyType.ObjectReference || !TypeUtil.IsType(_restrictionType, typeof(Component), typeof(IComponent)))
            if (property.propertyType != SerializedPropertyType.ObjectReference || (!this.AllowNonComponents && !ComponentUtil.IsAcceptableComponentType(this.RestrictionType)))
            {
                this.DrawAsMismatchedAttribute(position, property);
                return;
            }

            this.Init();

            GameObject targGo;

            if (this.ForceOnlySelf)
            {
                targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                if (targGo == null)
                {
                    this.DrawAsMismatchedAttribute(position, property);
                    return;
                }

                if (property.objectReferenceValue == null)
                {
                    property.objectReferenceValue = this.GetTargetFromSource(targGo);
                }
            }

            targGo = GameObjectUtil.GetGameObjectFromSource(property.objectReferenceValue);
            if (property.objectReferenceValue == null)
            {
                //SPEditorGUI.DefaultPropertyField(position, property, label);
                if (!this.ForceOnlySelf)
                {
                    this.DrawObjectRefField(position, property);
                }
                else
                {
                    EditorGUI.LabelField(position, "Malformed serializable field.");
                }
            }
            else if (this.AllowNonComponents)
            {
                if (targGo == null)
                {
                    this.DrawObjectRefField(position, property);
                }
                else
                {
                    this.ChoiceSelector.BeforeGUI(this, property, this.ComponentRestrictionType, this.AllowProxy);
                    var components = this.ChoiceSelector.GetComponents();

                    var fullsize = position;
                    if (components.Length == 0 ||
                        (this.ShowXButton && SPEditorGUI.XButton(ref position, "Clear Selected Object", this.XButtonOnRightSide)))
                    {
                        property.objectReferenceValue = null;
                        fullsize = this.DrawDotDotButton(fullsize, property);
                        this.DrawObjectRefField(fullsize, property);

                        this.ChoiceSelector.GUIComplete(property, -1);
                    }
                    else
                    {
                        position = this.DrawDotDotButton(position, property);
                        var names = this.ChoiceSelector.GetPopupEntries();
                        System.Array.Resize(ref names, names.Length + 1);
                        names[names.Length - 1] = EditorHelper.TempContent(targGo.name + " (...GameObject)");

                        int oi = (property.objectReferenceValue is GameObject) ? names.Length - 1 : this.ChoiceSelector.GetPopupIndexOfComponent(property.objectReferenceValue as Component);
                        int ni = EditorGUI.Popup(position, oi, names);

                        if (oi != ni)
                        {
                            if (ni == names.Length - 1)
                            {
                                property.objectReferenceValue = targGo;
                            }
                            else
                            {
                                property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni);
                            }

                            //if (ni < components.Length)
                            //    property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni);
                            //else
                            //    property.objectReferenceValue = targGo;
                        }

                        this.ChoiceSelector.GUIComplete(property, ni);
                    }
                }
            }
            else
            {
                this.ChoiceSelector.BeforeGUI(this, property, this.ComponentRestrictionType, this.AllowProxy);
                var components = this.ChoiceSelector.GetComponents();

                var fullsize = position;
                if (components.Length == 0 ||
                    (this.ShowXButton && SPEditorGUI.XButton(ref position, "Clear Selected Object", this.XButtonOnRightSide)))
                {
                    property.objectReferenceValue = null;
                    fullsize = this.DrawDotDotButton(fullsize, property);
                    this.DrawObjectRefField(fullsize, property);

                    this.ChoiceSelector.GUIComplete(property, -1);
                }
                else
                {
                    position = this.DrawDotDotButton(position, property);
                    var names = this.ChoiceSelector.GetPopupEntries();
                    int oi    = this.ChoiceSelector.GetPopupIndexOfComponent(property.objectReferenceValue as Component);
                    int ni    = EditorGUI.Popup(position, oi, names);
                    if (oi != ni)
                    {
                        property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni);
                    }

                    this.ChoiceSelector.GUIComplete(property, ni);
                }
            }
        }
        private static void ApplyDefaultAsList(SerializedProperty property, System.Type elementType, string name, bool bUseEntity)
        {
            if (elementType == null)
            {
                return;
            }
            if (property.arraySize != 0)
            {
                return;
            }

            var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);

            if (targ == null)
            {
                return;
            }
            if (bUseEntity)
            {
                targ = targ.FindRoot();
            }

            if (TypeUtil.IsType(elementType, typeof(VariantReference)))
            {
                var arr = targ.transform.FindAllByName(name);
                if (arr.Length > 0)
                {
                    property.arraySize = arr.Length;
                    property.serializedObject.ApplyModifiedProperties();
                    for (int i = 0; i < arr.Length; i++)
                    {
                        var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference;
                        if (variant != null && variant.Value == null && variant.ValueType == VariantType.GameObject)
                        {
                            variant.GameObjectValue = arr[i].gameObject;
                        }
                    }
                    property.serializedObject.Update();
                }
            }
            else
            {
                if (ComponentUtil.IsAcceptableComponentType(elementType))
                {
                    using (var lst = TempCollection.GetList <Component>())
                    {
                        foreach (var child in targ.transform.FindAllByName(name))
                        {
                            child.GetComponents(elementType, lst);
                            if (lst.Count > 0)
                            {
                                int low = property.arraySize;
                                property.arraySize += lst.Count;
                                for (int i = 0; i < lst.Count; i++)
                                {
                                    property.GetArrayElementAtIndex(low + i).objectReferenceValue = lst[i];
                                }
                            }
                            lst.Clear();
                        }
                    }
                }
                else if (TypeUtil.IsType(elementType, typeof(GameObject)))
                {
                    var arr = targ.transform.FindAllByName(name);
                    if (arr.Length > 0)
                    {
                        property.arraySize = arr.Length;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i].gameObject;
                        }
                        property.serializedObject.ApplyModifiedProperties();
                    }
                }
            }
        }