Browse Source

修改 文件显示

DGJ 1 year ago
parent
commit
c1359c046a

+ 4 - 1
Assets/LangChaoRTC/Remote/ShowRoom/RoomInvite/Scripts/BaseFilePrefabItem.cs

@@ -27,11 +27,14 @@ public class BaseFilePrefabItem : MonoBehaviour,IPointerHandler
 
     private void ClickOnHideBtn()
     {
+
+        if (this.fileConfig != null && this.fileConfig.FileType == RoomFileType.mp4)
+            return;
         if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig))
         {
             RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig);
         }
-        Destroy(this.gameObject);
+        this.gameObject.SetActive(false);
         if (this.fileConfig != null)
         {
             RoomFile.HidefileChooseAction?.Invoke(this.fileConfig);

+ 3 - 0
Assets/LangChaoRTC/Remote/ShowRoom/RoomInvite/Scripts/FileConfig.cs

@@ -24,6 +24,7 @@ public class FileConfig
     private string extname;
     private string objectName;
     private string bucket;
+    private string uuid;
 
     public string PeerId { get => peerId; set => peerId = value; }
     public string From { get => from; set => from = value; }
@@ -36,6 +37,8 @@ public class FileConfig
     public string Extname { get => extname; set => extname = value; }
     public string ObjectName { get => objectName; set => objectName = value; }
     public string Bucket { get => bucket; set => bucket = value; }
+
+    public string UUid { get => uuid; set => uuid = value; }
     public RoomFileType FileType
     {
         get

+ 45 - 20
Assets/LangChaoRTC/Remote/ShowRoom/RoomInvite/Scripts/Mp4Item.cs

@@ -14,6 +14,7 @@ public class Mp4Item : BaseFilePrefabItem
     public AVProVideoPlayer aVProVideoPlayer;
     public override void Init(FileConfig fileConfig)
     {
+        hideBtn.onClick.AddListener(() => { StartCoroutine(CloseVideo()); });
         Debug.Log("Hjj      "+ fileConfig.Url);
         base.Init(fileConfig);
         if (!string.IsNullOrEmpty(fileConfig.Url))
@@ -25,20 +26,37 @@ public class Mp4Item : BaseFilePrefabItem
                 url = "https://" + fileConfig.Url;
             }
 
-            LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
-
-                Debug.Log("rfd==>" + rfd.url);
-                Debug.Log("rfd==>" + rfd.bytes.Length);
-
-                // url = rfd.url;
-                // aVProVideoPlayer.SetUrl(url);
-                StartCoroutine(SaveMp4(Application.persistentDataPath + "/" + fileConfig.FileName, rfd.bytes));
-            });
-
           
          //   videoPlayer.url = url;
            
         }
+
+
+        LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
+
+            Debug.Log("rfd==>" + rfd.url);
+            Debug.Log("rfd==>" + rfd.bytes.Length);
+
+           // url = rfd.url;
+            // aVProVideoPlayer.SetUrl(url);
+            StartCoroutine(SaveMp4(Application.persistentDataPath + "/" + fileConfig.UUid + Path.GetExtension(fileConfig.FileName), rfd.bytes));
+        });
+
+    }
+
+    private IEnumerator CloseVideo()
+    {
+        transform.position += new Vector3(10000, 0, 0);
+        yield return !string.IsNullOrEmpty(aVProVideoPlayer.GetUrl());
+        if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig))
+        {
+            RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig);
+        }
+        this.gameObject.SetActive(false);
+        if (this.fileConfig != null)
+        {
+            RoomFile.HidefileChooseAction?.Invoke(this.fileConfig);
+        }
     }
 
     private IEnumerator SaveMp4(string path , byte[] bytes)
@@ -47,17 +65,24 @@ public class Mp4Item : BaseFilePrefabItem
         FileInfo file = new FileInfo(path);
         if (file.Exists)
         {
-            file.Delete();
+            // file.Delete();
+            yield return new WaitForSeconds(0.02f);
+            aVProVideoPlayer.SetUrl(path);
+
+        }
+        else
+        {
+            Stream sw = File.Create(path);
+            // FileStream sw = new FileStream(path);
+
+            sw.Write(bytes, 0, bytes.Length);
+
+            sw.Close();
+            sw.Dispose();
+            yield return new WaitForSeconds(0.02f);
+            aVProVideoPlayer.SetUrl(path);
         }
-        Stream sw = File.Create(path);
-       // FileStream sw = new FileStream(path);
-        
-        sw.Write(bytes, 0, bytes.Length);
-       
-        sw.Close();
-        sw.Dispose();
-        yield return new WaitForSeconds(0.02f);
-        aVProVideoPlayer.SetUrl(path);
+      
     }
 
     protected override void Start()

+ 1 - 1
Assets/LangChaoRTC/Remote/ShowRoom/RoomInvite/Scripts/Mp4List.cs

@@ -31,7 +31,7 @@ public class Mp4List : UnitySingleton<Mp4List>
         {
             for (int i = 0; i < transform.childCount; i++)
             {
-                Destroy(transform.GetChild(i).gameObject);
+                transform.GetChild(i).GetComponent<Mp4Item>().hideBtn.onClick.Invoke();
             }
         }
     }

+ 13 - 11
Assets/LangChaoRTC/Remote/ShowRoom/RoomInvite/Scripts/PngJpgItem.cs

@@ -32,18 +32,22 @@ public class PngJpgItem : BaseFilePrefabItem
         {
             string url = fileConfig.Url;
 
-            LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
-
-                Debug.Log("rfd==>" + rfd.url);
-                Debug.Log("rfd==>" + rfd.bytes.Length);
-                url = rfd.url;
-
-            });
+          
 
             if (!fileConfig.Url.Contains("http"))
             {
                 url = "https://" + fileConfig.Url;
             }
+         
+
+
+         }
+
+        LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
+
+            Debug.Log("rfd==>" + rfd.url);
+            Debug.Log("rfd==>" + rfd.bytes.Length);
+           string url = rfd.url;
             NetWorkHeaders.Instance.getNetTexture(url, null, (Texture tex) =>
             {
                 if (tex)
@@ -52,10 +56,8 @@ public class PngJpgItem : BaseFilePrefabItem
                     mainImage.texture = tex;
                 }
             });
-
-
-         }
-     }
+        });
+    }
 
     public void Adaption(Texture tex)
     {

+ 11 - 6
Assets/LangChaoRTC/Remote/Z_Blend/PdfManager.cs

@@ -15,19 +15,24 @@ public class PdfManager : BaseFilePrefabItem
         if (!string.IsNullOrEmpty(fileConfig.Url))
         {
             string url = fileConfig.Url;
+          
+            if (!fileConfig.Url.Contains("http"))
+            {
+                url = "https://" + fileConfig.Url;
+            }
             LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
 
                 Debug.Log("rfd==>" + rfd.url);
                 Debug.Log("rfd==>" + rfd.bytes.Length);
-                url = rfd.url;
+                string url = rfd.url;
+                showPDF(url);
 
             });
-            if (!fileConfig.Url.Contains("http"))
-            {
-                url = "https://" + fileConfig.Url;
-            }
-            showPDF(url);
+          
         }
+
+      
+       
     }
 
     public void showPDF(string url)

+ 45 - 0
Assets/Scenes/LangChaoDemo2.unity

@@ -3100,6 +3100,7 @@ Transform:
   - {fileID: 1485402483}
   - {fileID: 583309982}
   - {fileID: 1496039441}
+  - {fileID: 1677450787}
   m_Father: {fileID: 0}
   m_RootOrder: 13
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -22538,6 +22539,50 @@ Transform:
   m_Father: {fileID: 102144601}
   m_RootOrder: 5
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &1677450786
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1677450787}
+  - component: {fileID: 1677450788}
+  m_Layer: 0
+  m_Name: APPExit
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &1677450787
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1677450786}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 264371157}
+  m_RootOrder: 3
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!114 &1677450788
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1677450786}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: a99e85f81f8bbd748837b131ecc00723, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!1 &1681491339
 GameObject:
   m_ObjectHideFlags: 0

+ 34 - 0
Assets/Scripts/Tool/APPExit.cs

@@ -0,0 +1,34 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class APPExit : MonoBehaviour
+{
+    // Start is called before the first frame update
+    void Start()
+    {
+        
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        
+    }
+
+    private void OnApplicationPause(bool pauseStatus)
+    {
+        if (pauseStatus)
+        {
+            Debug.Log("应用进入后台");
+            // 在应用进入后台时执行的操作
+
+            Application.Quit();
+        }
+        else
+        {
+            Debug.Log("应用返回前台");
+            // 在应用返回前台时执行的操作
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Tool/APPExit.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a99e85f81f8bbd748837b131ecc00723
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: