Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.69 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.SceneManagement;
  4. using System.Collections.Generic;
  5. using Newtonsoft.Json;
  6. using UnityEngine.UI;
  7. using System;
  8. using SmartLocalization;
  9. using System.Diagnostics;
  10.  
  11. public class MainMenuController : MonoBehaviour {
  12.  
  13. public UpperMenu upperMenu;
  14. public InputField adressText;
  15. public InputField typeText;
  16. public InputField descText;
  17. public InputField userText;
  18. public InputField dateText;
  19.  
  20. public InputField debugText;
  21.  
  22. public InputField pointsSmInputField;
  23. public InputField pointsInputField;
  24. public InputField sectorsInputField;
  25. public InputField speedInputField;
  26.  
  27. public Text debugPathText;
  28. public Text dealer;
  29.  
  30. public static MainMenuController Instance;
  31.  
  32. public Dropdown typeDropdown;
  33.  
  34. public MainMenuSettings settings;
  35.  
  36. public GameObject SettingsDeviceBtn;
  37. public GameObject SettingsOpenLaucherPrompt;
  38. public PinPromptWindow PromptWindow;
  39. public GameObject DeviceSettingsWindow;
  40. public Text ErrorText;
  41. public GameObject ErrorBtn;
  42. public GameObject ErrorWindow;
  43.  
  44. public Text shortSerialText;
  45. public Text longSerialText;
  46.  
  47. private AndroidJavaObject gpsActivityJavaClass;
  48.  
  49. private bool isDemo = false;
  50.  
  51. public AsyncOperation _async;
  52.  
  53. void Awake()
  54. {
  55. //PlayerPrefs.DeleteAll();
  56. Instance = this;
  57. if (PlayerPrefs.HasKey("lang"))
  58. {
  59. LanguageManager.Instance.ChangeLanguage(PlayerPrefs.GetString("lang"));
  60. }
  61. else
  62. {
  63. SmartCultureInfo deviceCulture = LanguageManager.Instance.GetDeviceCultureIfSupported();
  64. if (deviceCulture != null)
  65. {
  66. LanguageManager.Instance.ChangeLanguage(deviceCulture);
  67. }
  68. else
  69. {
  70. LanguageManager.Instance.ChangeLanguage("ru");
  71. }
  72. }
  73.  
  74. if (PlayerPrefs.GetInt("metrics") == 0)
  75. {
  76. PlayerPrefs.SetInt("metrics", 8);
  77. }
  78. if (PlayerPrefs.GetInt("toggleCount") == 0)
  79. {
  80. PlayerPrefs.SetInt("toggleCount", 1);
  81. }
  82. if (PlayerPrefs.GetInt("om") == 0)
  83. {
  84. PlayerPrefs.SetInt("om", 30);
  85. }
  86.  
  87. adressText.text = PlayerPrefs.GetString("address");
  88. typeText.text = PlayerPrefs.GetInt("typeDrop", 0).ToString();
  89. descText.text = PlayerPrefs.GetString("desc");
  90. userText.text = PlayerPrefs.GetString("userLbl");
  91.  
  92. typeDropdown.options.Clear();
  93. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Spraying")));
  94. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Fertilizers")));
  95. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Cultivation")));
  96. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Harrowing")));
  97. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Sowing")));
  98. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Harvest")));
  99. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Another")));
  100. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Metering")));
  101. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Air")));
  102. //typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Transport")));
  103. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Plowing")));
  104. typeDropdown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Loosening")));
  105. typeDropdown.value = PlayerPrefs.GetInt("typeDrop", 0);
  106. typeDropdown.RefreshShownValue();
  107.  
  108.  
  109. }
  110. public void Start()
  111. {
  112. #if UNITY_WSA_10_0 && !UNITY_EDITOR
  113. dateText.text = DateTime.Now.ToString();
  114. UnityBluetoothLibrary.UnityBluetooth.EnableBluetooth();
  115.  
  116. #elif UNITY_ANDROID && !UNITY_EDITOR
  117. dateText.text = DateTime.Now.Date.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
  118. AndroidJNI.AttachCurrentThread();
  119. using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  120. {
  121. using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  122. {
  123. gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
  124. }
  125. }
  126. #endif
  127. SaveController.Instance.data = new SaveData();
  128. SaveController.Instance.saveName = "";
  129. debugPathText.text = System.IO.Path.Combine(Application.streamingAssetsPath, "test.db");
  130.  
  131.  
  132. pointsInputField.text = PlayerPrefs.GetFloat("startDevicedSquare").ToString();
  133. sectorsInputField.text = PlayerPrefs.GetInt("startDevicedSquareCount").ToString();
  134. speedInputField.text = PlayerPrefs.GetFloat("startDevicedSpeed").ToString();
  135. dealer.text = PlayerPrefs.GetString("delader");
  136.  
  137. if(ConstConfig.isDemo)
  138. {
  139. PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("OriginalDemo"));
  140. dealer.text = PlayerPrefs.GetString("delader");
  141. }
  142.  
  143. Screen.sleepTimeout = SleepTimeout.NeverSleep;
  144.  
  145. #if !UNITY_WSA_10_0 || UNITY_EDITOR
  146.  
  147. _async = SceneManager.LoadSceneAsync("Main");
  148. _async.allowSceneActivation = false;
  149. #endif
  150. CheckLauncher();
  151. CheckOriginalDevice();
  152. }
  153.  
  154. public void DeleteAllPrefs()
  155. {
  156. PlayerPrefs.DeleteAll();
  157. }
  158.  
  159. public void ChangeTexts()
  160. {
  161. pointsInputField.text = PlayerPrefs.GetFloat("startDevicedSquare").ToString();
  162. sectorsInputField.text = PlayerPrefs.GetInt("startDevicedSquareCount").ToString();
  163. speedInputField.text = PlayerPrefs.GetFloat("startDevicedSpeed").ToString();
  164. if (PlayerPrefs.GetInt("Inner") == 1)
  165. {
  166. if(PlayerPrefs.GetInt("VelestorDevice") == 0)
  167. {
  168. PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("Original"));
  169. }
  170. dealer.text = PlayerPrefs.GetString("delader");
  171. }
  172. else
  173. {
  174. dealer.text = PlayerPrefs.GetString("delader");
  175. }
  176. }
  177.  
  178. public void CheckLauncher()
  179. {
  180. #if UNITY_ANDROID && !UNITY_EDITOR
  181. if (!gpsActivityJavaClass.CallStatic<bool>("isMyLauncherDefault"))
  182. {
  183. SettingsOpenLaucherPrompt.SetActive(true);
  184. SettingsDeviceBtn.SetActive(false);
  185. }
  186. if (gpsActivityJavaClass.CallStatic<bool>("isMyLauncherDefault"))
  187. {
  188. SettingsDeviceBtn.SetActive(true);
  189. SettingsOpenLaucherPrompt.SetActive(false);
  190. }
  191. #endif
  192. }
  193.  
  194. public void CheckOriginalDevice()
  195. {
  196. if (PlayerPrefs.GetInt("VelestorDevice") == 0)
  197. {
  198. typeDropdown.interactable = false;
  199. }
  200. else
  201. {
  202. typeDropdown.interactable = true;
  203. }
  204.  
  205. }
  206.  
  207. public void OpenWLAN()
  208. {
  209. gpsActivityJavaClass.CallStatic<string>("OpenWifi");
  210. }
  211.  
  212. public void OpenSim()
  213. {
  214. gpsActivityJavaClass.CallStatic<string>("OpenNetwork");
  215. }
  216.  
  217. public void OpenSound()
  218. {
  219. gpsActivityJavaClass.CallStatic<string>("OpenSound");
  220. }
  221.  
  222. private int _errorOpenDevice = 0;
  223. public void OpenDeviceSettings()
  224. {
  225. PromptWindow.Open((r) =>
  226. {
  227. if (r == PlayerPrefs.GetString("key"))
  228. {
  229. gpsActivityJavaClass.CallStatic<string>("OpenSettings");
  230. PromptWindow.gameObject.SetActive(false);
  231. }
  232. else
  233. {
  234. _errorOpenDevice++;
  235. PromptWindow.gameObject.SetActive(false);
  236. if (_errorOpenDevice >= 3)
  237. {
  238. ShowBLock();
  239. }
  240. }
  241. });
  242. }
  243.  
  244. private void ShowBLock()
  245. {
  246. ErrorText.text = LanguageManager.Instance.GetTextValue("HelpBtnKey");
  247. ErrorBtn.SetActive(false);
  248. ErrorWindow.SetActive(true);
  249. StartCoroutine(CloseError());
  250. }
  251.  
  252. private IEnumerator CloseError()
  253. {
  254. yield return new WaitForSeconds(600);
  255. ErrorWindow.SetActive(false);
  256. }
  257.  
  258. public void OpenLaucherPrompt()
  259. {
  260. if (PlayerPrefs.GetInt("VelestorDevice") == 1)
  261. {
  262. gpsActivityJavaClass.CallStatic<string>("OpenLauncherPrompt");
  263. }
  264. else
  265. {
  266. StartCoroutine(MainMenuSettings.Instance.OpenCantOpenWindow());
  267. }
  268. }
  269.  
  270. public void DeleteAll()
  271. {
  272. PlayerPrefs.DeleteAll();
  273. SceneManager.LoadScene("Menu");
  274.  
  275. }
  276.  
  277. public void SetDemoMode()
  278. {
  279. isDemo = true;
  280. }
  281.  
  282. public void OnStartClicked()
  283. {
  284. if (upperMenu.isNewWork)
  285. {
  286. if (String.IsNullOrEmpty(adressText.text))
  287. {
  288. adressText.text = "-";
  289. }
  290. else
  291. {
  292. PlayerPrefs.SetString("address", adressText.text);
  293. }
  294. if (String.IsNullOrEmpty(typeText.text))
  295. {
  296. typeText.text = "-";
  297. }
  298. else
  299. {
  300. PlayerPrefs.SetString("type", typeText.text);
  301. }
  302. if (String.IsNullOrEmpty(descText.text))
  303. {
  304. descText.text = "-";
  305. }
  306. else
  307. {
  308. PlayerPrefs.SetString("desc", descText.text);
  309. }
  310. if (String.IsNullOrEmpty(userText.text))
  311. {
  312. userText.text = "-";
  313. }
  314. else
  315. {
  316. PlayerPrefs.SetString("userLbl", userText.text);
  317. }
  318. if (String.IsNullOrEmpty(adressText.text))
  319. {
  320. adressText.text = "-";
  321. }
  322. PlayerPrefs.SetInt("typeDrop", typeDropdown.value);
  323. typeText.text = typeDropdown.value.ToString();
  324.  
  325. if (typeDropdown.value != 0)
  326. {
  327. PlayerPrefs.SetInt("toggleCount", 1);
  328. settings.toggleCount = 1;
  329. }
  330.  
  331.  
  332.  
  333. SaveData data = new SaveData();
  334. data.positions = new List<Meshes>();
  335. data.curves = new List<CurvePoint>();
  336. data.date = dateText.text;
  337. data.adress = adressText.text;
  338. data.type = typeText.text;
  339. data.description = descText.text;
  340. data.user = userText.text;
  341. data.parallels = new List<Vector>();
  342. data.isAccelerator = SaveController.Instance.isDemo;
  343. data.isInner = ConstConfig.isInnerGPS;
  344.  
  345. if (PlayerPrefs.GetInt("toggleCount" + typeText.text) != 0)
  346. {
  347. data.sections = PlayerPrefs.GetInt("toggleCount" + typeText.text);
  348. }
  349. else
  350. {
  351. data.sections = settings.toggleCount;
  352. PlayerPrefs.SetInt("toggleCount" + typeText.text, settings.toggleCount);
  353. }
  354. if (PlayerPrefs.GetInt("metrics" + typeText.text) != 0)
  355. {
  356. data.widthM = PlayerPrefs.GetInt("metrics" + typeText.text);
  357. }
  358. else
  359. {
  360. if (typeDropdown.value == 4)
  361. {
  362. data.widthM = 3;
  363. PlayerPrefs.SetInt("metrics" + typeText.text, data.widthM);
  364. }else if (typeDropdown.value == 8)
  365. {
  366. data.widthM = 40;
  367. PlayerPrefs.SetInt("metrics" + typeText.text, data.widthM);
  368. }
  369. else
  370. {
  371. data.widthM = settings.metrics;
  372. PlayerPrefs.SetInt("metrics" + typeText.text, data.widthM);
  373. }
  374. }
  375. if (PlayerPrefs.GetInt("sm" + typeText.text) != 0)
  376. {
  377. data.widthSM = PlayerPrefs.GetInt("sm" + typeText.text);
  378. }
  379. else
  380. {
  381. if (typeDropdown.value == 4)
  382. {
  383. data.widthSM =60;
  384. PlayerPrefs.SetInt("sm" + typeText.text, data.widthSM);
  385. }
  386. else
  387. {
  388. data.widthSM = settings.sm;
  389. PlayerPrefs.SetInt("sm" + typeText.text, data.widthSM);
  390. }
  391. }
  392. if (PlayerPrefs.GetInt("xOffset" + typeText.text) != 0)
  393. {
  394. data.xOffset = PlayerPrefs.GetInt("xOffset" + typeText.text);
  395. }
  396. else
  397. {
  398. data.xOffset = settings.xOffset;
  399. PlayerPrefs.SetInt("xOffset" + typeText.text, data.xOffset);
  400. }
  401. if (PlayerPrefs.GetInt("xSMOffset" + typeText.text) != 0)
  402. {
  403. data.xSMOffset = PlayerPrefs.GetInt("xSMOffset" + typeText.text);
  404. }
  405. else
  406. {
  407. data.xSMOffset = settings.xSMOffset;
  408. PlayerPrefs.SetInt("xSMOffset" + typeText.text, data.xSMOffset);
  409. }
  410. if (PlayerPrefs.GetInt("om" + typeText.text) != 0)
  411. {
  412. data.overlapM = PlayerPrefs.GetInt("om" + typeText.text);
  413. }
  414. else
  415. {
  416. data.overlapM = settings.om;
  417. PlayerPrefs.SetInt("om" + typeText.text, data.overlapM);
  418. }
  419.  
  420.  
  421. if (!string.IsNullOrEmpty(debugText.text))
  422. {
  423. data.debugFileName = debugText.text;
  424. }
  425. else
  426. {
  427. data.debugFileName = "-";
  428. }
  429.  
  430. if (PlayerPrefs.GetInt("zOffset" + typeText.text) != 0)
  431. {
  432. data.zOffset = PlayerPrefs.GetInt("zOffset" + typeText.text);
  433. }
  434. else
  435. {
  436. if (typeDropdown.value != 8 && typeDropdown.value != 5)
  437. {
  438. if (PlayerPrefs.GetInt("VelestorDevice") == 1)
  439. {
  440. data.zOffset = 4;
  441. PlayerPrefs.SetInt("zOffset" + typeText.text, 4);
  442. }
  443. else
  444. {
  445. data.zOffset = 1;
  446. PlayerPrefs.SetInt("zOffset" + typeText.text, 1);
  447. }
  448. }
  449. else
  450. {
  451. data.zOffset = settings.zOffset;
  452. PlayerPrefs.SetInt("zOffset" + typeText.text, data.zOffset);
  453. }
  454. }
  455. if (PlayerPrefs.GetInt("zSMOffset" + typeText.text) != 0)
  456. {
  457. data.zSMOffset = PlayerPrefs.GetInt("zSMOffset" + typeText.text);
  458. }
  459. else
  460. {
  461. data.zSMOffset = settings.zSMOffset;
  462. PlayerPrefs.SetInt("zSMOffset" + typeText.text, data.zSMOffset);
  463. }
  464.  
  465. data.isNewSave = true;
  466. data.isDeleted = "false";
  467. data.isSetCurves = "false";
  468. data.debugData = new DebugData();
  469. data.debugData.minSpeed = float.Parse(speedInputField.text);
  470. data.debugData.pointsDealey = float.Parse(pointsInputField.text);
  471. data.debugData.sectorDealey = int.Parse(sectorsInputField.text);
  472.  
  473. if (typeDropdown.value == 8)
  474. {
  475. data.overlapM = 99;
  476. PlayerPrefs.SetInt("om" + typeText.text, 99);
  477. data.zOffset = 4;
  478. PlayerPrefs.SetInt("zOffset" + typeText.text, 4);
  479. }
  480. if (typeDropdown.value == 7)
  481. {
  482. data.overlapM = 30;
  483. PlayerPrefs.SetInt("om" + typeText.text, 30);
  484. data.zOffset = 1;
  485. PlayerPrefs.SetInt("zOffset" + typeText.text, 1);
  486. data.widthM = 2;
  487. PlayerPrefs.SetInt("metrics" + typeText.text, 2);
  488. }
  489.  
  490. if (typeDropdown.value == 5)
  491. {
  492. data.overlapM = 99;
  493. PlayerPrefs.SetInt("om" + typeText.text, 30);
  494. data.zOffset = 1;
  495. PlayerPrefs.SetInt("zOffset" + typeText.text, 1);
  496. if (data.widthM < 4)
  497. {
  498. data.widthM = 4;
  499. PlayerPrefs.SetInt("metrics" + typeText.text, 4);
  500. }
  501. if (data.widthM > 11)
  502. {
  503. data.widthM = 11;
  504. PlayerPrefs.SetInt("metrics" + typeText.text, 11);
  505. }
  506. data.widthSM = 0;
  507. PlayerPrefs.SetInt("sm" + typeText.text, 0);
  508. }
  509.  
  510. if (string.IsNullOrEmpty(data.saveIndex))
  511. {
  512. int i = PlayerPrefs.GetInt("saves");
  513. data.saveIndex = i.ToString();
  514. i++;
  515. PlayerPrefs.SetInt("saves", i);
  516.  
  517. }
  518.  
  519. SaveController.Instance.LoadData(data);
  520. #if !UNITY_WSA_10_0 || UNITY_EDITOR
  521. //
  522. _async.allowSceneActivation = true;
  523. #else
  524. SceneManager.LoadScene("Main");
  525. #endif
  526. }
  527. else
  528. {
  529. if (PlayerPrefs.GetInt("VelestorDevice") == 1)
  530. {
  531. SaveController.Instance.data.sections = settings.toggleCount;
  532. SaveController.Instance.data.widthM = settings.metrics;
  533. SaveController.Instance.data.widthSM = settings.sm;
  534. SaveController.Instance.data.xOffset = settings.xOffset;
  535. SaveController.Instance.data.xSMOffset = settings.xSMOffset;
  536. SaveController.Instance.data.overlapM = settings.om;
  537. SaveController.Instance.data.zOffset = settings.zOffset;
  538. SaveController.Instance.data.zSMOffset = settings.zSMOffset;
  539.  
  540. if (SaveController.Instance.data.overlapM < 1)
  541. {
  542. SaveController.Instance.data.overlapM = 30;
  543. }
  544.  
  545. if (SaveController.Instance.data.widthM == 0)
  546. {
  547. SaveController.Instance.data.widthM = 8;
  548. }
  549. if (SaveController.Instance.data.sections == 0)
  550. {
  551. SaveController.Instance.data.sections = 1;
  552. }
  553. if(PlayerPrefs.GetInt("Demo"+SaveController.Instance.data.saveIndex,0) == 1)
  554. {
  555. SaveController.Instance.data.isAccelerator = true;
  556. }
  557.  
  558. SaveController.Instance.PrepareToStart();
  559. //SceneManager.LoadScene("Main");
  560. #if !UNITY_WSA_10_0 || UNITY_EDITOR
  561. //
  562. _async.allowSceneActivation = true;
  563. #else
  564. SceneManager.LoadScene("Main");
  565. #endif
  566. }
  567. else
  568. {
  569. StartCoroutine(MainMenuSettings.Instance.OpenCantOpenWindow());
  570. }
  571. }
  572.  
  573. }
  574.  
  575. public void StartSendInnerDevice()
  576. {
  577. StartCoroutine(SendInnerDevice(ActivateWindow.GenerateSerial(), "", "", ""));
  578. }
  579.  
  580. public IEnumerator SendInnerDevice(string serial, string name, string pin, string mac)
  581. {
  582.  
  583. string imei = SystemInfo.deviceUniqueIdentifier;
  584. string deviceModel = SystemInfo.deviceModel;
  585. PlayerPrefs.SetString("serial", ActivateWindow.GenerateSerial());
  586.  
  587. #if !UNITY_EDITOR && UNITY_ANDROID
  588. AndroidJNI.AttachCurrentThread();
  589. using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  590. {
  591. using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  592. {
  593. gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
  594. }
  595. }
  596. string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
  597. string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  598. imei = phoneNumber[1];
  599. deviceModel = SystemInfo.deviceModel;
  600. #endif
  601. string url = "velestor." + ActivateWindow.URL_PREFIX + "/insertInnerDevice.php?serial=" + serial + "&name=" + deviceModel + "&pin=0000&mac=" + imei;
  602. url = url.Replace("\r\n", "%0A");
  603. url = url.Replace(" ", "%20");
  604. url = url.Replace(" ", "%20");
  605. url = url.Replace("#", "%23");
  606. url = url.Replace(":", "%3A");
  607. WWW www = new WWW("http://" + url);
  608. yield return www;
  609. ParseInnerGPS(www.text, www.url,www.error);
  610. if (!string.IsNullOrEmpty(www.error))
  611. {
  612. PromptDemoWindow.Instance.ShowInteretError();
  613. }
  614. else
  615. {
  616. if (string.IsNullOrEmpty(www.error) && www.text.StartsWith("OK"))
  617. {
  618. SaveController.Instance.isInnerGPS = true;
  619. ConstConfig.isInnerGPS = true;
  620. PromptDemoWindow.Instance.activateWindow.SetDemo();
  621. PlayerPrefs.SetInt("Active", 1);
  622. ConstConfig.isInnerGPS = true;
  623. PlayerPrefs.SetInt("Inner", 1);
  624. string[] s = www.text.Split(new char[] { '|' });
  625. PlayerPrefs.SetString("deviceId", s[1]);
  626. PlayerPrefs.SetInt("Active", 1);
  627. PlayerPrefs.SetString("mac", mac);
  628. PlayerPrefs.SetString("pin", pin);
  629. PlayerPrefs.SetString("device", name);
  630. PlayerPrefs.SetString("serial", s[1]);
  631. PlayerPrefs.SetString("key", pin);
  632. shortSerialText.text = "S/N: " + s[1];
  633. longSerialText.text = "S/N: " + s[1] + " PIN: 0000";
  634.  
  635. //Invoke(StartGetDetails(),1);
  636. PlayerPrefs.SetFloat("startDevicedSquare", 1);
  637. PlayerPrefs.SetInt("startDevicedSquareCount", 1);
  638. PlayerPrefs.SetFloat("startDevicedSpeed", 1);
  639. CheckDevice();
  640. MainMenuController.Instance.ChangeTexts();
  641.  
  642. //serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
  643. UnityEngine.Debug.Log(PlayerPrefs.GetString("serial"));
  644. //yield return StartCoroutine(GetDetailsMore());
  645. PromptDemoWindow.Instance.gameObject.SetActive(false);
  646. DownloadController.Instance.StartSendAnalitic(s[1], "123", "test", "test", "test", "OK");
  647. CheckForBan.Instance.OnSuccessLogin();
  648. CheckOriginalDevice();
  649.  
  650. }
  651.  
  652. }
  653. }
  654. private void CheckDevice()
  655. {
  656. if (PlayerPrefs.GetString("serial").Length > 8)
  657. {
  658. PlayerPrefs.SetInt("VelestorDevice", 0);
  659. PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("OriginalDemo"));
  660. MainMenuController.Instance.ChangeTexts();
  661. StartCoroutine(GetDetails());
  662. }
  663. else
  664. {
  665. PlayerPrefs.SetInt("VelestorDevice", 1);
  666. StartCoroutine(GetDetails());
  667. }
  668.  
  669. MainMenuController.Instance.CheckOriginalDevice();
  670.  
  671. }
  672. private string url = "http://velestor." + ActivateWindow.URL_PREFIX + "/";
  673. IEnumerator GetDetails()
  674. {
  675. WWW www = new WWW(url + "loxovnet.php?serial=" + PlayerPrefs.GetString("serial"));
  676. yield return www;
  677. ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
  678. if (!string.IsNullOrEmpty(model.error))
  679. {
  680.  
  681. }
  682. else
  683. {
  684. if (model.active == 0)
  685. {
  686. CheckModel(model);
  687. }
  688. else
  689. {
  690. CheckModel(model);
  691. PlayerPrefs.SetInt("Active", 1);
  692. PlayerPrefs.SetString("mac", model.mac);
  693. PlayerPrefs.SetString("pin", model.pin);
  694. PlayerPrefs.SetString("device", model.name);
  695. PlayerPrefs.SetString("deviceSpeed", model.deviceSpeed);
  696. PlayerPrefs.SetString("key", model.key);
  697.  
  698. PlayerPrefs.SetFloat("startDevicedSquare", model.squareDelta);
  699. PlayerPrefs.SetInt("startDevicedSquareCount", model.squareCount);
  700. PlayerPrefs.SetFloat("startDevicedSpeed", model.minSpeed);
  701. if(PlayerPrefs.GetInt("VelestorDevice") == 1)
  702. PlayerPrefs.SetString("delader", model.dealer);
  703. MainMenuController.Instance.ChangeTexts();
  704. PlayerPrefs.SetString("info", model.text);
  705. PlayerPrefs.SetString("activationDate", model.date);
  706.  
  707. PlayerPrefs.SetInt("control", model.control);
  708. PlayerPrefs.SetString("dealerContact", model.contact);
  709. PlayerPrefs.SetString("dealerEmail", model.email);
  710. PlayerPrefs.SetString("dealerAddress", model.address);
  711. PlayerPrefs.SetString("dealerTel", model.tel);
  712. CheckModel(model);
  713.  
  714. #if UNITY_ANDROID || UNITY_WSA_10_0
  715. string[] parts = model.mac.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  716. if (parts.Length < 6)
  717. {
  718. PlayerPrefs.SetInt("Inner", 1);
  719. SaveController.Instance.isInnerGPS = true;
  720. ConstConfig.isInnerGPS = true;
  721. }
  722. #endif
  723.  
  724. CheckForBan.Instance.OnSuccessLogin();
  725. }
  726. }
  727. }
  728.  
  729. private void CheckModel(ActivationModel model)
  730. {
  731. if(model != null)
  732. {
  733. UnityEngine.Debug.Log("Checked");
  734. }
  735. }
  736.  
  737. private void ParseInnerGPS(string text, string url,string error = null)
  738. {
  739. UnityEngine.Debug.Log(text + " " + url);
  740. }
  741.  
  742. public void StartGetLicense()
  743. {
  744. StartCoroutine(GetLicense());
  745. }
  746.  
  747. public IEnumerator GetLicense()
  748. {
  749. string url = "velestor." + ActivateWindow.URL_PREFIX + "/getLicense.php";
  750.  
  751. WWW www = new WWW("http://" + url);
  752. yield return www;
  753. if (string.IsNullOrEmpty(www.error))
  754. {
  755. ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
  756. PlayerPrefs.SetString("info", model.text);
  757. UnityEngine.Debug.Log("License: " + model.text);
  758. }
  759. yield return null;
  760. }
  761.  
  762. public void OnExitClicked()
  763. {
  764. if(ConstConfig.isDemo)
  765. {
  766. PlayerPrefs.DeleteAll();
  767. }
  768.  
  769. #if UNITY_ANDROID && !UNITY_EDITOR
  770. if(gpsActivityJavaClass.CallStatic<bool>("isMyLauncherDefault"))
  771. {
  772. if(PlayerPrefs.GetInt("VelestorDevice") == 0)
  773. {
  774. gpsActivityJavaClass.CallStatic<string>("CloseApp");
  775. }else
  776. {
  777. gpsActivityJavaClass.CallStatic<string>("LockScreen");
  778. }
  779. }else
  780. {
  781. Application.Quit();
  782. }
  783. #elif UNITY_WSA_10_0 && !UNITY_EDITOR || UNITY_STANDALONE_WIN
  784. Application.Quit();
  785.  
  786. #elif UNITY_STANDALONE_LINUX
  787. WinBluetoothController.Instance.SendShutdown();
  788. #endif
  789.  
  790. #if UNITY_STANDALONE
  791. foreach (var process in Process.GetProcessesByName("VelestorBT"))
  792. {
  793. process.Kill();
  794. }
  795. #endif
  796. }
  797.  
  798.  
  799. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement