Просмотр исходного кода

Merge pull request #20 from bsyx/dev01

修改日志路径,兼容手机平台
tanghai 8 лет назад
Родитель
Сommit
0c02304cbe
2 измененных файлов с 60 добавлено и 10 удалено
  1. 9 10
      Unity/Assets/Scripts/Base/Log.cs
  2. 51 0
      Unity/Assets/Scripts/Helper/PathHelp.cs

+ 9 - 10
Unity/Assets/Scripts/Base/Log.cs

@@ -10,20 +10,19 @@ namespace Model
 
 		private static readonly StreamWriter error;
 		
-#if UNITY_EDITOR
-		private static bool IsNeedFlush = true;
-#else
-		private static bool IsNeedFlush = true;
-#endif
-
+	    public static bool IsNeedFlush = true;
+        private static string dirName = "Logs";
+        private static string infoFileName = "/Log-Client-Info.txt";
+        private static string errorFileName = "/Log-Client-Error.txt";
 		static Log()
 		{
-			if (!Directory.Exists("./Logs"))
+            string dirPath =PathHelp.AppHotfixResPath + dirName;
+			if (!Directory.Exists(dirPath))
 			{
-				Directory.CreateDirectory("./Logs");
+				Directory.CreateDirectory(dirPath);
 			}
-			info = new StreamWriter("./Logs/Log-Client-Info.txt", false, Encoding.Unicode, 1024);
-			error = new StreamWriter("./Logs/Log-Client-Error.txt", false, Encoding.Unicode, 1024);
+			info = new StreamWriter(dirPath+ infoFileName, false, Encoding.Unicode, 1024);
+			error = new StreamWriter(dirPath+ errorFileName, false, Encoding.Unicode, 1024);
 		}
 
 		public static void Warning(string msg)

+ 51 - 0
Unity/Assets/Scripts/Helper/PathHelp.cs

@@ -0,0 +1,51 @@
+
+using System;
+using System.Text;
+using UnityEngine;
+
+namespace Model
+{
+    public static class PathHelp
+    {     /// <summary>
+          ///应用程序外部资源路径存放路径(热更新资源路径)
+          /// </summary>
+        public static string AppHotfixResPath
+        {
+            get
+            {
+                string game = Application.productName;
+                string path = AppResPath;
+                if (Application.isMobilePlatform)
+                {
+                    path = $"{Application.persistentDataPath} { "/"} {game} {"/"}";
+                }
+                return path;
+            }
+
+        }
+
+        /// <summary>
+        /// 应用程序内部资源路径存放路径
+        /// </summary>
+        public static string AppResPath
+        {
+            get
+            {
+                string path = string.Empty;
+                switch (Application.platform)
+                {
+                    case RuntimePlatform.Android:
+                        path = $"{"jar:file://"}{Application.dataPath}{"!!/assets/"}";
+                        break;
+                    case RuntimePlatform.IPhonePlayer:
+                        path = $"{Application.dataPath}{"/Raw/"}";
+                        break;
+                    default:
+                        path = $"{Application.dataPath}{"/StreamingAssets/"}";
+                        break;
+                }
+                return path;
+            }
+        }
+    }
+}