王琪诚

【任务】TAPD#

功能详情 朋友圈json加载
配置文件 否
提交作者 QiCheng.Wang
评审人员
@@ -947,7 +947,7 @@ RectTransform: @@ -947,7 +947,7 @@ RectTransform:
947 m_AnchorMin: {x: 0, y: 1} 947 m_AnchorMin: {x: 0, y: 1}
948 m_AnchorMax: {x: 0, y: 1} 948 m_AnchorMax: {x: 0, y: 1}
949 m_AnchoredPosition: {x: 800, y: -490} 949 m_AnchoredPosition: {x: 800, y: -490}
950 - m_SizeDelta: {x: 1160, y: 180} 950 + m_SizeDelta: {x: 1160, y: 160}
951 m_Pivot: {x: 0.5, y: 0.5} 951 m_Pivot: {x: 0.5, y: 0.5}
952 --- !u!114 &637033553 952 --- !u!114 &637033553
953 MonoBehaviour: 953 MonoBehaviour:
@@ -2319,7 +2319,7 @@ GameObject: @@ -2319,7 +2319,7 @@ GameObject:
2319 m_Icon: {fileID: 0} 2319 m_Icon: {fileID: 0}
2320 m_NavMeshLayer: 0 2320 m_NavMeshLayer: 0
2321 m_StaticEditorFlags: 0 2321 m_StaticEditorFlags: 0
2322 - m_IsActive: 1 2322 + m_IsActive: 0
2323 --- !u!224 &1347929217 2323 --- !u!224 &1347929217
2324 RectTransform: 2324 RectTransform:
2325 m_ObjectHideFlags: 0 2325 m_ObjectHideFlags: 0
@@ -2361,7 +2361,6 @@ MonoBehaviour: @@ -2361,7 +2361,6 @@ MonoBehaviour:
2361 danmakuPanel: {fileID: 1475588209} 2361 danmakuPanel: {fileID: 1475588209}
2362 danmakuPrefab: {fileID: 7870940708185808822, guid: 7b836662dd2b34183bc4e6c9d87f4d26, type: 3} 2362 danmakuPrefab: {fileID: 7870940708185808822, guid: 7b836662dd2b34183bc4e6c9d87f4d26, type: 3}
2363 speed: 100 2363 speed: 100
2364 - maxLines: 5  
2365 --- !u!1 &1447955073 2364 --- !u!1 &1447955073
2366 GameObject: 2365 GameObject:
2367 m_ObjectHideFlags: 0 2366 m_ObjectHideFlags: 0
@@ -2529,7 +2528,7 @@ RectTransform: @@ -2529,7 +2528,7 @@ RectTransform:
2529 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 2528 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
2530 m_AnchorMin: {x: 0.5, y: 0.5} 2529 m_AnchorMin: {x: 0.5, y: 0.5}
2531 m_AnchorMax: {x: 0.5, y: 0.5} 2530 m_AnchorMax: {x: 0.5, y: 0.5}
2532 - m_AnchoredPosition: {x: -4.7269, y: -245} 2531 + m_AnchoredPosition: {x: -4.7269, y: 283}
2533 m_SizeDelta: {x: 1500, y: 300} 2532 m_SizeDelta: {x: 1500, y: 300}
2534 m_Pivot: {x: 0.5, y: 0.5} 2533 m_Pivot: {x: 0.5, y: 0.5}
2535 --- !u!114 &1475588210 2534 --- !u!114 &1475588210
@@ -10,7 +10,6 @@ public class DanmakuManager : MonoBehaviour @@ -10,7 +10,6 @@ public class DanmakuManager : MonoBehaviour
10 public RectTransform danmakuPanel; // 弹幕pannel 10 public RectTransform danmakuPanel; // 弹幕pannel
11 public GameObject danmakuPrefab; 11 public GameObject danmakuPrefab;
12 public float speed = 100f; // px/sec 12 public float speed = 100f; // px/sec
13 - public int maxLines = 5; // 最多几行  
14 private int currentLine = 0; 13 private int currentLine = 0;
15 14
16 public void AddDanmaku(string text,int direction) 15 public void AddDanmaku(string text,int direction)
@@ -23,6 +23,7 @@ public class MomentItem : MonoBehaviour @@ -23,6 +23,7 @@ public class MomentItem : MonoBehaviour
23 23
24 public Transform imageGrid; // 父对象,用于图片缩略图排列 24 public Transform imageGrid; // 父对象,用于图片缩略图排列
25 public GameObject imagePrefab; // 小图预制体 25 public GameObject imagePrefab; // 小图预制体
  26 + public Image bigImageInit; //大图初始化
