123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using SC.XR.Unity.Module_Device;
- using System;
- using UnityEngine;
- public class DeviceSN : Singleton<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 "ABD1234561";
- #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;
- }
- public string GetSn()
- {
- #if UNITY_EDITOR
- return "ABD1234561";
- #elif UNITY_ANDROID
- AndroidJavaObject jo = new AndroidJavaObject("android.os.Build");
- serial = jo.GetStatic<string>("SERIAL");
- return serial;
- #endif
- return Module_Device.getInstance.Current.SN;
- }
- }
|