fix:1、添加项目
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
|
||||
using FlowerPower;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class AnimationCurveData : ScriptableObject
|
||||
{
|
||||
private static AnimationCurveData instance;
|
||||
|
||||
public static AnimationCurveData Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = LoadKit.Instance.LoadAsset<AnimationCurveData>("Data.ScriptableObjectData",
|
||||
"AnimationCurveData");
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public AnimationCurve LuckySpinAniCurve;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0a921ff368c47588249df420aa52091
|
||||
timeCreated: 1704964086
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace FutureCore
|
||||
{
|
||||
public static class Base64EncodeUtil
|
||||
{
|
||||
public static string Base64Encode(string source)
|
||||
{
|
||||
return Base64Encode(Encoding.UTF8, source);
|
||||
}
|
||||
|
||||
public static string Base64Decode(string result)
|
||||
{
|
||||
return Base64Decode(Encoding.UTF8, result);
|
||||
}
|
||||
|
||||
public static string Base64Encode(Encoding encoding, string source)
|
||||
{
|
||||
byte[] bytes = encoding.GetBytes(source);
|
||||
string encode = Convert.ToBase64String(bytes);
|
||||
return encode;
|
||||
}
|
||||
|
||||
public static string Base64Decode(Encoding encoding, string result)
|
||||
{
|
||||
byte[] bytes = Convert.FromBase64String(result);
|
||||
string decode = encoding.GetString(bytes);
|
||||
return decode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cb6f0cfcd844347bfe34d48a1f77555
|
||||
timeCreated: 1693215248
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using DG.Tweening;
|
||||
using FairyGUI;
|
||||
using FlowerPower;
|
||||
|
||||
|
||||
public static class CommonExpand
|
||||
{
|
||||
public static GTweener FadeIn(this GObject obj, float duration = 0.3f, float delay = 0)
|
||||
{
|
||||
return CommonHelper.FadeIn(obj, duration, delay);
|
||||
}
|
||||
|
||||
public static GTweener FadeOut(this GObject obj, float duration = 0.3f, float delay = 0)
|
||||
{
|
||||
return CommonHelper.FadeOut(obj, duration, delay);
|
||||
}
|
||||
|
||||
public static void SetClick(this GObject button, Action action, bool isNetworkCheck = false,
|
||||
bool isQuickClickCheck = true)
|
||||
{
|
||||
CommonHelper.InitGButton(button, action, isNetworkCheck, isQuickClickCheck);
|
||||
}
|
||||
|
||||
public static void SafeKill(this Tween tween)
|
||||
{
|
||||
if (tween != null && tween.IsActive())
|
||||
{
|
||||
tween.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 774c7c1119b44f86819883ab6e9240ec
|
||||
timeCreated: 1681803724
|
||||
@@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using FairyGUI;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace FlowerPower
|
||||
{
|
||||
public enum CountDownType
|
||||
{
|
||||
Second,
|
||||
Minute,
|
||||
Hour,
|
||||
Day
|
||||
}
|
||||
|
||||
public class CountDownKit
|
||||
{
|
||||
private int countDownTime;
|
||||
private int leftTime = 0;
|
||||
private GTextField textGComponent;
|
||||
private GProgressBar barGComponent;
|
||||
private Text textComponent;
|
||||
private CountDownType countDownType = CountDownType.Second;
|
||||
private Dictionary<int, Action> onTriggerEventDict = new Dictionary<int, Action>();
|
||||
private Tween timer;
|
||||
private Action onCompletedEvent;
|
||||
private long endTime;
|
||||
private bool isDependenceServerTime = true;
|
||||
|
||||
public CountDownKit SetTime(int second)
|
||||
{
|
||||
countDownTime = second;
|
||||
leftTime = countDownTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CountDownKit SetCountDownType(CountDownType countDownType)
|
||||
{
|
||||
this.countDownType = countDownType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CountDownKit SetText(GTextField gText)
|
||||
{
|
||||
textComponent = null;
|
||||
textGComponent = gText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CountDownKit SetBar(GProgressBar gProgressBar)
|
||||
{
|
||||
barGComponent = null;
|
||||
barGComponent = gProgressBar;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int interval = 1;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
endTime = (int)(DateTimeManager.Instance.GetServerCurrTimestamp() / 1000) + leftTime;
|
||||
UpdateView();
|
||||
timer = DOVirtual.DelayedCall(interval, () =>
|
||||
{
|
||||
leftTime -= interval;
|
||||
if (isDependenceServerTime)
|
||||
{
|
||||
var current = DateTimeManager.Instance.GetServerCurrTimestamp() / 1000;
|
||||
if (endTime <= current)
|
||||
{
|
||||
leftTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateView();
|
||||
if (leftTime <= 0)
|
||||
{
|
||||
Stop();
|
||||
OnCompleted();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnTrigger();
|
||||
}
|
||||
}, true).SetLoops(-1);
|
||||
}
|
||||
|
||||
private void UpdateView()
|
||||
{
|
||||
UpdateText();
|
||||
UpdateBar();
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (timer != null)
|
||||
{
|
||||
timer.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
if (timer != null)
|
||||
{
|
||||
timer.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (timer != null && timer.IsActive())
|
||||
{
|
||||
timer?.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
Stop();
|
||||
leftTime = 0;
|
||||
|
||||
textGComponent = null;
|
||||
|
||||
textComponent = null;
|
||||
onTriggerEventDict = null;
|
||||
onCompletedEvent = null;
|
||||
}
|
||||
|
||||
public void ConsumeTime(int consumeTime)
|
||||
{
|
||||
leftTime -= consumeTime;
|
||||
UpdateView();
|
||||
if (leftTime <= 0)
|
||||
{
|
||||
Stop();
|
||||
OnCompleted();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrigger()
|
||||
{
|
||||
if (onTriggerEventDict.ContainsKey(leftTime))
|
||||
{
|
||||
onTriggerEventDict[leftTime]?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearTriggerEvent()
|
||||
{
|
||||
onTriggerEventDict.Clear();
|
||||
}
|
||||
|
||||
public CountDownKit SetCompletedEvent(Action onCompleted)
|
||||
{
|
||||
onCompletedEvent = onCompleted;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void OnCompleted()
|
||||
{
|
||||
onCompletedEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void UpdateText()
|
||||
{
|
||||
if (textGComponent != null)
|
||||
{
|
||||
textGComponent.text = CommonHelper.TimeFormat(leftTime, countDownType);
|
||||
}
|
||||
|
||||
if (textComponent != null)
|
||||
{
|
||||
textComponent.text = CommonHelper.TimeFormat(leftTime, countDownType);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBar()
|
||||
{
|
||||
if (barGComponent != null)
|
||||
{
|
||||
if (barGComponent.max == 0)
|
||||
{
|
||||
barGComponent.max = countDownTime;
|
||||
}
|
||||
|
||||
barGComponent.TweenValue(leftTime, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetLeftTime()
|
||||
{
|
||||
return leftTime;
|
||||
}
|
||||
|
||||
public CountDownKit SetServerTimeDependence(bool _isDependenceServerTime)
|
||||
{
|
||||
isDependenceServerTime = _isDependenceServerTime;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34ed4a143324499ab1864f3c64019e16
|
||||
timeCreated: 1681804392
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FlowerPower
|
||||
{
|
||||
public static class GemCrushConstant
|
||||
{
|
||||
public const string croas = "Assets/GemCrushAssets/";
|
||||
public const string setbun = ".assetbundle";
|
||||
public static readonly string tbund = $"{Application.dataPath}/../AssetBundle/{undles}";
|
||||
public static readonly string fgklpk = "|";
|
||||
public const string undles = "AssetBundles";
|
||||
public const string nifest = ".manifest";
|
||||
public static readonly string lesest = $"{undles}{nifest}";
|
||||
public const string zyzootx = "GemCrushFile.txt";
|
||||
public const string nifldg = "[ GemCrush ]";
|
||||
public const string admsie = "4s2f6ac15sa6ds45";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73ce1d7d9d7bd5245878994917b71208
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,205 @@
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace FlowerPower
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public delegate void onLoaded(AssetBundle param);
|
||||
|
||||
public class GemCrushInfo
|
||||
{
|
||||
public string assetBundleName;
|
||||
|
||||
public List<string> parentABNameList = new();
|
||||
|
||||
public long assetBundleSize;
|
||||
|
||||
|
||||
public AssetBundle assetBundle { get; internal set; }
|
||||
|
||||
public GemCrushState assetBundleState;
|
||||
|
||||
public onLoaded ONLoaded;
|
||||
|
||||
public long waitUnloadCurrentTime;
|
||||
|
||||
public Action<Action<bool>> unloadAction;
|
||||
|
||||
public Action<bool> unloadCompletedAction;
|
||||
|
||||
public int waitUnloadTime;
|
||||
|
||||
|
||||
public static List<string> StatisticsCacheAssetList = new List<string>();
|
||||
|
||||
|
||||
private static bool isStatisticsCacheAssetList = false;
|
||||
|
||||
|
||||
public int ReferencedCount { get; set; }
|
||||
|
||||
|
||||
public float LastReferencedTimestamp { get; set; }
|
||||
|
||||
public GemCrushInfo(string assetBundleName, UnityAction<AssetBundle> onCompletedLoaded)
|
||||
{
|
||||
this.assetBundleName = assetBundleName;
|
||||
assetBundleState = GemCrushState.STATE_LOADING;
|
||||
Referenced(assetBundleName);
|
||||
LastReferencedTimestamp = Time.realtimeSinceStartup;
|
||||
if (onCompletedLoaded != null)
|
||||
{
|
||||
ONLoaded += a => onCompletedLoaded(a);
|
||||
}
|
||||
}
|
||||
|
||||
#region 引用关系
|
||||
|
||||
public int GetReferenced()
|
||||
{
|
||||
return ReferencedCount;
|
||||
}
|
||||
|
||||
|
||||
public void Referenced(string parentAbName)
|
||||
{
|
||||
parentAbName = parentAbName.ToLower();
|
||||
if (!parentABNameList.Contains(parentAbName))
|
||||
{
|
||||
ReferencedCount++;
|
||||
parentABNameList.Add(parentAbName);
|
||||
#if UNITY_EDITOR
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void UnReferenced(string parentAbName)
|
||||
{
|
||||
if (parentABNameList.Contains(parentAbName))
|
||||
{
|
||||
ReferencedCount--;
|
||||
parentABNameList.Remove(parentAbName);
|
||||
#if UNITY_EDITOR
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanReferenced()
|
||||
{
|
||||
ReferencedCount = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void callRes(string parentAbName, UnityAction<AssetBundle> action)
|
||||
{
|
||||
switch (assetBundleState)
|
||||
{
|
||||
case GemCrushState.STATE_NONE:
|
||||
break;
|
||||
case GemCrushState.STATE_LOADING:
|
||||
ONLoaded += a => { action(a); };
|
||||
break;
|
||||
case GemCrushState.STATE_LOADED:
|
||||
Referenced(parentAbName);
|
||||
action(this.assetBundle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onLoaded(string parentAbName, AssetBundle assetBundle)
|
||||
{
|
||||
Referenced(parentAbName);
|
||||
this.assetBundle = assetBundle;
|
||||
this.assetBundleState = GemCrushState.STATE_LOADED;
|
||||
ONLoaded(assetBundle);
|
||||
ONLoaded = null;
|
||||
OnAddtStatisticsCacheAssetList(assetBundle.name);
|
||||
}
|
||||
|
||||
public void Unload(bool isThorough)
|
||||
{
|
||||
CleanReferenced();
|
||||
if (assetBundle != null)
|
||||
assetBundle.Unload(isThorough);
|
||||
assetBundle = null;
|
||||
}
|
||||
|
||||
|
||||
private void OnAddtStatisticsCacheAssetList(string assetBundleName)
|
||||
{
|
||||
if (!isStatisticsCacheAssetList) return;
|
||||
if (!StatisticsCacheAssetList.Contains(assetBundleName))
|
||||
{
|
||||
StatisticsCacheAssetList.Add(assetBundleName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void OnStartStatisticsCacheAssetList()
|
||||
{
|
||||
isStatisticsCacheAssetList = true;
|
||||
StatisticsCacheAssetList.Clear();
|
||||
}
|
||||
|
||||
|
||||
public static string[] OnStopStatisticsCacheAssetList()
|
||||
{
|
||||
isStatisticsCacheAssetList = false;
|
||||
string[] tempList = StatisticsCacheAssetList.GetRange(0, StatisticsCacheAssetList.Count).ToArray();
|
||||
StatisticsCacheAssetList.Clear();
|
||||
return tempList;
|
||||
}
|
||||
|
||||
|
||||
public void UpdateWaitUnloadCurrentTime()
|
||||
{
|
||||
waitUnloadCurrentTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
|
||||
public long GetWaitUpdateTimeTD()
|
||||
{
|
||||
var tempTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
|
||||
return tempTime - waitUnloadCurrentTime;
|
||||
}
|
||||
|
||||
public void SetUnloadAction(Action<Action<bool>> action, Action<bool> onCompletedAction)
|
||||
{
|
||||
this.unloadAction = action;
|
||||
this.unloadCompletedAction = onCompletedAction;
|
||||
}
|
||||
|
||||
public void InvokeUnloadAction()
|
||||
{
|
||||
unloadAction?.Invoke(unloadCompletedAction);
|
||||
}
|
||||
|
||||
public void SetWaitUnloadTime(int time)
|
||||
{
|
||||
waitUnloadTime = time;
|
||||
}
|
||||
|
||||
public int GetWaitUnloadTime()
|
||||
{
|
||||
return waitUnloadTime;
|
||||
}
|
||||
|
||||
public void SetAssetBundleSize(long size)
|
||||
{
|
||||
if (size > 0)
|
||||
{
|
||||
assetBundleSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
public long GetSize()
|
||||
{
|
||||
return assetBundleSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f8e1bf1569620a45ba3a117072e9b57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,853 @@
|
||||
namespace FlowerPower
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.Events;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Object = UnityEngine.Object;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
public class GemCrushKit : Singleton<GemCrushKit>, ILoadAsset
|
||||
{
|
||||
private const bool IsMD5Encrypt = false;
|
||||
|
||||
|
||||
private string _assetBundleRootPath = GemCrushFileKit.GetFilePath();
|
||||
|
||||
|
||||
private static readonly Dictionary<string, GemCrushInfo> _cacheAssetBundleInfoDict =
|
||||
new Dictionary<string, GemCrushInfo>();
|
||||
|
||||
|
||||
private static readonly Dictionary<string, string[]> _cacheDependencyDict = new Dictionary<string, string[]>();
|
||||
|
||||
private static readonly List<GemCrushInfo> _waitUnloadList = new List<GemCrushInfo>();
|
||||
|
||||
private static AssetBundleManifest _manifest;
|
||||
|
||||
private static readonly Dictionary<string, string> decryptAssetBundleDict = new Dictionary<string, string>();
|
||||
|
||||
|
||||
private const int UnloadWaitTime = 30;
|
||||
|
||||
#region 加载AssetBundle的基础方法
|
||||
|
||||
public IEnumerator LoadABFromFileAsync(string assetBundlePath, string bundlePassword,
|
||||
UnityAction<AssetBundle> onCompleted)
|
||||
{
|
||||
yield return LoadDecryptAssetBundle(assetBundlePath, bundlePassword, onCompleted);
|
||||
}
|
||||
|
||||
private IEnumerator LoadDecryptAssetBundle(string assetBundlePath, string bundlePassword,
|
||||
UnityAction<AssetBundle> onCompleted)
|
||||
{
|
||||
string decryptPath;
|
||||
if (decryptAssetBundleDict.TryGetValue(assetBundlePath, out var outPath) && File.Exists(outPath))
|
||||
{
|
||||
decryptPath = outPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
var cachePath1 = Path.Combine(UnityEngine.Application.persistentDataPath, "Jarvis");
|
||||
if (!Directory.Exists(cachePath1))
|
||||
{
|
||||
Directory.CreateDirectory(cachePath1);
|
||||
}
|
||||
|
||||
var cachePath = Path.Combine(cachePath1, $"decryptedBundle{Guid.NewGuid():N}");
|
||||
|
||||
|
||||
using (Stream stream1 = File.OpenWrite(cachePath))
|
||||
{
|
||||
var decryptedData = AESForFileKit.DecryptToBytes(assetBundlePath, bundlePassword, out var dataSize);
|
||||
yield return stream1.WriteAsync(decryptedData, 0, dataSize);
|
||||
}
|
||||
|
||||
decryptPath = cachePath;
|
||||
decryptAssetBundleDict.TryAdd(assetBundlePath, decryptPath);
|
||||
}
|
||||
|
||||
var request = AssetBundle.LoadFromFileAsync(decryptPath);
|
||||
yield return request;
|
||||
onCompleted?.Invoke(request.assetBundle);
|
||||
}
|
||||
|
||||
private AssetBundle LoadDecryptAssetBundleSync(string assetBundlePath, string bundlePassword)
|
||||
{
|
||||
string decryptPath;
|
||||
if (decryptAssetBundleDict.TryGetValue(assetBundlePath, out var outPath) && File.Exists(outPath))
|
||||
{
|
||||
decryptPath = outPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
var decryptedData = AESForFileKit.DecryptToBytes(assetBundlePath, bundlePassword, out var dataSize);
|
||||
var cachePath1 = Path.Combine(UnityEngine.Application.persistentDataPath, "Jarvis");
|
||||
if (!Directory.Exists(cachePath1))
|
||||
{
|
||||
Directory.CreateDirectory(cachePath1);
|
||||
}
|
||||
|
||||
var cachePath = Path.Combine(cachePath1, $"decryptedBundle{Guid.NewGuid():N}");
|
||||
while (File.Exists(cachePath))
|
||||
{
|
||||
File.Delete(cachePath);
|
||||
cachePath = Path.Combine(cachePath1, $"decryptedBundle{Guid.NewGuid():N}");
|
||||
}
|
||||
|
||||
using (Stream stream = File.OpenWrite(cachePath))
|
||||
{
|
||||
stream.Write(decryptedData, 0, dataSize);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
decryptPath = cachePath;
|
||||
decryptAssetBundleDict.TryAdd(assetBundlePath, decryptPath);
|
||||
}
|
||||
|
||||
var assetBundle = AssetBundle.LoadFromFile(decryptPath);
|
||||
return assetBundle;
|
||||
}
|
||||
|
||||
private IEnumerator LoadAssetFromAssetBundle<T>(AssetBundle assetBundle, string assetName,
|
||||
UnityAction<T> onLoadCompleted) where T : Object
|
||||
{
|
||||
T resultAsset = null;
|
||||
|
||||
if (typeof(T) == typeof(Sprite))
|
||||
{
|
||||
var texture2D = assetBundle.LoadAsset<Texture2D>(assetName);
|
||||
if (texture2D != null)
|
||||
{
|
||||
var sprite = Sprite.Create(texture2D,
|
||||
new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f));
|
||||
|
||||
resultAsset = sprite as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] assetNameArray = assetName.Split('.');
|
||||
if (assetNameArray.Length > 1)
|
||||
{
|
||||
var resultAsset1 = assetBundle.LoadAssetWithSubAssets<T>(assetNameArray[0]);
|
||||
resultAsset = Array.Find(resultAsset1, item => item.name == assetNameArray[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var assetLoadRequest = assetBundle.LoadAssetAsync<T>(assetName);
|
||||
yield return assetLoadRequest;
|
||||
var gameObject = assetLoadRequest.asset;
|
||||
if (gameObject == null)
|
||||
{
|
||||
var subAssetLoadRequest = assetBundle.LoadAssetWithSubAssetsAsync<T>(assetName);
|
||||
yield return subAssetLoadRequest;
|
||||
resultAsset = subAssetLoadRequest.asset as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
resultAsset = gameObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
onLoadCompleted?.Invoke(resultAsset);
|
||||
}
|
||||
|
||||
private void LoadAssetInternal(string assetBundleName, UnityAction<AssetBundle> onCompleted)
|
||||
{
|
||||
var assetBundlePath = GenerateAssetBundlePath(assetBundleName);
|
||||
|
||||
GetAssetBundle(assetBundlePath, assetBundleName, onCompleted);
|
||||
}
|
||||
|
||||
public AssetBundle GetAssetBundle(string assetBundlePath, string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
CrazyAsyKit.StopAction(assetBundleName + "Unload");
|
||||
UnWaitUnload(assetBundleName);
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
CacheDependency(assetBundleName, new[] { assetBundleName });
|
||||
|
||||
var GemCrushInfo = GetCacheAssetBundle(assetBundleName);
|
||||
return GemCrushInfo?.assetBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
var GemCrushInfo = new GemCrushInfo(assetBundleName, null);
|
||||
CacheAssetBundle(assetBundleName, GemCrushInfo);
|
||||
var isFileLoadType = File.Exists(assetBundlePath);
|
||||
if (isFileLoadType)
|
||||
{
|
||||
GetAssetBundleDependency(assetBundleName);
|
||||
var assetBundle =
|
||||
LoadDecryptAssetBundleSync(assetBundlePath, GemCrushConstant.admsie);
|
||||
GemCrushInfo.assetBundle = assetBundle;
|
||||
return assetBundle;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void GetAssetBundle(string assetBundlePath, string assetBundleName, UnityAction<AssetBundle> onCompleted)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
CrazyAsyKit.StopAction(assetBundleName + "Unload");
|
||||
UnWaitUnload(assetBundleName);
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
CacheDependency(assetBundleName, new[] { assetBundleName });
|
||||
|
||||
var GemCrushInfo = GetCacheAssetBundle(assetBundleName);
|
||||
GemCrushInfo?.callRes(assetBundleName, onCompleted);
|
||||
}
|
||||
else
|
||||
{
|
||||
var GemCrushInfo = new GemCrushInfo(assetBundleName, onCompleted);
|
||||
CacheAssetBundle(assetBundleName, GemCrushInfo);
|
||||
var isFileLoadType = File.Exists(assetBundlePath);
|
||||
CrazyAsyKit.StartCoroutine(GetAssetBundleDependency(assetBundleName, delegate
|
||||
{
|
||||
if (isFileLoadType)
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(LoadABFromFileAsync(assetBundlePath,
|
||||
GemCrushConstant.admsie, bundle =>
|
||||
{
|
||||
if (bundle == null)
|
||||
{
|
||||
Debug.LogError("加载AssetBundle 失败:" + assetBundleName);
|
||||
UnCacheAssetBundle(assetBundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GemCrushInfo abInfo = GetCacheAssetBundle(assetBundleName);
|
||||
#if UNITY_EDITOR
|
||||
FileInfo file = new FileInfo(assetBundlePath);
|
||||
|
||||
abInfo.SetAssetBundleSize(file.Length);
|
||||
#endif
|
||||
abInfo.onLoaded(assetBundleName, bundle);
|
||||
}
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(LoadABFromFileAsync(assetBundlePath,
|
||||
GemCrushConstant.admsie, delegate (AssetBundle bundle)
|
||||
{
|
||||
if (bundle == null)
|
||||
{
|
||||
Debug.LogError("加载AssetBundle 失败:" + assetBundleName);
|
||||
UnCacheAssetBundle(assetBundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var abInfoV = GetCacheAssetBundle(assetBundleName);
|
||||
var file = new FileInfo(assetBundlePath);
|
||||
abInfoV.SetAssetBundleSize(file.Length);
|
||||
abInfoV.onLoaded(assetBundleName, bundle);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
#region AssetBundle 包的依赖相关
|
||||
|
||||
private IEnumerator GetAssetBundleDependency(string assetBundleName, Action action)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
|
||||
var allDependencies = new List<string>() { assetBundleName };
|
||||
allDependencies.AddRange(GetABDependency(assetBundleName));
|
||||
var index = 0;
|
||||
CacheDependency(assetBundleName, allDependencies.ToArray());
|
||||
var allDepends = allDependencies.Where(dependencyAbName => dependencyAbName != assetBundleName).ToList();
|
||||
|
||||
foreach (var dependencyAbName in allDepends)
|
||||
{
|
||||
yield return LoadDependencyAssetBundle(assetBundleName, dependencyAbName, delegate { index++; });
|
||||
}
|
||||
|
||||
while (index != allDepends.Count)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
action?.Invoke();
|
||||
}
|
||||
|
||||
private void GetAssetBundleDependency(string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
|
||||
var allDependencies = new List<string>() { assetBundleName };
|
||||
allDependencies.AddRange(GetABDependency(assetBundleName));
|
||||
CacheDependency(assetBundleName, allDependencies.ToArray());
|
||||
var allDepends = allDependencies.Where(dependencyAbName => dependencyAbName != assetBundleName).ToList();
|
||||
|
||||
foreach (var dependencyAbName in allDepends)
|
||||
{
|
||||
LoadDependencyAssetBundleSync(assetBundleName, dependencyAbName);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator LoadDependencyAssetBundle(string parentAssetBundleName, string assetBundleName,
|
||||
UnityAction<AssetBundle> onCompleted)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
var assetBundlePath = GenerateAssetBundlePath(assetBundleName, IsMD5Encrypt);
|
||||
|
||||
CrazyAsyKit.StopAction(assetBundleName + "Unload");
|
||||
UnWaitUnload(assetBundleName);
|
||||
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
CacheAssetBundle(assetBundleName, null, true);
|
||||
var GemCrushInfo = GetCacheAssetBundle(assetBundleName);
|
||||
GemCrushInfo?.callRes(parentAssetBundleName, onCompleted);
|
||||
}
|
||||
else
|
||||
{
|
||||
var GemCrushInfo = new GemCrushInfo(assetBundleName, onCompleted);
|
||||
CacheAssetBundle(assetBundleName, GemCrushInfo);
|
||||
if (File.Exists(assetBundlePath))
|
||||
{
|
||||
yield return LoadABFromFileAsync(assetBundlePath, GemCrushConstant.admsie,
|
||||
delegate (AssetBundle bundle)
|
||||
{
|
||||
if (bundle == null)
|
||||
{
|
||||
Debug.LogError("加载AssetBundle 失败:" + assetBundleName);
|
||||
UnCacheAssetBundle(assetBundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCacheAssetBundle(assetBundleName).onLoaded(parentAssetBundleName, bundle);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(LoadABFromFileAsync(assetBundlePath,
|
||||
GemCrushConstant.admsie, delegate (AssetBundle bundle)
|
||||
{
|
||||
if (bundle == null)
|
||||
{
|
||||
Debug.LogError("加载AssetBundle 失败:" + assetBundleName);
|
||||
UnCacheAssetBundle(assetBundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCacheAssetBundle(assetBundleName).onLoaded(parentAssetBundleName, bundle);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AssetBundle LoadDependencyAssetBundleSync(string parentAssetBundleName, string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
var assetBundlePath = GenerateAssetBundlePath(assetBundleName, IsMD5Encrypt);
|
||||
CrazyAsyKit.StopAction(assetBundleName + "Unload");
|
||||
UnWaitUnload(assetBundleName);
|
||||
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
CacheAssetBundle(assetBundleName, null, true);
|
||||
var assetBundleInfos = GetCacheAssetBundle(assetBundleName);
|
||||
return assetBundleInfos?.assetBundle;
|
||||
}
|
||||
|
||||
var GemCrushInfo = new GemCrushInfo(assetBundleName, null);
|
||||
CacheAssetBundle(assetBundleName, GemCrushInfo);
|
||||
if (File.Exists(assetBundlePath))
|
||||
{
|
||||
GetAssetBundleDependency(assetBundleName);
|
||||
var assetBundle =
|
||||
LoadDecryptAssetBundleSync(assetBundlePath, GemCrushConstant.admsie);
|
||||
GemCrushInfo.assetBundle = assetBundle;
|
||||
return assetBundle;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private string[] GetABDependency(string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
return GetManifest().GetDirectDependencies(assetBundleName);
|
||||
}
|
||||
|
||||
#region 依赖关系相关
|
||||
|
||||
private bool IsCacheDependency(string assetBundleName)
|
||||
{
|
||||
if (_cacheDependencyDict == null || _cacheDependencyDict.Count == 0) return false;
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
var isDependency = _cacheDependencyDict.ContainsKey(assetBundleName);
|
||||
|
||||
return isDependency;
|
||||
}
|
||||
|
||||
|
||||
private bool IsOtherDependency(string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
var isDependency = false;
|
||||
if (_cacheDependencyDict == null || _cacheDependencyDict.Count == 0) return false;
|
||||
foreach (var keyValuePair in _cacheDependencyDict)
|
||||
{
|
||||
isDependency = keyValuePair.Value.Contains(assetBundleName);
|
||||
if (isDependency)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isDependency;
|
||||
}
|
||||
|
||||
private void CacheDependency(string assetBundleName, string[] assetBundleNameArray)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
if (!IsCacheDependency(assetBundleName))
|
||||
{
|
||||
for (int i = 0; i < assetBundleNameArray.Length; i++)
|
||||
{
|
||||
assetBundleNameArray[i] = assetBundleNameArray[i].ToLower();
|
||||
}
|
||||
|
||||
_cacheDependencyDict.Add(assetBundleName, assetBundleNameArray);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UnCacheDependency(string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
if (IsCacheDependency(assetBundleName))
|
||||
{
|
||||
_cacheDependencyDict.Remove(assetBundleName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string[] GetCacheDependency(string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
string[] dependencyList = { };
|
||||
if (IsCacheDependency(assetBundleName))
|
||||
{
|
||||
dependencyList = _cacheDependencyDict[assetBundleName];
|
||||
}
|
||||
|
||||
return dependencyList;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region 管理已加载的AssetBundle文件
|
||||
|
||||
private void CacheAssetBundle(string assetBundleName, GemCrushInfo assetBundleInfoV,
|
||||
bool isDependency = false)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
if (isDependency)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_cacheAssetBundleInfoDict.Add(assetBundleName, assetBundleInfoV);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UnCacheAssetBundle(string assetBundleName)
|
||||
{
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
_cacheAssetBundleInfoDict.Remove(assetBundleName.ToLower());
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private GemCrushInfo GetCacheAssetBundle(string assetBundleName)
|
||||
{
|
||||
GemCrushInfo assetBundle = null;
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
assetBundle = _cacheAssetBundleInfoDict[assetBundleName.ToLower()];
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return assetBundle;
|
||||
}
|
||||
|
||||
|
||||
private bool IsCacheAssetBundle(string assetBundleName)
|
||||
{
|
||||
assetBundleName = assetBundleName.ToLower();
|
||||
if (_cacheAssetBundleInfoDict == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _cacheAssetBundleInfoDict.ContainsKey(assetBundleName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 卸载AssetBundle相关
|
||||
|
||||
#region 卸载AssetBundle相关信息管理
|
||||
|
||||
private bool WaitUnload(GemCrushInfo assetBundleInfoV)
|
||||
{
|
||||
var isInWait = IsWaitUnload(assetBundleInfoV.assetBundleName);
|
||||
if (isInWait) return true;
|
||||
assetBundleInfoV.UpdateWaitUnloadCurrentTime();
|
||||
_waitUnloadList.Add(assetBundleInfoV);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private bool IsWaitUnloadKey(string assetBundleName)
|
||||
{
|
||||
var isWaitUnload = false;
|
||||
if (_waitUnloadList == null || _waitUnloadList.Count <= 0) return false;
|
||||
foreach (var bundleInfo in _waitUnloadList)
|
||||
{
|
||||
if (bundleInfo == null || !string.IsNullOrEmpty(bundleInfo.assetBundleName)) continue;
|
||||
if (!bundleInfo.assetBundleName.Equals(assetBundleName)) continue;
|
||||
isWaitUnload = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return isWaitUnload;
|
||||
}
|
||||
|
||||
|
||||
private bool IsWaitUnload(string assetBundleName)
|
||||
{
|
||||
var isWaitUnload = false;
|
||||
if (_waitUnloadList == null || _waitUnloadList.Count == 0) return false;
|
||||
if (!IsWaitUnloadKey(assetBundleName))
|
||||
{
|
||||
foreach (var waitUnloadAssetBundle in _waitUnloadList)
|
||||
{
|
||||
if (waitUnloadAssetBundle == null ||
|
||||
!string.IsNullOrEmpty(waitUnloadAssetBundle.assetBundleName)) continue;
|
||||
isWaitUnload = GetABDependency(waitUnloadAssetBundle.assetBundleName).Contains(assetBundleName);
|
||||
if (isWaitUnload)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isWaitUnload = true;
|
||||
}
|
||||
|
||||
return isWaitUnload;
|
||||
}
|
||||
|
||||
|
||||
private bool UnWaitUnload(string assetBundleName)
|
||||
{
|
||||
var isRemove = false;
|
||||
|
||||
foreach (var bundleInfo in _waitUnloadList)
|
||||
{
|
||||
if (bundleInfo == null) continue;
|
||||
if (!bundleInfo.assetBundleName.Equals(assetBundleName)) continue;
|
||||
isRemove = _waitUnloadList.Remove(bundleInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public void UnloadAssetBundle(string assetBundleName,
|
||||
bool ignoreDependency = false,
|
||||
int unloadWaitTime = 0,
|
||||
Action<bool> onCompleted = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(assetBundleName))
|
||||
{
|
||||
onCompleted?.Invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
bool unloadSucceed;
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
var abInfo = GetCacheAssetBundle(assetBundleName);
|
||||
if (abInfo == null)
|
||||
{
|
||||
onCompleted?.Invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (WaitUnload(abInfo) && !ignoreDependency)
|
||||
{
|
||||
unloadSucceed = false;
|
||||
|
||||
UnCacheDependency(assetBundleName);
|
||||
|
||||
onCompleted?.Invoke(unloadSucceed);
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StopAction(assetBundleName + "Unload");
|
||||
CrazyAsyKit.StartAction(assetBundleName + "Unload", delegate
|
||||
{
|
||||
unloadSucceed = IsCacheAssetBundle(assetBundleName) &&
|
||||
UnloadAssetBundleInternal(assetBundleName, ignoreDependency);
|
||||
|
||||
UnWaitUnload(assetBundleName);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
#endif
|
||||
|
||||
onCompleted?.Invoke(unloadSucceed);
|
||||
}, unloadWaitTime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
onCompleted?.Invoke(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool UnloadAssetBundleInternal(string assetBundleName, bool isIgnoreDependency = false,
|
||||
bool isThorough = false)
|
||||
{
|
||||
var GemCrushInfo = GetCacheAssetBundle(assetBundleName);
|
||||
if (GemCrushInfo == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var dependencyArray = GetCacheDependency(assetBundleName);
|
||||
|
||||
|
||||
UnCacheDependency(assetBundleName);
|
||||
|
||||
|
||||
if (!isIgnoreDependency)
|
||||
{
|
||||
if (IsOtherDependency(assetBundleName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UnCacheAssetBundle(assetBundleName);
|
||||
|
||||
|
||||
GemCrushInfo.Unload(isThorough);
|
||||
|
||||
|
||||
foreach (var dependencyAssetBundleName in dependencyArray)
|
||||
{
|
||||
if (dependencyAssetBundleName == assetBundleName)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!IsOtherDependency(dependencyAssetBundleName))
|
||||
{
|
||||
UnloadAssetBundleInternal(dependencyAssetBundleName, false, isThorough);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region 封装直接加载资源的方法
|
||||
|
||||
public T GetAsset<T>(string assetBundleName, string assetName) where T : Object
|
||||
{
|
||||
var assetBundlePath = GenerateAssetBundlePath(assetBundleName);
|
||||
var assetBundle = GetAssetBundle(assetBundlePath, assetBundleName);
|
||||
|
||||
return assetBundle.LoadAsset<T>(assetName);
|
||||
}
|
||||
|
||||
|
||||
public void GetAsset<T>(string assetBundleName, string assetName, UnityAction<T> onCompleted) where T : Object
|
||||
{
|
||||
LoadAssetInternal(assetBundleName, delegate (AssetBundle bundle)
|
||||
{
|
||||
if (bundle == null)
|
||||
{
|
||||
Debug.LogError("加载AssetBundle 失败:" + assetBundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(LoadAssetFromAssetBundle(bundle, assetName, onCompleted));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void InitManifest(string assetBundleManifestName, UnityAction<bool> onCompleted)
|
||||
{
|
||||
CrazyAsyKit.StopAction(assetBundleManifestName + "Unload");
|
||||
if (UnWaitUnload(assetBundleManifestName))
|
||||
{
|
||||
}
|
||||
var assetBundles =
|
||||
AssetBundle.LoadFromFile($"{GemCrushFileKit.GetFilePath()}{GemCrushConstant.undles}");
|
||||
var manifest = assetBundles.LoadAsset<AssetBundleManifest>("assetbundlemanifest");
|
||||
_manifest = manifest;
|
||||
onCompleted?.Invoke(manifest != null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void RecycleAssetBundle(string assetBundleName, UnityAction onCompleted = null)
|
||||
{
|
||||
if (IsCacheAssetBundle(assetBundleName))
|
||||
{
|
||||
var abInfo = GetCacheAssetBundle(assetBundleName);
|
||||
abInfo.UnReferenced(assetBundleName);
|
||||
|
||||
RecycleAssetBundleDependency(assetBundleName, UnloadWaitTime);
|
||||
|
||||
if (abInfo.GetReferenced() <= 0)
|
||||
{
|
||||
UnloadAssetBundle(assetBundleName, false, UnloadWaitTime);
|
||||
}
|
||||
}
|
||||
|
||||
onCompleted?.Invoke();
|
||||
}
|
||||
|
||||
private void RecycleAssetBundleDependency(string abName, int waitTime)
|
||||
{
|
||||
var otherAbName = GetCacheDependency(abName);
|
||||
if (otherAbName.Length <= 0) return;
|
||||
foreach (var dependAbName in otherAbName)
|
||||
{
|
||||
if (dependAbName == abName) continue;
|
||||
var dependAbInfo = GetCacheAssetBundle(dependAbName);
|
||||
if (dependAbInfo == null) continue;
|
||||
dependAbInfo.UnReferenced(abName);
|
||||
|
||||
|
||||
if (dependAbInfo.GetReferenced() <= 0)
|
||||
{
|
||||
UnloadAssetBundle(dependAbName, false, waitTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 其他方法
|
||||
|
||||
private string GenerateAssetBundlePath(string assetBundleName, bool isMD5 = false, bool isManifest = false,
|
||||
bool isAddABSuffix = true)
|
||||
{
|
||||
var fileName = assetBundleName.ToLower();
|
||||
if (isMD5)
|
||||
{
|
||||
fileName = MD5String(fileName) + ".data";
|
||||
}
|
||||
|
||||
var filePath = _assetBundleRootPath.Replace("file:///", "") + assetBundleName.ToLower();
|
||||
if (isAddABSuffix)
|
||||
{
|
||||
filePath += GemCrushConstant.setbun;
|
||||
}
|
||||
|
||||
if (!isManifest)
|
||||
return filePath;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
return filePath;
|
||||
}
|
||||
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private static string MD5String(string str)
|
||||
{
|
||||
using var md5 = MD5.Create();
|
||||
var hash = md5.ComputeHash(Encoding.GetEncoding("utf-8").GetBytes(str));
|
||||
var tmp = new StringBuilder();
|
||||
foreach (var i in hash)
|
||||
{
|
||||
tmp.Append(i.ToString("x2"));
|
||||
}
|
||||
|
||||
return tmp.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void RecycleAsset(string assetUrl, UnityAction onCompleted)
|
||||
{
|
||||
RecycleAssetBundle(assetUrl, onCompleted);
|
||||
}
|
||||
|
||||
private AssetBundleManifest GetManifest()
|
||||
{
|
||||
if (_manifest == null)
|
||||
{
|
||||
Debug.LogError("AssetBundleManifest is null");
|
||||
var assetBundles =
|
||||
AssetBundle.LoadFromFile($"{GemCrushFileKit.GetFilePath()}{GemCrushConstant.undles}");
|
||||
var manifest = assetBundles.LoadAsset<AssetBundleManifest>("assetbundlemanifest");
|
||||
_manifest = manifest;
|
||||
}
|
||||
|
||||
return _manifest;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0049894e09758c34fb23600e4571504e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FlowerPower
|
||||
{
|
||||
public enum GemCrushState
|
||||
{
|
||||
STATE_NONE,
|
||||
STATE_LOADING,
|
||||
STATE_LOADED,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e6f867b844a92f4e8799eeb338a9aa2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
public class FXPool<T> : IDisposable where T : Enum
|
||||
{
|
||||
private Dictionary<T, List<Object>> PoolDic;
|
||||
private Dictionary<T, Transform> PollPar;
|
||||
private List<T> temp;
|
||||
private Transform objectPoolPar;
|
||||
public Func<T, Object> NewObjFunc;
|
||||
public Action<T, Object> RecObjFunc;
|
||||
public Action<T, Object> GetObjFunc;
|
||||
|
||||
public FXPool(Transform _objectPoolPar = null)
|
||||
{
|
||||
objectPoolPar = _objectPoolPar;
|
||||
if (objectPoolPar == null)
|
||||
{
|
||||
objectPoolPar = new GameObject("ObjectPool").transform;
|
||||
objectPoolPar.localPosition = Vector3.zero;
|
||||
objectPoolPar.localEulerAngles = Vector3.zero;
|
||||
}
|
||||
|
||||
PoolDic = new Dictionary<T, List<Object>>();
|
||||
PollPar = new Dictionary<T, Transform>();
|
||||
temp = new List<T>();
|
||||
}
|
||||
|
||||
public Obj GetObject<Obj>(T key) where Obj : Object
|
||||
{
|
||||
Obj obj = null;
|
||||
if (!PoolDic.ContainsKey(key))
|
||||
{
|
||||
AddKey(key);
|
||||
}
|
||||
|
||||
if (PoolDic[key].Count > 0)
|
||||
{
|
||||
obj = PoolDic[key][0] as Obj;
|
||||
PoolDic[key].RemoveAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = LoadObject<Obj>(key);
|
||||
}
|
||||
|
||||
GetObjFunc?.Invoke(key, obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void AddKey(T key)
|
||||
{
|
||||
PoolDic.Add(key, new List<Object>());
|
||||
Transform par = new GameObject(key.ToString()).transform;
|
||||
par.SetParent(objectPoolPar);
|
||||
par.localScale = Vector3.one;
|
||||
par.localPosition = Vector3.zero;
|
||||
par.localEulerAngles = Vector3.zero;
|
||||
PollPar.Add(key, par.transform);
|
||||
}
|
||||
|
||||
private Obj LoadObject<Obj>(T key) where Obj : UnityEngine.Object
|
||||
{
|
||||
Obj obj = NewObjFunc?.Invoke(key) as Obj;
|
||||
if (obj != null)
|
||||
{
|
||||
GameObject go = obj as GameObject ?? (obj as Component).gameObject;
|
||||
|
||||
if (PollPar.TryGetValue(key, out Transform par) && go != null)
|
||||
{
|
||||
go.transform.SetParent(par);
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void RecObject(T key, Object obj)
|
||||
{
|
||||
if (obj == null) return;
|
||||
if (!PoolDic.ContainsKey(key))
|
||||
{
|
||||
PoolDic.Add(key, new List<Object>());
|
||||
}
|
||||
|
||||
GameObject go = obj as GameObject ?? (obj as Component).gameObject;
|
||||
if (PollPar.TryGetValue(key, out Transform par))
|
||||
{
|
||||
go.transform.parent = (par);
|
||||
}
|
||||
|
||||
RecObjFunc?.Invoke(key, obj);
|
||||
PoolDic[key].Add(obj);
|
||||
}
|
||||
|
||||
public void RemoveKey(T key)
|
||||
{
|
||||
if (PoolDic.ContainsKey(key))
|
||||
{
|
||||
foreach (Object item in PoolDic[key])
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
GameObject go = item as GameObject;
|
||||
if (go == null)
|
||||
{
|
||||
Component cot = item as Component;
|
||||
go = cot.gameObject;
|
||||
}
|
||||
|
||||
GameObject.Destroy(go);
|
||||
}
|
||||
}
|
||||
|
||||
PoolDic[key].Clear();
|
||||
PoolDic.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAll()
|
||||
{
|
||||
temp.Clear();
|
||||
foreach (var item in PoolDic)
|
||||
{
|
||||
temp.Add(item.Key);
|
||||
}
|
||||
|
||||
foreach (var item in temp)
|
||||
{
|
||||
RemoveKey(item);
|
||||
}
|
||||
|
||||
temp.Clear();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
RemoveAll();
|
||||
PoolDic = null;
|
||||
PollPar = null;
|
||||
temp = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3de141293f3240ffbdc26570a545e96c
|
||||
timeCreated: 1681806263
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
public class MD5Kit
|
||||
{
|
||||
|
||||
public static string GetFileMD5(string file)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fs = new FileStream(file, FileMode.Open);
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
var retVal = md5.ComputeHash(fs);
|
||||
fs.Close();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (var str in retVal)
|
||||
{
|
||||
sb.Append(str.ToString("X2"));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("GetFileMD5 fail error: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字符串的MD5值
|
||||
/// </summary>
|
||||
public static string GetStringMD5(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] bytResult = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
string strResult = BitConverter.ToString(bytResult);
|
||||
strResult = strResult.Replace("-", string.Empty);
|
||||
return strResult;
|
||||
}
|
||||
|
||||
|
||||
public static string MD5String1(string text)
|
||||
{
|
||||
var buffer = Encoding.Default.GetBytes(text);
|
||||
var check = new MD5CryptoServiceProvider();
|
||||
var somme = check.ComputeHash(buffer);
|
||||
var result = new StringBuilder();
|
||||
foreach (var a in somme)
|
||||
{
|
||||
var value = a.ToString("X");
|
||||
if (a < 16)
|
||||
{
|
||||
result.Append(0);
|
||||
result.Append(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Append(value);
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToString().ToLower();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5697bf9fd10d9548977711311a96a00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,511 @@
|
||||
namespace FlowerPower
|
||||
{
|
||||
using System.Text;
|
||||
using UnityEngine.Events;
|
||||
using System.Collections;
|
||||
using UnityEngine.Networking;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using DG.Tweening;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
public class NetworkKit
|
||||
{
|
||||
public static string CDNUrl;
|
||||
|
||||
//打点需要的值-----began----
|
||||
public static string trace_id;
|
||||
public static string channel_id;
|
||||
public static long userId;
|
||||
//打点需要的值-----end----
|
||||
public static Dictionary<string, bool> statusDic = new Dictionary<string, bool>();
|
||||
public static Dictionary<string, Dictionary<string, bool>> statusDic2 = new Dictionary<string, Dictionary<string, bool>>();
|
||||
|
||||
public static string GetCacheToken()
|
||||
{
|
||||
|
||||
string token = null;
|
||||
if (PlayerPrefsKit.HasKey(PrefsKeyConst.JarvisToken))
|
||||
{
|
||||
token = PlayerPrefsKit.ReadString(PrefsKeyConst.JarvisToken);
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
public static void SetCacheToken(string token)
|
||||
{
|
||||
PlayerPrefsKit.WriteString(PrefsKeyConst.JarvisToken, token);
|
||||
}
|
||||
|
||||
private static IEnumerator PostInternal<T>(string url, object requestData, UnityAction<bool, T> onCompleted,
|
||||
Dictionary<string, string> header = null)
|
||||
{
|
||||
var requestJson = SerializeUtil.ToJsonIndented(requestData);
|
||||
|
||||
var url2 = url;
|
||||
#if FlowerPowerRelease
|
||||
url2 = Base64Kit.Encode(url);
|
||||
requestJson = Base64Kit.Encode(requestJson);
|
||||
#endif
|
||||
var bytes = Encoding.UTF8.GetBytes(requestJson);
|
||||
var url1 = NetworkManager.crazyUrl + url2;
|
||||
var loginRequest = new UnityWebRequest(url1, UnityWebRequest.kHttpVerbPOST)
|
||||
{
|
||||
uploadHandler = new UploadHandlerRaw(bytes),
|
||||
downloadHandler = new DownloadHandlerBuffer(),
|
||||
timeout = 10 // 设置超时时间为10秒
|
||||
};
|
||||
|
||||
if (header != null)
|
||||
{
|
||||
foreach (var keyValuePair in header)
|
||||
{
|
||||
loginRequest.SetRequestHeader(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
}
|
||||
|
||||
SetRequestContentType(loginRequest);
|
||||
// Debug.Log($"request url1======= {url1}");
|
||||
yield return loginRequest.SendWebRequest();
|
||||
// Debug.Log($"requestData11111======={url1}=={requestJson}");
|
||||
// Debug.Log($"requestData22222====={url1}==={JsonConvert.SerializeObject(loginRequest)}");
|
||||
if (loginRequest.result is not UnityWebRequest.Result.Success)
|
||||
{
|
||||
onCompleted?.Invoke(false, default);
|
||||
}
|
||||
else
|
||||
{
|
||||
var receiveContent = loginRequest.downloadHandler.text;
|
||||
#if FlowerPowerRelease
|
||||
if (!receiveContent.IsNullOrWhiteSpace())
|
||||
{
|
||||
receiveContent = receiveContent.Substring(0, receiveContent.Length - 1);
|
||||
receiveContent = receiveContent.Substring(1);
|
||||
receiveContent = Base64Kit.Decode(receiveContent,NetworkManager.DomainRelease);
|
||||
}
|
||||
#endif
|
||||
var response = SerializeUtil.ToObject<ResponseData>(receiveContent);
|
||||
|
||||
var respJson = "";
|
||||
#if UNITY_EDITOR
|
||||
respJson = JsonConvert.SerializeObject(response);
|
||||
|
||||
Debug.Log($"requestData======={url1}=={requestJson}");
|
||||
Debug.Log($"response========={respJson}");
|
||||
#endif
|
||||
if (response?.code == 0)
|
||||
{
|
||||
var responseData = SerializeUtil.ToObject<T>(response.data.ToString());
|
||||
onCompleted?.Invoke(true, responseData);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(response.code == 1005)
|
||||
{
|
||||
ReLoginGetToken();
|
||||
}
|
||||
|
||||
if (url == "shop/applePayCheck"){
|
||||
respJson = JsonConvert.SerializeObject(response);
|
||||
var responseData = SerializeUtil.ToObject<T>(respJson.ToString());
|
||||
onCompleted?.Invoke(false, responseData);
|
||||
}
|
||||
else
|
||||
{
|
||||
onCompleted?.Invoke(false, default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loginRequest.Dispose();
|
||||
}
|
||||
|
||||
public static void SetRequestContentType(UnityWebRequest request)
|
||||
{
|
||||
request.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
|
||||
}
|
||||
|
||||
public static void Post<T>(string url, object requestData, UnityAction<bool, T> onCompleted)
|
||||
{
|
||||
|
||||
CrazyAsyKit.StartCoroutine(PostInternal(url, requestData, onCompleted));
|
||||
}
|
||||
|
||||
public static void PostWithHeader<T>(string url, object requestData = null,
|
||||
UnityAction<bool, T> onCompleted = null)
|
||||
{
|
||||
ReSetToken();
|
||||
|
||||
var headers = new Dictionary<string, string> { { "x-token", GetCacheToken() } };
|
||||
CrazyAsyKit.StartCoroutine(PostInternal(url, requestData, onCompleted, headers));
|
||||
}
|
||||
|
||||
public static void PostWithHeader<T>(string url, UnityAction<bool, T> onCompleted)
|
||||
{
|
||||
if (onCompleted != null)
|
||||
{
|
||||
PostWithHeader<T>(url, null, (isSuccess, obj) => { onCompleted.Invoke(isSuccess, obj); });
|
||||
}
|
||||
else
|
||||
{
|
||||
PostWithHeader<T>(url);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostWithHeader(string url, object requestData = null, UnityAction<bool> onCompleted = null)
|
||||
{
|
||||
if (onCompleted != null)
|
||||
{
|
||||
PostWithHeader<object>(url, requestData, (isSuccess, obj) => { onCompleted?.Invoke(isSuccess); });
|
||||
}
|
||||
else
|
||||
{
|
||||
PostWithHeader<object>(url, requestData);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostFunnelLogin(RespLoginFunnelData reqData = null)
|
||||
{
|
||||
|
||||
if (statusDic.TryGetValue(reqData.type, out var status))
|
||||
{
|
||||
if (status)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (reqData.type == "bootstrap")
|
||||
{
|
||||
long timestamp = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
|
||||
trace_id = timestamp.ToString();
|
||||
}
|
||||
|
||||
var requestData = new RespLoginFunnelData
|
||||
{
|
||||
uid = userId,
|
||||
trace_id = trace_id,
|
||||
device_id = SystemInfo.deviceUniqueIdentifier,
|
||||
pack_name = NetworkManager.identifier,
|
||||
version = Application.version,
|
||||
channel = SuperApplication.Instance.attribution,
|
||||
type = reqData.type,
|
||||
payload = reqData.payload
|
||||
};
|
||||
|
||||
statusDic.Add(reqData.type, true);
|
||||
// Debug.Log($"PostFunnelLogin requestData1111========={reqData.type}");
|
||||
Post<RespLoginFunnelData>("event/funnelLogin", requestData, (isSuccess, data) =>
|
||||
{
|
||||
// Debug.Log($"PostFunnelLogin responseData2222========={isSuccess}{reqData.type}");
|
||||
});
|
||||
}
|
||||
public static void SendLogToServer(RespDebugData reqData)
|
||||
{
|
||||
// Debug.Log("SendLogToServer ====" + GameHelper.GetLoginModel().debug_log);
|
||||
if (!GameHelper.GetLoginModel().debug_log) return;
|
||||
|
||||
// 如果只需要日期部分,可以使用ToShortDateString()或ToString("yyyy-MM-dd")等进行格式化
|
||||
System.DateTime currentDate = System.DateTime.Now;
|
||||
var formattedDate = currentDate.ToString("yyyy_MM_dd_HH_mm");
|
||||
|
||||
var md5Str = MD5Kit.GetStringMD5(reqData.message + reqData.stacktrace);
|
||||
|
||||
if (!statusDic2.ContainsKey(formattedDate))
|
||||
{
|
||||
statusDic2.Add(formattedDate, new Dictionary<string, bool>());
|
||||
}
|
||||
|
||||
if (!statusDic2[formattedDate].ContainsKey(md5Str))
|
||||
{
|
||||
statusDic2[formattedDate].Add(md5Str, false);
|
||||
}
|
||||
|
||||
// Debug.Log($"SendLogToServer requestData========={formattedDate} \nmd5Str=== {md5Str}");
|
||||
if (statusDic2[formattedDate][md5Str])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var requestData = new RespDebugData
|
||||
{
|
||||
uid = userId,
|
||||
device = SystemInfo.deviceModel,
|
||||
os_ver = SystemInfo.operatingSystem,
|
||||
network = GetNetworkType(),
|
||||
device_id = SystemInfo.deviceUniqueIdentifier,
|
||||
pack_name = NetworkManager.identifier,
|
||||
version = Application.version,
|
||||
level = reqData.level,
|
||||
message = reqData.message,
|
||||
stacktrace = reqData.stacktrace,
|
||||
channel = SuperApplication.Instance.attribution,
|
||||
|
||||
};
|
||||
|
||||
statusDic2[formattedDate][md5Str] = true;
|
||||
|
||||
//Debug.Log($"SendLogToServer requestData1========={JsonConvert.SerializeObject(requestData)}");
|
||||
Post<RespDebugData>("event/cliDebugLog", requestData, (isSuccess, data) =>
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
public static string GetNetworkType()
|
||||
{
|
||||
|
||||
switch (Application.internetReachability)
|
||||
{
|
||||
case NetworkReachability.ReachableViaCarrierDataNetwork:
|
||||
return NetworkType.mobile;
|
||||
case NetworkReachability.ReachableViaLocalAreaNetwork:
|
||||
return NetworkType.wifi;
|
||||
case NetworkReachability.NotReachable:
|
||||
return NetworkType.notConnected;
|
||||
default:
|
||||
return NetworkType.notConnected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static BuriedPointObject buriedPointObject = new BuriedPointObject();
|
||||
|
||||
/*
|
||||
* 打点
|
||||
*/
|
||||
public static void BuriedPoint(string eventname, string eventproperty, int integer)
|
||||
{
|
||||
if (eventname == BuriedPointEvent.Apple_AD_event || eventname == BuriedPointEvent.Apple_pay_event)
|
||||
{
|
||||
if (GameHelper.IsAdModelOfPay())
|
||||
{
|
||||
eventname = BuriedPointEvent.Apple_AD_event;
|
||||
}
|
||||
else
|
||||
{
|
||||
int rate = GameHelper.GetCommonModel().PayRate;
|
||||
if (!GameHelper.IsGiftSwitch() || GameHelper.GetCommonModel().PayRate == 100) {
|
||||
MaxPayManager.isIOSPay = true;
|
||||
}
|
||||
eventname = MaxPayManager.isIOSPay ? BuriedPointEvent.Apple_ios_pay_event : BuriedPointEvent.Apple_pay_event;
|
||||
}
|
||||
}
|
||||
if (eventproperty == BuriedPointEvent.afterRewardAdShow || eventproperty == BuriedPointEvent.afterRewardAdEnd)
|
||||
{
|
||||
eventname = BuriedPointEvent.Apple_AD_event;
|
||||
}
|
||||
|
||||
buriedPointObject.@event = eventname;
|
||||
buriedPointObject.property = eventproperty;
|
||||
buriedPointObject.n = integer;
|
||||
PostWithHeader<BuriedPointObject>("/event/incrN", buriedPointObject, (isSuccess, obj) =>
|
||||
{
|
||||
// Debug.Log(isSuccess);
|
||||
// Debug.Log(eventproperty);
|
||||
//Debug.Log(JsonUtility.ToJson(obj));
|
||||
});
|
||||
}
|
||||
|
||||
private static bool isReqToken = false;
|
||||
public static void ReSetToken()
|
||||
{
|
||||
if (isReqToken) return;
|
||||
|
||||
var nowTimes = GameHelper.GetNowTime();
|
||||
var passtime = GameHelper.GetLoginModel().expires_at;
|
||||
// Debug.Log($"ReSetToken nowTimes:{nowTimes} passtime:{passtime}");
|
||||
if (passtime == 0 || passtime - nowTimes > 3600) return;
|
||||
|
||||
isReqToken = true;
|
||||
|
||||
var headers = new Dictionary<string, string> { { "x-token", GetCacheToken() } };
|
||||
|
||||
CrazyAsyKit.StartCoroutine(PostInternal<ResquestTokenData>("tokenRefresh", null, (isSuccess, tokenData) =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
LoginModel loginModel = GameHelper.GetLoginModel();
|
||||
loginModel.token = tokenData.token;
|
||||
loginModel.expires_at = tokenData.expires_at;
|
||||
|
||||
SetCacheToken(tokenData.token);
|
||||
}
|
||||
isReqToken = false;
|
||||
|
||||
}, headers));
|
||||
}
|
||||
|
||||
|
||||
private static bool isReqToken1 = false;
|
||||
|
||||
public static void ReLoginGetToken()
|
||||
{
|
||||
if (isReqToken1) return;
|
||||
|
||||
var requestLoginData = new RequestLoginData
|
||||
{
|
||||
device_id = SystemInfo.deviceUniqueIdentifier,
|
||||
pack_name = NetworkManager.identifier,
|
||||
app_version = Application.version,
|
||||
channel = SuperApplication.Instance.attribution,
|
||||
sim = NetworkManager.haveSimCard
|
||||
|
||||
};
|
||||
isReqToken1 = true;
|
||||
|
||||
|
||||
Post<LoginModel>("login", requestLoginData, (isSuccess, loginData) =>{
|
||||
if (isSuccess)
|
||||
{
|
||||
LoginModel loginModel = GameHelper.GetLoginModel();
|
||||
loginModel.token = loginData.token;
|
||||
loginModel.expires_at = loginData.expires_at;
|
||||
|
||||
SetCacheToken(loginData.token);
|
||||
}
|
||||
|
||||
isReqToken1 = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class NetworkType{
|
||||
public static string mobile = "Mobile Data";
|
||||
public static string wifi = "Wi-Fi";
|
||||
public static string notConnected = "Not Connected";
|
||||
}
|
||||
|
||||
public class BuriedPointObject
|
||||
{
|
||||
public string @event;
|
||||
public string property;
|
||||
public int n;
|
||||
}
|
||||
public class BuriedPointEvent
|
||||
{
|
||||
public static string play_event = "Number_of_people_play";
|
||||
public static string play_property = "Number_of_people_playing";
|
||||
|
||||
public static string playing_event = "Playing_time";
|
||||
public static string playing_property = "Room_type";
|
||||
|
||||
public static string ad_task = "ad_task";
|
||||
public static string watch_ad_number = "watch_ad_number";
|
||||
public static string finish_ad_number = "finish_ad_number";
|
||||
|
||||
public static string h5_event = "H5_task";
|
||||
public static string h5_event_time = "H5_time";
|
||||
public static string h5_event_numbers = "finish_H5_number";
|
||||
|
||||
public static string withdraw_behavior = "withdraw_behavior";
|
||||
public static string withdraw_message = "withdraw_message";
|
||||
public static string ww_ch1 = "ww_ch1";
|
||||
public static string ww_ch2 = "ww_ch2";
|
||||
public static string ww_ch3 = "ww_ch3";
|
||||
|
||||
public static string Hall_behavior = "Hall_behavior";
|
||||
public static string open_hall_number = "open_hall_number";
|
||||
//public static string open_hall_people = "open_hall_people";
|
||||
public static string collect_fly_number = "collect_fly_number";
|
||||
//public static string collect_fly_people = "collect_fly_people";
|
||||
public static string fly_ct_number = "fly_ct_number";
|
||||
//public static string fly_ct_people = "fly_ct_people";
|
||||
public static string annular_finish_number = "annular_finish_number";
|
||||
public static string annular_get_number = "annular_get_number";
|
||||
public static string annular_ct_number = "annular_ct_number";
|
||||
//public static string annular_ct_people = "annular_ct_people";
|
||||
|
||||
public static string video_behavior = "video_behavior";
|
||||
public static string watch_ad_people = "watch_ad_people";
|
||||
public static string watch_success_ad_people = "watch_success_ad_people";
|
||||
|
||||
public static string video_type = "video_type";
|
||||
public static string Rewarded_videos_trigger_number = "Rewarded_videos_trigger_number";
|
||||
public static string Rewarded_videos_fill_number = "Rewarded_videos_fill_number";
|
||||
public static string Rewarded_videos_dinish_number = "Rewarded_videos_dinish_number";
|
||||
public static string Interstitial_videos_trigger_number = "Interstitial_videos_trigger_number";
|
||||
public static string Interstitial_videos_fill_number = "Interstitial_videos_fill_number";
|
||||
public static string Interstitial_videos_dinish_number = "Interstitial_videos_dinish_number";
|
||||
|
||||
public static string open_ad = "open_ad";
|
||||
public static string open_show = "open_show";
|
||||
public static string open_show_people = "open_show_people";
|
||||
|
||||
public static string Apple_pay_event = "Max_pay_Event";
|
||||
public static string Apple_AD_event = "AD_Event";
|
||||
public static string Apple_ios_pay_event = "IOS_Pay_Event";
|
||||
|
||||
|
||||
public static string pack_show = "pack_show";
|
||||
public static string pack_click = "pack_click";
|
||||
public static string pack_open = "pack_open";
|
||||
public static string pack_success = "pack_success";
|
||||
|
||||
public static string remove_ad_show = "remove_ad_show";
|
||||
public static string remove_ad_click = "remove_ad_click";
|
||||
|
||||
public static string remove_ad_open = "remove_ad_open";
|
||||
public static string remove_ad_success = "remove_ad_success";
|
||||
|
||||
public static string pass_show = "pass_show";
|
||||
public static string pass_click = "pass_click";
|
||||
public static string pass_open = "pass_open";
|
||||
public static string pass_success = "pass_success";
|
||||
|
||||
public static string buy_one_show = "buy_one_show";
|
||||
public static string buy_one_click = "buy_one_click";
|
||||
public static string buy_one_open = "buy_one_open";
|
||||
public static string buy_one_success = "buy_one_success";
|
||||
|
||||
public static string buy_super_show = "buy_one_show";
|
||||
public static string buy_super_click = "buy_one_click";
|
||||
public static string buy_super_open = "buy_one_open";
|
||||
public static string buy_super_success = "buy_one_success";
|
||||
|
||||
public static string BuyOneOffShow = "BuyOneOffShow";
|
||||
public static string BuyOneOffClick = "BuyOneOffClick";
|
||||
public static string BuyOneOffOpen = "BuyOneOffOpen";
|
||||
public static string BuyOneOffSuccess = "BuyOneOffSuccess";
|
||||
|
||||
public static string BuyOneNewShow = "BuyOneNewShow";
|
||||
public static string BuyOneNewClick = "BuyOneNewClick";
|
||||
public static string BuyOneNewSuccess = "BuyOneNewSuccess";
|
||||
|
||||
public static string makeupAdTaskClick = "makeupAdTaskClick";
|
||||
|
||||
public static string gold_show = "shop_show";
|
||||
public static string gold_click_ad = "gold_click_ad";
|
||||
public static string gold_click_1 = "gold_click_1";
|
||||
public static string gold_click_2 = "gold_click_2";
|
||||
public static string gold_click_3 = "gold_click_3";
|
||||
public static string gold_click_4 = "gold_click_4";
|
||||
public static string gold_open_1 = "gold_open_1";
|
||||
public static string gold_open_2 = "gold_open_2";
|
||||
public static string gold_open_3 = "gold_open_3";
|
||||
public static string gold_open_4 = "gold_open_4";
|
||||
public static string gold_success_1 = "gold_success_1";
|
||||
public static string gold_success_2 = "gold_success_2";
|
||||
public static string gold_success_3 = "gold_success_3";
|
||||
public static string gold_success_4 = "gold_success_4";
|
||||
public static string afterRewardAdShow = "afterRewardAdShow";
|
||||
public static string afterRewardAdEnd = "afterRewardAdEnd";
|
||||
public static string fail_show = "fail_show";
|
||||
public static string fail_click = "fail_click";
|
||||
public static string fail_buy_success = "fail_buy_success";
|
||||
public static string fail_open = "fail_open";
|
||||
public static string three_days_gift_show = "three_days_gift_show";
|
||||
public static string three_days_gift_click = "three_days_gift_click";
|
||||
public static string three_days_gift_buy_success = "three_days_gift_buy_success";
|
||||
public static string three_days_gift_open = "three_days_gift_open";
|
||||
public static string three_day1_success = "three_day1_success";
|
||||
public static string three_day2_success = "three_day2_success";
|
||||
public static string three_day3_success = "three_day3_success";
|
||||
public static string Three_days_gift_event = "Three_days_gift_event";
|
||||
public static string rank_event = "rank_event";
|
||||
public static string rank_show = "rank_show";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7375397b5a640f4b3d00f86381f7a3a
|
||||
timeCreated: 1692338896
|
||||
Reference in New Issue
Block a user