Пример #1
0
 protected virtual void showLoading()
 {
     if (EnableLoading)
     {
         GameFrameEntry.GetModule <UIModule>().Loading.SetVisible(true);
     }
 }
Пример #2
0
        protected override async void Play()
        {
            base.Play();
            //朝向目标
            gameObject.transform.rotation = Quaternion.FromToRotation(new Vector3(0, 1, 0), targetPos - starPos);

            //计算起点
            Vector2 StartPos = GameFrameEntry.GetModule <EffectModule>().WorldToRectLocalPoint(starPos);
            //计算终点
            Vector2 EndPos = GameFrameEntry.GetModule <EffectModule>().WorldToRectLocalPoint(targetPos);

            float dis    = Vector2.Distance(StartPos, EndPos);
            float ScaleX = gameObject.transform.localScale.x;
            float ScaleZ = gameObject.transform.localScale.z;

            //拉伸
            gameObject.transform.localScale = new Vector3(ScaleX, (dis / 256.0f), ScaleZ);
            gameObject.transform.position   = starPos;

            gameObject.SetActive(m_isActive);
            if (Config.duration > 0) //有持续时间的自动停止
            {
                await new WaitForSeconds((float)Config.duration);
                Stop();
                onComplete?.Invoke(this);
            }
        }
Пример #3
0
        /// <summary>打开UI</summary>
        public async void _openUI(params object[] args)
        {
            _args = args;
            showLoading();
            GameObject obj = await GameFrameEntry.GetModule <UIModule>().LoadUI(UIPath, UINode.ToString());

            if (m_isDispose) //UI已经销毁掉了
            {
                GameObject.DestroyImmediate(obj);
                return;
            }

            if (obj == null)
            {
                return;
            }
            openTopUI();
            initGameObject(obj);
            addCanvas();
            closeLoading();
            Refresh();
            //GuideTrigger.OpenUI(this);
            if (OpenAnim == EUIAnim.Customize)
            {
                await OpenAnimCustomize();
            }
            else
            {
                await GameFrameEntry.GetModule <UIModule>().UIAnim(obj, OpenAnim);
            }
            OpenLater();
            MsgDispatcher.SendMessage(GlobalEventType.OpenUI, this);
        }
Пример #4
0
        /// <summary>
        /// 加载Texture
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <returns></returns>
        public static async Task <Texture> LoadTexture(string assetBundleName)
        {
            string assetName = assetBundleName.Substring(assetBundleName.LastIndexOf("/") + 1);

            assetBundleName = "Textures/" + assetBundleName + ".png";
            return(await GameFrameEntry.GetModule <AssetbundleModule>().LoadAsset <Texture>(assetBundleName, assetName));
        }
Пример #5
0
        /// <summary>
        /// 加载图集中的图片 转换成Texture2D放回
        /// </summary>
        /// <param name="uiAtlas"></param>
        /// <param name="spriteName"></param>
        /// <returns></returns>
        public static async Task <Texture2D> LoadTexture2DForAtlas(string uiAtlas, string spriteName)
        {
            Texture2D texture2D = GameFrameEntry.GetModule <AssetbundleModule>().GetTexture2D(spriteName);

            if (texture2D != null)
            {
                return(texture2D);
            }
            SpriteAtlas atlas = await GameFrameEntry.GetModule <AssetbundleModule>().LoadSpriteAtlas(uiAtlas);

            if (atlas == null)
            {
                return(null);
            }
            var loadSprite = atlas.GetSprite(spriteName);

            texture2D = new Texture2D((int)loadSprite.rect.width, (int)loadSprite.rect.height);
            var pixels = loadSprite.texture.GetPixels(
                (int)loadSprite.textureRect.x,
                (int)loadSprite.textureRect.y,
                (int)loadSprite.textureRect.width,
                (int)loadSprite.textureRect.height);

            texture2D.SetPixels(pixels);
            texture2D.Apply();
            GameFrameEntry.GetModule <AssetbundleModule>().AddGetTexture2D(spriteName, texture2D);
            return(texture2D);
        }
Пример #6
0
 protected virtual void closeLoading()
 {
     if (EnableLoading)
     {
         GameFrameEntry.GetModule <UIModule>().Loading.SetVisible(false);
     }
 }
