using asap.core; using cfg; using GameCore; using Script.RuntimeScript.model.Data; using System.Collections; using System.Threading.Tasks; using UnityEngine; using UnityEngine.EventSystems; namespace Script.RuntimeScript.GameLogic { public class GridItem : MonoBehaviour { public GridData Data { get; set; } public GridEffectType GridEffectType { get; set; } GridEffectType Passive; private LayerMask _clickableLayer; private GameObject _baseObj; private Animation _baseAni; Transform fx_root; /// /// 两个mesh 用来处理 点击两次的情况 /// private GameObject _mesh1; private GameObject _mesh2; private string[] _moveEffectNames = new string[] { "gridshake1", "gridshake2", "gridshake3" }; private string _moveEffctName = string.Empty; public void Awake() { _clickableLayer = LayerMask.GetMask("Default"); _baseObj = transform.Find("AnimationRoot")?.gameObject; if (_baseObj) { _mesh1 = _baseObj.FindChildGameObject("Mesh1"); _mesh2 = _baseObj.FindChildGameObject("Mesh2"); } _baseAni = this.GetComponent(); fx_root = transform.Find("fx_root"); if (fx_root != null) { fx_root.gameObject.SetActive(false); } SetMash(GridMeshType.Mesh1); } // 这个方法会被 overlay 相机影响 private void OnMouseDown() { if (EventSystem.current?.IsPointerOverGameObject() ?? true) return; if (Data == null || Data.IsOpen) return; OnClick(); } public async void OnClick() { DiggingGameManager diggingGameManager = GContext.container.Resolve(); if (diggingGameManager.GameState != SandDigGameState.Going) { return; } if (!diggingGameManager.IsCanClick) { return; } int digCount = diggingGameManager.DataModel.GetDigCount(); if (digCount <= 0) { //int propId = diggingGameManager.GetActivityPropId(); //if (propId > 0) //{ // cfg.Item item = GContext.container.Resolve().GetItemData(propId); // string itemName = LocalizationMgr.GetText(item.Name_l10n_key); // ToastPanel.Show(LocalizationMgr.GetFormatTextValue("UI_ToastPanel_75", itemName)); //} diggingGameManager.OnClickBtnPack(); return; } else { diggingGameManager.DataModel.UseDig(); } if (!Data.IsBorder) { diggingGameManager.IsCanClick = false; int curIndex = diggingGameManager.GetCurClampIndex(); int clickCount = diggingGameManager.DataModel.GetClickCount(); if (Data.DoubleClick && Data.hasClickCount < 1) { diggingGameManager.SandDigPoint(GridType.None, curIndex, clickCount); Data.IsOpen = false; Data.hasClickCount++; Passive = GridEffectType.DoubleClick; GridEffectType = GridEffectType.DoubleClick; diggingGameManager.DataModel.SaveAll(); diggingGameManager.ShowDigEffect(ClickDigType.Smail, Data.LocalPos); PlayEffect(); await Task.Delay(SandDigEventConst.ShovelAnimTime); } else { Data.IsOpen = true; EventGridClick eventGridClick = new EventGridClick(Data, false); GContext.Publish(eventGridClick); bool isBig = eventGridClick.IsBigDig; //DiggingGameManager.LogError("大挖不:::" + isBig); GridEffectType = isBig ? GridEffectType.ClickBigDig : GridEffectType.ClickDig; PlayEffect(); if (Data.ConfigData != null) { if (Data.ConfigData.Config.DiggingType is Normal) { diggingGameManager.SandDigPoint(GridType.Normal, curIndex, clickCount); } else if (Data.ConfigData.Config.DiggingType is Resource) { diggingGameManager.SandDigPoint(GridType.Resource, curIndex, clickCount); } else { diggingGameManager.SandDigPoint(GridType.Special, curIndex, clickCount); } } else { diggingGameManager.SandDigPoint(GridType.None, curIndex, clickCount); } if (isBig) { await Task.Delay(SandDigEventConst.BigShovelAnimTime + 2000); } else { await Task.Delay(SandDigEventConst.ShovelAnimTime); } } diggingGameManager.IsCanClick = true; } } /// /// 被动爆炸 触发点击 /// public void PassiveClick() { if (gameObject.activeSelf && !Data.IsBorder) { if (Data.DoubleClick && Data.hasClickCount < 1) { Data.IsOpen = false; Data.hasClickCount++; Passive = GridEffectType; GridEffectType = GridEffectType.DoubleClick; PlayEffect(); GContext.container.Resolve().DataModel.SaveAll(); } else { Data.IsOpen = true; PlayEffect(); GContext.Publish(new EventGridClick(Data, true)); } } } public void PlayPassClampEffect() { GridEffectType = GridEffectType.PassClamp; PlayEffect(); } private void PlayEffect() { StartCoroutine(IEPlayEffect()); } // public const int BigShovelEffectTime = 833;//特效出现延迟 //public const int BigShovelBlockAnimTime = 866;//块消失动画播放时间 //public const int BigShovelBlockDisappearTime = 1133;//块消失时间 IEnumerator PlayBigEffect(int EffectTime) { yield return new WaitForSeconds(EffectTime * 0.001f); fx_root.gameObject.SetActive(true); } IEnumerator PlayBigAni(int BigShovelBlockAnimTime) { yield return new WaitForSeconds(BigShovelBlockAnimTime * 0.001f); _baseAni?.Play("griddisappear"); } IEnumerator IEPlayEffect() { DiggingGameManager diggingGameManager = GContext.container.Resolve(); var configInit = diggingGameManager.DataModel.digActivityConfig; if (GridEffectType == GridEffectType.ClickDig) { diggingGameManager.ShowFX(GridEffectType, fx_root); //普通挖掘效果 StartCoroutine(PlayBigEffect(SandDigEventConst.ShovelEffectTime)); StartCoroutine(PlayBigAni(SandDigEventConst.ShovelBlockAnimTime)); //_digEffect.SetActive(true); //SetMash(GridMeshType.None); yield return new WaitForSeconds(SandDigEventConst.ShovelBlockDisappearTime * 0.001f); //_digEffect.SetActive(false); gameObject.SetActive(false); } else if (GridEffectType == GridEffectType.ClickBigDig) { diggingGameManager.ShowFX(GridEffectType, fx_root); //挖到了道具的特殊特效 StartCoroutine(PlayBigEffect(SandDigEventConst.BigShovelEffectTime)); StartCoroutine(PlayBigAni(SandDigEventConst.BigShovelBlockAnimTime)); yield return new WaitForSeconds(SandDigEventConst.BigShovelBlockDisappearTime * 0.001f); gameObject.SetActive(false); } else if (GridEffectType == GridEffectType.DoubleClick) { //挖两次才能打开的格子特效 diggingGameManager.ShowFX(GridEffectType, fx_root); float time = SandDigEventConst.ShovelEffectTime * 0.001f; if (Passive == GridEffectType.PassiveBomb) { time = configInit.BombBlockAniTime; } else if (Passive == GridEffectType.PassiveClear) { time = configInit.BombBlockAniTime; } yield return new WaitForSeconds(time); fx_root.gameObject.SetActive(true); SetMash(GridMeshType.Mesh2); yield return new WaitForSeconds(1); fx_root.gameObject.SetActive(false); } else if (GridEffectType == GridEffectType.PassiveBomb) { yield return new WaitForSeconds(configInit.BombBlockAniTime); //随机晃动 System.Random random = new System.Random(); int randomNumber = random.Next(0, _moveEffectNames.Length); _moveEffctName = _moveEffectNames[randomNumber]; _baseAni?.Play(_moveEffctName); //yield return new WaitForSeconds(1); //特效触发 diggingGameManager.ShowFX(GridEffectType, fx_root); fx_root.gameObject.SetActive(true); //SetMash(GridMeshType.None); yield return new WaitForSeconds(SandDigEventConst.BombBlockDisappearTime * 0.001f); _baseAni.Stop(); fx_root.gameObject.SetActive(false); gameObject.SetActive(false); } else if (GridEffectType == GridEffectType.PassiveClear) { yield return new WaitForSeconds(configInit.ClearBlockAniTime); //随机晃动 System.Random random = new System.Random(); int randomNumber = random.Next(0, _moveEffectNames.Length); _moveEffctName = _moveEffectNames[randomNumber]; _baseAni?.Play(_moveEffctName); //特效触发 diggingGameManager.ShowFX(GridEffectType, fx_root); fx_root.gameObject.SetActive(true); //SetMash(GridMeshType.None); yield return new WaitForSeconds(SandDigEventConst.ClearBlockDisappearTime * 0.001f); _baseAni.Stop(); fx_root.gameObject.SetActive(false); gameObject.SetActive(false); } else if (GridEffectType == GridEffectType.PassClamp) { //挖通关了 ,清屏 diggingGameManager.ShowFX(GridEffectType, fx_root); fx_root.gameObject.SetActive(true); yield return new WaitForSeconds(0.2f); gameObject.SetActive(false); } } public void SetMash(GridMeshType type) { _mesh1?.SetActive(false); _mesh2?.SetActive(false); if (type == GridMeshType.Mesh1) { _mesh1?.SetActive(true); } else if (type == GridMeshType.Mesh2) { _mesh2?.SetActive(true); } } } }