2656 lines
96 KiB
C#
2656 lines
96 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using Games.ChatHistory;
|
||
using Games.Fellow;
|
||
using Games.GlobeDefine;
|
||
using Games.Item;
|
||
using Games.TitleInvestitive;
|
||
using Games.UserCommonData;
|
||
using GCGame.Table;
|
||
using Module.Log;
|
||
using UnityEngine;
|
||
using UnityEngine.AI;
|
||
using UnityEngine.UI;
|
||
using Object = UnityEngine.Object;
|
||
using Random = UnityEngine.Random;
|
||
|
||
namespace GCGame
|
||
{
|
||
public class Utils
|
||
{
|
||
public enum ChatGender
|
||
{
|
||
Male,
|
||
Female
|
||
}
|
||
|
||
public enum RemainTimesType
|
||
{
|
||
Day = 1,
|
||
Day_Hour = 2,
|
||
Day_Hour_Minutes = 3,
|
||
Day_Hour_Minutes_Second = 4,
|
||
Hour_Minute = 5,
|
||
Hour_Minute_Second = 6
|
||
}
|
||
|
||
public enum ShareType
|
||
{
|
||
ShareType_Invalid = -1,
|
||
ShareType_SNS = 0, //SNS
|
||
ShareType_NanGua = 1, //南瓜
|
||
ShareType_Num
|
||
}
|
||
|
||
public enum SysIconType
|
||
{
|
||
None,
|
||
AI,
|
||
Sys,
|
||
Guild
|
||
}
|
||
|
||
private static readonly int _gradeDescStrId = 43070;
|
||
|
||
public static DateTime m_startTime = new DateTime(1970, 1, 1);
|
||
|
||
//本次登陆是否提示
|
||
private static bool tipsState = true;
|
||
|
||
/// <summary>
|
||
/// 按照规则严格进行分割
|
||
/// </summary>
|
||
/// <param name="str">原始字符</param>
|
||
/// <param name="nTypeList">字符串类型</param>
|
||
/// <param name="regix">规则词,只有一个</param>
|
||
/// <returns>返回分割的词</returns>
|
||
public static string[] MySplit(string str, string[] nTypeList, string regix)
|
||
{
|
||
if (string.IsNullOrEmpty(str)) return null;
|
||
var content = new string[nTypeList.Length];
|
||
var nIndex = 0;
|
||
var nstartPos = 0;
|
||
while (nstartPos <= str.Length)
|
||
{
|
||
var nsPos = str.IndexOf(regix, nstartPos);
|
||
if (nsPos < 0)
|
||
{
|
||
var lastdataString = str.Substring(nstartPos);
|
||
if (string.IsNullOrEmpty(lastdataString) && nTypeList[nIndex].ToLower() != "string")
|
||
content[nIndex++] = "--";
|
||
else
|
||
content[nIndex++] = lastdataString;
|
||
break;
|
||
}
|
||
|
||
if (nstartPos == nsPos)
|
||
{
|
||
if (nTypeList[nIndex].ToLower() != "string")
|
||
content[nIndex++] = "--";
|
||
else
|
||
content[nIndex++] = "";
|
||
}
|
||
else
|
||
{
|
||
content[nIndex++] = str.Substring(nstartPos, nsPos - nstartPos);
|
||
}
|
||
|
||
nstartPos = nsPos + 1;
|
||
}
|
||
|
||
return content;
|
||
}
|
||
|
||
public static string GetPlayerStringGuid()
|
||
{
|
||
var GUID = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid;
|
||
var serverId = (short) (GUID >> 48);
|
||
var low = (int) (GUID & 0xFFFFFFFF);
|
||
|
||
var result = new StringBuilder();
|
||
while (low > 0)
|
||
{
|
||
var remainder = low % 26;
|
||
result.Append((char) (remainder + 97)); //A -> 65
|
||
low /= 26;
|
||
}
|
||
|
||
for (var index = 0; index < result.Length / 2; index++)
|
||
{
|
||
var temp = result[index];
|
||
result[index] = result[result.Length - index - 1];
|
||
result[result.Length - index - 1] = temp;
|
||
}
|
||
|
||
var str = result.ToString();
|
||
return string.Format("{0}{1}", serverId, str);
|
||
}
|
||
|
||
public static string GetPlayerStringGuid(ulong GUID)
|
||
{
|
||
var serverId = (short) (GUID >> 48);
|
||
var low = (int) (GUID & 0xFFFFFFFF);
|
||
|
||
var result = new StringBuilder();
|
||
while (low > 0)
|
||
{
|
||
var remainder = low % 26;
|
||
result.Append((char) (remainder + 97)); //A -> 65
|
||
low /= 26;
|
||
}
|
||
|
||
for (var index = 0; index < result.Length / 2; index++)
|
||
{
|
||
var temp = result[index];
|
||
result[index] = result[result.Length - index - 1];
|
||
result[result.Length - index - 1] = temp;
|
||
}
|
||
|
||
var str = result.ToString();
|
||
return string.Format("{0}{1}", serverId, str);
|
||
}
|
||
|
||
// 复制一个obj并绑定到父节点
|
||
public static GameObject BindObjToParent(GameObject resObject, GameObject parentObject, string name = null)
|
||
{
|
||
if (null == resObject || null == parentObject) return null;
|
||
|
||
var newObj = Object.Instantiate(resObject);
|
||
newObj.transform.parent = parentObject.transform;
|
||
newObj.transform.localPosition = Vector3.zero;
|
||
newObj.transform.localScale = Vector3.one;
|
||
if (null != name) newObj.name = name;
|
||
return newObj;
|
||
}
|
||
|
||
public static Color GetColorByString(string strColor)
|
||
{
|
||
var r = 0;
|
||
var g = 0;
|
||
var b = 0;
|
||
if (strColor.Length == 8 &&
|
||
strColor.IndexOf("[") == 0 &&
|
||
strColor.IndexOf("]") == 7)
|
||
strColor = strColor.Substring(1, 6);
|
||
if (strColor.Length == 6)
|
||
{
|
||
var strR = strColor[0] + strColor[1].ToString();
|
||
var strG = strColor[2] + strColor[3].ToString();
|
||
var strB = strColor[4] + strColor[5].ToString();
|
||
r = Convert.ToInt32(strR, 16);
|
||
g = Convert.ToInt32(strG, 16);
|
||
b = Convert.ToInt32(strB, 16);
|
||
}
|
||
|
||
return new Color((float) r / 255, (float) g / 255, (float) b / 255);
|
||
}
|
||
|
||
// 界面道具等级颜色
|
||
public static string GetItemQualityColor(int nQuality, bool isFrenzy = false)
|
||
{
|
||
var strColor = StrDictionary.GetClientDictionaryString("#{5500}");
|
||
|
||
//if (isFrenzy)
|
||
//{
|
||
// strColor = StrDictionary.GetClientDictionaryString("#{5803}");
|
||
//}
|
||
//else
|
||
//{
|
||
switch ((ItemQuality) nQuality)
|
||
{
|
||
case ItemQuality.QUALITY_WHITE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5500}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GREEN:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5501}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_BLUE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5502}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PURPLE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5503}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PINK:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5504}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GOLD:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5505}");
|
||
}
|
||
break;
|
||
}
|
||
//}
|
||
|
||
return strColor;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提示界面中道具品质颜色,其他界面的道具颜色,请用 GetItemQualityColor
|
||
/// </summary>
|
||
/// <param name="nQuality"></param>
|
||
/// <returns></returns>
|
||
public static string GetQualityColorInTip(int nQuality, bool isFrenzy = false)
|
||
{
|
||
var strColor = StrDictionary.GetClientDictionaryString("#{5565}");
|
||
//if(isFrenzy)
|
||
//{
|
||
// strColor= StrDictionary.GetClientDictionaryString("#{5804}");
|
||
//}
|
||
//else
|
||
//{
|
||
switch ((ItemQuality) nQuality)
|
||
{
|
||
case ItemQuality.QUALITY_WHITE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5565}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GREEN:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5566}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_BLUE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5567}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PURPLE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5568}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PINK:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5569}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GOLD:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5570}");
|
||
}
|
||
break;
|
||
}
|
||
//}
|
||
|
||
return strColor;
|
||
}
|
||
|
||
public static string GetItemNameColor(int itemData, bool isBlack = false)
|
||
{
|
||
var commonItem = TableManager.GetCommonItemByID(itemData);
|
||
if (commonItem != null) return GetItemQualityName(commonItem.Quality, commonItem.Name, isBlack);
|
||
return "";
|
||
}
|
||
|
||
public static string GetColorDisableRed()
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{5526}");
|
||
}
|
||
|
||
public static string GetColorEnableGreen()
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{5525}");
|
||
}
|
||
|
||
//时间戳转年月日
|
||
public static DateTime TimesToDateTime(long times)
|
||
{
|
||
var date = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||
var span = new TimeSpan(times * 10000000L);
|
||
var newTime = date.Add(span);
|
||
return newTime;
|
||
}
|
||
|
||
public static string GetGradeString(int grade)
|
||
{
|
||
var strId = "#{" + (_gradeDescStrId + grade - 1) + "}";
|
||
return StrDictionary.GetClientDictionaryString(strId);
|
||
}
|
||
|
||
public static string GetTimeStr1(int needTime)
|
||
{
|
||
var hour = needTime / 3600;
|
||
var min = (needTime - hour * 3600) / 60;
|
||
var sec = needTime - hour * 3600 - min * 60;
|
||
var needtimeStr = "";
|
||
if (hour <= 0)
|
||
needtimeStr = string.Format("{0:D2}:{1:D2}", min, sec);
|
||
else
|
||
needtimeStr = string.Format("{0:D2}:{1:D2}:{2:D2}", hour, min, sec);
|
||
return needtimeStr;
|
||
}
|
||
|
||
public static string GetTimeStr(int needTime)
|
||
{
|
||
var hour = needTime / 3600;
|
||
var min = (needTime - hour * 3600) / 60;
|
||
var sec = needTime - hour * 3600 - min * 60;
|
||
var needtimeStr = "";
|
||
if (hour <= 0)
|
||
needtimeStr = StrDictionary.GetClientDictionaryString("#{1648}", min, sec);
|
||
else
|
||
needtimeStr = StrDictionary.GetClientDictionaryString("#{3195}", hour, min, sec);
|
||
return needtimeStr;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取截止时间戳,计算剩余时间,返回的是String
|
||
/// </summary>
|
||
/// <param name="endTime">截止时间戳</param>
|
||
/// <param name="type">RemainTimesType</param>
|
||
/// <returns></returns>
|
||
public static string GetRemaintimeByEndTime(int endTime,
|
||
RemainTimesType type = RemainTimesType.Day_Hour_Minutes_Second)
|
||
{
|
||
var remainTime = endTime - GlobalData.ServerAnsiTime;
|
||
if (remainTime > 0)
|
||
{
|
||
var day = remainTime / 3600 / 24;
|
||
var hour = (remainTime - day * 3600 * 24) / 3600;
|
||
var min = (remainTime - day * 3600 * 24 - hour * 3600) / 60;
|
||
var sec = remainTime - day * 3600 * 24 - hour * 3600 - min * 60;
|
||
switch (type)
|
||
{
|
||
case RemainTimesType.Day:
|
||
return StrDictionary.GetClientDictionaryString("#{86805}", day.ToString().PadLeft(2, '0'));
|
||
case RemainTimesType.Day_Hour:
|
||
return StrDictionary.GetClientDictionaryString("#{86806}", day.ToString().PadLeft(2, '0'),
|
||
hour.ToString().PadLeft(2, '0'));
|
||
case RemainTimesType.Day_Hour_Minutes:
|
||
return StrDictionary.GetClientDictionaryString("#{86807}", day.ToString().PadLeft(2, '0'),
|
||
hour.ToString().PadLeft(2, '0'), min.ToString().PadLeft(2, '0'));
|
||
case RemainTimesType.Day_Hour_Minutes_Second:
|
||
return StrDictionary.GetClientDictionaryString("#{86808}", day.ToString().PadLeft(2, '0'),
|
||
hour.ToString().PadLeft(2, '0'), min.ToString().PadLeft(2, '0'),
|
||
sec.ToString().PadLeft(2, '0'));
|
||
case RemainTimesType.Hour_Minute:
|
||
{
|
||
hour = remainTime / 3600;
|
||
min = (remainTime - hour * 3600) / 60;
|
||
return StrDictionary.GetClientDictionaryString("#{86810}", hour.ToString().PadLeft(2, '0'),
|
||
min.ToString().PadLeft(2, '0'));
|
||
}
|
||
case RemainTimesType.Hour_Minute_Second:
|
||
{
|
||
hour = remainTime / 3600;
|
||
min = (remainTime - hour * 3600) / 60;
|
||
sec = remainTime - hour * 3600 - min * 60;
|
||
return StrDictionary.GetClientDictionaryString("#{86811}", hour.ToString().PadLeft(2, '0'),
|
||
min.ToString().PadLeft(2, '0'), sec.ToString().PadLeft(2, '0'));
|
||
}
|
||
default:
|
||
return "0";
|
||
}
|
||
}
|
||
|
||
return "0";
|
||
}
|
||
|
||
public static string GetRareItemNameColor(int nQuality, bool isFrenzy = false)
|
||
{
|
||
var strColor = StrDictionary.GetClientDictionaryString("#{5506}");
|
||
if (isFrenzy)
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5805}");
|
||
else
|
||
switch ((ItemQuality) nQuality)
|
||
{
|
||
case ItemQuality.QUALITY_WHITE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5506}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GREEN:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5507}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_BLUE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5508}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PURPLE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5509}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PINK:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5510}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GOLD:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5511}");
|
||
}
|
||
break;
|
||
}
|
||
|
||
return strColor;
|
||
}
|
||
|
||
public static string GetRareItemNameColorBlack(int nQuality)
|
||
{
|
||
var strColor = StrDictionary.GetClientDictionaryString("#{5548}");
|
||
switch ((ItemQuality) nQuality)
|
||
{
|
||
case ItemQuality.QUALITY_WHITE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5548}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GREEN:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5549}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_BLUE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5550}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PURPLE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5551}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_PINK:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5552}");
|
||
}
|
||
break;
|
||
case ItemQuality.QUALITY_GOLD:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5553}");
|
||
}
|
||
break;
|
||
}
|
||
|
||
return strColor;
|
||
}
|
||
|
||
public static string GetItemQualityFrame(Tab_CommonItem tabItem)
|
||
{
|
||
//if (tabItem.ClassID == (int)ItemClass.EQUIP
|
||
// || tabItem.ClassID == (int)ItemClass.MAGICITEM)
|
||
{
|
||
return GetItemQualityFrame(tabItem.Quality);
|
||
}
|
||
//return "quality_1";
|
||
}
|
||
|
||
// isFrenzy 是否经过狂化
|
||
public static string GetItemQualityFrame(int quality, bool isSuper = false, bool isFrenzy = false)
|
||
{
|
||
switch ((ItemQuality) quality)
|
||
{
|
||
case ItemQuality.QUALITY_WHITE:
|
||
return "quality_1";
|
||
case ItemQuality.QUALITY_GREEN:
|
||
return "quality_2";
|
||
case ItemQuality.QUALITY_BLUE:
|
||
return "quality_3";
|
||
case ItemQuality.QUALITY_PURPLE:
|
||
return "quality_4";
|
||
case ItemQuality.QUALITY_PINK:
|
||
if (isFrenzy)
|
||
return "quality_7";
|
||
else
|
||
return "quality_5";
|
||
case ItemQuality.QUALITY_GOLD:
|
||
if (isFrenzy)
|
||
return "quality_8";
|
||
else
|
||
return "quality_6";
|
||
default:
|
||
return "quality_0";
|
||
}
|
||
}
|
||
|
||
// 获得物品的等级背景 - 长条形
|
||
// isFrenzy 是否经过狂化
|
||
public static string GetItemQualityBG(int quality, bool isFrenzy = false)
|
||
{
|
||
if (isFrenzy)
|
||
return "quality_BG_6";
|
||
switch ((ItemQuality) quality)
|
||
{
|
||
case ItemQuality.QUALITY_WHITE:
|
||
return "quality_BG_1";
|
||
case ItemQuality.QUALITY_GREEN:
|
||
return "quality_BG_2";
|
||
case ItemQuality.QUALITY_BLUE:
|
||
return "quality_BG_3";
|
||
case ItemQuality.QUALITY_PURPLE:
|
||
return "quality_BG_4";
|
||
case ItemQuality.QUALITY_PINK:
|
||
return "quality_BG_5";
|
||
case ItemQuality.QUALITY_GOLD:
|
||
return "quality_BG_6";
|
||
default:
|
||
return "quality_BG_0";
|
||
}
|
||
}
|
||
|
||
public static string GetItemQualityName(int quality, string name, bool isBGBlack = false)
|
||
{
|
||
if (isBGBlack)
|
||
return GetQualityColorInTip(quality) + name + "</color>";
|
||
return GetItemQualityColor(quality) + name + "</color>";
|
||
}
|
||
|
||
public static string GetDisableColorText(string text)
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{5512}") + text + "</color>";
|
||
}
|
||
|
||
public static string GetFellowQuilityStr(FELLOWQUALITY quilityType)
|
||
{
|
||
var IconPath = "#{6276}";
|
||
if (quilityType >= FELLOWQUALITY.ORANGE)
|
||
IconPath = "#{6279}";
|
||
switch (quilityType)
|
||
{
|
||
case FELLOWQUALITY.BLUE:
|
||
{
|
||
IconPath = "#{6276}";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.PURPLE:
|
||
{
|
||
IconPath = "#{6277}";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.RED:
|
||
{
|
||
IconPath = "#{6278}";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.ORANGE:
|
||
{
|
||
IconPath = "#{6279}";
|
||
}
|
||
break;
|
||
}
|
||
|
||
return IconPath;
|
||
}
|
||
|
||
public static string GetFellowQuilityIcon(int nQuality)
|
||
{
|
||
var IconPath = "quality_3";
|
||
if (nQuality >= (int) FELLOWQUALITY.ORANGE)
|
||
IconPath = "quality_6";
|
||
var quilityType = (FELLOWQUALITY) nQuality;
|
||
switch (quilityType)
|
||
{
|
||
case FELLOWQUALITY.WHITE:
|
||
{
|
||
IconPath = "quality_1";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.GREEN:
|
||
{
|
||
IconPath = "quality_2";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.BLUE:
|
||
{
|
||
IconPath = "quality_3";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.PURPLE:
|
||
{
|
||
IconPath = "quality_4";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.RED:
|
||
{
|
||
IconPath = "quality_5";
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.ORANGE:
|
||
{
|
||
IconPath = "quality_6";
|
||
}
|
||
break;
|
||
}
|
||
|
||
return IconPath;
|
||
}
|
||
|
||
//1白 2绿 3蓝 4紫 5红 6金
|
||
public static FELLOWQUALITY GetQualityIndex(int Quality)
|
||
{
|
||
//float quility = Quality * 1.0f / 100.0f; //服务器发过来的是整数,并且有乘以100
|
||
if (Quality >= 10)
|
||
Quality = Quality / 100;
|
||
if (Quality == 0)
|
||
return FELLOWQUALITY.WHITE;
|
||
if (Quality == 1)
|
||
return FELLOWQUALITY.GREEN;
|
||
if (Quality == 2)
|
||
return FELLOWQUALITY.BLUE;
|
||
if (Quality == 3)
|
||
return FELLOWQUALITY.PURPLE;
|
||
if (Quality == 4)
|
||
return FELLOWQUALITY.ORANGE;
|
||
if (Quality == 5)
|
||
return FELLOWQUALITY.RED;
|
||
return FELLOWQUALITY.ORANGE;
|
||
}
|
||
|
||
public static string GetFellowNameColor(int nQuality)
|
||
{
|
||
var strColor = StrDictionary.GetClientDictionaryString("#{5513}");
|
||
switch ((FELLOWQUALITY) nQuality)
|
||
{
|
||
case FELLOWQUALITY.WHITE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5513}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.GREEN:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5514}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.BLUE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5515}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.PURPLE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5516}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.RED:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5517}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.ORANGE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5518}");
|
||
}
|
||
break;
|
||
}
|
||
|
||
return strColor;
|
||
}
|
||
|
||
public static string GetFellowNameColorInBlack(int nQuality)
|
||
{
|
||
var strColor = StrDictionary.GetClientDictionaryString("#{5565}");
|
||
switch ((FELLOWQUALITY) nQuality)
|
||
{
|
||
case FELLOWQUALITY.WHITE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5565}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.GREEN:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5566}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.BLUE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5567}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.PURPLE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5568}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.RED:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5569}");
|
||
}
|
||
break;
|
||
case FELLOWQUALITY.ORANGE:
|
||
{
|
||
strColor = StrDictionary.GetClientDictionaryString("#{5570}");
|
||
}
|
||
break;
|
||
}
|
||
|
||
return strColor;
|
||
}
|
||
|
||
public static string GetTitleColor(int nColorLevel, string title)
|
||
{
|
||
var strColor = string.Format("{1}{0}</color>", title, StrDictionary.GetClientDictionaryString("#{5519}"));
|
||
switch ((TITLE_COLORLEVEL) nColorLevel)
|
||
{
|
||
case TITLE_COLORLEVEL.COLOR_WHITE:
|
||
{
|
||
strColor = string.Format("{1}{0}</color>", title,
|
||
StrDictionary.GetClientDictionaryString("#{5519}"));
|
||
}
|
||
break;
|
||
case TITLE_COLORLEVEL.COLOR_GREEN:
|
||
{
|
||
strColor = string.Format("{1}{0}</color>", title,
|
||
StrDictionary.GetClientDictionaryString("#{5520}"));
|
||
}
|
||
break;
|
||
case TITLE_COLORLEVEL.COLOR_BLUE:
|
||
{
|
||
strColor = string.Format("{1}{0}</color>", title,
|
||
StrDictionary.GetClientDictionaryString("#{5521}"));
|
||
}
|
||
break;
|
||
case TITLE_COLORLEVEL.COLOR_PURPLE:
|
||
{
|
||
strColor = string.Format("{1}{0}</color>", title,
|
||
StrDictionary.GetClientDictionaryString("#{5522}"));
|
||
}
|
||
break;
|
||
case TITLE_COLORLEVEL.COLOR_ORANGE:
|
||
{
|
||
strColor = string.Format("{1}{0}</color>", title,
|
||
StrDictionary.GetClientDictionaryString("#{5523}"));
|
||
}
|
||
break;
|
||
case TITLE_COLORLEVEL.COLOR_GOLD:
|
||
{
|
||
strColor = string.Format("{1}{0}</color>", title,
|
||
StrDictionary.GetClientDictionaryString("#{5524}"));
|
||
}
|
||
break;
|
||
}
|
||
|
||
return strColor;
|
||
}
|
||
|
||
public static string GetItemType(int nClassID, int nSubClassID, int propLimit)
|
||
{
|
||
var strType = "";
|
||
|
||
var itemClassTabs = TableManager.GetItemClassNameByID(nClassID);
|
||
if (itemClassTabs == null)
|
||
return strType;
|
||
foreach (var itemNameTab in itemClassTabs)
|
||
if (itemNameTab.SubClassID == -1 && string.IsNullOrEmpty(strType))
|
||
{
|
||
strType = itemNameTab.Name;
|
||
}
|
||
else if (itemNameTab.SubClassID == nSubClassID)
|
||
{
|
||
if (itemNameTab.ProLimit == -1 && string.IsNullOrEmpty(strType))
|
||
{
|
||
strType = itemNameTab.Name;
|
||
}
|
||
else if (itemNameTab.ProLimit == propLimit)
|
||
{
|
||
strType = itemNameTab.Name;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(strType))
|
||
LogModule.ErrorLog("找不到对应类型名称:" + nClassID + "," + nSubClassID + "," + propLimit);
|
||
return strType;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 过滤字
|
||
/// </summary>
|
||
/// <param name="str">原始字符</param>
|
||
/// <param name="nFilterType">过滤类型参考STRFILTER_TYPE</param>
|
||
/// <returns>返回空未没有找到,找到后返回相应字符</returns>
|
||
public static string GetStrFilter(string str, int nFilterType)
|
||
{
|
||
if (nFilterType < (int) GameDefine_Globe.STRFILTER_TYPE.STRFILTER_CHAT ||
|
||
nFilterType > (int) GameDefine_Globe.STRFILTER_TYPE.STRFILTER_NAME)
|
||
return null;
|
||
if (str == null)
|
||
return null;
|
||
foreach (var strFilter in TableManager.GetStrFilter().Values)
|
||
if (strFilter.GetTypebyIndex(nFilterType) && str.Contains(strFilter.SzString, StringComparison.Ordinal))
|
||
return strFilter.SzString;
|
||
//return GameManager.gameManager.PlayerDataPool.GetAbuseFilter(str);
|
||
return null;
|
||
}
|
||
|
||
public static void SendCGChatPak(string text, ChatHistoryItem historyReply, bool isGuidEnlist = false)
|
||
{
|
||
var packet = (CG_CHAT) PacketDistributed.CreatePacket(MessageID.PACKET_CG_CHAT);
|
||
packet.Chattype = (int) historyReply.EChannel;
|
||
if (packet.Chattype == (int) CG_CHAT.CHATTYPE.CHAT_TYPE_TELL ||
|
||
packet.Chattype == (int) CG_CHAT.CHATTYPE.CHAT_TYPE_FRIEND)
|
||
{
|
||
var tellGuid = GlobeVar.INVALID_GUID;
|
||
var tellName = "";
|
||
tellGuid = historyReply.ReceiverGuid;
|
||
tellName = historyReply.ReceiverName;
|
||
// 设置私聊对象同时去掉聊天信息中的"/对象名"
|
||
packet.Receiverguid = tellGuid;
|
||
packet.Receivername = tellName;
|
||
}
|
||
|
||
packet.Chatinfo = text;
|
||
LogModule.DebugLog("send chat:" + text);
|
||
|
||
if (isGuidEnlist) //任意值标示当前是帮派招募
|
||
packet.AddIntdata(1);
|
||
|
||
packet.SendPacket();
|
||
}
|
||
|
||
public static void SendLoudSpeaker(string text, int num)
|
||
{
|
||
var packet = (CG_CHAT) PacketDistributed.CreatePacket(MessageID.PACKET_CG_CHAT);
|
||
packet.Chattype = (int) CG_CHAT.CHATTYPE.CHAT_TYPE_LOUDSPEAKER;
|
||
//text = LoudSpeakerLogic.Instance().InsertLinkSymbols(text);
|
||
packet.Chatinfo = text;
|
||
packet.LoudSpeakerNum = num;
|
||
//WriteLinkToCGChat(packet, LoudSpeakerLogic.Instance().ChatLinkType, true);
|
||
// LoudSpeakerLogic.Instance().ClearLinkBuffer();
|
||
packet.SendPacket();
|
||
}
|
||
|
||
public static void SendGMCommand(string cmd)
|
||
{
|
||
var packet = (CG_GMCOMMAND) PacketDistributed.CreatePacket(MessageID.PACKET_CG_GMCOMMAND);
|
||
packet.Cmd = cmd;
|
||
packet.SendPacket();
|
||
}
|
||
|
||
// 将时间间隔格式化对应标签上
|
||
public static void SetTimeDiffToLabel(Text label, int timeDiff)
|
||
{
|
||
if (timeDiff <= 0)
|
||
label.text = "00:00:00";
|
||
else
|
||
label.text = string.Format("{0,2:D2}:{1,2:D2}:{2,2:D2}", timeDiff / 3600, timeDiff % 3600 / 60,
|
||
timeDiff % 60);
|
||
}
|
||
|
||
public static string GetTimeDiffFormatString(int timeDiff)
|
||
{
|
||
if (timeDiff <= 0)
|
||
return "00:00:00";
|
||
return string.Format("{0,2:D2}:{1,2:D2}:{2,2:D2}", timeDiff / 3600, timeDiff % 3600 / 60, timeDiff % 60);
|
||
}
|
||
|
||
// 清除GRID所有子ITEM
|
||
public static void CleanGrid(GameObject grid)
|
||
{
|
||
if (null == grid) return;
|
||
for (int i = 0, count = grid.transform.childCount; i < count; i++)
|
||
Object.Destroy(grid.transform.GetChild(i).gameObject);
|
||
|
||
grid.transform.DetachChildren();
|
||
}
|
||
|
||
public static string StrFilter_Chat(string strChat)
|
||
{
|
||
var text = strChat;
|
||
var strFilter = GetStrFilter(text, (int) GameDefine_Globe.STRFILTER_TYPE.STRFILTER_CHAT);
|
||
var count = 20;
|
||
while (strFilter != null && count > 0)
|
||
{
|
||
text = text.Replace(strFilter, "*");
|
||
strFilter = GetStrFilter(text, (int) GameDefine_Globe.STRFILTER_TYPE.STRFILTER_CHAT);
|
||
count--;
|
||
}
|
||
|
||
return text;
|
||
}
|
||
|
||
public static bool IsStrFilter_Chat(string strChat)
|
||
{
|
||
var text = strChat;
|
||
var strFilter = GetStrFilter(text, (int) GameDefine_Globe.STRFILTER_TYPE.STRFILTER_CHAT);
|
||
if (strFilter != null) return true;
|
||
return false;
|
||
}
|
||
|
||
public static string StrFilter_Abuse(string strChat)
|
||
{
|
||
var text = strChat;
|
||
var strFilter = GameManager.gameManager.PlayerDataPool.GetAbuseFilter(text);
|
||
var count = 20;
|
||
while (strFilter != null && count > 0)
|
||
{
|
||
text = text.Replace(strFilter, "*");
|
||
strFilter = GameManager.gameManager.PlayerDataPool.GetAbuseFilter(text);
|
||
count--;
|
||
}
|
||
|
||
return text;
|
||
}
|
||
|
||
public static bool IsStrFilter_Abuse(string strChat)
|
||
{
|
||
var text = strChat;
|
||
var strFilter = GameManager.gameManager.PlayerDataPool.GetAbuseFilter(text);
|
||
if (strFilter != null) return true;
|
||
return false;
|
||
}
|
||
|
||
public static string StrFilter_Mail(string strMailText)
|
||
{
|
||
var text = strMailText;
|
||
var strFilter = GetStrFilter(text, (int) GameDefine_Globe.STRFILTER_TYPE.STRFILTER_CHAT);
|
||
var count = 20;
|
||
while (strFilter != null && count > 0)
|
||
{
|
||
text = text.Replace(strFilter, "*");
|
||
strFilter = GetStrFilter(text, (int) GameDefine_Globe.STRFILTER_TYPE.STRFILTER_CHAT);
|
||
count--;
|
||
}
|
||
|
||
return text;
|
||
}
|
||
|
||
// public static GameObject LoadUIItem(GameObject parent, string name, UIPathData uiData)
|
||
// {
|
||
// GameObject resObj = ResourceManager.LoadResource(uiData.path) as GameObject;
|
||
// GameObject curItem = Utils.BindObjToParent(resObj, parent);
|
||
// curItem.name = name;
|
||
// return curItem;
|
||
// }
|
||
|
||
// 简单的获取表中的一个ID对应的文字。
|
||
public static string GetDicByID(int dicID)
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{" + dicID + "}");
|
||
}
|
||
|
||
public static Quaternion DirServerToClient(float rad)
|
||
{
|
||
return Quaternion.Euler(0, 90.0f - rad * 180.0f / Mathf.PI, 0);
|
||
}
|
||
|
||
public static float DirClientToServer(Quaternion rotate)
|
||
{
|
||
return Mathf.PI * 0.5f - rotate.eulerAngles.y * Mathf.PI / 180.0f;
|
||
}
|
||
|
||
//转化到0-2PI范围内
|
||
public static float NormaliseDirection(float fDirection)
|
||
{
|
||
var _2PI = (float) (Math.PI * 2);
|
||
var fRetValue = fDirection;
|
||
|
||
if (fRetValue >= _2PI)
|
||
{
|
||
fRetValue -= (int) (fDirection / _2PI) * _2PI;
|
||
fRetValue = fRetValue > 0.0F ? fRetValue : 0.0f;
|
||
fRetValue = fRetValue < _2PI ? fRetValue : _2PI;
|
||
}
|
||
else if (fRetValue < 0)
|
||
{
|
||
fRetValue += ((int) (-fDirection / _2PI) + 1) * _2PI;
|
||
fRetValue = fRetValue > 0.0F ? fRetValue : 0.0f;
|
||
fRetValue = fRetValue < _2PI ? fRetValue : _2PI;
|
||
}
|
||
|
||
return fRetValue;
|
||
}
|
||
|
||
//获取当前平台StreamingAsset路径
|
||
public static string GetStreamingAssetPath()
|
||
{
|
||
var strStreamingPath = "";
|
||
if (Application.platform == RuntimePlatform.IPhonePlayer)
|
||
strStreamingPath = Application.dataPath + "/Raw";
|
||
else if (Application.platform == RuntimePlatform.Android)
|
||
strStreamingPath = Application.streamingAssetsPath;
|
||
else
|
||
//strStreamingPath = "file://" + Application.streamingAssetsPath; WWW
|
||
strStreamingPath = Application.streamingAssetsPath; //File
|
||
|
||
return strStreamingPath;
|
||
}
|
||
|
||
// 获取属性类型字典
|
||
public static string GetAttrTypeString(int type)
|
||
{
|
||
if (CharacterDefine.AttrTable.ContainsKey(type)) return GetDicByID(CharacterDefine.AttrTable[type]);
|
||
|
||
return "";
|
||
}
|
||
|
||
public static void CheckTargetPath(string targetPath)
|
||
{
|
||
targetPath = targetPath.Replace('\\', '/');
|
||
|
||
var dotPos = targetPath.LastIndexOf('.');
|
||
var lastPathPos = targetPath.LastIndexOf('/');
|
||
|
||
if (dotPos > 0 && lastPathPos < dotPos) targetPath = targetPath.Substring(0, lastPathPos);
|
||
if (Directory.Exists(targetPath)) return;
|
||
|
||
|
||
var subPath = targetPath.Split('/');
|
||
var curCheckPath = "";
|
||
var subContentSize = subPath.Length;
|
||
for (var i = 0; i < subContentSize; i++)
|
||
{
|
||
curCheckPath += subPath[i] + '/';
|
||
if (!Directory.Exists(curCheckPath)) Directory.CreateDirectory(curCheckPath);
|
||
}
|
||
}
|
||
|
||
public static void CheckTargetPath(string root, string targetPath)
|
||
{
|
||
if (!Directory.Exists(root)) Directory.CreateDirectory(root);
|
||
|
||
targetPath = targetPath.Replace('\\', '/');
|
||
|
||
var dotPos = targetPath.LastIndexOf('.');
|
||
var lastPathPos = targetPath.LastIndexOf('/');
|
||
|
||
if (dotPos > 0 && lastPathPos < dotPos && lastPathPos > 0)
|
||
targetPath = targetPath.Substring(0, lastPathPos);
|
||
if (Directory.Exists(root + targetPath)) return;
|
||
if (lastPathPos < 0)
|
||
return;
|
||
|
||
var subPath = targetPath.Split('/');
|
||
var curCheckPath = root;
|
||
var subContentSize = subPath.Length;
|
||
for (var i = 0; i < subContentSize; i++)
|
||
{
|
||
curCheckPath += subPath[i] + '/';
|
||
if (!Directory.Exists(curCheckPath)) Directory.CreateDirectory(curCheckPath);
|
||
}
|
||
}
|
||
|
||
public static void DeleteFolder(string path)
|
||
{
|
||
if (!Directory.Exists(path)) return;
|
||
|
||
string[] strTemp;
|
||
//先删除该目录下的文件
|
||
strTemp = Directory.GetFiles(path);
|
||
foreach (var str in strTemp) File.Delete(str);
|
||
//删除子目录,递归
|
||
strTemp = Directory.GetDirectories(path);
|
||
foreach (var str in strTemp) DeleteFolder(str);
|
||
}
|
||
|
||
// 拷贝一个路径下所有的文件,不包含子目录
|
||
public static void CopyPathFile(string srcPath, string distPath)
|
||
{
|
||
if (!Directory.Exists(srcPath)) return;
|
||
|
||
CheckTargetPath(distPath);
|
||
|
||
var strLocalFile = Directory.GetFiles(srcPath);
|
||
foreach (var curFile in strLocalFile) File.Copy(curFile, distPath + "/" + Path.GetFileName(curFile), true);
|
||
}
|
||
|
||
// 获取MD5
|
||
public static string GetMD5Hash(string pathName)
|
||
{
|
||
var strResult = "";
|
||
var strHashData = "";
|
||
#if !UNITY_WP8
|
||
byte[] arrbytHashValue;
|
||
#endif
|
||
FileStream oFileStream = null;
|
||
var oMD5Hasher = new MD5CryptoServiceProvider();
|
||
try
|
||
{
|
||
oFileStream = new FileStream(pathName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||
#if UNITY_WP8
|
||
strHashData = oMD5Hasher.ComputeHash(oFileStream);
|
||
oFileStream.Close();
|
||
#else
|
||
arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);
|
||
oFileStream.Close();
|
||
strHashData = BitConverter.ToString(arrbytHashValue);
|
||
strHashData = strHashData.Replace("-", "");
|
||
#endif
|
||
|
||
strResult = strHashData;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogModule.ErrorLog("read md5 file error :" + pathName + " e: " + ex);
|
||
}
|
||
|
||
return strResult;
|
||
}
|
||
|
||
//登录场景播放音乐,其他地方不要使用
|
||
public static void PlaySceneMusic(int nSoundID)
|
||
{
|
||
if (null == GameManager.gameManager.SoundManager) return;
|
||
//
|
||
// Tab_Sounds soundsTab = TableManager.GetSoundsByID(nSoundID, 0);
|
||
// if (soundsTab == null)
|
||
// {
|
||
// return;
|
||
// }
|
||
|
||
GameManager.gameManager.SoundManager.PlayBGMusic(nSoundID);
|
||
}
|
||
|
||
public static string ConvertLargeNumToString(int num)
|
||
{
|
||
if (num >= 1000000)
|
||
// 超过100w的显示xx万
|
||
return StrDictionary.GetClientDictionaryString("#{2224}", num / 10000);
|
||
return num.ToString();
|
||
}
|
||
|
||
public static string ConvertLargeNumToString(long num)
|
||
{
|
||
if (num >= 1000000)
|
||
// 超过100w的显示xx万
|
||
return StrDictionary.GetClientDictionaryString("#{2224}", num / 10000);
|
||
return num.ToString();
|
||
}
|
||
|
||
public static string ConvertLargeNumToPretty(int num)
|
||
{
|
||
if (num >= 100000000)
|
||
// 超过100w的显示xx万
|
||
return StrDictionary.GetClientDictionaryString("#{6757}", num / 100000000);
|
||
if (num >= 10000)
|
||
return StrDictionary.GetClientDictionaryString("#{2224}", num / 10000);
|
||
return num.ToString();
|
||
}
|
||
|
||
public static int GetIntNumber(int src, int start, int len)
|
||
{
|
||
if (start < 0 || start > 9) return GlobeVar.INVALID_ID;
|
||
if (len < 1) return GlobeVar.INVALID_ID;
|
||
|
||
var result = 0;
|
||
for (var i = 0; i < len; i++) result += src / (int) Mathf.Pow(10, start + i) % 10 * (int) Mathf.Pow(10, i);
|
||
return result;
|
||
}
|
||
|
||
public static bool SetIntNumber(ref int src, int start, int len, int val)
|
||
{
|
||
if (start < 0 || start > 9) return false;
|
||
if (len < 1) return false;
|
||
if (val >= Mathf.Pow(10, len)) return false;
|
||
|
||
for (var i = 0; i < len; i++)
|
||
{
|
||
src -= src / (int) Mathf.Pow(10, start + i) % 10 * (int) Mathf.Pow(10, start + i);
|
||
src += val / (int) Mathf.Pow(10, i) % 10 * (int) Mathf.Pow(10, start + i);
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
public static string NumStr(int Num)
|
||
{
|
||
if (Num > 10 && Num < 100)
|
||
{
|
||
var tens = Num / 10;
|
||
var tensStr = NumToStr(tens);
|
||
var single = Num % 10;
|
||
var singleStr = NumToStr(single);
|
||
var tenStr = NumToStr(10);
|
||
if (tens == 1) tensStr = "";
|
||
if (single == 0) singleStr = "";
|
||
return tensStr + tenStr + singleStr;
|
||
}
|
||
|
||
return NumToStr(Num);
|
||
}
|
||
|
||
private static string NumToStr(int Num)
|
||
{
|
||
switch (Num)
|
||
{
|
||
case 0: return StrDictionary.GetClientDictionaryString("#{9921}");
|
||
case 1: return StrDictionary.GetClientDictionaryString("#{9907}");
|
||
case 2: return StrDictionary.GetClientDictionaryString("#{9908}");
|
||
case 3: return StrDictionary.GetClientDictionaryString("#{9909}");
|
||
case 4: return StrDictionary.GetClientDictionaryString("#{9910}");
|
||
case 5: return StrDictionary.GetClientDictionaryString("#{9911}");
|
||
case 6: return StrDictionary.GetClientDictionaryString("#{9912}");
|
||
case 7: return StrDictionary.GetClientDictionaryString("#{9913}");
|
||
case 8: return StrDictionary.GetClientDictionaryString("#{9914}");
|
||
case 9: return StrDictionary.GetClientDictionaryString("#{9915}");
|
||
case 10: return StrDictionary.GetClientDictionaryString("#{9916}");
|
||
case 100: return StrDictionary.GetClientDictionaryString("#{9917}");
|
||
case 1000: return StrDictionary.GetClientDictionaryString("#{9918}");
|
||
case 10000: return StrDictionary.GetClientDictionaryString("#{9919}");
|
||
case 100000000: return StrDictionary.GetClientDictionaryString("#{9920}");
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
public static bool GetFileInt(string path, out int retInt)
|
||
{
|
||
try
|
||
{
|
||
if (!File.Exists(path))
|
||
{
|
||
retInt = 0;
|
||
return false;
|
||
}
|
||
|
||
var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||
var sr = new StreamReader(fs);
|
||
var text = sr.ReadToEnd();
|
||
sr.Close();
|
||
fs.Close();
|
||
|
||
if (!int.TryParse(text, out retInt))
|
||
{
|
||
LogModule.ErrorLog("parse int error path:" + path);
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogModule.ErrorLog(ex.ToString());
|
||
retInt = 0;
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public static bool GetFileLong(string path, out long retLong)
|
||
{
|
||
try
|
||
{
|
||
if (!File.Exists(path))
|
||
{
|
||
retLong = 0;
|
||
return false;
|
||
}
|
||
|
||
var text = File.ReadAllText(path);
|
||
if (!long.TryParse(text, out retLong))
|
||
{
|
||
LogModule.ErrorLog("parse int error path:" + path);
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogModule.ErrorLog(ex.ToString());
|
||
retLong = 0;
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public static bool WriteStringToFile(string path, string text)
|
||
{
|
||
var result = false;
|
||
try
|
||
{
|
||
File.WriteAllText(path, text);
|
||
result = true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogModule.ErrorLog(ex.ToString());
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
// public static bool GenerateResFileList(string path, Dictionary<string, UpdateHelper.FileInfo> dicFileInfo)
|
||
// {
|
||
// try
|
||
// {
|
||
// CheckTargetPath(path);
|
||
//
|
||
// var streamWriter = new StreamWriter(path);
|
||
//
|
||
// foreach (var dicFile in dicFileInfo)
|
||
// streamWriter.WriteLine(dicFile.Key + ":" + dicFile.Value.md5 + ":" + dicFile.Value.size + ":" +
|
||
// dicFile.Value.resLevel);
|
||
// streamWriter.Close();
|
||
//
|
||
//
|
||
// return true;
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// LogModule.ErrorLog(ex.ToString());
|
||
// return false;
|
||
// }
|
||
// }
|
||
//
|
||
// public static void GetResFileList(string path, ref Dictionary<string, UpdateHelper.FileInfo> dicFileInfo)
|
||
// {
|
||
// var xmlRemote = new XmlDocument();
|
||
// xmlRemote.Load(path);
|
||
//
|
||
//
|
||
// var fileRootRemote = (XmlElement) xmlRemote.FirstChild;
|
||
//
|
||
// foreach (XmlElement fileInfoNode in fileRootRemote.ChildNodes)
|
||
// {
|
||
// var fileInfo = new UpdateHelper.FileInfo();
|
||
// foreach (XmlElement fileInfoChildNode in fileInfoNode.ChildNodes)
|
||
// if (fileInfoChildNode.Name == "path")
|
||
// dicFileInfo.Add(fileInfoChildNode.InnerText, fileInfo);
|
||
// else if (fileInfoChildNode.Name == "md5")
|
||
// fileInfo.md5 = fileInfoChildNode.InnerText;
|
||
// else if (fileInfoChildNode.Name == "size")
|
||
// fileInfo.size = long.Parse(fileInfoChildNode.InnerText);
|
||
// else if (fileInfoChildNode.Name == "level") fileInfo.level = int.Parse(fileInfoChildNode.InnerText);
|
||
// }
|
||
// }
|
||
|
||
public static Tab_SkillEx GetSkillidByLevel(int skillid, int level)
|
||
{
|
||
var _skillExinfo = TableManager.GetSkillExByID(skillid);
|
||
if (_skillExinfo == null) return null;
|
||
var nextSkill = _skillExinfo;
|
||
for (var i = 0; i < level; i++)
|
||
{
|
||
nextSkill = TableManager.GetSkillExByID(nextSkill.NextSkillId);
|
||
if (nextSkill == null) return null;
|
||
}
|
||
|
||
return nextSkill;
|
||
}
|
||
|
||
public static void GetSweepCounts(ref int curCount, ref int maxCount)
|
||
{
|
||
curCount = 0;
|
||
maxCount = 0;
|
||
var nSweep =
|
||
GameManager.gameManager.PlayerDataPool.CommonData.GetCommonData(
|
||
(int) USER_COMMONDATA.CD_COPYSCENE_CANGJINGGE_SWEEP);
|
||
var nMul = GameManager.gameManager.PlayerDataPool.CommonData.GetCopySceneMultiple(14);
|
||
maxCount = nMul * 3;
|
||
//策划要求不显示花费元宝的那些次数,计算参照OnSweepClick
|
||
//curCount = maxCount - nSweep;
|
||
if (nSweep >= nMul)
|
||
curCount = 0;
|
||
else
|
||
curCount = nMul - nSweep;
|
||
}
|
||
|
||
public static string GenCodeWithSelfGuid(ShareType nShareType)
|
||
{
|
||
if (Singleton<ObjManager>.Instance.MainPlayer != null)
|
||
{
|
||
var guid = Singleton<ObjManager>.Instance.MainPlayer.GUID;
|
||
var high = (uint) (guid >> 32);
|
||
var serial = (uint) (guid & 0xffffffff);
|
||
var worldId = (ushort) ((high >> 16) & 0xffff);
|
||
var carry = (byte) (high & 0xff);
|
||
var randKey = (uint) Random.Range(1000, 10000);
|
||
randKey = randKey & 0xfffc7fff;
|
||
if (nShareType == ShareType.ShareType_SNS)
|
||
randKey = randKey | 0x00000000;
|
||
else if (nShareType == ShareType.ShareType_NanGua)
|
||
randKey = randKey | 0x00008000;
|
||
else
|
||
randKey = randKey | 0x00038000;
|
||
return string.Format("{0}-{1}-{2}-{3}", worldId, carry, serial, randKey);
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
public static string GenServerNameWithSelfGuid()
|
||
{
|
||
if (Singleton<ObjManager>.Instance.MainPlayer != null)
|
||
{
|
||
var guid = Singleton<ObjManager>.Instance.MainPlayer.GUID;
|
||
var high = (uint) (guid >> 32);
|
||
var worldId = (ushort) ((high >> 16) & 0xffff);
|
||
var curData = LoginData.GetServerListDataByID(worldId);
|
||
if (null != curData) return curData.m_name;
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
public static string GetMarryRingString(GameItem item)
|
||
{
|
||
if (item != null && item.DataID == GlobeVar.MARRY_RING_ITEMID)
|
||
{
|
||
//no data
|
||
if (item.DynamicData[0] == 0 && item.DynamicData[1] == 0 && item.DynamicData[2] == 0 &&
|
||
item.DynamicData[3] == 0 && item.DynamicData[4] == 0 && item.DynamicData[5] == 0)
|
||
return "";
|
||
|
||
//(6/8)Dynamic
|
||
const int LEN = 6;
|
||
var byteArray = new byte[4 * LEN];
|
||
for (var i = 0; i < LEN; ++i)
|
||
{
|
||
var temp = BitConverter.GetBytes(item.DynamicData[i]);
|
||
Array.Copy(temp, 0, byteArray, 0 + 4 * i, 4);
|
||
}
|
||
#if UNITY_WP8
|
||
string desString = System.Text.Encoding.UTF8.GetString(byteArray,0,byteArray.Length);
|
||
#else
|
||
var desString = Encoding.UTF8.GetString(byteArray);
|
||
#endif
|
||
return "\n" + StrDictionary.GetClientDictionaryString("#{3290}", desString);
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
public static ulong GetMarryRingGUID(GameItem item)
|
||
{
|
||
if (item.DataID == GlobeVar.MARRY_RING_ITEMID)
|
||
{
|
||
}
|
||
|
||
return GlobeVar.INVALID_GUID;
|
||
}
|
||
|
||
public static DateTime GetServerDateTime()
|
||
{
|
||
var curDate = new DateTime(GlobalData.ServerAnsiTime * 10000000L + m_startTime.Ticks, DateTimeKind.Utc);
|
||
curDate = curDate.AddHours(8); //调到北京时间
|
||
//curDate = curDate.ToLocalTime();
|
||
return curDate;
|
||
}
|
||
|
||
public static DateTime GetServerDateTime(int serverTime)
|
||
{
|
||
var curDate = new DateTime(serverTime * 10000000L + m_startTime.Ticks, DateTimeKind.Utc);
|
||
curDate = curDate.AddHours(8); //调到北京时间
|
||
//curDate = curDate.ToLocalTime();
|
||
return curDate;
|
||
}
|
||
|
||
public static DateTime GetServerDateTime(long serverTime)
|
||
{
|
||
var curDate = new DateTime(serverTime * 10000000L + m_startTime.Ticks, DateTimeKind.Utc);
|
||
curDate = curDate.AddHours(8); //调到北京时间
|
||
//curDate = curDate.ToLocalTime();
|
||
return curDate;
|
||
}
|
||
|
||
public static ulong DateTimeToServerTime(DateTime dateTime)
|
||
{
|
||
var serverTime = (ulong) ((dateTime.Ticks - m_startTime.Ticks) / 10000000L);
|
||
return serverTime;
|
||
}
|
||
|
||
public static int GetRemainTime(ulong overTime)
|
||
{
|
||
return (int) overTime - GlobalData.ServerAnsiTime;
|
||
}
|
||
|
||
public static string GetProfession(int nProfession)
|
||
{
|
||
switch ((CharacterDefine.PROFESSION) nProfession)
|
||
{
|
||
case CharacterDefine.PROFESSION.TIANJI:
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{1178}");
|
||
}
|
||
case CharacterDefine.PROFESSION.SHUSHAN:
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{1180}");
|
||
}
|
||
case CharacterDefine.PROFESSION.LIUSHAN:
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{1179}");
|
||
}
|
||
case CharacterDefine.PROFESSION.XUANNV:
|
||
{
|
||
return StrDictionary.GetClientDictionaryString("#{1181}");
|
||
}
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
public static string GetProfessionSpriteName(int nProfession)
|
||
{
|
||
switch ((CharacterDefine.PROFESSION) nProfession)
|
||
{
|
||
case CharacterDefine.PROFESSION.TIANJI:
|
||
{
|
||
return "TianJiHead";
|
||
}
|
||
case CharacterDefine.PROFESSION.SHUSHAN:
|
||
{
|
||
return "ShuShanHead";
|
||
}
|
||
case CharacterDefine.PROFESSION.LIUSHAN:
|
||
{
|
||
return "LiuSanHead";
|
||
}
|
||
case CharacterDefine.PROFESSION.XUANNV:
|
||
{
|
||
return "XuannvHead";
|
||
}
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
public static string GetProfessionIconName(CharacterDefine.PROFESSION nProfession)
|
||
{
|
||
switch (nProfession)
|
||
{
|
||
case CharacterDefine.PROFESSION.TIANJI:
|
||
{
|
||
return "ProTianji";
|
||
}
|
||
case CharacterDefine.PROFESSION.SHUSHAN:
|
||
{
|
||
return "ProShushan";
|
||
}
|
||
case CharacterDefine.PROFESSION.LIUSHAN:
|
||
{
|
||
return "ProLiushan";
|
||
}
|
||
case CharacterDefine.PROFESSION.XUANNV:
|
||
{
|
||
return "ProXuannv";
|
||
}
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
public static string GetCaptainLevelIcon(int captainLevel)
|
||
{
|
||
var teamLeaderAwardLevelTab = TableManager.GetTeamLeaderAwardLevelByID(captainLevel);
|
||
if (teamLeaderAwardLevelTab == null) return "";
|
||
return teamLeaderAwardLevelTab.IconPath;
|
||
//return string.Format("captainlevel{0}", Mathf.Clamp(GameManager.gameManager.PlayerDataPool.TeamInfo.CaptainLevel, 1, 6));
|
||
}
|
||
|
||
public static string GetProfessionIconName2(CharacterDefine.PROFESSION nProfession)
|
||
{
|
||
switch (nProfession)
|
||
{
|
||
case CharacterDefine.PROFESSION.TIANJI:
|
||
{
|
||
return "ProTianji2";
|
||
}
|
||
case CharacterDefine.PROFESSION.SHUSHAN:
|
||
{
|
||
return "ProShushan2";
|
||
}
|
||
case CharacterDefine.PROFESSION.LIUSHAN:
|
||
{
|
||
return "ProLiushan2";
|
||
}
|
||
case CharacterDefine.PROFESSION.XUANNV:
|
||
{
|
||
return "ProXuannv2";
|
||
}
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
public static ChatGender GetProfessionGender(int nProfession)
|
||
{
|
||
if (nProfession == (int) CharacterDefine.PROFESSION.LIUSHAN
|
||
|| nProfession == (int) CharacterDefine.PROFESSION.XUANNV)
|
||
return ChatGender.Female;
|
||
|
||
return ChatGender.Male;
|
||
}
|
||
|
||
public static string GetSysIconName(SysIconType sysIcon)
|
||
{
|
||
switch (sysIcon)
|
||
{
|
||
case SysIconType.None:
|
||
return "shenmiren";
|
||
case SysIconType.AI:
|
||
return "AIHead";
|
||
case SysIconType.Sys:
|
||
return "SystemHead";
|
||
case SysIconType.Guild:
|
||
return "GuildHead";
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
//Unity物体操作有关 克隆物体
|
||
public static GameObject CloneObj(GameObject OldObj)
|
||
{
|
||
if (OldObj == null)
|
||
return null;
|
||
var newObj = Object.Instantiate(OldObj);
|
||
if (newObj == null)
|
||
return null;
|
||
newObj.SetActive(true);
|
||
newObj.transform.SetParent(OldObj.transform.parent);
|
||
newObj.transform.localPosition = OldObj.transform.localPosition;
|
||
newObj.transform.localScale = OldObj.transform.localScale;
|
||
return newObj;
|
||
}
|
||
|
||
public static void AddChildObj()
|
||
{
|
||
}
|
||
|
||
public static string GetTimeChinaStr(int timeSeconds)
|
||
{
|
||
var hou = timeSeconds / 3600;
|
||
var mm = (timeSeconds - hou * 3600) / 60;
|
||
var sec = timeSeconds - hou * 3600 - mm * 60;
|
||
if (hou <= 0 && mm <= 0) return StrDictionary.GetClientDictionaryString("#{1794}", sec);
|
||
if (hou <= 0)
|
||
return StrDictionary.GetClientDictionaryString("#{2448}", mm) +
|
||
StrDictionary.GetClientDictionaryString("#{1794}", sec);
|
||
return StrDictionary.GetClientDictionaryString("#{2447}", hou) +
|
||
StrDictionary.GetClientDictionaryString("#{2448}", mm) +
|
||
StrDictionary.GetClientDictionaryString("#{1794}", sec);
|
||
}
|
||
|
||
public static string GetTimeStr(float timeSeconds)
|
||
{
|
||
var day = 0;
|
||
var hour = 0;
|
||
var minute = 0;
|
||
var second = 0;
|
||
if (timeSeconds <= 0) return "00:00";
|
||
day = Mathf.FloorToInt(timeSeconds / (3600 * 24));
|
||
hour = Mathf.FloorToInt((timeSeconds - day * 3600 * 24) / 3600);
|
||
minute = Mathf.FloorToInt((timeSeconds - day * 3600 * 24 - hour * 3600) / 60);
|
||
second = Mathf.FloorToInt(timeSeconds - day * 3600 * 24 - hour * 3600 - minute * 60);
|
||
var result = "";
|
||
if (day > 0)
|
||
result = string.Format("{0}:{1}", result, day);
|
||
if (hour > 0)
|
||
result = string.Format("{0}:{1}", result, GetNumStr(hour));
|
||
result = string.Format("{0}:{1}", result, GetNumStr(minute));
|
||
result = string.Format("{0}:{1}", result, GetNumStr(second));
|
||
while (result.Length > 0)
|
||
if (result[0] == ':')
|
||
result = result.Remove(0, 1);
|
||
else
|
||
break;
|
||
return result;
|
||
}
|
||
|
||
public static string GetNumStr(int data)
|
||
{
|
||
if (data >= 10)
|
||
return data.ToString();
|
||
return string.Format("0{0}", data);
|
||
}
|
||
|
||
public static string GetChinaNum(char ch)
|
||
{
|
||
switch (ch)
|
||
{
|
||
case '1': return StrDictionary.GetClientDictionaryString("#{9907}");
|
||
case '2': return StrDictionary.GetClientDictionaryString("#{9908}");
|
||
case '3': return StrDictionary.GetClientDictionaryString("#{9909}");
|
||
case '4': return StrDictionary.GetClientDictionaryString("#{9910}");
|
||
case '5': return StrDictionary.GetClientDictionaryString("#{9911}");
|
||
case '6': return StrDictionary.GetClientDictionaryString("#{9912}");
|
||
case '7': return StrDictionary.GetClientDictionaryString("#{9913}");
|
||
case '8': return StrDictionary.GetClientDictionaryString("#{9914}");
|
||
case '9': return StrDictionary.GetClientDictionaryString("#{9915}");
|
||
case '0': return StrDictionary.GetClientDictionaryString("#{9921}");
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
public static string GetChinaNumStr(int num)
|
||
{
|
||
return string.Empty;
|
||
// ???????????????
|
||
//string data = "";
|
||
//int index = 0;
|
||
//while(num>0)
|
||
//{
|
||
// int residue = num % 10;
|
||
//}
|
||
//return data;
|
||
}
|
||
|
||
public static void ResetShader(GameObject newObj)
|
||
{
|
||
#if UNITY_EDITOR && UNITY_ANDROID
|
||
var renders = newObj.GetComponentsInChildren<Renderer>();
|
||
for (var i = 0; i < renders.Length; i++)
|
||
{
|
||
var render = renders[i];
|
||
if (render == null)
|
||
continue;
|
||
for (var j = 0; j < render.sharedMaterials.Length; j++)
|
||
if (render.sharedMaterials[j] != null && render.sharedMaterials[j].shader != null)
|
||
{
|
||
var shader = Shader.Find(render.sharedMaterials[j].shader.name);
|
||
render.sharedMaterials[j].shader = shader;
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
|
||
// public static bool InitMeshRenderWeapon(GameObject ModelObj,GameObject weaponModel, string strWeaponPoint)
|
||
// {
|
||
// if (ModelObj == null || weaponModel == null)
|
||
// return false;
|
||
//
|
||
// Transform weaponOld = null;
|
||
//
|
||
// //加 脚本节点方式先不使用,看后面需求
|
||
// WeaponAddPoint[] points = ModelObj.GetComponentsInChildren<WeaponAddPoint>();
|
||
// for (int i = 0; i < points.Length; i++)
|
||
// {
|
||
// WeaponAddPoint point = points[i];
|
||
// if (point.pointName == strWeaponPoint)
|
||
// {
|
||
// weaponOld = point.transform;
|
||
// WeaponAddPoint pointNew = weaponModel.GetComponent<WeaponAddPoint>();
|
||
// if (pointNew == null)
|
||
// {
|
||
// pointNew = weaponModel.AddComponent<WeaponAddPoint>();
|
||
// }
|
||
// if (pointNew != null)
|
||
// {
|
||
// pointNew.pointName = strWeaponPoint;
|
||
// }
|
||
// break;
|
||
// }
|
||
// }
|
||
// Transform weaponParent = null;
|
||
// if (weaponOld == null)
|
||
// {
|
||
// Transform Model = ModelObj.transform.Find("Model");
|
||
// if (Model == null)
|
||
// return false;
|
||
// weaponParent = Model.Find(strWeaponPoint);
|
||
// if (weaponParent == null)
|
||
// return false;
|
||
// if (weaponParent.childCount <= 0)
|
||
// return false;
|
||
// weaponOld = weaponParent.GetChild(0);
|
||
// }
|
||
// if (weaponParent == null)
|
||
// {
|
||
// return false;
|
||
// }
|
||
//
|
||
// weaponModel.transform.parent = weaponParent;
|
||
// weaponModel.layer = weaponOld.parent.gameObject.layer;
|
||
// Transform[] transforms = weaponModel.GetComponentsInChildren<Transform>();
|
||
// for (int i = 0; i < transforms.Length; i++)
|
||
// {
|
||
// transforms[i].gameObject.layer = weaponOld.parent.gameObject.layer;
|
||
// }
|
||
// weaponModel.transform.localPosition = weaponOld.localPosition;
|
||
// weaponModel.transform.localScale = weaponOld.localScale;
|
||
// weaponModel.transform.localRotation = weaponOld.localRotation;
|
||
// weaponOld.parent = null;
|
||
// weaponOld.gameObject.SetActive(false);
|
||
// GameObject.Destroy(weaponOld.gameObject);
|
||
// return true;
|
||
// }
|
||
//
|
||
// public static bool InitSkinMeshRenderWeapon(GameObject ModelObj, GameObject weaponModel, string strWeaponPoint)
|
||
// {
|
||
// if (ModelObj == null || weaponModel == null)
|
||
// return false;
|
||
//
|
||
// Transform weaponOld = null;
|
||
//
|
||
// //加 脚本节点方式先不使用,看后面需求
|
||
// WeaponAddPoint[] points = ModelObj.GetComponentsInChildren<WeaponAddPoint>();
|
||
// WeaponAddPoint pointNew = weaponModel.GetComponent<WeaponAddPoint>();
|
||
// for (int i = 0; i < points.Length; i++)
|
||
// {
|
||
// WeaponAddPoint point = points[i];
|
||
// if (point.pointName.ToLower() == strWeaponPoint.ToLower())
|
||
// {
|
||
// weaponOld = point.transform;
|
||
// if (pointNew == null)
|
||
// {
|
||
// pointNew = weaponModel.AddComponent<WeaponAddPoint>();
|
||
// }
|
||
// if (pointNew != null)
|
||
// {
|
||
// pointNew.pointName = strWeaponPoint;
|
||
// }
|
||
// break;
|
||
// }
|
||
// }
|
||
//
|
||
// if (weaponOld == null)
|
||
// {
|
||
// Transform Model = null;
|
||
// if (ModelObj.name == "Model")
|
||
// {
|
||
// Model = ModelObj.transform;
|
||
// }
|
||
// else
|
||
// {
|
||
// Model = ModelObj.transform.Find("Model");
|
||
// }
|
||
// if (Model == null)
|
||
// return false;
|
||
// Transform weaponParent = Model.transform.Find(strWeaponPoint);
|
||
// if (weaponParent == null)
|
||
// return false;
|
||
// if (weaponParent.childCount <= 0)
|
||
// return false;
|
||
// weaponOld = weaponParent.GetChild(0);
|
||
// }
|
||
// Transform wesponParent = weaponOld.parent;
|
||
// if (wesponParent == null)
|
||
// {
|
||
// return false;
|
||
// }
|
||
// weaponModel.transform.parent = wesponParent;
|
||
// weaponModel.layer = weaponOld.parent.gameObject.layer;
|
||
// Transform[] transforms = weaponModel.GetComponentsInChildren<Transform>();
|
||
// for (int i = 0; i < transforms.Length; i++)
|
||
// {
|
||
// transforms[i].gameObject.layer = weaponOld.parent.gameObject.layer;
|
||
// }
|
||
// weaponModel.transform.localPosition = weaponOld.localPosition;
|
||
// weaponModel.transform.localScale = weaponOld.localScale;
|
||
// weaponModel.transform.localEulerAngles = weaponOld.localEulerAngles;
|
||
//
|
||
// SkinnedMeshRenderer skinNew = weaponModel.GetComponentInChildren<SkinnedMeshRenderer>();
|
||
// SkinnedMeshRenderer skinOld = weaponOld.GetComponentInChildren<SkinnedMeshRenderer>();
|
||
// if (skinNew == null || skinOld == null)
|
||
// return false;
|
||
//
|
||
// Transform[] Bones = new Transform[skinNew.bones.Length];
|
||
// Transform[] ModelBones = ModelObj.transform.GetComponentsInChildren<Transform>(true);
|
||
// int iCount = skinNew.bones.Length;
|
||
// for (int i = 0; i < iCount; i++)
|
||
// {
|
||
// if (skinNew.bones[i])
|
||
// {
|
||
// if (skinOld.bones.Length <= i || skinOld.bones[i]==null)
|
||
// break;
|
||
// Bones[i] = Utils.FindNode(ModelBones, skinOld.bones[i].name);
|
||
// }
|
||
// }
|
||
//
|
||
// skinNew.rootBone = skinOld.rootBone;
|
||
// skinNew.bones = Bones;
|
||
// skinNew.updateWhenOffscreen = skinOld.updateWhenOffscreen;
|
||
// skinNew.localBounds = skinOld.localBounds;
|
||
// weaponOld.parent = null;
|
||
// weaponOld.gameObject.SetActive(false);
|
||
// GameObject.Destroy(weaponOld.gameObject);
|
||
// return true;
|
||
// }
|
||
|
||
//寻找子物体
|
||
public static Transform FindChild(Transform parent, string childPath)
|
||
{
|
||
if (parent == null)
|
||
return null;
|
||
var child = parent.Find(childPath);
|
||
return child;
|
||
}
|
||
|
||
public static Transform FindNode(Transform[] nodes, string name)
|
||
{
|
||
for (var i = 0; i < nodes.Length; i++)
|
||
if (nodes[i].name == name)
|
||
return nodes[i];
|
||
return null;
|
||
}
|
||
|
||
public static T GetChildComponent<T>(Transform parant, string childPath)
|
||
{
|
||
if (parant != null)
|
||
{
|
||
var child = FindChild(parant, childPath);
|
||
if (child != null) return child.gameObject.GetComponent<T>();
|
||
}
|
||
|
||
return default(T);
|
||
}
|
||
|
||
public static bool EnterCopy(int fubenID)
|
||
{
|
||
if (fubenID == GameManager.gameManager.PlayerDataPool.EnterSceneCache.EnterCopySceneID)
|
||
{
|
||
GUIData.AddNotifyData("#{49030}");
|
||
return false;
|
||
}
|
||
|
||
var req = (CG_REQ_ENTER_COPY) PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_ENTER_COPY);
|
||
req.SetCopyid(fubenID);
|
||
req.SendPacket();
|
||
return true;
|
||
}
|
||
|
||
public static bool IsCanPK(int nSceneClassID)
|
||
{
|
||
var tabSceneClass = TableManager.GetSceneClassByID(nSceneClassID);
|
||
if (tabSceneClass != null)
|
||
{
|
||
var nPVPRule = tabSceneClass.PVPRule;
|
||
var tabRule = TableManager.GetPVPRuleByID(nPVPRule);
|
||
if (tabRule != null) return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public static bool IsIncPKValue(int nSceneClassID)
|
||
{
|
||
var tabSceneClass = TableManager.GetSceneClassByID(nSceneClassID);
|
||
if (tabSceneClass != null)
|
||
{
|
||
var nPVPRule = tabSceneClass.PVPRule;
|
||
var tabRule = TableManager.GetPVPRuleByID(nPVPRule);
|
||
if (tabRule != null) return tabRule.IsIncPKValue == 1 ? true : false;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public static Vector3 GetInputPostion(int fingerId = -1)
|
||
{
|
||
var pos = Vector3.zero;
|
||
if (Input.touchPressureSupported)
|
||
{
|
||
if (Input.touchCount > 0)
|
||
{
|
||
if (fingerId >= 0)
|
||
for (var i = 0; i < Input.touchCount; i++)
|
||
if (Input.touches[i].fingerId == fingerId)
|
||
{
|
||
pos = Input.touches[i].position;
|
||
return pos;
|
||
}
|
||
|
||
var touch = Input.GetTouch(Input.touchCount - 1);
|
||
pos = touch.position;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
pos = Input.mousePosition;
|
||
}
|
||
|
||
return pos;
|
||
}
|
||
|
||
public static Vector3 PositionToRectLocal(RectTransform rect, Vector3 position)
|
||
{
|
||
if (rect == null)
|
||
return Vector3.zero;
|
||
if (UIManager.Instance().Canvas.renderMode == RenderMode.ScreenSpaceCamera)
|
||
{
|
||
var localPosition = Vector2.zero;
|
||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, position, UIManager.Instance().UICamera,
|
||
out localPosition);
|
||
return new Vector3(localPosition.x, localPosition.y, 0);
|
||
}
|
||
|
||
return rect.InverseTransformPoint(position);
|
||
}
|
||
|
||
//constType == 3 物品 constSubType为物品ID
|
||
//constType == 4 金钱 constSubType货币类型ID
|
||
public static int GetConstPrice(int constType, int constSubType, int moneyType, out int omoneyType)
|
||
{
|
||
omoneyType = (int) MONEYTYPE.MONEYTYPE_YUANBAO;
|
||
|
||
switch (constType)
|
||
{
|
||
case 3:
|
||
{
|
||
var shops = TableManager.GetYuanBaoShop().Values;
|
||
foreach (var shop in shops)
|
||
if ((moneyType == -1 || shop.MoneyType == moneyType) && shop.ItemID == constSubType)
|
||
{
|
||
omoneyType = shop.MoneyType;
|
||
return shop.PriceForever;
|
||
}
|
||
}
|
||
break;
|
||
case 4:
|
||
{
|
||
return 1;
|
||
}
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
public static Texture2D CaptureScreen(Camera came = null, string savePath = "")
|
||
{
|
||
if (came == null)
|
||
came = Camera.main;
|
||
if (came == null)
|
||
return null;
|
||
var r = new Rect(0, 0, Screen.width, Screen.height);
|
||
if (came.pixelRect.x != 1 || came.pixelRect.y != 1)
|
||
r = came.pixelRect;
|
||
var rt = new RenderTexture((int) r.width, (int) r.height, 0);
|
||
var Old = came.clearFlags;
|
||
came.clearFlags = CameraClearFlags.Depth;
|
||
came.targetTexture = rt;
|
||
came.Render();
|
||
|
||
RenderTexture.active = rt;
|
||
var screenShot = new Texture2D((int) r.width, (int) r.height, TextureFormat.ARGB32, false);
|
||
|
||
screenShot.ReadPixels(r, 0, 0);
|
||
screenShot.Apply();
|
||
came.targetTexture = null;
|
||
RenderTexture.active = null;
|
||
came.clearFlags = Old;
|
||
Object.Destroy(rt);
|
||
|
||
var bytes = screenShot.EncodeToPNG();
|
||
File.WriteAllBytes(savePath, bytes);
|
||
return screenShot;
|
||
}
|
||
|
||
public static string GetconstQuilityStr(int constType, int constSubType)
|
||
{
|
||
switch (constType)
|
||
{
|
||
case 3:
|
||
{
|
||
var commonItem = TableManager.GetCommonItemByID(constSubType);
|
||
if (commonItem != null)
|
||
return GetItemQualityFrame(commonItem.Quality);
|
||
}
|
||
break;
|
||
case 4:
|
||
{
|
||
return GetItemQualityFrame(3);
|
||
}
|
||
}
|
||
|
||
return GetItemQualityFrame(1);
|
||
}
|
||
|
||
public static string GetConstIcon(int constType, int constSubType)
|
||
{
|
||
switch (constType)
|
||
{
|
||
case 3:
|
||
{
|
||
var commonItem = TableManager.GetCommonItemByID(constSubType);
|
||
if (commonItem != null)
|
||
return commonItem.Icon;
|
||
}
|
||
break;
|
||
case 4:
|
||
{
|
||
return UICurrencyItem.GetCurrencySprite((MONEYTYPE) constSubType);
|
||
}
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
public static string GetConstName(int constType, int constSubType)
|
||
{
|
||
switch (constType)
|
||
{
|
||
case 3:
|
||
{
|
||
var commonItem = TableManager.GetCommonItemByID(constSubType);
|
||
if (commonItem != null)
|
||
return commonItem.Name;
|
||
}
|
||
break;
|
||
case 4:
|
||
{
|
||
return StrDictionary.GetClientStrMoneyType((MONEYTYPE) constSubType);
|
||
}
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
public static long GetConstHas(int constType, int constSubType)
|
||
{
|
||
switch (constType)
|
||
{
|
||
case 3:
|
||
{
|
||
return GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(constSubType);
|
||
}
|
||
|
||
case 4:
|
||
{
|
||
return GameManager.gameManager.PlayerDataPool.Money.GetMoneyByType((MONEYTYPE) constSubType);
|
||
}
|
||
}
|
||
|
||
return -1;
|
||
}
|
||
|
||
public static bool SetObjInputPosition(GameObject child, RectTransform rect = null)
|
||
{
|
||
var pos = GetInputPostion();
|
||
if (child != null && child.transform.parent != null)
|
||
{
|
||
if (rect == null)
|
||
rect = child.transform.parent.GetComponent<RectTransform>();
|
||
if (rect != null)
|
||
{
|
||
child.transform.localPosition = PositionToRectLocal(rect, pos);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public static string GetMoneyName(int moneyType)
|
||
{
|
||
switch (moneyType)
|
||
{
|
||
case (int) MONEYTYPE.MONEYTYPE_COIN:
|
||
return StrDictionary.GetClientDictionaryString("#{6003}");
|
||
case (int) MONEYTYPE.MONEYTYPE_YUANBAO:
|
||
return StrDictionary.GetClientDictionaryString("#{6001}");
|
||
case (int) MONEYTYPE.MONEYTYPE_YUANBAO_BIND:
|
||
return StrDictionary.GetClientDictionaryString("#{6002}");
|
||
case (int) MONEYTYPE.MONEYTYPE_COIN_BIND:
|
||
return StrDictionary.GetClientDictionaryString("#{6004}");
|
||
}
|
||
|
||
return "";
|
||
}
|
||
|
||
//帮会权限判断
|
||
public static int GuildJobPowerFull(int index)
|
||
{
|
||
var job = -1;
|
||
var guildJobs = TableManager.GetGuildJurisdiction();
|
||
foreach (var guildjob in guildJobs)
|
||
if (guildjob.Value.getAuthorityCount() > index && guildjob.Value.GetAuthoritybyIndex(index) == 1)
|
||
job = guildjob.Value.Id;
|
||
else
|
||
break;
|
||
return job;
|
||
}
|
||
|
||
//帮会权限判断
|
||
public static bool IsGuildPowerFull(int index, bool istip = true)
|
||
{
|
||
var table = GameManager.gameManager.PlayerDataPool.GuildInfo.GetMemberJurisdic(GameManager.gameManager
|
||
.PlayerDataPool.MainPlayerBaseAttr.Guid);
|
||
if (table == null || table.GetAuthoritybyIndex(index) == 0)
|
||
{
|
||
//无权进行此操作
|
||
if (istip)
|
||
{
|
||
var job = GuildJobPowerFull(index);
|
||
if (Guild.GuildJobName.ContainsKey(job))
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{2513}",
|
||
StrDictionary.GetClientDictionaryString(Guild.GuildJobName[job])));
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
//高昌报名的
|
||
public static void SignUp()
|
||
{
|
||
var activityBase =
|
||
ActivityDataManager.Instance.GetActivityTabByServerType(ActivityDataManager.Activity_Type
|
||
.ACTIVITY_TYPE_TREASURE_GLOD);
|
||
if (activityBase == null)
|
||
return;
|
||
if (GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level < activityBase.Level)
|
||
{
|
||
GUIData.AddNotifyData("#{9024}");
|
||
return;
|
||
}
|
||
|
||
UIManager.ShowUI(UIInfo.TreasureSignUp);
|
||
}
|
||
|
||
//计算两个点的路径长度
|
||
public static float GetNavMeshDistance(Vector3 Start, Vector3 End)
|
||
{
|
||
var path = new NavMeshPath();
|
||
if (NavMesh.CalculatePath(Start, End, -1, path))
|
||
{
|
||
if (path.corners.Length < 2)
|
||
return 0f;
|
||
|
||
//initialize variables
|
||
var previousCorner = path.corners[0];
|
||
var lengthSoFar = 0.0f;
|
||
var i = 1;
|
||
|
||
//iterate over corners for the full path length
|
||
while (i < path.corners.Length)
|
||
{
|
||
var currentCorner = path.corners[i];
|
||
lengthSoFar += Vector3.Distance(previousCorner, currentCorner);
|
||
previousCorner = currentCorner;
|
||
i++;
|
||
}
|
||
|
||
return lengthSoFar;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
//字符串字符个数
|
||
public static int StrCharLength(string strText)
|
||
{
|
||
var len = 0;
|
||
for (var i = 0; i < strText.Length; i++) len += (int) strText[i] > 127 ? 2 : 1;
|
||
return len;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取货币的可以替代类型
|
||
/// </summary>
|
||
/// <param name="consumeType">消耗类型</param>
|
||
/// <param name="consumeID">消耗子类型</param>
|
||
/// <param name="exchangeType">取代的消耗类型</param>
|
||
/// <param name="exchageId">取代的消耗子类型</param>
|
||
/// <returns>
|
||
/// true:存在可替换类型
|
||
/// false:不存在可替代类型
|
||
/// </returns>
|
||
public static bool ConsumeTypeExchange(int consumeType, int consumeID, out int cConsumeType, out int cConsumeId)
|
||
{
|
||
cConsumeType = -1;
|
||
cConsumeId = -1;
|
||
|
||
if ((int) CONSUM_TYPE.MONEY == consumeType)
|
||
switch ((MONEYTYPE) consumeID)
|
||
{
|
||
case MONEYTYPE.MONEYTYPE_COIN_BIND:
|
||
cConsumeType = (int) CONSUM_TYPE.MONEY;
|
||
cConsumeId = (int) MONEYTYPE.MONEYTYPE_COIN;
|
||
return true;
|
||
case MONEYTYPE.MONEYTYPE_YUANBAO_BIND:
|
||
cConsumeType = (int) CONSUM_TYPE.MONEY;
|
||
cConsumeId = (int) MONEYTYPE.MONEYTYPE_YUANBAO;
|
||
return true;
|
||
}
|
||
|
||
if ((int) PropID.PropertyID.BIND_YINLIANG == consumeID)
|
||
{
|
||
cConsumeType = (int) CONSUM_TYPE.MONEY;
|
||
cConsumeId = (int) MONEYTYPE.MONEYTYPE_COIN;
|
||
return true;
|
||
}
|
||
|
||
if ((int) PropID.PropertyID.BIND_YUANBAO == consumeID)
|
||
{
|
||
cConsumeType = (int) CONSUM_TYPE.MONEY;
|
||
cConsumeId = (int) MONEYTYPE.MONEYTYPE_YUANBAO_BIND;
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
// public static void CaptureScreen(Camera came = null, string savePath = "", CaptureOver fun = null)
|
||
// {
|
||
// if (came != null)
|
||
// {
|
||
// CameraCapture capTure = came.gameObject.AddComponent<CameraCapture>();
|
||
// if (capTure != null)
|
||
// {
|
||
// capTure.AddCaptureOver(fun);
|
||
// capTure.Capture(savePath);
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
/// <summary>
|
||
/// 判断两个时间是否跨天
|
||
/// </summary>
|
||
/// <param name="one">其中一个时间:距离1970经过的毫秒数</param>
|
||
/// <param name="other">另一个时间:距离1970经过的毫秒数</param>
|
||
/// <returns>true: 跨天 false: 不跨天</returns>
|
||
public static bool IsCrossDay(long one, long other)
|
||
{
|
||
var oneTime = new DateTime(one);
|
||
var otherTime = new DateTime(other);
|
||
if (oneTime.Year != otherTime.Year || oneTime.Month != otherTime.Month ||
|
||
oneTime.Day != otherTime.Day) return true;
|
||
|
||
return false;
|
||
}
|
||
|
||
public static void HideMainTopRightUI(bool closeMap = true, bool closeSHBtn = true)
|
||
{
|
||
if (closeMap)
|
||
UIManager.CloseUI(UIInfo.MiniMapRoot);
|
||
|
||
if (FunctionButtonLogic.Instance())
|
||
{
|
||
FunctionButtonLogic.Instance().HideBaseBtns();
|
||
if (closeSHBtn)
|
||
FunctionButtonLogic.Instance().ShowOrHideBtn.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
FunctionButtonLogic._IsShowInit = false;
|
||
}
|
||
|
||
if (ActiveBtns.Instance()) ActiveBtns.Instance().HidePanel();
|
||
if (GuanningAreaLogic.Instance()) GuanningAreaLogic.Instance().ShowPanel();
|
||
|
||
MarketingActsRoot.HideBtns();
|
||
|
||
if (SuperBenefitFirstRechargeTip.Instance == true) SuperBenefitFirstRechargeTip.Instance.HideBtns();
|
||
}
|
||
|
||
public static void ShowMainTopRightUI()
|
||
{
|
||
if (FunctionButtonLogic.Instance())
|
||
{
|
||
if (FunctionButtonLogic.Instance().ShowBaseBtns() == false)
|
||
return;
|
||
FunctionButtonLogic.Instance().ShowOrHideBtn.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
FunctionButtonLogic._IsShowInit = true;
|
||
}
|
||
|
||
UIManager.ShowUI(UIInfo.MiniMapRoot);
|
||
if (ActiveBtns.Instance()) ActiveBtns.Instance().ShowPanel();
|
||
if (GuanningAreaLogic.Instance()) GuanningAreaLogic.Instance().HidePanel();
|
||
|
||
MarketingActsRoot.ShowBtns();
|
||
|
||
if (SuperBenefitFirstRechargeTip.Instance) SuperBenefitFirstRechargeTip.Instance.ShowBtns();
|
||
}
|
||
|
||
public static void CheckFubenShowUI()
|
||
{
|
||
var fuben = TableManager.GetFubenByID(
|
||
GameManager.gameManager.PlayerDataPool.EnterSceneCache.EnterCopySceneID);
|
||
if (fuben == null)
|
||
return;
|
||
//世界BOSS和BOSS之家的副本
|
||
if (fuben.IsShowInfoUI == 2)
|
||
{
|
||
UIManager.ShowUI(UIInfo.CrossServerBossInfo);
|
||
if (WorldBossData.Instance.BossSceneType == 1 && tipsState) //是世界boss、没有队伍、没关闭提示
|
||
AutoCreateTeam();
|
||
}
|
||
|
||
//进入跨服BOSS活动副本
|
||
if (GameManager.gameManager.RunningScene == GlobeVar.CROSSSERVERSCENEID
|
||
&& ActivityDataManager.Instance.IsActivityState(
|
||
(int) ActivityDataManager.Activity_Type.ACTIVITY_TYPE_CROSSSERVERBOSS,
|
||
ActivityDataManager.ActivityState.Playing))
|
||
{
|
||
UIManager.ShowUI(UIInfo.CrossServerBossInfo);
|
||
PvpMatchRulePanel.OPenUI("#{49101}");
|
||
}
|
||
}
|
||
|
||
//自动创建队伍
|
||
private static void AutoCreateTeam()
|
||
{
|
||
if (Singleton<ObjManager>.GetInstance().MainPlayer != null)
|
||
{
|
||
Singleton<ObjManager>.GetInstance().MainPlayer.StopMove();
|
||
GameManager.gameManager.AutoSearch.Stop();
|
||
if (GameManager.gameManager.PlayerDataPool.IsHaveTeam() &&
|
||
GameManager.gameManager.PlayerDataPool.TeamInfo.IsCaptain() ||
|
||
!GameManager.gameManager.PlayerDataPool.IsHaveTeam())
|
||
MessageBoxLogic.OpenOKCancelToggleBox("boss实力过于强大,是否免费一键招募助战帮您攻击boss(不影响BOSS的相关掉落)",
|
||
state => { tipsState = state; }, tipsState, "招募", "否", null, () =>
|
||
{
|
||
if (!GameManager.gameManager.PlayerDataPool.IsHaveTeam())
|
||
GameManager.gameManager.PlayerDataPool.TeamInfo.CreaetTeam(-1, -1, -1, () =>
|
||
{
|
||
UIManager.ShowUI(UIInfo.TeamInfoRoot, (bSuccess, param) =>
|
||
{
|
||
if (bSuccess) AutoAddRobote();
|
||
});
|
||
});
|
||
else
|
||
UIManager.ShowUI(UIInfo.TeamInfoRoot, (bSuccess, param) =>
|
||
{
|
||
if (bSuccess) AutoAddRobote();
|
||
});
|
||
});
|
||
}
|
||
}
|
||
|
||
//自动雇佣机器人
|
||
private static void AutoAddRobote()
|
||
{
|
||
if (TeamInfoWindow.Instance())
|
||
{
|
||
var targetTabs = TableManager.GetTeamTarget().Values;
|
||
foreach (var item in targetTabs)
|
||
if (item.CopySceneId1 == GameManager.gameManager.PlayerDataPool.EnterSceneCache.EnterCopySceneID)
|
||
{
|
||
TeamInfoWindow.Instance().SelectedTargets(item, item.MinLV, item.MaxLv,
|
||
() => { TeamInfoWindow.Instance().OnBtnInvateRobot(); });
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
#region vip icon
|
||
|
||
public static int VipFreeLiveLeave()
|
||
{
|
||
var VipCanUseLevel = 0;
|
||
var vipId = TableManager.GetVipIdoitInChargeByID(GameManager.gameManager.PlayerDataPool.VipIdoitId);
|
||
if (vipId != null) VipCanUseLevel = vipId.Param;
|
||
Tab_PrivilegeFunction tab_PrivilegeFunction = null;
|
||
foreach (var tab in TableManager.GetPrivilegeFunction())
|
||
if (tab.Value.PrivilegeId == 20)
|
||
{
|
||
tab_PrivilegeFunction = tab.Value;
|
||
break;
|
||
}
|
||
|
||
if (VipCanUseLevel < GameManager.gameManager.PlayerDataPool.VipCost)
|
||
VipCanUseLevel = GameManager.gameManager.PlayerDataPool.VipCost;
|
||
int freeTimes;
|
||
if (tab_PrivilegeFunction != null &&
|
||
int.TryParse(tab_PrivilegeFunction.GetVipbyIndex(VipCanUseLevel), out freeTimes))
|
||
return freeTimes - GameManager.gameManager.PlayerDataPool.VipFreeLive;
|
||
return 0;
|
||
}
|
||
|
||
public static string GetVipIcon(int vipLevel)
|
||
{
|
||
if (vipLevel >= 1 && vipLevel <= 4)
|
||
return "ChatVip1";
|
||
if (vipLevel >= 5 && vipLevel <= 8)
|
||
return "ChatVip2";
|
||
if (vipLevel >= 9 && vipLevel <= 12)
|
||
return "ChatVip3";
|
||
return "";
|
||
}
|
||
|
||
public static string GetPrivilegeVipIcon(int privilegeVip)
|
||
{
|
||
if (privilegeVip == 1)
|
||
return "ChatPrivilegeVip1";
|
||
if (privilegeVip == 2)
|
||
return "ChatPrivilegeVip2";
|
||
if (privilegeVip == 3)
|
||
return "ChatPrivilegeVip3";
|
||
return "";
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region HTTP Sign(POST Sign + ParamDataStream)
|
||
|
||
private static readonly string _randomString = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789";
|
||
private static readonly int _randomStringLength = 8; //固定长度8
|
||
private static readonly string _tokenStr = "ZYAPI"; //固定TOKEN
|
||
private static string _timeAttr = "";
|
||
private static string _randomStrAttr = "";
|
||
|
||
public static string GetHttpSingStr()
|
||
{
|
||
return string.Format("t={0}&r={1}&sign={2}", GetTimeStamp(), GetRandomStr(),
|
||
GetSignString(_timeAttr, _randomStrAttr, _tokenStr));
|
||
}
|
||
|
||
public static string GetMD5SingStr(string tkey, string signKey, string key)
|
||
{
|
||
return string.Format("\"{0}\":\"{1}\",\"{2}\":\"{3}\"", tkey, GetTimeStamp(), signKey,
|
||
GetMd5_32(_timeAttr + key));
|
||
}
|
||
|
||
public static string GetHttpSingJSONStr(string tkey, string rkey, string signKey)
|
||
{
|
||
return string.Format("\"{0}\":\"{1}\",\"{2}\":\"{3}\",\"{4}\":\"{5}\"", tkey, GetTimeStamp(), rkey,
|
||
GetRandomStr(), signKey, GetSignString(_timeAttr, _randomStrAttr, _tokenStr));
|
||
}
|
||
|
||
public static string GetHttpSingStr(string tkey, string rkey, string signKey)
|
||
{
|
||
return string.Format("{0}={1}&{2}={3}&{4}={5}", tkey, GetTimeStamp(), rkey, GetRandomStr(), signKey,
|
||
GetSignString(_timeAttr, _randomStrAttr, _tokenStr));
|
||
}
|
||
|
||
public static string GetTimeStamp()
|
||
{
|
||
_timeAttr = GlobalData.ServerAnsiTime.ToString();
|
||
if (GlobalData.ServerAnsiTime <= 0)
|
||
{
|
||
var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
|
||
var timeStamp = (long) (DateTime.Now - startTime).TotalSeconds; // 相差秒数
|
||
_timeAttr = timeStamp.ToString();
|
||
}
|
||
|
||
return _timeAttr;
|
||
}
|
||
|
||
//获取随机字符串
|
||
public static string GetRandomStr()
|
||
{
|
||
_randomStrAttr = "";
|
||
for (var index = 0; index < _randomStringLength; index++)
|
||
{
|
||
var statrtIndex = Random.Range(0, _randomString.Length - 1);
|
||
_randomStrAttr += _randomString.Substring(statrtIndex, 1);
|
||
}
|
||
|
||
return _randomStrAttr;
|
||
}
|
||
|
||
//获取签名
|
||
public static string GetSignString(string _timeStamp, string _randomString, string apiKey)
|
||
{
|
||
var _strList = new List<string>();
|
||
|
||
_strList.Add(_timeStamp);
|
||
_strList.Add(_randomString);
|
||
_strList.Add(apiKey);
|
||
|
||
|
||
//首字母升序排序
|
||
|
||
//_strList.Sort((string strA, string strB) =>
|
||
//{
|
||
// return string.Compare(strA, strB, false);
|
||
//});
|
||
|
||
return GetSignString(_strList.ToArray());
|
||
}
|
||
|
||
public static string GetSignString(params string[] strList)
|
||
{
|
||
//拼接
|
||
var _formatString = "";
|
||
for (var index = 0; index < strList.Length; index++) _formatString += strList[index];
|
||
|
||
//sha1加密
|
||
_formatString = SHA1(_formatString);
|
||
|
||
//md5加密
|
||
_formatString = GetMd5_32(_formatString);
|
||
var _signAttr = _formatString.ToUpper();
|
||
return _signAttr;
|
||
}
|
||
|
||
/// <summary>
|
||
/// SHA1 加密,返回大写字符串
|
||
/// </summary>
|
||
/// <param name="content">需要加密字符串</param>
|
||
/// <returns>返回40位UTF8 大写</returns>
|
||
public static string SHA1(string content)
|
||
{
|
||
SHA1 sha1 = new SHA1CryptoServiceProvider();
|
||
var bytes_old_string = Encoding.Default.GetBytes(content);
|
||
var bytes_new_string = sha1.ComputeHash(bytes_old_string);
|
||
var new_string = BitConverter.ToString(bytes_new_string);
|
||
new_string = new_string.Replace("-", "");
|
||
return new_string;
|
||
}
|
||
|
||
//MD5加密
|
||
public static string GetMd5_32(string str)
|
||
{
|
||
MD5 md5 = new MD5CryptoServiceProvider();
|
||
var bytes_old_string = Encoding.Default.GetBytes(str);
|
||
var bytes_new_string = md5.ComputeHash(bytes_old_string);
|
||
var new_string = BitConverter.ToString(bytes_new_string);
|
||
new_string = new_string.Replace("-", "");
|
||
return new_string;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region For lua
|
||
|
||
public static int RandomRange_int(int min, int max)
|
||
{
|
||
return Random.Range(min, max);
|
||
}
|
||
|
||
public static float RandomRange_float(float min, float max)
|
||
{
|
||
return Random.Range(min, max);
|
||
}
|
||
|
||
public static int EnumToLua(object em)
|
||
{
|
||
return (int) em;
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
} |