Example #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);
            }
        }
        public static List <SmartGraphConnection> FindAllEvents()
        {
            List <SmartGraphConnection> calls = new List <SmartGraphConnection>();

            #region SmartRefs
            _refsToRemove.Clear();
            var refs = SmartData.Editors.SmartDataRegistry.GetSmartReferences();
            foreach (var r in refs)
            {
                if (!r.Key.IsAlive)
                {
                    // Mark ref for removal
                    _refsToRemove.Add(r.Key);
                    continue;
                }

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

                if (smart != null)
                {
                    string recMeta = "";
                    if (useMultiIndex)
                    {
                        FieldInfo multiIndex = r.Value.GetFieldPrivate("_multiIndex", binding);
                        if (multiIndex != null)
                        {
                            recMeta = string.Format("[{0}] ", multiIndex.GetValue(target));
                        }
                    }
                    recMeta += (writeable ? "Read / Write" : "Read Only");
                    Component owner = (Component)r.Value.GetFieldPrivate("_owner", binding).GetValue(target);

                    try {
                        calls.Add(
                            new SmartGraphConnection(
                                owner.gameObject,
                                smart, target,
                                string.Format("{0}::{1}", owner.GetType().Name, ((string)r.Value.GetFieldPrivate("_propertyPath", binding).GetValue(target)).Replace(".Array.data", "")),
                                recMeta, null, !writeable, false
                                )
                            );
                                        #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);
            }
            #endregion

            #region Get links from Multis to persistent child Vars
            var tm = typeof(SmartData.Abstract.SmartMultiBase);
            foreach (var a in SmartData.Editors.SmartDataRegistry.GetSmartDatas())
            {
                if (tm.IsAssignableFrom(a.Value))
                {
                    var persistent = (System.Array)a.Key.GetType().GetFieldPrivate("_persistent", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(a.Key);
                    if (persistent != null)
                    {
                        int i = 0;
                        foreach (var p in persistent)
                        {
                            var rec = p as Object;
                            calls.Add(
                                new SmartGraphConnection(
                                    a.Key,
                                    rec,
                                    null,
                                    string.Format("[{0}]", i),
                                    string.Format("Multi[{0}]", i), null, false, false
                                    )
                                );
                            ++i;
                        }
                    }
                }
            }
            #endregion

            return(calls);
        }
        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);
            }
        }