├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── TimeManager.asset ├── DynamicsManager.asset ├── EditorSettings.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── GraphicsSettings.asset ├── Physics2DSettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── .gitignore ├── Assets ├── Core.meta └── Core │ ├── Res.meta │ ├── Debug.meta │ ├── Utils.meta │ ├── Res │ ├── NextRes.meta │ ├── NextRes │ │ ├── Asset.meta │ │ ├── Bundle.meta │ │ ├── Maps.meta │ │ ├── Util.meta │ │ ├── WWW.meta │ │ ├── AssetLoad.meta │ │ ├── ResourcesLoad.meta │ │ ├── Asset │ │ │ ├── Asset.cs.meta │ │ │ ├── AssetPool.cs.meta │ │ │ ├── AssetPool.cs │ │ │ └── Asset.cs │ │ ├── Bundle │ │ │ ├── Bundle.cs.meta │ │ │ ├── BundlePool.cs.meta │ │ │ ├── LoadingProgressMgr.cs.meta │ │ │ ├── Bundle.cs │ │ │ ├── BundlePool.cs │ │ │ └── LoadingProgressMgr.cs │ │ ├── Maps │ │ │ ├── AssetMap.cs.meta │ │ │ ├── BundleMap.cs.meta │ │ │ ├── AssetMap.cs │ │ │ └── BundleMap.cs │ │ ├── WWW │ │ │ ├── WWWLoader.cs.meta │ │ │ ├── WWWUtil.cs.meta │ │ │ ├── WWWFilePool.cs.meta │ │ │ ├── WWWLoaderMgr.cs.meta │ │ │ ├── WWWUtil.cs │ │ │ ├── WWWLoader.cs │ │ │ ├── WWWLoaderMgr.cs │ │ │ └── WWWFilePool.cs │ │ ├── Util │ │ │ ├── MemoryPool.cs.meta │ │ │ └── MemoryPool.cs │ │ ├── AssetLoad │ │ │ ├── AssetLoader.cs.meta │ │ │ ├── AssetLoaderMgr.cs.meta │ │ │ ├── AssetLoaderMgr.cs │ │ │ └── AssetLoader.cs │ │ └── ResourcesLoad │ │ │ ├── ResourcesLoader.cs.meta │ │ │ ├── ResourcesLoaderMgr.cs.meta │ │ │ ├── ResourcesLoaderMgr.cs │ │ │ └── ResourcesLoader.cs │ ├── ResMgr.cs.meta │ ├── EditorResMgr.cs.meta │ ├── EditorResMgr.cs │ └── ResMgr.cs │ ├── Utils │ ├── json.meta │ ├── Toml.net.meta │ ├── Toml.net │ │ ├── Toml.meta │ │ └── Toml │ │ │ ├── Array.cs.meta │ │ │ ├── Entry.cs.meta │ │ │ ├── Group.cs.meta │ │ │ ├── Document.cs.meta │ │ │ ├── Parser.cs.meta │ │ │ ├── Program.cs.meta │ │ │ ├── Serializer.cs.meta │ │ │ ├── TestConfig.cs.meta │ │ │ ├── ParserException.cs.meta │ │ │ ├── TypeParsers.cs.meta │ │ │ ├── TestConfig.cs │ │ │ ├── ParserException.cs │ │ │ ├── Entry.cs │ │ │ ├── Document.cs │ │ │ ├── Program.cs │ │ │ ├── Serializer.cs │ │ │ ├── TypeParsers.cs │ │ │ ├── Array.cs │ │ │ └── Group.cs │ ├── json │ │ ├── fastJSON.meta │ │ ├── fastJSON │ │ │ ├── Getters.cs │ │ │ ├── JSON.cs.meta │ │ │ ├── Formatter.cs.meta │ │ │ ├── Getters.cs.meta │ │ │ ├── JsonParser.cs.meta │ │ │ ├── Reflection.cs.meta │ │ │ ├── dynamic.cs.meta │ │ │ ├── JsonSerializer.cs.meta │ │ │ ├── SafeDictionary.cs.meta │ │ │ ├── SafeDictionary.cs │ │ │ ├── Formatter.cs │ │ │ ├── dynamic.cs │ │ │ └── JsonParser.cs │ │ ├── JsonUtil.cs.meta │ │ ├── JsonSerializer.cs.meta │ │ ├── JsonFieldAttribute.cs.meta │ │ ├── JsonFieldAttribute.cs │ │ ├── JsonSerializer.cs │ │ └── JsonUtil.cs │ ├── CoreEnum.cs.meta │ ├── FileUtil.cs.meta │ ├── MathUtil.cs.meta │ ├── OrcaUtil.cs.meta │ ├── SysUtil.cs.meta │ ├── GUIDGenerater.cs.meta │ ├── SafeAction.cs.meta │ ├── EventsExtension.cs.meta │ ├── GUIDGenerater.cs │ ├── CoreEnum.cs │ ├── MathUtil.cs │ ├── EventsExtension.cs │ ├── FileUtil.cs │ ├── OrcaUtil.cs │ ├── SysUtil.cs │ └── SafeAction.cs │ └── Debug │ ├── D.cs.meta │ └── D.cs └── README.md /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.5.0f3 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Library/ 2 | *.csproj 3 | *.sln 4 | *.suo 5 | *.userprefs 6 | Temp/ 7 | obj/ 8 | .vs/ 9 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ixulin/OrcaRes-Unity3d/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/Core.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f1eb9ae16448fb45ab6a6adfc6283dd 3 | folderAsset: yes 4 | timeCreated: 1490355286 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6ba469485008a194bb6b3c78c0197978 3 | folderAsset: yes 4 | timeCreated: 1490355286 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Debug.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db94397016b499f4aafa7e70e9918697 3 | folderAsset: yes 4 | timeCreated: 1490355326 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Utils.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a64ee205a4e4355468fcf69aa6764860 3 | folderAsset: yes 4 | timeCreated: 1490355356 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7f08b970365c3a142913c131b8f84b29 3 | folderAsset: yes 4 | timeCreated: 1482838326 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e1a3ff6101a88645a39a2e61843449c 3 | folderAsset: yes 4 | timeCreated: 1460369956 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecba67c4dffec5f46aa48fb142ceaf1b 3 | folderAsset: yes 4 | timeCreated: 1460514684 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Bundle.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3caabccd1bd791245a76dad633ac70fc 3 | folderAsset: yes 4 | timeCreated: 1460514684 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Maps.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 905f879b3e0b3c34f8ee4287b77b70fc 3 | folderAsset: yes 4 | timeCreated: 1460513926 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Util.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c3ad55d887d10b40bb5f0668c29b5eb 3 | folderAsset: yes 4 | timeCreated: 1482838875 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 318614b55a3ffee48badd2f91d086321 3 | folderAsset: yes 4 | timeCreated: 1460514684 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 740f8b0ac5bfe44b4bc02c8bdfc33f76 3 | folderAsset: yes 4 | timeCreated: 1485439392 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e9e1ee2786a4934487cc62f510eef9e 3 | folderAsset: yes 4 | timeCreated: 1485223269 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e484b1dfabae5fd4fa44c3324b8bc8b7 3 | folderAsset: yes 4 | timeCreated: 1460369956 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/AssetLoad.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80bfc50d2de8872479217105b75516fd 3 | folderAsset: yes 4 | timeCreated: 1460718364 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/ResourcesLoad.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 970aa3412068f8c48b23b7df03988fab 3 | folderAsset: yes 4 | timeCreated: 1482895809 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OrcaRes-Unity3d 2 | 基于Unity3d的资源管理架构 3 | 4 | **目标是清晰易用,易扩展,易读** 5 | 6 | 框架图如下: 7 | ![img](https://ixulin.github.io/img/in-post/talk-res-mgr/resmgr-unity3d.jpg) 8 | 9 | 更多信息请戳这里。 10 | [Unity3D资源管理架构](https://ixulin.github.io/2017/04/01/talk-res-mgr/) 11 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/Getters.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace fastJSON 4 | { 5 | public sealed class DatasetSchema 6 | { 7 | public List Info ;//{ get; set; } 8 | public string Name ;//{ get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Assets/Core/Debug/D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f227afa067f7522438943ed917d36657 3 | timeCreated: 1482839295 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/ResMgr.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3aa5c00d957f4404a90aab360ed5ec6d 3 | timeCreated: 1454400481 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/CoreEnum.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24ff4cd50dd45ee4cb4340266284ef90 3 | timeCreated: 1474441664 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/FileUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55aabced8adab674792c119e64ad03b7 3 | timeCreated: 1460369957 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/MathUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4f798aa3b0ba63439545cad6b6dbed0 3 | timeCreated: 1474448040 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/OrcaUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f11c289df5cf41cb9fb703642441f3d 3 | timeCreated: 1484381793 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/SysUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9319f00c07c3e824cafa167b29b10583 3 | timeCreated: 1460369958 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/EditorResMgr.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 098927d0a6627f042ab75074f2cc6016 3 | timeCreated: 1476167112 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/GUIDGenerater.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5aeea2acf1426c042b9380b036016da0 3 | timeCreated: 1454387374 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/SafeAction.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 658585a9acf6ea846a604d78182741ff 3 | timeCreated: 1454392324 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/JsonUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa75e91f16169bd4bb88023a4b549727 3 | timeCreated: 1460369959 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Asset/Asset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6209fc44ed953374e9912e9cab8ae7e7 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Bundle/Bundle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 194dab6fcdd8cfa4796313d05dd24263 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Maps/AssetMap.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52a7526f440a13c4ab17e460e84a8114 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ae758e96e5bf6c478750eb77665e5c4 3 | timeCreated: 1460527280 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df89c2c65de71474db92586c89680d87 3 | timeCreated: 1460537226 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/EventsExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad5450acce103fd47ac1a021cad46ff4 3 | timeCreated: 1454392324 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Array.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 254aa6741a537a84da7578e63897b7c6 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Entry.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bfb5a3c6c36588443b32f1aeb571dc65 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Group.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26a263d4f264e6b43ba905fea8e4aa28 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/JsonSerializer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e13aac0868b0d34f822f02ad2595f6f 3 | timeCreated: 1460369957 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/JSON.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfaa4735e44615c4da9ce68d7465dd33 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Asset/AssetPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d754e29ec7acf449ab7049c3e8923d8 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Bundle/BundlePool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7696a2ea339aa4f4da38e9e691506fb8 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Maps/BundleMap.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8712b4edc77cc214d82c63c0f7b94dfe 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Util/MemoryPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59460b00c1d4fc44ab13f78c6d857bbf 3 | timeCreated: 1482838882 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWFilePool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d8e079ab632b144082782c8f39dec17 3 | timeCreated: 1460527280 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWLoaderMgr.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64af585dfe3bd59468f48d0eb679e2df 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Document.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 478db36d638bf7142806beeea34849d9 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Parser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9b926534cf2802c4d9f0fb40ca9a153f 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Program.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94fa14bafd5ca8d4f8a3c68060b201a0 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Serializer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c895678308e47304a889d9cc0eb6ee2d 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/TestConfig.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 528a210125f78044d8e1b6c6285659fb 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/JsonFieldAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1649ca54b95f3541b7c96ed7425afdf 3 | timeCreated: 1482839898 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/Formatter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f2800cbeaff53124498d2258abc7bd70 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/Getters.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 511b178f23ca5bd4cb0565cdd5f02dd4 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/JsonParser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 78927f25ea1270047a554df0e4e76b06 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/Reflection.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3880fe1ec0d964946a161d09754b4cb5 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/dynamic.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a11d38e08a43e304886f590c6b82267a 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/AssetLoad/AssetLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a856c4bd0fa68841a39513d587f1e67 3 | timeCreated: 1460600409 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/ParserException.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dbcd918eb55d8da42bb6300fdcab8423 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/TypeParsers.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 27ad1b4bd78fd6941bde50e04043db10 3 | timeCreated: 1485228724 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/JsonSerializer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5237a2728cac2d54a8e81b3d5ed17b7f 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/SafeDictionary.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 79f0f7ac57f91b345a8d40173f401d3f 3 | timeCreated: 1486360629 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/AssetLoad/AssetLoaderMgr.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e3458f3e87e4ff4eb74102043635d49 3 | timeCreated: 1460513931 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Bundle/LoadingProgressMgr.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f583d728470acca47bccc6b68ea46f06 3 | timeCreated: 1461118274 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/ResourcesLoad/ResourcesLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 066849801c006f346b2a16eba353045a 3 | timeCreated: 1482895809 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/ResourcesLoad/ResourcesLoaderMgr.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64b5b502341b04d448f837692d96fea0 3 | timeCreated: 1482895809 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Core/Utils/GUIDGenerater.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Orca 7 | { 8 | public class GUIDGenerater 9 | { 10 | private static long msActorGUID = 0; 11 | public static long GenerateUnitGUID() 12 | { 13 | return ++msActorGUID; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Assets/Core/Debug/D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public enum EMsgType 10 | { 11 | None = 0, 12 | Res, 13 | } 14 | public class D 15 | { 16 | private static long _frameNum; 17 | public static long FrameNum 18 | { 19 | set { _frameNum = value; } 20 | get { return _frameNum; } 21 | } 22 | public static void error(string str, EMsgType type = EMsgType.None) 23 | { 24 | Debug.LogError(_frameNum + " : " + str); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Assets/Core/Utils/CoreEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Orca 7 | { 8 | public enum EAniState 9 | { 10 | Idle = 0, 11 | Move = 1, 12 | Jump = 2, 13 | Attack = 3, 14 | Damage = 4, 15 | Death = 5, 16 | Enrage = 6, 17 | Laugh = 7, 18 | } 19 | 20 | public enum EAttackType 21 | { 22 | Attack0 = 0, 23 | Attack1 = 1, 24 | Attack2 = 2, 25 | Attack3 = 3, 26 | } 27 | 28 | public enum ELayerDef 29 | { 30 | Bullet = 8, 31 | WalkSurface = 9, 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Bundle/Bundle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class Bundle 10 | { 11 | private string mName; 12 | private AssetBundle mAssetBundle = null; 13 | 14 | public AssetBundle AssetBundle 15 | { 16 | get { return mAssetBundle; } 17 | } 18 | 19 | public static Bundle CreateInstance( string name ) 20 | { 21 | Bundle bundle = new Bundle(); 22 | bundle.mName = name; 23 | return bundle; 24 | } 25 | 26 | public void OnLoadWWW( string name, WWW www) 27 | { 28 | mAssetBundle = www.assetBundle; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Util/MemoryPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace OrcaCore 5 | { 6 | public class MemoryPool where T : class 7 | { 8 | public MemoryPool(int maxSize = 10) 9 | { 10 | _maxSize = maxSize; 11 | } 12 | public T Alloc() 13 | { 14 | T t = null; 15 | if (_objs.Count > 0) 16 | t = _objs.Dequeue(); 17 | return t; 18 | } 19 | public bool Free(T t) 20 | { 21 | if (_objs.Count < _maxSize) 22 | { 23 | _objs.Enqueue(t); 24 | return true; 25 | } 26 | return false; 27 | } 28 | public void Dispose() 29 | { 30 | _objs.Clear(); 31 | } 32 | public int Count { get { return _objs.Count; } } 33 | private Queue _objs = new Queue(); 34 | private int _maxSize = 10; 35 | } 36 | } -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/TestConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | //using System.Threading.Tasks; 6 | 7 | namespace TestCLI 8 | { 9 | [Serializable] 10 | class TestConfig 11 | { 12 | private TestConfig() 13 | { 14 | } 15 | 16 | public TestConfig(string ip, int port, bool enabled) 17 | { 18 | this.IP = ip; 19 | this.Port = port; 20 | this.IsEnabled = enabled; 21 | } 22 | 23 | public string IP { get; private set; } 24 | public int Port { get; private set; } 25 | public bool IsEnabled { get; private set; } 26 | public int[] BackupPorts { get; private set; } 27 | 28 | public string[][] IPNames { get; set; } 29 | 30 | public TestConfig[] ComplexArrayNoSerialize { get; set; } 31 | 32 | public TestConfig Alternative { get; private set; } 33 | public void SetAlternative(TestConfig alt) 34 | { 35 | this.Alternative = alt; 36 | } 37 | 38 | public void SetBackupPorts(int[] ports) 39 | { 40 | this.BackupPorts = ports; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/SafeDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace fastJSON 4 | { 5 | public sealed class SafeDictionary 6 | { 7 | private readonly object _Padlock = new object(); 8 | private readonly Dictionary _Dictionary; 9 | 10 | public SafeDictionary(int capacity) 11 | { 12 | _Dictionary = new Dictionary(capacity); 13 | } 14 | 15 | public SafeDictionary() 16 | { 17 | _Dictionary = new Dictionary(); 18 | } 19 | 20 | public bool TryGetValue(TKey key, out TValue value) 21 | { 22 | lock (_Padlock) 23 | return _Dictionary.TryGetValue(key, out value); 24 | } 25 | 26 | public int Count { get { lock (_Padlock) return _Dictionary.Count; } } 27 | 28 | public TValue this[TKey key] 29 | { 30 | get 31 | { 32 | lock (_Padlock) 33 | return _Dictionary[key]; 34 | } 35 | set 36 | { 37 | lock (_Padlock) 38 | _Dictionary[key] = value; 39 | } 40 | } 41 | 42 | public void Add(TKey key, TValue value) 43 | { 44 | lock (_Padlock) 45 | { 46 | if (_Dictionary.ContainsKey(key) == false) 47 | _Dictionary.Add(key, value); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Maps/AssetMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using OrcaCore; 6 | 7 | namespace OrcaCore 8 | { 9 | public class AssetMap 10 | { 11 | private static AssetMap _instance; 12 | public static AssetMap Instance 13 | { 14 | get 15 | { 16 | if( _instance == null) 17 | { 18 | _instance = new AssetMap(); 19 | } 20 | return _instance; 21 | } 22 | } 23 | 24 | private Dictionary mDicAssetMap = new Dictionary(); 25 | 26 | 27 | public void RegAssetIndex(string assetname, string bundlename) 28 | { 29 | if (mDicAssetMap.ContainsKey(assetname.GetHashCode())) 30 | { 31 | D.error("ResIdxMap:" + assetname + " is exist in " + GetBundleName(assetname)); 32 | return; 33 | } 34 | mDicAssetMap.Add(assetname.GetHashCode(), bundlename); 35 | } 36 | 37 | public void UnRegisterByAssetName(string assetname) 38 | { 39 | mDicAssetMap.Remove(assetname.GetHashCode()); 40 | } 41 | 42 | internal string GetBundleName(string assetname) 43 | { 44 | string bundlename; 45 | if (mDicAssetMap.TryGetValue(assetname.GetHashCode(), out bundlename)) 46 | { 47 | return bundlename; 48 | } 49 | else 50 | { 51 | return string.Empty; 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/JsonFieldAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace OrcaCore 7 | { 8 | public enum JsonFieldTypes 9 | { 10 | Null, 11 | UnEditable, 12 | BindPoint, 13 | Animation, 14 | ActEvent, 15 | HasChildren, 16 | PackType, 17 | PreProcess, 18 | PostProcess, 19 | ValidFuncs, 20 | } 21 | 22 | [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] 23 | public class JsonFieldAttribute:Attribute 24 | { 25 | private JsonFieldTypes _fieldType; 26 | public JsonFieldAttribute(JsonFieldTypes type) 27 | { 28 | this._fieldType = type; 29 | } 30 | 31 | public JsonFieldTypes FieldTypeName 32 | { 33 | get{return _fieldType;} 34 | } 35 | 36 | public static JsonFieldTypes GetFieldFlag(object obj, string proName) 37 | { 38 | Type t = obj.GetType(); 39 | foreach (System.Reflection.PropertyInfo p in t.GetProperties()) 40 | { 41 | if (p.Name == proName) 42 | { 43 | return GetFieldFlag(p); 44 | } 45 | } 46 | 47 | return JsonFieldTypes.Null; 48 | } 49 | 50 | public static JsonFieldTypes GetFieldFlag(System.Reflection.PropertyInfo pro) 51 | { 52 | object[] atts = pro.GetCustomAttributes(typeof(JsonFieldAttribute), false); 53 | if (atts.Length > 0) 54 | { 55 | JsonFieldAttribute attr = atts[0] as JsonFieldAttribute; 56 | return attr.FieldTypeName; 57 | } 58 | return JsonFieldTypes.Null; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/ParserException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | //using System.Threading.Tasks; 6 | 7 | namespace Toml 8 | { 9 | /// 10 | /// Represents a Parser Exception. 11 | /// 12 | public class ParserException : ApplicationException 13 | { 14 | /// 15 | /// Initializes a new instance of the ParserException class. 16 | /// 17 | /// The line number the parser error occurred on. 18 | /// The parser error message. 19 | public ParserException(int lineNumber, string message) 20 | : base(message) 21 | { 22 | this.LineNumber = lineNumber; 23 | } 24 | 25 | /// 26 | /// Initializes a new instance of the ParserException class. 27 | /// 28 | /// The line number the parser error occurred on. 29 | /// The position in the line the error was detected at. 30 | /// The text of the line the error occurred on. 31 | /// The parser error message. 32 | public ParserException(int lineNumber, int position, string currentLine, string message) 33 | : base(message) 34 | { 35 | this.LineNumber = lineNumber; 36 | this.Position = position; 37 | this.Context = currentLine; 38 | } 39 | 40 | /// 41 | /// Gets the line number the error occurred on. 42 | /// 43 | public int LineNumber { get; private set; } 44 | 45 | /// 46 | /// Gets the position of the error on the line. 47 | /// 48 | public int Position { get; private set; } 49 | 50 | /// 51 | /// Gets the context of the error. 52 | /// 53 | public string Context { get; private set; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Assets/Core/Res/EditorResMgr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | using System.IO; 7 | 8 | #if UNITY_EDITOR 9 | namespace OrcaCore 10 | { 11 | public class EditorResMgr 12 | { 13 | private static EditorResMgr mInst; 14 | public static EditorResMgr Inst 15 | { 16 | get 17 | { 18 | if( mInst == null ) 19 | { 20 | mInst = new EditorResMgr(); 21 | } 22 | return mInst; 23 | } 24 | } 25 | 26 | private Dictionary mDicFilePath = new Dictionary(); 27 | 28 | public void GetAsset(string name, Action func, ELoadPriority priority = ELoadPriority.Default) 29 | { 30 | UnityEngine.Object obj = null; 31 | string fullName = ""; 32 | if (!mDicFilePath.TryGetValue(name, out fullName)) 33 | { 34 | foreach (string file in UnityEditor.AssetDatabase.GetAllAssetPaths()) 35 | { 36 | string fileName = Path.GetFileName(file); 37 | if (fileName == name) 38 | { 39 | fullName = file; 40 | mDicFilePath.Add(name, fullName); 41 | break; 42 | } 43 | } 44 | } 45 | 46 | if ( string.IsNullOrEmpty(fullName)) 47 | { 48 | Debug.LogError("Can't find any asset named " + name); 49 | } 50 | else 51 | { 52 | obj = AssetDatabaseLoad(fullName); 53 | if (func != null) 54 | { 55 | func(name, obj); 56 | } 57 | } 58 | } 59 | 60 | public UnityEngine.Object AssetDatabaseLoad(string fullName) 61 | { 62 | UnityEngine.Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath(fullName, typeof(UnityEngine.Object)); 63 | return obj; 64 | } 65 | } 66 | } 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | /// 10 | /// 加载的url类型 11 | /// 12 | public enum EUrlType 13 | { 14 | Default, 15 | Streaming, 16 | Web, 17 | } 18 | public class WWWUtil 19 | { 20 | /// 21 | /// 从网络加载的url地址 22 | /// 23 | public static string GAME_RES_URL { set; get; } 24 | /// 25 | /// 是否禁用Cache 26 | /// 27 | public static bool DisableCache { set; get; } 28 | 29 | /// 30 | /// 异步加载的优先级 31 | /// 32 | public static bool LowAsyncLoadPriority { set; get; } 33 | /// 34 | /// 创建www 35 | /// 36 | /// 37 | /// 新加载资源 38 | /// 39 | /// 40 | public static WWW CreateWWW( string name, bool isRaw, bool isWeb ) 41 | { 42 | WWW www; 43 | string path = string.Empty; 44 | if( isWeb ) 45 | { 46 | path = GAME_RES_URL + "/" + name; 47 | } 48 | else if( Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) 49 | { 50 | path = Application.streamingAssetsPath + "/" + name; 51 | } 52 | else 53 | { 54 | path = "file:///" + Application.dataPath + "/../../bin/res/" + name; 55 | } 56 | 57 | if( isRaw || DisableCache) 58 | { 59 | www = new WWW(path); 60 | } 61 | else 62 | { 63 | www = WWW.LoadFromCacheOrDownload(path, 1); 64 | } 65 | if( LowAsyncLoadPriority ) 66 | { 67 | www.threadPriority = ThreadPriority.Low; 68 | } 69 | else 70 | { 71 | www.threadPriority = ThreadPriority.High; 72 | } 73 | return www; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/JsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class Vector3Json 10 | { 11 | public static string SerilizeVector3(object obj) 12 | { 13 | Vector3 vec = (Vector3)obj; 14 | return vec.x + "|" + vec.y + "|" + vec.z; 15 | } 16 | 17 | public static object DserializeVector3(string str) 18 | { 19 | string[] vs = JsonUtil.StringToStringArray(str); 20 | Vector3 vc = Vector3.zero; 21 | if(vs.Length == 3) 22 | { 23 | vc.x = float.Parse(vs[0]); 24 | vc.y = float.Parse(vs[1]); 25 | vc.z = float.Parse(vs[2]); 26 | } 27 | return vc; 28 | } 29 | } 30 | 31 | public class QuaternionJson 32 | { 33 | public static string SerilizeQuaternion(object obj) 34 | { 35 | Quaternion vec = (Quaternion)obj; 36 | return vec.w + "|" + vec.x + "|" + vec.y + "|" + vec.z; 37 | } 38 | 39 | public static object DserializeQuaternion(string str) 40 | { 41 | string[] vs = JsonUtil.StringToStringArray(str); 42 | Quaternion vc = Quaternion.identity; 43 | if (vs.Length == 4) 44 | { 45 | vc.w = float.Parse(vs[0]); 46 | vc.x = float.Parse(vs[1]); 47 | vc.y = float.Parse(vs[2]); 48 | vc.z = float.Parse(vs[3]); 49 | } 50 | return vc; 51 | } 52 | } 53 | 54 | public class JsonCustom 55 | { 56 | public static string SerilizeRect(object obj) 57 | { 58 | Rect vec = (Rect)obj; 59 | return vec.x + "|" + vec.y + "|" + vec.width + "|" + vec.height; 60 | } 61 | 62 | public static object DserializeRect(string str) 63 | { 64 | string[] vs = JsonUtil.StringToStringArray(str); 65 | Rect vc = Rect.zero; 66 | if (vs.Length == 4) 67 | { 68 | vc.x = float.Parse(vs[0]); 69 | vc.y = float.Parse(vs[1]); 70 | vc.width = float.Parse(vs[2]); 71 | vc.height = float.Parse(vs[3]); 72 | } 73 | return vc; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Assets/Core/Utils/MathUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace Orca 8 | { 9 | public class MathUtil 10 | { 11 | public static bool InCircle(Vector3 pos, Vector3 center, float radius ) 12 | { 13 | pos.y = 0; 14 | center.y = 0; 15 | return (pos - center).sqrMagnitude <= radius * radius; 16 | } 17 | 18 | public static Vector3 GetDir( Vector3 end, Vector3 start ) 19 | { 20 | return end - start; 21 | } 22 | 23 | public static bool IsEqual(float f1, float f2) 24 | { 25 | return System.Math.Abs(f1 - f2) < 0.00001f; 26 | } 27 | 28 | public static bool IsEqualXZ(Vector3 v1, Vector3 v2) 29 | { 30 | return IsEqual(v1.x, v2.x) && IsEqual(v1.z, v2.z); 31 | } 32 | 33 | public static bool IsEqual(Vector3 v1, Vector3 v2) 34 | { 35 | return IsEqual(v1.x, v2.x) && IsEqual(v1.y, v2.y) && IsEqual(v1.z, v2.z); 36 | } 37 | 38 | public static bool PosEqualXZ( Vector3 pos1, Vector3 pos2 ) 39 | { 40 | pos1.y = 0; 41 | pos2.y = 0; 42 | return (pos1 - pos2).magnitude < 0.2f; 43 | } 44 | 45 | public static bool PosEqual(Vector3 pos1, Vector3 pos2) 46 | { 47 | return (pos1 - pos2).magnitude < 0.2f; 48 | } 49 | 50 | 51 | public static float GetDisXZ( Vector3 pos1, Vector3 pos2 ) 52 | { 53 | pos1.y = 0; 54 | pos2.y = 0; 55 | return (pos1 - pos2).magnitude; 56 | } 57 | 58 | public static float GetDis(Vector3 pos1, Vector3 pos2) 59 | { 60 | return (pos1 - pos2).magnitude; 61 | } 62 | 63 | public static bool Arrived( Vector3 currpos, Vector3 lastPos, Vector3 targetPos) 64 | { 65 | Vector3 ab = targetPos - lastPos; 66 | if( ab.sqrMagnitude <= 0.0001f ) 67 | { 68 | return true; 69 | } 70 | Vector3 ac = currpos - lastPos; 71 | float dot = Vector3.Dot(ab, ac); 72 | dot = dot / ac.magnitude; 73 | if( dot > 0 && dot < ac.magnitude ) 74 | { 75 | return true; 76 | } 77 | else 78 | { 79 | return false; 80 | } 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/Formatter.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace fastJSON 4 | { 5 | internal static class Formatter 6 | { 7 | public static string Indent = " "; 8 | 9 | public static void AppendIndent(StringBuilder sb, int count) 10 | { 11 | for (; count > 0; --count) sb.Append(Indent); 12 | } 13 | 14 | public static string PrettyPrint(string input) 15 | { 16 | var output = new StringBuilder(); 17 | int depth = 0; 18 | int len = input.Length; 19 | char[] chars = input.ToCharArray(); 20 | for (int i = 0; i < len; ++i) 21 | { 22 | char ch = chars[i]; 23 | 24 | if (ch == '\"') // found string span 25 | { 26 | bool str = true; 27 | while (str) 28 | { 29 | output.Append(ch); 30 | ch = chars[++i]; 31 | if (ch == '\\') 32 | { 33 | output.Append(ch); 34 | ch = chars[++i]; 35 | } 36 | else if (ch == '\"') 37 | str = false; 38 | } 39 | } 40 | 41 | switch (ch) 42 | { 43 | case '{': 44 | case '[': 45 | output.Append(ch); 46 | output.AppendLine(); 47 | AppendIndent(output, ++depth); 48 | break; 49 | case '}': 50 | case ']': 51 | output.AppendLine(); 52 | AppendIndent(output, --depth); 53 | output.Append(ch); 54 | break; 55 | case ',': 56 | output.Append(ch); 57 | output.AppendLine(); 58 | AppendIndent(output, depth); 59 | break; 60 | case ':': 61 | output.Append(" : "); 62 | break; 63 | default: 64 | if (!char.IsWhiteSpace(ch)) 65 | output.Append(ch); 66 | break; 67 | } 68 | } 69 | 70 | return output.ToString(); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Assets/Core/Res/ResMgr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace OrcaCore 6 | { 7 | public enum ELoadSrc 8 | { 9 | DataBase = 0, 10 | Resources, 11 | AssetBundle, 12 | } 13 | public class ResMgr 14 | { 15 | private static ResMgr mInst = null; 16 | public static ResMgr Inst 17 | { 18 | get 19 | { 20 | if (mInst == null) 21 | { 22 | mInst = new ResMgr(); 23 | } 24 | return mInst; 25 | } 26 | } 27 | private static ELoadSrc mLoadSrc = ELoadSrc.DataBase; 28 | public static ELoadSrc LoadSrc 29 | { 30 | set { mLoadSrc = value; } 31 | get { return mLoadSrc; } 32 | } 33 | 34 | public static string GetResPath( string assetName ) 35 | { 36 | string resPath = Application.streamingAssetsPath + @"/" + assetName; 37 | return resPath; 38 | } 39 | 40 | public T GetAsset(string path, bool async = true, ELoadPriority priority = ELoadPriority.Default) where T :UnityEngine.Object 41 | { 42 | T t = null; 43 | switch (LoadSrc) 44 | { 45 | case ELoadSrc.DataBase: 46 | #if UNITY_EDITOR 47 | EditorResMgr.Inst.GetAsset(path, (name, obj) => 48 | { 49 | t = obj as T; 50 | }); 51 | break; 52 | #endif 53 | case ELoadSrc.Resources: 54 | ResourceLoaderMgr.Instance.LoadAsset(path, (name, obj) => 55 | { 56 | t = obj as T; 57 | }, async, priority); 58 | break; 59 | case ELoadSrc.AssetBundle: 60 | AssetPool.Instance.GetAsset(path, (name, obj) => 61 | { 62 | t = obj as T; 63 | }, async, priority); 64 | break; 65 | default: 66 | break; 67 | } 68 | return t; 69 | } 70 | 71 | /// 72 | /// 所有异步以及加载等待的管理类需要update // 73 | /// 74 | public void Update() 75 | { 76 | AssetLoaderMgr.Instance.Update(); 77 | ResourceLoaderMgr.Instance.Update(); 78 | WWWLoaderMgr.Instance.Update(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public enum EWWWState 10 | { 11 | None, 12 | Wait, 13 | Loading, 14 | Done, 15 | } 16 | 17 | public enum ELoadPriority 18 | { 19 | MostPrior = 20, 20 | HighPrior = 15, 21 | PriorLoad = 10, 22 | Default = 0, 23 | PostLoad = -10, 24 | } 25 | 26 | public class WWWLoader 27 | { 28 | private string mName = string.Empty; 29 | private string mOriginName = string.Empty; 30 | private WWW mWWW = null; 31 | private EWWWState mState = EWWWState.None; 32 | private Action mWWWCallback; 33 | public ELoadPriority LoadPriority { set; get; } 34 | 35 | public string Name { get { return mName; } } 36 | public string OriginName { get { return mOriginName; } } 37 | public EWWWState LoadState { get { return mState; } } 38 | public float Progress { set; get; } 39 | 40 | public void AddCallback( Action callback ) 41 | { 42 | mWWWCallback -= callback; 43 | mWWWCallback += callback; 44 | } 45 | 46 | public void ReleaseCallback(Action callback) 47 | { 48 | mWWWCallback -= callback; 49 | } 50 | 51 | public static WWWLoader CreateInstance( string name, string originName, ELoadPriority priority, bool isRaw, bool isWeb ) 52 | { 53 | WWWLoader loader = new WWWLoader(); 54 | loader.mName = name; 55 | loader.mOriginName = originName; 56 | loader.mWWW = WWWUtil.CreateWWW(name, isRaw, isWeb); 57 | loader.LoadPriority = priority; 58 | return loader; 59 | } 60 | 61 | public void Update() 62 | { 63 | Progress = mWWW.progress; 64 | if( mWWW.isDone ) 65 | { 66 | mState = EWWWState.Done; 67 | Progress = 1f; 68 | if( mWWWCallback != null) 69 | { 70 | Debug.LogError("www " + mOriginName + " is ok and callback"); 71 | mWWWCallback(mName, mWWW); 72 | } 73 | } 74 | } 75 | public static int WWWLoaderSort( WWWLoader lhs, WWWLoader rhs ) 76 | { 77 | if( lhs.LoadPriority > rhs.LoadPriority) 78 | { 79 | return -1; 80 | } 81 | else 82 | { 83 | return 1; 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Assets/Core/Utils/EventsExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Orca 4 | { 5 | public delegate void Action(T obj, T2 obj2, T3 obj3, T4 obj4, T5 obj5); 6 | public static class EventsExtension 7 | { 8 | public static void SafeInvoke(this Action evt) 9 | { 10 | if (evt != null) 11 | evt(); 12 | } 13 | 14 | public static void SafeInvoke(this Action evt, T arg) 15 | { 16 | if (evt != null) 17 | evt(arg); 18 | } 19 | public static void SafeInvoke(this Action evt, T arg, T2 arg2) 20 | { 21 | if (evt != null) 22 | evt(arg, arg2); 23 | } 24 | public static void SafeInvoke(this Action evt, T arg, T2 arg2, T3 arg3) 25 | { 26 | if (evt != null) 27 | evt(arg, arg2, arg3); 28 | } 29 | public static void SafeInvoke(this Action evt, T arg, T2 arg2, T3 arg3, T4 arg4) 30 | { 31 | if (evt != null) 32 | evt(arg, arg2, arg3, arg4); 33 | } 34 | 35 | public static void SafeInvoke(this Action evt, T arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5) 36 | { 37 | if (evt != null) 38 | evt(arg, arg2, arg3, arg4, arg5); 39 | } 40 | 41 | 42 | public static T SafeInvoke(this Func evt) 43 | { 44 | if (evt != null) 45 | return evt(); 46 | else 47 | return default(T); 48 | } 49 | public static T2 SafeInvoke(this Func evt, T arg) 50 | { 51 | if (evt != null) 52 | return evt(arg); 53 | else 54 | return default(T2); 55 | } 56 | public static T3 SafeInvoke(this Func evt, T arg, T2 arg2) 57 | { 58 | if (evt != null) 59 | return evt(arg, arg2); 60 | else 61 | return default(T3); 62 | } 63 | public static T4 SafeInvoke(this Func evt, T arg, T2 arg2, T3 arg3) 64 | { 65 | if (evt != null) 66 | return evt(arg, arg2, arg3); 67 | else 68 | return default(T4); 69 | } 70 | public static T5 SafeInvoke(this Func evt, T arg, T2 arg2, T3 arg3, T4 arg4) 71 | { 72 | if (evt != null) 73 | return evt(arg, arg2, arg3, arg4); 74 | else 75 | return default(T5); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/ResourcesLoad/ResourcesLoaderMgr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class ResourceLoaderMgr 10 | { 11 | private static ResourceLoaderMgr mInst; 12 | public static ResourceLoaderMgr Instance 13 | { 14 | get 15 | { 16 | if (mInst == null) 17 | { 18 | mInst = new ResourceLoaderMgr(); 19 | } 20 | return mInst; 21 | } 22 | } 23 | 24 | const int MAX_LOADING_COUNT = 9999; 25 | private List mLoadingAsset = new List(); 26 | private List mWaitAsset = new List(); 27 | 28 | private ResourceLoader _GetResourceLoader(string name) 29 | { 30 | ResourceLoader[] loaders = mLoadingAsset.Where(ld => ld.Name.Equals(name)).ToArray(); 31 | if (loaders.Length > 0) 32 | { 33 | return loaders[0]; 34 | } 35 | loaders = mWaitAsset.Where(ld => ld.Name.Equals(name)).ToArray(); 36 | if (loaders.Length > 0) 37 | { 38 | return loaders[0]; 39 | } 40 | return null; 41 | } 42 | 43 | public void LoadAsset(string path, Action callback, bool async, ELoadPriority priority) 44 | { 45 | int dotIdx = path.IndexOf('.'); 46 | if (dotIdx >= 0) 47 | { 48 | path = path.Remove(dotIdx); 49 | } 50 | ResourceLoader loader = _GetResourceLoader(path); 51 | if (loader == null) 52 | { 53 | loader = ResourceLoader.CreateInstance(path, callback, async); 54 | mWaitAsset.Add(loader); 55 | Update(); 56 | } 57 | } 58 | 59 | 60 | public void Update() 61 | { 62 | if (mLoadingAsset.Count < MAX_LOADING_COUNT && mWaitAsset.Count > 0) 63 | { 64 | mWaitAsset.Sort(ResourceLoader.ResourceLoaderSort); 65 | mLoadingAsset.Add(mWaitAsset[0]); 66 | mWaitAsset.RemoveAt(0); 67 | } 68 | for (int i = 0; i < mLoadingAsset.Count;) 69 | { 70 | ResourceLoader loader = mLoadingAsset[i]; 71 | loader.Update(); 72 | if (loader.State == ERequestState.Done) 73 | { 74 | mLoadingAsset.RemoveAt(i); 75 | } 76 | else 77 | { 78 | ++i; 79 | } 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/AssetLoad/AssetLoaderMgr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class AssetLoaderMgr 10 | { 11 | private static AssetLoaderMgr _instance; 12 | public static AssetLoaderMgr Instance 13 | { 14 | get 15 | { 16 | if( _instance == null) 17 | { 18 | _instance = new AssetLoaderMgr(); 19 | } 20 | return _instance; 21 | } 22 | } 23 | 24 | const int MAX_LOADING_COUNT = 9999; 25 | private List mLoadingAsset = new List(); 26 | private List mWaitAsset = new List(); 27 | 28 | private AssetLoader _GetAssetLoader( string name ) 29 | { 30 | AssetLoader[] loaders = mLoadingAsset.Where(ld => ld.Name.Equals(name)).ToArray(); 31 | if (loaders.Length > 0) 32 | { 33 | return loaders[0]; 34 | } 35 | loaders = mWaitAsset.Where(ld => ld.Name.Equals(name)).ToArray(); 36 | if (loaders.Length > 0) 37 | { 38 | return loaders[0]; 39 | } 40 | return null; 41 | } 42 | 43 | public void LoadAsset( Asset asset, bool async, ELoadPriority priority ) 44 | { 45 | AssetLoader loader = _GetAssetLoader(asset.Name); 46 | if (loader == null) 47 | { 48 | loader = AssetLoader.CreateInstance(asset, async); 49 | mWaitAsset.Add(loader); 50 | string bundleName = AssetMap.Instance.GetBundleName(asset.Name); 51 | BundlePool.Instance.GetBundle(bundleName, (cbBundleName, cbBundle) => 52 | { 53 | loader.OnLoadBundle(cbBundleName, cbBundle); 54 | }, priority); 55 | Update(); 56 | } 57 | } 58 | 59 | 60 | public void Update() 61 | { 62 | if (mLoadingAsset.Count < MAX_LOADING_COUNT && mWaitAsset.Count > 0) 63 | { 64 | mWaitAsset.Sort(AssetLoader.AssetLoaderSort); 65 | mLoadingAsset.Add(mWaitAsset[0]); 66 | mWaitAsset.RemoveAt(0); 67 | } 68 | for ( int i = 0; i < mLoadingAsset.Count; ) 69 | { 70 | AssetLoader loader = mLoadingAsset[i]; 71 | loader.Update(); 72 | if( loader.State == EAssetState.Done) 73 | { 74 | mLoadingAsset.RemoveAt(i); 75 | } 76 | else 77 | { 78 | ++i; 79 | } 80 | } 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Asset/AssetPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class AssetPool 10 | { 11 | private static AssetPool _instance; 12 | private Dictionary mDicAsset = new Dictionary(); 13 | 14 | public static AssetPool Instance 15 | { 16 | get 17 | { 18 | if( _instance == null) 19 | { 20 | _instance = new AssetPool(); 21 | } 22 | return _instance; 23 | } 24 | } 25 | public void GetAsset(string name, Action callback, bool async = true, ELoadPriority priority = ELoadPriority.Default) 26 | { 27 | Asset asset = null; 28 | if (mDicAsset.TryGetValue(name, out asset)) 29 | { 30 | if (callback != null) 31 | { 32 | if (asset.AssetValid) 33 | { 34 | callback(name, asset.GetObject()); 35 | } 36 | else 37 | { 38 | asset.AddCallback(callback); 39 | } 40 | } 41 | } 42 | else 43 | { 44 | Debug.LogError("get asset " + name); 45 | asset = Asset.CreateInstance(name); 46 | if (name.Contains(".ttf") || name.Contains(".TTF")) 47 | { 48 | int xx = 0; 49 | ++xx; 50 | } 51 | asset.AddCallback(callback); 52 | mDicAsset.Add(name, asset); 53 | AssetLoaderMgr.Instance.LoadAsset(asset, async, priority); 54 | } 55 | } 56 | 57 | public void ReleaseAssetCallback( string name, Action callback) 58 | { 59 | Asset asset = null; 60 | if (mDicAsset.TryGetValue(name, out asset)) 61 | { 62 | asset.ReleaseCallback(callback); 63 | } 64 | } 65 | 66 | public void ReleaseAsset(string name, bool includeSelf = false) 67 | { 68 | Asset asset = null; 69 | if (mDicAsset.TryGetValue(name, out asset)) 70 | { 71 | asset.ReleaseAsset(includeSelf); 72 | if (includeSelf) 73 | { 74 | mDicAsset.Remove(name); 75 | } 76 | } 77 | } 78 | public void ReleaseAssetRefrence( string name, UnityEngine.Object obj) 79 | { 80 | Asset asset = null; 81 | if (mDicAsset.TryGetValue(name, out asset)) 82 | { 83 | asset.ReleaseAssetReference(obj); 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Assets/Core/Utils/FileUtil.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.IO; 3 | 4 | namespace OrcaCore 5 | { 6 | public class EngineFileUtil 7 | { 8 | //IndexMap分隔字符// 9 | public const string msIndexMapSpliter = ":"; 10 | //扩展名// 11 | public const string m_fbxExt = ".fbx"; 12 | public const string m_matExt = ".mat"; 13 | public const string m_maxExt = ".max"; 14 | public const string m_prefabExt = ".prefab"; 15 | public const string m_animExt = ".anim"; 16 | public const string m_animSrcFileContain = "@"; 17 | public const string m_txtExt = ".txt"; 18 | public const string m_md5Ext = ".md5.txt"; 19 | public const string m_packExt = ".pack.txt"; 20 | public const string m_curveAnimExt = ".ca.txt"; 21 | public const string m_sceneDataExt = ".scene.txt"; 22 | public const string m_unityExt = ".unity"; 23 | public const string m_sceneExt = ".unity3d"; 24 | public const string m_bundleExt = ".bundle"; 25 | public const string m_bytesExt = ".bytes"; 26 | public const string m_hmdExt = ".unity.txt"; 27 | public const string m_reportExt = ".report.txt"; 28 | public const string m_oggExt = ".ogg"; 29 | public const string m_assetExt = ".asset"; 30 | public const string m_txtidxExt = ".txt_idx"; 31 | public const string m_idxExtPost = "_idx"; 32 | 33 | //搜索文件。由于FirePackBundle处于Unity运行时环境中,其.NET版本不支持SearchOption,所以必须由此编辑期模块中的函数处理。// 34 | public static string[] GetFilesFunc(string path, string searchPattern, bool includeSubDir) 35 | { 36 | //if(!Directory.Exists(path)) 37 | // return new string[]{}; 38 | return Directory.GetFiles(path, searchPattern, 39 | includeSubDir ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); 40 | } 41 | 42 | //获取文件大小。由于FirePackBundle处于Unity运行时环境中,其.NET版本不支持FileInfo.Length,所以必须由此编辑期模块中的函数处理。// 43 | public static long GetFileLength(string path) 44 | { 45 | FileInfo fi = new FileInfo(path); 46 | return fi.Length; 47 | } 48 | 49 | //工具函数// 50 | public static void SaveText(string str, string textFilePath) 51 | { 52 | FileStream fileStream = new FileStream(textFilePath, FileMode.Create); 53 | StreamWriter writer = new StreamWriter(fileStream); 54 | writer.Write(str); 55 | writer.Flush(); 56 | writer.Close(); 57 | fileStream.Close(); 58 | } 59 | public static string ReadText(string textFilePath) 60 | { 61 | if (!File.Exists(textFilePath)) 62 | return string.Empty; 63 | FileStream fileStream = new FileStream(textFilePath, FileMode.Open); 64 | StreamReader reader = new StreamReader(fileStream); 65 | string buf = reader.ReadToEnd(); 66 | reader.Close(); 67 | fileStream.Close(); 68 | return buf; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/dynamic.cs: -------------------------------------------------------------------------------- 1 | #if net4 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Dynamic; 6 | using System.Linq; 7 | 8 | namespace fastJSON 9 | { 10 | internal class DynamicJson : DynamicObject, IEnumerable 11 | { 12 | private IDictionary _dictionary { get; set; } 13 | private List _list { get; set; } 14 | 15 | public DynamicJson(string json) 16 | { 17 | var parse = fastJSON.JSON.Parse(json); 18 | 19 | if (parse is IDictionary) 20 | _dictionary = (IDictionary)parse; 21 | else 22 | _list = (List)parse; 23 | } 24 | 25 | private DynamicJson(object dictionary) 26 | { 27 | if (dictionary is IDictionary) 28 | _dictionary = (IDictionary)dictionary; 29 | } 30 | 31 | public override IEnumerable GetDynamicMemberNames() 32 | { 33 | return _dictionary.Keys.ToList(); 34 | } 35 | 36 | public override bool TryGetIndex(GetIndexBinder binder, Object[] indexes, out Object result) 37 | { 38 | var index = indexes[0]; 39 | if (index is int) 40 | { 41 | result = _list[(int) index]; 42 | } 43 | else 44 | { 45 | result = _dictionary[(string) index]; 46 | } 47 | if (result is IDictionary) 48 | result = new DynamicJson(result as IDictionary); 49 | return true; 50 | } 51 | 52 | public override bool TryGetMember(GetMemberBinder binder, out object result) 53 | { 54 | if (_dictionary.TryGetValue(binder.Name, out result) == false) 55 | if (_dictionary.TryGetValue(binder.Name.ToLower(), out result) == false) 56 | return false;// throw new Exception("property not found " + binder.Name); 57 | 58 | if (result is IDictionary) 59 | { 60 | result = new DynamicJson(result as IDictionary); 61 | } 62 | else if (result is List) 63 | { 64 | List list = new List(); 65 | foreach (object item in (List)result) 66 | { 67 | if (item is IDictionary) 68 | list.Add(new DynamicJson(item as IDictionary)); 69 | else 70 | list.Add(item); 71 | } 72 | result = list; 73 | } 74 | 75 | return _dictionary.ContainsKey(binder.Name); 76 | } 77 | 78 | IEnumerator IEnumerable.GetEnumerator() 79 | { 80 | foreach(var o in _list) 81 | { 82 | yield return new DynamicJson(o as IDictionary); 83 | } 84 | } 85 | } 86 | } 87 | #endif -------------------------------------------------------------------------------- /Assets/Core/Utils/OrcaUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | using System.IO; 7 | using System.Runtime.Serialization; 8 | using System.Runtime.Serialization.Formatters.Binary; 9 | 10 | namespace Orca 11 | { 12 | public class OrcaUtil 13 | { 14 | public static string Emphasize( string str) 15 | { 16 | return " [" + str + "] "; 17 | } 18 | 19 | public static GameObject GetBone(string boneName, GameObject parent) 20 | { 21 | if( string.IsNullOrEmpty(boneName)) 22 | { 23 | return parent; 24 | } 25 | 26 | Transform[] trs = parent.transform.GetComponentsInChildren(true); 27 | for (int i = 0; i < trs.Length; ++i) 28 | { 29 | if (trs[i].name == boneName) 30 | { 31 | return trs[i].gameObject; 32 | } 33 | } 34 | Debug.Log("can't find bone named " + boneName + Emphasize(parent.name)); 35 | return null; 36 | } 37 | 38 | public static bool RayCastWalkSurface(out Vector3 pos) 39 | { 40 | pos = Vector3.zero; 41 | Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 42 | RaycastHit hit; 43 | if (Physics.Raycast(ray, out hit, 1000, 1 << (int)ELayerDef.WalkSurface)) 44 | { 45 | pos = hit.point; 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | public static Vector3 GetFocusPos() 52 | { 53 | Vector3 pos = Vector3.zero; 54 | Ray ray = Camera.main.ViewportPointToRay(new Vector2(0.5f, 0.5f)); 55 | RaycastHit hit; 56 | if (Physics.Raycast(ray, out hit, 1000, 1 << (int)ELayerDef.WalkSurface)) 57 | { 58 | pos = hit.point; 59 | } 60 | return pos; 61 | } 62 | 63 | public static Vector3 String2Vec3(string str) 64 | { 65 | float[] array = str.Split(',').Select(p => float.Parse(p)).ToArray(); 66 | return new Vector3(array[0], array[1], array[2]); 67 | } 68 | public static string Vec32String(Vector3 vec) 69 | { 70 | return "[" + vec.x + ", " + vec.y + ", " + vec.z + "]"; 71 | } 72 | 73 | public static Rect String2Rect(string str) 74 | { 75 | float[] array = str.Split(',').Select(p => float.Parse(p)).ToArray(); 76 | return new Rect(array[0], array[1], array[2], array[3]); 77 | } 78 | public static string Rect2String(Rect vec) 79 | { 80 | return "[" + vec.x + ", " + vec.y + ", " + vec.width + ", " + vec.height + "]"; 81 | } 82 | 83 | public static T Copy( T RealObject ) 84 | { 85 | using (Stream objctStream = new MemoryStream ()) { 86 | IFormatter formatter = new BinaryFormatter (); 87 | formatter.Serialize (objctStream, RealObject); 88 | objctStream.Seek (0, SeekOrigin.Begin); 89 | return (T)formatter.Deserialize (objctStream); 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWLoaderMgr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class WWWLoaderMgr 10 | { 11 | private static WWWLoaderMgr _instance; 12 | public static WWWLoaderMgr Instance 13 | { 14 | get 15 | { 16 | if (_instance == null) 17 | { 18 | _instance = new WWWLoaderMgr(); 19 | } 20 | return _instance; 21 | } 22 | } 23 | 24 | const int MAX_DOWN_COUNT = 5; 25 | /// 26 | /// 这里放弃使用dic而用list,主要用于update loader 27 | /// 28 | private List mWaitList = new List(); 29 | private List mDownList = new List(); 30 | 31 | public void LoadWWW( string name, string originName, Action callback, ELoadPriority priority, bool isRaw, bool isWeb) 32 | { 33 | if( string.IsNullOrEmpty(name)) 34 | { 35 | Debug.LogError("load www but name is empty or null."); 36 | return; 37 | } 38 | WWWLoader loader = _GetWWWLoader(name); 39 | if( loader == null) 40 | { 41 | loader = WWWLoader.CreateInstance(name, originName, priority, isRaw, isWeb); 42 | mWaitList.Add(loader); 43 | } 44 | loader.AddCallback(callback); 45 | } 46 | 47 | private WWWLoader _GetWWWLoader( string name ) 48 | { 49 | WWWLoader loader = null; 50 | WWWLoader[] loaders = mDownList.Where(ld => ld.Name.Equals(name)).ToArray(); 51 | if (loaders.Length > 0) 52 | { 53 | loader = loaders[0]; 54 | } 55 | loaders = mWaitList.Where(ld => ld.Name.Equals(name)).ToArray(); 56 | if (loaders.Length > 0) 57 | { 58 | loader = loaders[0]; 59 | } 60 | return loader; 61 | } 62 | 63 | public float GetProgress(string name) 64 | { 65 | WWWLoader loader = _GetWWWLoader(name); 66 | if (loader == null) 67 | { 68 | return 0; 69 | } 70 | else 71 | { 72 | return loader.Progress; 73 | } 74 | } 75 | 76 | public void Update() 77 | { 78 | for( int i = 0; i < mDownList.Count; ) 79 | { 80 | WWWLoader loader = mDownList[i]; 81 | loader.Update(); 82 | if( loader.LoadState == EWWWState.Done) 83 | { 84 | mDownList.RemoveAt(i); 85 | } 86 | else 87 | { 88 | ++i; 89 | } 90 | } 91 | if( mDownList.Count < MAX_DOWN_COUNT && mWaitList.Count > 0) 92 | { 93 | mWaitList.Sort(WWWLoader.WWWLoaderSort); 94 | mDownList.Add(mWaitList[0]); 95 | mWaitList.RemoveAt(0); 96 | } 97 | } 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Bundle/BundlePool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class BundlePool 10 | { 11 | private static BundlePool _instance; 12 | public static BundlePool Instance 13 | { 14 | get 15 | { 16 | if (_instance == null) 17 | { 18 | _instance = new BundlePool(); 19 | } 20 | return _instance; 21 | } 22 | } 23 | 24 | private Dictionary mDicBundle = new Dictionary(); 25 | 26 | public bool IsBundleCached(string name) 27 | { 28 | Bundle bundle = null; 29 | if (mDicBundle.TryGetValue(name, out bundle)) 30 | { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | public void GetBundle(string bundleName, Action callback, ELoadPriority priority, bool isRaw = true, bool isWeb = false) 37 | { 38 | Bundle bundle = null; 39 | if (mDicBundle.TryGetValue(bundleName, out bundle)) 40 | { 41 | callback(bundleName, bundle); 42 | } 43 | else 44 | { 45 | string[] depends = BundleMap.Instance.GetDependence(bundleName); 46 | if( depends.Length > 0) 47 | { 48 | int dependsCount = depends.Length; 49 | for (int i = 0; i < depends.Length; ++i) 50 | { 51 | string dependBundleName = depends[i]; 52 | GetBundle(dependBundleName, (cbName, cbBundle) => 53 | { 54 | if(--dependsCount <= 0) 55 | { 56 | LoadBundle(bundleName, callback, priority, isRaw, isWeb); 57 | } 58 | }, priority); 59 | 60 | } 61 | } 62 | else 63 | { 64 | LoadBundle(bundleName, callback, priority, isRaw, isWeb); 65 | } 66 | 67 | } 68 | } 69 | 70 | private void LoadBundle(string bundleName, Action callback, ELoadPriority priority, bool isRaw, bool isWeb) 71 | { 72 | Bundle bundle = null; 73 | string md5Name = BundleMap.Instance.GetMd5Name(bundleName); 74 | Debug.LogError("load bundle " + bundleName + " : " + md5Name); 75 | WWWLoaderMgr.Instance.LoadWWW(md5Name, bundleName, (cbBundleName, cbWWW) => 76 | { 77 | if (bundleName.Contains("ui_font")) 78 | { 79 | int xx = 0; 80 | ++xx; 81 | } 82 | Debug.LogError("on load bundle ok " + bundleName); 83 | if (!mDicBundle.TryGetValue(bundleName, out bundle)) 84 | { 85 | bundle = Bundle.CreateInstance(bundleName); 86 | mDicBundle.Add(bundleName, bundle); 87 | } 88 | bundle.OnLoadWWW(bundleName, cbWWW); 89 | callback(bundleName, bundle); 90 | }, priority, isRaw, isWeb); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/ResourcesLoad/ResourcesLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace OrcaCore 7 | { 8 | public enum ERequestState 9 | { 10 | None = 0, 11 | Wait, 12 | BundleOk, 13 | Loading, 14 | Done, 15 | } 16 | public class ResourceLoader 17 | { 18 | private ERequestState mState = ERequestState.None; 19 | private bool mAsync = true; 20 | private ResourceRequest mRequest; 21 | private string mName = string.Empty; 22 | private Action mCallback; 23 | public Action Callback 24 | { 25 | set 26 | { 27 | mCallback -= value; 28 | mCallback += value; 29 | } 30 | get { return mCallback; } 31 | } 32 | 33 | public string Name 34 | { 35 | get { return mName; } 36 | } 37 | public ERequestState State 38 | { 39 | get { return mState; } 40 | set { mState = value; } 41 | } 42 | 43 | public static ResourceLoader CreateInstance(string name, Action callback, bool async) 44 | { 45 | ResourceLoader loader = new ResourceLoader(); 46 | loader.mName = name; 47 | loader.mAsync = async; 48 | loader.mState = ERequestState.Wait; 49 | loader.Callback += callback; 50 | return loader; 51 | } 52 | 53 | public void Update() 54 | { 55 | if (mName.Contains("nvTD")) 56 | { 57 | int xx = 0; 58 | ++xx; 59 | Debug.LogError("Update " + mName + " State = " + mState.ToString()); 60 | } 61 | if (mState == ERequestState.BundleOk) 62 | { 63 | if (mName.Contains("nvTD")) 64 | { 65 | int xx = 0; 66 | ++xx; 67 | D.error("resources load " + mName); 68 | } 69 | if (mAsync) 70 | { 71 | mRequest = Resources.LoadAsync(mName); 72 | mState = ERequestState.Loading; 73 | } 74 | else 75 | { 76 | UnityEngine.Object obj = Resources.Load(mName); 77 | mState = ERequestState.Done; 78 | Debug.LogError("on load asset " + mName); 79 | if( mCallback != null ) 80 | { 81 | mCallback(mName, obj); 82 | } 83 | } 84 | } 85 | if (mState == ERequestState.Loading && mRequest.isDone) 86 | { 87 | if (mName.Contains("nvTD")) 88 | { 89 | int xx = 0; 90 | ++xx; 91 | } 92 | mState = ERequestState.Done; 93 | if( mCallback != null ) 94 | { 95 | mCallback( mName, mRequest.asset); 96 | } 97 | } 98 | } 99 | 100 | public static int ResourceLoaderSort(ResourceLoader lhs, ResourceLoader rhs) 101 | { 102 | if (lhs.State > rhs.State) 103 | { 104 | return -1; 105 | } 106 | else 107 | { 108 | return 1; 109 | } 110 | } 111 | 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/AssetLoad/AssetLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public enum EAssetState 10 | { 11 | None = 0, 12 | Wait, 13 | BundleOk, 14 | Loading, 15 | Done, 16 | } 17 | public class AssetLoader 18 | { 19 | private Asset mAsset = null; 20 | private EAssetState mState = EAssetState.None; 21 | private Bundle mBundle = null; 22 | private bool mAsync = true; 23 | private AssetBundleRequest mRequest; 24 | 25 | public string Name 26 | { 27 | get 28 | { 29 | if (mAsset == null) 30 | { 31 | return string.Empty; 32 | } 33 | else 34 | { 35 | return mAsset.Name; 36 | } 37 | } 38 | } 39 | public EAssetState State 40 | { 41 | get { return mState; } 42 | set { mState = value; } 43 | } 44 | public static AssetLoader CreateInstance( Asset asset, bool async ) 45 | { 46 | AssetLoader loader = new AssetLoader(); 47 | loader.mAsync = async; 48 | loader.mAsset = asset; 49 | loader.mState = EAssetState.Wait; 50 | return loader; 51 | } 52 | 53 | public void Update() 54 | { 55 | if( mAsset.Name.Contains("nvTD")) 56 | { 57 | int xx = 0; 58 | ++xx; 59 | Debug.LogError("Update " + mAsset.Name + " State = " + mState.ToString()); 60 | } 61 | if( mState == EAssetState.BundleOk) 62 | { 63 | if (mAsset.Name.Contains("nvTD")) 64 | { 65 | int xx = 0; 66 | ++xx; 67 | Debug.LogError("OnAssetLoad " + mAsset.Name); 68 | } 69 | if (false) 70 | { 71 | mRequest = mBundle.AssetBundle.LoadAssetAsync(mAsset.Name); 72 | mState = EAssetState.Loading; 73 | } 74 | else 75 | { 76 | UnityEngine.Object obj = mBundle.AssetBundle.LoadAsset(mAsset.Name); 77 | mState = EAssetState.Done; 78 | Debug.LogError("on load asset " + mAsset.Name); 79 | mAsset.OnAssetLoad( mAsset.Name, obj); 80 | } 81 | } 82 | if (mState == EAssetState.Loading && mRequest.isDone) 83 | { 84 | if (mAsset.Name.Contains("nvTD")) 85 | { 86 | int xx = 0; 87 | ++xx; 88 | } 89 | mState = EAssetState.Done; 90 | mAsset.OnAssetLoad(mAsset.Name, mRequest.asset); 91 | } 92 | } 93 | 94 | public static int AssetLoaderSort( AssetLoader lhs, AssetLoader rhs) 95 | { 96 | if( lhs.State > rhs.State) 97 | { 98 | return -1; 99 | } 100 | else 101 | { 102 | return 1; 103 | } 104 | } 105 | 106 | public void OnLoadBundle( string bundleName, Bundle bundle ) 107 | { 108 | Debug.LogError("asset loader " + mAsset.Name + "on load bundle " + bundleName); 109 | mState = EAssetState.BundleOk; 110 | mBundle = bundle; 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/WWW/WWWFilePool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class WWWFilePool 10 | { 11 | private static WWWFilePool _instance; 12 | public static WWWFilePool Instance 13 | { 14 | get 15 | { 16 | if (_instance == null) 17 | { 18 | _instance = new WWWFilePool(); 19 | } 20 | return _instance; 21 | } 22 | } 23 | private Dictionary mDicObject = new Dictionary(); 24 | 25 | public bool IsWWWFileCached( string name ) 26 | { 27 | System.Object obj; 28 | if( mDicObject.TryGetValue(name, out obj)) 29 | { 30 | return true; 31 | } 32 | return false; 33 | } 34 | 35 | public void GetTextFile(string name, Action func, ELoadPriority priority = ELoadPriority.Default, bool isRaw = true, bool isWeb = false) 36 | { 37 | System.Object obj = null; 38 | if (mDicObject.TryGetValue(name, out obj)) 39 | { 40 | func(name, obj as string); 41 | } 42 | else 43 | { 44 | Debug.LogError("load text " + name); 45 | WWWLoaderMgr.Instance.LoadWWW(name, name, (cbName, cbWWW) => 46 | { 47 | Debug.LogError("on load text " + name); 48 | if (cbWWW.text == null) 49 | { 50 | Debug.LogError("get text from WWW, but www.text == null."); 51 | } 52 | else 53 | { 54 | mDicObject.Add(name, cbWWW.text); 55 | func(cbName, cbWWW.text); 56 | } 57 | }, priority, isRaw, isWeb); 58 | } 59 | } 60 | 61 | public void GetBytesFile(string name, Action func, ELoadPriority priority = ELoadPriority.Default, bool isRaw = true, bool isWeb = false) 62 | { 63 | System.Object obj = null; 64 | if (mDicObject.TryGetValue(name, out obj)) 65 | { 66 | func(name, obj as byte[]); 67 | } 68 | else 69 | { 70 | Debug.LogError("load bytes " + name); 71 | WWWLoaderMgr.Instance.LoadWWW(name, name, (cbName, cbWWW) => 72 | { 73 | Debug.LogError("on load bytes " + name); 74 | if (cbWWW.bytes == null) 75 | { 76 | Debug.LogError("get bytes from WWW, but www.bytes == null."); 77 | } 78 | else 79 | { 80 | mDicObject.Add(name, cbWWW.bytes); 81 | func(cbName, cbWWW.bytes); 82 | } 83 | }, priority, isRaw, isWeb); 84 | } 85 | } 86 | 87 | public void GetWWWFile(string name, Action func, ELoadPriority priority = ELoadPriority.Default, bool isRaw = true, bool isWeb = false) 88 | { 89 | System.Object obj = null; 90 | if (mDicObject.TryGetValue(name, out obj)) 91 | { 92 | func(name, obj as WWW); 93 | } 94 | else 95 | { 96 | Debug.LogError("load www " + name); 97 | WWWLoaderMgr.Instance.LoadWWW(name, name, (cbName, cbWWW) => 98 | { 99 | Debug.LogError("on load www " + name); 100 | mDicObject.Add(name, cbWWW); 101 | func(cbName, cbWWW); 102 | }, priority, isRaw, isWeb); 103 | } 104 | } 105 | 106 | public void RemoveWWWFile(string name) 107 | { 108 | mDicObject.Remove(name); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Entry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | //using System.Threading.Tasks; 6 | 7 | namespace Toml 8 | { 9 | /// 10 | /// Represents a identifier = value entry in the document. 11 | /// 12 | public class Entry 13 | { 14 | /// 15 | /// Supported TOML types. 16 | /// 17 | public enum TomlType 18 | { 19 | Unknown, 20 | String, 21 | Int, 22 | Float, 23 | DateTime, 24 | Boolean, 25 | Array 26 | } 27 | 28 | /// 29 | /// Initializes a new instance of the Entry class. 30 | /// 31 | public Entry(string group, string name, string source, int startLineNumber, int startPos, TomlType parsedType) 32 | { 33 | this.Group = group ?? string.Empty; 34 | this.Name = name; 35 | this.SourceText = source; 36 | this.LineNumber = startLineNumber; 37 | this.Position = startPos; 38 | this.ParsedType = parsedType; 39 | } 40 | 41 | /// 42 | /// Initializes a new instance of the Entry class. 43 | /// 44 | public Entry(Array parent, string group, string source, int startLineNumber, int startPos, TomlType parsedType) 45 | { 46 | this.Parent = parent; 47 | this.Group = group ?? string.Empty; 48 | this.Name = Array.GetEntryName(parent); 49 | this.SourceText = source; 50 | this.LineNumber = startLineNumber; 51 | this.Position = startPos; 52 | this.ParsedType = parsedType; 53 | } 54 | 55 | /// 56 | /// Returns a string representing the value 57 | /// 58 | /// A string representing the value 59 | public override string ToString() 60 | { 61 | if (this.Parent == null) 62 | { 63 | return string.Format 64 | ( 65 | "{0} {1} = {3}{2}{3}", 66 | this.ParsedType.ToString(), 67 | this.FullName, 68 | this.SourceText, 69 | this.ParsedType == TomlType.String ? "\"" : string.Empty 70 | ); 71 | } 72 | 73 | if (this.ParsedType == TomlType.String) 74 | { 75 | return "\"" + this.SourceText + "\""; 76 | } 77 | 78 | return this.SourceText; 79 | } 80 | 81 | /// 82 | /// The name of the group the value belongs to. 83 | /// 84 | public string Group { get; private set; } 85 | 86 | /// 87 | /// Gets the full name of the entry. 88 | /// 89 | public string FullName 90 | { 91 | get 92 | { 93 | if (string.IsNullOrEmpty(this.Group)) 94 | { 95 | return this.Name; 96 | } 97 | 98 | return this.Group + "." + this.Name; 99 | } 100 | } 101 | 102 | /// 103 | /// The name of the value item. 104 | /// 105 | public string Name { get; private set; } 106 | 107 | /// 108 | /// The text of the value. 109 | /// 110 | public string SourceText { get; protected set; } 111 | 112 | /// 113 | /// Gets the 1-based line number the value starts at. 114 | /// 115 | public int LineNumber { get; private set; } 116 | 117 | /// 118 | /// Gets the 0-based position on the line the value starts at. 119 | /// 120 | public int Position { get; private set; } 121 | 122 | /// 123 | /// The array (if any) that owns this entry. 124 | /// 125 | public Array Parent { get; private set; } 126 | 127 | /// 128 | /// Gets the type that the lexer parsed the entry as. 129 | /// 130 | public TomlType ParsedType { get; private set; } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Document.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | //using System.Threading.Tasks; 7 | 8 | namespace Toml 9 | { 10 | /// 11 | /// The root group for a Toml document. 12 | /// 13 | public class Document : Group 14 | { 15 | /// 16 | /// Loads a TOML document from the specified file. 17 | /// 18 | /// The name of the file to load. 19 | /// A new Document representing the contents of the file. 20 | public static Document Create(string filename) 21 | { 22 | var doc = new Document(); 23 | foreach (var entry in Parser.Parse(filename)) 24 | { 25 | doc.AddValue(entry); 26 | } 27 | 28 | return doc; 29 | } 30 | 31 | /// 32 | /// Loads a TOML document from the specified stream. 33 | /// 34 | /// The Stream to load the Document from. 35 | /// A new Document representing the contents of the stream. 36 | public static Document Create(Stream stream) 37 | { 38 | var doc = new Document(); 39 | foreach (var entry in Parser.Parse(stream)) 40 | { 41 | doc.AddValue(entry); 42 | } 43 | 44 | return doc; 45 | } 46 | 47 | /// 48 | /// Initializes a new instance of the Document class. 49 | /// 50 | internal Document() 51 | : base(string.Empty) 52 | { 53 | } 54 | 55 | /// 56 | /// Attempts to find the field with the specified name. 57 | /// 58 | /// 59 | /// 60 | /// true if the named value can be found and parsed as the requested type, otherwise false. 61 | public bool TryGetFieldValue(string name, out T result) 62 | { 63 | result = default(T); 64 | 65 | string value = null; 66 | if (TryGetValue(name, out value)) 67 | { 68 | return TypeParsers.TryParse(value, out result); 69 | } 70 | 71 | return false; 72 | } 73 | 74 | /// 75 | /// Attempts to find the field with the specified 76 | /// 77 | /// 78 | /// 79 | /// 80 | public T GetFieldValue(string name) 81 | { 82 | string value = null; 83 | if (TryGetValue(name, out value)) 84 | { 85 | return TypeParsers.Parse(value); 86 | } 87 | 88 | throw new KeyNotFoundException("Specified value was not found"); 89 | } 90 | 91 | /// 92 | /// Attempts to get the array field with the specified name. 93 | /// 94 | /// 95 | /// 96 | /// 97 | public T[] GetArrayValue(string name) 98 | { 99 | Entry entry = this.GetValue(name); 100 | if (entry.ParsedType != Entry.TomlType.Array) 101 | { 102 | throw new InvalidOperationException("Specified value is not an array"); 103 | } 104 | 105 | // TODO: MAKE MULTI-DIMENSION ARRAYS WORK. 106 | var arrayEntry = (Toml.Array)entry; 107 | //if (typeof(T).IsArray) 108 | //{ 109 | // return GetArrayValue(typeof(T).GetElementType(), name); 110 | //} 111 | 112 | //if (typeof(T).Equals(typeof(object))) 113 | //{ 114 | // return arrayEntry.Children 115 | // .Select(c => c.SourceText) 116 | // .Select(val => TypeParsers.Parse(arrayEntry.GetArrayType(), val)) 117 | // .ToArray(); 118 | //} 119 | 120 | return arrayEntry.Children 121 | .Select(c => c.SourceText) 122 | .Select(val => TypeParsers.Parse(val)) 123 | .ToArray(); 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Bundle/LoadingProgressMgr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class LoadingProgressMgr 10 | { 11 | private static LoadingProgressMgr _instance; 12 | public static LoadingProgressMgr Instance 13 | { 14 | get 15 | { 16 | if (_instance == null) 17 | { 18 | _instance = new LoadingProgressMgr(); 19 | } 20 | return _instance; 21 | } 22 | } 23 | 24 | class ProgressInfo 25 | { 26 | public string BundleName { set; get; } 27 | public string Md5Name { set; get; } 28 | public int Size { set; get; } 29 | public float Progress { set; get; } 30 | } 31 | 32 | private List mListProgress = new List(); 33 | private Action mProgressHandler = null; 34 | private Action mEndHandler = null; 35 | private int mAllSize = 0; 36 | 37 | public void SetProgress(string[] wwwNames, string[] bundleNames, string[] assetNames, Action handler, Action onEnd = null) 38 | { 39 | mListProgress.Clear(); 40 | HashSet wwwNameSet = new HashSet(); 41 | if (wwwNames != null) 42 | { 43 | foreach (string name in wwwNames) 44 | { 45 | wwwNameSet.Add(name); 46 | } 47 | } 48 | HashSet bundleNameSet = new HashSet(); 49 | if (bundleNames != null) 50 | { 51 | foreach (string bundleName in bundleNames) 52 | { 53 | bundleNameSet.Add(bundleName); 54 | } 55 | } 56 | if (assetNames != null) 57 | { 58 | foreach (string assetName in assetNames) 59 | { 60 | string bundleName = AssetMap.Instance.GetBundleName(assetName); 61 | bundleNameSet.Add(bundleName); 62 | } 63 | } 64 | HashSet dependsSet = new HashSet(); 65 | foreach (string bundleName in bundleNameSet) 66 | { 67 | string[] depends = BundleMap.Instance.GetDependence(bundleName); 68 | foreach (string dep in depends) 69 | { 70 | dependsSet.Add(dep); 71 | } 72 | } 73 | bundleNameSet.UnionWith(dependsSet); 74 | int mAllSize = 0; 75 | foreach (string bundleName in bundleNameSet) 76 | { 77 | int size = BundleMap.Instance.GetSize(bundleName); 78 | string md5Name = BundleMap.Instance.GetMd5Name(bundleName); 79 | ProgressInfo pi = new ProgressInfo(); 80 | pi.BundleName = bundleName; 81 | pi.Md5Name = md5Name; 82 | pi.Size = size; 83 | pi.Progress = 0; 84 | mListProgress.Add(pi); 85 | mAllSize += size; 86 | } 87 | mProgressHandler = handler; 88 | mEndHandler = onEnd; 89 | } 90 | 91 | public void Update() 92 | { 93 | float loadSize = 0; 94 | foreach (ProgressInfo pi in mListProgress) 95 | { 96 | bool cached = BundlePool.Instance.IsBundleCached(pi.BundleName); 97 | if (cached) 98 | { 99 | pi.Progress = 1; 100 | } 101 | else 102 | { 103 | cached = WWWFilePool.Instance.IsWWWFileCached(pi.Md5Name); 104 | if (cached) 105 | { 106 | pi.Progress = 1; 107 | } 108 | else 109 | { 110 | pi.Progress = WWWLoaderMgr.Instance.GetProgress(pi.Md5Name); 111 | } 112 | } 113 | loadSize += pi.Progress * pi.Size; 114 | } 115 | if (mProgressHandler != null) 116 | { 117 | mProgressHandler(loadSize / mAllSize); 118 | } 119 | if( Mathf.Abs(loadSize/mAllSize) - 1.0f <= 0.01f) 120 | { 121 | mEndHandler(); 122 | } 123 | } 124 | 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | //using System.Threading.Tasks; 7 | 8 | namespace TestCLI 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | TestSerializer(); 15 | 16 | var doc = Toml.Document.Create(".\\TestFiles\\TestData.toml"); 17 | Console.WriteLine(doc.ToString()); 18 | 19 | var value = doc.GetValue("servers.alpha.dc"); 20 | var multiLine = doc.GetFieldValue("multi_line_test"); 21 | Console.WriteLine("multi_line_test = {0}{1}", System.Environment.NewLine, multiLine); 22 | 23 | int conMax = doc.GetFieldValue("database.connection_max"); 24 | var ports = doc.GetArrayValue("database.ports"); 25 | var portStrings = doc.GetArrayValue("database.ports"); 26 | 27 | var clientsDataArray = doc.GetArrayValue("clients.data"); 28 | 29 | string bio = doc.GetFieldValue("owner.bio"); 30 | Console.WriteLine("bio: {0}", bio); 31 | 32 | // this type isn't supported, but the TryGetFieldValue shouldn't throw. 33 | Guid guidResult; 34 | bool success = doc.TryGetFieldValue("owner.bio", out guidResult); 35 | System.Diagnostics.Debug.Assert(!success); 36 | 37 | TestArray(); 38 | TestParser(); 39 | } 40 | 41 | static void TestSerializer() 42 | { 43 | TestConfig config = new TestConfig( 44 | "127.0.0.1", 45 | 8080, 46 | true 47 | ); 48 | 49 | config.SetAlternative 50 | ( 51 | new TestConfig("10.10.1.184", 8081, true) 52 | ); 53 | 54 | config.IPNames = new[] 55 | { 56 | new[] {"192.168.1.1", "192.168.1.2"}, 57 | new[] {"dns_root_1", "dns_root_2"} 58 | }; 59 | 60 | config.SetBackupPorts(new[] { 8082, 8083, 8084 }); 61 | 62 | using (var writer = File.CreateText("TestConfig.toml")) 63 | { 64 | Toml.Serializer.Write(config, string.Empty, writer); 65 | } 66 | 67 | return; 68 | } 69 | 70 | /// 71 | /// testing work-in-progress for pulling out strongly typed arrays. 72 | /// 73 | static void TestArray() 74 | { 75 | var arr = new object[] { new[] { (Int32)32, (Int32)63 }, new[] { "hello", "goodbye" } }; 76 | 77 | var arrayDoc = Toml.Document.Create(".\\TestFiles\\array.toml"); 78 | Type portsType = (arrayDoc.GetValue("clients.ports") as Toml.Array).GetArrayType(); 79 | Type randomType = (arrayDoc.GetValue("clients.random") as Toml.Array).GetArrayType(); 80 | Type dataType = (arrayDoc.GetValue("clients.data") as Toml.Array).GetArrayType(); 81 | Type hostsType = (arrayDoc.GetValue("clients.hosts") as Toml.Array).GetArrayType(); 82 | } 83 | 84 | /// 85 | /// was used while testing the new parser 86 | /// 87 | static void TestParser() 88 | { 89 | var exampleDoc = Toml.Document.Create(".\\TestFiles\\example.toml"); 90 | Console.WriteLine(exampleDoc); 91 | 92 | var server_alpha_dc = exampleDoc.GetFieldValue("servers.alpha.dc"); 93 | var database_connection_max = exampleDoc.GetFieldValue("database.connection_max"); 94 | string owner_bio = exampleDoc.GetFieldValue("owner.bio"); 95 | 96 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // 97 | var testDataDoc = Toml.Document.Create(".\\TestFiles\\TestData.toml"); 98 | Console.WriteLine(testDataDoc); 99 | 100 | var dob = testDataDoc.GetFieldValue("dob"); 101 | var multiLineTest = testDataDoc.GetFieldValue("multi_line_test"); 102 | var aNewArray = testDataDoc.GetFieldValue("aNewArray"); 103 | var filePath = testDataDoc.GetFieldValue("base_path"); 104 | 105 | var multiArray = testDataDoc.GetArrayValue("database.port_ips"); 106 | 107 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // 108 | var hardExampleDoc = Toml.Document.Create(".\\TestFiles\\hard_example.toml"); 109 | Console.WriteLine(hardExampleDoc); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Asset/Asset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace OrcaCore 8 | { 9 | public class Asset 10 | { 11 | public static Func PrefabUnInstantiateRule; 12 | 13 | private MemoryPool mObjectPool = new MemoryPool(); 14 | private UnityEngine.Object mObject; 15 | private string mName; 16 | public string Name { get { return mName; } } 17 | public int Reference { set; get; } 18 | public bool HasNoReference { get { return Reference <= 0; } } 19 | public bool AssetValid { get { return mObject != null; } } 20 | private Action mObjectCallback; 21 | 22 | public void AddCallback(Action callback) 23 | { 24 | mObjectCallback -= callback; 25 | mObjectCallback += callback; 26 | } 27 | public void ReleaseCallback(Action callback) 28 | { 29 | mObjectCallback -= callback; 30 | } 31 | 32 | public static Asset CreateInstance(string name) 33 | { 34 | Asset asset = new Asset(); 35 | asset.mName = name; 36 | return asset; 37 | } 38 | 39 | public void OnAssetLoad( string name, UnityEngine.Object obj ) 40 | { 41 | if( name.Contains("nvTD")) 42 | { 43 | Debug.LogError("OnAssetLoad " + name); 44 | } 45 | mObject = obj; 46 | if( mObjectCallback != null) 47 | { 48 | if (name.Contains("nvTD")) 49 | { 50 | Debug.LogError("OnAssetLoad callback " + name); 51 | } 52 | mObjectCallback(mName, GetObject()); 53 | } 54 | } 55 | 56 | public UnityEngine.Object GetObject() 57 | { 58 | if (AssetValid) 59 | { 60 | Reference++; 61 | UnityEngine.Object obj = mObjectPool.Alloc(); 62 | if (obj != null) 63 | { 64 | if (obj is GameObject) 65 | { 66 | (obj as GameObject).SetActive(true); 67 | } 68 | return obj; 69 | } 70 | else 71 | { 72 | return InstanceAsset(mObject, mName); 73 | } 74 | } 75 | else 76 | { 77 | return null; 78 | } 79 | } 80 | public static UnityEngine.Object InstanceAsset(UnityEngine.Object obj, string name) 81 | { 82 | if (name.IndexOf(".exr") >= 0) 83 | { 84 | return obj; 85 | } 86 | if (needInstance(obj)) 87 | { 88 | return GameObject.Instantiate(obj); 89 | } 90 | return obj; 91 | } 92 | 93 | /// 94 | /// 判定是否需要实例化 95 | /// 96 | /// 97 | /// 98 | private static bool needInstance(UnityEngine.Object obj) 99 | { 100 | if (obj is GameObject) 101 | { 102 | if (PrefabUnInstantiateRule != null && PrefabUnInstantiateRule(obj as GameObject)) 103 | { 104 | return false; 105 | } 106 | return true; 107 | } 108 | return false; 109 | } 110 | 111 | public void ReleaseAssetReference(UnityEngine.Object obj) 112 | { 113 | Reference--; 114 | if (obj is GameObject) 115 | { 116 | (obj as GameObject).SetActive(false); 117 | (obj as GameObject).transform.parent = null; 118 | } 119 | if (needInstance(obj)) 120 | { 121 | if (mObjectPool.Free(obj)) 122 | { 123 | return; 124 | } 125 | UnityEngine.Object.Destroy(obj); 126 | } 127 | } 128 | 129 | public bool CanRelease() 130 | { 131 | if (mObject == null) 132 | { 133 | return true; 134 | } 135 | if (mObject is TextAsset || mObject is Font) 136 | { 137 | return false; 138 | } 139 | return true; 140 | } 141 | 142 | public void ReleaseAsset(bool includeSelf) 143 | { 144 | mObjectCallback = null; 145 | while (true) 146 | { 147 | UnityEngine.Object obj = mObjectPool.Alloc(); 148 | if (obj != null) 149 | { 150 | UnityEngine.Object.Destroy(obj); 151 | } 152 | else 153 | { 154 | break; 155 | } 156 | } 157 | if (includeSelf) 158 | { 159 | if (mObject != null) 160 | { 161 | GameObject.DestroyImmediate(mObject, true); 162 | } 163 | mObjectPool.Dispose(); 164 | mObject = null; 165 | } 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /Assets/Core/Res/NextRes/Maps/BundleMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using UnityEngine; 7 | 8 | namespace OrcaCore 9 | { 10 | public class BundleInfo 11 | { 12 | public string Md5Name { set; get; } 13 | public int Size { set; get; } 14 | public string Md5 { set; get; } 15 | public HashSet AssetFiles { set; get; } 16 | public HashSet DependsOn { set; get; } 17 | public string FirstAsset { set; get; } 18 | } 19 | public class BundleMap 20 | { 21 | private static BundleMap _instance; 22 | public static BundleMap Instance 23 | { 24 | get 25 | { 26 | if (_instance == null) 27 | { 28 | _instance = new BundleMap(); 29 | } 30 | return _instance; 31 | } 32 | } 33 | 34 | const string BUNDLE_INFO_PREFIX = "&BundleInfo%"; 35 | const char splitchar = ':'; 36 | private Dictionary mDicBundleMap = new Dictionary(); 37 | 38 | public int GetSize(string name) 39 | { 40 | int size = 0; 41 | BundleInfo bi = GetBundleInfo(name); 42 | if (bi != null) 43 | { 44 | size = bi.Size; 45 | } 46 | else 47 | { 48 | Debug.LogError(name + " is not in bundle map"); 49 | } 50 | return size; 51 | } 52 | 53 | public string GetMd5Name(string name) 54 | { 55 | string md5name = string.Empty; 56 | BundleInfo bi = GetBundleInfo(name); 57 | if (bi != null) 58 | { 59 | md5name = bi.Md5Name; 60 | } 61 | else 62 | { 63 | Debug.LogError(name + " is not in bundle map"); 64 | } 65 | return md5name; 66 | } 67 | 68 | public string[] GetDependence(string name) 69 | { 70 | BundleInfo bi; 71 | if (!mDicBundleMap.TryGetValue(name, out bi)) 72 | { 73 | return new string[0]; 74 | } 75 | else 76 | { 77 | return bi.DependsOn.ToArray(); 78 | } 79 | } 80 | 81 | private BundleInfo GetBundleInfo(string name) 82 | { 83 | BundleInfo bi; 84 | if (!mDicBundleMap.TryGetValue(name, out bi)) 85 | { 86 | return null; 87 | } 88 | else 89 | { 90 | return bi; 91 | } 92 | } 93 | 94 | public void Read( string stream) 95 | { 96 | mDicBundleMap.Clear(); 97 | 98 | StringReader sr = new StringReader(stream); 99 | string line = sr.ReadLine(); 100 | while (null != line) 101 | { 102 | if (line.StartsWith(BUNDLE_INFO_PREFIX)) 103 | { 104 | byte[] buf = Convert.FromBase64String(line.Substring(BUNDLE_INFO_PREFIX.Length + 1)); 105 | MemoryStream ms = new MemoryStream(buf); 106 | BinaryReader br = new BinaryReader(ms); 107 | 108 | int bundleCnt = br.ReadInt32(); 109 | for (int i = 0; i < bundleCnt; i++) 110 | { 111 | string name = br.ReadString(); 112 | int size = br.ReadInt32(); 113 | int assetCnt = br.ReadInt32(); 114 | HashSet assets = new HashSet(); 115 | string firstAsset = null; 116 | for (int j = 0; j < assetCnt; j++) 117 | { 118 | string assetName = br.ReadString(); 119 | assets.Add(assetName); 120 | if (firstAsset == null) 121 | { 122 | firstAsset = assetName; 123 | } 124 | AssetMap.Instance.RegAssetIndex(assetName, name); 125 | } 126 | BundleInfo bi = GetBundleInfo(name); 127 | if( bi != null) 128 | { 129 | bi.AssetFiles = assets; 130 | bi.FirstAsset = firstAsset; 131 | int dependCnt = br.ReadInt32(); 132 | HashSet depends = new HashSet(); 133 | for (int j = 0; j < dependCnt; j++) 134 | { 135 | string depName = br.ReadString(); 136 | depends.Add(depName); 137 | } 138 | bi.DependsOn = depends; 139 | } 140 | } 141 | } 142 | else 143 | { 144 | string[] strs = OrcaCore.JsonUtil.StringToStringArray(line, splitchar); 145 | string name = strs[0]; 146 | BundleInfo bi = GetBundleInfo(name); 147 | if( bi == null) 148 | { 149 | bi = new BundleInfo(); 150 | mDicBundleMap.Add(name, bi); 151 | } 152 | bi.Md5Name = strs[1]; 153 | bi.Size = int.Parse(strs[2]); 154 | bi.Md5 = strs[3]; 155 | } 156 | line = sr.ReadLine(); 157 | } 158 | } 159 | 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/JsonUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using fastJSON; 7 | using System.Reflection; 8 | 9 | namespace OrcaCore 10 | { 11 | public class JsonUtil 12 | { 13 | public static void InitJson() 14 | { 15 | JSON.RegisterCustomType(typeof(UnityEngine.Vector3), Vector3Json.SerilizeVector3, Vector3Json.DserializeVector3); 16 | JSON.RegisterCustomType(typeof(UnityEngine.Quaternion), QuaternionJson.SerilizeQuaternion, QuaternionJson.DserializeQuaternion); 17 | JSON.RegisterCustomType(typeof(UnityEngine.Rect), JsonCustom.SerilizeRect, JsonCustom.DserializeRect); 18 | } 19 | public static PropertyInfo[] GetProperties(object obj) 20 | { 21 | Type t = obj.GetType(); 22 | return t.GetProperties(); 23 | } 24 | public static Type GetPropertyType(object obj, string proName) 25 | { 26 | Type t = obj.GetType(); 27 | foreach (System.Reflection.FieldInfo p in t.GetFields()) 28 | { 29 | if (p.Name == proName) 30 | return p.FieldType; 31 | } 32 | 33 | return null; 34 | } 35 | 36 | public static string[] StringToStringArray(string s, char splitchar) 37 | { 38 | if (s.Length == 0) 39 | return new string[] { }; 40 | string[] sa = s.Split(splitchar); 41 | return sa; 42 | } 43 | public static string[] StringToStringArray(string s) 44 | { 45 | return StringToStringArray(s, '|'); 46 | } 47 | public static string StringArrayToString(string[] sa) 48 | { 49 | string s = ""; 50 | for (int i = 0; i < sa.Length; i++) 51 | { 52 | string str = sa[i]; 53 | s += str; 54 | if (i < sa.Length - 1) 55 | s += "|"; 56 | } 57 | return s; 58 | } 59 | 60 | public static string ArrayToString(T[] sa) 61 | { 62 | if (sa == null) 63 | return ""; 64 | string s = ""; 65 | for (int i = 0; i < sa.Length; i++) 66 | { 67 | string str = sa[i].ToString(); 68 | s += str; 69 | if (i < sa.Length - 1) 70 | s += ","; 71 | } 72 | return s; 73 | } 74 | 75 | public static T[] StringToArray(string s, char splitchar = ',', int precision = 2) 76 | { 77 | if (s.Length == 0) 78 | return new T[] { }; 79 | string[] sa = s.Split(splitchar); 80 | List fl = new List(); 81 | foreach (string str in sa) 82 | { 83 | object f; 84 | if(typeof(T) == typeof(float)) 85 | { 86 | f = (float)Math.Round(float.Parse(str), precision); 87 | } 88 | else if (typeof(T) == typeof(double)) 89 | { 90 | f = Math.Round(float.Parse(str), precision); 91 | } 92 | else if(typeof(T) == typeof(int)) 93 | { 94 | f = int.Parse(str); 95 | } 96 | else 97 | { 98 | f = str; 99 | } 100 | 101 | fl.Add((T)f); 102 | } 103 | return fl.ToArray(); 104 | } 105 | 106 | //工具函数// 107 | public static void SaveText(string str, string textFilePath) 108 | { 109 | FileStream fileStream = new FileStream(textFilePath, FileMode.Create); 110 | StreamWriter writer = new StreamWriter(fileStream); 111 | writer.Write(str); 112 | writer.Flush(); 113 | writer.Close(); 114 | fileStream.Close(); 115 | } 116 | public static string ReadText(string textFilePath) 117 | { 118 | if (!File.Exists(textFilePath)) 119 | return string.Empty; 120 | FileStream fileStream = new FileStream(textFilePath, FileMode.Open); 121 | StreamReader reader = new StreamReader(fileStream); 122 | string buf = reader.ReadToEnd(); 123 | reader.Close(); 124 | fileStream.Close(); 125 | return buf; 126 | } 127 | public static object ReadJsonObject(string path) 128 | { 129 | //读文件// 130 | string buf = JsonUtil.ReadText(path); 131 | return JSON.ToObject(buf); 132 | } 133 | 134 | public static object ConvertData(string data, Type type) 135 | { 136 | if (type == typeof(string)) 137 | return data; 138 | else 139 | { 140 | if (data == string.Empty) 141 | return null; 142 | if (type == typeof(int)) 143 | return int.Parse(data); 144 | else if (type == typeof(short)) 145 | return short.Parse(data); 146 | else if (type == typeof(float)) 147 | return float.Parse(data); 148 | else if (type == typeof(string[])) 149 | return JsonUtil.StringToStringArray(data); 150 | else if (type == typeof(float[])) 151 | return JsonUtil.StringToArray(data); 152 | else if (type == typeof(int[])) 153 | return JsonUtil.StringToArray(data); 154 | else if (type == typeof(double)) 155 | return double.Parse(data); 156 | else if (type == typeof(bool)) 157 | { 158 | if (data == "0" || data.ToLower() == "false" || data == string.Empty) 159 | return false; 160 | else 161 | return true; 162 | } 163 | else 164 | return data; 165 | } 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /Assets/Core/Utils/SysUtil.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Text; 4 | using System.Security.Cryptography; 5 | using System.IO; 6 | 7 | namespace OrcaCore 8 | { 9 | static class SysUtil 10 | { 11 | public static bool isDebug = true; 12 | 13 | public static string CreateGUID() 14 | { 15 | return Guid.NewGuid().ToString("N"); 16 | } 17 | 18 | public static void DebugBreak() 19 | { 20 | if (isDebug) 21 | Debug.Break(); 22 | } 23 | 24 | public static void Assert(bool val, string msg) 25 | { 26 | if (isDebug && !val) 27 | { 28 | Debug.Log("assert failed:\n" + msg); 29 | Debug.Break(); 30 | } 31 | } 32 | 33 | public static int MilliSecToFps(long time) 34 | { 35 | return 1000 / (int)time; 36 | } 37 | 38 | public static long FpsToMilliSec(int fps) 39 | { 40 | return 1000 / fps; 41 | } 42 | 43 | public static long TickToMilliSec(long tick) 44 | { 45 | return tick / (10 * 1000); 46 | } 47 | 48 | public static long MilliSecToTick(long time) 49 | { 50 | return time * 10 * 1000; 51 | } 52 | 53 | public static float MilliSecToSec(long ms) 54 | { 55 | return ((float)ms) / 1000; 56 | } 57 | 58 | public static long SecToMilliSec(float s) 59 | { 60 | return (long)(s * 1000); 61 | } 62 | 63 | public static string GetAddr(string ip, int port) 64 | { 65 | return ip + ":" + port; 66 | } 67 | 68 | public static string GetMD5Str(string str) 69 | { 70 | MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); 71 | byte[] encryptedBytes = md5.ComputeHash(Encoding.ASCII.GetBytes(str)); 72 | StringBuilder sb = new StringBuilder(); 73 | for (int i = 0; i < encryptedBytes.Length; i++) 74 | { 75 | sb.AppendFormat("{0:x2}", encryptedBytes[i]); 76 | } 77 | return sb.ToString(); 78 | } 79 | 80 | public static string GetMD5Str(Stream stream) 81 | { 82 | MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); 83 | byte[] encryptedBytes = md5.ComputeHash(stream); 84 | StringBuilder sb = new StringBuilder(); 85 | for (int i = 0; i < encryptedBytes.Length; i++) 86 | { 87 | sb.AppendFormat("{0:x2}", encryptedBytes[i]); 88 | } 89 | return sb.ToString(); 90 | } 91 | 92 | public static void DrawDebugBounds(Bounds bound, Matrix4x4 mtx, Color col) 93 | { 94 | if (isDebug) 95 | { 96 | Vector3 src = Vector3.zero; 97 | Vector3 dst = Vector3.zero; 98 | 99 | //bottom 100 | src.x = bound.min.x; 101 | src.y = bound.min.y; 102 | src.z = bound.min.z; 103 | dst.x = bound.max.x; 104 | dst.y = bound.min.y; 105 | dst.z = bound.min.z; 106 | src = mtx.MultiplyPoint(src); 107 | dst = mtx.MultiplyPoint(dst); 108 | UnityEngine.Debug.DrawLine(src, dst, col); 109 | 110 | src.x = bound.min.x; 111 | src.y = bound.min.y; 112 | src.z = bound.min.z; 113 | dst.x = bound.min.x; 114 | dst.y = bound.min.y; 115 | dst.z = bound.max.z; 116 | src = mtx.MultiplyPoint(src); 117 | dst = mtx.MultiplyPoint(dst); 118 | UnityEngine.Debug.DrawLine(src, dst, col); 119 | 120 | src.x = bound.max.x; 121 | src.y = bound.min.y; 122 | src.z = bound.max.z; 123 | dst.x = bound.max.x; 124 | dst.y = bound.min.y; 125 | dst.z = bound.min.z; 126 | src = mtx.MultiplyPoint(src); 127 | dst = mtx.MultiplyPoint(dst); 128 | UnityEngine.Debug.DrawLine(src, dst, col); 129 | 130 | src.x = bound.max.x; 131 | src.y = bound.min.y; 132 | src.z = bound.max.z; 133 | dst.x = bound.min.x; 134 | dst.y = bound.min.y; 135 | dst.z = bound.max.z; 136 | src = mtx.MultiplyPoint(src); 137 | dst = mtx.MultiplyPoint(dst); 138 | UnityEngine.Debug.DrawLine(src, dst, col); 139 | 140 | //top 141 | src.x = bound.max.x; 142 | src.y = bound.max.y; 143 | src.z = bound.max.z; 144 | dst.x = bound.max.x; 145 | dst.y = bound.max.y; 146 | dst.z = bound.min.z; 147 | src = mtx.MultiplyPoint(src); 148 | dst = mtx.MultiplyPoint(dst); 149 | UnityEngine.Debug.DrawLine(src, dst, col); 150 | 151 | src.x = bound.max.x; 152 | src.y = bound.max.y; 153 | src.z = bound.max.z; 154 | dst.x = bound.min.x; 155 | dst.y = bound.max.y; 156 | dst.z = bound.max.z; 157 | src = mtx.MultiplyPoint(src); 158 | dst = mtx.MultiplyPoint(dst); 159 | UnityEngine.Debug.DrawLine(src, dst, col); 160 | 161 | src.x = bound.min.x; 162 | src.y = bound.max.y; 163 | src.z = bound.min.z; 164 | dst.x = bound.max.x; 165 | dst.y = bound.max.y; 166 | dst.z = bound.min.z; 167 | src = mtx.MultiplyPoint(src); 168 | dst = mtx.MultiplyPoint(dst); 169 | UnityEngine.Debug.DrawLine(src, dst, col); 170 | 171 | src.x = bound.min.x; 172 | src.y = bound.max.y; 173 | src.z = bound.min.z; 174 | dst.x = bound.min.x; 175 | dst.y = bound.max.y; 176 | dst.z = bound.max.z; 177 | src = mtx.MultiplyPoint(src); 178 | dst = mtx.MultiplyPoint(dst); 179 | UnityEngine.Debug.DrawLine(src, dst, col); 180 | 181 | //side 182 | src.x = bound.min.x; 183 | src.y = bound.min.y; 184 | src.z = bound.min.z; 185 | dst.x = bound.min.x; 186 | dst.y = bound.max.y; 187 | dst.z = bound.min.z; 188 | src = mtx.MultiplyPoint(src); 189 | dst = mtx.MultiplyPoint(dst); 190 | UnityEngine.Debug.DrawLine(src, dst, col); 191 | 192 | src.x = bound.max.x; 193 | src.y = bound.min.y; 194 | src.z = bound.min.z; 195 | dst.x = bound.max.x; 196 | dst.y = bound.max.y; 197 | dst.z = bound.min.z; 198 | src = mtx.MultiplyPoint(src); 199 | dst = mtx.MultiplyPoint(dst); 200 | UnityEngine.Debug.DrawLine(src, dst, col); 201 | 202 | src.x = bound.max.x; 203 | src.y = bound.max.y; 204 | src.z = bound.max.z; 205 | dst.x = bound.max.x; 206 | dst.y = bound.min.y; 207 | dst.z = bound.max.z; 208 | src = mtx.MultiplyPoint(src); 209 | dst = mtx.MultiplyPoint(dst); 210 | UnityEngine.Debug.DrawLine(src, dst, col); 211 | 212 | src.x = bound.min.x; 213 | src.y = bound.min.y; 214 | src.z = bound.max.z; 215 | dst.x = bound.min.x; 216 | dst.y = bound.max.y; 217 | dst.z = bound.max.z; 218 | src = mtx.MultiplyPoint(src); 219 | dst = mtx.MultiplyPoint(dst); 220 | UnityEngine.Debug.DrawLine(src, dst, col); 221 | } 222 | } 223 | 224 | public static KeyCode TransKeyToKeyCode(int key) 225 | { 226 | return (KeyCode)key; 227 | } 228 | 229 | public static int TransKeyCodeToKey(KeyCode code) 230 | { 231 | return (int)code; 232 | } 233 | 234 | //lower str, then rm all space 235 | public static string GetPureStr(string txt) 236 | { 237 | string pt = txt.ToLower(); 238 | pt = pt.Trim(); 239 | pt = pt.Replace('\t', '_'); 240 | pt = pt.Replace(' ', '_'); 241 | pt = pt.Replace('-', '_'); 242 | return pt; 243 | } 244 | 245 | public static bool StrPureEqual(string txt1, string txt2) 246 | { 247 | string pt1 = GetPureStr(txt1); 248 | string pt2 = GetPureStr(txt2); 249 | return pt1 == pt2; 250 | } 251 | 252 | public static bool DetectEnterKeyInStr(string str) 253 | { 254 | if (str == null || str == string.Empty) return false; 255 | 256 | return str[str.Length - 1] == '\n'; 257 | } 258 | 259 | public static string RmEnterKeyInStr(string str) 260 | { 261 | if (str == null || str == string.Empty) return str; 262 | 263 | string nStr = str; 264 | while (nStr.Length > 0) 265 | { 266 | if (nStr[nStr.Length - 1] == '\n' || nStr[nStr.Length - 1] == '\r') 267 | nStr = nStr.Remove(nStr.Length - 1); 268 | else 269 | break; 270 | } 271 | 272 | return nStr; 273 | } 274 | 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Serializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | //using System.Threading.Tasks; 8 | 9 | namespace Toml 10 | { 11 | public class Serializer 12 | { 13 | /// 14 | /// Defines the types that can be serialized directly, without recursion. 15 | /// 16 | private static readonly Dictionary> NativeTypes = new Dictionary>() 17 | { 18 | { typeof(bool), (val) => val.ToString() }, 19 | 20 | { typeof(SByte), (val) => val.ToString() }, 21 | { typeof(Byte), (val) => val.ToString() }, 22 | { typeof(Int16), (val) => val.ToString() }, 23 | { typeof(UInt16), (val) => val.ToString() }, 24 | { typeof(Int32), (val) => val.ToString() }, 25 | { typeof(UInt32), (val) => val.ToString() }, 26 | 27 | { typeof(float), (val) => val.ToString() }, 28 | { typeof(double), (val) => val.ToString() }, 29 | 30 | { typeof(string), (val) => EscapeAndQuoteString((string)val) }, 31 | { typeof(DateTime), (val) => val.ToString() }, 32 | 33 | // add by xl1991 for unity3d 34 | {typeof(UnityEngine.Vector3), (val) => { UnityEngine.Vector3 v = (UnityEngine.Vector3)val; return Orca.OrcaUtil.Vec32String(v); } }, 35 | {typeof(UnityEngine.Rect), (val) => { UnityEngine.Rect v = (UnityEngine.Rect)val; return Orca.OrcaUtil.Rect2String(v); } } 36 | 37 | }; 38 | 39 | /// 40 | /// Serializes the specified object to the StreamWriter, using the specified rootKeyGroup as the groupName 41 | /// for the values. 42 | /// 43 | /// The type of object to serialize. 44 | /// The value of the object to serialize. 45 | /// The key group to use to serialize the object. 46 | /// The StreamWriter to write with. 47 | public static void Write(T value, string rootKeyGroup, StreamWriter writer) 48 | { 49 | Serialize(typeof(T), value, rootKeyGroup, writer); 50 | } 51 | 52 | private static void Serialize(Type type, object value, string keyGroup, StreamWriter writer) 53 | { 54 | //if (!string.IsNullOrWhiteSpace(keyGroup)) 55 | if( !string.IsNullOrEmpty(keyGroup) && keyGroup.Trim().Length != 0) 56 | { 57 | keyGroup = keyGroup.TrimStart(Toml.Parser.Tokens.KeyStart) 58 | .TrimEnd(Toml.Parser.Tokens.KeyEnd) 59 | .Trim(Toml.Parser.Tokens.KeySeparator); 60 | 61 | writer.WriteLine("{0}{1}{2}", Toml.Parser.Tokens.KeyStart, keyGroup, Toml.Parser.Tokens.KeyEnd); 62 | } 63 | 64 | var properties = type.GetProperties() 65 | .Where(p => p.CanRead) 66 | .Where 67 | ( 68 | p => !((p.GetCustomAttributes(typeof(NonSerializedAttribute), true)).Any()) 69 | ); 70 | //.Where 71 | //( 72 | // p => (p.GetCustomAttributes(typeof(Orca.OrcaParamAttribute), true).Any() || 73 | // p.GetCustomAttributes(typeof(Orca.OrcaParamAttribute), true).Any()) 74 | // ); 75 | 76 | WriteNativeProperties(properties, value, writer); 77 | WriteArrayProperties(properties, value, writer); 78 | WriteComplexProperties(properties, value, keyGroup, writer); 79 | return; 80 | } 81 | 82 | /// 83 | /// Writes the native properties to the stream. 84 | /// 85 | private static bool WriteNativeProperties(IEnumerable properties, object owner, StreamWriter writer) 86 | { 87 | var nativeProperties = properties.Where(p => Serializer.IsNativeType(p.PropertyType)); 88 | return nativeProperties.Select 89 | ( 90 | p => string.Format 91 | ( 92 | "{0} {1} {2}", 93 | p.Name, 94 | Toml.Parser.Tokens.ValueSeparator, 95 | GetNativeValueString(p.PropertyType, p.GetValue(owner, null)) 96 | ) 97 | ) 98 | .Select(ps => { writer.WriteLine(ps); return true; }) 99 | .All(ps => ps); 100 | } 101 | 102 | /// 103 | /// Writes properties of complex types. 104 | /// 105 | private static bool WriteComplexProperties(IEnumerable properties, object owner, string keyGroup, StreamWriter writer) 106 | { 107 | var complexProperties = properties.Where 108 | ( 109 | p => !Serializer.IsNativeType(p.PropertyType) && !IsArrayType(p.PropertyType, p.GetValue(owner, null)) 110 | ); 111 | 112 | return complexProperties 113 | .Select 114 | ( 115 | p => 116 | { 117 | var val = p.GetValue(owner, null); 118 | if (val != null) 119 | { 120 | writer.WriteLine(); 121 | Serialize(p.PropertyType, val, keyGroup + Toml.Parser.Tokens.KeySeparator + p.Name, writer); 122 | return true; 123 | } 124 | 125 | return true; 126 | } 127 | ).All(p => p); 128 | } 129 | 130 | /// 131 | /// Write the values of the arrays to the stream. 132 | /// 133 | /// The arrays to be written. 134 | /// The value that owns the arrays. 135 | /// The StreamWriter to write the array values to. 136 | private static bool WriteArrayProperties(IEnumerable properties, object owner, StreamWriter writer) 137 | { 138 | var arrayProperties = properties.Where(p => IsArrayType(p.PropertyType, p.GetValue(owner, null))); 139 | foreach (var arrayProp in arrayProperties) 140 | { 141 | var arrayVal = (System.Collections.IEnumerable)arrayProp.GetValue(owner, null); 142 | var elementType = arrayProp.PropertyType.GetElementType(); 143 | 144 | if (IsArrayType(elementType, arrayVal)) 145 | { 146 | continue; 147 | } 148 | 149 | if (!IsNativeType(elementType)) 150 | { 151 | throw new InvalidOperationException("Cannot Serialize Complex Types in an array"); 152 | } 153 | 154 | bool isFirstEntry = true; 155 | 156 | writer.Write("{0} {1} {2}", arrayProp.Name, Toml.Parser.Tokens.ValueSeparator, Toml.Parser.Tokens.ArrayStart); 157 | foreach (var entry in arrayVal) 158 | { 159 | if (!isFirstEntry) 160 | { 161 | writer.Write("{0} {1}", Toml.Parser.Tokens.ArraySeparator, GetNativeValueString(elementType, entry)); 162 | } 163 | else 164 | { 165 | writer.Write("{0}", GetNativeValueString(elementType, entry)); 166 | isFirstEntry = false; 167 | } 168 | } 169 | 170 | writer.WriteLine(Toml.Parser.Tokens.ArrayEnd); 171 | } 172 | 173 | return true; 174 | } 175 | 176 | /// 177 | /// Indicates whether the specified type can be serialized as a native Toml Type. 178 | /// 179 | /// The type to check. 180 | /// true if the type can be serialized as a native Toml Type, otherwise false. 181 | private static bool IsNativeType(Type type) 182 | { 183 | return NativeTypes.Any(kv => kv.Key == type); 184 | } 185 | 186 | /// 187 | /// Indicates whether or not the value of the specified type should be serialized as an array. 188 | /// 189 | private static bool IsArrayType(Type type, object value) 190 | { 191 | // we need to make sure strings don't get written as arrays 192 | if (IsNativeType(type)) 193 | { 194 | return false; 195 | } 196 | 197 | return ((value != null) && (type.IsArray || (typeof(System.Collections.IEnumerable).IsInstanceOfType(value)))); 198 | } 199 | 200 | /// 201 | /// Gets the string to use when writing a native type value. 202 | /// 203 | /// 204 | /// 205 | /// 206 | private static string GetNativeValueString(Type valueType, object value) 207 | { 208 | return NativeTypes.Where(kv => kv.Key == valueType) 209 | .Select(kv => kv.Value(value)).First(); 210 | } 211 | 212 | /// 213 | /// Wraps a string in quotes and adds an escape char before any escapable charaters. 214 | /// 215 | private static string EscapeAndQuoteString(string value) 216 | { 217 | return "\"" 218 | + value.Replace("\\", "\\\\") 219 | .Replace("\"", "\\\"") 220 | .Replace("\r", "\\\r") 221 | .Replace("\n", "\\\n") 222 | .Replace("\f", "\\\f") 223 | .Replace("\t", "\\\t") 224 | + "\""; 225 | } 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/TypeParsers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | //using System.Threading.Tasks; 6 | 7 | namespace Toml 8 | { 9 | public static class TypeParsers 10 | { 11 | /// 12 | /// Represents the base ParseResult instance. 13 | /// 14 | private class ParseResultBase 15 | { 16 | /// 17 | /// Initializes a new instance of the ParseResultBase class. 18 | /// 19 | /// The exception that occurred while parsing the value. 20 | public ParseResultBase(Exception error) 21 | { 22 | this.Success = false; 23 | this.Error = error; 24 | } 25 | 26 | /// 27 | /// Initializes a new instance of the ParseResultBase class. 28 | /// 29 | public ParseResultBase() 30 | { 31 | this.Success = true; 32 | } 33 | 34 | /// 35 | /// Indicates whether or not the parsing succeeded. 36 | /// 37 | public bool Success { get; private set; } 38 | 39 | /// 40 | /// Gets the exception that occurred while parsing the value. 41 | /// 42 | public Exception Error { get; private set; } 43 | } 44 | 45 | /// 46 | /// Represents the result of a parse attempt. 47 | /// 48 | /// The type of object being parsed. 49 | private class ParseResult : ParseResultBase 50 | { 51 | /// 52 | /// The parsed value, if any. 53 | /// 54 | private T _value; 55 | 56 | /// 57 | /// Initializes a new instance of the ParseResult class. 58 | /// 59 | /// The exception that occurred while parsing the value. 60 | public ParseResult(Exception error) 61 | : base(error) 62 | { 63 | this.Value = default(T); 64 | } 65 | 66 | /// 67 | /// Initializes a new instance of the ParseResult class. 68 | /// 69 | /// The parsed value. 70 | public ParseResult(T value) 71 | : base() 72 | { 73 | this.Value = value; 74 | } 75 | 76 | /// 77 | /// Gets the value generated by the parser 78 | /// 79 | public T Value 80 | { 81 | get 82 | { 83 | if (!this.Success) 84 | { 85 | throw this.Error; 86 | } 87 | 88 | return _value; 89 | } 90 | private set 91 | { 92 | _value = value; 93 | } 94 | } 95 | } 96 | 97 | /// 98 | /// Stores the registered type parsers. 99 | /// 100 | private static Dictionary> ParserFuncs = RegisterParsers(); 101 | 102 | /// 103 | /// Registers the supported type parsers. 104 | /// 105 | /// 106 | private static Dictionary> RegisterParsers() 107 | { 108 | var parsers = new Dictionary>(); 109 | 110 | parsers.Add(typeof(Int32), ParseInt32); 111 | parsers.Add(typeof(Int64), ParseInt64); 112 | parsers.Add(typeof(UInt32), ParseUInt32); 113 | parsers.Add(typeof(UInt64), ParseUInt64); 114 | parsers.Add(typeof(float), ParseFloat); 115 | parsers.Add(typeof(double), ParseDouble); 116 | parsers.Add(typeof(DateTime), ParseDateTime); 117 | parsers.Add(typeof(string), ParseString); 118 | 119 | // add by xl1991 for unity3d 120 | parsers.Add(typeof(UnityEngine.Vector3), ParseVector3); 121 | parsers.Add(typeof(UnityEngine.Rect), ParseRect); 122 | 123 | return parsers; 124 | } 125 | 126 | #region Parse Funcs 127 | 128 | /// 129 | /// Parses an Int32 value. 130 | /// 131 | private static ParseResult ParseInt32(string value) 132 | { 133 | try 134 | { 135 | return new ParseResult(Int32.Parse(value)); 136 | } 137 | catch (Exception ex) 138 | { 139 | return new ParseResult(ex); 140 | } 141 | } 142 | 143 | /// 144 | /// Parses an Int64 value. 145 | /// 146 | private static ParseResult ParseInt64(string value) 147 | { 148 | try 149 | { 150 | return new ParseResult(Int64.Parse(value)); 151 | } 152 | catch (Exception ex) 153 | { 154 | return new ParseResult(ex); 155 | } 156 | } 157 | 158 | /// 159 | /// Parses a UInt32 value. 160 | /// 161 | private static ParseResult ParseUInt32(string value) 162 | { 163 | try 164 | { 165 | return new ParseResult(UInt32.Parse(value)); 166 | } 167 | catch (Exception ex) 168 | { 169 | return new ParseResult(ex); 170 | } 171 | } 172 | 173 | /// 174 | /// Parses an UInt64 value. 175 | /// 176 | private static ParseResult ParseUInt64(string value) 177 | { 178 | try 179 | { 180 | return new ParseResult(UInt64.Parse(value)); 181 | } 182 | catch (Exception ex) 183 | { 184 | return new ParseResult(ex); 185 | } 186 | } 187 | 188 | /// 189 | /// Parses a float value. 190 | /// 191 | private static ParseResult ParseFloat(string value) 192 | { 193 | try 194 | { 195 | return new ParseResult(float.Parse(value)); 196 | } 197 | catch (Exception ex) 198 | { 199 | return new ParseResult(ex); 200 | } 201 | } 202 | 203 | /// 204 | /// Parses an double value. 205 | /// 206 | private static ParseResult ParseDouble(string value) 207 | { 208 | try 209 | { 210 | return new ParseResult(double.Parse(value)); 211 | } 212 | catch (Exception ex) 213 | { 214 | return new ParseResult(ex); 215 | } 216 | } 217 | 218 | /// 219 | /// Parses a DateTime value. 220 | /// 221 | private static ParseResult ParseDateTime(string value) 222 | { 223 | try 224 | { 225 | return new ParseResult(DateTime.Parse(value)); 226 | } 227 | catch (Exception ex) 228 | { 229 | return new ParseResult(ex); 230 | } 231 | } 232 | 233 | /// 234 | /// Parses a string value. 235 | /// 236 | private static ParseResult ParseString(string value) 237 | { 238 | return new ParseResult(value); 239 | } 240 | 241 | #endregion 242 | 243 | /// 244 | /// Attempts to parse the given value into the requested type. 245 | /// 246 | public static bool TryParse(string value, out T result) 247 | { 248 | result = default(T); 249 | 250 | Func parser = null; 251 | if (!TypeParsers.ParserFuncs.TryGetValue(typeof(T), out parser)) 252 | { 253 | return false; 254 | } 255 | 256 | var parseResult = parser(value); 257 | if (parseResult is ParseResult) 258 | { 259 | if (parseResult.Success) 260 | { 261 | result = ((ParseResult)parseResult).Value; 262 | return true; 263 | } 264 | } 265 | 266 | return false; 267 | } 268 | 269 | /// 270 | /// Attempts to parse the specified value into the requested type. 271 | /// 272 | public static T Parse(string value) 273 | { 274 | Func parser = null; 275 | if (TypeParsers.ParserFuncs.TryGetValue(typeof(T), out parser)) 276 | { 277 | return ((ParseResult)parser(value)).Value; 278 | } 279 | 280 | if (typeof(T) == typeof(object)) 281 | { 282 | return (T)((object)value); 283 | } 284 | 285 | throw new InvalidOperationException("A parser for the specified type is not registered"); 286 | } 287 | 288 | // TODO: MAKE THIS WORK 289 | //public static object Parse(Type type, string value) 290 | //{ 291 | // Func parser = null; 292 | // if (TypeParsers.ParserFuncs.TryGetValue(type, out parser)) 293 | // { 294 | // var parserResult = typeof(ParseResult<>).MakeGenericType(type); 295 | // return ((parserResult)parser(value)).Value; 296 | // } 297 | 298 | // if (typeof(T) == typeof(object)) 299 | // { 300 | // return (T)((object)value); 301 | // } 302 | 303 | // throw new InvalidOperationException("A parser for the specified type is not registered"); 304 | //} 305 | 306 | private static ParseResult ParseVector3(string value) 307 | { 308 | try 309 | { 310 | return new ParseResult(Orca.OrcaUtil.String2Vec3(value)); 311 | } 312 | catch (Exception ex) 313 | { 314 | return new ParseResult(ex); 315 | } 316 | } 317 | 318 | private static ParseResult ParseRect(string value) 319 | { 320 | try 321 | { 322 | return new ParseResult(Orca.OrcaUtil.String2Rect(value)); 323 | } 324 | catch (Exception ex) 325 | { 326 | return new ParseResult(ex); 327 | } 328 | } 329 | 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Array.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | //using System.Threading.Tasks; 6 | 7 | namespace Toml 8 | { 9 | 10 | /// 11 | /// Represents an array entry 12 | /// 13 | public class Array : Entry 14 | { 15 | public class Dimensions 16 | { 17 | public int Depth { get; set; } 18 | public int Length { get; set; } 19 | } 20 | 21 | /// 22 | /// Array containing one element with a value of 0, used for Min/Max calls 23 | /// that require a non-empty sequence. 24 | /// 25 | private static readonly int[] EnumerableOfZero = new int[] { 0 }; 26 | 27 | #region Constructor 28 | 29 | /// 30 | /// Initializes a new instance of the Entry class. 31 | /// 32 | public Array(string group, string name, int startLineNumber, int startPos) 33 | : base(group, name, string.Empty, startLineNumber, startPos, TomlType.Array) 34 | { 35 | this.Children = new List(); 36 | } 37 | 38 | /// 39 | /// Initializes a new instance of the Entry class. 40 | /// 41 | public Array(Array parent, int startLineNumber, int startPos) 42 | : base(parent, parent.Group, Array.GetEntryName(parent), startLineNumber, startPos, TomlType.Array) 43 | { 44 | this.Children = new List(); 45 | parent.AddEntry(this); 46 | } 47 | 48 | #endregion 49 | 50 | #region Properties 51 | 52 | /// 53 | /// Gets the entries owned by this array. 54 | /// 55 | public List Children { get; private set; } 56 | 57 | #endregion 58 | 59 | #region Methods 60 | 61 | /// 62 | /// Gets a name that can be used to identify an array 63 | /// 64 | /// 65 | /// 66 | public static string GetEntryName(Array parent) 67 | { 68 | if (parent == null) 69 | { 70 | System.Diagnostics.Debug.Assert(parent != null); 71 | return string.Empty; 72 | } 73 | 74 | int pos = parent.Children.Count; 75 | return pos.ToString(); 76 | } 77 | 78 | /// 79 | /// Adds an entry to the array. 80 | /// 81 | /// The entry to add to the array. 82 | public void AddEntry(Entry entry) 83 | { 84 | this.Children.Add(entry); 85 | } 86 | 87 | /// 88 | /// Instructs the array to calculate its SourceText property. 89 | /// 90 | /// 91 | /// 92 | /// This is handled outside of the constructor for arrays, because we don't 93 | /// know where the sourceText will end until the array gets closed. 94 | /// 95 | public void UpdateSourceText() 96 | { 97 | this.SourceText = string.Format 98 | ( 99 | "{0}{1}{2}", 100 | Parser.Tokens.ArrayStart, 101 | String.Join(Parser.Tokens.ArraySeparator.ToString(), (this.Children.Select(c => c.SourceText)).ToArray()), 102 | Parser.Tokens.ArrayEnd 103 | ); 104 | } 105 | 106 | /// 107 | /// Gets a string representing the array. 108 | /// 109 | /// A string representing the array entry. 110 | public override string ToString() 111 | { 112 | StringBuilder valueText = new StringBuilder(); 113 | if (this.Parent == null) 114 | { 115 | valueText.AppendFormat("Array {0} = ", this.FullName); 116 | } 117 | 118 | valueText.Append(Parser.Tokens.ArrayStart); 119 | valueText.Append(string.Join(Parser.Tokens.ArraySeparator + " ", (this.Children.Select(c => c.ToString()).ToArray()))); 120 | valueText.Append(Parser.Tokens.ArrayEnd); 121 | 122 | return valueText.ToString(); 123 | } 124 | 125 | /// 126 | /// Gets a type that can be used to represent the array. 127 | /// 128 | /// 129 | public Type GetArrayType() 130 | { 131 | var dimensions = GetDimensions(); 132 | 133 | if (dimensions.Depth == 1) 134 | { 135 | if (dimensions.Length > 0) 136 | { 137 | Type currentType = null; 138 | foreach (var child in this.Children) 139 | { 140 | if (!GetBestType(ref currentType, Array.TomlTypeToNative(child.ParsedType))) 141 | { 142 | return typeof(object).MakeArrayType(); 143 | } 144 | } 145 | 146 | return (currentType == null) ? typeof(object).MakeArrayType() : currentType.MakeArrayType(); 147 | } 148 | 149 | return typeof(object).MakeArrayType(); 150 | } 151 | 152 | if (dimensions.Length > 0) 153 | { 154 | var childTypes = this.Children 155 | .Where(c => c.ParsedType == TomlType.Array) 156 | .Cast() 157 | .Select(ta => ta.GetArrayType()); 158 | 159 | if (childTypes.Count() == 0) 160 | { 161 | return typeof(object).MakeArrayType(); 162 | } 163 | 164 | if (childTypes.All(at => at.Equals(childTypes.First()))) 165 | { 166 | return childTypes.First().MakeArrayType(); 167 | } 168 | } 169 | 170 | return typeof(object).MakeArrayType(); 171 | } 172 | 173 | /// 174 | /// Gets the native type that corresponds to the specified TomlType. 175 | /// 176 | /// The TomlType to find the corresponding Native Type for. 177 | /// A Type that corresponds to the TomlType. 178 | private static Type TomlTypeToNative(TomlType type) 179 | { 180 | switch (type) 181 | { 182 | case TomlType.Int: return typeof(Int64); 183 | case TomlType.Float: return typeof(double); 184 | case TomlType.Boolean: return typeof(bool); 185 | case TomlType.DateTime: return typeof(DateTime); 186 | case TomlType.String: return typeof(string); 187 | default: return typeof(object); 188 | } 189 | } 190 | 191 | /// 192 | /// Used to find the best type for the elements in an array. 193 | /// 194 | /// 195 | /// 196 | /// 197 | private bool GetBestType(ref Type currentType, Type newType) 198 | { 199 | if (newType == typeof(Int64)) 200 | { 201 | if ((currentType == null) || (currentType == typeof(Int64))) 202 | { 203 | currentType = typeof(Int64); 204 | return true; 205 | } 206 | 207 | if (currentType == typeof(double)) 208 | { 209 | currentType = typeof(double); 210 | return true; 211 | } 212 | 213 | return false; 214 | } 215 | if (newType == typeof(double)) 216 | { 217 | if ((currentType == null) || (currentType == typeof(double))) 218 | { 219 | currentType = typeof(double); 220 | return true; 221 | } 222 | 223 | if (currentType == typeof(double)) 224 | { 225 | currentType = typeof(double); 226 | return true; 227 | } 228 | 229 | return false; 230 | } 231 | if (newType == typeof(bool)) 232 | { 233 | if ((currentType == null) || (currentType == typeof(bool))) 234 | { 235 | currentType = typeof(bool); 236 | return true; 237 | } 238 | 239 | if ((currentType == typeof(Int64)) || (currentType == typeof(double)) || (currentType == typeof(string))) 240 | { 241 | return true; 242 | } 243 | return false; 244 | } 245 | if (newType == typeof(DateTime)) 246 | { 247 | if ((currentType == null) || (currentType == typeof(DateTime))) 248 | { 249 | currentType = typeof(DateTime); 250 | return true; 251 | } 252 | 253 | if (currentType == typeof(string)) 254 | { 255 | return true; 256 | } 257 | return false; 258 | } 259 | if (newType == typeof(string)) 260 | { 261 | if ((currentType == typeof(double)) || (currentType == typeof(Int64))) 262 | { 263 | return false; 264 | } 265 | 266 | currentType = typeof(string); 267 | return true; 268 | } 269 | 270 | return false; 271 | } 272 | 273 | /// 274 | /// Gets the max depth and length of the children/child arrays. 275 | /// 276 | /// The depth of the deepest child in the array. 277 | private Array.Dimensions GetDimensions() 278 | { 279 | return new Dimensions() { Depth = GetMaxDepth(), Length = GetMaxLength() }; 280 | } 281 | 282 | /// 283 | /// Gets the deepest child in the array. 284 | /// 285 | /// The depth of the deepest child in the array. 286 | private int GetMaxDepth() 287 | { 288 | return 1 + this.Children 289 | .Where(c => c.ParsedType == TomlType.Array) 290 | .Cast() 291 | .Select(c => c.GetMaxDepth()) 292 | .Concat(Array.EnumerableOfZero) 293 | .Max(); 294 | } 295 | 296 | /// 297 | /// Gets the maximum length of all the child arrays in this array, or the length of this array if it's the longest. 298 | /// 299 | /// 300 | private int GetMaxLength() 301 | { 302 | int maxChildLength = this.Children 303 | .Where(c => c.ParsedType == TomlType.Array) 304 | .Cast() 305 | .Select(c => c.GetMaxDepth()) 306 | .Concat(Array.EnumerableOfZero) 307 | .Max(); 308 | 309 | return this.Children.Count > maxChildLength ? this.Children.Count : maxChildLength; 310 | } 311 | 312 | #endregion 313 | } 314 | } 315 | -------------------------------------------------------------------------------- /Assets/Core/Utils/json/fastJSON/JsonParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Text; 5 | 6 | namespace fastJSON 7 | { 8 | 9 | /// 10 | /// This class encodes and decodes JSON strings. 11 | /// Spec. details, see http://www.json.org/ 12 | /// 13 | internal sealed class JsonParser 14 | { 15 | enum Token 16 | { 17 | None = -1, // Used to denote no Lookahead available 18 | Curly_Open, 19 | Curly_Close, 20 | Squared_Open, 21 | Squared_Close, 22 | Colon, 23 | Comma, 24 | String, 25 | Number, 26 | True, 27 | False, 28 | Null 29 | } 30 | 31 | readonly string json; 32 | readonly StringBuilder s = new StringBuilder(); // used for inner string parsing " \"\r\n\u1234\'\t " 33 | Token lookAheadToken = Token.None; 34 | int index; 35 | 36 | internal JsonParser(string json) 37 | { 38 | this.json = json; 39 | } 40 | 41 | public object Decode() 42 | { 43 | return ParseValue(); 44 | } 45 | 46 | private Dictionary ParseObject() 47 | { 48 | Dictionary table = new Dictionary(); 49 | 50 | ConsumeToken(); // { 51 | 52 | while (true) 53 | { 54 | switch (LookAhead()) 55 | { 56 | 57 | case Token.Comma: 58 | ConsumeToken(); 59 | break; 60 | 61 | case Token.Curly_Close: 62 | ConsumeToken(); 63 | return table; 64 | 65 | default: 66 | { 67 | // name 68 | string name = ParseString(); 69 | 70 | // : 71 | if (NextToken() != Token.Colon) 72 | { 73 | throw new Exception("Expected colon at index " + index); 74 | } 75 | 76 | // value 77 | object value = ParseValue(); 78 | 79 | table[name] = value; 80 | } 81 | break; 82 | } 83 | } 84 | } 85 | 86 | private List ParseArray() 87 | { 88 | List array = new List(); 89 | ConsumeToken(); // [ 90 | 91 | while (true) 92 | { 93 | switch (LookAhead()) 94 | { 95 | case Token.Comma: 96 | ConsumeToken(); 97 | break; 98 | 99 | case Token.Squared_Close: 100 | ConsumeToken(); 101 | return array; 102 | 103 | default: 104 | array.Add(ParseValue()); 105 | break; 106 | } 107 | } 108 | } 109 | 110 | private object ParseValue() 111 | { 112 | switch (LookAhead()) 113 | { 114 | case Token.Number: 115 | return ParseNumber(); 116 | 117 | case Token.String: 118 | return ParseString(); 119 | 120 | case Token.Curly_Open: 121 | return ParseObject(); 122 | 123 | case Token.Squared_Open: 124 | return ParseArray(); 125 | 126 | case Token.True: 127 | ConsumeToken(); 128 | return true; 129 | 130 | case Token.False: 131 | ConsumeToken(); 132 | return false; 133 | 134 | case Token.Null: 135 | ConsumeToken(); 136 | return null; 137 | } 138 | 139 | throw new Exception("Unrecognized token at index" + index); 140 | } 141 | 142 | private string ParseString() 143 | { 144 | ConsumeToken(); // " 145 | 146 | s.Length = 0; 147 | 148 | int runIndex = -1; 149 | int l = json.Length; 150 | //fixed (char* p = json) 151 | string p = json; 152 | { 153 | while (index < l) 154 | { 155 | var c = p[index++]; 156 | 157 | if (c == '"') 158 | { 159 | if (runIndex != -1) 160 | { 161 | if (s.Length == 0) 162 | return json.Substring(runIndex, index - runIndex - 1); 163 | 164 | s.Append(json, runIndex, index - runIndex - 1); 165 | } 166 | return s.ToString(); 167 | } 168 | 169 | if (c != '\\') 170 | { 171 | if (runIndex == -1) 172 | runIndex = index - 1; 173 | 174 | continue; 175 | } 176 | 177 | if (index == l) break; 178 | 179 | if (runIndex != -1) 180 | { 181 | s.Append(json, runIndex, index - runIndex - 1); 182 | runIndex = -1; 183 | } 184 | 185 | switch (p[index++]) 186 | { 187 | case '"': 188 | s.Append('"'); 189 | break; 190 | 191 | case '\\': 192 | s.Append('\\'); 193 | break; 194 | 195 | case '/': 196 | s.Append('/'); 197 | break; 198 | 199 | case 'b': 200 | s.Append('\b'); 201 | break; 202 | 203 | case 'f': 204 | s.Append('\f'); 205 | break; 206 | 207 | case 'n': 208 | s.Append('\n'); 209 | break; 210 | 211 | case 'r': 212 | s.Append('\r'); 213 | break; 214 | 215 | case 't': 216 | s.Append('\t'); 217 | break; 218 | 219 | case 'u': 220 | { 221 | int remainingLength = l - index; 222 | if (remainingLength < 4) break; 223 | 224 | // parse the 32 bit hex into an integer codepoint 225 | uint codePoint = ParseUnicode(p[index], p[index + 1], p[index + 2], p[index + 3]); 226 | s.Append((char)codePoint); 227 | 228 | // skip 4 chars 229 | index += 4; 230 | } 231 | break; 232 | } 233 | } 234 | } 235 | 236 | throw new Exception("Unexpectedly reached end of string"); 237 | } 238 | 239 | private uint ParseSingleChar(char c1, uint multipliyer) 240 | { 241 | uint p1 = 0; 242 | if (c1 >= '0' && c1 <= '9') 243 | p1 = (uint)(c1 - '0') * multipliyer; 244 | else if (c1 >= 'A' && c1 <= 'F') 245 | p1 = (uint)((c1 - 'A') + 10) * multipliyer; 246 | else if (c1 >= 'a' && c1 <= 'f') 247 | p1 = (uint)((c1 - 'a') + 10) * multipliyer; 248 | return p1; 249 | } 250 | 251 | private uint ParseUnicode(char c1, char c2, char c3, char c4) 252 | { 253 | uint p1 = ParseSingleChar(c1, 0x1000); 254 | uint p2 = ParseSingleChar(c2, 0x100); 255 | uint p3 = ParseSingleChar(c3, 0x10); 256 | uint p4 = ParseSingleChar(c4, 1); 257 | 258 | return p1 + p2 + p3 + p4; 259 | } 260 | 261 | private long CreateLong(string s) 262 | { 263 | long num = 0; 264 | bool neg = false; 265 | foreach (char cc in s) 266 | { 267 | if (cc == '-') 268 | neg = true; 269 | else if (cc == '+') 270 | neg = false; 271 | else 272 | { 273 | num *= 10; 274 | num += (int)(cc - '0'); 275 | } 276 | } 277 | 278 | return neg ? -num : num; 279 | } 280 | 281 | private object ParseNumber() 282 | { 283 | ConsumeToken(); 284 | 285 | // Need to start back one place because the first digit is also a token and would have been consumed 286 | var startIndex = index - 1; 287 | bool dec = false; 288 | do 289 | { 290 | if (index == json.Length) 291 | break; 292 | var c = json[index]; 293 | 294 | if ((c >= '0' && c <= '9') || c == '.' || c == '-' || c == '+' || c == 'e' || c == 'E') 295 | { 296 | if (c == '.' || c == 'e' || c == 'E') 297 | dec = true; 298 | if (++index == json.Length) 299 | break;//throw new Exception("Unexpected end of string whilst parsing number"); 300 | continue; 301 | } 302 | break; 303 | } while (true); 304 | 305 | if (dec) 306 | { 307 | string s = json.Substring(startIndex, index - startIndex); 308 | return double.Parse(s, NumberFormatInfo.InvariantInfo); 309 | } 310 | return JSON.CreateLong(json, startIndex, index - startIndex); 311 | } 312 | 313 | private Token LookAhead() 314 | { 315 | if (lookAheadToken != Token.None) return lookAheadToken; 316 | 317 | return lookAheadToken = NextTokenCore(); 318 | } 319 | 320 | private void ConsumeToken() 321 | { 322 | lookAheadToken = Token.None; 323 | } 324 | 325 | private Token NextToken() 326 | { 327 | var result = lookAheadToken != Token.None ? lookAheadToken : NextTokenCore(); 328 | 329 | lookAheadToken = Token.None; 330 | 331 | return result; 332 | } 333 | 334 | private Token NextTokenCore() 335 | { 336 | char c; 337 | 338 | // Skip past whitespace 339 | do 340 | { 341 | c = json[index]; 342 | 343 | if (c == '/' && json[index + 1] == '/') // c++ style single line comments 344 | { 345 | index++; 346 | index++; 347 | do 348 | { 349 | c = json[index]; 350 | if (c == '\r' || c == '\n') break; // read till end of line 351 | } 352 | while (++index < json.Length); 353 | } 354 | if (c > ' ') break; 355 | if (c != ' ' && c != '\t' && c != '\n' && c != '\r') break; 356 | 357 | } while (++index < json.Length); 358 | 359 | if (index == json.Length) 360 | { 361 | throw new Exception("Reached end of string unexpectedly"); 362 | } 363 | 364 | c = json[index]; 365 | 366 | index++; 367 | 368 | switch (c) 369 | { 370 | case '{': 371 | return Token.Curly_Open; 372 | 373 | case '}': 374 | return Token.Curly_Close; 375 | 376 | case '[': 377 | return Token.Squared_Open; 378 | 379 | case ']': 380 | return Token.Squared_Close; 381 | 382 | case ',': 383 | return Token.Comma; 384 | 385 | case '"': 386 | return Token.String; 387 | 388 | case '0': 389 | case '1': 390 | case '2': 391 | case '3': 392 | case '4': 393 | case '5': 394 | case '6': 395 | case '7': 396 | case '8': 397 | case '9': 398 | case '-': 399 | case '+': 400 | case '.': 401 | return Token.Number; 402 | 403 | case ':': 404 | return Token.Colon; 405 | 406 | case 'f': 407 | if (json.Length - index >= 4 && 408 | json[index + 0] == 'a' && 409 | json[index + 1] == 'l' && 410 | json[index + 2] == 's' && 411 | json[index + 3] == 'e') 412 | { 413 | index += 4; 414 | return Token.False; 415 | } 416 | break; 417 | 418 | case 't': 419 | if (json.Length - index >= 3 && 420 | json[index + 0] == 'r' && 421 | json[index + 1] == 'u' && 422 | json[index + 2] == 'e') 423 | { 424 | index += 3; 425 | return Token.True; 426 | } 427 | break; 428 | 429 | case 'n': 430 | if (json.Length - index >= 3 && 431 | json[index + 0] == 'u' && 432 | json[index + 1] == 'l' && 433 | json[index + 2] == 'l') 434 | { 435 | index += 3; 436 | return Token.Null; 437 | } 438 | break; 439 | } 440 | throw new Exception("Could not find token at index " + --index); 441 | } 442 | } 443 | } 444 | -------------------------------------------------------------------------------- /Assets/Core/Utils/Toml.net/Toml/Group.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | //using System.Threading.Tasks; 6 | 7 | namespace Toml 8 | { 9 | public class Group 10 | { 11 | #region Public Static Fields 12 | 13 | /// 14 | /// The string used to separate groups, from their parent groups. 15 | /// 16 | public static readonly string Separator = "."; 17 | 18 | /// 19 | /// The Separator array used by String.Split. 20 | /// 21 | public static readonly string[] Separators = { Separator }; 22 | 23 | #endregion 24 | 25 | #region Private Members 26 | 27 | /// 28 | /// The children of this group. 29 | /// 30 | private Dictionary _children = new Dictionary(); 31 | 32 | /// 33 | /// The values of this group. 34 | /// 35 | private Dictionary _items = new Dictionary(); 36 | 37 | #endregion 38 | 39 | #region Constructor 40 | 41 | /// 42 | /// Initializes a new instance of the Group class. 43 | /// 44 | /// The key of the new Group. 45 | internal Group(string key) 46 | { 47 | this.Key = key; 48 | } 49 | 50 | /// 51 | /// Initializes a new instance of the Group class. 52 | /// 53 | /// The owner of the new Group. 54 | /// The key of the new Group. 55 | internal Group(Group parent, string key) 56 | { 57 | this.Parent = parent; 58 | this.Key = key; 59 | } 60 | 61 | #endregion 62 | 63 | #region Public Properties 64 | 65 | /// 66 | /// Gets the key that identifies this Group. 67 | /// 68 | public string Key { get; private set; } 69 | 70 | /// 71 | /// Gets the full key of the Group, using the keys 72 | /// of the parent groups to create the key 73 | /// 74 | public string FullKey 75 | { 76 | get 77 | { 78 | if (this.Parent != null) 79 | { 80 | string parentKey = this.Parent.FullKey; 81 | if (!string.IsNullOrEmpty(parentKey)) 82 | { 83 | return this.Parent.FullKey + Group.Separator + this.Key; 84 | } 85 | } 86 | 87 | return this.Key; 88 | } 89 | } 90 | 91 | /// 92 | /// Gets the parent of this Group, if any. 93 | /// 94 | public Group Parent { get; private set; } 95 | 96 | /// 97 | /// Gets the groups owned by this group. 98 | /// 99 | public IEnumerable Children 100 | { 101 | get { return _children.Values; } 102 | } 103 | 104 | /// 105 | /// Gets the Items owned by the group. 106 | /// 107 | public IEnumerable> Items 108 | { 109 | get 110 | { 111 | return _items.Select(entry => new KeyValuePair(entry.Key, entry.Value)); 112 | } 113 | } 114 | 115 | /// 116 | /// Gets all the items in the tree, from this node down. 117 | /// 118 | public IEnumerable> AllItems 119 | { 120 | get 121 | { 122 | return (this.Items).Concat(this._children.SelectMany((item) => item.Value.AllItems)); 123 | } 124 | } 125 | 126 | /// 127 | /// Gets the Groups that comprise this item, starting from 128 | /// the current group, working towards the root of the tree. 129 | /// 130 | public IEnumerable DescendingGroups 131 | { 132 | get 133 | { 134 | var current = this; 135 | while (current != null) 136 | { 137 | yield return current; 138 | current = current.Parent; 139 | } 140 | 141 | yield break; 142 | } 143 | } 144 | 145 | /// 146 | /// Gets the Groups that comprise this item, starting from 147 | /// the root of the tree, to the current group. 148 | /// 149 | public IEnumerable AscendingGroups 150 | { 151 | get 152 | { 153 | return this.DescendingGroups.Reverse(); 154 | } 155 | } 156 | 157 | #endregion 158 | 159 | #region Public Methods 160 | 161 | /// 162 | /// Creates a string representing the values and subgroups in the Group. 163 | /// 164 | /// A string representing the Group's contents. 165 | public override string ToString() 166 | { 167 | string value = string.Empty; 168 | if (!string.IsNullOrEmpty(this.Key)) 169 | { 170 | value += "[" + this.FullKey + "]" + System.Environment.NewLine; 171 | } 172 | 173 | foreach (var item in this.Items) 174 | { 175 | value += item.ToString() + System.Environment.NewLine; 176 | } 177 | 178 | foreach (var group in this.Children) 179 | { 180 | value += group.ToString(); 181 | value += System.Environment.NewLine; 182 | } 183 | 184 | return value; 185 | } 186 | 187 | /// 188 | /// Attempts to retrieve the group with the specified key. 189 | /// 190 | /// The key of the group to search for. 191 | /// The located group. 192 | /// 193 | public bool TryGetGroup(IEnumerable keyParts, out Group group) 194 | { 195 | if (keyParts.Count() == 0) 196 | { 197 | group = this; 198 | return true; 199 | } 200 | Group child; 201 | if(_children.TryGetValue(keyParts.First(), out child)) 202 | { 203 | return child.TryGetGroup(keyParts.Skip(1), out group); 204 | } 205 | group = null; 206 | return false; 207 | } 208 | 209 | /// 210 | /// Attempts to retrieve the group with the specified key. 211 | /// 212 | /// The key of the group to search for. 213 | /// The located group. 214 | /// 215 | public Group GetGroup(IEnumerable keyParts) 216 | { 217 | if (keyParts.Count() == 0) 218 | { 219 | return this; 220 | } 221 | 222 | Group child = _children[keyParts.First()]; 223 | return child.GetGroup(keyParts.Skip(1)); 224 | } 225 | 226 | /// 227 | /// Attempts to create the group comprised of the specified key. 228 | /// 229 | public Group CreateGroup(string key) 230 | { 231 | var keyParts = key.Split(Group.Separators, StringSplitOptions.None); 232 | return CreateGroup(keyParts); 233 | } 234 | 235 | /// 236 | /// Attempts to create the group comprised of the specified key parts. 237 | /// 238 | /// The key parts that define the group key. 239 | /// The new key group. 240 | protected Group CreateGroup(IEnumerable keyParts) 241 | { 242 | if (keyParts.Count() == 0) 243 | { 244 | return this; 245 | } 246 | 247 | string firstKeyPart = keyParts.First(); 248 | 249 | Group child = null; 250 | if (!_children.TryGetValue(firstKeyPart, out child)) 251 | { 252 | // create the missing child group 253 | child = new Group(this, firstKeyPart); 254 | _children.Add(firstKeyPart, child); 255 | } 256 | 257 | return child.CreateGroup(keyParts.Skip(1)); 258 | } 259 | 260 | /// 261 | /// Indicates whether or not all the keys in the path exist. 262 | /// 263 | /// The key parts to search for. 264 | /// true if all the key parts are found, otherwise false. 265 | public bool GroupExists(IEnumerable keyParts) 266 | { 267 | if (keyParts.Count() == 0) 268 | { 269 | return true; 270 | } 271 | 272 | Group child = _children[keyParts.First()] as Group; 273 | if (child == null) 274 | { 275 | return false; 276 | } 277 | 278 | return child.GroupExists(keyParts.Skip(1)); 279 | } 280 | 281 | /// 282 | /// Attempts to add the specified item under this Item. 283 | /// 284 | /// The child item to add. 285 | public void AddValue(Entry entry) 286 | { 287 | IEnumerable keyParts = entry.FullName.Split(Group.Separators, StringSplitOptions.None); 288 | if (keyParts.Count() == 1) 289 | { 290 | _items.Add(keyParts.Last(), entry); 291 | return; 292 | } 293 | 294 | Group group = CreateGroup(keyParts.Take(keyParts.Count() - 1)); 295 | group.AddValueDirect(entry); 296 | } 297 | 298 | /// 299 | /// Adds the value directly under this node. 300 | /// 301 | /// The value to add. 302 | private void AddValueDirect(Entry entry) 303 | { 304 | //Console.WriteLine(entry.FullName + " : " + this.FullKey); 305 | var pathParts = entry.FullName.Split(Group.Separators, StringSplitOptions.None); 306 | 307 | //Console.WriteLine(pathParts[0] + " : " + this.FullKey); 308 | string[] arr = (pathParts.Take(pathParts.Length - 1).Select(s => s + ".")).ToArray(); 309 | var parentPath = string.Concat(arr); 310 | //Console.WriteLine(parentPath + " : " + this.FullKey); 311 | 312 | // remove the extra "." at the end 313 | parentPath = parentPath.TrimEnd('.'); 314 | 315 | // verify the parent path == our path 316 | if (!parentPath.Equals(this.FullKey)) 317 | { 318 | throw new InvalidOperationException("Cannot add a value to a group it doesn't belong to"); 319 | } 320 | 321 | _items.Add(entry.Name, entry); 322 | return; 323 | } 324 | 325 | /// 326 | /// Attempts to add a child with the specified key/value. 327 | /// 328 | /// The type of the new child to add. 329 | /// The key of the new item. 330 | /// The value of the new key to add. 331 | public void AddValue(string key, T value) 332 | { 333 | if (value is Entry) 334 | { 335 | AddValue(value as Entry); 336 | return; 337 | } 338 | 339 | if (string.IsNullOrEmpty(key)) 340 | { 341 | throw new ArgumentException("Key cannot be null or Empty", "Key"); 342 | } 343 | 344 | if (value == null) 345 | { 346 | throw new ArgumentNullException("value", "Value cannot be null"); 347 | } 348 | 349 | var entry = Parser.ParseEntry(string.Format("{0} = {1}", key, value.ToString())).First(); 350 | 351 | AddValue(key, entry); 352 | return; 353 | } 354 | 355 | /// 356 | /// Attempts to find the child with the specified key. 357 | /// 358 | /// The key of the item to search for. 359 | /// true if the Item is found, otherwise false. 360 | public bool TryGetValue(string key, out string result) 361 | { 362 | var keyParts = key.Split(Group.Separators, StringSplitOptions.None); 363 | if (keyParts.Count() == 1) 364 | { 365 | Entry entry = null; 366 | bool found = _items.TryGetValue(keyParts.Last(), out entry); 367 | 368 | result = null; 369 | if (found) 370 | { 371 | result = entry.SourceText; 372 | } 373 | 374 | return found; 375 | } 376 | 377 | Group group = null; 378 | if (this.TryGetGroup(keyParts.Take(keyParts.Count() - 1), out group)) 379 | { 380 | return group.TryGetValue(keyParts.Last(), out result); 381 | } 382 | 383 | result = null; 384 | return false; 385 | } 386 | 387 | /// 388 | /// Attempts to find the child with the specified key. 389 | /// 390 | /// The key of the item to search for. 391 | /// The item Entry. 392 | public Entry GetValue(string key) 393 | { 394 | var keyParts = key.Split(Group.Separators, StringSplitOptions.None); 395 | if (keyParts.Count() == 1) 396 | { 397 | return _items[key]; 398 | } 399 | 400 | Group group = GetGroup(keyParts.Take(keyParts.Count() - 1)); 401 | return group.GetValue(keyParts.Last()); 402 | } 403 | 404 | /// 405 | /// Attempts to find the child with the specified key. 406 | /// 407 | /// The key of the item to search for. 408 | /// The item Entry text. 409 | public string GetValueString(string key) 410 | { 411 | return GetValue(key).SourceText; 412 | } 413 | 414 | #endregion 415 | } 416 | } 417 | -------------------------------------------------------------------------------- /Assets/Core/Utils/SafeAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Orca 4 | { 5 | /// 6 | /// 能避免重复挂事件的默认委托 7 | /// 8 | public struct SafeAction 9 | { 10 | Action act; 11 | 12 | public static implicit operator Action(SafeAction a) 13 | { 14 | return a.act; 15 | } 16 | 17 | public static implicit operator SafeAction(Action a) 18 | { 19 | SafeAction res = new SafeAction(); 20 | res.act = a; 21 | return res; 22 | } 23 | public static SafeAction operator +(SafeAction a, Action b) 24 | { 25 | a.act -= b; 26 | SafeAction res = new SafeAction(); 27 | res.act = a.act + b; 28 | 29 | return res; 30 | } 31 | 32 | public static SafeAction operator -(SafeAction a, Action b) 33 | { 34 | SafeAction res = new SafeAction(); 35 | res.act = a.act - b; 36 | return res; 37 | } 38 | 39 | public void SafeInvoke() 40 | { 41 | act.SafeInvoke(); 42 | } 43 | 44 | public bool IsNull 45 | { 46 | get 47 | { 48 | return act == null; 49 | } 50 | } 51 | 52 | public void Dispose() 53 | { 54 | act = null; 55 | } 56 | } 57 | 58 | /// 59 | /// 能避免重复挂事件的默认委托 60 | /// 61 | public struct SafeAction 62 | { 63 | Action act; 64 | 65 | public static implicit operator Action(SafeAction a) 66 | { 67 | return a.act; 68 | } 69 | 70 | public static implicit operator SafeAction(Action a) 71 | { 72 | SafeAction res = new SafeAction(); 73 | res.act = a; 74 | return res; 75 | } 76 | public static SafeAction operator +(SafeAction a, Action b) 77 | { 78 | a.act -= b; 79 | SafeAction res = new SafeAction(); 80 | res.act = a.act + b; 81 | 82 | return res; 83 | } 84 | 85 | public static SafeAction operator -(SafeAction a, Action b) 86 | { 87 | SafeAction res = new SafeAction(); 88 | res.act = a.act - b; 89 | return res; 90 | } 91 | 92 | public void SafeInvoke(T param) 93 | { 94 | act.SafeInvoke(param); 95 | } 96 | 97 | public bool IsNull 98 | { 99 | get 100 | { 101 | return act == null; 102 | } 103 | } 104 | 105 | public void Dispose() 106 | { 107 | act = null; 108 | } 109 | } 110 | 111 | /// 112 | /// 能避免重复挂事件的默认委托 113 | /// 114 | public struct SafeAction 115 | { 116 | Action act; 117 | 118 | public static implicit operator Action(SafeAction a) 119 | { 120 | return a.act; 121 | } 122 | 123 | public static implicit operator SafeAction(Action a) 124 | { 125 | SafeAction res = new SafeAction(); 126 | res.act = a; 127 | return res; 128 | } 129 | 130 | public static SafeAction operator +(SafeAction a, Action b) 131 | { 132 | a.act -= b; 133 | SafeAction res = new SafeAction(); 134 | res.act = a.act + b; 135 | 136 | return res; 137 | } 138 | 139 | public static SafeAction operator -(SafeAction a, Action b) 140 | { 141 | SafeAction res = new SafeAction(); 142 | res.act = a.act - b; 143 | return res; 144 | } 145 | 146 | public void SafeInvoke(T param, T2 param2) 147 | { 148 | act.SafeInvoke(param, param2); 149 | } 150 | 151 | public bool IsNull 152 | { 153 | get 154 | { 155 | return act == null; 156 | } 157 | } 158 | 159 | public void Dispose() 160 | { 161 | act = null; 162 | } 163 | } 164 | 165 | /// 166 | /// 能避免重复挂事件的默认委托 167 | /// 168 | public struct SafeAction 169 | { 170 | Action act; 171 | 172 | public static implicit operator Action(SafeAction a) 173 | { 174 | return a.act; 175 | } 176 | 177 | public static implicit operator SafeAction(Action a) 178 | { 179 | SafeAction res = new SafeAction(); 180 | res.act = a; 181 | return res; 182 | } 183 | public static SafeAction operator +(SafeAction a, Action b) 184 | { 185 | a.act -= b; 186 | SafeAction res = new SafeAction(); 187 | res.act = a.act + b; 188 | 189 | return res; 190 | } 191 | 192 | public static SafeAction operator -(SafeAction a, Action b) 193 | { 194 | SafeAction res = new SafeAction(); 195 | res.act = a.act - b; 196 | return res; 197 | } 198 | 199 | public void SafeInvoke(T param, T2 param2, T3 param3) 200 | { 201 | act.SafeInvoke(param, param2, param3); 202 | } 203 | 204 | public bool IsNull 205 | { 206 | get 207 | { 208 | return act == null; 209 | } 210 | } 211 | 212 | public void Dispose() 213 | { 214 | act = null; 215 | } 216 | } 217 | 218 | /// 219 | /// 能避免重复挂事件的默认委托 220 | /// 221 | public struct SafeAction 222 | { 223 | Action act; 224 | 225 | public static implicit operator Action(SafeAction a) 226 | { 227 | return a.act; 228 | } 229 | 230 | public static implicit operator SafeAction(Action a) 231 | { 232 | SafeAction res = new SafeAction(); 233 | res.act = a; 234 | return res; 235 | } 236 | 237 | public static SafeAction operator +(SafeAction a, Action b) 238 | { 239 | a.act -= b; 240 | SafeAction res = new SafeAction(); 241 | res.act = a.act + b; 242 | return res; 243 | } 244 | 245 | public static SafeAction operator -(SafeAction a, Action b) 246 | { 247 | SafeAction res = new SafeAction(); 248 | res.act = a.act - b; 249 | return res; 250 | } 251 | 252 | public void SafeInvoke(T param, T2 param2, T3 param3, T4 param4) 253 | { 254 | act.SafeInvoke(param, param2, param3,param4); 255 | } 256 | 257 | public bool IsNull 258 | { 259 | get 260 | { 261 | return act == null; 262 | } 263 | } 264 | 265 | public void Dispose() 266 | { 267 | act = null; 268 | } 269 | } 270 | 271 | /// 272 | /// 能避免重复挂事件的默认委托 273 | /// 274 | public struct SafeAction 275 | { 276 | Action act; 277 | 278 | public static implicit operator Action(SafeAction a) 279 | { 280 | return a.act; 281 | } 282 | 283 | public static implicit operator SafeAction(Action a) 284 | { 285 | SafeAction res = new SafeAction(); 286 | res.act = a; 287 | return res; 288 | } 289 | public static SafeAction operator +(SafeAction a, Action b) 290 | { 291 | a.act -= b; 292 | SafeAction res = new SafeAction(); 293 | res.act = a.act + b; 294 | return res; 295 | } 296 | 297 | public static SafeAction operator -(SafeAction a, Action b) 298 | { 299 | SafeAction res = new SafeAction(); 300 | res.act = a.act - b; 301 | return res; 302 | } 303 | 304 | public void SafeInvoke(T param, T2 param2, T3 param3, T4 param4, T5 param5) 305 | { 306 | act.SafeInvoke(param, param2, param3, param4, param5); 307 | } 308 | 309 | public bool IsNull 310 | { 311 | get 312 | { 313 | return act == null; 314 | } 315 | } 316 | 317 | public void Dispose() 318 | { 319 | act = null; 320 | } 321 | } 322 | 323 | /// 324 | /// 能避免重复挂事件的默认委托 325 | /// 326 | public struct SafeFunc 327 | { 328 | Func act; 329 | 330 | public static implicit operator Func(SafeFunc a) 331 | { 332 | return a.act; 333 | } 334 | 335 | public static implicit operator SafeFunc(Func a) 336 | { 337 | SafeFunc res = new SafeFunc(); 338 | res.act = a; 339 | return res; 340 | } 341 | public static SafeFunc operator +(SafeFunc a, Func b) 342 | { 343 | a.act -= b; 344 | SafeFunc res = new SafeFunc(); 345 | res.act = a.act + b; 346 | 347 | return res; 348 | } 349 | 350 | public static SafeFunc operator -(SafeFunc a, Func b) 351 | { 352 | SafeFunc res = new SafeFunc(); 353 | res.act = a.act - b; 354 | return res; 355 | } 356 | 357 | public T SafeInvoke() 358 | { 359 | return act.SafeInvoke(); 360 | } 361 | 362 | public bool IsNull 363 | { 364 | get 365 | { 366 | return act == null; 367 | } 368 | } 369 | 370 | public void Dispose() 371 | { 372 | act = null; 373 | } 374 | } 375 | 376 | /// 377 | /// 能避免重复挂事件的默认委托 378 | /// 379 | public struct SafeFunc 380 | { 381 | Func act; 382 | 383 | public static implicit operator Func(SafeFunc a) 384 | { 385 | return a.act; 386 | } 387 | public static implicit operator SafeFunc(Func a) 388 | { 389 | SafeFunc res = new SafeFunc(); 390 | res.act = a; 391 | return res; 392 | } 393 | public static SafeFunc operator +(SafeFunc a, Func b) 394 | { 395 | a.act -= b; 396 | SafeFunc res = new SafeFunc(); 397 | res.act = a.act + b; 398 | 399 | return res; 400 | } 401 | 402 | public static SafeFunc operator -(SafeFunc a, Func b) 403 | { 404 | SafeFunc res = new SafeFunc(); 405 | res.act = a.act - b; 406 | return res; 407 | } 408 | 409 | public T2 SafeInvoke(T param) 410 | { 411 | return act.SafeInvoke(param); 412 | } 413 | 414 | public bool IsNull 415 | { 416 | get 417 | { 418 | return act == null; 419 | } 420 | } 421 | 422 | public void Dispose() 423 | { 424 | act = null; 425 | } 426 | } 427 | 428 | /// 429 | /// 能避免重复挂事件的默认委托 430 | /// 431 | public struct SafeFunc 432 | { 433 | Func act; 434 | 435 | public static implicit operator Func(SafeFunc a) 436 | { 437 | return a.act; 438 | } 439 | 440 | public static implicit operator SafeFunc(Func a) 441 | { 442 | SafeFunc res = new SafeFunc(); 443 | res.act = a; 444 | return res; 445 | } 446 | public static SafeFunc operator +(SafeFunc a, Func b) 447 | { 448 | a.act -= b; 449 | SafeFunc res = new SafeFunc(); 450 | res.act = a.act + b; 451 | 452 | return res; 453 | } 454 | 455 | public static SafeFunc operator -(SafeFunc a, Func b) 456 | { 457 | SafeFunc res = new SafeFunc(); 458 | res.act = a.act - b; 459 | return res; 460 | } 461 | 462 | public T3 SafeInvoke(T param, T2 param2) 463 | { 464 | return act.SafeInvoke(param, param2); 465 | } 466 | 467 | public bool IsNull 468 | { 469 | get 470 | { 471 | return act == null; 472 | } 473 | } 474 | 475 | public void Dispose() 476 | { 477 | act = null; 478 | } 479 | } 480 | 481 | /// 482 | /// 能避免重复挂事件的默认委托 483 | /// 484 | public struct SafeFunc 485 | { 486 | Func act; 487 | 488 | public static implicit operator Func(SafeFunc a) 489 | { 490 | return a.act; 491 | } 492 | 493 | public static implicit operator SafeFunc(Func a) 494 | { 495 | SafeFunc res = new SafeFunc(); 496 | res.act = a; 497 | return res; 498 | } 499 | public static SafeFunc operator +(SafeFunc a, Func b) 500 | { 501 | a.act -= b; 502 | SafeFunc res = new SafeFunc(); 503 | res.act = a.act + b; 504 | 505 | return res; 506 | } 507 | 508 | public static SafeFunc operator -(SafeFunc a, Func b) 509 | { 510 | SafeFunc res = new SafeFunc(); 511 | res.act = a.act - b; 512 | return res; 513 | } 514 | 515 | public T4 SafeInvoke(T param, T2 param2, T3 param3) 516 | { 517 | return act.SafeInvoke(param, param2, param3); 518 | } 519 | 520 | public bool IsNull 521 | { 522 | get 523 | { 524 | return act == null; 525 | } 526 | } 527 | 528 | public void Dispose() 529 | { 530 | act = null; 531 | } 532 | } 533 | 534 | /// 535 | /// 能避免重复挂事件的默认委托 536 | /// 537 | public struct SafeFunc 538 | { 539 | Func act; 540 | 541 | public static implicit operator Func(SafeFunc a) 542 | { 543 | return a.act; 544 | } 545 | 546 | public static implicit operator SafeFunc(Func a) 547 | { 548 | SafeFunc res = new SafeFunc(); 549 | res.act = a; 550 | return res; 551 | } 552 | public static SafeFunc operator +(SafeFunc a, Func b) 553 | { 554 | a.act -= b; 555 | SafeFunc res = new SafeFunc(); 556 | res.act = a.act + b; 557 | 558 | return res; 559 | } 560 | 561 | public static SafeFunc operator -(SafeFunc a, Func b) 562 | { 563 | SafeFunc res = new SafeFunc(); 564 | res.act = a.act - b; 565 | return res; 566 | } 567 | 568 | public T5 SafeInvoke(T param, T2 param2, T3 param3, T4 param4) 569 | { 570 | return act.SafeInvoke(param, param2, param3, param4); 571 | } 572 | 573 | public bool IsNull 574 | { 575 | get 576 | { 577 | return act == null; 578 | } 579 | } 580 | 581 | public void Dispose() 582 | { 583 | act = null; 584 | } 585 | } 586 | } 587 | --------------------------------------------------------------------------------