123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- 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<Rigidbody2D>();
- 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<RectTransform>().sizeDelta=new Vector2(restart_pl.GetComponent<RectTransform>().rect.width / 2,左按鈕_bt.GetComponent<RectTransform>().sizeDelta.y);
- 右按鈕_bt .GetComponent<RectTransform>().sizeDelta=new Vector2(restart_pl.GetComponent<RectTransform>().rect.width / 2,右按鈕_bt.GetComponent<RectTransform>().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<AudioSource>();
- if(Main.Global.關卡難度=="一般"){
- 歷史最高_tb.text = Main.Global.一般最高;
- Hp=10;
- audioSource.clip = AudioClip[0];
- 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[0];
- 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,103f);
- 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,15f);
- 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,55f);
- 頭頂刺.GetComponent<BoxCollider2D>().offset=new Vector2(0f,-45f);
- FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[0]);
- }else if(Main.Global.關卡難度=="困難"){
- 歷史最高_tb.text = Main.Global.困難最高;
- Hp=10;
- audioSource.clip = AudioClip[1];
- 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[1];
- 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,80f);
- 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,22f);
- 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,37f);
- 頭頂刺.GetComponent<BoxCollider2D>().offset=new Vector2(0f,-43f);
- FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[1]);
- }else if(Main.Global.關卡難度=="地獄"){
- 歷史最高_tb.text = Main.Global.地獄最高;
- Hp=10;
- audioSource.clip = AudioClip[2];
- 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[2];
- 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,103f);
- 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,16f);
- 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,55f);
- 頭頂刺.GetComponent<BoxCollider2D>().offset=new Vector2(0f,-45f);
- FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[2]);
- }else{
- 歷史最高_tb.text = Main.Global.夢魘最高;
- Hp=10;
- audioSource.clip = AudioClip[3];
- 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[3];
- 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,115f);
- 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,20f);
- 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,55f);
- 頭頂刺.GetComponent<BoxCollider2D>().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<Animator>().SetBool("Super",false);
- }
-
- }
- //Hp=10;
- if(加速){
- timer1 += Time.deltaTime;
- if(停止){
- if (timer1 >= 3f){timer1 = 0f;speed=500f;加速=false;停止=false;GetComponent<Animator>().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<RectTransform>().localPosition=new Vector3(transform.GetComponent<RectTransform>().localPosition.x,transform.GetComponent<RectTransform>().localPosition.y+100f,0f);
- }
- transform.GetComponent<RectTransform>().sizeDelta=new Vector2 (100f,100f);
- transform.GetComponent<BoxCollider2D>().size=new Vector2(79f,100f);
- transform.GetComponent<BoxCollider2D>().offset=new Vector2(3.6f,-50f);
- 變大=false;
- }
- }
- if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)){
- transform.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
- 氣泡框_pl.GetComponent<RectTransform>().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<RectTransform>().rotation = Quaternion.Euler(0, 180, 0);
- 氣泡框_pl.GetComponent<RectTransform>().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<BoxCollider2D>().enabled = false;
- if(!super){ModifyHp(-3);GetComponent<Animator>().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<Animator>().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<BoxCollider2D>().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<RectTransform>().localPosition=new Vector3(transform.GetComponent<RectTransform>().localPosition.x,transform.GetComponent<RectTransform>().localPosition.y+150f,0f);
- transform.GetComponent<RectTransform>().sizeDelta=new Vector2 (200f,200f);
- transform.GetComponent<BoxCollider2D>().size=new Vector2(158f,200f);
- transform.GetComponent<BoxCollider2D>().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<RectTransform>().sizeDelta=new Vector2 (50f,50f);
- transform.GetComponent<BoxCollider2D>().size=new Vector2(40f,50f);
- transform.GetComponent<BoxCollider2D>().offset=new Vector2(1.86f,-25f);
- }else if(other.gameObject.tag == "item_frezz"){
- 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_冰凍;
- Destroy(other.gameObject);
- GetComponent<Animator>().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;i<HpBar.Length;i++){
- if(Hp>i){
- 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<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
- 氣泡框_pl.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
- _rigidbody.velocity = new Vector2(speed ,_rigidbody.velocity.y);
- }
-
- public void MoveLeft() {
- transform.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 180, 0);
- 氣泡框_pl.GetComponent<RectTransform>().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<Animator>().SetBool("Super",true);
- Time.timeScale = 1f;
- transform.GetComponent<RectTransform>().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<Animator>().SetBool("Super",true);
- Time.timeScale = 1f;
- transform.GetComponent<RectTransform>().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<Animator>().SetBool("Super",true);
- Time.timeScale = 1f;
- transform.GetComponent<RectTransform>().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<Animator>().SetBool("Super",true);
- ModifyHp(10);
- transform.GetComponent<RectTransform>().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<Animator>().SetBool("Super",true);
- ModifyHp(10);
- transform.GetComponent<RectTransform>().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";
- }
- }
-
- }
|