两个列表进骑行释放内存

This commit is contained in:
Caiyanpeng committed 2021-11-16 18:41:18 +08:00
1 parent 3295314b7e
commit 6a4390f1b9
7 files changed
+88 -32

No files matched your search

+14 -9
View File
@@ -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;
}
+14 -2
View File
@@ -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");
}
}