internal RuntimeUnityEditorCore(MonoBehaviour pluginObject, ILoggerWrapper logger, string configPath)
        {
            if (Instance != null)
            {
                throw new InvalidOperationException("Can only create one instance of the Core object");
            }

            CompositeResolver.RegisterAndSetAsDefault(GeneratedResolver.Instance, BuiltinResolver.Instance, PrimitiveObjectResolver.Instance);

            PluginObject = pluginObject;
            Logger       = logger;
            Instance     = this;

            InitNativeGUI();

            Inspector = new Inspector.Inspector(targetTransform => TreeViewer.SelectAndShowObject(targetTransform));

            TreeViewer = new ObjectTreeViewer(pluginObject);
            TreeViewer.InspectorOpenCallback = items =>
            {
                Inspector.InspectorClear();
                foreach (var stackEntry in items)
                {
                    Inspector.InspectorPush(stackEntry);
                }
            };

            if (UnityFeatureHelper.SupportsVectrosity)
            {
                GizmoDrawer = new GizmoDrawer(pluginObject);
                TreeViewer.TreeSelectionChangedCallback = transform => GizmoDrawer.UpdateState(transform);
            }

            if (UnityFeatureHelper.SupportsCursorIndex &&
                UnityFeatureHelper.SupportsXml)
            {
                try
                {
                    Repl = new ReplWindow(Path.Combine(configPath, "RuntimeUnityEditor.Autostart.cs"));
                    Repl.RunAutostart();
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.Warning, "Failed to load REPL - " + ex.Message);
                }
            }
        }
예제 #2
0
        public void Setup(ILoggerWrapper logger)
        {
            INSTANCE = this;
            LOGGER   = logger;

            SettingsData = SettingsManager.LoadOrCreate();
            DnSpyHelper.SetPath(SettingsData.DNSpyPath, false);

            SettingsViewer = new SettingsViewer();
            TreeViewer     = new ObjectTreeViewer(this, _gameObjectSearcher)
            {
                InspectorOpenCallback = items =>
                {
                    Inspector.InspectorClear();
                    foreach (var stackEntry in items)
                    {
                        Inspector.InspectorPush(stackEntry);
                    }
                }
            };

            _gizmoDrawer = new GizmoDrawer(this);
            TreeViewer.TreeSelectionChangedCallback = transform => _gizmoDrawer.UpdateState(transform);
            RegisterWindow(TreeViewer);

            if (UnityFeatureHelper.SupportsCursorIndex && UnityFeatureHelper.SupportsXml)
            {
                try
                {
                    Repl = new ReplWindow("RuntimeUnityEditor.Autostart.cs");
                    Repl.RunAutostart();
                    windows.Add(Repl);
                }
                catch (Exception ex)
                {
                    LOGGER.Log(LogLevel.Warning, "Failed to load REPL - " + ex.Message);
                }
            }

            Inspector = new Inspector.Inspector(targetTransform => TreeViewer.SelectAndShowObject(targetTransform), Repl);
            RegisterWindow(Inspector);

            PinnedVariablesData   = new PinnedVariablesData();
            PinnedVariablesViewer = new PinnedVariablesViewer(PinnedVariablesData);
            RegisterWindow(PinnedVariablesViewer);
        }
예제 #3
0
        public RuntimeUnityEditorCore(MonoBehaviour pluginObject, ILoggerWrapper logger)
        {
            if (Instance != null)
            {
                throw new InvalidOperationException("Can only create one instance of the Core object");
            }

            PluginObject = pluginObject;
            Logger       = logger;
            Instance     = this;

            Inspector = new Inspector.Inspector(targetTransform => TreeViewer.SelectAndShowObject(targetTransform));

            TreeViewer = new ObjectTreeViewer(pluginObject);
            TreeViewer.InspectorOpenCallback = items =>
            {
                Inspector.InspectorClear();
                foreach (var stackEntry in items)
                {
                    Inspector.InspectorPush(stackEntry);
                }
            };

            if (Utils.UnityFeatureHelper.SupportsVectrosity)
            {
                GizmoDrawer = new GizmoDrawer(pluginObject);
                TreeViewer.TreeSelectionChangedCallback = transform => GizmoDrawer.UpdateState(transform);
            }

            if (Utils.UnityFeatureHelper.SupportsCursorIndex &&
                Utils.UnityFeatureHelper.SupportsXml)
            {
                try
                {
                    Repl = new ReplWindow();
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.Warning, "Failed to load REPL - " + ex.Message);
                }
            }
        }
            private void CacheAllMembers(InstanceStackEntry entry)
            {
                _fieldCache.Clear();

                var objectToOpen = entry?.Instance;

                if (objectToOpen == null)
                {
                    return;
                }

                var type = objectToOpen.GetType();

                try
                {
                    if (objectToOpen is Component cmp)
                    {
                        _fieldCache.Add(new CallbackCacheEntry("Open in Scene Object Browser",
                                                               "Navigate to GameObject this Component is attached to",
                                                               () => Inspector._treeListShowCallback(cmp.transform)));
                    }
                    else if (objectToOpen is GameObject castedObj)
                    {
                        _fieldCache.Add(new CallbackCacheEntry("Open in Scene Object Browser",
                                                               "Navigate to this object in the Scene Object Browser",
                                                               () => Inspector._treeListShowCallback(castedObj.transform)));
                        _fieldCache.Add(new ReadonlyCacheEntry("Child objects",
                                                               castedObj.transform.Cast <Transform>().ToArray()));
                        _fieldCache.Add(new ReadonlyCacheEntry("Components", castedObj.GetComponents <Component>()));
                    }

                    // If we somehow enter a string, this allows user to see what the string actually says
                    if (type == typeof(string))
                    {
                        _fieldCache.Add(new ReadonlyCacheEntry("this", objectToOpen));
                    }
                    else if (objectToOpen is Transform)
                    {
                        // Prevent the list overloads from listing subcomponents
                    }
                    else if (objectToOpen is IList list)
                    {
                        for (var i = 0; i < list.Count; i++)
                        {
                            _fieldCache.Add(new ListCacheEntry(list, i));
                        }
                    }
                    else if (objectToOpen is IEnumerable enumerable)
                    {
                        _fieldCache.AddRange(enumerable.Cast <object>()
                                             .Select((x, y) => x is ICacheEntry ? x : new ReadonlyListCacheEntry(x, y))
                                             .Cast <ICacheEntry>());
                    }

                    // No need if it's not a value type, only used to propagate changes back so it's redundant with classes
                    var parent = entry.Parent?.Type().IsValueType == true ? entry.Parent : null;

                    // Instance members
                    _fieldCache.AddRange(type.GetAllFields(false)
                                         .Where(f => !f.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                         .Select(f => new FieldCacheEntry(objectToOpen, f, parent)).Cast <ICacheEntry>());
                    _fieldCache.AddRange(type.GetAllProperties(false)
                                         .Where(f => !f.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                         .Select(p => new PropertyCacheEntry(objectToOpen, p, parent)).Cast <ICacheEntry>());
                    _fieldCache.AddRange(MethodsToCacheEntries(objectToOpen, type, type.GetAllMethods(false)));

                    CacheStaticMembersHelper(type);
                }
                catch (Exception ex)
                {
                    RuntimeUnityEditorCore.Logger.Log(LogLevel.Warning, "[Inspector] CacheFields crash: " + ex);
                }
            }