Example #1
0
    private void OnEnable()
    {
        m_Target    = (ComponentAutoBindTool)target;
        m_BindDatas = serializedObject.FindProperty("BindDatas");
        m_BindComs  = serializedObject.FindProperty("m_BindComs");

        m_HelperTypeNames = GetTypeNames(typeof(IAutoBindRuleHelper), s_AssemblyNames);

        string[] paths = AssetDatabase.FindAssets("t:AutoBindGlobalSetting");
        if (paths.Length == 0)
        {
            Debug.LogError("不存在AutoBindGlobalSetting");
            return;
        }
        if (paths.Length > 1)
        {
            Debug.LogError("AutoBindGlobalSetting数量大于1");
            return;
        }
        string path = AssetDatabase.GUIDToAssetPath(paths[0]);

        m_Setting = AssetDatabase.LoadAssetAtPath <AutoBindGlobalSetting>(path);


        m_Namespace = serializedObject.FindProperty("m_Namespace");
        m_ClassName = serializedObject.FindProperty("m_ClassName");
        m_CodePath  = serializedObject.FindProperty("m_CodePath");

        m_Namespace.stringValue = string.IsNullOrEmpty(m_Namespace.stringValue) ? m_Setting.Namespace : m_Namespace.stringValue;
        m_ClassName.stringValue = string.IsNullOrEmpty(m_ClassName.stringValue) ? m_Target.gameObject.name : m_ClassName.stringValue;
        m_CodePath.stringValue  = string.IsNullOrEmpty(m_CodePath.stringValue) ? m_Setting.CodePath : m_CodePath.stringValue;

        serializedObject.ApplyModifiedProperties();
    }
Example #2
0
    private void BindComponent(GameObject go)
    {
        ComponentAutoBindTool autoBindTool = go.GetComponent <ComponentAutoBindTool>();

        m_Img_Test = autoBindTool.GetObj <Image>(0);
        m_Btn_Test = autoBindTool.GetObj <Button>(1);
        m_Txt_Test = autoBindTool.GetObj <Text>(2);
    }
Example #3
0
    private void GetBindComponents(GameObject go)
    {
        ComponentAutoBindTool autoBindTool = go.GetComponent <ComponentAutoBindTool>();

        m_Img_Test1  = autoBindTool.GetBindComponent <Image>(0);
        m_Btn_Test2  = autoBindTool.GetBindComponent <Button>(1);
        m_Txt_Test3  = autoBindTool.GetBindComponent <Text>(2);
        m_Drop_Test4 = autoBindTool.GetBindComponent <Dropdown>(3);
        m_Img_Test4  = autoBindTool.GetBindComponent <Image>(4);
    }
Example #4
0
    /// <summary>
    /// 绘制辅助器选择框
    /// </summary>
    private void DrawHelperSelect()
    {
        m_HelperTypeName = m_HelperTypeNames[0];

        if (m_Target.RuleHelper != null)
        {
            m_HelperTypeName = m_Target.RuleHelper.GetType().Name;

            for (int i = 0; i < m_HelperTypeNames.Length; i++)
            {
                if (m_HelperTypeName == m_HelperTypeNames[i])
                {
                    m_HelperTypeNameIndex = i;
                }
            }
        }
        else
        {
            IAutoBindRuleHelper helper = (IAutoBindRuleHelper)CreateHelperInstance(m_HelperTypeName, s_AssemblyNames);
            m_Target.RuleHelper = helper;
        }

        foreach (GameObject go in Selection.gameObjects)
        {
            ComponentAutoBindTool autoBindTool = go.GetComponent <ComponentAutoBindTool>();
            if (autoBindTool.RuleHelper == null)
            {
                IAutoBindRuleHelper helper = (IAutoBindRuleHelper)CreateHelperInstance(m_HelperTypeName, s_AssemblyNames);
                autoBindTool.RuleHelper = helper;
            }
        }

        int selectedIndex = EditorGUILayout.Popup("AutoBindRuleHelper", m_HelperTypeNameIndex, m_HelperTypeNames);

        if (selectedIndex != m_HelperTypeNameIndex)
        {
            m_HelperTypeNameIndex = selectedIndex;
            m_HelperTypeName      = m_HelperTypeNames[selectedIndex];
            IAutoBindRuleHelper helper = (IAutoBindRuleHelper)CreateHelperInstance(m_HelperTypeName, s_AssemblyNames);
            m_Target.RuleHelper = helper;
        }
    }
Example #5
0
        /// <summary>
        /// 排序
        /// </summary>
        private void Sort()
        {
            ComponentAutoBindTool target = (ComponentAutoBindTool)this.target;

            m_TempList.Clear();
            foreach (BindData data in target.BindDatas)
            {
                m_TempList.Add(new BindData(data.Name, data.BindCom));
            }
            m_TempList.Sort((x, y) =>
            {
                return(string.Compare(x.Name, y.Name, StringComparison.Ordinal));
            });

            m_BindDatas.ClearArray();
            foreach (BindData data in m_TempList)
            {
                AddBindData(data.Name, data.BindCom);
            }

            SyncBindComs();
        }
Example #6
0
        private void GenAutoBindCode(string codePath, GameObject go, string nameSpace, string nameEx = "")
        {
            ComponentAutoBindTool bindTool = go.GetComponent <ComponentAutoBindTool>();

            if (bindTool == null)
            {
                return;
            }

            if (!Directory.Exists($"{codePath}/BindComponents/"))
            {
                Directory.CreateDirectory($"{codePath}/BindComponents/");
            }

            using (StreamWriter sw = new StreamWriter($"{codePath}/BindComponents/{go.name}{nameEx}.BindComponents.cs"))
            {
                sw.WriteLine("using UnityEngine;");
                if (m_GenCodeType == GenCodeType.UIForm)
                {
                    sw.WriteLine("using UnityEngine.UI;");
                }
                sw.WriteLine("");

                sw.WriteLine("//自动生成于:" + DateTime.Now);

                //命名空间
                sw.WriteLine("namespace " + nameSpace);
                sw.WriteLine("{");
                sw.WriteLine("");

                //类名
                sw.WriteLine($"\tpublic partial class {go.name}{nameEx}");
                sw.WriteLine("\t{");
                sw.WriteLine("");


                foreach (BindData data in bindTool.BindDatas)
                {
                    sw.WriteLine($"\t\tprivate {data.BindCom.GetType().Name} m_{data.Name};");
                }
                sw.WriteLine("");

                sw.WriteLine("\t\tprivate void GetBindComponents(GameObject go)");
                sw.WriteLine("\t\t{");

                //获取绑定的组件
                sw.WriteLine($"\t\t\tComponentAutoBindTool autoBindTool = go.GetComponent<ComponentAutoBindTool>();;");
                sw.WriteLine("");

                //根据索引获取

                for (int i = 0; i < bindTool.BindDatas.Count; i++)
                {
                    BindData data      = bindTool.BindDatas[i];
                    string   filedName = $"m_{data.Name}";
                    sw.WriteLine($"\t\t\t{filedName} = autoBindTool.GetBindComponent<{data.BindCom.GetType().Name}>({i});");
                }



                sw.WriteLine("\t\t}");

                sw.WriteLine("");

                sw.WriteLine("\t}");

                sw.WriteLine("}");
            }
        }