ball 项目提交
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public static class SerializeUtil
|
||||
{
|
||||
static SerializeUtil()
|
||||
{
|
||||
JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() => { return DefaultUseJsonSettings; });
|
||||
}
|
||||
|
||||
private static JsonSerializerSettings DefaultUseJsonSettings = new JsonSerializerSettings
|
||||
{
|
||||
Formatting = Formatting.None,
|
||||
DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
|
||||
DateFormatString = "yyyy/MM/dd hh:mm:ss",
|
||||
};
|
||||
|
||||
private static JsonSerializerSettings JsonIndentedSettings = new JsonSerializerSettings
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
|
||||
DateFormatString = "yyyy/MM/dd hh:mm:ss",
|
||||
};
|
||||
|
||||
public static string ToJson(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj, DefaultUseJsonSettings);
|
||||
}
|
||||
|
||||
public static string ToJsonIndented(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj, JsonIndentedSettings);
|
||||
}
|
||||
|
||||
public static string ToJson(object obj, Type type)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj, type, DefaultUseJsonSettings);
|
||||
}
|
||||
|
||||
public static string ToJson<T>(object obj)
|
||||
{
|
||||
return ToJson(obj, typeof(T));
|
||||
}
|
||||
|
||||
public static T ToObject<T>(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 094e748a04f77844d960e9e2d87e6559
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class TaskSequence
|
||||
{
|
||||
public Action onFinish;
|
||||
private List<TaskProcedure> taskList;
|
||||
private bool isCancel = false;
|
||||
|
||||
public int Count => taskList.Count;
|
||||
|
||||
public TaskSequence Add(Action<TaskProcedure> taskFunc)
|
||||
{
|
||||
TaskProcedure task = new TaskProcedure();
|
||||
task.taskSequence = this;
|
||||
task.onTaskFunc = taskFunc;
|
||||
taskList.Add(task);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskSequence Add(bool result, Action<TaskProcedure> trueTaskFunc)
|
||||
{
|
||||
if (!result) return this;
|
||||
return Add(trueTaskFunc);
|
||||
}
|
||||
|
||||
public TaskSequence Run()
|
||||
{
|
||||
if (isCancel)
|
||||
return null;
|
||||
for (int i = 0; i < taskList.Count - 1; i++)
|
||||
{
|
||||
int index = i;
|
||||
int nextIndex = index + 1;
|
||||
taskList[index].onComplete = () => taskList[nextIndex].onTaskFunc(taskList[nextIndex]);
|
||||
}
|
||||
|
||||
if (taskList.Count > 0)
|
||||
{
|
||||
taskList[taskList.Count - 1].onComplete = onFinish;
|
||||
taskList[0].onTaskFunc(taskList[0]);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskSequence Clear()
|
||||
{
|
||||
onFinish = null;
|
||||
if (taskList != null)
|
||||
{
|
||||
foreach (TaskProcedure task in taskList)
|
||||
{
|
||||
task?.Dispose();
|
||||
}
|
||||
|
||||
taskList.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskList = new List<TaskProcedure>();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class TaskProcedure
|
||||
{
|
||||
public TaskSequence taskSequence;
|
||||
public Action<TaskProcedure> onTaskFunc;
|
||||
public Action onComplete;
|
||||
|
||||
public void InvokeComplete()
|
||||
{
|
||||
if (onComplete != null)
|
||||
{
|
||||
onComplete();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
taskSequence = null;
|
||||
onTaskFunc = null;
|
||||
onComplete = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa7436b18ddf94d44b141a67425a0759
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f071f4f98482cb4ea09fbf4ed3bbfe4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class EasyTimer : MonoBehaviour
|
||||
{
|
||||
private Dictionary<Action, float> mIntervalDic = new();
|
||||
private List<Action> triggers = new();
|
||||
|
||||
[SerializeField] private string timerName;
|
||||
private TimerTimeType type = TimerTimeType.Null;
|
||||
|
||||
public void SetTimer(string name, TimerTimeType type)
|
||||
{
|
||||
this.timerName = name + "_" + type;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private float GetTime()
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
TimerTimeType.Time => Time.time,
|
||||
TimerTimeType.UnscaledTime => Time.unscaledTime,
|
||||
TimerTimeType.RealtimeSinceStartup => Time.realtimeSinceStartup,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (mIntervalDic.Count > 0)
|
||||
{
|
||||
triggers.Clear();
|
||||
foreach (var keyValue in mIntervalDic.Where(keyValue => keyValue.Value <= GetTime()))
|
||||
{
|
||||
triggers.Add(keyValue.Key);
|
||||
}
|
||||
|
||||
foreach (var func in triggers)
|
||||
{
|
||||
mIntervalDic.Remove(func);
|
||||
func();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTimer(float interval, Action func)
|
||||
{
|
||||
if (null != func)
|
||||
{
|
||||
if (interval <= 0)
|
||||
{
|
||||
func();
|
||||
return;
|
||||
}
|
||||
|
||||
mIntervalDic[func] = GetTime() + interval;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
mIntervalDic.Clear();
|
||||
triggers.Clear();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearAll();
|
||||
mIntervalDic = null;
|
||||
triggers = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cccc8c2ef81a9c04c99cc97fdf07a8a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class NormalTimer : MonoBehaviour
|
||||
{
|
||||
private class TimerTask
|
||||
{
|
||||
private NormalTimer mNormalTimer;
|
||||
|
||||
private string name;
|
||||
private TimerMode mode;
|
||||
private float startTime;
|
||||
private float duration;
|
||||
|
||||
private bool isBreak = false;
|
||||
private float breakStart;
|
||||
private float breakDuration = 0;
|
||||
|
||||
private Action timerEvent;
|
||||
private Action<object[]> timerArgsEvent;
|
||||
private object[] args = null;
|
||||
|
||||
public float TimeLeft => Mathf.Max(0f, duration - (mNormalTimer.GetTime() - startTime) + breakDuration);
|
||||
|
||||
public void Run()
|
||||
{
|
||||
if (isBreak)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeLeft > 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == TimerMode.Normal)
|
||||
{
|
||||
mNormalTimer.RemoveTimer(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
startTime = mNormalTimer.GetTime();
|
||||
breakDuration = 0;
|
||||
}
|
||||
|
||||
timerEvent?.Invoke();
|
||||
timerArgsEvent?.Invoke(args);
|
||||
}
|
||||
|
||||
public static implicit operator bool(TimerTask timerTask)
|
||||
{
|
||||
return null != timerTask;
|
||||
}
|
||||
}
|
||||
|
||||
private enum TimerMode
|
||||
{
|
||||
Normal,
|
||||
Repeat,
|
||||
}
|
||||
|
||||
private Dictionary<string, TimerTask> addTimerList = new();
|
||||
private Dictionary<string, TimerTask> timerList = new();
|
||||
private List<string> destroyTimerList = new();
|
||||
|
||||
[SerializeField] private string timerName;
|
||||
private TimerTimeType type = TimerTimeType.Null;
|
||||
|
||||
public void SetTimer(string name, TimerTimeType type)
|
||||
{
|
||||
timerName = name + "_" + type;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private float GetTime()
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
TimerTimeType.Time => Time.time,
|
||||
TimerTimeType.UnscaledTime => Time.unscaledTime,
|
||||
TimerTimeType.RealtimeSinceStartup => Time.realtimeSinceStartup,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (destroyTimerList.Count > 0)
|
||||
{
|
||||
foreach (var i in destroyTimerList)
|
||||
{
|
||||
timerList.Remove(i);
|
||||
}
|
||||
|
||||
destroyTimerList.Clear();
|
||||
}
|
||||
|
||||
if (addTimerList.Count > 0)
|
||||
{
|
||||
foreach (var i in addTimerList.Where(i => i.Value != null))
|
||||
{
|
||||
timerList[i.Key] = i.Value;
|
||||
}
|
||||
|
||||
addTimerList.Clear();
|
||||
}
|
||||
|
||||
if (timerList.Count > 0)
|
||||
{
|
||||
foreach (var timer in timerList.Values)
|
||||
{
|
||||
if (timer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RemoveTimer(string key)
|
||||
{
|
||||
if (!timerList.ContainsKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!destroyTimerList.Contains(key))
|
||||
{
|
||||
destroyTimerList.Add(key);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
addTimerList.Clear();
|
||||
timerList.Clear();
|
||||
destroyTimerList.Clear();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearAll();
|
||||
addTimerList = null;
|
||||
timerList = null;
|
||||
destroyTimerList = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fefb9ed2ef0fffd409b6ea3e113cb153
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class TimerTask
|
||||
{
|
||||
private Timer timer;
|
||||
|
||||
public int repeatCount;
|
||||
public float interval;
|
||||
private Action<TimerTask> onCallBack;
|
||||
public object[] args;
|
||||
public float time;
|
||||
public bool isActive = true;
|
||||
public bool isFrameUpdate = false;
|
||||
|
||||
public TimerTask(Timer timer, float interval, Action<TimerTask> onCallBack, params object[] args)
|
||||
{
|
||||
this.timer = timer;
|
||||
|
||||
repeatCount = 1;
|
||||
this.interval = interval;
|
||||
this.onCallBack = onCallBack;
|
||||
this.args = args;
|
||||
time = timer.GetTriggerTime(interval);
|
||||
}
|
||||
|
||||
public TimerTask(Timer timer, int repeatCount, float interval, Action<TimerTask> onCallBack,
|
||||
params object[] args)
|
||||
{
|
||||
this.timer = timer;
|
||||
|
||||
this.repeatCount = repeatCount;
|
||||
this.interval = interval;
|
||||
this.onCallBack = onCallBack;
|
||||
this.args = args;
|
||||
time = timer.GetTriggerTime(interval);
|
||||
}
|
||||
|
||||
public TimerTask(Timer timer, Action<TimerTask> onCallBack, params object[] args)
|
||||
{
|
||||
this.timer = timer;
|
||||
|
||||
this.onCallBack = onCallBack;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public void CallFunc()
|
||||
{
|
||||
onCallBack?.Invoke(this);
|
||||
}
|
||||
|
||||
public static implicit operator bool(TimerTask timerTask)
|
||||
{
|
||||
return null != timerTask;
|
||||
}
|
||||
}
|
||||
|
||||
public class Timer : MonoBehaviour
|
||||
{
|
||||
public const int INFINITE_LOOP = -1;
|
||||
|
||||
private List<TimerTask> timerTaskList = new();
|
||||
private List<TimerTask> timerTaskTriggers = new();
|
||||
|
||||
[SerializeField] private string timerName;
|
||||
private TimerTimeType type = TimerTimeType.Null;
|
||||
|
||||
public void SetTimer(string name, TimerTimeType type)
|
||||
{
|
||||
this.timerName = name + "_" + type;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private float GetTime()
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
TimerTimeType.Time => Time.time,
|
||||
TimerTimeType.UnscaledTime => Time.unscaledTime,
|
||||
TimerTimeType.RealtimeSinceStartup => Time.realtimeSinceStartup,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (timerTaskList.Count > 0)
|
||||
{
|
||||
timerTaskTriggers.Clear();
|
||||
foreach (var timerTask in timerTaskList.Where(timerTask => timerTask.isActive))
|
||||
{
|
||||
if (timerTask.isFrameUpdate)
|
||||
{
|
||||
timerTaskTriggers.Add(timerTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timerTask.time <= GetTime())
|
||||
{
|
||||
timerTaskTriggers.Add(timerTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var triggerTimerTask in timerTaskTriggers)
|
||||
{
|
||||
if (triggerTimerTask.repeatCount != INFINITE_LOOP)
|
||||
{
|
||||
triggerTimerTask.repeatCount--;
|
||||
}
|
||||
|
||||
if (triggerTimerTask.repeatCount == 0)
|
||||
{
|
||||
timerTaskList.Remove(triggerTimerTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!triggerTimerTask.isFrameUpdate)
|
||||
{
|
||||
triggerTimerTask.time = GetTriggerTime(triggerTimerTask.interval);
|
||||
}
|
||||
}
|
||||
|
||||
triggerTimerTask.CallFunc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TimerTask AddLoopTimer(float interval, Action<TimerTask> onCallBack, params object[] args)
|
||||
{
|
||||
var timeTask = new TimerTask(this, INFINITE_LOOP, interval, onCallBack, args);
|
||||
AddTimer(timeTask);
|
||||
return timeTask;
|
||||
}
|
||||
|
||||
public void AddTimer(TimerTask timerTask)
|
||||
{
|
||||
if (null != timerTask)
|
||||
{
|
||||
if (!timerTask.isFrameUpdate)
|
||||
{
|
||||
if (timerTask.interval <= 0)
|
||||
{
|
||||
timerTask.CallFunc();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
timerTaskList.Add(timerTask);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
timerTaskList.Clear();
|
||||
timerTaskTriggers.Clear();
|
||||
}
|
||||
|
||||
public float GetTriggerTime(float interval)
|
||||
{
|
||||
return GetTime() + interval;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearAll();
|
||||
timerTaskList = null;
|
||||
timerTaskTriggers = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1af09b65e6897dd4e8adcb89203638d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public static class TimerHelper
|
||||
{
|
||||
private static string name = "TimerHelper";
|
||||
|
||||
#region Time
|
||||
|
||||
private static EasyTimer sEasyTimer;
|
||||
private static Timer _Timer;
|
||||
private static NormalTimer sNormalTimer;
|
||||
|
||||
public static EasyTimer mEasy
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sEasyTimer == null)
|
||||
{
|
||||
sEasyTimer = TimerIManager.Instance.CreateSimpleTimer(name, TimerTimeType.Time);
|
||||
}
|
||||
|
||||
return sEasyTimer;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UnscaledTime
|
||||
|
||||
private static EasyTimer sUnscaledEasyTimer;
|
||||
private static Timer _UnscaledTimer;
|
||||
private static NormalTimer sUnscaledNormalTimer;
|
||||
|
||||
public static Timer UnscaleGeneral
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_UnscaledTimer == null)
|
||||
{
|
||||
_UnscaledTimer = TimerIManager.Instance.CreateTimer(name, TimerTimeType.UnscaledTime);
|
||||
}
|
||||
|
||||
return _UnscaledTimer;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RealtimeSinceStartup
|
||||
|
||||
private static EasyTimer sRealEasyTimer;
|
||||
private static Timer _RealTimer;
|
||||
private static NormalTimer sRealNormalTimer;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 889a363446c9d38489732b45d60696c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class UnitConvertUtil
|
||||
{
|
||||
public static string[] UnitSuffixs =
|
||||
{
|
||||
"", "K", "M", "B", "T", "aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj ", "ak", "al", "am", "an",
|
||||
"ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw", "ax", "ay", "az", "ba", "bb", "bc", "bd", "be", "bf",
|
||||
"bg", "bh", "bi", "bj", "bk", "bl", "bm", "bn", "bo", "bp", "bq", "br", "bs", "bt", "bu", "bv", "bw", "bx",
|
||||
"by", "bz", "ca", "cb", "cc", "cd", "ce", "cf", "cg", "ch", "ci", "cj", "ck", "cl", "cm", "cn", "co", "cp",
|
||||
"cq", "cr", "cs", "ct", "cu", "cv", "cw", "cx", "cy", "da", "db", "dc", "dd", "de", "df", "dg", "dh", "di",
|
||||
"dj", "dk", "dl", "dm", "dn", "do", "dp", "dq", "dr", "ds", "dt", "du", "dv", "dw", "dx", "dy"
|
||||
};
|
||||
|
||||
|
||||
public static string ConvertIntUnitStr(double value)
|
||||
{
|
||||
int count = GetDigitNumber(value);
|
||||
int unitNum = 0;
|
||||
while (count > 3)
|
||||
{
|
||||
count -= 3;
|
||||
value /= 1000;
|
||||
unitNum++;
|
||||
}
|
||||
|
||||
return (int)value + UnitSuffixs[unitNum];
|
||||
}
|
||||
|
||||
public static int GetDigitNumber(double value)
|
||||
{
|
||||
int count = 0;
|
||||
while (value > 1)
|
||||
{
|
||||
count++;
|
||||
value = value / 10;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public static string ConvertUnit(int value)
|
||||
{
|
||||
int unit = GetDigitNumber(value);
|
||||
if (unit > 0)
|
||||
{
|
||||
unit--;
|
||||
}
|
||||
|
||||
int unitIdx = 0;
|
||||
if (unit >= 6)
|
||||
{
|
||||
unitIdx = (int)Mathf.Ceil(unit / 3) - 1;
|
||||
}
|
||||
|
||||
unitIdx = Mathf.Min(unitIdx, UnitSuffixs.Length - 1);
|
||||
|
||||
float baseNum = Mathf.Pow(10, unitIdx * 3);
|
||||
string numToShow = Mathf.Ceil(value / baseNum).ToString();
|
||||
string numToShowString = string.Empty;
|
||||
int j = 0;
|
||||
for (int i = numToShow.Length - 1; i >= 0; i--)
|
||||
{
|
||||
j++;
|
||||
numToShowString = numToShow[i] + numToShowString;
|
||||
if (i != 0 && j % 3 == 0)
|
||||
{
|
||||
numToShowString = "," + numToShowString;
|
||||
}
|
||||
}
|
||||
|
||||
return numToShowString + UnitSuffixs[unitIdx];
|
||||
}
|
||||
|
||||
public static string ConvertNoDecimalUnit(double value, string symbol = ".")
|
||||
{
|
||||
int count = GetDigitNumber(value);
|
||||
int unitNum = 0;
|
||||
while (count > 7)
|
||||
{
|
||||
count -= 3;
|
||||
value /= 1000;
|
||||
unitNum++;
|
||||
}
|
||||
|
||||
string valueStr = value.ToString("f0");
|
||||
string unitStr = UnitSuffixs[unitNum];
|
||||
for (int i = 0; i < (valueStr.Length - 1) / 3; i++)
|
||||
{
|
||||
int index = valueStr.Length % 3 + i * ((valueStr.Length - 1) / 3) + i;
|
||||
valueStr = valueStr.Insert(index, symbol);
|
||||
}
|
||||
|
||||
if (valueStr.StartsWith(symbol))
|
||||
valueStr = valueStr.Remove(0, 1);
|
||||
return valueStr + unitStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d812f124e53f2548bc7aba6bf278bc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user