1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using QFramework;
- using System;
- using UnityEngine;
- public class DeviceSN : MonoSingleton<DeviceSN>
- {
- private string serial;
-
- /// <summary>
- /// 获取设备ID的后十位数字,在Unity中时为预设的设备ID
- /// </summary>
- /// <returns></returns>
- public long SendSerial()
- {
- AndroidJavaObject jo = new AndroidJavaObject("android.os.Build");
- serial = jo.GetStatic<string>("SERIAL");
- return SubStringDefault(serial);
- }
- public string SendSerialBy16()
- {
- //Debug.Log(Convert.ToString(DeviceSN.GetInstance().SendSerial(), 16));
- //return Convert.ToString(DeviceSN.GetInstance().SendSerial(), 16);
- #if UNITY_EDITOR
- return "ABD123456";
- #elif UNITY_ANDROID
- return Convert.ToString(DeviceSN.Instance.SendSerial(), 16);
- #endif
- }
- /// <summary>
- /// 获取从后往前数length位的string
- /// </summary>
- /// <param name="str">需要获取的源字符串</param>
- /// <param name="index">从第多少位开始往前数</param>
- /// <param name="length">往前数多少位</param>
- /// <returns></returns>
- public string SubStringByEnd(string str, int index, int length)
- {
- return str.Substring((index - length) < 0 ? 0 : (index - length), length);
- }
- /// <summary>
- /// 获取从最后一位开始往前数10位的数字
- /// </summary>
- /// <param name="str">输入源字符串</param>
- /// <returns></returns>
- public long SubStringDefault(string str)
- {
- bool r = long.TryParse(SubStringByEnd(str, str.Length, 10),out long result);
- if (!r)
- {
- Debug.LogError($"获取TagID失败 : {result}");
- }
- return result;
- }
- }
|