using System; using System.ComponentModel; using GoogleMobileAds.Api; using TMPro; using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.Advertisements; using System.Data; public class Player : MonoBehaviour,IUnityAdsLoadListener, IUnityAdsShowListener { public CanvasScaler canvasScaler; private ScreenOrientation currentOrientation; #if UNITY_ANDROID //private string _adUnitId = "ca-app-pub-3940256099942544/1033173712"; private string _adUnitId = "ca-app-pub-3570555734266765/2691950166"; #elif UNITY_IPHONE //private string _adUnitId = "ca-app-pub-3940256099942544/1033173712"; private string _adUnitId = "ca-app-pub-3570555734266765/2691950166"; #else private string _adUnitId = "unused"; #endif private InterstitialAd _interstitialAd; float speed; [SerializeField] int Hp; [SerializeField] GameObject[] HpBar,FloorPrefabs; [SerializeField] AudioClip[] AudioClip; [SerializeField] Sprite[] 頭頂尖刺; [SerializeField] TextMeshProUGUI scoreText,歷史最高_tb,關卡難度_tb,目前層數_tb,本丸可使用次數_tb,獲得菟菟幣_tb,吃到菟菟幣_tb,本丸數量_tb,氣泡文字_tb; [SerializeField] GameObject restart_pl,左按鈕_bt,右按鈕_bt,螢幕_pl,本丸_bt,看廣告_bt,背景_pl,回到遊戲_bt,頭頂刺,UT看廣告_bt,氣泡框_pl,復活菟_bt,快速購買_pl; [SerializeField] TextMeshProUGUI 菟菟能量_lb,目前層數_lb,菟菟幣_lb,選擇難度_lb,歷史層數_lb,本丸可使用次數_lb,本丸數量_lb,下樓層數_lb,獲得菟菟幣_lb,繼續關卡使用本丸_lb,繼續關卡觀看廣告_lb, 重新開始_lb,回到主畫面_lb,繼續關卡_lb,繼續關卡觀看UT廣告_lb,復活菟數量_lb,繼續關卡使用復活菟_lb,復活菟1_lb,復活菟2_lb,取消_lb; [SerializeField] string _androidAdUnitId = "Interstitial_Android"; [SerializeField] string _iOsAdUnitId = "Interstitial_iOS"; string _adUnitIds,氣泡框_開始,氣泡框_頭頂刺,氣泡框_地板刺,氣泡框_菟菟幣,氣泡框_加速,氣泡框_滿血包,氣泡框_減速,氣泡框_變大,氣泡框_縮小,氣泡框_冰凍; int score; float scoreTime; bool moveLeft,moveRight,加速=false,變大=false,縮小=false,停止=false,super=false,氣泡啟動=false; GameObject currentFloor = null; int coin_data=0,本丸_data=0,廣告_data=0; float timer1=0f,timer2=0f,timer3=0f,氣泡_Time=0f; private Rigidbody2D _rigidbody; // Start is called before the first frame updat void Awake(){ _adUnitIds = (Application.platform == RuntimePlatform.IPhonePlayer) ? _iOsAdUnitId : _androidAdUnitId; } void Start(){ timer1=0f;timer2=0f;timer3=0f; speed=500f;super=false; _rigidbody = transform.GetComponent(); Screen.autorotateToPortrait = true; Screen.orientation = ScreenOrientation.AutoRotation; if (Main.Global.螢幕方向=="直"){ canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高); canvasScaler.matchWidthOrHeight=Main.Global.固比; }else{ canvasScaler.referenceResolution = new Vector2(Main.Global.固高, Main.Global.固寬); canvasScaler.matchWidthOrHeight=Main.Global.固比1; } currentOrientation = Screen.orientation; 左按鈕_bt .GetComponent().sizeDelta=new Vector2(restart_pl.GetComponent().rect.width / 2,左按鈕_bt.GetComponent().sizeDelta.y); 右按鈕_bt .GetComponent().sizeDelta=new Vector2(restart_pl.GetComponent().rect.width / 2,右按鈕_bt.GetComponent().sizeDelta.y); MobileAds.Initialize(initStatus => { }); LoadInterstitialAd(); if(Main.Global.系統語言=="中文"){ 復活菟數量_lb .text= "復活菟數量 : "+ Main.Global.使用者現金道具1; }else{ 復活菟數量_lb .text= "Anabiosis Count : "+ Main.Global.使用者現金道具1; } AudioSource audioSource = transform.GetComponent(); if(Main.Global.關卡難度=="一般"){ 歷史最高_tb.text = Main.Global.一般最高; Hp=10; audioSource.clip = AudioClip[0]; 頭頂刺.GetComponent().sprite = 頭頂尖刺[0]; 頭頂刺.GetComponent().sizeDelta=new Vector2 (頭頂刺.GetComponent().sizeDelta.x,103f); 頭頂刺.GetComponent().anchoredPosition=new Vector2(頭頂刺.GetComponent().anchoredPosition.x,15f); 頭頂刺.GetComponent().size=new Vector2(背景_pl.GetComponent().rect.width-60f,55f); 頭頂刺.GetComponent().offset=new Vector2(0f,-45f); FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[0]); }else if(Main.Global.關卡難度=="困難"){ 歷史最高_tb.text = Main.Global.困難最高; Hp=10; audioSource.clip = AudioClip[1]; 頭頂刺.GetComponent().sprite = 頭頂尖刺[1]; 頭頂刺.GetComponent().sizeDelta=new Vector2 (頭頂刺.GetComponent().sizeDelta.x,80f); 頭頂刺.GetComponent().anchoredPosition=new Vector2(頭頂刺.GetComponent().anchoredPosition.x,22f); 頭頂刺.GetComponent().size=new Vector2(背景_pl.GetComponent().rect.width-60f,37f); 頭頂刺.GetComponent().offset=new Vector2(0f,-43f); FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[1]); }else if(Main.Global.關卡難度=="地獄"){ 歷史最高_tb.text = Main.Global.地獄最高; Hp=10; audioSource.clip = AudioClip[2]; 頭頂刺.GetComponent().sprite = 頭頂尖刺[2]; 頭頂刺.GetComponent().sizeDelta=new Vector2 (頭頂刺.GetComponent().sizeDelta.x,103f); 頭頂刺.GetComponent().anchoredPosition=new Vector2(頭頂刺.GetComponent().anchoredPosition.x,16f); 頭頂刺.GetComponent().size=new Vector2(背景_pl.GetComponent().rect.width-60f,55f); 頭頂刺.GetComponent().offset=new Vector2(0f,-45f); FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[2]); }else{ 歷史最高_tb.text = Main.Global.夢魘最高; Hp=10; audioSource.clip = AudioClip[3]; 頭頂刺.GetComponent().sprite = 頭頂尖刺[3]; 頭頂刺.GetComponent().sizeDelta=new Vector2 (頭頂刺.GetComponent().sizeDelta.x,115f); 頭頂刺.GetComponent().anchoredPosition=new Vector2(頭頂刺.GetComponent().anchoredPosition.x,20f); 頭頂刺.GetComponent().size=new Vector2(背景_pl.GetComponent().rect.width-60f,55f); 頭頂刺.GetComponent().offset=new Vector2(0f,-45f); FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[3]); } if(audioSource.isPlaying){audioSource.Stop();} audioSource.Play(); 本丸_data=1; 廣告_data=5; score = 0; scoreTime = 0; UT看廣告_bt.SetActive(false);看廣告_bt.SetActive(true);復活菟_bt.SetActive(true); 快速購買_pl.SetActive(false); 系統語言轉換(); Set_氣泡框(); 氣泡啟動 = true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_開始; } void Update(){ if(Main.Global.刷新現金道具2){ Debug.Log("INN"); Main.Global.刷新現金道具2=false; 快速購買_pl.SetActive(false); if(Main.Global.系統語言=="中文"){ 復活菟數量_lb .text= "復活菟數量 : "+ Main.Global.使用者現金道具1; }else{ 復活菟數量_lb .text= "Anabiosis Count : "+ Main.Global.使用者現金道具1; } } } // Update is called once per frame void FixedUpdate(){ if(氣泡啟動){ 氣泡框_pl.SetActive(true); 氣泡_Time += Time.deltaTime; if(氣泡_Time >= 2f){ 氣泡啟動=false;氣泡_Time=0f;氣泡框_pl.SetActive(false); } } if(super){ timer3 += Time.deltaTime; if(timer3 >= 3f){ timer3=0f; super=false; GetComponent().SetBool("Super",false); } } //Hp=10; if(加速){ timer1 += Time.deltaTime; if(停止){ if (timer1 >= 3f){timer1 = 0f;speed=500f;加速=false;停止=false;GetComponent().SetBool("Freez",false);} }else{ if (timer1 >= 5f){timer1 = 0f;speed=500f;加速=false;} } } if(變大){ timer2 += Time.deltaTime; if (timer2 >= 5f){ timer2 = 0f; if(縮小){ 縮小=false; transform.GetComponent().localPosition=new Vector3(transform.GetComponent().localPosition.x,transform.GetComponent().localPosition.y+100f,0f); } transform.GetComponent().sizeDelta=new Vector2 (100f,100f); transform.GetComponent().size=new Vector2(79f,100f); transform.GetComponent().offset=new Vector2(3.6f,-50f); 變大=false; } } if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)){ transform.GetComponent().rotation = Quaternion.Euler(0, 0, 0); 氣泡框_pl.GetComponent().rotation = Quaternion.Euler(0, 0, 0); //氣泡框_pl.transform.SetAsLastSibling(); _rigidbody.velocity = new Vector2(speed ,_rigidbody.velocity.y); }else if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)){ transform.GetComponent().rotation = Quaternion.Euler(0, 180, 0); 氣泡框_pl.GetComponent().rotation = Quaternion.Euler(0, 0, 0); //氣泡框_pl.transform.SetAsLastSibling(); _rigidbody.velocity = new Vector2(-speed ,_rigidbody.velocity.y); } if(moveLeft){ MoveLeft(); } if(moveRight){ MoveRight(); } UpdateScore(); } void OnCollisionEnter2D(Collision2D other){ if(other.gameObject.tag == "Ceiling"){ currentFloor.GetComponent().enabled = false; if(!super){ModifyHp(-3);GetComponent().SetTrigger("Hurt");} 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_頭頂刺; } if(other.gameObject.tag == "Floor_Normal"){ if(other.contacts[0].normal == new Vector2(0f,1f)){ currentFloor = other.gameObject; ModifyHp(1); } }else if(other.gameObject.tag == "Floor_Nails"){ if(other.contacts[0].normal == new Vector2(0f,1f)){ currentFloor = other.gameObject; if(!super){ModifyHp(-3);GetComponent().SetTrigger("Hurt");} 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_地板刺; } }else if(other.gameObject.tag == "Floor_Fake"){ if(other.contacts[0].normal == new Vector2(0f,1f)){ other.gameObject.GetComponent().enabled = false; ModifyHp(1); } } } void OnTriggerEnter2D(Collider2D other){ if(other.gameObject.tag == "DeathLine"){ Debug.Log("你輸了!"); restart_pl.SetActive(true); 本丸可使用次數_tb.text = 本丸_data.ToString(); 本丸數量_tb.text=Main.Global.使用者道具1; if(本丸_data>0 && int.Parse(Main.Global.使用者道具1)>0){本丸_bt.SetActive(true);}else{本丸_bt.SetActive(false);} if(廣告_data > 3){ 看廣告_bt.SetActive(true);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false); }else if(廣告_data >= 1){ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(true);復活菟_bt.SetActive(false); }else{ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(true); } 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString(); Time.timeScale = 0f; }else if(other.gameObject.tag == "coin"){ Debug.Log("吃到錢錢!"); 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_菟菟幣; Destroy(other.gameObject); coin_data+=1; 吃到菟菟幣_tb.text=coin_data.ToString(); Debug.Log("目前錢錢 : "+coin_data); }else if(other.gameObject.tag == "item_speed"){ Debug.Log("吃到加速!"); 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_加速; timer1 = 0f; speed=1000f; Destroy(other.gameObject); 加速=true; }else if(other.gameObject.tag == "item_hpmax"){ 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_滿血包; ModifyHp(10); Destroy(other.gameObject); }else if(other.gameObject.tag == "item_slow"){ 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_減速; Destroy(other.gameObject); timer1 = 0f; speed=100f; 加速=true; }else if(other.gameObject.tag == "item_big"){ 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_變大; Destroy(other.gameObject); timer2 = 0f; 變大=true; transform.GetComponent().localPosition=new Vector3(transform.GetComponent().localPosition.x,transform.GetComponent().localPosition.y+150f,0f); transform.GetComponent().sizeDelta=new Vector2 (200f,200f); transform.GetComponent().size=new Vector2(158f,200f); transform.GetComponent().offset=new Vector2(7f,-100f); }else if(other.gameObject.tag == "item_small"){ 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_縮小; Destroy(other.gameObject); timer2 = 0f; 變大=true;縮小=true; transform.GetComponent().sizeDelta=new Vector2 (50f,50f); transform.GetComponent().size=new Vector2(40f,50f); transform.GetComponent().offset=new Vector2(1.86f,-25f); }else if(other.gameObject.tag == "item_frezz"){ 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_冰凍; Destroy(other.gameObject); GetComponent().SetBool("Freez",true); timer1 = 0f; speed=0f; 加速=true;停止=true; } } void ModifyHp(int num){ Hp += num; if(Hp > 10){ Hp = 10; }else if(Hp <= 0){ Hp = 0; restart_pl.SetActive(true); 本丸可使用次數_tb.text = 本丸_data.ToString(); 本丸數量_tb.text=Main.Global.使用者道具1; if(本丸_data>0 && int.Parse(Main.Global.使用者道具1)>0){本丸_bt.SetActive(true);}else{本丸_bt.SetActive(false);} if(廣告_data > 3){ 看廣告_bt.SetActive(true);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false); }else if(廣告_data >= 1 && 廣告_data < 3){ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(true);復活菟_bt.SetActive(false); }else{ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(true); } 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString(); Time.timeScale = 0f; } UpdateHpBar(); } void UpdateHpBar(){ for(int i=0;ii){ HpBar[i].SetActive(true); } else { HpBar[i].SetActive(false); } } } void UpdateScore(){ scoreTime +=Time.deltaTime; if(scoreTime>3f){ score++; scoreTime = 0f; scoreText.text = score.ToString(); 目前層數_tb.text = score.ToString(); } } private void Set_氣泡框(){ SQL_game_sys.SQL_氣泡框(Main.Global.關卡難度,Main.Global.系統語言); DataSet ds1 = new(); SQL_Module.da.Fill(ds1); DataTable 氣泡框清單_table = ds1.Tables[0]; for(int i=0;i<=氣泡框清單_table.Rows.Count-1;i++){ if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="開始"){ 氣泡框_開始 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="頭頂刺"){ 氣泡框_頭頂刺 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="地板刺"){ 氣泡框_地板刺 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="菟菟幣"){ 氣泡框_菟菟幣 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="加速"){ 氣泡框_加速 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="滿血包"){ 氣泡框_滿血包 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="減速"){ 氣泡框_減速 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="變大"){ 氣泡框_變大 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="縮小"){ 氣泡框_縮小 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="冰凍"){ 氣泡框_冰凍 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString(); } } } public void Replay(){ if(int.Parse(scoreText.text) > int.Parse(歷史最高_tb.text)){ SQL_game_sys.SQL_使用者_紀錄更新(Main.Global.關卡難度,scoreText.text,Main.Global.使用者UID); 歷史最高_tb.text=scoreText.text; if(Main.Global.關卡難度=="一般"){ Main.Global.一般最高 = scoreText.text; }else if(Main.Global.關卡難度=="困難"){ Main.Global.困難最高 = scoreText.text; }else if(Main.Global.關卡難度=="地獄"){ Main.Global.地獄最高 = scoreText.text; }else if(Main.Global.關卡難度=="夢魘"){ Main.Global.夢魘最高 = scoreText.text; } } double 目前金幣 = double.Parse(Main.Global.使用者金幣); double 新金幣 = 目前金幣 + double.Parse(獲得菟菟幣_tb.text); Main.Global.使用者金幣 = 新金幣.ToString(); SQL_game_sys.SQL_使用者_金幣更新(Main.Global.使用者UID,Main.Global.使用者金幣); coin_data=0;本丸_data=1;廣告_data=5; Time.timeScale = 1f; SceneManager.LoadScene("Statge"); } public void BackHome(){ if(int.Parse(scoreText.text) > int.Parse(歷史最高_tb.text)){ SQL_game_sys.SQL_使用者_紀錄更新(Main.Global.關卡難度,scoreText.text,Main.Global.使用者UID); 歷史最高_tb.text=scoreText.text; } double 目前金幣 = double.Parse(Main.Global.使用者金幣); double 新金幣 = 目前金幣 + double.Parse(獲得菟菟幣_tb.text); Main.Global.使用者金幣 = 新金幣.ToString(); SQL_game_sys.SQL_使用者_金幣更新(Main.Global.使用者UID,Main.Global.使用者金幣); coin_data=0;本丸_data=1;廣告_data=5; Time.timeScale = 1f; SceneManager.LoadScene("Login"); } public void MoveRight() { transform.GetComponent().rotation = Quaternion.Euler(0, 0, 0); 氣泡框_pl.GetComponent().rotation = Quaternion.Euler(0, 0, 0); _rigidbody.velocity = new Vector2(speed ,_rigidbody.velocity.y); } public void MoveLeft() { transform.GetComponent().rotation = Quaternion.Euler(0, 180, 0); 氣泡框_pl.GetComponent().rotation = Quaternion.Euler(0, 0, 0); _rigidbody.velocity = new Vector2(-speed ,_rigidbody.velocity.y); } public void MouseDownL(){ moveLeft = true; } public void MouseUpL(){ moveLeft = false; } public void MouseDownR(){ moveRight = true; } public void MouseUpR(){ moveRight = false; } public void LoadInterstitialAd(){ if (_interstitialAd != null){ _interstitialAd.Destroy(); _interstitialAd = null; } Debug.Log("Loading the interstitial ad."); var adRequest = new AdRequest(); InterstitialAd.Load(_adUnitId, adRequest,(InterstitialAd ad, LoadAdError error) =>{ if (error != null || ad == null){ Debug.LogError("interstitial ad failed to load an ad with error : " + error); if(PlayerPrefs.HasKey("訂閱使用")){ if(PlayerPrefs.GetString("訂閱使用")=="true" && 廣告_data > 0){ 看廣告_bt.SetActive(true); }else{ 看廣告_bt.SetActive(false); } }else{ 看廣告_bt.SetActive(false); } return; } Debug.Log("Interstitial ad loaded with response : "+ ad.GetResponseInfo()); _interstitialAd = ad; 看廣告_bt.SetActive(true); RegisterEventHandlers(_interstitialAd); }); } public void ShowInterstitialAd(){ int 廣告次數=0; SQL_game_sys.SQL_使用者_取得看廣告次數(Main.Global.使用者UID); if(SQL_Module.dr.Read()){ if(DBNull.Value.Equals(SQL_Module.dr[0])){ 廣告次數=0; }else{ 廣告次數 = int.Parse(SQL_Module.dr[0].ToString()); } } 廣告次數++; SQL_game_sys.SQL_使用者_更新看廣告次數(Main.Global.使用者UID,廣告次數.ToString(),DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); if(PlayerPrefs.HasKey("訂閱使用")){ if(PlayerPrefs.GetString("訂閱使用")=="true"){ restart_pl.SetActive(false); if(廣告_data >0){廣告_data--;} ModifyHp(10); super=true; GetComponent().SetBool("Super",true); Time.timeScale = 1f; transform.GetComponent().anchoredPosition=new Vector3(-225f,-100f,0f); }else{ if (_interstitialAd != null && _interstitialAd.CanShowAd()){ Debug.Log("Showing interstitial ad."); _interstitialAd.Show(); }else{ Debug.LogError("Interstitial ad is not ready yet."); } } }else{ if (_interstitialAd != null && _interstitialAd.CanShowAd()){ Debug.Log("Showing interstitial ad."); _interstitialAd.Show(); }else{ Debug.LogError("Interstitial ad is not ready yet."); } } } private void RegisterEventHandlers(InterstitialAd interstitialAd){ interstitialAd.OnAdPaid += (AdValue adValue) =>{ Debug.Log(String.Format("Interstitial ad paid {0} {1}.",adValue.Value,adValue.CurrencyCode)); }; interstitialAd.OnAdImpressionRecorded += () =>{ Debug.Log("Interstitial ad recorded an impression."); }; interstitialAd.OnAdClicked += () =>{ Debug.Log("Interstitial ad was clicked."); }; interstitialAd.OnAdFullScreenContentOpened += () =>{ Debug.Log("Interstitial ad full screen content opened."); }; interstitialAd.OnAdFullScreenContentClosed += () =>{ Debug.Log("Interstitial ad full screen content closed."); LoadInterstitialAd(); restart_pl.SetActive(false); if(廣告_data >0){廣告_data--;} ModifyHp(10); super=true; GetComponent().SetBool("Super",true); Time.timeScale = 1f; transform.GetComponent().anchoredPosition=new Vector3(-225f,-100f,0f); }; interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>{ Debug.LogError("Interstitial ad failed to open full screen content with error : " + error); LoadInterstitialAd(); }; } public void LoadAd(){ Debug.Log("Loading Ad: " + _adUnitIds); Advertisement.Load(_adUnitIds, this); } public void ShowAd(){ Debug.Log("Showing Ad: " + _adUnitIds); Advertisement.Show(_adUnitIds, this); } public void OnUnityAdsAdLoaded(string adUnitIds){ ShowAd(); } public void OnUnityAdsFailedToLoad(string _adUnitIds, UnityAdsLoadError error, string message){ Debug.Log($"Error loading Ad Unit: {_adUnitIds} - {error.ToString()} - {message}"); } public void OnUnityAdsShowFailure(string _adUnitIds, UnityAdsShowError error, string message){ Debug.Log($"Error showing Ad Unit {_adUnitIds}: {error.ToString()} - {message}"); } public void OnUnityAdsShowStart(string _adUnitIds){ } public void OnUnityAdsShowClick(string _adUnitIds){ } public void OnUnityAdsShowComplete(string _adUnitIds, UnityAdsShowCompletionState showCompletionState){ restart_pl.SetActive(false); if(廣告_data >0){廣告_data--;} ModifyHp(10); super=true; GetComponent().SetBool("Super",true); Time.timeScale = 1f; transform.GetComponent().anchoredPosition=new Vector3(-225f,-100f,0f); } public void 使用本丸(){ int 本丸數 = int.Parse(Main.Global.使用者道具1); if(本丸數 > 0 && 本丸_data> 0){ 本丸_data--; 本丸數--; SQL_game_sys.SQL_使用者_刷新本丸數量(Main.Global.使用者UID,本丸數.ToString()); Main.Global.使用者道具1=本丸數.ToString(); restart_pl.SetActive(false); Time.timeScale = 1f; super=true; GetComponent().SetBool("Super",true); ModifyHp(10); transform.GetComponent().anchoredPosition=new Vector3(-225f,-100f,0f); } } public void 使用復活菟(){ int 復活菟數 = int.Parse(Main.Global.使用者現金道具1); if(復活菟數 > 0){ 復活菟數--; SQL_game_sys.SQL_現金道具更新(Main.Global.使用者UID,"使用者現金道具1",復活菟數.ToString()); Main.Global.使用者現金道具1=復活菟數.ToString(); if(Main.Global.系統語言=="中文"){ 復活菟數量_lb .text= "復活菟數量 : "+復活菟數.ToString(); }else{ 復活菟數量_lb .text= "Anabiosis Count : "+復活菟數.ToString(); } restart_pl.SetActive(false); Time.timeScale = 1f; super=true; GetComponent().SetBool("Super",true); ModifyHp(10); transform.GetComponent().anchoredPosition=new Vector3(-225f,-100f,0f); }else{ 快速購買_pl.SetActive(true); } } public void 回到遊戲(){ Time.timeScale = 1f; restart_pl.SetActive(false); if(廣告_data > 3){ 看廣告_bt.SetActive(true);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false); }else if(廣告_data >= 1 && 廣告_data < 3){ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(true);復活菟_bt.SetActive(false); }else{ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(true); } 本丸_bt.SetActive(true); 回到遊戲_bt.SetActive(false); } public void 暫停(){ Time.timeScale = 0f; 本丸可使用次數_tb.text = 本丸_data.ToString(); 本丸數量_tb.text=Main.Global.使用者道具1; //if(本丸_data>0 && int.Parse(Main.Global.使用者道具1)>0){本丸_bt.SetActive(true);}else{本丸_bt.SetActive(false);} 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString(); restart_pl.SetActive(true); 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false); 本丸_bt.SetActive(false); 回到遊戲_bt.SetActive(true); } public void 關閉快速購買(){ 快速購買_pl.SetActive(false); } void OnApplicationFocus(bool hasFocus) { if (hasFocus){ Debug.Log("应用程序获得焦点"); }else{ if(!restart_pl.activeInHierarchy){ Main.Global.失去焦點=true; Time.timeScale = 0f; 本丸可使用次數_tb.text = 本丸_data.ToString(); 本丸數量_tb.text=Main.Global.使用者道具1; if(本丸_data>0 && int.Parse(Main.Global.使用者道具1)>0){本丸_bt.SetActive(true);}else{本丸_bt.SetActive(false);} 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString(); restart_pl.SetActive(true); if(廣告_data > 3){ 看廣告_bt.SetActive(true);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false); }else if(廣告_data >= 1 && 廣告_data < 3){ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(true);復活菟_bt.SetActive(false); }else{ 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(true); } 本丸_bt.SetActive(false); 回到遊戲_bt.SetActive(true); Debug.Log("应用程序失去焦点"); } } } public static void 購買完成(string productId){ Debug.Log("購買完成且成功 :"+productId); if(productId.Contains("tubao_coin")){ for(int i=0;i<=Main.Global.道具清單_tabel.Rows.Count-1;i++){ if(Main.Global.道具清單_tabel.Rows[i][2].ToString()==productId){ int 獲得錢錢 = int.Parse(Main.Global.道具清單_tabel.Rows[i][1].ToString()[4..]); int 錢錢 = int.Parse(Main.Global.使用者金幣)+獲得錢錢; Main.Global.使用者金幣 = 錢錢.ToString(); SQL_game_sys.SQL_使用者_金幣更新(Main.Global.使用者UID,Main.Global.使用者金幣); Main.Global.刷新金幣=true; break; } } }else if(productId=="tubao_noad1"){ PlayerPrefs.SetString("訂閱使用","true"); Main.Global.刷新訂閱時間=true; }else if(productId.Contains("tubao_life")){ for(int i=0;i<=Main.Global.菟幣道具清單_tabel.Rows.Count-1;i++){ if(Main.Global.菟幣道具清單_tabel.Rows[i][2].ToString()==productId){ int 獲得錢錢 = int.Parse(Main.Global.菟幣道具清單_tabel.Rows[i][1].ToString()[4..]); string 道具對應名稱 = Main.Global.菟幣道具清單_tabel.Rows[i][5].ToString(); if(道具對應名稱=="使用者現金道具1"){ int 使用者道具 = int.Parse(Main.Global.使用者現金道具1); Main.Global.使用者現金道具1 = (使用者道具+獲得錢錢).ToString(); SQL_game_sys.SQL_現金道具更新(Main.Global.使用者UID,道具對應名稱,Main.Global.使用者現金道具1); Main.Global.刷新現金道具2=true; } break; } } } } private void 系統語言轉換(){ if(Main.Global.系統語言=="中文"){ 關卡難度_tb.text = Main.Global.關卡難度; 菟菟能量_lb.text="菟菟能量";目前層數_lb.text="目前層數 :";菟菟幣_lb.text="菟菟幣 :";選擇難度_lb.text="難度 :";歷史層數_lb.text="歷史層數 :";本丸可使用次數_lb.text="本丸可使用次數 :"; 本丸數量_lb.text="本丸持有數量 :";下樓層數_lb.text="下樓層數";獲得菟菟幣_lb.text="獲得菟菟幣";繼續關卡使用本丸_lb.text="繼續關卡-使用本丸";繼續關卡觀看廣告_lb.text="繼續關卡-觀看廣告"; 重新開始_lb.text="重新開始";回到主畫面_lb.text="回到主畫面";繼續關卡_lb.text="繼續關卡";繼續關卡觀看UT廣告_lb.text="繼續關卡-觀看廣告";復活菟1_lb.text="復活菟x5";復活菟2_lb.text="復活菟x50"; 取消_lb.text="取消"; 繼續關卡使用復活菟_lb.text="繼續關卡-使用復活菟"; }else{ if(Main.Global.關卡難度=="一般"){關卡難度_tb.text ="Normal";}else if(Main.Global.關卡難度=="困難"){關卡難度_tb.text ="Hard";}else if(Main.Global.關卡難度=="地獄"){關卡難度_tb.text ="Hell";}else{關卡難度_tb.text ="Nightmare";} 菟菟能量_lb.text="TuTu Hp";目前層數_lb.text="Now :";菟菟幣_lb.text="Coin :";選擇難度_lb.text="Difficulty :";歷史層數_lb.text="Top :";本丸可使用次數_lb.text="本丸 can be used :"; 本丸數量_lb.text="本丸 Count :";下樓層數_lb.text="Level :";獲得菟菟幣_lb.text="Get Coin :";繼續關卡使用本丸_lb.text="Continue - Use 本丸";繼續關卡觀看廣告_lb.text="Continue - View AD"; 重新開始_lb.text="ReStart";回到主畫面_lb.text="Main";繼續關卡_lb.text="Continue";繼續關卡觀看UT廣告_lb.text="Continue - View AD";繼續關卡使用復活菟_lb.text="Continue - Anabiosis"; 復活菟1_lb.text="Anabiosisx5";復活菟2_lb.text="Anabiosisx50";取消_lb.text="Cancel"; } } }