using UnityEngine;
using System.Collections;
using System;
using System.Net.NetworkInformation;
public class CStaticMethod
{
/// 获得系统经过的时间
/// int 毫秒
public static int SystemAfterTime()
{
return (int)(Time.realtimeSinceStartup * 1000);
}
/// 帧时间
public static int SystemFrameTime()
{
return (int)(Time.deltaTime * 1000);
}
private static System.Random mRandomFloat = null;
/// 获得一个0.0到1.0之间的随机数
public static float RandomFloat()
{
if(mRandomFloat==null)
{
mRandomFloat = new System.Random();
}
return (float)mRandomFloat.NextDouble();
}
/// 随机一个指定区间的整数
public static int RandomNext(int nMin, int nMax)
{
if(mRandomFloat==null)
{
mRandomFloat = new System.Random();
}
return mRandomFloat.Next (nMin, nMax);
}
/// 格式化时间
public static string FormatTime(float secondValue)
{
int intSecond = Mathf.FloorToInt(secondValue);
//小时
int hour = Mathf.FloorToInt(secondValue / 60 / 60);
//分钟
int minute = Mathf.FloorToInt((secondValue - hour * 60) / 60);
//秒
int second = intSecond % 60;
System.Text.StringBuilder strBuf = new System.Text.StringBuilder();
if(hour!=0)
{
strBuf.Append(hour);
strBuf.Append(":");
}
if (minute == 0)
{
strBuf.Append("00");
strBuf.Append(":");
}
else if (minute < 10)
{
strBuf.Append("0");
strBuf.Append(minute);
strBuf.Append(":");
}
else
{
strBuf.Append(minute);
strBuf.Append(":");
}
if (second == 0)
{
strBuf.Append("00");
}
else if (second < 10)
{
strBuf.Append("0");
strBuf.Append(second);
}
else
{
strBuf.Append(second);
}
return strBuf.ToString();
}
/// 格式化时间
public static string FormatShortTime(float secondValue)
{
int intSecond = Mathf.FloorToInt(secondValue);
//小时
int hour = Mathf.FloorToInt(secondValue / 60 / 60);
//分钟
int minute = Mathf.FloorToInt((secondValue - hour * 60) / 60);
//秒
int second = intSecond % 60;
System.Text.StringBuilder strBuf = new System.Text.StringBuilder ();
if (minute == 0)
{
strBuf.Append("00");
strBuf.Append(":");
}
else if (minute < 10)
{
strBuf.Append("0");
strBuf.Append(minute);
strBuf.Append(":");
}
else
{
strBuf.Append(minute);
strBuf.Append(":");
}
if (second == 0)
{
strBuf.Append("00");
}
else if (second < 10)
{
strBuf.Append("0");
strBuf.Append(second);
}
else
{
strBuf.Append(second);
}
return strBuf.ToString();
}
/// 获得资源的名字
public static string GetAssetsName(UnityEngine.Object assetsObject, string prefixName)
{
System.Text.StringBuilder strBuf = new System.Text.StringBuilder ();
strBuf.Append (prefixName);
strBuf.Append (assetsObject.name);
return strBuf.ToString ();
}
/// 是否为编辑器环境
public static bool IsEditor
{
get
{
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
return true;
#else
return true;
#endif
}
}
/// 调试设备地址
public static void DebugDeviceMac()
{
NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
for (int i = 0; i < nis.Length; i++)
{
CDebug.Log("name = " + nis[i].Name);
CDebug.Log("des = " + nis[i].Description);
CDebug.Log("type = " + nis[i].NetworkInterfaceType.ToString());
CDebug.Log("mac = " + nis[i].GetPhysicalAddress().ToString());
CDebug.Log("---------------------------");
}
}
public static string GetSubjectNameById(int value)
{
switch(value)
{
case 1: return "化学";
case 2: return "生物";
case 3: return "物理";
default:
return "未知课程";
}
}
public static int GetSelectIndexByAnswer(string value)
{
switch (value)
{
case "A": return 0;
case "B": return 1;
case "C": return 2;
case "D": return 3;
default:
return -1;
}
}
public static string FormatParagraph(string str, int count)
{
var paragraph = "";
for (int i = 0; i < str.Length; i++)
{
paragraph += str[i];
if (paragraph.Length % count == 0)
{
paragraph += "\n";//不需要换行就注掉
}
}
return paragraph;
}
public static string SerialId()
{
#if UNITY_EDITOR
return System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString();
#elif UNITY_ANDROID
AndroidJavaClass jo = new AndroidJavaClass(className: "android.os.Build");
string serial = jo.GetStatic(fieldName: "SERIAL");
return serial;
#elif UNITY_IPHONE
return "UNITY_IPHONE";
#endif
}
public static string DeviceType()
{
#if UNITY_EDITOR
return "windows";
#elif UNITY_ANDROID
return "android";
#elif UNITY_IPHONE
return "ios";
#else
return "default";
#endif
}
public static int CurTimeStamp()
{
return (int)((System.DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
}
}