Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Player.cs 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. using System;
  2. using System.ComponentModel;
  3. using GoogleMobileAds.Api;
  4. using TMPro;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using UnityEngine.SceneManagement;
  8. using UnityEngine.UI;
  9. using UnityEngine.Advertisements;
  10. using System.Data;
  11. public class Player : MonoBehaviour,IUnityAdsLoadListener, IUnityAdsShowListener
  12. {
  13. public CanvasScaler canvasScaler;
  14. private ScreenOrientation currentOrientation;
  15. #if UNITY_ANDROID
  16. private string _adUnitId = "ca-app-pub-3940256099942544/1033173712";
  17. //private string _adUnitId = "ca-app-pub-3570555734266765/2691950166";
  18. #elif UNITY_IPHONE
  19. private string _adUnitId = "ca-app-pub-3940256099942544/1033173712";
  20. //private string _adUnitId = "ca-app-pub-3570555734266765/2691950166";
  21. #else
  22. private string _adUnitId = "unused";
  23. #endif
  24. private InterstitialAd _interstitialAd;
  25. float speed;
  26. [SerializeField] int Hp;
  27. [SerializeField] GameObject[] HpBar,FloorPrefabs;
  28. [SerializeField] AudioClip[] AudioClip;
  29. [SerializeField] Sprite[] 頭頂尖刺;
  30. [SerializeField] TextMeshProUGUI scoreText,歷史最高_tb,關卡難度_tb,目前層數_tb,本丸可使用次數_tb,獲得菟菟幣_tb,吃到菟菟幣_tb,本丸數量_tb,氣泡文字_tb;
  31. [SerializeField] GameObject restart_pl,左按鈕_bt,右按鈕_bt,螢幕_pl,本丸_bt,看廣告_bt,背景_pl,回到遊戲_bt,頭頂刺,UT看廣告_bt,氣泡框_pl,復活菟_bt,快速購買_pl;
  32. [SerializeField] TextMeshProUGUI 菟菟能量_lb,目前層數_lb,菟菟幣_lb,選擇難度_lb,歷史層數_lb,下樓層數_lb,獲得菟菟幣_lb,繼續關卡使用本丸_lb,繼續關卡觀看廣告_lb,
  33. 重新開始_lb,回到主畫面_lb,繼續關卡_lb,繼續關卡觀看UT廣告_lb,復活菟數量_lb;
  34. [SerializeField] string _androidAdUnitId = "Interstitial_Android";
  35. [SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
  36. string _adUnitIds,氣泡框_開始,氣泡框_頭頂刺,氣泡框_地板刺,氣泡框_菟菟幣,氣泡框_加速,氣泡框_滿血包,氣泡框_減速,氣泡框_變大,氣泡框_縮小,氣泡框_冰凍;
  37. int score;
  38. float scoreTime;
  39. bool moveLeft,moveRight,加速=false,變大=false,縮小=false,停止=false,super=false,氣泡啟動=false;
  40. GameObject currentFloor = null;
  41. int coin_data=0,本丸_data=0,廣告_data=0;
  42. float timer1=0f,timer2=0f,timer3=0f,氣泡_Time=0f;
  43. private Rigidbody2D _rigidbody;
  44. // Start is called before the first frame updat
  45. void Awake(){
  46. _adUnitIds = (Application.platform == RuntimePlatform.IPhonePlayer) ? _iOsAdUnitId : _androidAdUnitId;
  47. }
  48. void Start(){
  49. timer1=0f;timer2=0f;timer3=0f;
  50. speed=500f;super=false;
  51. _rigidbody = transform.GetComponent<Rigidbody2D>();
  52. Screen.autorotateToPortrait = true;
  53. Screen.orientation = ScreenOrientation.AutoRotation;
  54. if (Main.Global.螢幕方向=="直"){
  55. canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
  56. canvasScaler.matchWidthOrHeight=Main.Global.固比;
  57. }else{
  58. canvasScaler.referenceResolution = new Vector2(Main.Global.固高, Main.Global.固寬);
  59. canvasScaler.matchWidthOrHeight=Main.Global.固比1;
  60. }
  61. currentOrientation = Screen.orientation;
  62. 左按鈕_bt .GetComponent<RectTransform>().sizeDelta=new Vector2(restart_pl.GetComponent<RectTransform>().rect.width / 2,左按鈕_bt.GetComponent<RectTransform>().sizeDelta.y);
  63. 右按鈕_bt .GetComponent<RectTransform>().sizeDelta=new Vector2(restart_pl.GetComponent<RectTransform>().rect.width / 2,右按鈕_bt.GetComponent<RectTransform>().sizeDelta.y);
  64. MobileAds.Initialize(initStatus => { });
  65. LoadInterstitialAd();
  66. 復活菟數量_lb.text = "復活菟數量 : " + Main.Global.使用者現金道具1;
  67. AudioSource audioSource = transform.GetComponent<AudioSource>();
  68. if(Main.Global.關卡難度=="一般"){
  69. 歷史最高_tb.text = Main.Global.一般最高;
  70. Hp=10;
  71. audioSource.clip = AudioClip[0];
  72. 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[0];
  73. 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,103f);
  74. 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,15f);
  75. 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,55f);
  76. 頭頂刺.GetComponent<BoxCollider2D>().offset=new Vector2(0f,-45f);
  77. FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[0]);
  78. }else if(Main.Global.關卡難度=="困難"){
  79. 歷史最高_tb.text = Main.Global.困難最高;
  80. Hp=10;
  81. audioSource.clip = AudioClip[1];
  82. 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[1];
  83. 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,80f);
  84. 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,22f);
  85. 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,37f);
  86. 頭頂刺.GetComponent<BoxCollider2D>().offset=new Vector2(0f,-43f);
  87. FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[1]);
  88. }else if(Main.Global.關卡難度=="地獄"){
  89. 歷史最高_tb.text = Main.Global.地獄最高;
  90. Hp=10;
  91. audioSource.clip = AudioClip[2];
  92. 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[2];
  93. 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,103f);
  94. 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,16f);
  95. 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,55f);
  96. 頭頂刺.GetComponent<BoxCollider2D>().offset=new Vector2(0f,-45f);
  97. FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[2]);
  98. }else{
  99. 歷史最高_tb.text = Main.Global.夢魘最高;
  100. Hp=10;
  101. audioSource.clip = AudioClip[3];
  102. 頭頂刺.GetComponent<Image>().sprite = 頭頂尖刺[3];
  103. 頭頂刺.GetComponent<RectTransform>().sizeDelta=new Vector2 (頭頂刺.GetComponent<RectTransform>().sizeDelta.x,115f);
  104. 頭頂刺.GetComponent<RectTransform>().anchoredPosition=new Vector2(頭頂刺.GetComponent<RectTransform>().anchoredPosition.x,20f);
  105. 頭頂刺.GetComponent<BoxCollider2D>().size=new Vector2(背景_pl.GetComponent<RectTransform>().rect.width-60f,55f);
  106. 頭頂刺.GetComponent<BoxCollider2D>().offset=new Vector2(0f,-45f);
  107. FloorManager.初始平台生成(螢幕_pl,FloorPrefabs[3]);
  108. }
  109. if(audioSource.isPlaying){audioSource.Stop();}
  110. audioSource.Play();
  111. 本丸_data=1;
  112. 廣告_data=3;
  113. score = 0;
  114. scoreTime = 0;
  115. UT看廣告_bt.SetActive(false);看廣告_bt.SetActive(true);復活菟_bt.SetActive(true);
  116. 快速購買_pl.SetActive(false);
  117. 系統語言轉換();
  118. Set_氣泡框();
  119. 氣泡啟動 = true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_開始;
  120. }
  121. void Update(){
  122. if(Main.Global.刷新現金道具2){
  123. Debug.Log("INN");
  124. Main.Global.刷新現金道具2=false;
  125. 快速購買_pl.SetActive(false);
  126. 復活菟數量_lb.text = "復活菟數量 : "+Main.Global.使用者現金道具1;
  127. }
  128. }
  129. // Update is called once per frame
  130. void FixedUpdate(){
  131. if(氣泡啟動){
  132. 氣泡框_pl.SetActive(true);
  133. 氣泡_Time += Time.deltaTime;
  134. if(氣泡_Time >= 2f){
  135. 氣泡啟動=false;氣泡_Time=0f;氣泡框_pl.SetActive(false);
  136. }
  137. }
  138. if(super){
  139. timer3 += Time.deltaTime;
  140. if(timer3 >= 3f){
  141. timer3=0f;
  142. super=false;
  143. GetComponent<Animator>().SetBool("Super",false);
  144. }
  145. }
  146. //Hp=10;
  147. if(加速){
  148. timer1 += Time.deltaTime;
  149. if(停止){
  150. if (timer1 >= 3f){timer1 = 0f;speed=500f;加速=false;停止=false;GetComponent<Animator>().SetBool("Freez",false);}
  151. }else{
  152. if (timer1 >= 5f){timer1 = 0f;speed=500f;加速=false;}
  153. }
  154. }
  155. if(變大){
  156. timer2 += Time.deltaTime;
  157. if (timer2 >= 5f){
  158. timer2 = 0f;
  159. if(縮小){
  160. 縮小=false;
  161. transform.GetComponent<RectTransform>().localPosition=new Vector3(transform.GetComponent<RectTransform>().localPosition.x,transform.GetComponent<RectTransform>().localPosition.y+100f,0f);
  162. }
  163. transform.GetComponent<RectTransform>().sizeDelta=new Vector2 (100f,100f);
  164. transform.GetComponent<BoxCollider2D>().size=new Vector2(79f,100f);
  165. transform.GetComponent<BoxCollider2D>().offset=new Vector2(3.6f,-50f);
  166. 變大=false;
  167. }
  168. }
  169. if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)){
  170. transform.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
  171. 氣泡框_pl.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
  172. //氣泡框_pl.transform.SetAsLastSibling();
  173. _rigidbody.velocity = new Vector2(speed ,_rigidbody.velocity.y);
  174. }else if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)){
  175. transform.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 180, 0);
  176. 氣泡框_pl.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
  177. //氣泡框_pl.transform.SetAsLastSibling();
  178. _rigidbody.velocity = new Vector2(-speed ,_rigidbody.velocity.y);
  179. }
  180. if(moveLeft){
  181. MoveLeft();
  182. }
  183. if(moveRight){
  184. MoveRight();
  185. }
  186. UpdateScore();
  187. }
  188. void OnCollisionEnter2D(Collision2D other){
  189. if(other.gameObject.tag == "Ceiling"){
  190. currentFloor.GetComponent<BoxCollider2D>().enabled = false;
  191. if(!super){ModifyHp(-3);GetComponent<Animator>().SetTrigger("Hurt");}
  192. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_頭頂刺;
  193. }
  194. if(other.gameObject.tag == "Floor_Normal"){
  195. if(other.contacts[0].normal == new Vector2(0f,1f)){
  196. currentFloor = other.gameObject;
  197. ModifyHp(1);
  198. }
  199. }else if(other.gameObject.tag == "Floor_Nails"){
  200. if(other.contacts[0].normal == new Vector2(0f,1f)){
  201. currentFloor = other.gameObject;
  202. if(!super){ModifyHp(-3);GetComponent<Animator>().SetTrigger("Hurt");}
  203. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_地板刺;
  204. }
  205. }else if(other.gameObject.tag == "Floor_Fake"){
  206. if(other.contacts[0].normal == new Vector2(0f,1f)){
  207. other.gameObject.GetComponent<BoxCollider2D>().enabled = false;
  208. ModifyHp(1);
  209. }
  210. }
  211. }
  212. void OnTriggerEnter2D(Collider2D other){
  213. if(other.gameObject.tag == "DeathLine"){
  214. Debug.Log("你輸了!");
  215. restart_pl.SetActive(true);
  216. if(Main.Global.系統語言=="中文"){
  217. 本丸可使用次數_tb.text = "本丸可使用次數 : "+本丸_data.ToString();
  218. 本丸數量_tb.text = "本丸持有數量 : "+Main.Global.使用者道具1;
  219. }else{
  220. 本丸可使用次數_tb.text = "本丸 can used : "+本丸_data.ToString();
  221. 本丸數量_tb.text = "本丸 Count : "+Main.Global.使用者道具1;
  222. }
  223. if(本丸_data>0 && int.Parse(Main.Global.使用者道具1)>0){本丸_bt.SetActive(true);}else{本丸_bt.SetActive(false);}
  224. if(廣告_data > 3){
  225. 看廣告_bt.SetActive(true);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false);
  226. }else if(廣告_data >= 1){
  227. 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(true);復活菟_bt.SetActive(false);
  228. }else{
  229. 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(true);
  230. }
  231. 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString();
  232. Time.timeScale = 0f;
  233. }else if(other.gameObject.tag == "coin"){
  234. Debug.Log("吃到錢錢!");
  235. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_菟菟幣;
  236. Destroy(other.gameObject);
  237. coin_data+=1;
  238. 吃到菟菟幣_tb.text=coin_data.ToString();
  239. Debug.Log("目前錢錢 : "+coin_data);
  240. }else if(other.gameObject.tag == "item_speed"){
  241. Debug.Log("吃到加速!");
  242. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_加速;
  243. timer1 = 0f;
  244. speed=1000f;
  245. Destroy(other.gameObject);
  246. 加速=true;
  247. }else if(other.gameObject.tag == "item_hpmax"){
  248. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_滿血包;
  249. ModifyHp(10);
  250. Destroy(other.gameObject);
  251. }else if(other.gameObject.tag == "item_slow"){
  252. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_減速;
  253. Destroy(other.gameObject);
  254. timer1 = 0f;
  255. speed=100f;
  256. 加速=true;
  257. }else if(other.gameObject.tag == "item_big"){
  258. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_變大;
  259. Destroy(other.gameObject);
  260. timer2 = 0f;
  261. 變大=true;
  262. transform.GetComponent<RectTransform>().localPosition=new Vector3(transform.GetComponent<RectTransform>().localPosition.x,transform.GetComponent<RectTransform>().localPosition.y+150f,0f);
  263. transform.GetComponent<RectTransform>().sizeDelta=new Vector2 (200f,200f);
  264. transform.GetComponent<BoxCollider2D>().size=new Vector2(158f,200f);
  265. transform.GetComponent<BoxCollider2D>().offset=new Vector2(7f,-100f);
  266. }else if(other.gameObject.tag == "item_small"){
  267. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_縮小;
  268. Destroy(other.gameObject);
  269. timer2 = 0f;
  270. 變大=true;縮小=true;
  271. transform.GetComponent<RectTransform>().sizeDelta=new Vector2 (50f,50f);
  272. transform.GetComponent<BoxCollider2D>().size=new Vector2(40f,50f);
  273. transform.GetComponent<BoxCollider2D>().offset=new Vector2(1.86f,-25f);
  274. }else if(other.gameObject.tag == "item_frezz"){
  275. 氣泡啟動=true;氣泡_Time=0f;氣泡文字_tb.text=氣泡框_冰凍;
  276. Destroy(other.gameObject);
  277. GetComponent<Animator>().SetBool("Freez",true);
  278. timer1 = 0f;
  279. speed=0f;
  280. 加速=true;停止=true;
  281. }
  282. }
  283. void ModifyHp(int num){
  284. Hp += num;
  285. if(Hp > 10){
  286. Hp = 10;
  287. }else if(Hp <= 0){
  288. Hp = 0;
  289. restart_pl.SetActive(true);
  290. if(Main.Global.系統語言=="中文"){
  291. 本丸可使用次數_tb.text = "本丸可使用次數 : "+本丸_data.ToString();
  292. 本丸數量_tb.text = "本丸持有數量 : "+Main.Global.使用者道具1;
  293. }else{
  294. 本丸可使用次數_tb.text = "本丸 can used : "+本丸_data.ToString();
  295. 本丸數量_tb.text = "本丸 Count : "+Main.Global.使用者道具1;
  296. }
  297. if(本丸_data>0 && int.Parse(Main.Global.使用者道具1)>0){本丸_bt.SetActive(true);}else{本丸_bt.SetActive(false);}
  298. if(廣告_data > 3){
  299. 看廣告_bt.SetActive(true);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false);
  300. }else if(廣告_data >= 1 && 廣告_data < 3){
  301. 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(true);復活菟_bt.SetActive(false);
  302. }else{
  303. 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(true);
  304. }
  305. 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString();
  306. Time.timeScale = 0f;
  307. }
  308. UpdateHpBar();
  309. }
  310. void UpdateHpBar(){
  311. for(int i=0;i<HpBar.Length;i++){
  312. if(Hp>i){
  313. HpBar[i].SetActive(true);
  314. }
  315. else
  316. {
  317. HpBar[i].SetActive(false);
  318. }
  319. }
  320. }
  321. void UpdateScore(){
  322. scoreTime +=Time.deltaTime;
  323. if(scoreTime>3f){
  324. score++;
  325. scoreTime = 0f;
  326. scoreText.text = score.ToString();
  327. 目前層數_tb.text = score.ToString();
  328. }
  329. }
  330. private void Set_氣泡框(){
  331. SQL_game_sys.SQL_氣泡框(Main.Global.關卡難度,Main.Global.系統語言);
  332. DataSet ds1 = new();
  333. SQL_Module.da.Fill(ds1);
  334. DataTable 氣泡框清單_table = ds1.Tables[0];
  335. for(int i=0;i<=氣泡框清單_table.Rows.Count-1;i++){
  336. if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="開始"){
  337. 氣泡框_開始 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  338. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="頭頂刺"){
  339. 氣泡框_頭頂刺 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  340. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="地板刺"){
  341. 氣泡框_地板刺 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  342. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="菟菟幣"){
  343. 氣泡框_菟菟幣 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  344. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="加速"){
  345. 氣泡框_加速 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  346. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="滿血包"){
  347. 氣泡框_滿血包 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  348. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="減速"){
  349. 氣泡框_減速 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  350. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="變大"){
  351. 氣泡框_變大 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  352. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="縮小"){
  353. 氣泡框_縮小 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  354. }else if(氣泡框清單_table.Rows[i]["使用範圍"].ToString()=="冰凍"){
  355. 氣泡框_冰凍 = 氣泡框清單_table.Rows[i]["氣泡內容"].ToString();
  356. }
  357. }
  358. }
  359. public void Replay(){
  360. if(int.Parse(scoreText.text) > int.Parse(歷史最高_tb.text)){
  361. SQL_game_sys.SQL_使用者_紀錄更新(Main.Global.關卡難度,scoreText.text,Main.Global.使用者UID);
  362. 歷史最高_tb.text=scoreText.text;
  363. if(Main.Global.關卡難度=="一般"){
  364. Main.Global.一般最高 = scoreText.text;
  365. }else if(Main.Global.關卡難度=="困難"){
  366. Main.Global.困難最高 = scoreText.text;
  367. }else if(Main.Global.關卡難度=="地獄"){
  368. Main.Global.地獄最高 = scoreText.text;
  369. }else if(Main.Global.關卡難度=="夢魘"){
  370. Main.Global.夢魘最高 = scoreText.text;
  371. }
  372. }
  373. double 目前金幣 = double.Parse(Main.Global.使用者金幣);
  374. double 新金幣 = 目前金幣 + double.Parse(獲得菟菟幣_tb.text);
  375. Main.Global.使用者金幣 = 新金幣.ToString();
  376. SQL_game_sys.SQL_使用者_金幣更新(Main.Global.使用者UID,Main.Global.使用者金幣);
  377. coin_data=0;本丸_data=1;廣告_data=3;
  378. Time.timeScale = 1f;
  379. SceneManager.LoadScene("Statge");
  380. }
  381. public void BackHome(){
  382. if(int.Parse(scoreText.text) > int.Parse(歷史最高_tb.text)){
  383. SQL_game_sys.SQL_使用者_紀錄更新(Main.Global.關卡難度,scoreText.text,Main.Global.使用者UID);
  384. 歷史最高_tb.text=scoreText.text;
  385. }
  386. double 目前金幣 = double.Parse(Main.Global.使用者金幣);
  387. double 新金幣 = 目前金幣 + double.Parse(獲得菟菟幣_tb.text);
  388. Main.Global.使用者金幣 = 新金幣.ToString();
  389. SQL_game_sys.SQL_使用者_金幣更新(Main.Global.使用者UID,Main.Global.使用者金幣);
  390. coin_data=0;本丸_data=1;廣告_data=3;
  391. Time.timeScale = 1f;
  392. SceneManager.LoadScene("Login");
  393. }
  394. public void MoveRight() {
  395. transform.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
  396. 氣泡框_pl.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
  397. _rigidbody.velocity = new Vector2(speed ,_rigidbody.velocity.y);
  398. }
  399. public void MoveLeft() {
  400. transform.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 180, 0);
  401. 氣泡框_pl.GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
  402. _rigidbody.velocity = new Vector2(-speed ,_rigidbody.velocity.y);
  403. }
  404. public void MouseDownL(){
  405. moveLeft = true;
  406. }
  407. public void MouseUpL(){
  408. moveLeft = false;
  409. }
  410. public void MouseDownR(){
  411. moveRight = true;
  412. }
  413. public void MouseUpR(){
  414. moveRight = false;
  415. }
  416. public void LoadInterstitialAd(){
  417. if (_interstitialAd != null){
  418. _interstitialAd.Destroy();
  419. _interstitialAd = null;
  420. }
  421. Debug.Log("Loading the interstitial ad.");
  422. var adRequest = new AdRequest();
  423. InterstitialAd.Load(_adUnitId, adRequest,(InterstitialAd ad, LoadAdError error) =>{
  424. if (error != null || ad == null){
  425. Debug.LogError("interstitial ad failed to load an ad with error : " + error);
  426. if(PlayerPrefs.HasKey("訂閱使用")){
  427. if(PlayerPrefs.GetString("訂閱使用")=="true" && 廣告_data > 0){
  428. 看廣告_bt.SetActive(true);
  429. }else{
  430. 看廣告_bt.SetActive(false);
  431. }
  432. }else{
  433. 看廣告_bt.SetActive(false);
  434. }
  435. return;
  436. }
  437. Debug.Log("Interstitial ad loaded with response : "+ ad.GetResponseInfo());
  438. _interstitialAd = ad;
  439. 看廣告_bt.SetActive(true);
  440. RegisterEventHandlers(_interstitialAd);
  441. });
  442. }
  443. public void ShowInterstitialAd(){
  444. int 廣告次數=0;
  445. SQL_game_sys.SQL_使用者_取得看廣告次數(Main.Global.使用者UID);
  446. if(SQL_Module.dr.Read()){
  447. if(DBNull.Value.Equals(SQL_Module.dr[0])){
  448. 廣告次數=0;
  449. }else{
  450. 廣告次數 = int.Parse(SQL_Module.dr[0].ToString());
  451. }
  452. }
  453. 廣告次數++;
  454. SQL_game_sys.SQL_使用者_更新看廣告次數(Main.Global.使用者UID,廣告次數.ToString(),DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  455. if(PlayerPrefs.HasKey("訂閱使用")){
  456. if(PlayerPrefs.GetString("訂閱使用")=="true"){
  457. restart_pl.SetActive(false);
  458. if(廣告_data >0){廣告_data--;}
  459. ModifyHp(10);
  460. super=true;
  461. GetComponent<Animator>().SetBool("Super",true);
  462. Time.timeScale = 1f;
  463. transform.GetComponent<RectTransform>().anchoredPosition=new Vector3(-225f,-100f,0f);
  464. }else{
  465. if (_interstitialAd != null && _interstitialAd.CanShowAd()){
  466. Debug.Log("Showing interstitial ad.");
  467. _interstitialAd.Show();
  468. }else{
  469. Debug.LogError("Interstitial ad is not ready yet.");
  470. }
  471. }
  472. }else{
  473. if (_interstitialAd != null && _interstitialAd.CanShowAd()){
  474. Debug.Log("Showing interstitial ad.");
  475. _interstitialAd.Show();
  476. }else{
  477. Debug.LogError("Interstitial ad is not ready yet.");
  478. }
  479. }
  480. }
  481. private void RegisterEventHandlers(InterstitialAd interstitialAd){
  482. interstitialAd.OnAdPaid += (AdValue adValue) =>{
  483. Debug.Log(String.Format("Interstitial ad paid {0} {1}.",adValue.Value,adValue.CurrencyCode));
  484. };
  485. interstitialAd.OnAdImpressionRecorded += () =>{
  486. Debug.Log("Interstitial ad recorded an impression.");
  487. };
  488. interstitialAd.OnAdClicked += () =>{
  489. Debug.Log("Interstitial ad was clicked.");
  490. };
  491. interstitialAd.OnAdFullScreenContentOpened += () =>{
  492. Debug.Log("Interstitial ad full screen content opened.");
  493. };
  494. interstitialAd.OnAdFullScreenContentClosed += () =>{
  495. Debug.Log("Interstitial ad full screen content closed.");
  496. LoadInterstitialAd();
  497. restart_pl.SetActive(false);
  498. if(廣告_data >0){廣告_data--;}
  499. ModifyHp(10);
  500. super=true;
  501. GetComponent<Animator>().SetBool("Super",true);
  502. Time.timeScale = 1f;
  503. transform.GetComponent<RectTransform>().anchoredPosition=new Vector3(-225f,-100f,0f);
  504. };
  505. interstitialAd.OnAdFullScreenContentFailed += (AdError error) =>{
  506. Debug.LogError("Interstitial ad failed to open full screen content with error : " + error);
  507. LoadInterstitialAd();
  508. };
  509. }
  510. public void LoadAd(){
  511. Debug.Log("Loading Ad: " + _adUnitIds);
  512. Advertisement.Load(_adUnitIds, this);
  513. }
  514. public void ShowAd(){
  515. Debug.Log("Showing Ad: " + _adUnitIds);
  516. Advertisement.Show(_adUnitIds, this);
  517. }
  518. public void OnUnityAdsAdLoaded(string adUnitIds){
  519. ShowAd();
  520. }
  521. public void OnUnityAdsFailedToLoad(string _adUnitIds, UnityAdsLoadError error, string message){
  522. Debug.Log($"Error loading Ad Unit: {_adUnitIds} - {error.ToString()} - {message}");
  523. }
  524. public void OnUnityAdsShowFailure(string _adUnitIds, UnityAdsShowError error, string message){
  525. Debug.Log($"Error showing Ad Unit {_adUnitIds}: {error.ToString()} - {message}");
  526. }
  527. public void OnUnityAdsShowStart(string _adUnitIds){
  528. }
  529. public void OnUnityAdsShowClick(string _adUnitIds){
  530. }
  531. public void OnUnityAdsShowComplete(string _adUnitIds, UnityAdsShowCompletionState showCompletionState){
  532. restart_pl.SetActive(false);
  533. if(廣告_data >0){廣告_data--;}
  534. ModifyHp(10);
  535. super=true;
  536. GetComponent<Animator>().SetBool("Super",true);
  537. Time.timeScale = 1f;
  538. transform.GetComponent<RectTransform>().anchoredPosition=new Vector3(-225f,-100f,0f);
  539. }
  540. public void 使用本丸(){
  541. int 本丸數 = int.Parse(Main.Global.使用者道具1);
  542. if(本丸數 > 0 && 本丸_data> 0){
  543. 本丸_data--;
  544. 本丸數--;
  545. SQL_game_sys.SQL_使用者_刷新本丸數量(Main.Global.使用者UID,本丸數.ToString());
  546. Main.Global.使用者道具1=本丸數.ToString();
  547. restart_pl.SetActive(false);
  548. Time.timeScale = 1f;
  549. super=true;
  550. GetComponent<Animator>().SetBool("Super",true);
  551. ModifyHp(10);
  552. transform.GetComponent<RectTransform>().anchoredPosition=new Vector3(-225f,-100f,0f);
  553. }
  554. }
  555. public void 使用復活菟(){
  556. int 復活菟數 = int.Parse(Main.Global.使用者現金道具1);
  557. if(復活菟數 > 0){
  558. 復活菟數--;
  559. SQL_game_sys.SQL_現金道具更新(Main.Global.使用者UID,"使用者現金道具1",復活菟數.ToString());
  560. Main.Global.使用者現金道具1=復活菟數.ToString();
  561. 復活菟數量_lb .text= "復活菟數量 : "+復活菟數.ToString();
  562. restart_pl.SetActive(false);
  563. Time.timeScale = 1f;
  564. super=true;
  565. GetComponent<Animator>().SetBool("Super",true);
  566. ModifyHp(10);
  567. transform.GetComponent<RectTransform>().anchoredPosition=new Vector3(-225f,-100f,0f);
  568. }else{
  569. 快速購買_pl.SetActive(true);
  570. }
  571. }
  572. public void 回到遊戲(){
  573. Time.timeScale = 1f;
  574. restart_pl.SetActive(false);
  575. if(廣告_data > 3){
  576. 看廣告_bt.SetActive(true);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false);
  577. }else if(廣告_data >= 1 && 廣告_data < 3){
  578. 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(true);復活菟_bt.SetActive(false);
  579. }else{
  580. 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(true);
  581. }
  582. 本丸_bt.SetActive(true);
  583. 回到遊戲_bt.SetActive(false);
  584. }
  585. public void 暫停(){
  586. Time.timeScale = 0f;
  587. if(Main.Global.系統語言=="中文"){
  588. 本丸可使用次數_tb.text = "本丸可使用次數 : "+本丸_data.ToString();
  589. 本丸數量_tb.text = "本丸持有數量 : "+Main.Global.使用者道具1;
  590. }else{
  591. 本丸可使用次數_tb.text = "本丸 can used : "+本丸_data.ToString();
  592. 本丸數量_tb.text = "本丸 Count : "+Main.Global.使用者道具1;
  593. }
  594. //if(本丸_data>0 && int.Parse(Main.Global.使用者道具1)>0){本丸_bt.SetActive(true);}else{本丸_bt.SetActive(false);}
  595. 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString();
  596. restart_pl.SetActive(true);
  597. 看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);復活菟_bt.SetActive(false);
  598. 本丸_bt.SetActive(false);
  599. 回到遊戲_bt.SetActive(true);
  600. }
  601. public void 關閉快速購買(){
  602. 快速購買_pl.SetActive(false);
  603. }
  604. void OnApplicationFocus(bool hasFocus) {
  605. if (hasFocus){
  606. Debug.Log("应用程序获得焦点");
  607. }else{
  608. if(!restart_pl.activeInHierarchy){
  609. Main.Global.失去焦點=true;
  610. Time.timeScale = 0f;
  611. if(Main.Global.系統語言=="中文"){
  612. 本丸可使用次數_tb.text = "本丸可使用次數 : "+本丸_data.ToString();
  613. 本丸數量_tb.text = "本丸持有數量 : "+Main.Global.使用者道具1;
  614. }else{
  615. 本丸可使用次數_tb.text = "本丸 can used : "+本丸_data.ToString();
  616. 本丸數量_tb.text = "本丸 Count : "+Main.Global.使用者道具1;
  617. }
  618. 獲得菟菟幣_tb .text = (int.Parse(目前層數_tb.text) + coin_data).ToString();
  619. restart_pl.SetActive(true);
  620. 本丸_bt.SetActive(false);看廣告_bt.SetActive(false);UT看廣告_bt.SetActive(false);
  621. 回到遊戲_bt.SetActive(true);復活菟_bt.SetActive(true);
  622. Debug.Log("应用程序失去焦点");
  623. }
  624. }
  625. }
  626. public static void 購買完成(string productId){
  627. Debug.Log("購買完成且成功 :"+productId);
  628. if(productId.Contains("tubao_coin")){
  629. for(int i=0;i<=Main.Global.道具清單_tabel.Rows.Count-1;i++){
  630. if(Main.Global.道具清單_tabel.Rows[i][2].ToString()==productId){
  631. int 獲得錢錢 = int.Parse(Main.Global.道具清單_tabel.Rows[i][1].ToString()[4..]);
  632. int 錢錢 = int.Parse(Main.Global.使用者金幣)+獲得錢錢;
  633. Main.Global.使用者金幣 = 錢錢.ToString();
  634. SQL_game_sys.SQL_使用者_金幣更新(Main.Global.使用者UID,Main.Global.使用者金幣);
  635. Main.Global.刷新金幣=true;
  636. break;
  637. }
  638. }
  639. }else if(productId=="tubao_noad1"){
  640. PlayerPrefs.SetString("訂閱使用","true");
  641. Main.Global.刷新訂閱時間=true;
  642. }else if(productId.Contains("tubao_life")){
  643. for(int i=0;i<=Main.Global.菟幣道具清單_tabel.Rows.Count-1;i++){
  644. if(Main.Global.菟幣道具清單_tabel.Rows[i][2].ToString()==productId){
  645. int 獲得錢錢 = int.Parse(Main.Global.菟幣道具清單_tabel.Rows[i][1].ToString()[4..]);
  646. string 道具對應名稱 = Main.Global.菟幣道具清單_tabel.Rows[i][5].ToString();
  647. if(道具對應名稱=="使用者現金道具1"){
  648. int 使用者道具 = int.Parse(Main.Global.使用者現金道具1);
  649. Main.Global.使用者現金道具1 = (使用者道具+獲得錢錢).ToString();
  650. SQL_game_sys.SQL_現金道具更新(Main.Global.使用者UID,道具對應名稱,Main.Global.使用者現金道具1);
  651. Main.Global.刷新現金道具2=true;
  652. }
  653. break;
  654. }
  655. }
  656. }
  657. }
  658. private void 系統語言轉換(){
  659. if(Main.Global.系統語言=="中文"){
  660. 關卡難度_tb.text = Main.Global.關卡難度;
  661. 菟菟能量_lb.text="菟菟能量";目前層數_lb.text="目前層數 :";菟菟幣_lb.text="菟菟幣 :";選擇難度_lb.text="難度 :";歷史層數_lb.text="歷史層數 :";
  662. 下樓層數_lb.text="下樓層數";獲得菟菟幣_lb.text="獲得菟菟幣";繼續關卡使用本丸_lb.text="繼續關卡-使用本丸";繼續關卡觀看廣告_lb.text="繼續關卡-觀看廣告";
  663. 重新開始_lb.text="重新開始";回到主畫面_lb.text="回到主畫面";繼續關卡_lb.text="繼續關卡";繼續關卡觀看UT廣告_lb.text="繼續關卡-觀看廣告";
  664. }else{
  665. if(Main.Global.關卡難度=="一般"){關卡難度_tb.text ="Normal";}else if(Main.Global.關卡難度=="困難"){關卡難度_tb.text ="Hard";}else if(Main.Global.關卡難度=="地獄"){關卡難度_tb.text ="Hell";}else{關卡難度_tb.text ="Nightmare";}
  666. 菟菟能量_lb.text="TuTu Hp";目前層數_lb.text="Now :";菟菟幣_lb.text="Coin :";選擇難度_lb.text="Difficulty :";歷史層數_lb.text="Top :";
  667. 下樓層數_lb.text="Level :";獲得菟菟幣_lb.text="Get Coin :";繼續關卡使用本丸_lb.text="Continue - Use 本丸";繼續關卡觀看廣告_lb.text="Continue - View AD";
  668. 重新開始_lb.text="ReStart";回到主畫面_lb.text="Main";繼續關卡_lb.text="Continue";繼續關卡觀看UT廣告_lb.text="Continue - View AD";
  669. }
  670. }
  671. }