Esempio n. 1
0
    public UIGenWindow(UIBinder binder)
    {
        _binder = binder;

        foreach (Transform trans in binder.gameObject.transform)
        {
            var ctrlBinder = trans.GetComponent <UIBinder>();
            if (ctrlBinder == null)
            {
                continue;
            }

            if (ctrlBinder.Type == CodeGenObjectType.Unknown)
            {
                continue;
            }

            if (!UIBinder.CheckName(trans.gameObject.name))
            {
                continue;
            }

            _controls.Add(new UIGenControl(this, ctrlBinder));
        }
    }
Esempio n. 2
0
            private static void UIBinderLoadPrefix(UIBinder __instance, out TranslationHookState __state)
            {
                var gameObject = __instance.gameObject;
                var path       = CombinePaths(gameObject.scene.path.Replace(".unity", ""), gameObject.name);

                BaseTextDumpPlugin.Logger.LogInfo($"[TextDump] Collecting UI info for {path}");
                var items      = EnumerateTextComponents(gameObject).ToList();
                var components = items.Select(t => t.Value).ToList();
                var scopes     = items.Select(t =>
                {
                    try
                    {
                        return(t.Key.scene.buildIndex);
                    }
                    catch
                    {
                        return(-1);
                    }
                }).ToList();


                __state = new TranslationHookState(path);

                __state.Context.Add(components);
                __state.Context.Add(scopes);
                var origValues = components.Select(GetTextFromSupportedComponent).ToList();

                __state.Context.Add(origValues);
                var origResizers = components.Select(GetTextResizerFromComponent).ToList();

                __state.Context.Add(origResizers);
            }
Esempio n. 3
0
            private static void UIBinderLoadPostfix(UIBinder __instance, TranslationHookState __state)
            {
                var gameObject = __instance.gameObject;
                var path       = __state.Path;

                var components   = (List <Component>)__state.Context[0];
                var scopes       = (List <int>)__state.Context[1];
                var origValues   = (List <string>)__state.Context[2];
                var origResizers = (List <XuaResizerResult>)__state.Context[3];

                var items = EnumerateTextComponents(gameObject).ToList();

                if (items.Count != components.Count)
                {
                    BaseTextDumpPlugin.Logger.LogWarning(
                        $"UIBinder {gameObject}: Component count has changed, may not be able to get all translations");
                }
                else
                {
                    components = items.Select(t => t.Value).ToList();
                }

                var results  = new TranslationDictionary();
                var resizers = new ResizerCollection();

                for (var i = 0; i < components.Count; i++)
                {
                    var key = origValues[i];
                    var val = GetTextFromSupportedComponent(components[i]);

                    var scope = scopes[i];
                    _instance.AddLocalizationToResults(results.GetScope(scope), key, val);


                    var currentResizer = GetTextResizerFromComponent(components[i]);

                    var resizePath = components[i].GetXuaResizerPath();
                    if (!string.IsNullOrEmpty(resizePath))
                    {
                        var delta          = currentResizer.Delta(origResizers[i]);
                        var scopedResizers = resizers.GetScope(scope);
                        scopedResizers[resizePath] = delta.GetDirectives().ToList();
                    }
                }

                var outputName = CombinePaths("Bind/UI", path);

                HookedTextLocalizationGenerators.Add(new StringTranslationDumper(outputName, () => results));
                HookedTextLocalizationGenerators.Add(new ResizerDumper(outputName, () => resizers));
            }
Esempio n. 4
0
    public override void OnInspectorGUI()
    {
        UIBinder binder = target as UIBinder;

        if (GUILayout.Button("Add Binder To Top Child"))
        {
            binder.AddBinderToAllTopChild();
        }

        if (GUILayout.Button("Remove All Top Child Binder"))
        {
            binder.RemoveAllTopChildBinder();
        }


        base.OnInspectorGUI();
    }
Esempio n. 5
0
    public override void OnInspectorGUI()
    {
        UIBinder binder = (UIBinder)target;

        // DrawDefaultInspector();
        EditorGUILayout.Space();
        serializedObject.Update();
        reorderableList.DoLayoutList();
        serializedObject.ApplyModifiedProperties();

        if (GUILayout.Button("查找对应组件"))
        {
            binder.FindComponent();
        }
        if (GUILayout.Button("生成绑定代码到剪贴板"))
        {
            binder.GenerateBindCode();
        }
    }
Esempio n. 6
0
    static void ScanWindowObject(UIBinder canvas)
    {
        if (canvas == null)
        {
            return;
        }

        foreach (Transform trans in canvas.transform)
        {
            var binder = trans.GetComponent <UIBinder>();
            if (binder == null)
            {
                continue;
            }

            if (binder.Type != CodeGenObjectType.GenAsWindow)
            {
                continue;
            }

            var win = new UIGenWindow(binder);

            // 代码目录预创建
            win.PrepareFolder();

            // 绑定代码
            {
                var text = win.PrintAutoBindCode();
                win.WriteFile(string.Format("{0}_AutoBind.cs", win.Name), text);
            }

            // 当主逻辑文件存在时, 不覆盖
            if (!win.MainLogicFileExists)
            {
                var text = win.PrintMainLogicCode();
                win.WriteFile(string.Format("{0}.cs", win.Name), text);
            }
        }
    }
Esempio n. 7
0
 public UIGenControl(UIGenWindow win, UIBinder binder)
 {
     _binder = binder;
     _window = win;
 }
Esempio n. 8
0
 private void AutoBindField()
 {
     binder = GameObject.GetComponent <UIBinder>();
     binder.RuntimeBind(this);
 }