Ejemplo n.º 1
0
 /// <summary>
 /// Check target file exist
 /// </summary>
 public static Boolean ExistFile(String path) {
     if (path.IsNullOrEmpty()) {
         BenLogger.Error("ExistFile Path is empty!");
         return false;
     }
     return File.Exists(path);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get json data by read text(First Cache, Second Resources)
        /// </summary>
        public static Boolean TryReadTextByAll(String path, out JsonData totalJson) {
            totalJson = null;
            if (File.Exists(path)) {
                Boolean isRet = false;
                String jsonStr = ReadTextByStream(path);
                if (false == jsonStr.IsNullOrEmpty() && jsonStr != "\r" && jsonStr != "\n" && jsonStr != "\r\n") {
                    try {
                        totalJson = JsonMapper.ToObject(jsonStr);
                        isRet = true;
                    } catch (Exception ex) {
                        BenLogger.Error("Resources info convert to <LitJson.JsonData> error, delete file! Path: " + path + " || Exception: " + ex.Message);
                        isRet = false;
                    }
                } else {
                    BenLogger.Error("File exist, but info is null, delete file! Path: " + path);
                    isRet = false;
                }

                if (totalJson == null) {
                    DeleteFile(path);
                    isRet = TryReadTextByResource(DirectoryConst.TABLE + path.LastSlashToPoint(), out totalJson);
                }
                return isRet;
            } else {
                return TryReadTextByResource(DirectoryConst.TABLE + path.LastSlashToPoint(), out totalJson);
            }
        }
 /// <summary>
 /// Stop By Tag
 /// </summary>
 public void Stop(string tag) {
     _stopwatch.Stop();
     if (string.IsNullOrEmpty(tag)) {
         BenLogger.Debug("StopWatch Print ElapsedMillseconds: " + _stopwatch.ElapsedMilliseconds);
     } else {
         BenLogger.Debug("Tag: " + tag + " | StopWatch Print ElapsedMillseconds: " + _stopwatch.ElapsedMilliseconds);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Save string to file
        /// </summary>
        public static void SaveTextByDelete(Boolean isSave, String path, String info) {
            if (isSave) {
                FileUtil.DeleteFile(path);
                FileUtil.WriteTextByStream(path, info);

                BenLogger.Debug("Save " + path + " Success!");
            }
        }
Ejemplo n.º 5
0
 public static string GetDeviceInfo() {
     StringBuilder stringBuilder = new StringBuilder();
     BenLogger.Debug("设备模型deviceModel: " + SystemInfo.deviceModel);
     BenLogger.Debug("设备名称deviceName: " + SystemInfo.deviceName);
     BenLogger.Debug("设备类型(PC电脑,掌上型)deviceType: " + SystemInfo.deviceType);
     BenLogger.Debug("设备唯一标识符 deviceUniqueIdentifier: " + SystemInfo.deviceUniqueIdentifier);
     BenLogger.Debug("操作系统operatingSystem: " + SystemInfo.operatingSystem);
     BenLogger.Debug("系统内存大小MBsystemMemorySize: " + SystemInfo.systemMemorySize);
     return stringBuilder.ToString();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Check Directory
        /// </summary>
        public static void CheckDirectory(String path) {
            if (path.IsNullOrEmpty()) {
                BenLogger.Error("CheckDirectory Path is empty!");
                return;
            }

            if (!Directory.Exists(path)) {
                Directory.CreateDirectory(path);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Write string by IO.FileStream
 /// </summary>
 public static void WriteTextByIO(String path, String info) {
     try {
         FileStream fs = new FileStream(path, FileMode.Create);
         Byte[] data = ENCODING_FORMAT.GetBytes(info);
         fs.Write(data, 0, data.Length);
         fs.Flush();
         fs.Dispose();
         fs = null;
     } catch (Exception e) {
         BenLogger.Error("The file could not be write! Path: " + path + " || Message: " + e.Message);
     }
 }
Ejemplo n.º 8
0
        public static void GetSystemMemoryStatus() {
            MemoryInfo memoryInfo = new MemoryInfo();
            GlobalMemoryStatus(ref memoryInfo);

            long avaliableMb = Convert.ToInt64(memoryInfo.dwAvailPhys.ToString())/1024/1024;
            BenLogger.Debug("FreeMemory: " + Convert.ToString(avaliableMb) + " MB");
            if (avaliableMb<200) {
                BenLogger.Debug("内存不足");
            } else {
                BenLogger.Debug("可以使用");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Delete target file
        /// </summary>
        public static void DeleteFile(String path) {
            if (path.IsNullOrEmpty()) {
                BenLogger.Error("DeleteFile Path is empty!");
                return;
            }

            if (File.Exists(path)) {
                File.Delete(path);
            }

            CheckDirectory(path.StartToLastSlash());
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Get Sprite by Unity WWW
 /// </summary>
 public static IEnumerator GetSpriteByWWW(String srcPath, Sprite sprite) {
     WWW www = new WWW(srcPath);
     yield return www;
     if (www != null && www.error.IsNullOrEmpty()) {
         Texture2D texture = www.texture;
         sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), VECTOR2_CENTER);
     } else {
         BenLogger.Error("Load Error Path: " + srcPath);
     }
     www.Dispose();
     www = null;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Get string by IO.FileStream
 /// </summary>
 public static String ReadTextByIO(String path) {
     if (File.Exists(path)) {
         Byte[] byteArray = _GetBytesByStream(path);
         if (byteArray != null) {
             return ENCODING_FORMAT.GetString(byteArray);
         } else {
             BenLogger.Error("The file could not be read! Path: " + path);
         }
     } else {
         BenLogger.Error("No exist file! Path: " + path);
     }
     return "";
 }
Ejemplo n.º 12
0
 public static string GetGraphicsInfo() {
     StringBuilder stringBuilder = new StringBuilder();
     BenLogger.Debug("显卡IDgraphicsDeviceID: " + SystemInfo.graphicsDeviceID);
     BenLogger.Debug("显卡名称graphicsDeviceName: " + SystemInfo.graphicsDeviceName);
     BenLogger.Debug("显卡类型graphicsDeviceType: " + SystemInfo.graphicsDeviceType);
     BenLogger.Debug("显卡供应商graphicsDeviceVendor: " + SystemInfo.graphicsDeviceVendor);
     BenLogger.Debug("显卡供应唯一IDgraphicsDeviceVendorID: " + SystemInfo.graphicsDeviceVendorID);
     BenLogger.Debug("显卡版本号graphicsDeviceVersion: " + SystemInfo.graphicsDeviceVersion);
     BenLogger.Debug("显存大小MBgraphicsMemorySize: " + SystemInfo.graphicsMemorySize);
     BenLogger.Debug("显卡是否支持多线程渲染graphicsMultiThreaded: " + SystemInfo.graphicsMultiThreaded);
     BenLogger.Debug("支持的渲染目标数量graphicsShaderLevel: " + SystemInfo.graphicsShaderLevel);
     return stringBuilder.ToString();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Write string by StreamWriter
        /// </summary>
        public static void WriteTextByStream(String path, String info) {
            try {
                FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs, ENCODING_FORMAT);
                sw.Write(info);
                sw.Flush();
                sw.Dispose();
                sw = null;

                fs = null;
            } catch (Exception e) {
                BenLogger.Error("The file could not be write! Path: " + path + " || Message: " + e.Message);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Get string by read text(First Cache, Then Resources)
 /// </summary>
 public static Boolean TryReadTextByAll(String path, out String info) {
     info = null;
     if (File.Exists(path)) {
         info = ReadTextByStream(path);
         if (false == info.IsNullOrEmpty()) {
             return true;
         } else {
             BenLogger.Error("File exist, but info is null, delete file! Path: " + path);
             return false;
         }
     } else {
         return TryReadTextByResource(DirectoryConst.TABLE + path.LastSlashToPoint(), out info);
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Get string by read Resources text
        /// </summary>
        public static Boolean TryReadTextByResource(String relativePath, out String info) {
            info = null;
            TextAsset textAsset = Resources.Load(relativePath) as TextAsset;
            if (textAsset != null) {
                info = textAsset.text;
            }

            if (false == info.IsNullOrEmpty()) {
                return true;
            } else {
                BenLogger.Error("Resources info is null!Path: " + relativePath);
                return false;
            }
        }
Ejemplo n.º 16
0
        public static void GetSystemInfo() {
            try {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(GetDeviceInfo());
                stringBuilder.AppendLine(GetGraphicsInfo());
                stringBuilder.AppendLine(GetProcessorInfo());
                stringBuilder.AppendLine(GetRenderInfo());

                BenLogger.Debug(stringBuilder.ToString());
            } catch (Exception) {
                
                throw;
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Get string by read text
 /// </summary>
 public static Boolean TryReadText(String path, out String info) {
     if (File.Exists(path)) {
         info = ReadTextByStream(path);
         if (false == info.IsNullOrEmpty()) {
             return true;
         } else {
             DeleteFile(path);
             BenLogger.Error("File exist, but info is null, delete file! Path: " + path);
             return false;
         }
     } else {
         info = "";
         return false;
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Get byte array by IO.FileStream
 /// </summary>
 static Byte[] _GetBytesByStream(String path) {
     if (File.Exists(path)) {
         try {
             FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
             fileStream.Seek(0, SeekOrigin.Begin);
             Byte[] bytes = new Byte[fileStream.Length];
             fileStream.Read(bytes, 0, (Int32)fileStream.Length);
             fileStream.Dispose();
             fileStream = null;
             return bytes;
         } catch (Exception e) {
             BenLogger.Error("The file could not be read! Path: " + path + " || Message: " + e.Message);
         }
     } else {
         BenLogger.Error("No Exist File! Path: " + path);
     }
     return null;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Clear all file and directory of the target directory
 /// </summary>
 public static void ClearDirectoryFiles(String path) {
     try {
         DirectoryInfo dir = new DirectoryInfo(path);
         FileSystemInfo[] fileInfo = dir.GetFileSystemInfos();
         foreach (FileSystemInfo i in fileInfo) {
             if (i is DirectoryInfo) {
                 DirectoryInfo subDir = new DirectoryInfo(i.FullName);
                 subDir.Delete(true);
             } else {
                 File.Delete(i.FullName);
             }
         }
         BenLogger.Error("Delete Path: " + path + " All Info Success!");
     } catch (Exception e) {
         BenLogger.Error("FileClearDir: " + path + " Exception: " + e.Message);
         throw;
     }
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Get string by read line text
 /// </summary>
 static String ReadTextByStreamLine(String path) {
     String result = "";
     if (File.Exists(path)) {
         try {
             StreamReader sr = new StreamReader(path, ENCODING_FORMAT);
             String line;
             while ((line = sr.ReadLine()) != null) {
                 result += line;
             }
             sr.Dispose();
             sr = null;
         } catch (Exception e) {
             BenLogger.Error("The file could not be read! Path: " + path + " || Message: " + e.Message);
         }
     } else {
         BenLogger.Error("No exist file! Path: " + path);
     }
     return result;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Get json data by read text
 /// </summary>
 public static Boolean TryReadText(String path, out JsonData totalJson) {
     if (File.Exists(path)) {
         String jsonStr = ReadTextByStream(path);
         if (false == jsonStr.IsNullOrEmpty() && jsonStr != "\r" && jsonStr != "\n" && jsonStr != "\r\n") {
             try {
                 totalJson = JsonMapper.ToObject(jsonStr);
                 return true;
             } catch (Exception ex) {
                 DeleteFile(path);
                 BenLogger.Error("File convert to <LitJson.JsonData> error, delete file! Path: " + path + " || Exception: " + ex.Message);
             }
         } else {
             DeleteFile(path);
             BenLogger.Error("File exist, but info is null, delete file! Path: " + path);
         }
     }
     totalJson = null;
     return false;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Get string by StreamReader
 /// </summary>
 public static String ReadTextByStream(String path) {
     String result = "";
     if (File.Exists(path)) {
         try {
             //using (StreamReader sr = new StreamReader(path, ENCODING_FORMAT)) {
             //    result = sr.ReadToEnd();
             //}
             StreamReader sr = new StreamReader(path, ENCODING_FORMAT);
             result = sr.ReadToEnd();
             sr.Dispose();
             sr = null;
         } catch (Exception e) {
             BenLogger.Error("The file could not be read! Path: " + path + " || Message: " + e.Message);
         }
     } else {
         BenLogger.Error("No exist file! Path: " + path);
     }
     return result;
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Get json data by read Resources text
        /// </summary>
        public static Boolean TryReadTextByResource(String relativePath, out JsonData totalJson) {
            String jsonStr = null;
            TextAsset textAsset = Resources.Load(relativePath) as TextAsset;
            if (textAsset != null) {
                jsonStr = textAsset.text;

                if (false == jsonStr.IsNullOrEmpty()) {
                    try {
                        totalJson = JsonMapper.ToObject(jsonStr);
                        return true;
                    } catch (Exception ex) {
                        BenLogger.Error("Resources info convert to <LitJson.JsonData> error, delete file! Path: " + relativePath + " || Exception: " + ex.Message);
                    }
                } else {
                    BenLogger.Error("Resources info is null!Path: " + relativePath);
                }
            }
            totalJson = null;
            return false;
        }
Ejemplo n.º 24
0
        public static string GetRenderInfo() {
            StringBuilder stringBuilder = new StringBuilder();
            BenLogger.Debug("支持渲染多少目标纹理supportedRenderTargetCount: " + SystemInfo.supportedRenderTargetCount);
            BenLogger.Debug("是否支持3D(体积)纹理supports3DTextures: " + SystemInfo.supports3DTextures);
            BenLogger.Debug("是否支持获取加速度计supportsAccelerometer: " + SystemInfo.supportsAccelerometer);
            BenLogger.Debug("是否支持计算着色器supportsComputeShaders: " + SystemInfo.supportsComputeShaders);
            BenLogger.Debug("是否支持获取陀螺仪supportsGyroscope: " + SystemInfo.supportsGyroscope);
            BenLogger.Debug("是否支持图形特效supportsImageEffects: " + SystemInfo.supportsImageEffects);
            BenLogger.Debug("是否支持实例化GPU的Draw CallsupportsInstancing: " + SystemInfo.supportsInstancing);
            BenLogger.Debug("是否支持定位功能supportsLocationService: " + SystemInfo.supportsLocationService);
#if !UNITY_5_5
            BenLogger.Debug("是否支持渲染纹理supportsRenderTextures: " + SystemInfo.supportsRenderTextures);
#endif
            BenLogger.Debug("是否支持立方体纹理supportsRenderToCubemap: " + SystemInfo.supportsRenderToCubemap);
            BenLogger.Debug("是否支持内置阴影supportsShadows: " + SystemInfo.supportsShadows);
            BenLogger.Debug("是否支持稀疏纹理supportsSparseTextures: " + SystemInfo.supportsSparseTextures);
#if !UNITY_5_5
            BenLogger.Debug("是否支持模版缓存supportsStencil: " + SystemInfo.supportsStencil);
#endif
            BenLogger.Debug("是否支持用户触摸震动反馈supportsVibration: " + SystemInfo.supportsVibration);

            foreach (RenderTextureFormat type in System.Enum.GetValues(typeof(RenderTextureFormat))) {
                try {
                    BenLogger.Debug("是否支持渲染纹理格式RenderTextureFormat: " + type.ToString() + " | SupportsRenderTextureFormat: " + SystemInfo.SupportsRenderTextureFormat(type));
                } catch (Exception ex) {
                    BenLogger.Debug(ex.Message);
                }
            }

            foreach (TextureFormat type in System.Enum.GetValues(typeof(TextureFormat))) {
                try {
                    BenLogger.Debug("是否支持纹理格式TextureFormat: " + type + " | SupportsTextureFormat: " + SystemInfo.SupportsTextureFormat(type));
                } catch (Exception ex) {
                    BenLogger.Debug(ex.Message);
                }
            }
            return stringBuilder.ToString();
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Get node by read text
        /// </summary>
        public static Boolean TryReadText(String path, out XmlNode rootNode) {
            rootNode = null;
            StreamReader sr;
            XmlDocument xmlDoc = new XmlDocument();
            if (!File.Exists(path)) {
                return false;
            } else if (CheckTextIsNull(path)) {
                DeleteFile(path);
                BenLogger.Error("File exist, but info is null, delete file! Path: " + path);
                return false;
            } else {
                sr = new StreamReader(path, ENCODING_FORMAT);
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = true;
                XmlReader reader = XmlReader.Create(sr, settings);
                xmlDoc.Load(reader);
            }

            rootNode = xmlDoc.SelectSingleNode("Data");
            if (rootNode == null) {
                sr.Close();
                xmlDoc = null;
                DeleteFile(path);
                BenLogger.Error("XML root node <Data> is not exist, delete file! Path: " + path);
                return false;
            }

            if (rootNode.ChildNodes.Count == 0) {
                sr.Close();
                rootNode = null;
                xmlDoc = null;
                DeleteFile(path);
                BenLogger.Error("XML root node <Data> info is null, delete file! Path: " + path);
                return false;
            }
            sr.Close();
            return true;
        }
        /// <summary>
        /// Get Selection GameObject MeshRenderer Bones
        /// </summary>
        public static Transform[] GetMeshRendererBones(this Transform trans, Transform skinRootTrans) {
            List<Transform> resultBones = new List<Transform>();
            if (trans != null) {
                List<Transform> smrBones = new List<Transform>(), aloneBones = new List<Transform>(), bodyBones = new List<Transform>();
                // All SkinnedMeshRenderer
                foreach (SkinnedMeshRenderer smr in trans.GetComponentsInChildren<SkinnedMeshRenderer>(true)) {
                    smrBones.AddRange(smr.bones);
                }
                smrBones.RemoveNull();
                smrBones = smrBones.Distinct().ToList();
                // Child index
                List<int> childIndexList = new List<int>();
                for (int i = 0; i < smrBones.Count; ++i) {
                    for (int j = 0; j < smrBones.Count; ++j) {
                        if (i != j) {
                            if (smrBones[i] == smrBones[j].parent) {
                                childIndexList.Add(j);
                            }
                        }
                    }
                }
                // Remove the child of the parent in the bonelist
                for (int i = childIndexList.Count - 1; i >= 0; --i) {
                    smrBones.RemoveAt(i);
                }
                // Find the node of bip
                foreach (Transform bone in smrBones) {
                    bool bodyBip = false, aloneBone = false;
                    Transform temp = bone;

                    while (true) {
                        if (temp.name.Equals("Bip001")) {
                            bodyBip = true;
                            break;
                        }
                        // Alone bone root transform
                        if (temp.parent == skinRootTrans) {
                            aloneBone = true;
                            break;
                        }
                        if (temp.parent == null) {
                            BenLogger.Error("Parent is null!");
                            break;
                        }

                        temp = temp.parent;
                    }
                    if (bodyBip) {
                        bodyBones.Add(bone);
                    } else {
                        if (aloneBone) {
                            aloneBones.Add(temp);
                        } else {
                            BenLogger.Debug("Bone < " + bone.name + " > Top Parent is null!");
                        }
                    }
                }
                bodyBones = bodyBones.Distinct().ToList();
                aloneBones = aloneBones.Distinct().ToList();
                resultBones.AddRange(bodyBones);
                resultBones.AddRange(aloneBones);
            }
            return resultBones.ToArray();
        }
Ejemplo n.º 27
0
 public static string GetProcessorInfo() {
     StringBuilder stringBuilder = new StringBuilder();
     BenLogger.Debug("处理器的数量processorCount: " + SystemInfo.processorCount);
     BenLogger.Debug("处理器的名称processorType: " + SystemInfo.processorType);
     return stringBuilder.ToString();
 }