Пример #7
0
        /// <summary>
        /// 重新加载配置表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        public static async Task ReloadConfig <T>(Dictionary <object, T> source) where T : BaseConfig
        {
            string fileName = typeof(T).Name;

            source.Clear();
            UnityEngine.Object configObj = await GameFrameEntry.GetModule <AssetbundleModule>().LoadAsset <UnityEngine.Object>(configAssetbundle, fileName);

            if (configObj != null)
            {
                string   strconfig = configObj.ToString();
                List <T> list      = JsonMapper.ToObject <List <T> >(strconfig);
                for (int i = 0; i < list.Count; i++)
                {
                    if (source.ContainsKey(list[i].UniqueID))
                    {
                        CLog.Error($"表[{fileName}]中有相同键({list[i].UniqueID})");
                    }
                    else
                    {
                        source.Add(list[i].UniqueID, list[i]);
                    }
                }
            }
            else
            {
                CLog.Error($"配置文件不存在{fileName}");
            }
        }
Пример #8
0
 private static void AddSaveListener()
 {
     if (m_TickTimeId >= 0)
     {
         GameFrameEntry.GetModule <TimeModule>().RemoveTime(m_TickTimeId);
     }
     m_TickTimeId = GameFrameEntry.GetModule <TimeModule>().SetEveryMinute(CheckUseByTime, 5);
 }
Пример #9
0
        /// <summary>
        /// 世界坐标转换成UI对象本地坐标
        /// </summary>
        /// <param name="WorldPos"></param>
        /// <returns></returns>
        public Vector2 WorldToRectLocalPoint(Vector3 WorldPos)
        {
            Vector2 ScrePos = RectTransformUtility.WorldToScreenPoint(GameFrameEntry.GetModule <UIModule>().UICamera, WorldPos);
            Vector2 v2      = Vector2.zero;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(_LineEffectRoot, ScrePos, GameFrameEntry.GetModule <UIModule>().UICamera, out v2);
            return(v2);
        }
Пример #10
0
 protected override void OnDispose()
 {
     if (m_FadeTimeId != 0)
     {
         GameFrameEntry.GetModule <TimeModule>().RemoveTime(m_FadeTimeId);
     }
     AudioTools.DestroyAudioSource(base.s_audioSource);
     base.s_audioSource = null;
 }
Пример #11
0
        /// <summary>
        /// 加载声音文件
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <returns></returns>
        public static async Task <AudioClip> LoadSound(string assetBundleName)
        {
            string assetNameByHZ = assetBundleName.Substring(assetBundleName.LastIndexOf("/") + 1);

            string[] AudioNameS = assetNameByHZ.Split('.');//去掉文件后缀
            string   assetName  = AudioNameS[0];

            return(await GameFrameEntry.GetModule <AssetbundleModule>().LoadAsset <AudioClip>(assetBundleName, assetName));
        }
Пример #12
0
 /// <summary>
 /// 异步加载资源
 /// </summary>
 /// <param name="assetBundleName">完整资源包名,注:带文件扩展名</param>
 /// <param name="assetName">资源名</param>
 public static async Task <T> LoadAsset <T>(string assetBundleName, string assetName = null) where T : UObject
 {
     //assetBundleName = assetBundleName.ToLower();
     //assetBundleName += AppSetting.ExtName;
     if (string.IsNullOrEmpty(assetName))
     {
         string assetFullName = assetBundleName.Substring(assetBundleName.LastIndexOf("/") + 1);
         assetName = assetFullName.Split('.')[0];
     }
     return(await GameFrameEntry.GetModule <AssetbundleModule>().LoadAsset <T>(assetBundleName, assetName));
 }
Пример #13
0
        /// <summary>加载特效</summary>
        async void Load()
        {
            m_IsLoad   = false;
            gameObject = await GameFrameEntry.GetModule <AssetbundleModule>().LoadPrefab("Effect/" + getEffectFolder() + Config.res);

            gameObject.transform.SetParent(m_parent, false);
            gameObject.transform.localPosition    = m_pos;
            gameObject.transform.localEulerAngles = m_rot;
            SetComponent();
            m_IsLoad = true;
        }
Пример #14
0
        // 移动audio监听
        public void MoveAudioListen(AudioMode audioMode)
        {
            Camera uiCamera = GameFrameEntry.GetModule <UIModule>().UICamera;

            CreateListener();
            if (audioMode == AudioMode.A2D)
            {
                if (uiCamera != null)
                {
                    m_AudioListener.transform.SetParent(uiCamera.transform);
                }
            }
        }
Пример #15
0
        internal override async Task Initialize()
        {
            canvas = GameObject.Find("Canvas");
            canvas.transform.position = new Vector3(-100, 0, 0);
            GameObject CameraObj = GameObject.Find("UICamera");

            if (CameraObj == null)
            {
                Debug.LogError("UI相机未找到");
            }
            UICamera = CameraObj?.GetComponent <Camera>();
            UnityEngine.GameObject.DontDestroyOnLoad(canvas);

            GameObject obj = await GameFrameEntry.GetModule <AssetbundleModule>().LoadPrefab("UI/UIRoot", "UIRoot");

            UIRoot = obj.GetComponent <RectTransform>();
            UIRoot.transform.SetParent(canvas.transform);

            UIRoot.localScale = Vector3.one;
            UIRoot.anchorMin  = Vector2.zero;
            UIRoot.anchorMax  = Vector2.one;
            UIRoot.offsetMin  = Vector2.zero;
            UIRoot.offsetMax  = Vector2.zero;
            //是竖版的情况,并且处于平板上时,适配平板
            if (AppSetting.IsPortrait && canvas.GetComponent <CanvasScaler>().matchWidthOrHeight == 1)
            {
                float CurrWidth = canvas.GetComponent <RectTransform>().sizeDelta.x;
                //按照高控制宽
                if (CurrWidth > 720)
                {
                    float offsetX = (CurrWidth - 720) / 2.0f;
                    //宽被拉到了 把宽缩小到720的正常分辨率中
                    UIRoot.offsetMax = new Vector2(-offsetX, 0);
                    UIRoot.offsetMin = new Vector2(offsetX, 0);
                }
            }
            //else
            //{
            //    float CurrHeight = canvas.GetComponent<RectTransform>().sizeDelta.y;
            //    //按宽控制高
            //    if (CurrHeight > 1280)
            //    {
            //        float offsetY = (CurrHeight - 1280) / 2.0f;
            //        //高被拉了 把宽缩小到720的正常分辨率中
            //        //UIRoot.offsetMax = new Vector2(-offsetX, 0);
            //        UIRoot.offsetMin = new Vector2(UIRoot.offsetMin.x, offsetY);
            //    }
            //}

            CLog.Log("初始化UIModule完成");
        }
Пример #16
0
        /// <summary>
        /// 是否变大,不是则变小
        /// </summary>
        /// <param name="audio"></param>
        /// <param name="isHigh"></param>
        private void OnFade(AudioSource audio, bool isHigh, Action onFadeEnd = null)
        {
            if (audio != null)
            {
                TimeModule.CompleteHandler completeHandler = delegate(int id)
                {
                    GameFrameEntry.GetModule <TimeModule>().RemoveTime(id);
                    if (audio == null)
                    {
                        return;
                    }
                    if (isHigh)
                    {
                        audio.volume = this.m_MaxVolume;
                    }
                    else
                    {
                        audio.volume = 0;
                        if (onFadeEnd != null)
                        {
                            onFadeEnd();
                        }
                    }
                };

                TimeModule.EveryHandle everyHandle = delegate(int id, int time)
                {
                    if (audio == null)
                    {
                        return;
                    }
                    float volume = 0;
                    if (isHigh)
                    {
                        volume = this.m_MaxVolume * ((m_FadeTime - (float)time) / (float)this.m_FadeTime);
                    }
                    else
                    {
                        volume = this.m_MaxVolume * ((float)time / (float)this.m_FadeTime);
                    }
                    //Util.Log("aaaaaaaaaaaaaa-->", time, volume);
                    audio.volume = volume;
                };
                if (m_FadeTimeId != 0)
                {
                    GameFrameEntry.GetModule <TimeModule>().RemoveTime(m_FadeTimeId);
                }
                m_FadeTimeId = GameFrameEntry.GetModule <TimeModule>().SetCountDownByMillisecond(this.m_FadeTime, completeHandler, everyHandle);
            }
        }
Пример #17
0
        /// <summary>关闭当前UI</summary>
        public virtual void CloseSelf()
        {
            //if (ShowTop && UINode == EUINode.UIWindow)
            //{
            //    TopUI  top = Mgr.UI.GetUI<TopUI>();
            //    BaseUI ui  = top?.GetFirst();
            //    if (ui != null && ui == this)
            //    {
            //        top.DisposeFirst();
            //    }
            //}

            CloseAction?.Invoke();

            GameFrameEntry.GetModule <UIModule>().CloseForName(GetType().Name);
        }
Пример #18
0
        /// <summary>
        /// 加载Sprite Textures目录下的图片  目前只能加载png图片
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <returns></returns>
        public static async Task <Sprite> LoadSprite(string assetBundleName)
        {
            string assetName = assetBundleName.Substring(assetBundleName.LastIndexOf("/") + 1);
            Sprite sprite    = GameFrameEntry.GetModule <AssetbundleModule>().GetSprite(assetName);

            if (sprite != null)
            {
                return(sprite);
            }
            assetBundleName = "Textures/" + assetBundleName + ".png";
            Texture texture = await GameFrameEntry.GetModule <AssetbundleModule>().LoadAsset <Texture>(assetBundleName, assetName);

            sprite      = Sprite.Create((Texture2D)texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
            sprite.name = texture.name;
            GameFrameEntry.GetModule <AssetbundleModule>().AddSprite(assetName, sprite);
            return(sprite);
        }
Пример #19
0
        /// <summary>
        /// 加载UI
        /// </summary>
        /// <param name="uiPath">相对于UI目录下的路径如:Login/Login</param>
        public async Task <GameObject> LoadUI(string uiPath, string uiNode)
        {
            string     uiName = uiPath.Substring(uiPath.LastIndexOf("/") + 1);
            GameObject go     = await GameFrameEntry.GetModule <AssetbundleModule>().LoadPrefab("UI/" + uiPath, uiName);

            await wait;

            go.transform.SetParent(_GetUINode(uiNode));
            RectTransform rect = go.GetComponent <RectTransform>();

            rect.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.one;
            rect.offsetMin = Vector2.zero;
            rect.offsetMax = Vector2.zero;

            return(go);
        }
Пример #20
0
 void addCanvas()
 {
     if (UINode == EUINode.UIWindow)
     {
         Canvas canvas = transform.GetComponent <Canvas>();
         if (canvas == null)
         {
             canvas = transform.gameObject.AddComponent <Canvas>();
         }
         canvas.overrideSorting = true;
         canvas.sortingOrder    = 10 + (GameFrameEntry.GetModule <UIModule>().GetWindowNum() - 1) * 3;
         canvas.sortingLayerID  = SortingLayer.NameToID("UIWindow");
         if (transform.GetComponent <GraphicRaycaster>() == null)
         {
             gameObject.AddComponent <GraphicRaycaster>();
         }
     }
 }
Пример #21
0
 /// <summary>关闭UI</summary>
 public async void _closeUI()
 {
     CloseBefore();
     if (CloseAnim == EUIAnim.Customize)
     {
         await CloseAnimCustomize();
     }
     else
     {
         await GameFrameEntry.GetModule <UIModule>().UIAnim(gameObject, CloseAnim);
     }
     m_isDispose = true;
     await new WaitForEndOfFrame();
     Dispose();
     GameObject.DestroyImmediate(gameObject);
     await new WaitForEndOfFrame();
     MsgDispatcher.SendMessage(GlobalEventType.CloseUI, this);
 }
Пример #22
0
        /// <summary>
        /// 读取竖表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        public static async Task <T> readConfigV <T>() where T : BaseConfig
        {
            string fileName = typeof(T).Name;

            UnityEngine.Object configObj = await GameFrameEntry.GetModule <AssetbundleModule>().LoadAsset <UnityEngine.Object>(configAssetbundle, fileName);

            if (configObj != null)
            {
                string   strconfig = configObj.ToString();
                List <T> list      = JsonMapper.ToObject <List <T> >(strconfig);
                if (list.Count > 0)
                {
                    return(list[0]);
                }
            }
            else
            {
                CLog.Error($"配置文件不存在{fileName}");
            }
            return(null);
        }
Пример #23
0
 /// <summary>
 /// 跟据语言类型获取值
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public string GetValue(ELangType type)
 {
     return(GameFrameEntry.GetModule <LangModule>().Get(key, type));
 }
Пример #24
0
 /// <summary>
 /// 异步加载Model文件夹下的预设
 /// </summary>
 /// <param name="assetBundleName"></param>
 /// <param name="assetName"></param>
 /// <returns></returns>
 public static async Task <GameObject> LoadModelPrefab(string PrefabsName)
 {
     PrefabsName = "Model/" + PrefabsName;
     return(await GameFrameEntry.GetModule <AssetbundleModule>().LoadPrefab(PrefabsName));
 }
Пример #25
0
        /// <summary>
        /// 异步加载场景
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="isAdditive"></param>
        /// <param name="cbProgress"></param>
        /// <returns></returns>
        public static async Task LoadScene(string sceneName, bool isAdditive = false, Action <float> cbProgress = null)
        {
            await GameFrameEntry.GetModule <AssetbundleModule>().LoadScene(sceneName, isAdditive, cbProgress);

            //GuideTrigger.LoadScene(sceneName);
        }