Нема описа
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.

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