26 27
27 public Transform videoGrid; // 父对象 28 public Transform videoGrid; // 父对象
28 public GameObject videoPrefab; // 视频预制体 29 public GameObject videoPrefab; // 视频预制体
@@ -218,9 +219,12 @@ public class MomentItem : MonoBehaviour @@ -218,9 +219,12 @@ public class MomentItem : MonoBehaviour
218 } 219 }
219 220
220 Image img = imgObj.GetComponent<Image>(); 221 Image img = imgObj.GetComponent<Image>();
221 - //缩略图和大图不一样,第一次LoadImage只为了预下载大图片  
222 - StartCoroutine(ImageLoader.LoadImage(url, img)); 222 + //缩略图和大图不一样,第1次LoadImage只为了预下载大图片
223 StartCoroutine(ImageLoader.LoadImage(AddSuffixBeforeExtension(url,"-s"), img)); 223 StartCoroutine(ImageLoader.LoadImage(AddSuffixBeforeExtension(url,"-s"), img));
  224 +
  225 + StartCoroutine(ImageLoader.LoadImage(url, bigImageInit));
  226 + bigImageInit.sprite = null;
  227 +
224 Transform child = imgObj.transform.GetChild(0); 228 Transform child = imgObj.transform.GetChild(0);
225 child.DOScale(1.5f, 2f).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.InOutSine); 229 child.DOScale(1.5f, 2f).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.InOutSine);
226 230
@@ -13,8 +13,16 @@ public class MomentManager : MonoBehaviour @@ -13,8 +13,16 @@ public class MomentManager : MonoBehaviour
13 13
14 void Start() 14 void Start()
15 { 15 {
16 - TextAsset jsonText = Resources.Load<TextAsset>("Jsons/friend_data");  
17 - MomentList data = JsonUtility.FromJson<MomentList>(jsonText.text); 16 + StartCoroutine(JsonLoaderManager.LoadJson("https://h5.edcc.cn/FriendCircle/json/friend_data.json","Jsons/friend_data",data =>
  17 + {
  18 + Debug.Log("最终获取到的 JSON 数据:\n" + data);
  19 + InitFriendCircle(data);
  20 + }));
  21 + }
  22 +
  23 + private void InitFriendCircle(string jsonText)
  24 + {
  25 + MomentList data = JsonUtility.FromJson<MomentList>(jsonText);
18 26
19 StartCoroutine(ImageLoader.LoadImage(data.cover, coverImage)); 27 StartCoroutine(ImageLoader.LoadImage(data.cover, coverImage));
20 StartCoroutine(ImageLoader.LoadImage(data.bottom, bottomImage)); 28 StartCoroutine(ImageLoader.LoadImage(data.bottom, bottomImage));
@@ -60,8 +68,7 @@ public class MomentManager : MonoBehaviour @@ -60,8 +68,7 @@ public class MomentManager : MonoBehaviour
60 68
61 //设置外层ScrollContent层高度 69 //设置外层ScrollContent层高度
62 RectTransform scrollContentRt = contentParent.parent.GetComponent<RectTransform>(); 70 RectTransform scrollContentRt = contentParent.parent.GetComponent<RectTransform>();
63 - scrollContentRt.sizeDelta =  
64 - new Vector2(scrollContentRt.sizeDelta.x, coverHeight + momentListHeight + bottomHeight); 71 + scrollContentRt.sizeDelta = new Vector2(scrollContentRt.sizeDelta.x, coverHeight + momentListHeight + bottomHeight);
65 } 72 }
66 73
67 private void OnApplicationQuit() 74 private void OnApplicationQuit()
  1 +using UnityEngine;
  2 +using UnityEngine.Networking;
  3 +using System.Collections;
  4 +
  5 +public class JsonLoaderManager : Singleton<JsonLoaderManager>
  6 +{
  7 +
  8 +
  9 + public static IEnumerator LoadJson(string remoteUrl,string localUrl,System.Action<string> onJsonReady)
  10 + {
  11 + string json = null;
  12 + bool loadedFromWeb = false;
  13 +
  14 + using (UnityWebRequest uwr = UnityWebRequest.Get(remoteUrl))
  15 + {
  16 + uwr.timeout = 5; // 设置超时时间
  17 + yield return uwr.SendWebRequest();
  18 +
  19 + if (uwr.result == UnityWebRequest.Result.Success)
  20 + {
  21 + json = uwr.downloadHandler.text;
  22 + loadedFromWeb = true;
  23 + Debug.Log("✅ 从网络加载成功");
  24 + }
  25 + else
  26 + {
  27 + Debug.LogWarning("⚠️ 网络加载失败,尝试加载本地 JSON:" + uwr.error);
  28 + }
  29 + }
  30 +
  31 + if (!loadedFromWeb)
  32 + {
  33 + TextAsset localJson = Resources.Load<TextAsset>(localUrl);
  34 + if (localJson != null)
  35 + {
  36 + json = localJson.text;
  37 + Debug.Log("📁 从本地加载 JSON 成功");
  38 + }
  39 + else
  40 + {
  41 + Debug.LogError("❌ 本地 JSON 不存在!");
  42 + }
  43 + }
  44 + onJsonReady?.Invoke(json);
  45 + }
  46 +}
  1 +fileFormatVersion: 2
  2 +guid: bdb69f00adae4726a321eebf82ac9b79
  3 +timeCreated: 1750834988
