Esempio n. 1
0
        // Fixes nulls in serialization manually...*sigh*.
        public override void OnDeserialization()
        {
            if (objID == null)
            {
                objID = new ObjectID();
            }
            objID.OnDeserialization();
            if (searchProperty == null)
            {
                searchProperty = new PropertyPopupData();
            }
            searchProperty.label = "Property:";

            if (propertyCriteria == null)
            {
                propertyCriteria = new DynamicTypeField();
            }
            propertyCriteria.searchItem = this;
            propertyCriteria.OnDeserialization(); // sigh...this is getting old.
            propertyCriteria.showMoreOptions = showMoreOptions;

            searchProperty.SetType(objID.obj);
            initializationContext = new InitializationContext(searchProperty.fieldData, objID.obj);
            if (searchProperty.HasOptions())
            {
                propertyCriteria.SetType(initializationContext);
            }
            if (searchDepth == 0)
            {
                root = this;
            }
            OnDeserializeSubSearch();
        }
Esempio n. 2
0
        public static bool ValidateAndAssign(UnityEngine.Object newObj, ObjectID objID, PropertyPopupData searchProperty, ref InitializationContext initializationContext)
        {
            // First we need to attempt validation, or find the 'real' object we are
            // interested in.
            UnityEngine.Object contextObj = newObj;
            bool objectValid = true;

            // If the object is a 'scene' object, let's get the prefab object if it
            // exists.
            if (newObj != null)
            {
                if (newObj.GetInstanceID() < 0)
                {
                    // Debug.Log("[SearchItemProperty] finding prefab.");
#if UNITY_2018_2_OR_NEWER
                    UnityEngine.Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(newObj);
#else
                    UnityEngine.Object prefab = PrefabUtility.GetPrefabParent(newObj);
#endif
                    if (prefab != null)
                    {
                        newObj = prefab;
                    }
                }
                PrefabTypes newObjPrefabType = PrefabUtil.GetPrefabType(newObj);
                if (newObjPrefabType == PrefabTypes.NotAPrefab)
                {
                    if (newObj is Component)
                    {
                        if (newObj is MonoBehaviour)
                        {
                            MonoScript script = MonoScript.FromMonoBehaviour((MonoBehaviour)newObj);
                            if (script != null)
                            {
                                newObj = script;
                            }
                        }
                    }
                }
            }

            if (newObj is MonoScript)
            {
                MonoScript m = (MonoScript)newObj;
                if (typeof(MonoBehaviour).IsAssignableFrom(m.GetClass()) || typeof(ScriptableObject).IsAssignableFrom(m.GetClass()))
                {
                    // Debug.Log("[SearchItemProperty] Valid monobehaviour"+m.GetClass());
                }
                else
                {
                    Debug.LogWarning("[Search And Replace] The object given does not contain a script.");
                    objectValid = false;
                }
            }

            //Ok, validation is complete, let's process the new object.
            if (objectValid)
            {
                objID.SetObject(newObj);
                searchProperty.SetType(objID.obj);
                initializationContext             = new InitializationContext(searchProperty.fieldData, contextObj);
                initializationContext.forceUpdate = true;
                SRWindow.Instance.PersistCurrentSearch();
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        public override void OnDeserialization()
        {
            popupLabel = "Replace Another Property";
            typeHash   = new Dictionary <Type, ReplaceItem>();

            if (objID == null)
            {
                objID = new ObjectID();
            }
            objID.OnDeserialization();
            if (searchProperty == null)
            {
                searchProperty = new PropertyPopupData();
            }
            searchProperty.label = "Property:";

            searchProperty.SetType(objID.obj);
            initializationContext = new InitializationContext(searchProperty.fieldData, objID.obj);
            initSubItem <ReplaceItemString>(new List <Type>()
            {
                typeof(string)
            }, ref replaceItemString);
            initSubItem <ReplaceItemFloat>(new List <Type>()
            {
                typeof(float)
            }, ref replaceItemFloat);
            initSubItem <ReplaceItemObject>(new List <Type>()
            {
                typeof(UnityEngine.Object)
            }, ref replaceItemObject);
            initSubItem <ReplaceItemInt>(new List <Type>()
            {
                typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(byte), typeof(sbyte),
            }, ref replaceItemInt);
            initSubItem <ReplaceItemDouble>(new List <Type>()
            {
                typeof(double)
            }, ref replaceItemDouble);
            initSubItem <ReplaceItemBool>(new List <Type>()
            {
                typeof(bool)
            }, ref replaceItemBool);
            initSubItem <ReplaceItemChar>(new List <Type>()
            {
                typeof(char)
            }, ref replaceItemChar);
            initSubItem <ReplaceItemVector2>(new List <Type>()
            {
                typeof(Vector2)
            }, ref replaceItemVector2);
            initSubItem <ReplaceItemVector3>(new List <Type>()
            {
                typeof(Vector3)
            }, ref replaceItemVector3);
            initSubItem <ReplaceItemVector4>(new List <Type>()
            {
                typeof(Vector4)
            }, ref replaceItemVector4);
            initSubItem <ReplaceItemRect>(new List <Type>()
            {
                typeof(Rect)
            }, ref replaceItemRect);
            initSubItem <ReplaceItemColor>(new List <Type>()
            {
                typeof(Color), typeof(Color32)
            }, ref replaceItemColor);
            initSubItem <ReplaceItemQuaternion>(new List <Type>()
            {
                typeof(Quaternion)
            }, ref replaceItemQuaternion);
            initSubItem <ReplaceItemEnum>(new List <Type>()
            {
                typeof(Enum)
            }, ref replaceItemEnum);

            type = null;
            if (objID.obj != null)
            {
                setType(initializationContext.fieldData.fieldType);
            }
        }