예제 #1
0
        void PopulateRefs()
        {
            _refsToRemove.Clear();
            _refs.Clear();
            foreach (var r in SmartDataRegistry.GetSmartReferences())
            {
                if (!r.Key.IsAlive)
                {
                    // Mark ref for removal
                    _refsToRemove.Add(r.Key);
                    continue;
                }

                BindingFlags binding       = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
                SmartRefBase smartRef      = (SmartRefBase)r.Key.Target;
                bool         useMultiIndex = false;
                bool         writeable     = false;
                SmartBase    smart         = SmartRefBase._EDITOR_GetSmartObject(r.Value, smartRef, out useMultiIndex, out writeable);

                if (smart == target)
                {
                    try {
                        Component      owner = (Component)r.Value.GetFieldPrivate("_owner", binding).GetValue(smartRef);
                        string         pPath = ((string)r.Value.GetFieldPrivate("_propertyPath", binding).GetValue(smartRef)).Replace(".Array.data", "");
                        List <RefData> data  = null;
                        if (!_refs.TryGetValue(owner.gameObject, out data))
                        {
                            data = new List <RefData>();
                            _refs.Add(owner.gameObject, data);
                        }
                        data.Add(new RefData(string.Format("{0}.{1}", owner.GetType().Name, pPath), writeable));
                                        #pragma warning disable 0168
                    } catch (MissingReferenceException e) {
                        // Gameobject probably destroyed - remove ref from registry.
                        _refsToRemove.Add(r.Key);
                        continue;
                    }
                                        #pragma warning restore 0168
                }
            }
            // Sweep marked refs
            foreach (var r in _refsToRemove)
            {
                SmartData.Editors.SmartDataRegistry.UnregisterReference(r);
            }
        }
        void PopulateRefs()
        {
            _refsToRemove.Clear();
            _refs.Clear();
            foreach (var r in SmartDataRegistry.GetSmartReferences())
            {
                if (!r.Key.IsAlive)
                {
                    // Mark ref for removal
                    _refsToRemove.Add(r.Key);
                    continue;
                }

                BindingFlags binding       = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
                SmartRefBase smartRef      = (SmartRefBase)r.Key.Target;
                bool         useMultiIndex = false;
                bool         writeable     = false;
                SmartBase    smart         = SmartRefBase._EDITOR_GetSmartObject(r.Value, smartRef, out useMultiIndex, out writeable);

                if (smart == target)
                {
                    ISmartRefOwnerRedirect redirect = null;
                    try {
                        Object owner    = (Object)r.Value.GetFieldPrivate("_owner", binding).GetValue(smartRef);
                        string typeName = owner.GetType().Name;
                        if (owner is ISmartRefOwnerRedirect)
                        {
                            redirect = (owner as ISmartRefOwnerRedirect);
                            var redirectedOwner = redirect.GetSmartRefOwner();
                            if (redirectedOwner)
                            {
                                owner    = redirect.GetSmartRefOwner();
                                typeName = redirect.GetOwnerType().Name;
                            }
                            else
                            {
                                // ISmartRefOwnerRedirect probably hasn't had its owner populated yet
                                Debug.LogWarning("Warning: ISmartRefOwnerRedirect owner probably null", redirect as Object);
                                typeName = "MISSING REDIRECT FROM " + typeName;
                            }
                        }
                        else if (owner is Component)
                        {
                            owner    = (owner as Component).gameObject;
                            typeName = typeof(GameObject).Name;
                        }
                        string         pPath = ((string)r.Value.GetFieldPrivate("_propertyPath", binding).GetValue(smartRef)).Replace(".Array.data", "");
                        List <RefData> data  = null;
                        if (!_refs.TryGetValue(owner, out data))
                        {
                            data = new List <RefData>();
                            _refs.Add(owner, data);
                        }
                        data.Add(new RefData(string.Format("{0}.{1}", typeName, pPath), writeable));
                                        #pragma warning disable 0168
                    } catch (MissingReferenceException e) {
                        // Gameobject probably destroyed - remove ref from registry.
                        _refsToRemove.Add(r.Key);
                        continue;
                    }
                                        #pragma warning restore 0168
                }
            }
            // Sweep marked refs
            foreach (var r in _refsToRemove)
            {
                SmartData.Editors.SmartDataRegistry.UnregisterReference(r);
            }
        }