Browse Source

添加解锁逻辑

lzx 13 hours ago
parent
commit
fa8b33eeac

+ 3 - 0
Assets/Res/Config/UnlockConfig.json

@@ -0,0 +1,3 @@
+{
+  "configList": []
+}

+ 7 - 0
Assets/Res/Config/UnlockConfig.json.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: W3gc5Cr5WinuYb0aYOPoF85fOXCGLRjoqAF3ShsCDK6JTL29T5Xooa4S1m1o
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Assets/Scripts/Core/Event/Event/CustomEventType.cs

@@ -118,6 +118,7 @@ namespace Fort23.Core
       DaoYouCounUpdate,
       UpdateZuiZhongEvent,
       CancelEvent,
+      RefreshULock
 
     }
 }

+ 80 - 0
Assets/Scripts/GameData/ExcelConfig/UnlockConfig.cs

@@ -0,0 +1,80 @@
+// Auto Generated Code By excel2json
+// Generate From Excel\Unlock.xlsx. SheetName: UnlockConfig
+
+using System;
+using Fort23.GameData;
+
+namespace Excel2Json
+{
+	[Config(prefab = "UnlockConfig.json")]
+	public partial class UnlockConfigHolder : ConfigHolder<UnlockConfig>
	{
+	}
+
+
+	[Serializable]
+	public struct UnlockConfig : IConfig
	{
+		public int GetID() {return ID;} 
+		/// <summary>
+		///序列
+		/// </summary>
+#if !COMBAT_SERVER
+		public int ID;
+#else
+		public int ID{ set; get; }
+#endif
+		
+
+		/// <summary>
+		///解锁功能 见解锁功能查询
+		/// </summary>
+#if !COMBAT_SERVER
+		public int ulockFunction;
+#else
+		public int ulockFunction{ set; get; }
+#endif
+		
+
+		/// <summary>
+		///解锁方式 1=境界等级解锁  5=主线章节ID
+		/// </summary>
+#if !COMBAT_SERVER
+		public int ulockCondition;
+#else
+		public int ulockCondition{ set; get; }
+#endif
+		
+
+		/// <summary>
+		///ulockCondition=1,境界等级 
+		/// </summary>
+#if !COMBAT_SERVER
+		public int ulockValue;
+#else
+		public int ulockValue{ set; get; }
+#endif
+		
+
+		/// <summary>
+		///未解锁前对应入口的展现形式 1、看不见 2、置灰
+		/// </summary>
+#if !COMBAT_SERVER
+		public int lockType;
+#else
+		public int lockType{ set; get; }
+#endif
+		
+
+		/// <summary>
+		///未解锁时点击的提示语言表ID {0}取ulockValue
+		/// </summary>
+#if !COMBAT_SERVER
+		public int UnlockTipsID;
+#else
+		public int UnlockTipsID{ set; get; }
+#endif
+		
+
+	}
+
+}
+// End of Auto Generated Code

+ 11 - 0
Assets/Scripts/GameData/ExcelConfig/UnlockConfig.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: W3kWtCn7B3uETV59fPIFcL7fTytpSl8AxPrk3n946pcZKtEwnDTRlwHZongK
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/Scripts/GameLogic/UnLock.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: WXMdty6rWy2FRb5ei0EfURH6xHauEA9mDhBcSaTxTA2FdQOKejro/0jLNIKW
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 138 - 0
Assets/Scripts/GameLogic/UnLock/ULockManager.cs

@@ -0,0 +1,138 @@
+using System;
+using Core.Language;
+using Excel2Json;
+using Fort23.Core;
+using Fort23.Mono;
+using Fort23.UTool;
+using UnityEngine;
+using Utility;
+
+public class ULockManager : Singleton<ULockManager>
+{
+    public UnlockConfig[] Configs;
+
+
+    public bool Nolock;
+
+    public ULockManager()
+    {
+        Configs = ConfigComponent.Instance.GetAll<UnlockConfig>();
+    }
+
+    /// <summary>
+    /// 获取解锁表
+    /// </summary>
+    /// <param name="unLockValue">解锁值(功能ID、表ID)</param>
+    /// <param name="isFunction">第一个参是否为功能ID</param>
+    /// <returns></returns>
+    public UnlockConfig GetULockConfig(int unLockValue, bool isFunction = true)
+    {
+        for (int i = 0; i < Configs.Length; i++)
+        {
+            if (isFunction)
+            {
+                if (Configs[i].ulockFunction == unLockValue)
+                {
+                    return Configs[i];
+                }
+            }
+            else
+            {
+                if (Configs[i].ID == unLockValue)
+                {
+                    return Configs[i];
+                }
+            }
+        }
+
+        if (isFunction)
+        {
+            LogTool.Error("功能 ulockFunction 值 配置错误,找不到这样一个功能,请请检查:" + unLockValue);
+        }
+        else
+        {
+            LogTool.Error("解锁ID配置错误,找不到这样一个功能,请请检查:" + unLockValue);
+        }
+
+        return new UnlockConfig();
+    }
+
+
+    /// <summary>
+    /// 刷新解锁状态, 影响解锁的值变化时调用(通关、飞艇升级等)
+    /// </summary>
+    public void RefreshULock()
+    {
+        EventManager.Instance.Dispatch(CustomEventType.RefreshULock, null);
+    }
+
+    /// <summary>
+    /// 解锁功能
+    /// </summary>
+    /// <param name="config">解锁表</param>
+    /// <returns>true表示解锁成功</returns>
+    public bool IsULock(UnlockConfig config)
+    {
+        if (Nolock)
+        {
+            return true;
+        }
+
+        switch (config.ulockCondition)
+        {
+            case 1:
+                return PlayerManager.Instance.myHero.powerUpConfig.ID >= config.ulockValue;
+        
+        }
+
+        return false;
+    }
+
+    public bool IsULock(int functionID)
+    {
+        if (Nolock)
+        {
+            return true;
+        }
+
+        // if (mGameRuntimeConfig.unLockAll)
+        // {
+        //     return true;
+        // }
+
+        if (functionID <= 0)
+        {
+            return true;
+        }
+
+        foreach (var config in Configs)
+        {
+            if (config.ulockFunction == functionID)
+            {
+                return IsULock(config);
+            }
+        }
+
+        return false;
+    }
+
+    public string ShowUnlockTips(int unlockConfigId)
+    {
+        UnlockConfig _config = ConfigComponent.Instance.Get<UnlockConfig>(unlockConfigId);
+        if (_config.ID == 0)
+            return "";
+        int unLockCondition = _config.ulockCondition;
+        int unLockValue = _config.ulockValue;
+        string tips = String.Empty;
+        switch (unLockCondition)
+        {
+            case 1: //玩家境界
+                // LevelBattleConfig levelBattleConfig = ConfigComponent.Instance.Get<LevelBattleConfig>(unLockValue);
+                // tips = LanguageManager.Instance.Text(_config.UnlockTipsID, levelBattleConfig.levelName);
+                break;
+
+        }
+        
+        return tips;
+    }
+}

+ 11 - 0
Assets/Scripts/GameLogic/UnLock/ULockManager.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 2560385ff34654c3cbbe6e6138ceed1c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 158 - 0
Assets/Scripts/GameUI/ULockWidget.cs

@@ -0,0 +1,158 @@
+using System;
+using Excel2Json;
+using Fort23.Core;
+using Fort23.Mono;
+using Fort23.UTool;
+using UnityEngine;
+using UnityEngine.EventSystems;
+using UnityEngine.UI;
+
+public class ULockWidget : MonoBehaviour, IPointerClickHandler
+{
+    private int uLockId;
+
+    public int uLockFunction;
+
+
+    public Action ulockCallBack;
+
+    private UnlockConfig _config;
+    private bool _currULock;
+    private Button mUIButton;
+    private bool mIsUnlock;
+
+
+    private void Awake()
+    {
+        if (uLockFunction == 0)
+            return;
+        StartULock();
+        if (mUIButton == null) return;
+    }
+
+    public void SetuLockFunction(int id)
+    {
+        uLockFunction = id;
+        if (uLockFunction == 0)
+        {
+            mIsUnlock = true;
+            UnlockShow(mIsUnlock);
+            return;
+        }
+
+        StartULock();
+        if (mUIButton == null) return;
+    }
+
+
+    public void StartULock()
+    {
+        if (uLockId <= 0)
+        {
+            _config = ULockManager.Instance.GetULockConfig(uLockFunction);
+        }
+        else
+        {
+            _config = ULockManager.Instance.GetULockConfig(uLockId, false);
+        }
+
+        mUIButton = transform.GetComponentInChildren<Button>();
+
+        EventManager.Instance.RemoveEventListener(CustomEventType.RefreshULock, RefreshULock);
+        EventManager.Instance.AddEventListener(CustomEventType.RefreshULock, RefreshULock);
+        ULock();
+    }
+
+    public void UnlockCallBack()
+    {
+        ulockCallBack?.Invoke();
+    }
+
+    private void OnDestroy()
+    {
+        EventManager.Instance.RemoveEventListener(CustomEventType.RefreshULock, RefreshULock);
+        ulockCallBack = null;
+    }
+
+    private void RefreshULock(IEventData e)
+    {
+        ULock();
+    }
+
+
+    private void ULock()
+    {
+        if (_config.ID == 0)
+        {
+            mIsUnlock = true;
+            return;
+        }
+
+        mIsUnlock = ULockManager.Instance.IsULock(_config);
+        UnlockShow(mIsUnlock);
+    }
+
+
+    /// <summary>
+    /// 解锁的表现逻辑
+    /// </summary>
+    /// <param name="isUnlock">是否解锁</param>
+    private void UnlockShow(bool isUnlock)
+    {
+        mIsUnlock = isUnlock;
+        if (gameObject == null) return;
+        Text[] texts = gameObject.GetComponentsInChildren<Text>();
+
+        if (!isUnlock)
+        {
+            if (_config.lockType == 1)
+            {
+                gameObject.SetActive(false);
+            }
+            else if (_config.lockType == 2)
+            {
+                if (mUIButton != null)
+                {
+                    mUIButton.enabled = false;
+                }
+                else
+                {
+                    LogTool.Log("没有碰撞区域" + gameObject.name);
+                }
+
+                gameObject.transform.Gray(true);
+            }
+
+            _currULock = true;
+        }
+        else
+        {
+            if (_config.lockType == 1)
+            {
+                gameObject.SetActive(true);
+            }
+            else if (_config.lockType == 2)
+            {
+                if (mUIButton != null)
+                {
+                    mUIButton.enabled = true;
+                }
+
+                //TODO 恢复正常颜色
+                gameObject.transform.RecoverColor();
+            }
+
+            UnlockCallBack();
+            EventManager.Instance.RemoveEventListener(CustomEventType.RefreshULock, RefreshULock);
+        }
+    }
+
+    public void OnPointerClick(PointerEventData eventData)
+    {
+        LogTool.Log("点击~");
+        if (!mIsUnlock)
+        {
+            TipMessagePanel.OpenTipMessagePanel(ULockManager.Instance.ShowUnlockTips(_config.ID), Vector2.zero);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/GameUI/ULockWidget.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: CHkcsX+pAnMQ000CN6lyx49Brjb4thhtX+wuACZOY6X7h64yeD8Z2YRA6Ncc
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Excel2Json/Excel/Unlock.xlsx