Main/Component/UI/Common/MountCanvasCamera.cs
New file @@ -0,0 +1,15 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; public class MountCanvasCamera : MonoBehaviour { void Awake() { Canvas canvas = GetComponent<Canvas>(); if (null != canvas) { canvas.worldCamera = CameraManager.uiCamera; } } } Main/Component/UI/Common/MountCanvasCamera.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: e331f42a91da7ef4c84f7c5472adbeb7 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: Main/Config/ConfigBase.cs
@@ -59,8 +59,6 @@ { dic.Clear(); Dictionary<string, string> rawDatas = new Dictionary<string, string>(); for (int i = 3; i < lines.Length; i++) { string line = lines[i]; Main/Config/ConfigManager.cs
@@ -54,7 +54,7 @@ typeof(GmCmdConfig), typeof(GuideConfig), typeof(IconConfig), typeof(InitialFunctionConfig), //typeof(InitialFunctionConfig), typeof(ItemConfig), typeof(KickOutReasonConfig), typeof(LanguageConfig), @@ -68,7 +68,7 @@ typeof(PlayerFaceStarConfig), typeof(PlayerLVConfig), typeof(priorbundleConfig), typeof(PriorLanguageConfig), //typeof(PriorLanguageConfig), typeof(RichTextMsgReplaceConfig), typeof(RuleConfig), typeof(SkillConfig), Main/Core/GameEngine/Launch/BuiltInAssetCopyTask.cs
@@ -37,16 +37,18 @@ if (!firstLaunch) { LoadInitalConfig().Forget(); //LoadInitalConfig().Forget(); done = true; } } protected async UniTask LoadInitalConfig() { await ConfigManager.Instance.LoadConfigByType(typeof(InitialFunctionConfig)); //应该是下载最新的表格后再次加载 非拷贝 //protected async UniTask LoadInitalConfig() //{ // await ConfigManager.Instance.LoadConfigByType(typeof(InitialFunctionConfig)); done = true; } // done = true; //} public override void End() { Main/Core/GameEngine/Launch/InitSettingTask.cs
@@ -14,7 +14,7 @@ { ShaderUtility.InitGlobalParams(); SoundPlayer.CreateSoundPlayer(); SoundPlayer.Instance.PlayLoginMusic(); //SoundPlayer.Instance.PlayLoginMusic(); SystemSetting.Instance.SetSoundVolume(SystemSetting.Instance.GetSoundVolume()); SystemSetting.Instance.SetSoundEffect(SystemSetting.Instance.GetSoundEffect()); Main/Core/GameEngine/Launch/LaunchInHot.cs
@@ -26,11 +26,12 @@ Application.backgroundLoadingPriority = ThreadPriority.High; Screen.sleepTimeout = SleepTimeout.NeverSleep; InitSystemMgr(); SDKUtils.Instance.Init(); //原sdk接口 // 这里还没开始加载配置 但是提前加载了供LaunchWin使用 LanguageConfig.ForceInit(); InitSystemMgr(); SDKUtils.Instance.Init(); //原sdk接口 // 这里还没开始加载配置 但是提前加载了供LaunchWin使用 PriorLanguageConfig.ForceInit(); InitialFunctionConfig.ForceInit(); UIManager.Instance.OpenWindow<LaunchWin>(); Main/Manager/UIManager.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic; using UnityEngine; using System.Linq; using DG.Tweening; /// <summary> /// UI管理器 - 负责管理所有UI界面的显示、隐藏和层级 @@ -64,23 +65,25 @@ #endregion #region 初始化 /// <summary> /// 初始化UI管理器 /// </summary> public override void Init() { base.Init(); // 初始化UI根节点 InitUIRoot(); // 初始化缓存 layerSortingOrderCache.Clear(); layerTransformCache.Clear(); uiInstanceCounter.Clear(); DOTween.SetTweensCapacity(500, 50); Debug.Log("UI管理器初始化完成"); } /// <summary> Main/System/ClientVersion/RequestSecretWin.cs
@@ -30,10 +30,12 @@ #endif }); m_Fuwu.SetListener(()=> { UIManager.Instance.OpenWindow<GameAgeWarnWin>().SetFunctionOrder(1); GameAgeWarnWin.data = 1; UIManager.Instance.OpenWindow<GameAgeWarnWin>(); }); m_Yinsi.SetListener(() => { UIManager.Instance.OpenWindow<GameAgeWarnWin>().SetFunctionOrder(2); GameAgeWarnWin.data = 2; UIManager.Instance.OpenWindow<GameAgeWarnWin>(); }); } Main/System/ClientVersion/VersionUtility.cs
@@ -208,7 +208,7 @@ if (task.IsDone) { step = Step.Completed; // VersionUpdateWin.Instance.CloseWindow(); UIManager.Instance.CloseWindow<VersionUpdateWin>(); // // WindowCenter.Instance.Close<VersionUpdateWin>(); SDKUtils.Instance.InstallAPK(GetApkLocalUrl()); } Main/System/Language/Language.cs
@@ -97,7 +97,7 @@ // if (_id.StartsWith(NewBieGuideScriptableObject.GuidesPrefixNewBie) || // _id.StartsWith(NewBieGuideScriptableObject.GuidesPrefixFun)) // return string.Empty; // Debug.LogFormat("缺少语言表配置,id: {0}", _id); Debug.LogErrorFormat("缺少语言表配置,id: {0}", _id); #endif return string.Empty; } Main/System/Launch/LaunchWin.cs
@@ -118,8 +118,9 @@ else { m_AndroidProgressContainer.SetActive(true); m_IosProgressContainer.SetActive(false); m_Version.text = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, Language.Id); m_IosProgressContainer.SetActive(false); //打包版本 + 功能版本 + 语言ID m_Version.text = LoginManager.Instance.GetVersionStr(); } if (m_StageDescription != null) Main/System/Launch/LoadingWin.cs
@@ -59,7 +59,9 @@ { base.OnPreOpen(); currentProgress = targetProgress = 0; Refresh(); Refresh(); //打包版本 + 功能版本 + 语言ID m_Version.text = LoginManager.Instance.GetVersionStr(); } protected override void OnPreClose() Main/System/Login/GameAgeWarnWin.cs
@@ -15,47 +15,27 @@ [SerializeField] Transform m_Title3; //年龄 [SerializeField] Transform m_Info3; [SerializeField] Button m_Close; // 生命周期 protected override void Awake() { base.Awake(); // 初始化组件引用 public static int data = 1; protected override void InitComponent() { m_Close.AddListener(CloseWindow); } protected override void Start() { base.Start(); // 初始化数据 } // UI事件 protected override void OnOpen() { base.OnOpen(); // 窗口打开时的逻辑 // m_Title1.SetActive(functionOrder == 1); // m_Info1.SetActive(functionOrder == 1); // m_Title2.SetActive(functionOrder == 2); // m_Info2.SetActive(functionOrder == 2); // m_Title3.SetActive(functionOrder == 3); // m_Info3.SetActive(functionOrder == 3); m_Title1.SetActive(data == 1); m_Info1.SetActive(data == 1); m_Title2.SetActive(data == 2); m_Info2.SetActive(data == 2); m_Title3.SetActive(data == 3); m_Info3.SetActive(data == 3); } protected override void OnClose() { base.OnClose(); // 窗口关闭时的逻辑 } public override void Refresh() { base.Refresh(); // 刷新UI显示 } public void SetFunctionOrder(int _functionOrder) { } } Main/System/Login/LoginManager.cs
@@ -294,72 +294,77 @@ } public C0101_tagCPlayerLogin Get0101SendPackage(H0101_tagServerPrepared _serverInfo) { var send = new C0101_tagCPlayerLogin(); switch (VersionConfig.Get().versionAuthority) { var send = new C0101_tagCPlayerLogin(); switch (VersionConfig.Get().versionAuthority) { case VersionAuthority.InterTest: send.IDType = 1; send.AccID = accountBuf; if (sdkLoginResult == null) send.Password = "111"; else send.Password = sdkLoginResult.token; send.MAC = DeviceUtility.GetMac(); send.Version = _serverInfo.Version; send.LineNO = 255; send.AppID = VersionConfig.Get().appId; send.AccountID = 1000;// 内部登陆的时候的id send.TokenExpire = "1519750743000";// 内部登陆的时长,无所谓的 send.Phone = 0; send.ServerID = (uint)ServerListCenter.Instance.currentServer.region_flag; send.Adult = 1; send.ExtraLen = 0; send.Extra = ""; break; case VersionAuthority.Release: { var deviceInfo = DeviceUtility.GetDeviceModel(); deviceInfo.Replace(" ", "").Replace("=", "").Replace("%", "").Replace("-", "").Replace("|", ""); var versionStr = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", deviceInfo); send.Extra = StringUtility.Contact(VersionConfig.Get().SpID, "|", SDKUtils.Instance.Device.uniqueID, "|", sdkLoginResult.token, "|", sdkLoginResult.qkUserName, "|", versionStr.Substring(0, Math.Min(24, versionStr.Length))); Debug.Log("=====> extra: " + send.Extra); send.ExtraLen = (ushort)send.Extra.Length; send.IDType = (byte)SDKUtils.Instance.ChannelPlatform; case VersionAuthority.InterTest: send.IDType = 1; send.AccID = accountBuf; if (sdkLoginResult == null) send.Password = "111"; else send.Password = sdkLoginResult.token; send.AccID = sdkLoginResult.account; send.MAC = DeviceUtility.GetMac(); send.Version = _serverInfo.Version; send.LineNO = 255; send.AppID = VersionConfig.Get().appId; send.AccountID = (uint)sdkLoginResult.accountID; send.TokenExpire = sdkLoginResult.tokenExpire; send.Phone = (byte)sdkLoginResult.phone; send.ServerID = (uint)ServerListCenter.Instance.currentServer.region_flag; if (sdkIDCheckIDAuthentication.type == "1") { send.Adult = 1; } else if (sdkIDCheckIDAuthentication.type == "2") { send.Adult = MathUtility.CheckAdult(sdkIDCheckIDAuthentication.card_id) ? (byte)1 : (byte)0; } else { send.Adult = 0; } break; } } return send; send.MAC = DeviceUtility.GetMac(); send.Version = _serverInfo.Version; send.LineNO = 255; send.AppID = VersionConfig.Get().appId; send.AccountID = 1000;// 内部登陆的时候的id send.TokenExpire = "1519750743000";// 内部登陆的时长,无所谓的 send.Phone = 0; send.ServerID = (uint)ServerListCenter.Instance.currentServer.region_flag; send.Adult = 1; send.ExtraLen = 0; send.Extra = ""; break; case VersionAuthority.Release: { var deviceInfo = DeviceUtility.GetDeviceModel(); deviceInfo.Replace(" ", "").Replace("=", "").Replace("%", "").Replace("-", "").Replace("|", ""); var versionStr = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", deviceInfo); send.Extra = StringUtility.Contact(VersionConfig.Get().SpID, "|", SDKUtils.Instance.Device.uniqueID, "|", sdkLoginResult.token, "|", sdkLoginResult.qkUserName, "|", versionStr.Substring(0, Math.Min(24, versionStr.Length))); Debug.Log("=====> extra: " + send.Extra); send.ExtraLen = (ushort)send.Extra.Length; send.IDType = (byte)SDKUtils.Instance.ChannelPlatform; send.Password = sdkLoginResult.token; send.AccID = sdkLoginResult.account; send.MAC = DeviceUtility.GetMac(); send.Version = _serverInfo.Version; send.LineNO = 255; send.AppID = VersionConfig.Get().appId; send.AccountID = (uint)sdkLoginResult.accountID; send.TokenExpire = sdkLoginResult.tokenExpire; send.Phone = (byte)sdkLoginResult.phone; send.ServerID = (uint)ServerListCenter.Instance.currentServer.region_flag; if (sdkIDCheckIDAuthentication.type == "1") { send.Adult = 1; } else if (sdkIDCheckIDAuthentication.type == "2") { send.Adult = MathUtility.CheckAdult(sdkIDCheckIDAuthentication.card_id) ? (byte)1 : (byte)0; } else { send.Adult = 0; } break; } } return send; } public string GetVersionStr() { return StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", InitialFunctionConfig.Get("version").Numerical1); } } Main/System/Login/LoginWin.cs
@@ -20,7 +20,7 @@ [SerializeField] Image m_Logo; [SerializeField] UIAlphaTween m_AlphaTween; // [SerializeField] UIAlphaTween m_AlphaTween; [SerializeField] RectTransform m_WaitServerList; [SerializeField] RectTransform m_ContainerEnterGame; [SerializeField] RectTransform m_ContainerAccount; @@ -64,18 +64,17 @@ m_CleanCache.SetListener(CleanCache); serverRead.SetListener(() => { GameAgeWarnWin win = UIManager.Instance.OpenWindow<GameAgeWarnWin>(); win.SetFunctionOrder(1); // WindowCenter.Instance.OpenFromLocal<GameAgeWarnWin>(1); GameAgeWarnWin.data = 1; UIManager.Instance.OpenWindow<GameAgeWarnWin>(); }); hideRead.SetListener(() => { GameAgeWarnWin win = UIManager.Instance.OpenWindow<GameAgeWarnWin>(); win.SetFunctionOrder(2); GameAgeWarnWin.data = 2; UIManager.Instance.OpenWindow<GameAgeWarnWin>(); }); ageWarn.SetListener(() => { GameAgeWarnWin win = UIManager.Instance.OpenWindow<GameAgeWarnWin>(); win.SetFunctionOrder(3); GameAgeWarnWin.data = 3; UIManager.Instance.OpenWindow<GameAgeWarnWin>(); }); } @@ -91,15 +90,24 @@ ServerListCenter.Instance.RequestPlayerServerList(); LoginManager.Instance.isLogined = false; ServerListCenter.Instance.FiltrateDefaultServerAndServerGroup(); m_AlphaTween.SetStartState(); // m_AlphaTween.SetStartState(); Refresh(); m_AlphaTween.Play(() => { firstOpenEnd = true; InGameDownLoad.Instance.downLoadGo = false; DownloadMgr.MaxDownLoadTask = InGameDownLoad.Instance.GetMaxTask(); }); // m_AlphaTween.Play(() => { // firstOpenEnd = true; // InGameDownLoad.Instance.downLoadGo = false; // DownloadMgr.MaxDownLoadTask = InGameDownLoad.Instance.GetMaxTask(); // }); } protected override void OnOpenAnimationComplete() { base.OnOpenAnimationComplete(); firstOpenEnd = true; InGameDownLoad.Instance.downLoadGo = false; DownloadMgr.MaxDownLoadTask = InGameDownLoad.Instance.GetMaxTask(); } protected override void OnPreClose() @@ -116,12 +124,10 @@ public override void Refresh() { base.Refresh(); Debug.Log("刷新登录窗口"); // 版本信息 string strVersion = StringUtility.Contact("ver ", InitialFunctionConfig.Get("version").Numerical1); verInfo.text = strVersion; Debug.Log("刷新登录窗口"); //打包版本 + 功能版本 + 语言ID verInfo.text = LoginManager.Instance.GetVersionStr(); var sprite = BuiltInLoader.LoadSprite("TB_DL_Logo"); m_Logo.overrideSprite = sprite; Main/System/Main/MainWin.cs
@@ -12,6 +12,8 @@ // 底部按钮组 private Button[] bottomTabButtons; private GameObject[] bottomTabEffects; // 当前选中的底部标签索引 private int currentTabIndex = 0; @@ -26,14 +28,16 @@ { base.InitComponent(); windowBackground = transform.Find("RawImgBackground").gameObject; windowBackground = _rectTransform.Find("RawImgBackground").gameObject; bottomTabButtons = new Button[5]; for (int i = 1; i <= 5; i++) { string buttonName = "Buttons/Button" + i; bottomTabButtons[i-1] = transform.Find(buttonName).GetComponent<Button>(); bottomTabButtons[i-1] = _rectTransform.Find(buttonName).GetComponent<Button>(); #if UNITY_EDITOR //测试代码 #endif } // 初始化UI组件事件 @@ -53,6 +57,7 @@ OnBottomTabButtonClicked(index); }); } } protected override void OnOpen() @@ -71,6 +76,26 @@ UpdatePlayerInfo(); UpdateCurrency(); } protected override void OnPreOpen() { base.OnPreOpen(); bottomTabEffects = new GameObject[bottomTabButtons.Length]; for (int i = 0; i < bottomTabButtons.Length; i++) { bottomTabEffects[i] = PlayUIEffect(1004, bottomTabButtons[i].transform, false); } } protected override void OnPreClose() { base.OnPreClose(); foreach (var effectGO in bottomTabEffects) { DestroyImmediate(effectGO); } bottomTabEffects = null; } /// <summary> /// 更新玩家信息 Main/System/Sound/SoundPlayer.cs
@@ -302,23 +302,23 @@ } } public void PlayLoginMusic() { var loginMusic = BuiltInLoader.LoadMusic("Music_Login"); if (!m_MusicAudioSource.isPlaying || m_MusicAudioSource.clip != loginMusic) { StartCoroutine(Co_BackGroundMusicFadeOutIn(loginMusic, false)); } } //public void PlayLoginMusic() //{ // var loginMusic = BuiltInLoader.LoadMusic("Music_Login"); // if (!m_MusicAudioSource.isPlaying || m_MusicAudioSource.clip != loginMusic) // { // StartCoroutine(Co_BackGroundMusicFadeOutIn(loginMusic, false)); // } //} private void LateUpdate() { // if (CameraController.Instance != null && CameraController.Instance.CameraObject != null) // { // this.transform.position = CameraController.Instance.transform.position + new Vector3(0, 5, 0); // this.transform.rotation = CameraController.Instance.CameraObject.transform.rotation; // } } //private void LateUpdate() //{ // if (CameraController.Instance != null && CameraController.Instance.CameraObject != null) // { // this.transform.position = CameraController.Instance.transform.position + new Vector3(0, 5, 0); // this.transform.rotation = CameraController.Instance.CameraObject.transform.rotation; // } //} IEnumerator Co_BackGroundMusicFadeOutIn(AudioClip _clip, bool _oneShot) { Main/System/UIBase/UIBase.cs
@@ -45,7 +45,7 @@ [SerializeField][HideInInspector] public int maxIdleRounds = 20; // 动画相关 [SerializeField] public UIAnimationType openAnimationType = UIAnimationType.ScaleInOut; [SerializeField] public UIAnimationType openAnimationType = UIAnimationType.None; [SerializeField] public UIAnimationType closeAnimationType = UIAnimationType.None; [SerializeField]/*[HideInInspector]*/ public float animeDuration = 0.2f; [SerializeField][HideInInspector] public Ease animationEase = Ease.OutQuad; // 确保使用 DG.Tweening.Ease @@ -53,6 +53,8 @@ // 运行时状态 [HideInInspector] public int lastUsedRound = 0; [HideInInspector] public UIBase parentUI; [HideInInspector] public GameObject rootNode; // 根节点 // 子UI管理 [HideInInspector] public List<UIBase> childrenUI = new List<UIBase>(); @@ -77,10 +79,9 @@ // 组件引用 protected Canvas canvas; protected CanvasGroup canvasGroup; protected RectTransform rectTransform; protected RectTransform _rectTransform; //界面默认添加根节点用于表现界面开启关闭动画 // 动画相关 protected Vector3 originalScale; protected Vector3 originalPosition; protected Sequence currentAnimation; @@ -92,19 +93,16 @@ protected virtual void Awake() { // 确保 DOTween 已初始化 DOTween.SetTweensCapacity(500, 50); CreateRootNode(); // 防止有人不写base.InitComponent引发错误 所以拆分 InitComponentInternal(); // 在Awake中进行基本初始化 InitComponent(); // 保存原始值用于动画 if (rectTransform != null) if (_rectTransform != null) { originalScale = rectTransform.localScale; originalPosition = rectTransform.anchoredPosition; originalPosition = _rectTransform.anchoredPosition; } ApplySettings(); @@ -118,27 +116,56 @@ } } private void CreateRootNode() { if (openAnimationType == UIAnimationType.None && closeAnimationType == UIAnimationType.None) return; List<Transform> children = new List<Transform>(); foreach (Transform child in transform) { children.Add(child); } rootNode = new GameObject("WindowRoot"); rootNode.transform.SetParent(transform, false); rootNode.layer = LayerMask.NameToLayer("UI"); _rectTransform = rootNode.AddMissingComponent<RectTransform>(); //设置成拉伸效果,和父容器保持同样大小自动适配 _rectTransform.anchorMin = Vector2.zero; _rectTransform.anchorMax = Vector2.one; _rectTransform.pivot = new Vector2(0.5f, 0.5f); _rectTransform.anchoredPosition = Vector2.zero; _rectTransform.sizeDelta = Vector2.zero; // 设置为0,表示拉伸到父容器大小 foreach (Transform child in children) { child.SetParent(rootNode.transform, false); } } protected virtual void Start() { // 子类可以重写此方法进行额外初始化 } protected async UniTask ApplySettings() { await UniTask.DelayFrame(5); if (null != transform) { if (clickEmptySpaceClose) { if (clickEmptySpaceClose) { GameObject goBtnESC = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/ClickEmptyCloseMask"), transform); // Load btnClickEmptyClose = goBtnESC.GetComponent<Button>(); btnClickEmptyClose.AddListener(CloseWindow); btnClickEmptyClose.transform.SetAsFirstSibling(); } //延迟创建会导致层级在ScreenMask之上 GameObject goBtnESC = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/ClickEmptyCloseMask"), transform); btnClickEmptyClose = goBtnESC.GetComponent<Button>(); btnClickEmptyClose.AddListener(CloseWindow); btnClickEmptyClose.transform.SetAsFirstSibling(); await UniTask.DelayFrame(5); btnClickEmptyClose = goBtnESC.GetComponent<Button>(); btnClickEmptyClose.AddListener(CloseWindow); } } protected async void ExecuteNextFrame(Action _action) { @@ -172,6 +199,8 @@ // 设置Canvas属性 canvas.overrideSorting = true; canvas.worldCamera = CameraManager.uiCamera; // 获取或添加CanvasGroup组件 canvasGroup = GetComponent<CanvasGroup>(); if (canvasGroup == null) @@ -186,9 +215,6 @@ } canvasScaler = GetComponent<CanvasScaler>(); // 获取RectTransform组件 rectTransform = GetComponent<RectTransform>(); } // 获取必要的组件 @@ -317,7 +343,7 @@ /// <param name="autoDestroy">是否自动销毁,默认为true</param> /// <param name="destroyDelay">自动销毁延迟时间,默认为5秒</param> /// <returns>特效游戏对象</returns> public async UniTask<GameObject> PlayUIEffect(int id, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f) public GameObject PlayUIEffect(int id, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f) { // 使用默认值 if (parent == null) parent = transform; @@ -344,7 +370,11 @@ // 添加特效穿透阻挡器 EffectPenetrationBlocker blocker = effectObj.AddComponent<EffectPenetrationBlocker>(); blocker.parentCanvas = canvas; blocker.UpdateSortingOrder(); // 延迟一帧才生效 this.DelayFrame(blocker.UpdateSortingOrder); // blocker.UpdateSortingOrder(); // 自动销毁 if (autoDestroy) @@ -479,15 +509,13 @@ // 播放打开动画 protected virtual void PlayOpenAnimation() { if (openAnimationType == UIAnimationType.None) { // 无动画,直接启用交互 if (canvasGroup != null) { canvasGroup.alpha = 1f; canvasGroup.interactable = true; canvasGroup.blocksRaycasts = true; } // 初始值设定好 _ResetToBegin(); return; } @@ -503,74 +531,62 @@ canvasGroup.interactable = false; canvasGroup.blocksRaycasts = false; } if (canvasScaler != null) { canvasScaler.scaleFactor = 1f; } break; case UIAnimationType.ScaleInOut: if (rectTransform != null) if (canvasGroup != null) { canvasScaler.scaleFactor = 0.3f; canvasGroup.alpha = 1f; canvasGroup.interactable = false; canvasGroup.blocksRaycasts = false; } if (canvasScaler != null) { canvasScaler.scaleFactor = 0.3f; } break; case UIAnimationType.SlideFromTop: if (rectTransform != null) _ResetToBegin(); if (_rectTransform != null) { Vector2 startPos = originalPosition; startPos.y = Screen.height; rectTransform.anchoredPosition = startPos; } if (canvasGroup != null) { canvasGroup.alpha = 0f; canvasGroup.interactable = false; canvasGroup.blocksRaycasts = false; startPos.y = originalPosition.y + Screen.height; _rectTransform.anchoredPosition = startPos; } break; case UIAnimationType.SlideFromBottom: if (rectTransform != null) _ResetToBegin(); if (_rectTransform != null) { Vector2 startPos = originalPosition; startPos.y = -Screen.height; rectTransform.anchoredPosition = startPos; } if (canvasGroup != null) { canvasGroup.alpha = 0f; canvasGroup.interactable = false; canvasGroup.blocksRaycasts = false; startPos.y = originalPosition.y-Screen.height; _rectTransform.anchoredPosition = startPos; } break; case UIAnimationType.SlideFromLeft: if (rectTransform != null) _ResetToBegin(); if (_rectTransform != null) { Vector2 startPos = originalPosition; startPos.x = -Screen.width; rectTransform.anchoredPosition = startPos; } if (canvasGroup != null) { canvasGroup.alpha = 0f; canvasGroup.interactable = false; canvasGroup.blocksRaycasts = false; startPos.x = originalPosition.x-Screen.width; _rectTransform.anchoredPosition = startPos; } break; case UIAnimationType.SlideFromRight: if (rectTransform != null) _ResetToBegin(); if (_rectTransform != null) { Vector2 startPos = originalPosition; startPos.x = Screen.width; rectTransform.anchoredPosition = startPos; } if (canvasGroup != null) { canvasGroup.alpha = 0f; canvasGroup.interactable = false; canvasGroup.blocksRaycasts = false; startPos.x = originalPosition.x+Screen.width; _rectTransform.anchoredPosition = startPos; } break; } @@ -591,9 +607,9 @@ break; case UIAnimationType.ScaleInOut: if (rectTransform != null) if (_rectTransform != null) { currentAnimation.Append(DOVirtual.Float(0.3f, originalScale.x, animeDuration, (value) => {canvasScaler.scaleFactor = value;}).SetEase(animationEase)); currentAnimation.Append(DOVirtual.Float(0.3f, 1f, animeDuration, (value) => {canvasScaler.scaleFactor = value;}).SetEase(animationEase)); } break; @@ -601,13 +617,9 @@ case UIAnimationType.SlideFromBottom: case UIAnimationType.SlideFromLeft: case UIAnimationType.SlideFromRight: if (rectTransform != null) if (_rectTransform != null) { currentAnimation.Append(rectTransform.DOAnchorPos(originalPosition, animeDuration).SetEase(animationEase)); } if (canvasGroup != null) { currentAnimation.Join(canvasGroup.DOFade(1f, animeDuration).SetEase(animationEase)); currentAnimation.Append(_rectTransform.DOAnchorPos(originalPosition, animeDuration).SetEase(animationEase)); } break; } @@ -617,12 +629,15 @@ { isAnimating = false; OnOpenAnimationComplete(); // 启用交互 if (canvasGroup != null) { canvasGroup.interactable = true; canvasGroup.blocksRaycasts = true; } }); currentAnimation.Play(); @@ -640,6 +655,35 @@ } isAnimating = false; } } // private void Update() // { // Debug.LogError(_rectTransform.parent.name + ":" + _rectTransform.anchoredPosition); // } private void _ResetToBegin() { if (canvasGroup != null) { canvasGroup.alpha = 1f; canvasGroup.interactable = true; canvasGroup.blocksRaycasts = true; } if (canvasScaler != null) { canvasScaler.scaleFactor = 1f; } if (_rectTransform != null) { _rectTransform.anchoredPosition = originalPosition; } } protected virtual void OnOpenAnimationComplete() { } // 播放关闭动画 - 修改后的方法 @@ -664,66 +708,50 @@ case UIAnimationType.FadeInOut: if (canvasGroup != null) { currentAnimation.Append(canvasGroup.DOFade(0f, animeDuration).SetEase(animationEase)); currentAnimation.Append(canvasGroup.DOFade(0.1f, animeDuration).SetEase(animationEase)); } break; case UIAnimationType.ScaleInOut: if (rectTransform != null) if (_rectTransform != null) { currentAnimation.Append(DOVirtual.Float(originalScale.x, 0.3f, animeDuration, (value) => {canvasScaler.scaleFactor = value;}).SetEase(animationEase)); currentAnimation.Append(DOVirtual.Float(1f, 0.3f, animeDuration, (value) => {canvasScaler.scaleFactor = value;}).SetEase(animationEase)); } break; case UIAnimationType.SlideFromTop: if (rectTransform != null) if (_rectTransform != null) { Vector2 endPos = originalPosition; endPos.y = Screen.height; currentAnimation.Append(rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } if (canvasGroup != null) { currentAnimation.Join(canvasGroup.DOFade(0f, animeDuration).SetEase(animationEase)); currentAnimation.Append(_rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } break; case UIAnimationType.SlideFromBottom: if (rectTransform != null) if (_rectTransform != null) { Vector2 endPos = originalPosition; endPos.y = -Screen.height; currentAnimation.Append(rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } if (canvasGroup != null) { currentAnimation.Join(canvasGroup.DOFade(0f, animeDuration).SetEase(animationEase)); currentAnimation.Append(_rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } break; case UIAnimationType.SlideFromLeft: if (rectTransform != null) if (_rectTransform != null) { Vector2 endPos = originalPosition; endPos.x = -Screen.width; currentAnimation.Append(rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } if (canvasGroup != null) { currentAnimation.Join(canvasGroup.DOFade(0f, animeDuration).SetEase(animationEase)); currentAnimation.Append(_rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } break; case UIAnimationType.SlideFromRight: if (rectTransform != null) if (_rectTransform != null) { Vector2 endPos = originalPosition; endPos.x = Screen.width; currentAnimation.Append(rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } if (canvasGroup != null) { currentAnimation.Join(canvasGroup.DOFade(0f, animeDuration).SetEase(animationEase)); currentAnimation.Append(_rectTransform.DOAnchorPos(endPos, animeDuration).SetEase(animationEase)); } break; } Main/Utility/CameraManager.cs
@@ -1,6 +1,7 @@ using UnityEngine; using System.Collections; public class CameraManager { /// <summary> @@ -11,20 +12,11 @@ { get { if (null == m_UICamera) { m_UICamera = GameObject.Find("UICamera").GetComponent<Camera>(); } return m_UICamera; } set { m_UICamera = value; } } private static Camera m_SceneCamera = null; public static Camera sceneCamera { get { return m_SceneCamera; } set { m_SceneCamera = value; } } } Main/Utility/EffectPenetrationBlocker.cs
@@ -26,9 +26,9 @@ public Canvas parentCanvas; [Tooltip("特效在Canvas中的排序偏移量")] public int sortingOrderOffset = 1; public int _sortingOrderOffset = 0; private int canvasSortingOrder = 0; public int canvasSortingOrder = 0; private void Awake() { @@ -88,7 +88,7 @@ } // 将特效的排序顺序设置为Canvas排序顺序加上偏移量 ApplySortingSettings(canvasSortingOrder + sortingOrderOffset, customSortingLayer); ApplySortingSettings(canvasSortingOrder + _sortingOrderOffset, customSortingLayer); } /// <summary> @@ -96,12 +96,15 @@ /// </summary> private void ApplySortingSettings(int sortingOrder, string sortingLayer) { // const int overlayRQ = 4000; // 应用到渲染器 foreach (Renderer renderer in effectRenderers) { if (renderer != null) { renderer.sortingOrder = sortingOrder; // renderer.material.renderQueue = overlayRQ; if (!string.IsNullOrEmpty(sortingLayer)) { renderer.sortingLayerName = sortingLayer; @@ -118,6 +121,7 @@ if (psRenderer != null) { psRenderer.sortingOrder = sortingOrder; // psRenderer.material.renderQueue = overlayRQ; if (!string.IsNullOrEmpty(sortingLayer)) { psRenderer.sortingLayerName = sortingLayer; @@ -153,4 +157,12 @@ UpdateSortingOrder(); } } #if UNITY_EDITOR [ContextMenu("Apply")] public void Apply() { UpdateSortingOrder(); } #endif } Main/Utility/UniTaskExtension.cs
New file @@ -0,0 +1,22 @@ using UnityEngine; using Cysharp.Threading.Tasks; using System; public static class UniTaskExtension { public static void DelayFrame(this GameObject go, Action action) { DelayFrameInternal(action); } public static void DelayFrame(this Component cmp, Action action) { DelayFrameInternal(action); } private async static UniTask DelayFrameInternal(Action action) { await UniTask.DelayFrame(1); action?.Invoke(); } } Main/Utility/UniTaskExtension.cs.meta
New file @@ -0,0 +1,11 @@ fileFormatVersion: 2 guid: 66bafc3f6f9d7a44197ce6cc49cd26fc MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: