/// <summary>
    /// 初始化
    /// </summary>
    /// <param name="assemblyName">窗口类所在的程序集</param>
    public void Initialize(string assemblyName)
    {
        if (string.IsNullOrEmpty(assemblyName))
        {
            throw new ArgumentNullException();
        }
        _assemblyName = assemblyName;

        List <Type> types = AssemblyUtility.GetAssignableAttributeTypes(assemblyName, typeof(UIWindow), typeof(WindowAttribute));

        for (int i = 0; i < types.Count; i++)
        {
            System.Type     type      = types[i];
            WindowAttribute attribute = Attribute.GetCustomAttribute(type, typeof(WindowAttribute)) as WindowAttribute;

            // 判断是否重复
            if (_types.ContainsKey(attribute.WindowType))
            {
                throw new Exception($"Window type {attribute.WindowType} already exist.");
            }

            // 添加到集合
            _types.Add(attribute.WindowType, type);
        }
    }
Esempio n. 2
0
        /// <summary>
        /// 初始化控制台
        /// </summary>
        /// <param name="assemblyName">扩展的控制台窗口所在的程序集</param>
        public static void Initialize(bool showFPS = true, string assemblyName = AssemblyUtility.UnityDefaultAssemblyName)
        {
            if (showFPS)
            {
                _fpsCounter = new FPSCounter();
            }

            // 加载背景纹理
            string textureName = "console_background";

            _bgTexture = Resources.Load <Texture>(textureName);
            if (_bgTexture == null)
            {
                UnityEngine.Debug.LogWarning($"Not found {textureName} texture in Resources folder.");
            }

            // 获取所有控制台窗口类
            List <Type> types = AssemblyUtility.GetAssignableAttributeTypes(AssemblyUtility.MotionFrameworkAssemblyName, typeof(IConsoleWindow), typeof(ConsoleAttribute));
            List <Type> temps = AssemblyUtility.GetAssignableAttributeTypes(assemblyName, typeof(IConsoleWindow), typeof(ConsoleAttribute));

            types.AddRange(temps);
            for (int i = 0; i < types.Count; i++)
            {
                ConsoleAttribute attribute = (ConsoleAttribute)Attribute.GetCustomAttribute(types[i], typeof(ConsoleAttribute));
                WindowWrapper    wrapper   = new WindowWrapper()
                {
                    ClassType = types[i],
                    Title     = attribute.Title,
                    Priority  = attribute.Order,
                };
                _wrappers.Add(wrapper);
            }

            // 根据优先级排序
            _wrappers.Sort();

            // 创建实例类
            for (int i = 0; i < _wrappers.Count; i++)
            {
                WindowWrapper wrapper = _wrappers[i];
                wrapper.Instance = (IConsoleWindow)Activator.CreateInstance(wrapper.ClassType);
            }

            // 标题列表
            List <string> titles = new List <string>();

            for (int i = 0; i < _wrappers.Count; i++)
            {
                titles.Add(_wrappers[i].Title);
            }
            _toolbarTitles = titles.ToArray();
        }
        /// <summary>
        /// 初始化控制台
        /// </summary>
        public static void Initialize()
        {
            // 加载背景纹理
            string textureName = "console_background";

            _bgTexture = Resources.Load <Texture>(textureName);
            if (_bgTexture == null)
            {
                UnityEngine.Debug.LogWarning($"Not found {textureName} texture in Resources folder.");
            }

            // 获取所有调试类
            List <Type> allTypes = AssemblyUtility.GetAssignableAttributeTypes(typeof(IConsoleWindow), typeof(ConsoleAttribute));

            for (int i = 0; i < allTypes.Count; i++)
            {
                ConsoleAttribute attribute = (ConsoleAttribute)Attribute.GetCustomAttribute(allTypes[i], typeof(ConsoleAttribute));
                WindowWrapper    wrapper   = new WindowWrapper()
                {
                    ClassType = allTypes[i],
                    Title     = attribute.Title,
                    Priority  = attribute.Order,
                };
                _wrappers.Add(wrapper);
            }

            // 根据优先级排序
            _wrappers.Sort();

            // 创建实例类
            for (int i = 0; i < _wrappers.Count; i++)
            {
                WindowWrapper wrapper = _wrappers[i];
                wrapper.Instance = (IConsoleWindow)Activator.CreateInstance(wrapper.ClassType);
            }

            // 标题列表
            List <string> titles = new List <string>();

            for (int i = 0; i < _wrappers.Count; i++)
            {
                titles.Add(_wrappers[i].Title);
            }
            _toolbarTitles = titles.ToArray();
        }
Esempio n. 4
0
        /// <summary>
        /// 初始化控制台
        /// </summary>
        public static void Init()
        {
            // 加载背景纹理
            _bgTexture = Resources.Load <Texture>("builtin_background");
            if (_bgTexture == null)
            {
                UnityEngine.Debug.LogWarning("Not found builtin_background texture in Resources folder.");
            }

            // 获取所有调试类
            List <Type> allTypes = AssemblyUtility.GetAssignableAttributeTypes(typeof(IDebug), typeof(DebugAttribute));

            for (int i = 0; i < allTypes.Count; i++)
            {
                DebugAttribute attribute = (DebugAttribute)Attribute.GetCustomAttribute(allTypes[i], typeof(DebugAttribute));
                NodeWrapper    wrapper   = new NodeWrapper()
                {
                    ClassType = allTypes[i],
                    Title     = attribute.Title,
                    Priority  = attribute.Order,
                };
                _wrappers.Add(wrapper);
            }

            // 根据优先级排序
            _wrappers.Sort();

            // 创建实例类
            for (int i = 0; i < _wrappers.Count; i++)
            {
                NodeWrapper wrapper = _wrappers[i];
                wrapper.Instance = (IDebug)Activator.CreateInstance(wrapper.ClassType);
                wrapper.Instance.OnInit();
            }

            // 标题列表
            List <string> titles = new List <string>();

            for (int i = 0; i < _wrappers.Count; i++)
            {
                titles.Add(_wrappers[i].Title);
            }
            _toolbarTitles = titles.ToArray();
        }
Esempio n. 5
0
        static ConfigHandler()
        {
            List <Type> result = AssemblyUtility.GetAssignableAttributeTypes(typeof(AssetConfig), typeof(ConfigAttribute));

            for (int i = 0; i < result.Count; i++)
            {
                Type type = result[i];

                // 判断是否重复
                ConfigAttribute attribute = (ConfigAttribute)Attribute.GetCustomAttribute(type, typeof(ConfigAttribute));
                if (_cfgTypes.ContainsKey(attribute.CfgType))
                {
                    throw new Exception($"Config {type} has same value : {attribute.CfgType}");
                }

                // 添加到集合
                _cfgTypes.Add(attribute.CfgType, type);
            }
        }