123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- using UnityEngine;
- using System.Collections;
- using System;
- using System.Net.NetworkInformation;
- public class CStaticMethod
- {
- /// <summary>获得系统经过的时间</summary>
- /// <returns>int 毫秒</returns>
- public static int SystemAfterTime()
- {
- return (int)(Time.realtimeSinceStartup * 1000);
- }
- /// <summary>帧时间</summary>
- public static int SystemFrameTime()
- {
- return (int)(Time.deltaTime * 1000);
- }
- private static System.Random mRandomFloat = null;
- /// <summary>获得一个0.0到1.0之间的随机数</summary>
- public static float RandomFloat()
- {
- if(mRandomFloat==null)
- {
- mRandomFloat = new System.Random();
- }
- return (float)mRandomFloat.NextDouble();
- }
- /// <summary>随机一个指定区间的整数</summary>
- public static int RandomNext(int nMin, int nMax)
- {
- if(mRandomFloat==null)
- {
- mRandomFloat = new System.Random();
- }
- return mRandomFloat.Next (nMin, nMax);
- }
- /// <summary>格式化时间</summary>
- 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();
- }
- /// <summary>格式化时间</summary>
- 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();
- }
- /// <summary>获得资源的名字</summary>
- 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 ();
- }
- /// <summary>是否为编辑器环境</summary>
- public static bool IsEditor
- {
- get
- {
- #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
- return true;
- #else
- return true;
- #endif
- }
- }
- /// <summary>调试设备地址</summary>
- 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<string>(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);
- }
- }
|