@@ -104,7 +104,7 @@ @@ -104,7 +104,7 @@
104 }, 104 },
105 { 105 {
106 "username": "祝融号", 106 "username": "祝融号",
107 - "avatarUrl": "https://h5.edcc.cn/FriendCircle/image/head-video.png", 107 + "avatarUrl": "https://h5.edcc.cn/FriendCircle/image/head.png",
108 "text": "忍不住发了好几条朋友圈,你们有看到吗?我还能原地转弯呢。", 108 "text": "忍不住发了好几条朋友圈,你们有看到吗?我还能原地转弯呢。",
109 "from": "来自:火星", 109 "from": "来自:火星",
110 "time": "2021年6月11日", 110 "time": "2021年6月11日",
@@ -1002,6 +1002,7 @@ RectTransform: @@ -1002,6 +1002,7 @@ RectTransform:
1002 - {fileID: 5137047804386020533} 1002 - {fileID: 5137047804386020533}
1003 - {fileID: 3638516876483047710} 1003 - {fileID: 3638516876483047710}
1004 - {fileID: 954098158191977059} 1004 - {fileID: 954098158191977059}
  1005 + - {fileID: 2685931706963452372}
1005 m_Father: {fileID: 0} 1006 m_Father: {fileID: 0}
1006 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 1007 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1007 m_AnchorMin: {x: 0, y: 1} 1008 m_AnchorMin: {x: 0, y: 1}
@@ -1026,6 +1027,7 @@ MonoBehaviour: @@ -1026,6 +1027,7 @@ MonoBehaviour:
1026 contentText: {fileID: 4430445110796385188} 1027 contentText: {fileID: 4430445110796385188}
1027 imageGrid: {fileID: 1041260462946003438} 1028 imageGrid: {fileID: 1041260462946003438}
1028 imagePrefab: {fileID: 6223382467879224884, guid: ca325bf8ed54c41479e9c7d18e457e1e, type: 3} 1029 imagePrefab: {fileID: 6223382467879224884, guid: ca325bf8ed54c41479e9c7d18e457e1e, type: 3}
  1030 + bigImageInit: {fileID: 2628341785345091319}
1029 videoGrid: {fileID: 8815226098748290278} 1031 videoGrid: {fileID: 8815226098748290278}
1030 videoPrefab: {fileID: 646672757163800049, guid: bd2d13416179847beac4e59cd608113c, type: 3} 1032 videoPrefab: {fileID: 646672757163800049, guid: bd2d13416179847beac4e59cd608113c, type: 3}
1031 from: {fileID: 3009102025949839682} 1033 from: {fileID: 3009102025949839682}
@@ -1054,7 +1056,6 @@ MonoBehaviour: @@ -1054,7 +1056,6 @@ MonoBehaviour:
1054 danmakuPanel: {fileID: 954098158191977059} 1056 danmakuPanel: {fileID: 954098158191977059}
1055 danmakuPrefab: {fileID: 7870940708185808822, guid: 7b836662dd2b34183bc4e6c9d87f4d26, type: 3} 1057 danmakuPrefab: {fileID: 7870940708185808822, guid: 7b836662dd2b34183bc4e6c9d87f4d26, type: 3}
1056 speed: 100 1058 speed: 100
1057 - maxLines: 5  
1058 --- !u!222 &8920725948406434288 1059 --- !u!222 &8920725948406434288
1059 CanvasRenderer: 1060 CanvasRenderer:
1060 m_ObjectHideFlags: 0 1061 m_ObjectHideFlags: 0
@@ -1367,6 +1368,81 @@ MonoBehaviour: @@ -1367,6 +1368,81 @@ MonoBehaviour:
1367 m_FlexibleWidth: -1 1368 m_FlexibleWidth: -1
1368 m_FlexibleHeight: -1 1369 m_FlexibleHeight: -1
1369 m_LayoutPriority: 1 1370 m_LayoutPriority: 1
  1371 +--- !u!1 &4336015732213254032
  1372 +GameObject:
  1373 + m_ObjectHideFlags: 0
  1374 + m_CorrespondingSourceObject: {fileID: 0}
  1375 + m_PrefabInstance: {fileID: 0}
  1376 + m_PrefabAsset: {fileID: 0}
  1377 + serializedVersion: 6
  1378 + m_Component:
  1379 + - component: {fileID: 2685931706963452372}
  1380 + - component: {fileID: 8974834196693201696}
  1381 + - component: {fileID: 2628341785345091319}
  1382 + m_Layer: 5
  1383 + m_Name: ImageInit
  1384 + m_TagString: Untagged
  1385 + m_Icon: {fileID: 0}
  1386 + m_NavMeshLayer: 0
  1387 + m_StaticEditorFlags: 0
  1388 + m_IsActive: 0
  1389 +--- !u!224 &2685931706963452372
  1390 +RectTransform:
  1391 + m_ObjectHideFlags: 0
  1392 + m_CorrespondingSourceObject: {fileID: 0}
  1393 + m_PrefabInstance: {fileID: 0}
  1394 + m_PrefabAsset: {fileID: 0}
  1395 + m_GameObject: {fileID: 4336015732213254032}
  1396 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  1397 + m_LocalPosition: {x: 0, y: 0, z: 0}
  1398 + m_LocalScale: {x: 1, y: 1, z: 1}
  1399 + m_ConstrainProportionsScale: 0
  1400 + m_Children: []
  1401 + m_Father: {fileID: 5112969456787946611}
  1402 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
  1403 + m_AnchorMin: {x: 0.5, y: 0.5}
  1404 + m_AnchorMax: {x: 0.5, y: 0.5}
  1405 + m_AnchoredPosition: {x: 0, y: 0}
  1406 + m_SizeDelta: {x: 100, y: 100}
  1407 + m_Pivot: {x: 0.5, y: 0.5}
  1408 +--- !u!222 &8974834196693201696
  1409 +CanvasRenderer:
  1410 + m_ObjectHideFlags: 0
  1411 + m_CorrespondingSourceObject: {fileID: 0}
  1412 + m_PrefabInstance: {fileID: 0}
  1413 + m_PrefabAsset: {fileID: 0}
  1414 + m_GameObject: {fileID: 4336015732213254032}
  1415 + m_CullTransparentMesh: 1
  1416 +--- !u!114 &2628341785345091319
  1417 +MonoBehaviour:
  1418 + m_ObjectHideFlags: 0
  1419 + m_CorrespondingSourceObject: {fileID: 0}
  1420 + m_PrefabInstance: {fileID: 0}
  1421 + m_PrefabAsset: {fileID: 0}
  1422 + m_GameObject: {fileID: 4336015732213254032}
  1423 + m_Enabled: 1
  1424 + m_EditorHideFlags: 0
  1425 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
  1426 + m_Name:
  1427 + m_EditorClassIdentifier:
  1428 + m_Material: {fileID: 0}
  1429 + m_Color: {r: 1, g: 1, b: 1, a: 1}
  1430 + m_RaycastTarget: 1
  1431 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
  1432 + m_Maskable: 1
  1433 + m_OnCullStateChanged:
  1434 + m_PersistentCalls:
  1435 + m_Calls: []
  1436 + m_Sprite: {fileID: 0}
  1437 + m_Type: 0
  1438 + m_PreserveAspect: 0
  1439 + m_FillCenter: 1
  1440 + m_FillMethod: 4
  1441 + m_FillAmount: 1
  1442 + m_FillClockwise: 1
  1443 + m_FillOrigin: 0
  1444 + m_UseSpriteMesh: 0
  1445 + m_PixelsPerUnitMultiplier: 1
1370 --- !u!1 &4531716383457095180 1446 --- !u!1 &4531716383457095180
1371 GameObject: 1447 GameObject:
1372 m_ObjectHideFlags: 0 1448 m_ObjectHideFlags: 0