| | |
| | | |
| | | public TextMeshProUGUI timeTextNew = null; |
| | | |
| | | public TextMeshProUGUI timeStatic = null; |
| | | //public TextMeshProUGUI timeStatic = null; |
| | | |
| | | /// <summary> |
| | | /// 结算界面 |
| | |
| | | |
| | | private bool isPause; |
| | | |
| | | public bool beginSkillStep = false; |
| | | public bool beginDragStep = false; |
| | | public bool guideThirdWaveStep = false; |
| | | |
| | | public GameObject darkGroundImg; |
| | | |
| | | /// <summary> |
| | | /// Awake is called when the script instance is being loaded. |
| | | /// </summary> |
| | | protected override void Awake() |
| | | { |
| | | base.Awake(); |
| | | //这里为了方便直接使用Endless2D |
| | | GameObject root = GameObject.Find("ManagerRoot"); |
| | | |
| | | if (root == null) |
| | | { |
| | | root = new GameObject("ManagerRoot"); |
| | | root.AddComponent<DoNotDestory>(); |
| | | root.AddComponent<MasterSocket>(); |
| | | root.AddComponent<TDAA_SDKManager>(); |
| | | root.AddComponent<AudioSourceManager>(); |
| | | root.AddComponent<JsonDataReader>(); |
| | | root.AddComponent<JsonDataInit>(); |
| | | } |
| | | firstStart = true; |
| | | //EventCenter.Ins.Add((int)KTGMGemClient.EventType.JsonDataReadDone, JsonDataReadDone); |
| | | } |
| | | |
| | | Vector2 tmpOffect;//计算适配的偏移量 |
| | | bool firstStart = true; |
| | | // Start is called before the first frame update |
| | | void Start() |
| | | { |
| | | InitSDK(); |
| | | bGameStart = false; |
| | | bFirstLoaded = false; |
| | | GameConfig.CreateRandomTower = true; |
| | | |
| | | bVibrate = new bool[4]; |
| | | bVibrate[0] = bVibrate[1] = bVibrate[2] = bVibrate[3] = false; |
| | | |
| | | if (timeStatic) |
| | | timeStatic.gameObject.SetActive(false); |
| | | EndlessBuffSelect.instance.HideBuffUI(); |
| | | EndlessSettlement settlement = SettlementUI.transform.GetChild(0).GetComponent<EndlessSettlement>(); |
| | | EndlessSettlement settlement = SettlementUI.transform.Find("BgMask").GetComponent<EndlessSettlement>(); |
| | | settlement.Init(); |
| | | SettlementUI.SetActive(false); |
| | | EndlessMaskUI.instance.Hide(); |
| | | EndlessBossHPManager.instance.HideHP(); |
| | | EndlessScoreManager.instance.HideScore(); |
| | | |
| | | |
| | | float ratio = 0.06666667f; |
| | | RectTransform ts = GetComponent<RectTransform>(); |
| | | float tmpScale = ratio / ts.localScale.x - 1.0f; |
| | | float offect = tmpScale * (ts.sizeDelta.y * 0.5f); |
| | | //Debug.Log($"tmpScale:{tmpScale} offect:{offect}"); |
| | | tmpOffect = new Vector2(0, offect); |
| | | transform.Find("Panel/Bottom").GetComponent<RectTransform>().anchoredPosition += tmpOffect; |
| | | transform.Find("Panel/TowerBuyBtn").GetComponent<RectTransform>().anchoredPosition += tmpOffect; |
| | | transform.Find("Panel/SwitchSpeed").GetComponent<RectTransform>().anchoredPosition += tmpOffect; |
| | | |
| | | transform.Find("Panel/BossHPBar").GetComponent<RectTransform>().anchoredPosition -= tmpOffect * 0.5f; |
| | | transform.Find("Panel/Score").GetComponent<RectTransform>().anchoredPosition -= tmpOffect * 0.5f; |
| | | transform.Find("Panel/TimeInfo").GetComponent<RectTransform>().anchoredPosition -= tmpOffect * 0.5f; |
| | | //transform.Find("Panel/Boss").GetComponent<RectTransform>().anchoredPosition -= tmpOffect*0.5f; |
| | | |
| | | |
| | | //darkGroundImg = transform.Find("Image_DarkGround").gameObject; |
| | | darkGroundImg.GetComponent<RectTransform>().offsetMin += tmpOffect; |
| | | darkGroundImg.GetComponent<RectTransform>().offsetMax -= tmpOffect * 0.5f; |
| | | |
| | | darkGroundImg.SetActive(false); |
| | | |
| | | //查询是否已经做过了新手引导 |
| | | int guide = PlayerPrefs.GetInt("GemBattleGuide"); |
| | | GameConfig.IsNewbie = guide == 0; |
| | | |
| | | if (GameConfig.IsNewbie) |
| | | { |
| | | Debug.Log("开始新手引导"); |
| | | Pause(); |
| | | uiStartMssk.gameObject.SetActive(false); |
| | | countDownTextNew.text = ""; |
| | | countDownTextNew.gameObject.SetActive(false); |
| | | |
| | | Instantiate(Resources.Load<GameObject>("UI/Guide/GuidePanel"), this.transform); |
| | | AddGuideEvent(); |
| | | } |
| | | //CheckIsNewbie(); |
| | | |
| | | GameConfig.EndlessOpenAttackTowerCount = 0; |
| | | GameConfig.EndlessBuyTowerCount = 0; |
| | | GameConfig.EndlessPortUseSkillTowerCount = 0; |
| | | |
| | | AudioSourceManager.Ins.Play(AudioEnum.BGM2); |
| | | |
| | | fireSkillBgImg = transform.Find("Panel/Energy/FireSkillBg").GetComponent<Image>(); |
| | | transform.Find("Panel/Energy/FireSkillBg/SkillBtn").GetComponent<Button>().onClick.AddListener(OnClickFireSkillBtn); |
| | | fireSkillLevelText = transform.Find("Panel/Energy/FireSkillBg/Level/Text").GetComponent<Text>(); |
| | | skillSliderValueRect = transform.Find("Panel/Energy/FireSkillBg/SliderValue").GetComponent<RectTransform>(); |
| | | skillSliderVStartP = skillSliderValueRect.anchoredPosition; |
| | | skillSliderVStartHeight = skillSliderValueRect.sizeDelta; |
| | | |
| | | skillPS1 = transform.Find("Panel/Energy/FireSkillBg/Effect_UI_JiNengTuBiao/03 (9)").GetComponent<ParticleSystem>(); |
| | | skillPS2 = transform.Find("Panel/Energy/FireSkillBg/Effect_UI_JiNengTuBiao_02/03 (16)").GetComponent<ParticleSystem>(); |
| | | |
| | | transform.Find("Panel/BuffPreviewButton").gameObject.SetActive(false); |
| | | |
| | | GameConfig.EnergyCount = 0; |
| | | GameConfig.SkillLevel = 1; |
| | | |
| | | //CalculateSkillSliderValue(); |
| | | transform.Find("Panel/Energy").gameObject.SetActive(false); |
| | | |
| | | EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EnergyUp, EnergyUp); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.SkillLevelUpBuff, SkillLevelUpBuff); |
| | | |
| | | |
| | | } |
| | | |
| | | private void CheckIsNewbie() |
| | | { |
| | | if (GameConfig.IsNewbie) |
| | | { |
| | | Debug.Log("开始新手引导"); |
| | | GameConfig.CanDragTower = false; |
| | | Pause(); |
| | | HideUIMask(); |
| | | countDownTextNew.text = ""; |
| | | countDownTextNew.gameObject.SetActive(false); |
| | | |
| | | GameObject guideObj = Instantiate(Resources.Load<GameObject>("UI/Guide/GuidePanel"), transform.Find("Panel")); |
| | | guideObj.GetComponent<RectTransform>().offsetMin += tmpOffect; |
| | | AddGuideEvent(); |
| | | |
| | | transform.Find("Panel/SwitchSpeed").gameObject.SetActive(false); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 所有数据读取完毕 |
| | | /// </summary> |
| | | private void JsonDataReadDone() |
| | | { |
| | | Debug.Log("设置激活"); |
| | | transform.Find("Panel/Energy").gameObject.SetActive(true); |
| | | |
| | | transform.Find("Panel/BuffPreviewButton").gameObject.SetActive(true); |
| | | fireSkillCost = JsonDataCenter.GetSkillLevelInfo(fireSkillID, GameConfig.SkillLevel).cost; |
| | | bombSkillCost = JsonDataCenter.GetSkillLevelInfo(bombSkillID, GameConfig.SkillLevel).cost; |
| | | |
| | | energyMax = JsonDataCenter.GetById<battle>(22).value; |
| | | |
| | | //transform.Find("Panel/Energy/FireSkillBtn/Image/EnergyText").GetComponent<TextMeshProUGUI>().text = fireSkillCost.ToString(); |
| | | //transform.Find("Panel/Energy/BombSkillBtn/Image/EnergyText").GetComponent<TextMeshProUGUI>().text = bombSkillCost.ToString(); |
| | | |
| | | EnergyUp(0); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 拖拽时候黑色背景 |
| | | /// </summary> |
| | | /// <param name="isOn"></param> |
| | | public void SetDarkGround(bool isOn) |
| | | { |
| | | if (darkGroundImg.activeSelf != isOn) |
| | | darkGroundImg.SetActive(isOn); |
| | | } |
| | | private void InitSDK() |
| | | { |
| | | if (TDAA_SDKManager.Ins == null) |
| | | gameObject.AddComponent<TDAA_SDKManager>(); |
| | | TDAA_SDKManager.Ins.ArriveBattle();//埋点 |
| | | TDAA_SDKManager.Ins.Statistics(4);//埋点 |
| | | |
| | | if (AudioSourceManager.Ins == null) |
| | | gameObject.AddComponent<AudioSourceManager>(); |
| | | } |
| | | |
| | | public void ShowUIMask() |
| | | { |
| | | uiStartMssk.gameObject.SetActive(true); |
| | | } |
| | | |
| | | public void HideUIMask() |
| | | { |
| | | uiStartMssk.gameObject.SetActive(false); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.AddGold, AddGold); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateWaterLv1, CreateWaterLv1); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateSecondWave, CreateSecondWave); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.SkillRelease, SkillRelease); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateThirdWave, CreateThirdWave); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateThirdWaveDone, CreateThirdWaveDone); |
| | | EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.GuideEnergyUp, GuideEnergyUp); |
| | | |
| | | |
| | | //EventCenter.Ins.Add((int)KTGMGemClient.EventType.SkillRelease, SkillRelease); |
| | | EventCenter.Ins.Add((int)KTGMGemClient.EventType.GuideFinish, NewbieGuideEnd); |
| | | } |
| | | |
| | | private void RemoveGuideEvent() |
| | | { |
| | | EventCenter.Ins.Remove((int)KTGMGemClient.EventType.CreateFireLv2, CreateFireLv2); |
| | | EventCenter.Ins.Remove((int)KTGMGemClient.EventType.CreateFirstWave, CreateFirstWave); |
| | | EventCenter.Ins.Remove((int)KTGMGemClient.EventType.RestartWave, RestartWave); |
| | | EventCenter.Ins.Remove<int>((int)KTGMGemClient.EventType.AddGold, AddGold); |
| | | EventCenter.Ins.Remove((int)KTGMGemClient.EventType.CreateWaterLv1, CreateWaterLv1); |
| | | EventCenter.Ins.Remove((int)KTGMGemClient.EventType.CreateSecondWave, CreateSecondWave); |
| | | EventCenter.Ins.Remove((int)KTGMGemClient.EventType.SkillRelease, SkillRelease); |
| | | EventCenter.Ins.Remove((int)KTGMGemClient.EventType.GuideFinish, NewbieGuideEnd); |
| | | } |
| | | |
| | | protected override void OnDestroy() |
| | | { |
| | | base.OnDestroy(); |
| | | RemoveGuideEvent(); |
| | | //EventCenter.Ins.Add<Vector3>((int)KTGMGemClient.EventType.PlayAppearEffect, GuidePlayAppearEffect); |
| | | EventCenter.Ins.Add<Vector3>((int)KTGMGemClient.EventType.GuidePlayUpgradeEffect, GuidePlayUpgradeEffect); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 在攻击位置上创建一个1级的水塔 |
| | | /// 新手引导生成特效 |
| | | /// </summary> |
| | | private void GuidePlayAppearEffect(Vector3 worldPos) |
| | | { |
| | | EndlessGameUI.instance.PlayAppearEffectGuide(worldPos); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 新手引导合成特效 |
| | | /// </summary> |
| | | private void GuidePlayUpgradeEffect(Vector3 worldPos) |
| | | { |
| | | EndlessGameUI.instance.GuidePlayUpgradeEffect(worldPos); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 在攻击位置上创建一个1级的木塔 |
| | | /// </summary> |
| | | private void CreateWaterLv1() |
| | | { |
| | | Tower aTower = EndlessRandomTower.instance.getTowerByName("CopyCatTower"); |
| | | Tower aTower = EndlessRandomTower.instance.getTowerByName("BlinkTower"); |
| | | EndlessGameUI.instance.PlaceTowerForce(aTower, new IntVector2(1, 3), 1); |
| | | } |
| | | |
| | |
| | | private void CreateSecondWave() |
| | | { |
| | | EndlessLevelManager.instance.NewbieUpdateLevel(); |
| | | beginSkillStep = true; |
| | | beginDragStep = true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 开始第三关 |
| | | /// </summary> |
| | | private void CreateThirdWave() |
| | | { |
| | | CommonDebugHelper.Debug($"开始下一关"); |
| | | |
| | | EndlessLevelManager.instance.NewbieUpdateLevel(); |
| | | beginDragStep = false; |
| | | guideThirdWaveStep = true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 第三关出兵完毕,暂停出兵 |
| | | /// </summary> |
| | | private void CreateThirdWaveDone() |
| | | { |
| | | EndlessLevelManager.instance.PauseWave(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 在第三条兵线释放技能宝石 |
| | |
| | | { |
| | | EndlessLevelManager.instance.RestartWave(); |
| | | GameConfig.IsNewbie = false; |
| | | transform.Find("Panel/SwitchSpeed").gameObject.SetActive(true); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | } |
| | | |
| | | #region 点击右侧技能按钮释放技能 |
| | | |
| | | private int fireSkillCost, bombSkillCost;//两个技能花费 |
| | | private int fireSkillID = 99902; |
| | | private int bombSkillID = 99901; |
| | | private int energyMax = 0;//能量最大值,目前写死 |
| | | private Color normalColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); |
| | | private Color disColor = new Color(1.0f, 1.0f, 1.0f, 0); |
| | | private Text fireSkillLevelText; |
| | | private Image fireSkillBgImg; |
| | | private ParticleSystem skillPS1, skillPS2; |
| | | |
| | | /// <summary> |
| | | /// 点击火技能 |
| | | /// </summary> |
| | | private void OnClickFireSkillBtn() |
| | | { |
| | | //Debug.Log("释放了火技能:" + GameConfig.EnergyCount + " fireSkillCost:" + fireSkillCost); |
| | | if (GameConfig.EnergyCount >= fireSkillCost) |
| | | { |
| | | EnergyUp(-fireSkillCost); |
| | | Debug.Log("释放了火技能" + GameConfig.SkillLevel); |
| | | // 播放特效,并处理伤害. |
| | | EndlessWaveLineManager.instance.PlayAllWaveLineEffect(); |
| | | AgentInsManager.instance.ExecAllWavelineAttack(fireSkillID, GameConfig.SkillLevel, false); |
| | | ++GameConfig.EndlessPortUseSkillTowerCount; |
| | | } |
| | | } |
| | | |
| | | public void GuideEnergyUp(int count) |
| | | { |
| | | GameConfig.EnergyCount = count; |
| | | EnergyUp(0); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 击杀小怪能量(释放技能使用) |
| | | /// </summary> |
| | | private void EnergyUp(int upCount) |
| | | { |
| | | Debug.Log("开始检查"); |
| | | |
| | | GameConfig.EnergyCount += upCount; |
| | | if (GameConfig.EnergyCount > energyMax) |
| | | { |
| | | GameConfig.EnergyCount = energyMax; |
| | | } |
| | | CalculateSkillSliderValue(); |
| | | |
| | | if (GameConfig.EnergyCount >= fireSkillCost) |
| | | { |
| | | if (GameConfig.EnergyCount == energyMax) |
| | | { |
| | | |
| | | Debug.Log("能量已满"); |
| | | if (fireSkillBgImg.color != disColor) |
| | | { |
| | | fireSkillBgImg.color = disColor; |
| | | } |
| | | skillPS1.Play(); |
| | | skillPS2.Play(); |
| | | } |
| | | else |
| | | { |
| | | Debug.Log("能量达到一次使用"); |
| | | if (fireSkillBgImg.color != normalColor) |
| | | { |
| | | fireSkillBgImg.color = normalColor; |
| | | } |
| | | if (skillPS1.isPlaying) skillPS1.Stop(); |
| | | if (!skillPS2.isPlaying) skillPS2.Play(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (fireSkillBgImg.color != normalColor) |
| | | { |
| | | fireSkillBgImg.color = normalColor; |
| | | } |
| | | if (skillPS1.isPlaying) skillPS1.Stop(); |
| | | if (skillPS2.isPlaying) skillPS2.Stop(); |
| | | |
| | | } |
| | | } |
| | | |
| | | RectTransform skillSliderValueRect; |
| | | Vector2 skillSliderVStartP; |
| | | Vector2 skillSliderVStartHeight; |
| | | |
| | | private void CalculateSkillSliderValue() |
| | | { |
| | | float value = (float)GameConfig.EnergyCount / 200.0f; |
| | | float height = skillSliderVStartHeight.y * value; |
| | | float y = skillSliderVStartP.y - (skillSliderVStartHeight.y - height) * 0.5f; |
| | | skillSliderValueRect.sizeDelta = new Vector2(skillSliderVStartHeight.x, height); |
| | | skillSliderValueRect.anchoredPosition = new Vector2(skillSliderVStartP.x, y); |
| | | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 增加技能等级的事件监听 |
| | | /// </summary> |
| | | private void SkillLevelUpBuff() |
| | | { |
| | | if (GameConfig.SkillLevel <= 5) |
| | | { |
| | | GameConfig.SkillLevel++; |
| | | fireSkillCost = JsonDataCenter.GetSkillLevelInfo(fireSkillID, GameConfig.SkillLevel).cost; |
| | | bombSkillCost = JsonDataCenter.GetSkillLevelInfo(bombSkillID, GameConfig.SkillLevel).cost; |
| | | //Debug.Log($"技能最高5级,当前技能等级:{GameConfig.SkillLevel} fireSkillCost:{fireSkillCost} "); |
| | | fireSkillLevelText.text = "Lv." + GameConfig.SkillLevel; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | public void Pause() |
| | | { |
| | | isPause = true; |
| | |
| | | // Update is called once per frame |
| | | void Update() |
| | | { |
| | | if (firstStart) |
| | | { |
| | | if (!GameConfig.JsonReadDone) |
| | | return; |
| | | else |
| | | { |
| | | firstStart = false; |
| | | CheckIsNewbie(); |
| | | } |
| | | } |
| | | if (isPause) return; |
| | | |
| | | if (bGameStart) |
| | |
| | | // 开启游戏,且隐藏中间的数字. |
| | | if (secToDo <= 0) |
| | | { |
| | | uiStartMssk.gameObject.SetActive(false); |
| | | HideUIMask(); |
| | | countDownTextNew.text = ""; |
| | | countDownTextNew.gameObject.SetActive(false); |
| | | bGameStart = true; |
| | |
| | | EndlessLevelManager.instance.StartLevel(); |
| | | timeTextNew.gameObject.SetActive(true); |
| | | |
| | | JsonDataReadDone(); |
| | | // 开始播放背景音乐. |
| | | if (bgMusic != null) |
| | | bgMusic.Play(); |
| | |
| | | EndlessLevelManager.instance.StartLevel(); |
| | | timeTextNew.gameObject.SetActive(true); |
| | | |
| | | JsonDataReadDone(); |
| | | |
| | | if (bgMusic != null) |
| | | bgMusic.Play(); |
| | | } |