两个列表进骑行释放内存
This commit is contained in:
parent
3295314b7e
commit
6a4390f1b9
@ -15,7 +15,7 @@ using System.Timers;
|
||||
|
||||
public static class App
|
||||
{
|
||||
public static string Host = "http://192.168.0.101:5085/";
|
||||
public static string Host = "http://192.168.0.101:5084/";
|
||||
|
||||
public static string AppVersion = Application.version;
|
||||
|
||||
@ -111,7 +111,7 @@ public static class App
|
||||
Host = "https://wx.powerfun.com.cn/";
|
||||
UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11000);
|
||||
TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11001);
|
||||
Debug.unityLogger.logEnabled = false;
|
||||
//Debug.unityLogger.logEnabled = false;
|
||||
#endif
|
||||
var isRower = PlayerPrefs.GetString("IsRowerMode");
|
||||
if (!string.IsNullOrEmpty(isRower))
|
||||
|
||||
@ -43,8 +43,13 @@ public class MapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler,
|
||||
}
|
||||
float? localY = null;
|
||||
MapRoute map;
|
||||
public void Initial(MapRoute myMap)
|
||||
Dictionary<string, Texture> caches;
|
||||
public void Initial(MapRoute myMap, Dictionary<string, Texture> caches)
|
||||
{
|
||||
if (caches != null)
|
||||
{
|
||||
this.caches = caches;
|
||||
}
|
||||
map = myMap;
|
||||
//localY = transform.GetComponent<RectTransform>().rect.height;
|
||||
//Debug.Log(localY);
|
||||
@ -122,8 +127,8 @@ public class MapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler,
|
||||
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
||||
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
||||
|
||||
Utils.DisplayImage(transform.Find("MapTitleImg").GetComponent<RawImage>(), myMap.CoverImage, true);
|
||||
Utils.DisplayImage(transform.Find("MapHBImg").GetComponent<RawImage>(), myMap.AltitudeGraph, true);
|
||||
Utils.DisplayImageTempDict(transform.Find("MapTitleImg").GetComponent<RawImage>(), myMap.CoverImage, this.caches);
|
||||
Utils.DisplayImageTempDict(transform.Find("MapHBImg").GetComponent<RawImage>(), myMap.AltitudeGraph, this.caches);
|
||||
|
||||
SetActive4Button(false);
|
||||
}
|
||||
@ -140,11 +145,11 @@ public class MapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler,
|
||||
App.MainSceneParam["Name"] = "MapListPanel";
|
||||
}
|
||||
SceneManager.LoadScene("Ride");
|
||||
foreach (var item in Utils.propTextureCache)
|
||||
{
|
||||
DestroyImmediate(item.Value);
|
||||
}
|
||||
Utils.propTextureCache.Clear();
|
||||
//foreach (var item in Utils.propTextureCache)
|
||||
//{
|
||||
// DestroyImmediate(item.Value);
|
||||
//}
|
||||
//Utils.propTextureCache.Clear();
|
||||
}
|
||||
|
||||
private void Info()
|
||||
@ -262,7 +267,7 @@ public class MapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler,
|
||||
AltitudeGraph = model.AltitudeGraph,
|
||||
Distance = model.Distance,
|
||||
IsFavorite = model.IsFavorite,
|
||||
});
|
||||
},null);
|
||||
}
|
||||
|
||||
public void Move(Vector3 position)
|
||||
|
||||
@ -262,6 +262,7 @@ public class MapListController : PFUIPanel
|
||||
});
|
||||
//sortDir.GetComponent<Button>().onClick.AddListener();
|
||||
}
|
||||
caches = new Dictionary<string, Texture>();
|
||||
}
|
||||
void onEndEdit()
|
||||
{
|
||||
@ -354,6 +355,7 @@ public class MapListController : PFUIPanel
|
||||
}
|
||||
|
||||
}
|
||||
Dictionary<string, Texture> caches = null;
|
||||
void DisplayMaps(List<MapRoute> list)
|
||||
{
|
||||
if (map != null)
|
||||
@ -361,7 +363,7 @@ public class MapListController : PFUIPanel
|
||||
foreach (var item in list)
|
||||
{
|
||||
var obj = Instantiate(map);
|
||||
obj.GetComponent<MapItem>().Initial(item);
|
||||
obj.GetComponent<MapItem>().Initial(item, caches);
|
||||
//obj.SendMessage("Initial", );
|
||||
obj.transform.SetParent(content.transform);
|
||||
obj.transform.localScale = new Vector3(1, 1, 1);
|
||||
@ -468,4 +470,12 @@ public class MapListController : PFUIPanel
|
||||
ResetPanel();
|
||||
transform.MyDOFade();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
caches = null;
|
||||
Resources.UnloadUnusedAssets();
|
||||
GC.Collect();
|
||||
Debug.Log("list empty");
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,10 @@ public class RaceItemScript : MonoBehaviour, IPointerExitHandler, IPointerEnterH
|
||||
}
|
||||
public void Initial(MapCompetition mapCompetition,Transform parent,string from = "list")
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
transform.GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
transform.GetComponent<Button>().onClick.AddListener(() =>
|
||||
@ -48,7 +52,7 @@ public class RaceItemScript : MonoBehaviour, IPointerExitHandler, IPointerEnterH
|
||||
App.CompetionId = mapCompetition.Id;
|
||||
SceneManager.LoadScene("Ride");
|
||||
});
|
||||
Utils.DisplayImage(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, true);
|
||||
Utils.DisplayImageTempDict(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, this.parent.GetComponent<RaceScript>().caches);
|
||||
#else
|
||||
if (string.IsNullOrEmpty(_from))
|
||||
{
|
||||
@ -56,14 +60,14 @@ public class RaceItemScript : MonoBehaviour, IPointerExitHandler, IPointerEnterH
|
||||
}
|
||||
if (_from == "list")
|
||||
{
|
||||
Utils.DisplayImage(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, true);
|
||||
Utils.DisplayImageTempDict(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, this.parent.GetComponent<RaceScript>().caches);
|
||||
transform.GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
UIManager.ShowRaceDetailModal(transform,mapCompetition);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
Utils.DisplayImage(transform.Find("AltitudeCurve").GetComponent<RawImage>(), mapCompetition.AltitudeGraph, true);
|
||||
Utils.DisplayImageTempDict(transform.Find("AltitudeCurve").GetComponent<RawImage>(), mapCompetition.AltitudeGraph, this.parent.GetComponent<RaceScript>().caches);
|
||||
transform.Find("InfoContainer/Text").GetComponent<Text>().SetTextWithEllipsis(mapCompetition.Title);
|
||||
transform.Find("GetReadyContainer").gameObject.SetActive(mapCompetition.Status != 4);
|
||||
transform.Find("GetReadyContainer-2").gameObject.SetActive(mapCompetition.Status == 1);
|
||||
@ -91,10 +95,7 @@ public class RaceItemScript : MonoBehaviour, IPointerExitHandler, IPointerEnterH
|
||||
SetButtonGroup(mapCompetition);
|
||||
}
|
||||
#endif
|
||||
if (parent != null)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
this.mapCompetition = mapCompetition;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Assets.Scripts;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -10,6 +11,8 @@ public class RaceScript : PFUIPanel
|
||||
// Start is called before the first frame update
|
||||
protected Transform currentItem { get; set; }
|
||||
IEnumerator _timer { get; set; }
|
||||
public Dictionary<string, Texture> caches { get; set; }
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
@ -71,7 +74,6 @@ public class RaceScript : PFUIPanel
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForSeconds(1.0f); //
|
||||
Debug.Log(123);
|
||||
HandleTime();
|
||||
//time = UIManager.Now.GetDateTime().AddSeconds(1);
|
||||
}
|
||||
@ -138,8 +140,10 @@ public class RaceScript : PFUIPanel
|
||||
}
|
||||
}
|
||||
|
||||
void Awake()
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
caches = new Dictionary<string, Texture>();
|
||||
if (_timer == null)
|
||||
{
|
||||
_timer = Timer();
|
||||
@ -151,4 +155,12 @@ public class RaceScript : PFUIPanel
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
caches = null;
|
||||
Resources.UnloadUnusedAssets();
|
||||
GC.Collect();
|
||||
Debug.Log("list empty");
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ namespace Assets.Scripts
|
||||
/*显示网络图片*/
|
||||
public static Dictionary<string, Texture> propTextureCache = new Dictionary<string, Texture>();
|
||||
public delegate Coroutine StartCoroutine(IEnumerator routine);
|
||||
public static void DisplayImage(RawImage img, string url, bool cache = false)
|
||||
public static void DisplayImage(RawImage img, string url, bool cache = false,Dictionary<string,Texture> caches = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
return;
|
||||
@ -332,12 +332,38 @@ namespace Assets.Scripts
|
||||
}
|
||||
}
|
||||
UIManager.Instance.StartCoroutine(DownloadImage(img, url,(texture)=> {
|
||||
if (cache && !propTextureCache.ContainsKey(url))
|
||||
{
|
||||
propTextureCache.Add(url, texture);
|
||||
}
|
||||
//if (cache && !propTextureCache.ContainsKey(url))
|
||||
//{
|
||||
// propTextureCache.Add(url, texture);
|
||||
//}
|
||||
}));
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 使用临时字典存放图片,切换页面后清除
|
||||
/// </summary>
|
||||
/// <param name="img"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="caches"></param>
|
||||
public static void DisplayImageTempDict(RawImage img, string url, Dictionary<string, Texture> caches = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
return;
|
||||
if (caches!=null)
|
||||
{
|
||||
if (caches.ContainsKey(url))
|
||||
{
|
||||
img.texture = caches[url];
|
||||
return;
|
||||
}
|
||||
}
|
||||
UIManager.Instance.StartCoroutine(DownloadImage(img, url, (texture) => {
|
||||
if (caches != null && !caches.ContainsKey(url))
|
||||
{
|
||||
caches.Add(url, texture);
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
public static void DisplayImageAysnc(StartCoroutine startCoroutine, RawImage img, string url,Action<string> action)
|
||||
@ -349,13 +375,15 @@ namespace Assets.Scripts
|
||||
|
||||
static IEnumerator DownloadImage(RawImage img,string MediaUrl, Action<Texture> action = null)
|
||||
{
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl,true);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.isNetworkError || request.isHttpError)
|
||||
Debug.Log(request.error);
|
||||
else if(img!=null)
|
||||
{
|
||||
img.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
|
||||
var _t = ((DownloadHandlerTexture)request.downloadHandler).texture;
|
||||
_t.name = MediaUrl;
|
||||
img.texture = _t;
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(img.texture);
|
||||
@ -365,7 +393,7 @@ namespace Assets.Scripts
|
||||
|
||||
static IEnumerator DownloadImageCallBack(RawImage img, string MediaUrl,Action<string> action)
|
||||
{
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl, true);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.isNetworkError || request.isHttpError)
|
||||
Debug.Log(request.error);
|
||||
|
||||
@ -179,7 +179,7 @@ PlayerSettings:
|
||||
applicationIdentifier:
|
||||
Android: com.ZhiXingPai.PowerFunUnity
|
||||
buildNumber:
|
||||
iPhone: 2.0.5.0
|
||||
iPhone: 2.0.6.2
|
||||
AndroidBundleVersionCode: 8
|
||||
AndroidMinSdkVersion: 24
|
||||
AndroidTargetSdkVersion: 30
|
||||
@ -256,7 +256,7 @@ PlayerSettings:
|
||||
clonedFromGUID: c0afd0d1d80e3634a9dac47e8a0426ea
|
||||
templatePackageId: com.unity.template.3d@4.2.8
|
||||
templateDefaultScene: Assets/Scenes/SampleScene.unity
|
||||
AndroidTargetArchitectures: 3
|
||||
AndroidTargetArchitectures: 1
|
||||
AndroidSplashScreenScale: 0
|
||||
androidSplashScreen: {fileID: 0}
|
||||
AndroidKeystoreName: '{inproject}: Assets/Plugins/Android/powerfun.keystore'
|
||||
@ -868,7 +868,7 @@ PlayerSettings:
|
||||
platformArchitecture:
|
||||
iPhone: 1
|
||||
scriptingBackend:
|
||||
Android: 1
|
||||
Android: 0
|
||||
Standalone: 0
|
||||
il2cppCompilerConfiguration:
|
||||
Standalone: 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user