示例#1
0
        /// <summary>
        /// 加载资源文件
        /// </summary>
        /// <typeparam name="T">文件类型</typeparam>
        /// <param name="assetName">文件名</param>
        /// <returns></returns>
        public static T GetAsset <T>(string assetName) where T : Object
        {
            //通过反射获取常量类中的文件名
            string assetsPath = UIReflection.GetConstField(assetName + UIConst.ASSETPATH, typeof(UIConst)).ToString();

            return(Resources.Load <T>(assetsPath));
        }
示例#2
0
        /// <summary>
        /// 为子对象添加对应的行为脚本
        /// </summary>
        private void AddUIBehaviour()
        {
            for (int i = 0; i < allChild.Length; i++)
            {
                for (int j = 0; j < UIManager.instance.GetUITokenList().Count; j++)
                {
                    UIToken uIToken = UIManager.instance.GetUITokenList()[j];
                    if (allChild[i].name.EndsWith(uIToken.token))
                    {
                        Type currentType = UIReflection.GetUIBehaviourByName(uIToken.behaviourName, UIConst.UIBEHAVIOUR);
                        if (currentType == null)
                        {
                            return;
                        }

                        //避免重复添加脚本
                        if (allChild[i].gameObject.GetComponent(currentType) == null)
                        {
                            allChild[i].gameObject.AddComponent(currentType);
                        }
                    }
                }
            }
        }