Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7. using System.Text.RegularExpressions;
  8. using System.Data.SqlClient;
  9. using TMPro;
  10. using System;
  11. using System.IO;
  12. using System.Text;
  13. using ZXing;
  14. using ZXing.QrCode;
  15. using System.Net;
  16. using SimpleJSON;
  17. using System.ComponentModel;
  18. using System.Runtime.InteropServices;
  19. using ExifLib;
  20. using static NativeCamera;
  21. using System.Linq;
  22. public class 錄音測試 : MonoBehaviour
  23. {
  24. [SerializeField] RawImage 拍照用;
  25. [SerializeField] TextMeshProUGUI 失敗1;
  26. [SerializeField] TextMeshProUGUI 失敗;
  27. // Start is called before the first frame update
  28. //[SerializeField] GameObject 照片欄, 照片欄1, 照片欄2, 照片欄3, 照片欄4,文字欄;
  29. //[SerializeField] RawImage 縮圖, 縮圖1, 縮圖2, 縮圖3, 縮圖4;
  30. //private Texture2D 上傳圖, 上傳圖1, 上傳圖2, 上傳圖3, 上傳圖4;
  31. //[SerializeField] GameObject 照片欄刪除, 照片欄刪除1, 照片欄刪除2, 照片欄刪除3, 照片欄刪除4;
  32. //[SerializeField] GameObject 照片欄新增, 照片欄新增1, 照片欄新增2, 照片欄新增3, 照片欄新增4;
  33. [SerializeField] GameObject 拍頁;
  34. [SerializeField] GameObject 主頁;
  35. [SerializeField] GameObject 返回紐;
  36. [SerializeField] GameObject 文字欄;
  37. [SerializeField] GameObject[] 照片欄Array;
  38. Texture2D[] 上傳圖Array = new Texture2D[5];
  39. [SerializeField] RawImage[] 縮圖Array;
  40. [SerializeField] GameObject[] 照片欄刪除Array;
  41. [SerializeField] GameObject[] 照片欄新增Array;
  42. private int 照片欄數量 = 0;
  43. private WebCamTexture myCam;
  44. [SerializeField] GameObject 錄音頁;
  45. [SerializeField] GameObject 錄音頁叉叉;
  46. [SerializeField] GameObject 錄音顯示;
  47. [SerializeField] GameObject 錄音紐;
  48. [SerializeField] Button 錄音開始;
  49. [SerializeField] Button 錄音結束;
  50. [SerializeField] GameObject 相片選擇頁;
  51. private string 地址1, 地址2,錄音流水,控制表單號;
  52. string[] 圖片流水 = new string[5];
  53. [SerializeField] TMP_InputField 貼文內容;
  54. public CanvasScaler canvasScaler;
  55. private AudioClip recordedClip;
  56. public AudioSource audioSource;
  57. [SerializeField] TextMeshProUGUI 顯示;
  58. [SerializeField] TextMeshProUGUI 顯示1;
  59. [SerializeField] TextMeshProUGUI 顯示2;
  60. public Slider progressBar;
  61. [SerializeField] TextMeshProUGUI timeText;
  62. public Button playPauseButton;
  63. public Sprite playSprite;
  64. public Sprite pauseSprite;
  65. private float currentTime;
  66. private bool isPlaying;
  67. private bool isDraggingProgress = false;
  68. private float recordingTime = 0f;
  69. private bool isRecording = false;
  70. private float maxRecordingTime = 180f;
  71. public RawImage imageDisplay;
  72. private Texture2D 存圖1;
  73. public RawImage 圖1;
  74. [SerializeField] TMP_InputField 緯度;
  75. [SerializeField] TMP_InputField 經度;
  76. private int totalPages;
  77. [SerializeField] Button 彈跳是;
  78. [SerializeField] Button 彈跳否;
  79. [SerializeField] Button 彈跳叉;
  80. [SerializeField] GameObject 彈跳面板;
  81. [SerializeField] TextMeshProUGUI 彈跳文字;
  82. [SerializeField] GameObject 讀取面板;
  83. [SerializeField] TextMeshProUGUI 讀取;
  84. private string loadingText = "";
  85. private int dotCount = 0;
  86. private string 圖片資料庫名稱 = "";
  87. private string 錄音資料庫名稱 = "";
  88. bool pic = false;
  89. void Start()
  90. {
  91. Screen.autorotateToPortrait = false;
  92. Screen.orientation = ScreenOrientation.Portrait;
  93. if (Screen.orientation == ScreenOrientation.LandscapeLeft)
  94. {
  95. float rate = 900.0f / 1900.0f;
  96. if (Main.Global.rate<rate)
  97. {
  98. canvasScaler.matchWidthOrHeight = 1f;
  99. }
  100. else
  101. {
  102. canvasScaler.matchWidthOrHeight = 0f;
  103. }
  104. }
  105. if (Screen.orientation == ScreenOrientation.Portrait)
  106. {
  107. float rate = 900.0f / 1900.0f;
  108. if (Main.Global.rate>rate)
  109. {
  110. canvasScaler.matchWidthOrHeight = 1f;
  111. }
  112. else
  113. {
  114. canvasScaler.matchWidthOrHeight = 0f;
  115. }
  116. }
  117. //SQL_CommString.SQL_連線字串_正式_SQL();
  118. //SQL_CommString.SQL_連線字串_圖片_SQL();
  119. //SQL_CommString.SQL_連線字串_錄音_SQL();
  120. StartCoroutine(AnimateText());
  121. audioSource.Stop();
  122. 主頁.SetActive(true);
  123. 拍頁.SetActive(false);
  124. 返回紐.SetActive(true);
  125. 錄音顯示.SetActive(false);
  126. //錄音紐.SetActive(true);
  127. 照片欄Array[0].SetActive(true);
  128. 照片欄刪除Array[0].SetActive(false);
  129. 照片欄新增Array[0].SetActive(true);
  130. 文字欄.SetActive(false);
  131. for (int i = 1; i < 照片欄Array.Length; i++)
  132. {
  133. 照片欄Array[i].SetActive(false);
  134. 照片欄刪除Array[i].SetActive(false);
  135. 照片欄新增Array[i].SetActive(true);
  136. }
  137. 資料庫選擇();
  138. }
  139. private void 資料庫選擇()
  140. {
  141. SQL_game_sys.SQL_讀取資料庫名稱("音");
  142. if (SQL_Module.dr.Read())
  143. {
  144. 錄音資料庫名稱 =SQL_Module.dr["資料庫名稱"].ToString();
  145. SQL_game_sys.SQL_讀取資料庫名稱("圖");
  146. if (SQL_Module.dr.Read())
  147. {
  148. 圖片資料庫名稱 =SQL_Module.dr["資料庫名稱"].ToString();
  149. Debug.Log(錄音資料庫名稱);
  150. Debug.Log(圖片資料庫名稱);
  151. }
  152. else
  153. {
  154. 彈跳面板開啟("圖片資料庫已滿,請找系統管理員!!", false, false, true, () => { }, () => { }, back1);
  155. }
  156. }
  157. else
  158. {
  159. 彈跳面板開啟("錄音資料庫已滿,請找系統管理員!!", false, false, true, () => { }, () => { }, back1);
  160. }
  161. }
  162. IEnumerator AnimateText()
  163. {
  164. string qqq = 讀取.text.ToString();
  165. while (true)
  166. {
  167. yield return new WaitForSeconds(0.5f);
  168. if (dotCount < 3)
  169. {
  170. loadingText += ".";
  171. dotCount++;
  172. }
  173. else
  174. {
  175. loadingText = "";
  176. dotCount = 0;
  177. }
  178. 讀取.text = qqq+loadingText;
  179. }
  180. }
  181. public void 照片選擇()
  182. {
  183. 主頁.SetActive(false);
  184. 相片選擇頁.SetActive(true);
  185. 返回紐.SetActive(false);
  186. }
  187. public void 照片欄位新增()
  188. {
  189. if (照片欄數量 < 照片欄Array.Length)
  190. {
  191. 照片欄數量++;
  192. 照片欄新增Array[照片欄數量 - 1].SetActive(false);
  193. 照片欄刪除Array[照片欄數量 - 1].SetActive(true);
  194. if (照片欄數量 == 照片欄Array.Length)
  195. {
  196. 文字欄.SetActive(true);
  197. }
  198. else
  199. {
  200. 照片欄Array[照片欄數量].SetActive(true);
  201. }
  202. 選擇照片();
  203. 相片選擇頁.SetActive(false);
  204. }
  205. }
  206. public void 欄位刪除(int index)
  207. {
  208. if (照片欄數量==5)
  209. {
  210. 文字欄.SetActive(false);
  211. }
  212. else
  213. {
  214. 照片欄Array[照片欄數量].SetActive(false);
  215. }
  216. for (int i = index; i < 照片欄數量 - 1; i++)
  217. {
  218. 縮圖Array[i].texture = 縮圖Array[i + 1].texture;
  219. 上傳圖Array[i] = 上傳圖Array[i + 1];
  220. }
  221. 照片欄刪除Array[照片欄數量-1].SetActive(false);
  222. 照片欄新增Array[照片欄數量-1].SetActive(true);
  223. 上傳圖Array[照片欄數量-1]=null;
  224. 縮圖Array[照片欄數量-1].texture=null;
  225. 照片欄數量--;
  226. }
  227. public void 選擇照片()
  228. {
  229. // 調用Native插件的選擇照片函數
  230. NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
  231. {
  232. if (path != null)
  233. {
  234. // 加載並顯示選擇的照片
  235. StartCoroutine(LoadImage(path));
  236. 主頁.SetActive(true);
  237. }
  238. else
  239. {
  240. 照片欄新增Array[照片欄數量 - 1].SetActive(true);
  241. 照片欄刪除Array[照片欄數量 - 1].SetActive(false);
  242. 照片欄Array[照片欄數量].SetActive(false);
  243. 照片欄數量--;
  244. 主頁.SetActive(true);
  245. }
  246. });
  247. // 檢查權限
  248. if (permission == NativeGallery.Permission.Granted)
  249. {
  250. // 權限已經被授予
  251. Debug.Log("Gallery permission granted");
  252. }
  253. else if (permission == NativeGallery.Permission.ShouldAsk)
  254. {
  255. // 權限尚未被授予,需要詢問用戶
  256. Debug.Log("Gallery permission should ask");
  257. }
  258. else
  259. {
  260. // 權限被拒絕
  261. Debug.Log("Gallery permission denied");
  262. }
  263. IEnumerator LoadImage(string path)
  264. {
  265. UnityWebRequest www = UnityWebRequestTexture.GetTexture("file://" + path);
  266. yield return www.SendWebRequest();
  267. if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
  268. {
  269. Debug.LogError("Failed to load image: " + www.error);
  270. }
  271. else
  272. {
  273. Texture2D texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
  274. Texture2D texture1 = ((DownloadHandlerTexture)www.downloadHandler).texture;
  275. byte[] imageBytes = File.ReadAllBytes(path);
  276. try
  277. {
  278. ExifLib.JpegInfo jpi = ExifLib.ExifReader.ReadJpeg(imageBytes, "Foo");
  279. //Debug.Log("Orientation: " + jpi.Orientation.ToString());
  280. //Debug.Log(jpi.Width);
  281. //Debug.Log(jpi.Height);
  282. if (jpi.Width >jpi.Height)
  283. {
  284. texture =ResizeTexture(texture, 1920, 1080);
  285. }
  286. else
  287. {
  288. texture =ResizeTexture(texture, 1080, 1920);
  289. }
  290. texture1=ResizeTexture(texture1, 196, 196);
  291. texture =AdjustTextureOrientation(texture, jpi.Orientation);
  292. texture1 =AdjustTextureOrientation(texture1, jpi.Orientation);
  293. }
  294. catch (Exception ex)
  295. {
  296. Debug.LogError("Error reading Exif data: " + ex.Message);
  297. }
  298. 上傳圖Array[照片欄數量 - 1] = texture;
  299. 縮圖Array[照片欄數量 - 1].texture = texture1;
  300. }
  301. }
  302. Texture2D ResizeTexture(Texture2D originalTexture, int newWidth, int newHeight)
  303. {
  304. Texture2D resizedTexture = new Texture2D(newWidth, newHeight, originalTexture.format, true);
  305. Color[] pixels = new Color[newWidth * newHeight];
  306. float incX = ((float)1 / originalTexture.width) * ((float)originalTexture.width / newWidth);
  307. float incY = ((float)1 / originalTexture.height) * ((float)originalTexture.height / newHeight);
  308. for (int x = 0; x < newWidth; x++)
  309. {
  310. for (int y = 0; y < newHeight; y++)
  311. {
  312. pixels[y * newWidth + x] = originalTexture.GetPixelBilinear(incX * x, incY * y);
  313. }
  314. }
  315. resizedTexture.SetPixels(pixels);
  316. resizedTexture.Apply();
  317. return resizedTexture;
  318. }
  319. Texture2D AdjustTextureOrientation(Texture2D originalTexture, ExifOrientation orientation)
  320. {
  321. Texture2D adjustedTexture = new Texture2D(originalTexture.width, originalTexture.height);
  322. switch (orientation)
  323. {
  324. case ExifOrientation.TopLeft:
  325. // 图片方向为正常方向,无需调整
  326. adjustedTexture = originalTexture;
  327. break;
  328. case ExifOrientation.TopRight:
  329. // 逆时针旋转图片90度
  330. adjustedTexture = RotateTexture(originalTexture, -90f);
  331. break;
  332. case ExifOrientation.BottomRight:
  333. // 旋转180度
  334. adjustedTexture = RotateTexture(originalTexture, 180f);
  335. break;
  336. case ExifOrientation.BottomLeft:
  337. adjustedTexture = RotateTexture(originalTexture, 90f);
  338. break;
  339. default:
  340. // 默认情况下,返回原始图片
  341. adjustedTexture = originalTexture;
  342. break;
  343. }
  344. return adjustedTexture;
  345. }
  346. Texture2D RotateTexture(Texture2D originalTexture, float angle)
  347. {
  348. // Calculate the dimensions of the rotated texture
  349. int width = originalTexture.width;
  350. int height = originalTexture.height;
  351. float rotatedWidth = Mathf.Abs(width * Mathf.Cos(angle * Mathf.Deg2Rad)) + Mathf.Abs(height * Mathf.Sin(angle * Mathf.Deg2Rad));
  352. float rotatedHeight = Mathf.Abs(width * Mathf.Sin(angle * Mathf.Deg2Rad)) + Mathf.Abs(height * Mathf.Cos(angle * Mathf.Deg2Rad));
  353. // Create a new texture to store rotated pixels
  354. Texture2D rotatedTexture = new Texture2D(Mathf.RoundToInt(rotatedWidth), Mathf.RoundToInt(rotatedHeight));
  355. // Get the pixel data of the original texture
  356. Color32[] pixels = originalTexture.GetPixels32();
  357. Color32[] rotatedPixels = new Color32[Mathf.RoundToInt(rotatedWidth) * Mathf.RoundToInt(rotatedHeight)];
  358. // Calculate the center of the original texture
  359. float centerX = width / 2f;
  360. float centerY = height / 2f;
  361. // Iterate over each pixel in the rotated texture
  362. for (int x = 0; x < rotatedTexture.width; x++)
  363. {
  364. for (int y = 0; y < rotatedTexture.height; y++)
  365. {
  366. // Calculate the coordinates of the pixel in the original texture
  367. float originalX = Mathf.Cos(-angle * Mathf.Deg2Rad) * (x - rotatedWidth / 2) - Mathf.Sin(-angle * Mathf.Deg2Rad) * (y - rotatedHeight / 2) + centerX;
  368. float originalY = Mathf.Sin(-angle * Mathf.Deg2Rad) * (x - rotatedWidth / 2) + Mathf.Cos(-angle * Mathf.Deg2Rad) * (y - rotatedHeight / 2) + centerY;
  369. // Get the pixel color from the original texture and assign it to the rotated texture
  370. if (originalX >= 0 && originalX < width && originalY >= 0 && originalY < height)
  371. {
  372. int index = Mathf.RoundToInt(originalY) * width + Mathf.RoundToInt(originalX);
  373. rotatedPixels[y * rotatedTexture.width + x] = pixels[index];
  374. }
  375. else
  376. {
  377. // If the coordinates are outside the bounds of the original texture, set the pixel color to transparent
  378. rotatedPixels[y * rotatedTexture.width + x] = new Color32(0, 0, 0, 0);
  379. }
  380. }
  381. }
  382. // Set the rotated pixels to the rotated texture and apply changes
  383. rotatedTexture.SetPixels32(rotatedPixels);
  384. rotatedTexture.Apply();
  385. return rotatedTexture;
  386. }
  387. }
  388. public void 新增錄音()
  389. {
  390. 錄音頁.SetActive(true);
  391. 錄音頁叉叉.SetActive(true);
  392. 主頁.SetActive(false);
  393. 返回紐.SetActive(false);
  394. 錄音開始.interactable = true;
  395. 錄音結束.interactable = false;
  396. 顯示.text="錄音最大時長為3分鐘,按下start後開始錄音";
  397. 顯示1.text="";
  398. timeText.text="0:00 / 0:00";
  399. }
  400. public void 關閉錄音頁()
  401. {
  402. 錄音頁.SetActive(false);
  403. }
  404. public void 刪除錄音()
  405. {
  406. if (recordedClip != null)
  407. {
  408. // 清除錄音的緩衝區
  409. recordedClip = null;
  410. }
  411. 顯示.text="";
  412. 顯示1.text="";
  413. timeText.text="0:00 / 0:00";
  414. 錄音顯示.SetActive(false);
  415. 錄音紐.SetActive(true);
  416. }
  417. public void StartRecording()
  418. {
  419. 錄音頁叉叉.SetActive(false);
  420. 錄音開始.interactable = false;
  421. 錄音結束.interactable = true;
  422. // 開始錄音
  423. if (recordedClip != null)
  424. {
  425. // 清除錄音的緩衝區
  426. recordedClip = null;
  427. }
  428. isRecording = true;
  429. recordingTime = 0f;
  430. recordedClip = Microphone.Start(null, false, 181, 44100);
  431. audioSource.clip=null;
  432. 顯示.text="錄音中...";
  433. }
  434. public void StopRecording()
  435. {
  436. // 停止錄音
  437. Microphone.End(null);
  438. isRecording = false;
  439. recordedClip=TrimSilenceFromAudioClip(recordedClip);
  440. audioSource.clip=recordedClip;
  441. UpdateProgressBar();
  442. UpdateTimeText();
  443. 錄音頁.SetActive(false);
  444. 錄音顯示.SetActive(true);
  445. 錄音紐.SetActive(false);
  446. 主頁.SetActive(true);
  447. 返回紐.SetActive(true);
  448. }
  449. AudioClip TrimSilenceFromAudioClip(AudioClip clip)
  450. {
  451. // 獲取錄音副本的音頻數據
  452. float[] data = new float[clip.samples * clip.channels];
  453. clip.GetData(data, 0);
  454. // 計算錄音的持續時間(以秒為單位)
  455. float clipDuration = clip.length;
  456. // 計算有聲的部分的持續時間(以秒為單位)
  457. float soundDuration = recordingTime+1;
  458. // 計算有聲部分的開始和結束索引
  459. int startSample = 0;
  460. int endSample = Mathf.FloorToInt((soundDuration / clipDuration) * clip.samples);
  461. // 創建新的音頻數據副本,僅包含有聲的部分
  462. int newSamples = endSample - startSample;
  463. float[] newData = new float[newSamples];
  464. Array.Copy(data, startSample, newData, 0, newSamples);
  465. AudioClip trimmedClip = AudioClip.Create("TrimmedAudio", newSamples, clip.channels, clip.frequency, false);
  466. trimmedClip.SetData(newData, 0);
  467. return trimmedClip;
  468. }
  469. public void TogglePlayPause()
  470. {
  471. // 切換播放/暫停
  472. if (isPlaying)
  473. {
  474. audioSource.Pause();
  475. playPauseButton.image.sprite = playSprite;
  476. isPlaying = false;
  477. }
  478. else
  479. {
  480. audioSource.Play();
  481. playPauseButton.image.sprite = pauseSprite;
  482. isPlaying = true;
  483. }
  484. }
  485. void Update()
  486. {
  487. if (isPlaying)
  488. {
  489. UpdateProgressBar();
  490. UpdateTimeText();
  491. // 如果音頻播放完畢,則停止播放並將播放標誌設置為false
  492. if (!audioSource.isPlaying)
  493. {
  494. playPauseButton.image.sprite = playSprite;
  495. isPlaying = false;
  496. audioSource.time = 0;
  497. progressBar.value = 0;
  498. UpdateTimeText();
  499. }
  500. }
  501. else
  502. {
  503. if(audioSource.clip != null)
  504. {
  505. UpdateProgressBar();
  506. UpdateTimeText();
  507. }
  508. }
  509. if (isRecording)
  510. {
  511. recordingTime += Time.deltaTime;
  512. UpdateRecordingTimeText();
  513. if (recordingTime >= maxRecordingTime)
  514. {
  515. StopRecording();
  516. }
  517. }
  518. }
  519. void UpdateRecordingTimeText()
  520. {
  521. 顯示1.text = FormatTime(recordingTime);
  522. }
  523. void UpdateProgressBar()
  524. {
  525. // 更新進度條的值
  526. if (recordedClip != null && audioSource.time != recordedClip.length)
  527. {
  528. progressBar.value = audioSource.time / recordedClip.length;
  529. UpdateTimeText();
  530. }
  531. }
  532. void UpdateTimeText()
  533. {
  534. // 更新時間文字顯示
  535. if (recordedClip != null)
  536. {
  537. currentTime = audioSource.time;
  538. timeText.text = FormatTime(currentTime) + " / " + FormatTime(recordedClip.length);
  539. }
  540. }
  541. string FormatTime(float time)
  542. {
  543. // 格式化時間
  544. int minutes = Mathf.FloorToInt(time / 60);
  545. int seconds = Mathf.FloorToInt(time % 60);
  546. return string.Format("{0:00}:{1:00}", minutes, seconds);
  547. }
  548. public void OnProgressBarValueChanged()
  549. {
  550. // 當 Bar 條的值發生變化時(用戶拖動),更新播放器的播放位置
  551. float newTime = progressBar.value * recordedClip.length;
  552. if (newTime < 0)
  553. {
  554. newTime = 0;
  555. }
  556. else if (newTime > recordedClip.length)
  557. {
  558. newTime = recordedClip.length;
  559. }
  560. audioSource.time = newTime;
  561. }
  562. public void OnPointerDownProgressBar()
  563. {
  564. // 當用戶按下 Bar 條時,設置拖動標誌為true
  565. isDraggingProgress = true;
  566. }
  567. public void OnPointerUpProgressBar()
  568. {
  569. // 當用戶放開 Bar 條時,設置拖動標誌為false
  570. isDraggingProgress = false;
  571. }
  572. //public void 上傳()
  573. //{
  574. // string connectionString = "Data Source=106.1.48.106,4567;Initial Catalog=OW-ERP-SYS;User ID=B70340;Password=Lee0911274990";
  575. // Debug.Log(connectionString);
  576. // using (SqlConnection connection = new SqlConnection(connectionString))
  577. // {
  578. // try
  579. // {
  580. // connection.Open();
  581. // byte[] wavData = WavUtility.FromAudioClip(recordedClip);
  582. // string query = "INSERT INTO 測試錄音檔 (名稱, 音檔) VALUES (@流水號, @binary_file)";
  583. // using (SqlCommand command = new SqlCommand(query, connection))
  584. // {
  585. // 添加流水號參數
  586. // command.Parameters.AddWithValue("@流水號", "測試");
  587. // 添加二進制圖片數據參數
  588. // command.Parameters.AddWithValue("@binary_file", wavData);
  589. // int rowsAffected = command.ExecuteNonQuery();
  590. // Debug.Log("成功插入 " + rowsAffected + " 行數據");
  591. // }
  592. // }
  593. // catch (Exception ex)
  594. // {
  595. // Debug.LogError("Error connecting to the database: " + ex.Message);
  596. // }
  597. // finally
  598. // {
  599. // connection.Close();
  600. // }
  601. // }
  602. //}
  603. //public void 讀取圖片()
  604. //{
  605. // string connectionString = "Data Source=106.1.48.106,4567;Initial Catalog=OW-ERP-SYS;User ID=B70340;Password=Lee0911274990";
  606. // using (SqlConnection connection = new SqlConnection(connectionString))
  607. // {
  608. // try
  609. // {
  610. // connection.Open();
  611. // string query = "SELECT 音檔 FROM 測試錄音檔 WHERE 名稱 LIKE '測試'";
  612. // using (SqlCommand command = new SqlCommand(query, connection))
  613. // {
  614. // using (SqlDataReader reader = command.ExecuteReader())
  615. // {
  616. // if (reader.Read())
  617. // {
  618. // 讀取圖片的二進位資料
  619. // byte[] imageData = (byte[])reader["音檔"];
  620. // recordedClip=LoadAudioClip(imageData);
  621. // audioSource.clip = LoadAudioClip(imageData);
  622. // UpdateProgressBar();
  623. // UpdateTimeText();
  624. // }
  625. // }
  626. // }
  627. // }
  628. // catch (Exception ex)
  629. // {
  630. // Debug.LogError("Error connecting to the database: " + ex.Message);
  631. // }
  632. // finally
  633. // {
  634. // connection.Close();
  635. // }
  636. // }
  637. //}
  638. //private AudioClip LoadAudioClip(byte[] audioData)
  639. //{
  640. // 將音頻資料轉換為 AudioClip
  641. // return WavUtility.ToAudioClip(audioData);
  642. //}
  643. //public void 上傳1()
  644. //{
  645. // string connectionString = "Data Source=106.1.48.106,4567;Initial Catalog=OW-ERP-SYS;User ID=B70340;Password=Lee0911274990";
  646. // Debug.Log(connectionString);
  647. // using (SqlConnection connection = new SqlConnection(connectionString))
  648. // {
  649. // try
  650. // {
  651. // connection.Open();
  652. // byte[] imageBytes = 存圖1.EncodeToJPG();
  653. // string query = "INSERT INTO 測試錄音檔 (名稱, 音檔) VALUES (@流水號, @binary_file)";
  654. // using (SqlCommand command = new SqlCommand(query, connection))
  655. // {
  656. // 添加流水號參數
  657. // command.Parameters.AddWithValue("@流水號", "測試");
  658. // 添加二進制圖片數據參數
  659. // command.Parameters.AddWithValue("@binary_file", imageBytes);
  660. // int rowsAffected = command.ExecuteNonQuery();
  661. // Debug.Log("成功插入 " + rowsAffected + " 行數據");
  662. // }
  663. // }
  664. // catch (Exception ex)
  665. // {
  666. // Debug.LogError("Error connecting to the database: " + ex.Message);
  667. // }
  668. // finally
  669. // {
  670. // connection.Close();
  671. // }
  672. // }
  673. //}
  674. //public void 讀取圖片1()
  675. //{
  676. // 圖1.texture = null;
  677. // string connectionString = "Data Source=106.1.48.106,4567;Initial Catalog=OW-ERP-SYS;User ID=B70340;Password=Lee0911274990";
  678. // using (SqlConnection connection = new SqlConnection(connectionString))
  679. // {
  680. // try
  681. // {
  682. // connection.Open();
  683. // string query = "SELECT 音檔 FROM 測試錄音檔 WHERE 名稱 LIKE '測試'";
  684. // using (SqlCommand command = new SqlCommand(query, connection))
  685. // {
  686. // using (SqlDataReader reader = command.ExecuteReader())
  687. // {
  688. // if (reader.Read())
  689. // {
  690. // 讀取圖片的二進位資料
  691. // byte[] imageData = (byte[])reader["音檔"];
  692. // System.IO.File.WriteAllBytes(Application.persistentDataPath + "/pic.jpg", imageData);
  693. // Texture2D texture = new Texture2D(1, 1);
  694. // texture.LoadImage(imageData);
  695. // 將 Texture2D 設置為 RawImage 的 texture
  696. // if (texture.width >texture.height)
  697. // {
  698. // 圖1.rectTransform.sizeDelta = new Vector2(600, 450);
  699. // }
  700. // else
  701. // {
  702. // 圖1.rectTransform.sizeDelta = new Vector2(450, 600);
  703. // }
  704. // 圖1.texture = texture;
  705. // }
  706. // }
  707. // }
  708. // }
  709. // catch (Exception ex)
  710. // {
  711. // Debug.LogError("Error connecting to the database: " + ex.Message);
  712. // }
  713. // finally
  714. // {
  715. // connection.Close();
  716. // }
  717. // }
  718. //}
  719. //public void OpenNativeCamera()
  720. //{
  721. // AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
  722. // string action = intentClass.GetStatic<string>("ACTION_IMAGE_CAPTURE");
  723. // AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", action);
  724. // AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  725. // AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
  726. // if (intent.Call<AndroidJavaObject>("resolveActivity", currentActivity.GetStatic<AndroidJavaObject>("getPackageManager")) != null)
  727. // {
  728. // currentActivity.Call("startActivity", intent);
  729. // }
  730. // else
  731. // {
  732. // 失敗.text="No camera app available.";
  733. // }
  734. //}
  735. //public void OpenCamera()
  736. //{
  737. // string packageName = "com.sec.android.app.camera";
  738. // AndroidJavaClass appLauncherClass = new AndroidJavaClass("com.test.install.Install");
  739. // AndroidJavaObject unityContext = GetUnityContext();
  740. // appLauncherClass.CallStatic("openAppByPackageName", unityContext, packageName);
  741. // pic = true;
  742. //}
  743. //void OnApplicationFocus(bool hasFocus)
  744. //{
  745. // if (hasFocus)
  746. // {
  747. // if (pic)
  748. // {
  749. // 照片欄位新增();
  750. // pic = false;
  751. // }
  752. // 失敗.text="應用程序獲得焦點。";
  753. // // 在這裡執行應用程序獲得焦點時的操作
  754. // }
  755. // else
  756. // {
  757. // 失敗.text="應用程序失去焦點。";
  758. // // 在這裡執行應用程序失去焦點時的操作
  759. // }
  760. //}
  761. //private AndroidJavaObject GetUnityContext()
  762. //{
  763. // AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  764. // return unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
  765. //}
  766. public void 開啟相機()
  767. {
  768. 拍頁.SetActive(true);
  769. 返回紐.SetActive(true);
  770. 主頁.SetActive(false);
  771. 相片選擇頁.SetActive(false);
  772. StartCoroutine(open_Camera());
  773. }
  774. private IEnumerator open_Camera()
  775. {
  776. yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);//授權開啟鏡頭
  777. if (Application.HasUserAuthorization(UserAuthorization.WebCam))
  778. {
  779. /* (攝影機名稱, 攝影機要拍到的寬度, 攝影機要拍到的高度, 攝影機的FPS) */
  780. myCam = new WebCamTexture(WebCamTexture.devices[0].name, 1080, 1920, 60);
  781. 拍照用.texture = myCam;
  782. myCam.Play();//開啟攝影機
  783. }
  784. }
  785. public void 相機鈕()
  786. {
  787. Texture2D photoTexture = CapturePhoto();
  788. if (photoTexture != null)
  789. {
  790. if (照片欄數量 < 照片欄Array.Length)
  791. {
  792. 照片欄數量++;
  793. 照片欄新增Array[照片欄數量 - 1].SetActive(false);
  794. 照片欄刪除Array[照片欄數量 - 1].SetActive(true);
  795. if (照片欄數量 == 照片欄Array.Length)
  796. {
  797. 文字欄.SetActive(true);
  798. }
  799. else
  800. {
  801. 照片欄Array[照片欄數量].SetActive(true);
  802. }
  803. Texture2D texture = photoTexture;
  804. Texture2D texture1 = photoTexture;
  805. texture1=ResizeTexture(texture1, 196, 196);
  806. DeviceOrientation orientation = Input.deviceOrientation;
  807. 失敗1.text += orientation.ToString();
  808. texture =AdjustTextureOrientation(texture, orientation);
  809. texture1 =AdjustTextureOrientation(texture1, orientation);
  810. 上傳圖Array[照片欄數量 - 1] = texture;
  811. 縮圖Array[照片欄數量 - 1].texture = texture1;
  812. 相片選擇頁.SetActive(false);
  813. }
  814. }
  815. myCam.Stop();
  816. myCam = null;
  817. 拍頁.SetActive(false);
  818. 主頁.SetActive(true);
  819. Texture2D AdjustTextureOrientation(Texture2D originalTexture, DeviceOrientation orientation)
  820. {
  821. Texture2D adjustedTexture = new Texture2D(originalTexture.width, originalTexture.height);
  822. switch (orientation)
  823. {
  824. case DeviceOrientation.LandscapeLeft:
  825. // 顺时针旋转90度
  826. adjustedTexture = RotateTexture1(originalTexture, 90f);
  827. break;
  828. case DeviceOrientation.LandscapeRight:
  829. // 逆时针旋转90度
  830. adjustedTexture = RotateTexture1(originalTexture, -90f);
  831. break;
  832. case DeviceOrientation.PortraitUpsideDown:
  833. // 旋转180度
  834. adjustedTexture = RotateTexture1(originalTexture, 180f);
  835. break;
  836. default:
  837. // 其他情况下,返回原始图片
  838. adjustedTexture = originalTexture;
  839. break;
  840. }
  841. return adjustedTexture;
  842. }
  843. Texture2D CapturePhoto()
  844. {
  845. if (myCam != null)
  846. {
  847. int width = myCam.width;
  848. int height = myCam.height;
  849. // 创建一个新的 Texture2D,并读取当前帧的像素
  850. Texture2D photoTexture = new Texture2D(width, height);
  851. photoTexture.SetPixels(myCam.GetPixels());
  852. photoTexture.Apply();
  853. Texture2D rotatedTexture = RotateTexture(photoTexture, true);
  854. return rotatedTexture;
  855. }
  856. return null;
  857. }
  858. Texture2D ResizeTexture(Texture2D originalTexture, int newWidth, int newHeight)
  859. {
  860. Texture2D resizedTexture = new Texture2D(newWidth, newHeight, originalTexture.format, true);
  861. Color[] pixels = new Color[newWidth * newHeight];
  862. float incX = ((float)1 / originalTexture.width) * ((float)originalTexture.width / newWidth);
  863. float incY = ((float)1 / originalTexture.height) * ((float)originalTexture.height / newHeight);
  864. for (int x = 0; x < newWidth; x++)
  865. {
  866. for (int y = 0; y < newHeight; y++)
  867. {
  868. pixels[y * newWidth + x] = originalTexture.GetPixelBilinear(incX * x, incY * y);
  869. }
  870. }
  871. resizedTexture.SetPixels(pixels);
  872. resizedTexture.Apply();
  873. return resizedTexture;
  874. }
  875. Texture2D RotateTexture(Texture2D originalTexture, bool clockwise)
  876. {
  877. int width = originalTexture.width;
  878. int height = originalTexture.height;
  879. Texture2D rotatedTexture = new Texture2D(height, width);
  880. Color32[] originalPixels = originalTexture.GetPixels32();
  881. Color32[] rotatedPixels = new Color32[width * height];
  882. for (int y = 0; y < height; y++)
  883. {
  884. for (int x = 0; x < width; x++)
  885. {
  886. int newX = clockwise ? y : height - y - 1;
  887. int newY = clockwise ? width - x - 1 : x;
  888. rotatedPixels[newY * height + newX] = originalPixels[y * width + x];
  889. }
  890. }
  891. rotatedTexture.SetPixels32(rotatedPixels);
  892. rotatedTexture.Apply();
  893. return rotatedTexture;
  894. }
  895. Texture2D RotateTexture1(Texture2D originalTexture, float angle)
  896. {
  897. // Calculate the dimensions of the rotated texture
  898. int width = originalTexture.width;
  899. int height = originalTexture.height;
  900. float rotatedWidth = Mathf.Abs(width * Mathf.Cos(angle * Mathf.Deg2Rad)) + Mathf.Abs(height * Mathf.Sin(angle * Mathf.Deg2Rad));
  901. float rotatedHeight = Mathf.Abs(width * Mathf.Sin(angle * Mathf.Deg2Rad)) + Mathf.Abs(height * Mathf.Cos(angle * Mathf.Deg2Rad));
  902. // Create a new texture to store rotated pixels
  903. Texture2D rotatedTexture = new Texture2D(Mathf.RoundToInt(rotatedWidth), Mathf.RoundToInt(rotatedHeight));
  904. // Get the pixel data of the original texture
  905. Color32[] pixels = originalTexture.GetPixels32();
  906. Color32[] rotatedPixels = new Color32[Mathf.RoundToInt(rotatedWidth) * Mathf.RoundToInt(rotatedHeight)];
  907. // Calculate the center of the original texture
  908. float centerX = width / 2f;
  909. float centerY = height / 2f;
  910. // Iterate over each pixel in the rotated texture
  911. for (int x = 0; x < rotatedTexture.width; x++)
  912. {
  913. for (int y = 0; y < rotatedTexture.height; y++)
  914. {
  915. // Calculate the coordinates of the pixel in the original texture
  916. float originalX = Mathf.Cos(-angle * Mathf.Deg2Rad) * (x - rotatedWidth / 2) - Mathf.Sin(-angle * Mathf.Deg2Rad) * (y - rotatedHeight / 2) + centerX;
  917. float originalY = Mathf.Sin(-angle * Mathf.Deg2Rad) * (x - rotatedWidth / 2) + Mathf.Cos(-angle * Mathf.Deg2Rad) * (y - rotatedHeight / 2) + centerY;
  918. // Get the pixel color from the original texture and assign it to the rotated texture
  919. if (originalX >= 0 && originalX < width && originalY >= 0 && originalY < height)
  920. {
  921. int index = Mathf.RoundToInt(originalY) * width + Mathf.RoundToInt(originalX);
  922. rotatedPixels[y * rotatedTexture.width + x] = pixels[index];
  923. }
  924. else
  925. {
  926. // If the coordinates are outside the bounds of the original texture, set the pixel color to transparent
  927. rotatedPixels[y * rotatedTexture.width + x] = new Color32(0, 0, 0, 0);
  928. }
  929. }
  930. }
  931. // Set the rotated pixels to the rotated texture and apply changes
  932. rotatedTexture.SetPixels32(rotatedPixels);
  933. rotatedTexture.Apply();
  934. return rotatedTexture;
  935. }
  936. }
  937. private IEnumerator WaitForLocationService()
  938. {
  939. float latitude = 0;
  940. float longitude = 0;
  941. if (Input.location.isEnabledByUser)
  942. {
  943. while (Input.location.status == LocationServiceStatus.Initializing)
  944. {
  945. yield return null;
  946. }
  947. // 检查位置服务是否可用
  948. if (Input.location.isEnabledByUser)
  949. {
  950. // 获取当前位置信息
  951. latitude = Input.location.lastData.latitude;
  952. longitude = Input.location.lastData.longitude;
  953. 顯示2.text += "Latitude: " + latitude.ToString() +"\n\rLongitude: " + longitude.ToString();
  954. }
  955. else
  956. {
  957. Debug.LogWarning("Location services are not enabled.");
  958. }
  959. // 停止位置服务
  960. Input.location.Stop();
  961. yield return StartCoroutine(GetGeocodingData(latitude, longitude));
  962. }
  963. else
  964. {
  965. // 提示用户启用位置服务
  966. Debug.LogWarning("Location services are not enabled.");
  967. }
  968. }
  969. private IEnumerator GetGeocodingData(float latitude, float longitude)
  970. {
  971. string apiKey = "AIzaSyANrU_RGJBK4gPsqKYPZKwljvOqJvrfXi4";
  972. string url= $"https://maps.googleapis.com/maps/api/geocode/json?latlng={latitude},{longitude}&key={apiKey}";
  973. using (UnityWebRequest www = UnityWebRequest.Get(url))
  974. {
  975. yield return www.SendWebRequest();
  976. if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
  977. {
  978. Debug.LogError("Error: " + www.error);
  979. }
  980. else
  981. {
  982. // 解析 JSON 响应
  983. string jsonResponse = www.downloadHandler.text;
  984. //顯示2.text = "\n\r" + jsonResponse;
  985. ParseGeocodingResponse(jsonResponse);
  986. // 在这里处理 JSON 响应,提取地址信息
  987. }
  988. }
  989. }
  990. private void ParseGeocodingResponse(string jsonResponse)
  991. {
  992. JSONNode locationData = JSON.Parse(jsonResponse);
  993. Debug.Log(locationData);
  994. if (locationData["status"].Value == "OK")
  995. {
  996. JSONArray results = locationData["results"].AsArray;
  997. string combinedLocation = "";
  998. foreach (JSONNode result in results)
  999. {
  1000. JSONArray addressComponents = result["address_components"].AsArray;
  1001. string county = "";
  1002. string township = "";
  1003. foreach (JSONNode component in addressComponents)
  1004. {
  1005. JSONArray types = component["types"].AsArray;
  1006. string longName = component["long_name"];
  1007. // 檢查是否為 administrative_area_level_1 或 administrative_area_level_2
  1008. if (types != null && types.Count > 0)
  1009. {
  1010. foreach (JSONNode type in types)
  1011. {
  1012. if (type.Value == "administrative_area_level_1")
  1013. {
  1014. county = longName;
  1015. }
  1016. else if (type.Value == "administrative_area_level_2")
  1017. {
  1018. township = longName;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. if (!string.IsNullOrEmpty(county) && !string.IsNullOrEmpty(township))
  1024. {
  1025. bool containsChinese = Regex.IsMatch(county, @"[\u4e00-\u9fa5]");
  1026. bool containsChinese1 = Regex.IsMatch(township, @"[\u4e00-\u9fa5]");
  1027. if (containsChinese && containsChinese1)
  1028. {
  1029. combinedLocation = county + "+" + township;
  1030. 地址1=county;
  1031. 地址2=township;
  1032. Debug.Log("縣和鄉的地理位置:" + combinedLocation);
  1033. 顯示2.text += "\n\r縣和鄉的地理位置:" + combinedLocation;
  1034. break; // 出現1次就好,所以在這裡退出迴圈
  1035. }
  1036. }
  1037. }
  1038. if (string.IsNullOrEmpty(combinedLocation))
  1039. {
  1040. foreach (JSONNode result in results)
  1041. {
  1042. JSONArray addressComponents = result["address_components"].AsArray;
  1043. string county = "";
  1044. string township = "";
  1045. foreach (JSONNode component in addressComponents)
  1046. {
  1047. JSONArray types = component["types"].AsArray;
  1048. string shortName = component["short_name"];
  1049. // 檢查是否為 administrative_area_level_1 或 administrative_area_level_2
  1050. if (types != null && types.Count > 0)
  1051. {
  1052. foreach (JSONNode type in types)
  1053. {
  1054. if (type.Value == "administrative_area_level_1")
  1055. {
  1056. county = shortName;
  1057. }
  1058. else if (type.Value == "administrative_area_level_2")
  1059. {
  1060. township = shortName;
  1061. }
  1062. }
  1063. }
  1064. }
  1065. if (!string.IsNullOrEmpty(county) && !string.IsNullOrEmpty(township))
  1066. {
  1067. combinedLocation = county + "+" + township;
  1068. 地址1=county;
  1069. 地址2=township;
  1070. Debug.Log("縣和鄉的地理位置:" + combinedLocation);
  1071. break; // 出現1次就好,所以在這裡退出迴圈
  1072. }
  1073. }
  1074. }
  1075. }
  1076. else
  1077. {
  1078. Debug.Log("找不到縣和鄉的地理位置");
  1079. }
  1080. }
  1081. public void 新增貼文()
  1082. {
  1083. Debug.Log(照片欄數量);
  1084. if (照片欄數量 == 0)
  1085. {
  1086. 彈跳面板開啟("至少新增一張相片!!",false,false,true,() => { },() => { },彈跳面板關閉);
  1087. }
  1088. else
  1089. {
  1090. 讀取面板.SetActive(true);
  1091. 地址1 = "";
  1092. 地址2 = "";
  1093. for (int i = 0; i < 圖片流水.Length; i++)
  1094. {
  1095. 圖片流水[i] = "";
  1096. }
  1097. 錄音流水 = "";
  1098. 控制表單號 = "";
  1099. StartCoroutine(新增貼文流程());
  1100. }
  1101. }
  1102. private IEnumerator 新增貼文流程()
  1103. {
  1104. Input.location.Start();
  1105. yield return StartCoroutine(WaitForLocationService());
  1106. Set_控制表單號();
  1107. if (recordedClip != null)
  1108. {
  1109. SQL_CommString.SQL_連線字串_錄音_SQL(Main.Global.伺服器, 錄音資料庫名稱);
  1110. Set_錄音流水號();
  1111. byte[] wavData = WavUtility.FromAudioClip(recordedClip);
  1112. SQL_game_sys.SQL_新增錄音(錄音流水, wavData, 控制表單號);
  1113. }
  1114. for (int i = 0; i < 照片欄數量; i++)
  1115. {
  1116. SQL_CommString.SQL_連線字串_圖片_SQL(Main.Global.伺服器, 圖片資料庫名稱);
  1117. Set_圖片流水號(i);
  1118. byte[] imageBytes = 上傳圖Array[i].EncodeToJPG();
  1119. SQL_game_sys.SQL_新增圖片(圖片流水[i], imageBytes, 控制表單號);
  1120. }
  1121. string currentTime = DateTime.Now.ToString("yyyyMMdd-HHmmss");
  1122. SQL_game_sys.SQL_新增貼文(控制表單號, currentTime, 貼文內容.text, 圖片流水[0], 圖片流水[1], 圖片流水[2], 圖片流水[3], 圖片流水[4]
  1123. , 錄音流水, 地址1, 地址2, Main.Global.使用者UID, 圖片資料庫名稱, 錄音資料庫名稱);
  1124. Main.change_Secen(0);
  1125. }
  1126. public void back()
  1127. {
  1128. if (拍頁.activeSelf)
  1129. {
  1130. myCam.Stop();
  1131. myCam = null;
  1132. 拍頁.SetActive(false);
  1133. 相片選擇頁.SetActive(false);
  1134. 主頁.SetActive(true);
  1135. }
  1136. else
  1137. {
  1138. if (照片欄數量 == 0 && 貼文內容.text =="" && recordedClip == null)
  1139. {
  1140. Main.change_Secen(0);
  1141. }
  1142. else
  1143. {
  1144. 彈跳面板開啟("有讀取到內容,是否要放棄編輯", true, true, false, back1, 彈跳面板關閉, () => { });
  1145. }
  1146. }
  1147. }
  1148. private void back1()
  1149. {
  1150. Main.change_Secen(0);
  1151. }
  1152. public void 彈跳面板開啟(string str,bool 是 , bool 否, bool 叉, Action 是監聽, Action 否監聽, Action 叉監聽)
  1153. {
  1154. 彈跳面板.SetActive(true);
  1155. 主頁.SetActive(false);
  1156. 返回紐.SetActive(false);
  1157. 彈跳是.gameObject.SetActive(是);
  1158. 彈跳否.gameObject.SetActive(否);
  1159. 彈跳叉.gameObject.SetActive(叉);
  1160. 彈跳文字.text=str;
  1161. void 叉監聽器()
  1162. {
  1163. 叉監聽();
  1164. // 在這裡添加任何你需要的額外邏輯
  1165. // 現在你可以輕鬆地刪除監聽器
  1166. 彈跳叉.onClick.RemoveListener(叉監聽器);
  1167. }
  1168. void 是監聽器()
  1169. {
  1170. 是監聽();
  1171. // 在這裡添加任何你需要的額外邏輯
  1172. // 現在你可以輕鬆地刪除監聽器
  1173. 彈跳是.onClick.RemoveListener(是監聽器);
  1174. }
  1175. void 否監聽器()
  1176. {
  1177. 否監聽();
  1178. // 在這裡添加任何你需要的額外邏輯
  1179. // 現在你可以輕鬆地刪除監聽器
  1180. 彈跳否.onClick.RemoveListener(否監聽器);
  1181. }
  1182. // 將監聽器添加到按鈕點擊事件中
  1183. 彈跳叉.onClick.AddListener(叉監聽器);
  1184. 彈跳是.onClick.AddListener(是監聽器);
  1185. 彈跳否.onClick.AddListener(否監聽器);
  1186. }
  1187. public void 彈跳面板關閉()
  1188. {
  1189. 主頁.SetActive(true);
  1190. 返回紐.SetActive(true);
  1191. 彈跳面板.SetActive(false);
  1192. 彈跳文字.text="";
  1193. }
  1194. private void Set_錄音流水號()
  1195. {
  1196. SQL_game_sys.SQL_查詢錄音流水號();
  1197. if (SQL_Module.dr.Read())
  1198. {
  1199. string 流水 = SQL_Module.dr["錄音流水號"].ToString();
  1200. double 流水號數字部分 = double.Parse(流水.Substring(1));
  1201. double 新流水號數字部分 = 流水號數字部分 + 1;
  1202. string 新流水號數字部分字串 = 新流水號數字部分.ToString().PadLeft(8, '0');
  1203. 錄音流水 = "V" + 新流水號數字部分字串;
  1204. }
  1205. else
  1206. {
  1207. 錄音流水 ="V00000000";
  1208. }
  1209. }
  1210. private void Set_圖片流水號(int i)
  1211. {
  1212. SQL_game_sys.SQL_查詢圖片流水號();
  1213. if (SQL_Module.dr.Read())
  1214. {
  1215. string 流水 = SQL_Module.dr["圖片流水號"].ToString();
  1216. double 流水號數字部分 = double.Parse(流水.Substring(1));
  1217. double 新流水號數字部分 = 流水號數字部分 + 1;
  1218. string 新流水號數字部分字串 = 新流水號數字部分.ToString().PadLeft(8, '0');
  1219. 圖片流水[i] = "P" + 新流水號數字部分字串;
  1220. }
  1221. else
  1222. {
  1223. 圖片流水[i] ="P00000000";
  1224. }
  1225. }
  1226. private void Set_控制表單號()
  1227. {
  1228. string date = DateTime.Today.ToString("yyyyMMdd");
  1229. SQL_game_sys.SQL_查詢貼文流水號(date);
  1230. if (SQL_Module.dr.Read())
  1231. {
  1232. string 流水 = SQL_Module.dr["控制表單號"].ToString(); // 將流水號轉換為字串
  1233. string parts = 流水.Substring(流水.Length - 8);
  1234. double 流水號數字部分 = double.Parse(parts);
  1235. double 新流水號數字部分 = 流水號數字部分 + 1;
  1236. string 新流水號數字部分字串 = 新流水號數字部分.ToString().PadLeft(8, '0');
  1237. 控制表單號 = "A-" + date + "-" + 新流水號數字部分字串;
  1238. }
  1239. else
  1240. {
  1241. 控制表單號 = "A-" + date + "-00000001";
  1242. }
  1243. }
  1244. public void 截圖()
  1245. {
  1246. Main.截圖();
  1247. }
  1248. }