Browse Source

分享,剧情模块,卡牌合成

zhangyuqian 1 year ago
parent
commit
784f632b6c

+ 12 - 25
GameClient/Assets/Game/HotUpdate/Data/ShareDataManager.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using ET;
@@ -11,7 +12,6 @@ namespace GFGGame
     {
         //当前分享
         public byte[] imageBytes;
-        public Camera targetCamera; // 指定要读取的摄像机
         public string outputImagePath; // 输出图片的路径
 
         public void ShareImage(string imageUrl)
@@ -21,36 +21,23 @@ namespace GFGGame
         }
         public void CaptureCameraToImage(bool isJump = true)
         {
-            targetCamera = GameObject.Find("Stage Camera").GetComponent<Camera>();
+            Timers.inst.StartCoroutine(CaptureCameraImage(isJump));
+        }
+        private IEnumerator CaptureCameraImage(bool isJump = true)
+        {
+            yield return new WaitForEndOfFrame();
             SetImageTargetPath();
-            // 创建RenderTexture
-            RenderTexture renderTexture = new RenderTexture(targetCamera.pixelWidth, targetCamera.pixelHeight, 24);
-            targetCamera.targetTexture = renderTexture;
-
-            // 强制摄像机渲染
-            targetCamera.Render();
-
-            // 创建Texture2D
-            Texture2D screenShot = new Texture2D(targetCamera.pixelWidth, targetCamera.pixelHeight, TextureFormat.RGBA32, false);
-            RenderTexture.active = renderTexture;
-            screenShot.ReadPixels(new Rect(0, 0, targetCamera.pixelWidth, targetCamera.pixelHeight), 0, 0);
-            screenShot.Apply();
-
-            // 将RenderTexture中的像素数据读取到Texture2D
-            screenShot.ReadPixels(new Rect(0, 0, targetCamera.pixelWidth, targetCamera.pixelHeight), 0, 0);
-            screenShot.Apply();
+            Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
+            Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);//新建一个Texture2D对象
+            tex.ReadPixels(rect, 0, 0);//读取像素,屏幕左下角为0点
+            tex.Apply();//保存像素信息
 
             // 将Texture2D保存为图片
-            imageBytes = screenShot.EncodeToPNG();
+            imageBytes = tex.EncodeToPNG();
 
             // 保存到磁盘
             File.WriteAllBytes(outputImagePath, imageBytes);
 
-            // 释放资源
-            renderTexture.Release();
-            Resources.UnloadUnusedAssets();
-            targetCamera.targetTexture = null;
-
             Debug.Log("Camera capture saved to " + outputImagePath);
             if(isJump)
             {
@@ -61,7 +48,7 @@ namespace GFGGame
         public Texture2D ConvertBytesToTexture(byte[] imageBytes)
         {
             // 创建一个新的Texture2D对象
-            Texture2D texture = new Texture2D(targetCamera.pixelWidth, targetCamera.pixelHeight); // 宽度和高度需要根据图片实际尺寸来设置
+            Texture2D texture = new Texture2D(UnityEngine.Screen.width, UnityEngine.Screen.height); // 宽度和高度需要根据图片实际尺寸来设置
             texture.LoadImage(imageBytes); // 加载图片数据
 
             // 应用纹理设置

+ 1 - 1
GameClient/Assets/Game/HotUpdate/DressUp/SceneController.cs

@@ -198,7 +198,7 @@ namespace GFGGame
                 value = string.Format("DressUp/{0}", value);
                 string res = value.Split('/')[1];
                 animObj = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetStoryDialogCGPath(value, res));
-                animObj.transform.position = new Vector3(0, -8, 0);
+                animObj.transform.position = new Vector3(0, -9, 0);
                 animObj.transform.localScale = new Vector3(2.5f, 2.5f, 2.5f);
                 //StoryDialogDataManager.Instance.dialogShowDelay = 0.4f;
             }

+ 4 - 1
GameClient/Assets/Game/HotUpdate/Views/MainStory/StoryDialogView.cs

@@ -834,7 +834,10 @@ namespace GFGGame
             }
             if (emojiValue.Length > 0)
             {
-                SceneController.UpdateDialogPic("0", _sceneObject);
+                if(emojiValue != "0")
+                {
+                    SceneController.UpdateDialogPic("0", _sceneObject);
+                }
                 UpdateLiveEmoji(emojiValue);
             }
         }

BIN
GameClient/Assets/ResIn/UI/CardSynthetic/CardSynthetic_atlas0!a.png


BIN
GameClient/Assets/ResIn/UI/CardSynthetic/CardSynthetic_atlas0.png


BIN
GameClient/Assets/ResIn/UI/CardSynthetic/CardSynthetic_fui.bytes