Browse Source

修改编码

“hujiajun” 1 year ago
parent
commit
0c1850ca5e

+ 178 - 0
Assets/Editor/change.cs

@@ -0,0 +1,178 @@
+using UnityEngine;
+using UnityEditor;
+using System.IO;
+using System.Text;
+
+public class change
+{
+    // 添加一个右键菜单。
+    // % 按下ctrl时显示菜单。(Windows: control, macOS: command)
+    // & 按下alt时显示菜单。(Windows/Linux: alt, macOS: option)
+    // _ 按下shift时显示菜单。(Windows/Linux/macOS: shift)
+    [MenuItem("Assets/脚本改格式:GB2312->UTF8无BOM %g", false, 100)]
+    private static void CustomMenu()
+    {
+            Object[] selectedObjects = Selection.objects;
+            for(int i=0;i<selectedObjects.Length;i++)
+            {
+
+                // 例如: 获取Project视图中选定的对象
+                Object selectedObject = selectedObjects[i];
+                if (selectedObject != null)
+                {
+                    // 获取选定对象的相对路径
+                    string relativeAssetPath = AssetDatabase.GetAssetPath(selectedObject);
+                    // 获取项目根目录路径
+                    string projectPath = Path.GetDirectoryName(Application.dataPath);
+                    // 获取选定对象的绝对路径
+                    string absoluteAssetPath = Path.Combine(projectPath, relativeAssetPath);
+                    // 获取选定对象的文件名(包括后缀)
+                    string fileName = Path.GetFileName(relativeAssetPath);
+
+                    Debug.Log("执行自定义操作: " + selectedObject.name +
+                            ", 相对路径: " + relativeAssetPath +
+                            ", 绝对路径: " + absoluteAssetPath +
+                            ", 文件名: " + fileName);
+
+                    //判断是否是CSharp文件
+                    if (IsCSharpFile(fileName))
+                    {
+                        Debug.Log("这是一个csharp文件");
+                        ChangeFormat(absoluteAssetPath);
+                    }
+                    else
+                    {
+                        Debug.Log("兄弟,这不是一个csharp文件啊~~~~~~~~~~~");
+                    }
+                }
+            }
+    }
+
+    // 如果项目视图中有选中的对象,则启用右键菜单项
+    [MenuItem("Assets/脚本改格式:GB2312->UTF8无BOM %g", true)]
+    private static bool ValidateCustomMenu()
+    {
+        return Selection.activeObject != null;
+    }
+
+    /// <summary>
+    /// 判断该文件是否是CSharp文件
+    /// </summary>
+    /// <param name="fileName"></param>
+    /// <returns></returns>
+    private static bool IsCSharpFile(string fileName)
+    {
+        // 获取文件扩展名(包括点)
+        string fileExtension = Path.GetExtension(fileName);
+
+        // 将扩展名转换为小写并与 ".cs" 进行比较
+        if (fileExtension.ToLower() == ".cs")
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    /// <summary>
+    /// 文件格式转码:GB2312转成UTF8
+    /// 读取指定的文件,转换成UTF8(无BOM标记)格式后,回写覆盖原文件
+    /// </summary>
+    /// <param name="sourceFilePath">文件路径</param>
+    public static void ChangeFormat(string sourceFilePath)
+    {
+        Encoding ed =GetType(sourceFilePath);
+        
+        if( ed is System.Text.ASCIIEncoding )
+        {
+            ed =Encoding.GetEncoding("GB2312");
+            string fileContent = File.ReadAllText(sourceFilePath, ed);
+            File.WriteAllText(sourceFilePath, fileContent, Encoding.UTF8);
+        }
+        Debug.Log("处理结束!");
+    }
+    public static System.Text.Encoding GetType(string FILE_NAME)
+    {
+        FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);
+        Encoding r = GetType(fs);
+        fs.Close();
+        return r;
+    }
+        /// <summary>
+    /// 通过给定的文件流,判断文件的编码类型
+    /// </summary>
+    /// <param name="fs">文件流</param>
+    /// <returns>文件的编码类型</returns>
+    public static System.Text.Encoding GetType(FileStream fs)
+    {
+        byte[] Unicode = new byte[] { 0xFF, 0xFE, 0x41 };
+        byte[] UnicodeBIG = new byte[] { 0xFE, 0xFF, 0x00 };
+        byte[] UTF8 = new byte[] { 0xEF, 0xBB, 0xBF }; //带BOM
+        Encoding reVal = Encoding.Default;
+ 
+        BinaryReader r = new BinaryReader(fs, System.Text.Encoding.Default);
+        int i;
+        int.TryParse(fs.Length.ToString(), out i);
+        byte[] ss = r.ReadBytes(i);
+        if (IsUTF8Bytes(ss) || (ss[0] == 0xEF && ss[1] == 0xBB && ss[2] == 0xBF))
+        {
+            reVal = Encoding.UTF8;
+        }
+        else if (ss[0] == 0xFE && ss[1] == 0xFF && ss[2] == 0x00)
+        {
+            reVal = Encoding.BigEndianUnicode;
+        }
+        else if (ss[0] == 0xFF && ss[1] == 0xFE && ss[2] == 0x41)
+        {
+            reVal = Encoding.Unicode;
+        }
+        r.Close();
+        return reVal;
+ 
+    }
+      /// <summary>
+    /// 判断是否是不带 BOM 的 UTF8 格式
+    /// </summary>
+    /// <param name="data"></param>
+    /// <returns></returns>
+    private static bool IsUTF8Bytes(byte[] data)
+    {
+        int charByteCounter = 1;
+        //计算当前正分析的字符应还有的字节数
+        byte curByte; //当前分析的字节.
+        for (int i = 0; i < data.Length; i++)
+        {
+            curByte = data[i];
+            if (charByteCounter == 1)
+            {
+                if (curByte >= 0x80)
+                {
+                    //判断当前
+                    while (((curByte <<= 1) & 0x80) != 0)
+                    {
+                        charByteCounter++;
+                    }
+                    //标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X
+                    if (charByteCounter == 1 || charByteCounter > 6)
+                    {
+                        return false;
+                    }
+                }
+            }
+            else
+            {
+                //若是UTF-8 此时第一位必须为1
+                if ((curByte & 0xC0) != 0x80)
+                {
+                    return false;
+                }
+                charByteCounter--;
+            }
+        }
+        if (charByteCounter > 1)
+        {
+           // throw new Exception("非预期的byte格式");
+        }
+        return true;
+    }
+}

+ 11 - 0
Assets/Editor/change.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: da524eb190cf848efbf4c9ce910b573a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Assets/HotUpdate/GetScenePosRotEvent.cs

@@ -1,8 +1,8 @@
-using Blue;
+锘縰sing Blue;
 using System.Collections.Generic;
 
 /// <summary>
-/// 获取场景 Pos、Rot事件
+/// 鑾峰彇鍦烘櫙 Pos銆丷ot浜嬩欢
 /// </summary>
 public class GetScenePosRotEvent : IEvent
 {

+ 9 - 9
Assets/HotUpdate/GetZeroPos.cs

@@ -1,4 +1,4 @@
-using UnityEngine;
+锘縰sing UnityEngine;
 using XRTool.Util;
 
 public class GetZeroPos : MonoBehaviour
@@ -6,21 +6,21 @@ public class GetZeroPos : MonoBehaviour
     public Transform arMap;
     void Start()
     {
-        TimerMgr.Instance.CreateTimer(()=> {         // 获取MeshFilter组件
+        TimerMgr.Instance.CreateTimer(()=> {         // 鑾峰彇MeshFilter缁勪欢
             MeshFilter meshFilter = arMap.GetComponent<MeshFilter>();
 
             if (meshFilter != null)
             {
-                // 获取Mesh
+                // 鑾峰彇Mesh
                 Mesh mesh = meshFilter.mesh;
 
-                // 获取所有顶点
+                // 鑾峰彇鎵€鏈夐《鐐�
                 Vector3[] vertices = mesh.vertices;
 
-                // 初始化最小坐标值为第一个顶点的坐标
+                // 鍒濆�鍖栨渶灏忓潗鏍囧€间负绗�竴涓�《鐐圭殑鍧愭爣
                 Vector3 minPoint = vertices[0];
 
-                // 找到最小的X、Y和Z坐标值
+                // 鎵惧埌鏈€灏忕殑X銆乊鍜孼鍧愭爣鍊�
                 for (int i = 1; i < vertices.Length; i++)
                 {
                     Vector3 vertex = vertices[i];
@@ -29,12 +29,12 @@ public class GetZeroPos : MonoBehaviour
                     minPoint.z = Mathf.Min(minPoint.z, vertex.z);
                 }
 
-                // 最小坐标值就是网格的零点
-                Debug.Log("Mesh的零点:" + minPoint);
+                // 鏈€灏忓潗鏍囧€煎氨鏄�綉鏍肩殑闆剁偣
+                Debug.Log("Mesh鐨勯浂鐐癸細" + minPoint);
             }
             else
             {
-                Debug.LogError("未找到MeshFilter组件");
+                Debug.LogError("鏈�壘鍒癕eshFilter缁勪欢");
             }
         },1,-1);
 

+ 7 - 7
Assets/HotUpdate/GongShi2.cs

@@ -1,4 +1,4 @@
-using System.Collections;
+锘縰sing System.Collections;
 using System.Collections.Generic;
 using Blue;
 using UnityEngine;
@@ -33,7 +33,7 @@ public class GongShi2 : MonoBehaviour
             WebPosObj2 = new GameObject();
 
         //  Transform meshTestParent =(SceneIOCContainer.Instance.Pull("ARSpaceForAll") as GameObject).transform;
-        //创建空锚点GameObject
+        //鍒涘缓绌洪敋鐐笹ameObject
         GameObject go = WebPosObj;
         go.transform.parent = parent.parent;
         Vector2 p1 = new Vector2(x2 / tw * sceneLength, (th - (y2)) / th * sceneWidth);
@@ -44,7 +44,7 @@ public class GongShi2 : MonoBehaviour
         go.transform.localPosition = Vector3.zero;
         parent.parent = go.transform;
         yield return new WaitForSeconds(0.1f);
-        //创建空锚点 朝向
+        //鍒涘缓绌洪敋鐐� 鏈濆悜
         p1 = new Vector2(x22 / tw * sceneLength, (th - (y22)) / th * sceneWidth);
         p2 = Vector2.zero - p1;
         newPosition = new Vector3(-p2.x, 0, -p2.y);
@@ -59,12 +59,12 @@ public class GongShi2 : MonoBehaviour
         yield return new WaitForSeconds(0.1f);
       //  go.transform.parent = parent.parent;
      //   yield return new WaitForSeconds(0.1f);
-        //把当前物体设置到锚点内
+        //鎶婂綋鍓嶇墿浣撹�缃�埌閿氱偣鍐�
       //  yield return new WaitForSeconds(0.1f);
         go.transform.LookAt(go2.transform);
         go.transform.localEulerAngles = new Vector3(0, 360-go.transform.localEulerAngles.y, 0);
         yield return new WaitForSeconds(0.1f);
-        //设置回来
+        //璁剧疆鍥炴潵
         parent.parent = go.transform.parent;
 
         yield return new WaitForSeconds(0.1f);
@@ -88,8 +88,8 @@ public class GongShi2 : MonoBehaviour
         lvlist.Add(p1);
         Vector2 p2 = new Vector2(WebPosObj2.transform.localPosition.x / sceneLength * tw , th-((WebPosObj2.transform.localPosition.z )/ sceneWidth * th  ));
         lvlist.Add(p2);
-        Debug.Log("Web端Pos  :" + p1);
-        Debug.Log("Web端Pos 2 :" + p2);
+        Debug.Log("Web绔疨os  :" + p1);
+        Debug.Log("Web绔疨os 2 :" + p2);
         WebPosObj.transform.parent = parent.parent;
         WebPosObj2.transform.parent = parent.parent;
         return lvlist;

+ 3 - 3
Assets/HotUpdate/SavePanel.cs

@@ -1,4 +1,4 @@
-using Blue;
+锘縰sing Blue;
 using Newtonsoft.Json;
 using System.Collections.Generic;
 using UnityEngine;
@@ -19,7 +19,7 @@ public class SavePanel : AbstractController
     private ScenePosRotInfo rot = new ScenePosRotInfo();
 
     public LoadReference LoadReferenceController;
-    private GameObject goReference // 参照物
+    private GameObject goReference // 鍙傜収鐗�
     {
         get =>SceneIOCContainer.Instance.Pull("goRefrence")as GameObject;
     }
@@ -34,7 +34,7 @@ public class SavePanel : AbstractController
         if (b)
         {
             txtTip.SetActive(true);
-            txtTip.GetComponentInChildren<Text>().text = "如需移动场景,请按住手柄拖动场景并走动\n场景将跟随您的脚步进行整体移动";
+            txtTip.GetComponentInChildren<Text>().text = "濡傞渶绉诲姩鍦烘櫙锛岃�鎸変綇鎵嬫焺鎷栧姩鍦烘櫙骞惰蛋鍔╘n鍦烘櫙灏嗚窡闅忔偍鐨勮剼姝ヨ繘琛屾暣浣撶Щ鍔�";
         }
         this.gameObject.SetActive(b);
         parentObj.SetActive(!b);

+ 8 - 8
Assets/HotUpdate/SpotsItem.cs

@@ -1,4 +1,4 @@
-using LitJson;
+锘縰sing LitJson;
 using Newtonsoft.Json;
 using SC.XR.Unity.Module_InputSystem;
 using System.Collections;
@@ -28,7 +28,7 @@ public class SpotsItem
     public int triggerImageId;
 
     public UserSceneItem usi;
-    //景点中的模型
+    //鏅�偣涓�殑妯″瀷
     public Dictionary<string, ModelList> modelList = new Dictionary<string, ModelList>();
     public GameObject VuforiaItem;
     GameObject _spotsObj;
@@ -43,7 +43,7 @@ public class SpotsItem
                 VuforiaItem.transform.localPosition = Vector3.zero;
                 VuforiaItem.transform.localEulerAngles = Vector3.zero;
                 VuforiaItem.SetActive(false);
-                _spotsObj = new GameObject("景点--"+name);
+                _spotsObj = new GameObject("鏅�偣--"+name);
                 _spotsObj.transform.parent = VuforiaItem.transform;
 
 
@@ -58,7 +58,7 @@ public class SpotsItem
     public void setObVuforia(ObserverBehaviour obVuforia)
     {
         this.obVuforia = obVuforia;
-        Debug.Log("添加Vuforia监听" + obVuforia.TargetName+"    景点===》"+name);
+        Debug.Log("娣诲姞Vuforia鐩戝惉" + obVuforia.TargetName+"    鏅�偣===銆�"+name);
 
         this.obVuforia.OnTargetStatusChanged += OnTargetStatusChanged;
         obVuforia.gameObject.name = "ImageTarget_" + obVuforia.TargetName;
@@ -89,7 +89,7 @@ public class SpotsItem
     {
         if (status.Status == Status.TRACKED)
         {
-            Debug.Log("OnTargetStatusChanged 发现 " + behaviour.TargetName + "status ==>" + status.Status.ToString());
+            Debug.Log("OnTargetStatusChanged 鍙戠幇 " + behaviour.TargetName + "status ==>" + status.Status.ToString());
             if(obVuforia.TargetName == behaviour.TargetName)
             {
                 foreach (var item in usi.SpotsList.Keys)
@@ -111,13 +111,13 @@ public class SpotsItem
                     }
 
                 }
-                Debug.Log("OnTargetStatusChanged 发现 VuforiaItem " + VuforiaItem.name);
+                Debug.Log("OnTargetStatusChanged 鍙戠幇 VuforiaItem " + VuforiaItem.name);
 
                 TimerMgr.Instance.CreateTimer(()=> {
                     VuforiaItem.transform.position = obj.transform.position;
                     VuforiaItem.transform.eulerAngles = obj.transform.eulerAngles;
                     VuforiaItem.transform.eulerAngles = new Vector3(0, VuforiaItem.transform.eulerAngles.y, 0);
-                    Debug.Log("OnTargetStatusChanged 发现 " + obj.transform.position + "status ==>" + obj.transform.eulerAngles);
+                    Debug.Log("OnTargetStatusChanged 鍙戠幇 " + obj.transform.position + "status ==>" + obj.transform.eulerAngles);
                 }, 0.1f,10);
                 if (!isInitModel)
                 {
@@ -251,7 +251,7 @@ public class SpotsItem
         }
         else
         {
-            Debug.Log("OnTargetStatusChanged 消失 " + behaviour.TargetName + "status ==>" + status.Status.ToString());
+            Debug.Log("OnTargetStatusChanged 娑堝け " + behaviour.TargetName + "status ==>" + status.Status.ToString());
 
           //  if (obVuforia.TargetName == behaviour.TargetName)
             //    SpotsObj.SetActive(false);

+ 2 - 2
Assets/HotUpdate/StartImmersalLocalizerEvent.cs

@@ -1,7 +1,7 @@
-using Blue;
+锘縰sing Blue;
 
 /// <summary>
-/// 开始Immersal定位事件
+/// 寮€濮婭mmersal瀹氫綅浜嬩欢
 /// </summary>
 public class StartImmersalLocalizerEvent : IEvent
 {

+ 3 - 3
Assets/HotUpdate/UnityWebRequestUtility.cs

@@ -1,10 +1,10 @@
-using Blue;
+锘縰sing Blue;
 using UnityEngine.Networking;
 
 public class UnityWebRequestUtility : IUtility
 {
     /// <summary>
-    /// 获取下载进度
+    /// 鑾峰彇涓嬭浇杩涘害
     /// </summary>
     public float GetProcess(UnityWebRequest webRequestPoint)
     {
@@ -16,7 +16,7 @@ public class UnityWebRequestUtility : IUtility
     }
 
     /// <summary>
-    /// 获取当前下载内容长度
+    /// 鑾峰彇褰撳墠涓嬭浇鍐呭�闀垮害
     /// </summary>
     public long GetCurrentLength(UnityWebRequest webRequestPoint)
     {

+ 6 - 6
Assets/HotUpdate/UserInfo.cs

@@ -1,4 +1,4 @@
-using System.Collections;
+锘縰sing System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
@@ -6,15 +6,15 @@ public class UserInfo: Singleton<UserInfo>
 {
     public  bool is20 = false;
 
-    //用户令牌
+    //鐢ㄦ埛浠ょ墝
     public string Token;
-    //用户名字
+    //鐢ㄦ埛鍚嶅瓧
     public string name;
-    //用户名字
+    //鐢ㄦ埛鍚嶅瓧
     public string Account;
-    //用户名字
+    //鐢ㄦ埛鍚嶅瓧
     public string Password;
-    //用户拥有的场景
+    //鐢ㄦ埛鎷ユ湁鐨勫満鏅�
     public Dictionary<string, UserSceneItem> SceneList =new Dictionary<string, UserSceneItem>();
 
 

+ 2 - 2
Assets/HotUpdate/UserManager.cs

@@ -1,4 +1,4 @@
-using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Linq;
 using SC.XR.Unity;
 using UnityEngine;
 
@@ -10,7 +10,7 @@ public class UserManager : SingletonMono<UserManager>
         {
             UserSceneManager.Instance.callback += (bool b) => { 
             
-                //³õʼ»¯³¡¾°½áÊø
+                //�始化场景结�
                 if(b)
                 {
                     GameScene.Instance.ShowScenes();

+ 1 - 0
Packages/manifest.json

@@ -20,6 +20,7 @@
     "com.unity.xr.interactionsubsystems": "1.0.1",
     "com.unity.xr.openxr": "1.5.3",
     "jh.immersalsdk.engine": "ssh://git@gogs.ghz-tech.com:30979/GHzGlass/ImmersalSDK.git#ImmersalSDK_Nreal",
+    "jh.opencvforunity.engine": "ssh://git@gogs.ghz-tech.com:30979/GHzGlass/OpenCVForUnity.git",
     "jh.trilib.engine": "ssh://git@gogs.ghz-tech.com:30979/GHzGlass/TriLibXR.git",
     "jh.xr.engine": "ssh://git@gogs.ghz-tech.com:30979/GHzGlass/GHZSDKXR.git#XRSDK_Nreal",
     "com.unity.modules.ai": "1.0.0",

+ 12 - 1
Packages/packages-lock.json

@@ -290,12 +290,23 @@
       },
       "hash": "12e268d7733ff732984a15a792f2bd2dc666915a"
     },
+    "jh.opencvforunity.engine": {
+      "version": "ssh://git@gogs.ghz-tech.com:30979/GHzGlass/OpenCVForUnity.git",
+      "depth": 0,
+      "source": "git",
+      "dependencies": {
+        "com.unity.xr.management": "4.0.1",
+        "com.unity.xr.legacyinputhelpers": "2.1.2",
+        "com.unity.inputsystem": "1.4.2"
+      },
+      "hash": "66118273877173fd3de91b8232a52838d87d7485"
+    },
     "jh.trilib.engine": {
       "version": "ssh://git@gogs.ghz-tech.com:30979/GHzGlass/TriLibXR.git",
       "depth": 0,
       "source": "git",
       "dependencies": {},
-      "hash": "c5c738ff16760f354d638d62cda2206176c2ba75"
+      "hash": "0124fefeb16d355c5f4affd25cfad240e7ef0f2d"
     },
     "jh.xr.engine": {
       "version": "ssh://git@gogs.ghz-tech.com:30979/GHzGlass/GHZSDKXR.git#XRSDK_Nreal",