Beispiel #1
0
 protected override void OnEnable()
 {
     base.OnEnable();
     titleContent = new GUIContent("duktape.json");
     _prefs       = Prefs.Load();
     _assemblies  = AppDomain.CurrentDomain.GetAssemblies();
 }
Beispiel #2
0
        public static void InvokeReflectBinding(ScriptRuntime runtime)
        {
            var bm = new BindingManager(Prefs.Load(), new ReflectBindingCallback(runtime));

            bm.Collect();
            bm.Generate(TypeBindingFlags.None);
            bm.Report();
        }
Beispiel #3
0
        static EditorRuntime()
        {
            var prefs = Prefs.Load();

            if (prefs.editorScripting)
            {
                _instance = new EditorRuntime();
            }
        }
Beispiel #4
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _ready = true;
         var prefs = Prefs.Load();
         _runtime.EvalMain(prefs?.editorEntryPoint);
     }
 }
Beispiel #5
0
        public static void GenerateTypeDefinition()
        {
            var bm = new BindingManager(Prefs.Load());

            bm.Collect();
            bm.Generate(TypeBindingFlags.TypeDefinition);
            bm.Cleanup();
            bm.Report();
            AssetDatabase.Refresh();
        }
Beispiel #6
0
        public static void GenerateBindingsAndTypeDefinition()
        {
            var bm = new BindingManager(Prefs.Load(), new DefaultBindingCallback());

            bm.Collect();
            bm.Generate(TypeBindingFlags.Default);
            bm.Cleanup();
            bm.Report();
            AssetDatabase.Refresh();
        }
Beispiel #7
0
 public void OnComplete(ScriptRuntime runtime)
 {
     if (!runtime.isWorker)
     {
         _ready = true;
         var prefs = Prefs.Load();
         if (prefs != null && !string.IsNullOrEmpty(prefs.editorEntryPoint))
         {
             _runtime.EvalMain(prefs.editorEntryPoint);
         }
     }
 }
Beispiel #8
0
        public static void ClearBindings()
        {
            var prefs = Prefs.Load();
            var kv    = new Dictionary <string, List <string> >();

            foreach (var dir in prefs.cleanupDir)
            {
                var pdir = ReplacePathVars(dir);
                kv[pdir] = new List <string>();
            }
            BindingManager.Cleanup(kv, null);
            AssetDatabase.Refresh();
        }
        private JSScriptFinder GetScriptFinder()
        {
            if (_finder == null)
            {
                var baseDir = Prefs.Load().sourceDir;
                _finder = new JSScriptFinder(baseDir);

                //TODO: need optimization, make the full collecting process async, and wait it finished
                _finder.Start();
            }

            return(_finder);
        }
Beispiel #10
0
 public static bool IsReflectBindingSupported()
 {
     return(Prefs.Load().reflectBinding);
 }
Beispiel #11
0
        protected override void OnPaint()
        {
            EditorGUILayout.HelpBox("(experimental) Editor for duktape.json", MessageType.Warning);
            EditorGUILayout.BeginHorizontal();
            Block("Assemblies", () =>
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Preview", GUILayout.Width(60f));
                EditorGUILayout.LabelField("Binding", GUILayout.Width(100f));
                EditorGUILayout.LabelField("Assembly Name");
                EditorGUILayout.EndHorizontal();
                _sv = EditorGUILayout.BeginScrollView(_sv);
                for (var i = 0; i < _assemblies.Length; i++)
                {
                    var a       = _assemblies[i];
                    var name    = a.GetName().Name;
                    var pMethod = BindingGenMethod.None;
                    if (_prefs.implicitAssemblies.Contains(name))
                    {
                        pMethod = BindingGenMethod.Implicit;
                    }
                    else if (_prefs.explicitAssemblies.Contains(name))
                    {
                        pMethod = BindingGenMethod.Explicit;
                    }
                    EditorGUI.BeginDisabledGroup(a.IsDynamic);
                    EditorGUILayout.BeginHorizontal();
                    var tRect    = EditorGUILayout.GetControlRect(GUILayout.Width(60f));
                    tRect.xMin   = tRect.xMax - 20f;
                    var selected = EditorGUI.Toggle(tRect, _selectedIndex == i);
                    var rMethod  = (BindingGenMethod)EditorGUILayout.EnumPopup(pMethod, GUILayout.Width(100f));
                    if (selected)
                    {
                        if (_selectedIndex != i)
                        {
                            _selectedIndex = i;
                            FilterTypes();
                        }
                    }
                    EditorGUILayout.TextField(name);
                    if (rMethod != pMethod)
                    {
                        switch (rMethod)
                        {
                        case BindingGenMethod.None:
                            if (pMethod == BindingGenMethod.Implicit)
                            {
                                _prefs.implicitAssemblies.Remove(name);
                                _prefs.MarkAsDirty();
                            }
                            else if (pMethod == BindingGenMethod.Explicit)
                            {
                                _prefs.explicitAssemblies.Remove(name);
                                _prefs.MarkAsDirty();
                            }
                            break;

                        case BindingGenMethod.Implicit:
                            if (pMethod == BindingGenMethod.Explicit)
                            {
                                _prefs.explicitAssemblies.Remove(name);
                            }
                            _prefs.implicitAssemblies.Add(name);
                            _prefs.MarkAsDirty();
                            break;

                        case BindingGenMethod.Explicit:
                            if (pMethod == BindingGenMethod.Implicit)
                            {
                                _prefs.implicitAssemblies.Remove(name);
                            }
                            _prefs.explicitAssemblies.Add(name);
                            _prefs.MarkAsDirty();
                            break;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUILayout.EndScrollView();
            }, () =>
            {
                var color = GUI.color;
                GUI.color = Color.green;
                if (GUILayout.Button("R", GUILayout.Width(20f)))
                {
                    if (EditorUtility.DisplayDialog("Reload", "Reload duktape.json?", "ok", "cancel"))
                    {
                        Defer(() => _prefs = Prefs.Load());
                    }
                }
                GUI.color = color;
            }, () =>
            {
                var color = GUI.color;
                GUI.color = Color.yellow;
                if (GUILayout.Button("G", GUILayout.Width(20f)))
                {
                    if (EditorUtility.DisplayDialog("Generate", "Generate all binding code?", "ok", "cancel"))
                    {
                        Defer(() => UnityHelper.GenerateBindingsAndTypeDefinition());
                    }
                }
                GUI.color = color;
            }, () =>
            {
                var color = GUI.color;
                GUI.color = Color.red;
                if (GUILayout.Button("C", GUILayout.Width(20f)))
                {
                    if (EditorUtility.DisplayDialog("Cleanup", "Cleanup generated binding code?", "ok", "cancel"))
                    {
                        Defer(() => UnityHelper.ClearBindings());
                    }
                }
                GUI.color = color;
            });
            EditorGUILayout.BeginVertical();
            Block("Assembly Info", () =>
            {
                if (_selectedIndex >= 0 && _selectedIndex < _assemblies.Length)
                {
                    var assembly = _assemblies[_selectedIndex];
                    EditorGUILayout.TextField("Full Name", assembly.FullName);
                    EditorGUILayout.TextField("Location", assembly.Location, GUILayout.MinWidth(500f));
                }
            });
            Block("Types", () =>
            {
                var count = _filteredTypes.Count;
                for (var i = 0; i < count; i++)
                {
                    var type = _filteredTypes[i];
                    EditorGUILayout.TextField(type.FullName);
                }
                if (count == 0)
                {
                    EditorGUILayout.HelpBox("No type to bindgen.", MessageType.Info);
                }
            });
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }