2025-06-07 17:43:34 +08:00

1190 lines
43 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Cysharp.Threading.Tasks;
using DG.Tweening;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public static class GlobalUtil
{
public static int[] Minutes_Seconds(float second)
{
int[] result = new int[2];
result[0] = Mathf.FloorToInt(second / 60f);
result[1] = Mathf.FloorToInt(second % 60f);
return result;
}
public static int[] Hour_Minutes_Seconds(float second)
{
int[] result = new int[3];
result[0] = (int)second / 3600;
result[1] = ((int)second - result[0] * 3600) / 60;
result[2] = (int)second - result[0] * 3600 - result[1] * 60;
return result;
}
//
// public static string Common_TimeFormat(float leftTime, bool isStandard = true)
// {
// var day = (int)leftTime / 60 / 60 / 24;
// var hour = (int)(leftTime - day * 60 * 60 * 24) / 60 / 60;
// if (isStandard == true)
// {
// var minute = (int)(leftTime - day * 60 * 60 * 24 - hour * 60 * 60) / 60;
// var second = (int)leftTime % 60;
// return string.Format(Framework.language.GetLangByID("common.time4"), day, hour, minute, second);
// }
// else
// {
// if (day >= 1) //超过1显示为 **天**小时
// {
// return string.Format(Framework.language.GetLangByID("common.time1"), day, hour);
// }
// var minute = (int)(leftTime - day * 60 * 60 * 24 - hour * 60 * 60) / 60;
// if (day < 1 && hour >= 1)
// {
// return string.Format(Framework.language.GetLangByID("common.time2"), hour, minute);
// }
// else
// {
// var second = (int)leftTime % 60;
// return string.Format(Framework.language.GetLangByID("common.time3"), minute, second);
// }
// }
// }
public static int Day(float second)
{
return Mathf.FloorToInt(second / 86400f);
}
#region UI相关
/// <summary>
/// 文本长度显示
/// </summary>
/// <param name="tx"></param>
/// <param name="count"></param>
public static void SetText_Count(this Text tx, int count)
{
/* if (count > 9999)
tx.text = $"x9999+";
else
tx.text = $"x{count}";*/
tx.text = $"x{SetFormatNum(count)}";
}
public static async void ForceRebuildLayoutImmediate(GameObject go)
{
//await Task.Delay(1);
var list = go.GetComponentsInChildren<RectTransform>(true);
//Debug.LogError("ForceRebuildLayoutImmediate.list.Lenth==" + list.Length);
for (int i = list.Length - 1; i <= 0; i--)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(list[i]);
}
LayoutRebuilder.ForceRebuildLayoutImmediate(go.GetComponent<RectTransform>());
}
#endregion
#region DOTween
public static Tweener DOScale_zero(this Transform target, Vector3 endValue, float duration)
{
target.transform.localScale = Vector3.zero;
return target.DOScale(endValue, duration);
}
#endregion
public static T FromJson<T>(this string jsonString)
{
return JsonConvert.DeserializeObject<T>(jsonString);
}
/// <summary>
/// 判断阶级是否足够
/// </summary>
/// <param name="hero"></param>
/// <returns></returns>
// public static bool GetIsUp_Str(HeroData hero)
// {
// var config = Config_Hero.GetItem(hero.heroId);
// var item = Config_HeroRank.GetItem(config.colour, hero.rank);
// return hero.level < item.maxLv;
// }
/// <summary>
/// 升阶条件判断(是否可升阶)
/// </summary>
/// <returns></returns>
// public static bool GetIsUpStar(HeroData hero)
// {
// var heroCfg = Config_Hero.GetItem(hero.heroId);
// var rank = Config_HeroRank.GetItem(heroCfg.colour, hero.rank);
// string[] strs = rank.specialEffect.Split(',');
// switch (strs[0])
// {
// case "lvHeroCount":
// var lv = int.Parse(strs[1]);
// var num = int.Parse(strs[2]);
//
// var cardNum = 0;
// foreach (var card in Game.account.heroDatas)
// if (card.Value.level >= lv)
// cardNum++;
//
// if (cardNum >= num)
// return true;
//
// UITool.OpenTips($"必须有{num}个{lv}级英雄。");
// break;
// }
// return false;
// }
/// <summary>
/// 是否可升星
/// </summary>
// public static bool GetIsUpStar2(HeroData hero)
// {
// var allStars = Config_HeroSkill.GetItems(hero.heroId);
// bool isMax = hero.starLevel >= allStars[allStars.Count - 1].star;
// if (isMax) return false;//星级已满
//
// /// 同阵营同星级
// HashSet<long> hs_zhen_star = new HashSet<long>();
//
// /// 同模版同星级
// HashSet<long> hs_m_star = new HashSet<long>();
//
// var heroConfig = Config_Hero.GetItem(hero.heroId);
// var skillConfig = Config_HeroSkill.GetItem(hero.heroId, hero.starLevel);
// var starConfig = Config_HeroStar.GetItem(heroConfig.colour, hero.starLevel);
//
// int moBan_starNum, moBan_count, zhen_starNum, zhen_count;
//
// //显示升星材料
// var strs = starConfig.consume.Split(';').Where((s) => !string.IsNullOrEmpty(s)).ToArray();
// for (int index = 0; index < strs.Length; index++)
// {
// var ins_strs = strs[index].Split(',');
//
// var v_type = ins_strs[0];
// var v_star = int.Parse(ins_strs[1]);
// var v_num = int.Parse(ins_strs[2]);
//
// if (v_type == "sameTp")//同模版X星级
// {
// moBan_starNum = v_star;
// moBan_count = v_num;
//
// var config_icon = Config_FakeItem.GetItem(heroConfig.item_icon);
// }
// else if (v_type == "sameCamp")//同阵营X星级
// {
// zhen_starNum = v_star;
// zhen_count = v_num;
// }
//
// }
//
//
//
// //bool GetIs
// return false;
//
// }
/// <summary>
/// 升级道具是否足够
/// </summary>
/// <returns></returns>
// public static bool GetIsUp_Prop(HeroData hero, int[] up_ids = null)
// {
// if (up_ids == null)
// up_ids = Config_GlobalAtt.GetItem("resetBioExpItemIds").value.Split(';').Select(int.Parse).ToArray();
//
// //判断是否可升级
// var config_level = Config_HeroLevel.GetItem(hero.level);
// var config = Config_Hero.GetItem(hero.heroId);
// var config_rank = Config_HeroRank.GetItem(config.colour, hero.rank);
// int exp = 0;
// switch (config_rank.afterColour)
// {
// case 2: exp = config_level.expColour2; break;
// case 3: exp = config_level.expColour3; break;
// case 4: exp = config_level.expColour4; break;
// case 5: exp = config_level.expColour5; break;
// }
//
// int allPropExp = 0;
// //升级道具
// foreach (var id in up_ids)
// {
// var prop = Config_PropItem.GetItem(id);
// string[] strs = prop.useLogic.Split(';');
// foreach (string str in strs)
// {
// string[] strs2 = str.Split(",");
// if (strs2.Length == 3 && strs2[0] == "heroExp")
// {
// int addExp = int.Parse(strs2[2]);
// allPropExp += addExp * Game.backpack.GetCount(prop.itemId);
// }
// }
//
// }
// //if (!(allPropExp >= exp))
// // Debug.Log($"还差:{exp - allPropExp}");
// return allPropExp >= exp;
// }
/// <summary>
/// 神器升级道具是否足够
/// </summary>
/// <returns></returns>
// public static bool GetRelicIsUp_Prop(ArtifactData data, int[] up_ids = null)
// {
// if (up_ids == null)
// up_ids = Config_GlobalAtt.GetItem("resetRelicExpItemIds").value.Split(';').Select(int.Parse).ToArray();
//
// //判断是否可升级
// var config = Config_Relic.GetItem(data.petId);
// var config_level = Config_RelicLevel.GetItem(config.colour, data.level);
//
// int exp = config_level.exp;
//
// int allPropExp = 0;
// //升级道具
// foreach (var id in up_ids)
// {
// var prop = Config_PropItem.GetItem(id);
// string[] strs = prop.useLogic.Split(';');
// foreach (string str in strs)
// {
// string[] strs2 = str.Split(",");
// if (strs2.Length == 2 && strs2[0] == "relicExp")
// {
// int addExp = int.Parse(strs2[1]);
// allPropExp += addExp * Game.backpack.GetCount(prop.itemId);
// }
// }
//
// }
//
// return allPropExp >= exp;
// }
/// <summary>
/// 计算神器升级使用道具
/// </summary>
/// <returns> 道具uuid, 数量 </returns>
// public static Tuple<long, int>[] GetRelicUpProp(ArtifactData data, int[] up_ids = null)
// {
// if (up_ids == null)
// up_ids = Config_GlobalAtt.GetItem("resetRelicExpItemIds").value.Split(';').Select(int.Parse).ToArray();
//
// //判断是否可升级
// var config = Config_Relic.GetItem(data.petId);
// var config_level = Config_RelicLevel.GetItem(config.colour, data.level);
//
// int exp = config_level.exp;
//
// var list = new List<Tuple<long, int, int>>();
//
// //升级道具
// foreach (var id in up_ids)
// {
// var prop = Config_PropItem.GetItem(id);
// string[] strs = prop.useLogic.Split(';');
//
// foreach (string str in strs)
// {
// string[] strs2 = str.Split(",");
// if (strs2.Length == 2 && strs2[0] == "relicExp")
// {
// var item = Game.backpack.GetItem(id);
// if (item != null && item.count > 0)
// list.Add(Tuple.Create(item.uuid, int.Parse(strs2[1]), item.count));
// break;
// }
// }
//
//
// }
//
// return FindItemsToLevelUp(list, exp);
// }
/// <summary>
/// 计算使用道具
/// </summary>
/// <returns> 道具uuid, 数量 </returns>
// public static Tuple<long, int>[] GetUpProp(HeroData hero, int[] up_ids = null)
// {
// if (up_ids == null)
// up_ids = Config_GlobalAtt.GetItem("resetBioExpItemIds").value.Split(';').Select(int.Parse).ToArray();
//
// var config_level = Config_HeroLevel.GetItem(hero.level);
// var config = Config_Hero.GetItem(hero.heroId);
// var config_rank = Config_HeroRank.GetItem(config.colour, hero.rank);
// int exp = 0;
// switch (config_rank.afterColour)
// {
// case 2: exp = config_level.expColour2; break;
// case 3: exp = config_level.expColour3; break;
// case 4: exp = config_level.expColour4; break;
// case 5: exp = config_level.expColour5; break;
// }
//
// var list = new List<Tuple<long, int, int>>();
//
// //升级道具
// foreach (var id in up_ids)
// {
// var prop = Config_PropItem.GetItem(id);
// string[] strs = prop.useLogic.Split(';');
//
// foreach (string str in strs)
// {
// string[] strs2 = str.Split(",");
// if (strs2.Length == 3 && strs2[0] == "heroExp")
// {
// var item = Game.backpack.GetItem(id);
// if (item != null && item.count > 0)
// list.Add(Tuple.Create(item.uuid, int.Parse(strs2[2]), item.count));
// break;
// }
// }
//
//
// }
//
// return FindItemsToLevelUp(list, exp);
// }
/// <summary>
/// 计算需要使用的道具
/// </summary>
/// <param name="items"> Item1:道具UUIDItem2: 增加的经验值Item3:拥有的数量</param>
/// <param name="exp">升级所需经验值</param>
/// <returns>Item1:道具UUID, Item2:使用数量</returns>
public static Tuple<long, int>[] FindItemsToLevelUp(List<Tuple<long, int, int>> items, int expToNextLevel)
{
items.Sort((a, b) => a.Item2.CompareTo(b.Item2)); // 按经验值从小到大排序
var result = new List<Tuple<long, int>>();
int totalExp = 0;
// 首先尝试使用最低经验的道具
foreach (var item in items)
{
long itemId = item.Item1;
int itemExp = item.Item2;
int itemCount = item.Item3;
int neededCount = Math.Min((expToNextLevel - totalExp + itemExp - 1) / itemExp, itemCount);
if (neededCount > 0)
{
result.Add(Tuple.Create(itemId, neededCount));
totalExp += neededCount * itemExp;
if (totalExp >= expToNextLevel)
return result.ToArray();
}
}
// 如果最低经验道具不足,则尝试使用更高经验的道具
if (totalExp < expToNextLevel)
{
result.Clear();
totalExp = 0;
foreach (var item in items)
{
long itemId = item.Item1;
int itemExp = item.Item2;
int itemCount = item.Item3;
int neededCount = Math.Min((expToNextLevel - totalExp + itemExp - 1) / itemExp, itemCount);
if (neededCount > 0)
{
result.Add(Tuple.Create(itemId, neededCount));
totalExp += neededCount * itemExp;
if (totalExp >= expToNextLevel)
break;
}
}
}
return result.ToArray();
}
public static Vector2 GetPivotByScreenClick(Vector2 click)
{
float x = 0f;
float y = 0f;
if (click.x > Screen.width / 2)
x = 1f;
if (click.y > Screen.height / 2)
y = 1f;
return new Vector2(x, y);
}
public static void LogDouble(string title, string info)
{
Debug.Log($"<color=#861b2d>{title}</color> |- <i><color=#c5c870>{info}</color></i>");
}
public static void LogDouble_Blue(string title, string info)
{
Debug.Log($"<color=#861b2d>{title}</color> |- <i><color=#9cd3d1>{info}</color></i>");
}
public static void LogDouble(string title, string info, string info2)
{
Debug.Log($"<color=#861b2d>{title}</color> |- <color=#BB1b2d>{info}</color> <i><color=#70c870>{info2}</color></i>");
}
public static void LogDouble(string title, string info, string info2, string info3)
{
Debug.Log($"<color=#861b2d>{title}</color> |- <color=#BB1b2d>{info}</color> <i><color=#70c870>{info2}</color></i> <color=#c1c477>{info3}</color>");
}
public static void Log_OpenUI_Light2(string title, string info1, string info2)
{
Debug.Log($"<color=#f19849>{title}</color> <color=#baeafb>{info1}</color> |- <i><color=#c5c870>{info2}</color></i>");
}
public static void Log_OpenUI_Light(string title, string info1, string info2)
{
Debug.Log($"<color=#962b3d>{title}</color> <color=#fc9f5f>{info1}</color> |- <i><color=#c5c870>{info2}</color></i>");
}
public static void Log_OpenUI_Drak(string title, string info1, string info2)
{
Debug.Log($"<color=#70755e>{title}</color> <color=#dc7f3f>{info1}</color> |- <i><color=#a57880>{info2}</color></i>");
}
public static void LogDouble_Magenta(string title, string info)
{
Debug.Log($"<color=#861b2d>{title}</color> |- <i><color=magenta>{info}</color></i>");
}
public static void LogDoubleError(string title, string info)
{
Debug.LogError($"<color=#861b2d>{title}</color> |- <color=#BB1b2d>{info}</color>");
}
public static void LogDoubleError(string title, string info, string info2)
{
Debug.LogError($"<color=#861b2d>{title}</color> |- <color=#BB1b2d>{info}</color> <i><color=#70c870>{info2}</color></i>");
}
public static void LogDoubleError_ExcelBug(string title, object info)
{
Debug.LogError($"<color=#cd97f9>{title}</color> |- <color=#ffc000>{info}</color>");
}
public static void LogDoubleError_ExcelBug(string title, object info, object info2)
{
Debug.LogError($"<color=#cd97f9>{title}</color> |- <color=#ffc000>{info}</color> <i><color=#70c870>{info2}</color></i>");
}
public static void LogDouble_Green(string title, string info, string info2)
{
Debug.Log($"<color=#861b2d>{title}</color> |- <color=#BB1b2d>{info}</color> <i><color=#70c870>{info2}</color></i>");
}
public static void LogDouble_Yelow(string title, string info, string info2)
{
Debug.Log($"<color=#861b2d>{title}</color> |- <color=#BB1b2d>{info}</color> <i><color=#c1c477>{info2}</color></i>");
}
public static void ClearConsole()
{
#if UNITY_EDITOR
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(UnityEditor.SceneView));
System.Type logEntries = assembly.GetType("UnityEditor.LogEntries");
System.Reflection.MethodInfo clearConsoleMethod = logEntries.GetMethod("Clear");
clearConsoleMethod.Invoke(new object(), null);
#endif
}
/// <summary>
/// 转百分比
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
[Obsolete("停止使用")]
public static string ToPercentage(this float number)
{
// 将浮点数乘以100
float percentageValue = number * 100;
// 使用CultureInfo.InvariantCulture确保使用不依赖于当前文化的字符串格式
// "0.##" 格式确保最多保留两位小数
string formattedValue = percentageValue.ToString("0.##", CultureInfo.InvariantCulture) + "%";
return formattedValue;
}
/// <summary>
/// 显示属性
/// </summary>
[Obsolete("停止使用")]
public static string ToAtt(this string att, int type)
{
return int.Parse(att).ToAtt(type);
}
/// <summary>
/// 显示属性
/// </summary>
[Obsolete("停止使用")]
public static string ToAtt(this int att, int type, string fq = "v")
{
if (att == 0) return (type == 1 || fq == "q") ? "0%" : "0";
if (type == 1 || fq == "q")
return (att / 1000f).ToPercentage();
else
return att.ToString();
}
public static string GetSkillType(int typeII)
{
switch (typeII)
{
case 0:
return "普";
case 1:
return "密";
case 2:
return "必";
case 3:
return "被";
case 4:
return "神";
}
return "无";
}
/// <summary>
/// 显示星星
/// </summary>
public static void ShowSart(Transform starItem, int num)
{
if (num == 0)
{
starItem.parent.gameObject.SetActive(false);
return;
}
else
starItem.parent.gameObject.SetActive(true);
if (num <= 5)
{
starItem.ForParent(num, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star(img, 0);
img.color = Color.white;
});
}
else if (num <= 10)
{
starItem.ForParent(num - 5, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star(img, 1);
img.color = Color.white;
});
}
else if (num <= 15)
{
starItem.ForParent(num - 10, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star(img, 2);
img.color = Color.white;
});
}
else if (num <= 20)
{
starItem.ForParent(num - 15, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star(img, 3);
img.color = Color.white;
});
}
else
{
starItem.ForParent(num - 20, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star(img, 4);
img.color = Color.white;
});
}
starItem.parent.gameObject.SetActive(num > 0);
}
/// <summary>
/// 显示星星
/// </summary>
public static void ShowSart_white(Transform starItem, int num)
{
if (num <= 5)
starItem.ForParent(num, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star_White(img, 0);
img.color = new Color32(58, 57, 53, 255);
});
else if (num <= 10)
starItem.ForParent(num - 5, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star_White(img, 1);
img.color = new Color32(58, 57, 53, 255);
});
else if (num <= 15)
starItem.ForParent(num - 10, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star_White(img, 2);
img.color = new Color32(58, 57, 53, 255);
});
else if (num <= 20)
starItem.ForParent(num - 15, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star_White(img, 3);
img.color = new Color32(58, 57, 53, 255);
});
else
starItem.ForParent(num - 20, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star_White(img, 4);
img.color = new Color32(58, 57, 53, 255);
});
}
/// <summary>
/// 神器显示0星
/// </summary>
public static void ShowSart_Zero(Transform starItem)
{
starItem.ForParent(5, (tr, index) =>
{
var img = tr.GetComponent<Image>();
RewardUtil.SetSprite_Star_White(img, 0);
//img.SetSprite_Star_White(0);
img.color = new Color32(93, 91, 88, 255);
});
}
//public static bool GetCondition_Hero(string text, HeroData hero)
//{
// if (hero == null) return true;
// MatchCollection matches = Regex.Matches(text, @"(\w+):(\d+)");
// foreach (Match match in matches)
// {
// // 提取键和值
// string key = match.Groups[1].Value;
// int value = int.Parse(match.Groups[2].Value);
// switch (key)
// {
// case "lv":
// if (hero.level < value) return false;
// break;
// case "star":
// if (hero.starLevel < value) return false;
// break;
// }
// }
// return true;
//}
//public static bool GetCondition_Relic(string text, ArtifactData relic)
//{
// if (relic == null) return true;
// MatchCollection matches = Regex.Matches(text, @"(\w+):(\d+)");
// foreach (Match match in matches)
// {
// // 提取键和值
// string key = match.Groups[1].Value;
// int value = int.Parse(match.Groups[2].Value);
// switch (key)
// {
// case "lv":
// if (relic.level < value) return false;
// break;
// case "star":
// if (relic.star < value) return false;
// break;
// }
// }
// return true;
//}
//static bool GetCondition_Hero2(string text, HeroData hero)
//{
// if (hero == null) return true;
// MatchCollection matches = Regex.Matches(text, @"(\w+),(\d+)");
// foreach (Match match in matches)
// {
// // 提取键和值
// string key = match.Groups[1].Value;
// int value = int.Parse(match.Groups[2].Value);
// switch (key)
// {
// case "lv":
// if (hero.level < value) return false;
// break;
// case "star":
// if (hero.starLevel < value) return false;
// break;
// }
// }
// return true;
//}
/// <summary>
/// 显示神器图标
/// </summary>
// public static void ShowRelicIcons(Transform[] relicContents, List<int> ids)
// {
// //显示神器
// if (ids.Count == 0)
// {
// foreach (var item in relicContents)
// if (item != null)
// item.gameObject.SetActive(false);
// }
// else
// {
// var content = relicContents[ids.Count - 1];
//
// for (int i = 0; i < relicContents.Length; i++)
// relicContents[i].gameObject.SetActive(i == ids.Count - 1);
//
// content.ForChild(async (tr, index) =>
// {
// var relicCfg = Config_Relic.GetItem(ids[index]);
// var img = content.GetChild(index).GetComponent<Image>();
// await RewardUtil.SetSprite_RelicIcon_Small(img, relicCfg.img2);
// //await img.SetSprite_RelicIcon_Small(relicCfg.img2);
// img.SetNativeSize();
// img.gameObject.SetActive(true);
// img.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);
// //岩柱神器 做特殊处理
// if (relicCfg.id == 9)
// switch (ids.Count)
// {
// case 1:
// img.transform.localPosition = new Vector3(78, 90, 0);
// img.transform.localScale = new Vector3(1.3f, 1.3f, 1.3f);
// break;
// case 2:
// switch (index)
// {
// case 0:
// img.transform.localPosition = new Vector3(-119, 31, 0);
// img.transform.localScale = new Vector3(-1.2f, 1.2f, 1.2f);
// break;
//
// case 1:
// img.transform.localPosition = new Vector3(128, 23, 0);
// img.transform.localScale = new Vector3(1.26f, 1.26f, 1.26f);
// break;
// }
// break;
// case 3:
// switch (index)
// {
// case 0:
// img.transform.localPosition = new Vector3(-136, 20, 0);
// img.transform.localScale = new Vector3(-1.2f, 1.2f, 1.2f);
// break;
//
// case 1:
// img.transform.localPosition = new Vector3(66, 82, 0);
// img.transform.localScale = new Vector3(1f, 1f, 1f);
// break;
//
// case 2:
// img.transform.localPosition = new Vector3(147, 6, 0);
// img.transform.localScale = new Vector3(1f, 1f, 1f);
// break;
// }
//
// break;
//
// }
// else
// switch (ids.Count)
// {
// case 1:
// img.transform.localPosition = new Vector3(12, 50, 0);
// img.transform.localScale = new Vector3(1.3f, 1.3f, 1.3f);
// break;
// case 2:
// switch (index)
// {
// case 0:
// img.transform.localPosition = new Vector3(-37, 43, 0);
// img.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);
// break;
//
// case 1:
// img.transform.localPosition = new Vector3(68, 57, 0);
// img.transform.localScale = new Vector3(1.26f, 1.26f, 1.26f);
// break;
// }
// break;
// case 3:
// switch (index)
// {
// case 0:
// img.transform.localPosition = new Vector3(-67, 11, 0);
// img.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);
// break;
// case 1:
// img.transform.localPosition = new Vector3(11, 59, 0);
// img.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);
// break;
// case 2:
// img.transform.localPosition = new Vector3(73, 3, 0);
// img.transform.localScale = new Vector3(1.4f, 1.4f, 1.4f);
// break;
// }
// break;
// }
// });
// }
// }
//
// public static string GetLangByJson(this LanguageJson_UTFP utfp)
// {
// return Framework.language.GetLangByJson(utfp);
// }
//
// [Obsolete("停止使用")]
// public static void SetText_Power(this Text tx, long power)
// {
// if (power >= 100000000) // 大于等于1亿时用亿为单位保留小数点后1位
// tx.text = (power / 100000000f).ToString("F1") + "亿";
// else if (power >= 100000) // 大于等于10万且小于1亿时用万为单位保留小数点后1位
// tx.text = (power / 10000f).ToString("F1") + "万";
// else
// tx.text = power.ToString(); // 小于10万时直接显示
// }
//
// public static bool SetGoodsCountDown(ShopGoodData data, GameObject go, LanguageDownTime ldt, OnDownTimeCallBack callBack = null)
// {
// double leftTime = 0.0f;
// double refreshTime = data.refreshGoodsCountTime == "-1" ? -1 : double.Parse(data.refreshGoodsCountTime) - double.Parse(data.goodsTimeLimitNowTime);
// double limitTime = string.IsNullOrEmpty(data.goodsTimeLimitEndTime) ? 0 : double.Parse(data.goodsTimeLimitEndTime) - double.Parse(data.goodsTimeLimitNowTime);
// var srCfg = Config_ShopReplenishment.GetItem(data.limitBuyId);
// if (srCfg == null || refreshTime == -1) //非限购 或 限购但不需补货
// {
// if (limitTime > 0) //限时
// leftTime = limitTime;
// }
// else
// {
// if (limitTime > 0) //限时
// leftTime = refreshTime > limitTime ? limitTime : refreshTime; //取小的
// else
// leftTime = refreshTime;
// }
//
// if (leftTime > 0)
// {
// go.SetActive(true);
// ldt.callBack = callBack;
// ldt.timeUnitType = TimeUnitType.Common;
// ldt.i18n = ""; //"shop.leftTime";
// ldt.SetTime((float)leftTime / 1000, true);
// ldt.RefDownTime();
// return true;
// }
// else
// {
// ldt.SetTime(0, false);
// go.SetActive(false);
// return false;
// }
// }
// public static int CreateAttr(Transform clone, int value, string type, string k, int idx, AttrData attrData = null, bool isZeroShow = false, bool isZeroCreate = false, bool prefix = false)
// {
// if (isZeroCreate == false && value == 0)
// return 0;
// else
// {
// attrData = attrData ?? new AttrData();
// var cfg = Config_BonusProperty.GetItem(k);
// if (type == "v" || type == "fv")
// {
// CreateAttrObj(clone, idx, value, (tr) =>
// {
// tr.Find("value").GetComponent<Text>().text = (value > 0 && prefix == true ? "+" : "") + value.ToString().ToAtt(cfg.type);
// tr.Find("name").GetComponent<Text>().text = Framework.language.GetLangByID(cfg.text_i18);
// tr.Find("icon").GetComponent<Image>().SetAtlasSprite("Assets/Art/UI/Picture/Attribute/atlas_Attribute", cfg.icon);
//
// if (tr.Find("ga_nextLv") != null)
// {
// var nextValue = type == "v" ? attrData.v : attrData.fv;
// tr.Find("ga_nextLv").gameObject.SetActive(nextValue > value);
// tr.Find("ga_nextLv/tx_nextLv").GetComponent<Text>().text = nextValue.ToString().ToAtt(cfg.type); // + (Game.gsAttr.IsPercent(k) ? "%" : "");
// }
// }, isZeroShow, isZeroCreate);
// return 1;
// }
// else if (type == "q" || type == "fq")
// {
// CreateAttrObj(clone, idx, value, (tr) =>
// {
// tr.Find("value").GetComponent<Text>().text = (value > 0 && prefix == true ? "+" : "") + (value / 1000f).ToPercentage(); // + "%";
// tr.Find("name").GetComponent<Text>().text = Framework.language.GetLangByID(cfg.text_i18);
// tr.Find("icon").GetComponent<Image>().SetAtlasSprite("Assets/Art/UI/Picture/Attribute/atlas_Attribute", cfg.icon);
//
// if (tr.Find("ga_nextLv") != null)
// {
// var nextValue = type == "q" ? attrData.q : attrData.fq;
// tr.Find("ga_nextLv").gameObject.SetActive(nextValue > value);
// tr.Find("ga_nextLv/tx_nextLv").GetComponent<Text>().text = (nextValue / 1000f).ToPercentage();
// }
// }, isZeroShow, isZeroCreate);
// return 1;
// }
// else
// return 0;
// }
// }
public static void CreateAttrObj(Transform clone, int idx, int value, Action<Transform> onCreate, bool isZeroShow = false, bool isZeroCreate = false)
{
Transform tr;
if (idx < clone.parent.childCount)
tr = clone.parent.GetChild(idx);
else
tr = GameObject.Instantiate(clone.gameObject, clone.parent).transform;
tr.gameObject.SetActive(true);
if (isZeroShow == false && value == 0)
tr.ForChild((child, idx) => child.gameObject.SetActive(false));
else
{
tr.ForChild((child, idx) => child.gameObject.SetActive(true));
onCreate.Invoke(tr);
}
}
public static string SetFormatNum(long num)
{
if (Math.Abs(num) < 100000)
return num.ToString();
else if (Math.Abs(num) >= 100000 && Math.Abs(num) < 1000000)
return (Math.Abs(num) / 10000f).ToString("F1") + "W";
else if (Math.Abs(num) >= 1000000 && Math.Abs(num) < 1000000000)
return (Math.Abs(num) / 1000000f).ToString("F1") + "M";
else
return (Math.Abs(num) / 1000000000f).ToString("F1") + "G";
}
public static string SetFormatPower(long power)
{
if (power >= 100000000) // 大于等于1亿时用亿为单位保留小数点后1位
return (power / 100000000f).ToString("F1") + "亿";
else if (power >= 100000) // 大于等于10万且小于1亿时用万为单位保留小数点后1位
return (power / 10000f).ToString("F1") + "万";
else
return power.ToString(); // 小于10万时直接显示
}
public static string SetFormatDate(string time)
{
DateTime utcDateTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(time)).UtcDateTime;
TimeZoneInfo targetTimeZone = TimeZoneInfo.Local;
DateTime localDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, targetTimeZone);
return localDateTime.ToString("yyyy-MM-dd-HH:mm");
}
public static string SetFormatTokenNum(long num)
{
if (Math.Abs(num) < 100000000)
return num.ToString();
else
return (Math.Abs(num) / 10000f).ToString("F0") + "W";
}
//布阵限制/星数条件
// public static bool TeamSetupConditionFilter(string condition, List<HeroData> cards, HeroData card = null)
// {
// string i18n;
// return TeamSetupConditionFilter(condition, cards, card, out i18n);
// }
//
// public static bool TeamSetupConditionFilter(string condition, List<HeroData> cards, HeroData card, out string i18n)
// {
// i18n = "";
// var str = condition.Split(',');
// var state = false;
// switch (str[0])
// {
// case "hpPerUp":
// case "pkLimitTime":
// case "maxDeadCount":
// case "win":
// case "allCarLive":
// state = true;
// break;
// case "joinBanClan":
// if (card != null)
// state = IsJoinBanClan(str, new List<HeroData> { card }, out i18n);
// else
// state = IsJoinBanClan(str, cards, out i18n);
// break;
// case "joinClanCount":
// state = IsJoinClanCount(str, cards, card, out i18n);
// break;
// case "joinLimitClan":
// if (card != null)
// state = IsJoinLimitClan(str, new List<HeroData> { card }, out i18n);
// else
// state = IsJoinLimitClan(str, cards, out i18n);
// break;
// default:
// state = true;
// break;
// }
// return state;
// }
//禁用xx阵营角色, 阵营1#阵营2...
// static bool IsJoinBanClan(string[] str, List<HeroData> nodes, out string i18n)
// {
// i18n = "";
// var clans = str[1].Split('#');
// //var nodes = nodes_left.GetAllNodes();
// foreach (var item in nodes)
// {
// var cfg = Config_Hero.GetItem(item.heroId);
// foreach (var item2 in clans)
// {
// if (cfg.tankClans == item2)
// {
// var clanCfg = Config_HeroClan.GetItem(int.Parse(cfg.tankClans));
// i18n = string.Format(Framework.language.GetLangByID("teamsetup.limit.joinBanClan"), Framework.language.GetLangByID(clanCfg.name_i18));
// return false;
// }
// }
// }
// return true;
// }
//xx阵营角色不能多余xx名 阵营#数量
// static bool IsJoinClanCount(string[] str, List<HeroData> nodes, HeroData node, out string i18n)
// {
// i18n = "";
// var clanCountStr = str[1].Split('#');
// var count = 0;
// //var nodes = nodes_left.GetAllNodes();
// //var flag = false;
// foreach (var item in nodes)
// {
// var cfg = Config_Hero.GetItem(item.heroId);
// if (cfg.tankClans == clanCountStr[0])
// {
// /*if (node != null && item.heroUUID == node.heroUUID) //忘记用来做什么了 @许杰涛
// flag = true;*/
// count++;
// }
// }
// if (count > int.Parse(clanCountStr[1]))
// {
// var clanCfg = Config_HeroClan.GetItem(int.Parse(clanCountStr[0]));
// i18n = string.Format(Framework.language.GetLangByID("teamsetup.limit.joinClanCount"), Framework.language.GetLangByID(clanCfg.name_i18), clanCountStr[1]);
// }
// /* if (!flag)
// return true;
// else*/
// return count <= int.Parse(clanCountStr[1]);
// }
//只能使用xx阵营的角色挑战副本 阵营1#阵营2...
// static bool IsJoinLimitClan(string[] str, List<HeroData> nodes, out string i18n)
// {
// i18n = "";
// var clans = str[1].Split('#');
// //var nodes = nodes_left.GetAllNodes();
// var state = true;
// foreach (var item in nodes)
// {
// var cfg = Config_Hero.GetItem(item.heroId);
// if (!clans.Contains(cfg.tankClans))
// {
// state = false;
// break;
// }
// }
// if (!state)
// {
// var str2 = "";
// foreach (var item2 in clans)
// {
// var clanCfg = Config_HeroClan.GetItem(int.Parse(item2));
// str2 += Framework.language.GetLangByID(clanCfg.name_i18);
// }
// for (int i = 0; i < clans.Length; i++)
// {
// var clanCfg = Config_HeroClan.GetItem(int.Parse(clans[i]));
// str2 += Framework.language.GetLangByID(clanCfg.name_i18) + ((i != clans.Length - 1) ? "/" : "");
// }
// i18n = string.Format(Framework.language.GetLangByID("teamsetup.limit.joinLimitClan"), str2);
// }
// return state;
// }
#region
public static long GetCurrentTimeStamp()
{
DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long currentTimestamp = (long)(DateTime.UtcNow - epochStart).TotalMilliseconds;
return currentTimestamp;
}
public static double GetCurrentTimeStampSeconds()
{
DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return (DateTime.UtcNow - epochStart).TotalSeconds;
//return currentTimestamp;
}
#endregion
}