From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/PartLoadTask.cs | 297 ++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/PartLoadTask.cs (limited to 'Client/Assets/Scripts/XMainClient/PartLoadTask.cs') diff --git a/Client/Assets/Scripts/XMainClient/PartLoadTask.cs b/Client/Assets/Scripts/XMainClient/PartLoadTask.cs new file mode 100644 index 00000000..8270b6de --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/PartLoadTask.cs @@ -0,0 +1,297 @@ +using System; +using System.Collections.Generic; +using KKSG; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class PartLoadTask : EquipLoadTask + { + private string replaceMeshLocation = null; + + private string replaceTexLocation = null; + + public byte partType = 0; + + public Mesh mesh = null; + + private Texture2D tex = null; + + private Texture2D aplhaTex = null; + + private byte loadState = 0; + + private static PartLoadTask.MeshPart fakeMeshPart = new PartLoadTask.MeshPart(); + + private static PartLoadTask.TexPart fakeTexPart = new PartLoadTask.TexPart(); + + private static PartLoadTask.AlphaTexPart fakeAlphaTexPart = new PartLoadTask.AlphaTexPart(); + + private LoadAsyncTask meshLoadTask = null; + + private LoadAsyncTask texLoadTask = null; + + private LoadAsyncTask alphaLoadTask = null; + + private LoadCallBack loadCb = null; + + private PartLoadCallback m_PartLoadCb = null; + + private class MeshPart + { + } + + private class TexPart + { + } + + private class AlphaTexPart + { + } + + public PartLoadTask(EPartType p, PartLoadCallback partLoadCb) : base(p) + { + this.loadCb = new LoadCallBack(this.LoadFinish); + this.m_PartLoadCb = partLoadCb; + } + + public override void Load(XEntity e, int prefessionID, ref FashionPositionInfo newFpi, bool async, HashSet loadedPath) + { + bool flag = base.IsSamePart(ref newFpi); + if (flag) + { + bool flag2 = this.m_PartLoadCb != null; + if (flag2) + { + this.m_PartLoadCb(this, false); + } + } + else + { + this.Reset(e); + bool flag3 = base.MakePath(ref newFpi, loadedPath); + if (flag3) + { + this.replaceMeshLocation = null; + this.replaceTexLocation = null; + bool meshInfo = XEquipDocument._MeshPartList.GetMeshInfo(this.location, prefessionID, (int)this.part, newFpi.fashionDir, out this.partType, ref this.replaceMeshLocation, ref this.replaceTexLocation); + if (meshInfo) + { + if (async) + { + bool flag4 = this.replaceMeshLocation != null; + if (flag4) + { + this.meshLoadTask = XSingleton.singleton.GetShareResourceAsync(this.replaceMeshLocation, ".asset", this.loadCb, PartLoadTask.fakeMeshPart); + } + else + { + this.meshLoadTask = XSingleton.singleton.GetShareResourceAsync(this.location, ".asset", this.loadCb, PartLoadTask.fakeMeshPart); + } + bool flag5 = this.replaceTexLocation != null; + if (flag5) + { + this.texLoadTask = XSingleton.singleton.GetShareResourceAsync(this.replaceTexLocation, ".tga", this.loadCb, PartLoadTask.fakeTexPart); + bool flag6 = this.partType == XMeshPartList.CutoutPart; + if (flag6) + { + this.alphaLoadTask = XSingleton.singleton.GetShareResourceAsync(this.replaceTexLocation + "_A", ".png", this.loadCb, PartLoadTask.fakeAlphaTexPart); + } + } + else + { + this.texLoadTask = XSingleton.singleton.GetShareResourceAsync(this.location, ".tga", this.loadCb, PartLoadTask.fakeTexPart); + bool flag7 = this.partType == XMeshPartList.CutoutPart; + if (flag7) + { + this.alphaLoadTask = XSingleton.singleton.GetShareResourceAsync(this.location + "_A", ".png", this.loadCb, PartLoadTask.fakeAlphaTexPart); + } + } + } + else + { + bool flag8 = this.replaceMeshLocation != null; + Mesh sharedResource; + if (flag8) + { + sharedResource = XSingleton.singleton.GetSharedResource(this.replaceMeshLocation, ".asset", true, false); + } + else + { + sharedResource = XSingleton.singleton.GetSharedResource(this.location, ".asset", true, false); + } + this.LoadFinish(sharedResource, PartLoadTask.fakeMeshPart); + bool flag9 = this.replaceTexLocation != null; + if (flag9) + { + Texture2D sharedResource2 = XSingleton.singleton.GetSharedResource(this.replaceTexLocation, ".tga", true, false); + this.LoadFinish(sharedResource2, PartLoadTask.fakeTexPart); + bool flag10 = this.partType == XMeshPartList.CutoutPart; + if (flag10) + { + Texture2D sharedResource3 = XSingleton.singleton.GetSharedResource(this.replaceTexLocation + "_A", ".png", true, false); + this.LoadFinish(sharedResource3, PartLoadTask.fakeAlphaTexPart); + } + } + else + { + Texture2D sharedResource4 = XSingleton.singleton.GetSharedResource(this.location, ".tga", true, false); + this.LoadFinish(sharedResource4, PartLoadTask.fakeTexPart); + bool flag11 = this.partType == XMeshPartList.CutoutPart; + if (flag11) + { + Texture2D sharedResource5 = XSingleton.singleton.GetSharedResource(this.location + "_A", ".png", true, false); + this.LoadFinish(sharedResource5, PartLoadTask.fakeAlphaTexPart); + } + } + } + } + else + { + this.processStatus = EProcessStatus.EPreProcess; + bool flag12 = this.m_PartLoadCb != null; + if (flag12) + { + this.m_PartLoadCb(this, true); + } + } + } + else + { + bool flag13 = this.m_PartLoadCb != null; + if (flag13) + { + this.m_PartLoadCb(this, true); + } + } + } + } + + private void LoadFinish(UnityEngine.Object obj, object cbOjb) + { + bool flag = this.processStatus == EProcessStatus.EProcessing; + if (flag) + { + bool flag2 = cbOjb is PartLoadTask.MeshPart; + if (flag2) + { + this.mesh = (obj as Mesh); + this.loadState |= 1; + this.meshLoadTask = null; + } + else + { + bool flag3 = cbOjb is PartLoadTask.TexPart; + if (flag3) + { + Texture2D texture2D = obj as Texture2D; + this.tex = texture2D; + this.texLoadTask = null; + this.loadState |= 2; + } + else + { + bool flag4 = cbOjb is PartLoadTask.AlphaTexPart; + if (flag4) + { + Texture2D texture2D2 = obj as Texture2D; + this.aplhaTex = texture2D2; + this.alphaLoadTask = null; + this.loadState |= 4; + } + else + { + XSingleton.singleton.AddErrorLog("assert error equip type", null, null, null, null, null); + } + } + } + bool flag5 = XMeshPartList.ConvertType(this.partType) == this.loadState; + if (flag5) + { + this.processStatus = EProcessStatus.EPreProcess; + bool flag6 = this.m_PartLoadCb != null; + if (flag6) + { + this.m_PartLoadCb(this, true); + } + } + } + } + + public override void Reset(XEntity e) + { + bool flag = this.mesh != null; + if (flag) + { + bool flag2 = !string.IsNullOrEmpty(this.replaceMeshLocation); + if (flag2) + { + XSingleton.singleton.UnSafeDestroyShareResource(this.replaceMeshLocation, ".asset", this.mesh, XSingleton.singleton.SceneType == SceneType.SCENE_HALL); + } + else + { + XSingleton.singleton.UnSafeDestroyShareResource(this.location, ".asset", this.mesh, XSingleton.singleton.SceneType == SceneType.SCENE_HALL); + } + this.mesh = null; + } + this.replaceMeshLocation = null; + bool flag3 = this.tex != null; + if (flag3) + { + bool flag4 = !string.IsNullOrEmpty(this.replaceTexLocation); + if (flag4) + { + XSingleton.singleton.UnSafeDestroyShareResource(this.replaceTexLocation, ".tga", this.tex, XSingleton.singleton.SceneType == SceneType.SCENE_HALL); + } + else + { + XSingleton.singleton.UnSafeDestroyShareResource(this.location, ".tga", this.tex, XSingleton.singleton.SceneType == SceneType.SCENE_HALL); + } + this.tex = null; + } + bool flag5 = this.aplhaTex != null; + if (flag5) + { + XSingleton.singleton.UnSafeDestroyShareResource(this.location + "_A", ".png", this.aplhaTex, XSingleton.singleton.SceneType == SceneType.SCENE_HALL); + this.aplhaTex = null; + } + this.replaceTexLocation = null; + this.loadState = 0; + bool flag6 = this.meshLoadTask != null; + if (flag6) + { + this.meshLoadTask.CancelLoad(this.loadCb); + this.meshLoadTask = null; + } + bool flag7 = this.texLoadTask != null; + if (flag7) + { + this.texLoadTask.CancelLoad(this.loadCb); + this.texLoadTask = null; + } + bool flag8 = this.alphaLoadTask != null; + if (flag8) + { + this.alphaLoadTask.CancelLoad(this.loadCb); + this.alphaLoadTask = null; + } + base.Reset(e); + } + + public bool HasMesh() + { + return this.mesh != null; + } + + public Texture2D GetTexture() + { + return this.tex; + } + + public Texture2D GetAlpha() + { + return this.aplhaTex; + } + } +} -- cgit v1.1-26-g67d0