├── .gitignore ├── .vs └── LockstepFundation │ └── v15 │ └── Server │ └── sqlite3 │ ├── db.lock │ ├── storage.ide │ ├── storage.ide-shm │ └── storage.ide-wal ├── Assets ├── Demo.meta ├── Demo │ ├── Editor.meta │ ├── Editor │ │ ├── Collider.cs │ │ ├── Collider.cs.meta │ │ ├── ColliderEditor.cs │ │ └── ColliderEditor.cs.meta │ ├── Res.meta │ ├── Res │ │ ├── Fighter Pack Bundle FREE.meta │ │ ├── Fighter Pack Bundle FREE │ │ │ ├── Berserker Fighter Mecanim Animation Pack FREE.meta │ │ │ └── Berserker Fighter Mecanim Animation Pack FREE │ │ │ │ ├── Animations.meta │ │ │ │ ├── Animations │ │ │ │ ├── Berserker@Punch.FBX │ │ │ │ └── Berserker@Punch.FBX.meta │ │ │ │ ├── Characters.meta │ │ │ │ └── Characters │ │ │ │ ├── Berserker.FBX │ │ │ │ └── Berserker.FBX.meta │ │ ├── Material.meta │ │ ├── Material │ │ │ ├── Plane.mat │ │ │ ├── Plane.mat.meta │ │ │ ├── StaticObject.mat │ │ │ └── StaticObject.mat.meta │ │ ├── Raw Mocap Data.meta │ │ ├── Raw Mocap Data │ │ │ ├── Animations.meta │ │ │ ├── Animations │ │ │ │ ├── Idle.meta │ │ │ │ ├── Idle │ │ │ │ │ ├── Idle_Ready.fbx │ │ │ │ │ └── Idle_Ready.fbx.meta │ │ │ │ ├── Running.meta │ │ │ │ └── Running │ │ │ │ │ ├── JogForward_NtrlFaceFwd.fbx │ │ │ │ │ └── JogForward_NtrlFaceFwd.fbx.meta │ │ │ ├── DefaultAvatar.fbm.meta │ │ │ ├── DefaultAvatar.fbm │ │ │ │ ├── body normal.png │ │ │ │ ├── body normal.png.meta │ │ │ │ ├── body_color_map.png │ │ │ │ ├── body_color_map.png.meta │ │ │ │ ├── body_specular_map.png │ │ │ │ ├── body_specular_map.png.meta │ │ │ │ ├── eyes_color_map.png │ │ │ │ ├── eyes_color_map.png.meta │ │ │ │ ├── eyes_specular_map.png │ │ │ │ ├── eyes_specular_map.png.meta │ │ │ │ ├── face normal.png │ │ │ │ ├── face normal.png.meta │ │ │ │ ├── face_color_map.png │ │ │ │ └── face_color_map.png.meta │ │ │ ├── DefaultAvatar.fbx │ │ │ ├── DefaultAvatar.fbx.meta │ │ │ ├── Materials.meta │ │ │ ├── Materials │ │ │ │ ├── DefaultAvatar-body.mat │ │ │ │ ├── DefaultAvatar-body.mat.meta │ │ │ │ ├── DefaultAvatar-eyes.mat │ │ │ │ ├── DefaultAvatar-eyes.mat.meta │ │ │ │ ├── DefaultAvatar-face.mat │ │ │ │ ├── DefaultAvatar-face.mat.meta │ │ │ │ ├── body normal.png │ │ │ │ ├── body normal.png.meta │ │ │ │ ├── body_color_map.png │ │ │ │ ├── body_color_map.png.meta │ │ │ │ ├── eyes_color_map.png │ │ │ │ ├── eyes_color_map.png.meta │ │ │ │ ├── face normal.png │ │ │ │ ├── face normal.png.meta │ │ │ │ ├── face_color_map.png │ │ │ │ └── face_color_map.png.meta │ │ │ ├── PC.controller │ │ │ └── PC.controller.meta │ │ ├── Shurikens pack.meta │ │ ├── Shurikens pack │ │ │ ├── Materials.meta │ │ │ ├── Materials │ │ │ │ ├── Shuriken6.mat │ │ │ │ └── Shuriken6.mat.meta │ │ │ ├── Models.meta │ │ │ ├── Models │ │ │ │ ├── Shuriken6.FBX │ │ │ │ └── Shuriken6.FBX.meta │ │ │ ├── Prefabs.meta │ │ │ ├── Prefabs │ │ │ │ ├── Shuriken6.prefab │ │ │ │ └── Shuriken6.prefab.meta │ │ │ ├── Textures.meta │ │ │ └── Textures │ │ │ │ ├── Shuriken6_d.png │ │ │ │ ├── Shuriken6_d.png.meta │ │ │ │ ├── Shuriken6_m.png │ │ │ │ ├── Shuriken6_m.png.meta │ │ │ │ ├── Shuriken6_n.png │ │ │ │ └── Shuriken6_n.png.meta │ │ ├── Sprite.meta │ │ └── Sprite │ │ │ ├── AllAxis_Outline.png │ │ │ ├── AllAxis_Outline.png.meta │ │ │ ├── Handle_Ridged.png │ │ │ └── Handle_Ridged.png.meta │ ├── Resources.meta │ ├── Resources │ │ ├── GameScene.meta │ │ └── GameScene │ │ │ ├── Bullet.meta │ │ │ ├── Bullet │ │ │ ├── Shuriken6.prefab │ │ │ └── Shuriken6.prefab.meta │ │ │ ├── Player.meta │ │ │ └── Player │ │ │ ├── DefaultAvatar.prefab │ │ │ └── DefaultAvatar.prefab.meta │ ├── SampleScene.unity │ ├── SampleScene.unity.meta │ ├── Scripts.meta │ └── Scripts │ │ ├── Bullet.cs │ │ ├── Bullet.cs.meta │ │ ├── GameSceneManager.cs │ │ ├── GameSceneManager.cs.meta │ │ ├── Player.cs │ │ ├── Player.cs.meta │ │ ├── PlayerCamera.cs │ │ ├── PlayerCamera.cs.meta │ │ ├── PlayerView.cs │ │ ├── PlayerView.cs.meta │ │ ├── UIJoyStick.cs │ │ └── UIJoyStick.cs.meta ├── MGF.meta └── MGF │ ├── Component.meta │ ├── Component │ ├── Collider2DBase.cs │ ├── Collider2DBase.cs.meta │ ├── MGFBoxCollider2D.cs │ ├── MGFBoxCollider2D.cs.meta │ ├── MGFCollision.cs │ ├── MGFCollision.cs.meta │ ├── MGFComponet.cs │ ├── MGFComponet.cs.meta │ ├── MGFObject.cs │ ├── MGFObject.cs.meta │ ├── MGFPolygon.cs │ ├── MGFPolygon.cs.meta │ ├── MGFTransform.cs │ ├── MGFTransform.cs.meta │ ├── MGFView.cs │ ├── MGFView.cs.meta │ ├── SphereCollider2D.cs │ └── SphereCollider2D.cs.meta │ ├── Debugger.meta │ ├── Debugger │ ├── Debugger.cs │ ├── Debugger.cs.meta │ ├── DebuggerExtension.cs │ └── DebuggerExtension.cs.meta │ ├── Math.meta │ ├── Math │ ├── Fix64.cs │ ├── Fix64.cs.meta │ ├── Fix64SinLut.cs │ ├── Fix64SinLut.cs.meta │ ├── Fix64TanLut.cs │ ├── Fix64TanLut.cs.meta │ ├── Fix64Vector2.cs │ └── Fix64Vector2.cs.meta │ ├── Module.meta │ ├── Module │ ├── Example.meta │ ├── Example │ │ ├── ModuleExample.cs │ │ └── ModuleExample.cs.meta │ ├── Framework.meta │ ├── Framework │ │ ├── BusinessModule.cs │ │ ├── BusinessModule.cs.meta │ │ ├── EventTable.cs │ │ ├── EventTable.cs.meta │ │ ├── LuaModule.cs │ │ ├── LuaModule.cs.meta │ │ ├── Module.cs │ │ ├── Module.cs.meta │ │ ├── ModuleManager.cs │ │ ├── ModuleManager.cs.meta │ │ ├── ServiceModule.cs │ │ ├── ServiceModule.cs.meta │ │ ├── Singleton.cs │ │ └── Singleton.cs.meta │ ├── GlobalEvent.cs │ └── GlobalEvent.cs.meta │ ├── Physics.meta │ ├── Physics │ ├── MGFPhysics.cs │ ├── MGFPhysics.cs.meta │ ├── PhysicsManager.cs │ ├── PhysicsManager.cs.meta │ ├── Quadtree.cs │ └── Quadtree.cs.meta │ ├── UI.meta │ ├── UI │ ├── Example.meta │ ├── Example │ │ ├── UIExample.cs │ │ ├── UIExample.cs.meta │ │ ├── UIPage1.cs │ │ ├── UIPage1.cs.meta │ │ ├── UIPage2.cs │ │ ├── UIPage2.cs.meta │ │ ├── UIWidget1.cs │ │ ├── UIWidget1.cs.meta │ │ ├── UIWnd1.cs │ │ └── UIWnd1.cs.meta │ ├── Framework.meta │ └── Framework │ │ ├── UIManager.cs │ │ ├── UIManager.cs.meta │ │ ├── UIPage.cs │ │ ├── UIPage.cs.meta │ │ ├── UIPanel.cs │ │ ├── UIPanel.cs.meta │ │ ├── UIRes.cs │ │ ├── UIRes.cs.meta │ │ ├── UIRoot.cs │ │ ├── UIRoot.cs.meta │ │ ├── UIUtils.cs │ │ ├── UIUtils.cs.meta │ │ ├── UIWidget.cs │ │ ├── UIWidget.cs.meta │ │ ├── UIWindow.cs │ │ └── UIWindow.cs.meta │ ├── Utils.meta │ └── Utils │ ├── CoroutineTool.cs │ ├── CoroutineTool.cs.meta │ ├── FileUtils.cs │ ├── FileUtils.cs.meta │ ├── IRecycleAble.cs │ ├── IRecycleAble.cs.meta │ ├── ObjectPool.cs │ ├── ObjectPool.cs.meta │ ├── PathUtils.cs │ └── PathUtils.cs.meta ├── LICENSE ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── PresetManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityConnectSettings.asset └── VFXManager.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /Library/ 2 | /Temp/ 3 | /Obj/ 4 | /Build/ 5 | /Builds/ 6 | /ProjectSettings/ProjectVersion.txt 7 | /Assets/AssetStoreTools* 8 | /Packages/ 9 | /Logs/ 10 | /.vs/ 11 | 12 | *.svd 13 | *.userprefs 14 | /*.csproj 15 | *.pidb 16 | *.suo 17 | /*.sln 18 | *.user 19 | *.unityproj 20 | *.booproj 21 | -------------------------------------------------------------------------------- /.vs/LockstepFundation/v15/Server/sqlite3/db.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YouRenJee/LockstepFundation/e912326fe44e310c8354ba0437eea01190279f61/.vs/LockstepFundation/v15/Server/sqlite3/db.lock -------------------------------------------------------------------------------- /.vs/LockstepFundation/v15/Server/sqlite3/storage.ide: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YouRenJee/LockstepFundation/e912326fe44e310c8354ba0437eea01190279f61/.vs/LockstepFundation/v15/Server/sqlite3/storage.ide -------------------------------------------------------------------------------- /.vs/LockstepFundation/v15/Server/sqlite3/storage.ide-shm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YouRenJee/LockstepFundation/e912326fe44e310c8354ba0437eea01190279f61/.vs/LockstepFundation/v15/Server/sqlite3/storage.ide-shm -------------------------------------------------------------------------------- /.vs/LockstepFundation/v15/Server/sqlite3/storage.ide-wal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YouRenJee/LockstepFundation/e912326fe44e310c8354ba0437eea01190279f61/.vs/LockstepFundation/v15/Server/sqlite3/storage.ide-wal -------------------------------------------------------------------------------- /Assets/Demo.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4214336923640094e9886712f3a2b2bd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Demo/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 135de83c516b7f342a9cdc384e4566de 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Demo/Editor/Collider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | 7 | [CustomEditor(typeof(MGFCollision))] 8 | public class ColliderEditor : EditorWindow 9 | { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Assets/Demo/Editor/Collider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb48b3025b9e9d84e8110c8c3c319e6d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Demo/Editor/ColliderEditor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | 7 | [CustomEditor(typeof(MGFPolygon))] 8 | public class Collider : Editor 9 | { 10 | private MGFPolygon _target; 11 | private bool _editMode = false; 12 | 13 | 14 | private void OnEnable() 15 | { 16 | if (!_target) _target = target as MGFPolygon; 17 | } 18 | 19 | public override void OnInspectorGUI() 20 | { 21 | base.OnInspectorGUI(); 22 | var vertex = _target.vertex; 23 | if (vertex != null) 24 | { 25 | for(int i=0;i= m_aliveTime) 49 | { 50 | GameSceneManager.Instance.DestroyFromPool(this); 51 | return; 52 | } 53 | 54 | Move(Forward * 5); 55 | 56 | 57 | } 58 | 59 | 60 | public int InitNum() 61 | { 62 | return 20; 63 | } 64 | 65 | public string RecycleName() 66 | { 67 | return Tag; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/Bullet.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dafa44e197ea2ff49b0c214b2cf8914e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/GameSceneManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9032f35e9c00a7548b709a1923075d6d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/Player.cs: -------------------------------------------------------------------------------- 1 |  2 | using MGF.Math; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using UnityEngine; 6 | 7 | 8 | public enum PlayerStateInGame 9 | { 10 | idle = 1, 11 | run = 2, 12 | attack = 3, 13 | } 14 | 15 | [RequireComponent(typeof(PlayerView))] 16 | public class Player : MGFObject 17 | { 18 | public int PlayerID = 1; 19 | private PlayerView pv; 20 | internal override void Init() 21 | { 22 | Fix64 x = new Fix64(32); 23 | base.Init(); 24 | pv = GetComponent(); 25 | } 26 | 27 | internal void Skill() 28 | { 29 | Bullet bt= GameSceneManager.Instance.CreateFromPool("BULLET",GetPos() + Forward.Nomalize() , tr.Rot); 30 | bt.PlayerID = PlayerID; 31 | pv.Skill(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/Player.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce72e89bed837b242a95fd0c18745fb9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/PlayerCamera.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class PlayerCamera : MonoBehaviour 6 | { 7 | private bool IsInit = false; 8 | 9 | public Transform Player; 10 | 11 | private Vector3 _offset; 12 | public void Init() 13 | { 14 | IsInit = true; 15 | _offset = new Vector3(0,15,-12); 16 | transform.position = Vector3.Lerp(transform.position, Player.position + _offset, Time.deltaTime * 10); 17 | } 18 | 19 | private void LateUpdate() 20 | { 21 | if (IsInit==false) 22 | { 23 | return; 24 | } 25 | transform.position = Vector3.Lerp(transform.position, Player.position + _offset, Time.deltaTime * 10); 26 | 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/PlayerCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c98cd194ece13414085cbeeca7386aa4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/PlayerView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | [RequireComponent(typeof(Animator))] 6 | public class PlayerView : MGFView 7 | { 8 | Animator m_anim; 9 | 10 | internal override void Init() 11 | { 12 | base.Init(); 13 | m_anim = GetComponent(); 14 | } 15 | 16 | public void Skill() 17 | { 18 | m_anim.SetTrigger("Attack"); 19 | } 20 | 21 | protected override void DefaultViewBehaviour() 22 | { 23 | base.DefaultViewBehaviour(); 24 | if (m_Obj.IsMoving) 25 | { 26 | m_anim.SetBool("IdleToWalk", true); 27 | } 28 | else 29 | { 30 | m_anim.SetBool("IdleToWalk", false); 31 | } 32 | 33 | } 34 | 35 | private void Update() 36 | { 37 | DefaultViewBehaviour(); 38 | } 39 | 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/PlayerView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26a20ba659431844ea34bf0c35fd25d9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/UIJoyStick.cs: -------------------------------------------------------------------------------- 1 |  2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEngine.UI; 6 | 7 | public class UIJoyStick : MonoBehaviour 8 | { 9 | 10 | private Canvas m_Cs; 11 | public Transform Stick; 12 | public float MaxR = 80; 13 | public Queue Commands = new Queue(); 14 | 15 | 16 | 17 | private Vector2 m_TouchDir = Vector2.up; 18 | private static Command skill = new Command(CommandType.Skill); 19 | public static Command stick = new Command(CommandType.JoyStick); 20 | public void OnSkillClick() 21 | { 22 | Commands.Enqueue(skill); 23 | } 24 | 25 | 26 | 27 | 28 | private float VectorAngle(Vector2 from, Vector2 to) 29 | { 30 | float angle; 31 | 32 | Vector3 cross = Vector3.Cross(from, to); 33 | angle = Vector2.Angle(from, to); 34 | return cross.z > 0 ? -angle : angle; 35 | } 36 | 37 | public float Dir 38 | { 39 | get 40 | { 41 | return VectorAngle(Vector2.up, m_TouchDir); 42 | } 43 | } 44 | 45 | public void Init() 46 | { 47 | m_Cs = GameObject.Find("UIRoot").GetComponent(); 48 | Stick.localPosition = Vector2.zero; 49 | m_TouchDir = Vector2.up; 50 | } 51 | 52 | 53 | public void OnStickDrag() 54 | { 55 | Vector2 pos = Vector2.zero; 56 | 57 | RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform as RectTransform, Input.mousePosition, m_Cs.worldCamera, out pos); 58 | 59 | float len = pos.magnitude; 60 | if (len <= 0) 61 | { 62 | m_TouchDir = Vector2.up; 63 | return; 64 | } 65 | 66 | m_TouchDir.x = pos.x / len; 67 | m_TouchDir.y = pos.y / len; 68 | 69 | if (len >= MaxR) 70 | { 71 | pos.x = pos.x * MaxR / len; 72 | pos.y = pos.y * MaxR / len; 73 | } 74 | 75 | Stick.localPosition = pos; 76 | 77 | 78 | } 79 | 80 | 81 | public void OnEndDrag() 82 | { 83 | Stick.localPosition = Vector2.zero; 84 | m_TouchDir = Vector2.up; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /Assets/Demo/Scripts/UIJoyStick.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 942fd6d5219c6c44b99bbdaca5789289 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6376b401b1e8bd40889f92531d8d7cb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Component.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f6a9c73a020ecb4e8cfb31f92de48ef 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Component/Collider2DBase.cs: -------------------------------------------------------------------------------- 1 | //using MGF.Math; 2 | //using System.Collections; 3 | //using System.Collections.Generic; 4 | //using UnityEngine; 5 | //using static MGF.Physics.Quadtree; 6 | 7 | //public abstract class Collider2DBase : MonoBehaviour 8 | //{ 9 | // public bool EnableCheck = true; 10 | // public bool IsStatic = true; 11 | 12 | 13 | // public abstract bool Check(Collider2DBase obj); 14 | // public abstract Fix64Vector2 GetPos(); 15 | 16 | // internal abstract Fix64 GetHalfHeight(); 17 | 18 | // internal abstract Fix64 GetHalfWidth(); 19 | 20 | //} 21 | -------------------------------------------------------------------------------- /Assets/MGF/Component/Collider2DBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36a875df45385de4dadb0c2eec3a7a46 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFBoxCollider2D.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF.Math; 5 | 6 | public class MGFBoxCollider2D : MGFCollision 7 | { 8 | //矩形碰撞盒大小 9 | private Fix64Vector2 halfSize = new Fix64Vector2(0, 0); 10 | 11 | //矩形碰撞体有4个顶点 12 | private Fix64Vector2[] vertex = new Fix64Vector2[4]; 13 | 14 | 15 | internal override string Tag { get { return "MGFBoxCollider2D"; } } 16 | internal override void Init() 17 | { 18 | Quaternion qua = transform.rotation; 19 | transform.rotation = Quaternion.Euler(0, 0, 0); 20 | if (GetComponent() != null) 21 | { 22 | halfSize.X = (Fix64)(GetComponent().mesh.bounds.size.x * transform.localScale.x / 2); 23 | halfSize.Y = (Fix64)(GetComponent().mesh.bounds.size.z * transform.localScale.z / 2); 24 | } 25 | else 26 | { 27 | halfSize.X = (Fix64)(GetComponent().bounds.size.x / 2); 28 | halfSize.Y = (Fix64)(GetComponent().bounds.size.z / 2); 29 | } 30 | 31 | vertex[0] = Fix64Vector2.SetVertex(halfSize.X, halfSize.Y); 32 | vertex[1] = Fix64Vector2.SetVertex( halfSize.X, -halfSize.Y); 33 | vertex[2] = Fix64Vector2.SetVertex(-halfSize.X, -halfSize.Y); 34 | vertex[3] = Fix64Vector2.SetVertex( -halfSize.X, halfSize.Y); 35 | transform.rotation = qua; 36 | } 37 | 38 | public override Fix64Vector2[] GetColliderPos() 39 | { 40 | return vertex; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFBoxCollider2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 03cca4de9375ed74999aaa0571bee976 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFCollision.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF.Math; 5 | 6 | public abstract class MGFCollision : MGFComponet 7 | { 8 | /// 9 | /// 获得该多边形碰撞体初始状态(旋转为0)的顶点坐标 10 | /// 11 | /// 12 | public abstract Fix64Vector2[] GetColliderPos(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFCollision.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0fac23c62247c74e94b8118cc042255 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFComponet.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public abstract class MGFComponet : MonoBehaviour 6 | { 7 | internal virtual void Init() 8 | { 9 | } 10 | 11 | internal virtual void MGFEnable() 12 | { 13 | 14 | } 15 | 16 | internal virtual void MGFDestroy() 17 | { } 18 | 19 | internal virtual string Tag => this.name; 20 | } 21 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFComponet.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df34a17ef4f3e2a47a2f6a8b59962635 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFObject.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 625e646a91ca4184a83574849f18f22c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFPolygon.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF; 5 | using MGF.Math; 6 | 7 | 8 | [ExecuteInEditMode] 9 | public class MGFPolygon : MGFCollision 10 | { 11 | public bool EditMode = false; 12 | public Fix64Vector2[] vertex; 13 | 14 | 15 | public override Fix64Vector2[] GetColliderPos() 16 | { 17 | throw new System.NotImplementedException(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFPolygon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 34f49952af655df40a46759924aa262f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFTransform.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF.Math; 5 | 6 | 7 | public class MGFTransform : MGFComponet 8 | { 9 | public Fix64Vector2 Pos = new Fix64Vector2(0,0); 10 | public Fix64 Rot = Fix64.Zero; 11 | 12 | internal override string Tag { get { return "MGFTransform"; } } 13 | 14 | internal override void Init() 15 | { 16 | Pos.X = (Fix64) transform.position.x; 17 | Pos.Y = (Fix64) transform.position.z; 18 | Rot = (Fix64)transform.rotation.eulerAngles.y; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFTransform.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb9f02ada83558941b57abb72b66dcaa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {fileID: 2800000, guid: 7e44dccf031ee44fe8512a94d298e3aa, type: 3} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using MGF.Math; 3 | using UnityEngine; 4 | 5 | 6 | public class MGFView : MGFComponet 7 | { 8 | protected MGFObject m_Obj; 9 | 10 | internal override string Tag { get { return "MGFView"; }} 11 | 12 | internal override void Init() 13 | { 14 | m_Obj = GetComponent(); 15 | } 16 | 17 | public void MoveTo() 18 | { 19 | transform.position = m_Obj.tr.Pos.ToVector3Zero(); 20 | } 21 | 22 | public void Rot() 23 | { 24 | transform.rotation = Quaternion.Euler(0, (float)m_Obj.tr.Rot, 0); 25 | } 26 | 27 | 28 | 29 | 30 | protected virtual void DefaultViewBehaviour() 31 | { 32 | if (m_Obj == null || m_Obj.IsStatic) 33 | { 34 | return; 35 | } 36 | transform.position = Vector3.Lerp(transform.position, m_Obj.tr.Pos.ToVector3Zero(), Time.deltaTime * 20); 37 | transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, (float)m_Obj.tr.Rot, 0), Time.deltaTime * 10); 38 | } 39 | 40 | private void Update() 41 | { 42 | DefaultViewBehaviour(); 43 | } 44 | 45 | 46 | public void Hide() 47 | { 48 | foreach (var item in GetComponentsInChildren()) 49 | { 50 | item.enabled = false; 51 | } 52 | 53 | } 54 | 55 | public void Show() 56 | { 57 | foreach (var item in GetComponentsInChildren()) 58 | { 59 | item.enabled = true; 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Assets/MGF/Component/MGFView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0dc7c32d038c9b94eb19521744c723fb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Component/SphereCollider2D.cs: -------------------------------------------------------------------------------- 1 | //using System.Collections; 2 | //using System.Collections.Generic; 3 | //using UnityEngine; 4 | //using MGF.Math; 5 | //using System; 6 | //using MGF.Physics; 7 | 8 | //public class SphereCollider2D : Collider2DBase 9 | //{ 10 | 11 | 12 | // public Fix64 Radius = new Fix64(0.5f); 13 | 14 | 15 | // public override bool Check(Collider2DBase obj) 16 | // { 17 | 18 | 19 | // if (Fix64Vector2.Distance(GetPos(), obj.GetPos()) > (Radius + obj.GetHalfHeight())) 20 | // { 21 | // return false; 22 | // } 23 | // else 24 | // { 25 | // return true; 26 | // } 27 | 28 | // } 29 | 30 | // public override Fix64Vector2 GetPos() 31 | // { 32 | // return new Fix64Vector2(new Fix64(transform.localPosition.x), new Fix64(transform.localPosition.z)); 33 | // } 34 | 35 | // internal override Fix64 GetHalfHeight() 36 | // { 37 | // return Radius; 38 | // } 39 | 40 | // internal override Fix64 GetHalfWidth() 41 | // { 42 | // return Radius; 43 | // } 44 | 45 | 46 | 47 | 48 | // void OnDrawGizmosSelected() 49 | // { 50 | 51 | // Gizmos.DrawSphere(transform.position, 0.5f); 52 | // Gizmos.color = Color.green; 53 | 54 | // if (Quadtree.dic.Count == 0) 55 | // { 56 | // return; 57 | // } 58 | // if (Quadtree.dic.ContainsKey(this)) 59 | // { 60 | // Quadtree.Rectangle rt = Quadtree.dic[this].GetCenter(); 61 | // Gizmos.DrawCube(new Vector3((float)rt.bounds.X, 0.1f, (float)rt.bounds.Y), new Vector3((float)rt.GetHalfWidth() * 2, 0, (float)rt.GetHalfWidth() * 2)); 62 | 63 | // } 64 | // } 65 | 66 | //} 67 | 68 | -------------------------------------------------------------------------------- /Assets/MGF/Component/SphereCollider2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dc4b4d13a8b908647ab48809ffa0671b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Debugger.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84ee19d66345dc24387be8321355d5fe 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Debugger/Debugger.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bc664538c983bf4f880911c2155e3db 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Debugger/DebuggerExtension.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using System.Diagnostics; 4 | using System.Reflection; 5 | 6 | namespace MGF 7 | { 8 | public static class DebuggerExtension 9 | { 10 | //---------------------------------------------------------------------- 11 | 12 | [Conditional("ENABLE_LOG")] 13 | public static void Log(this object obj, string message = "") 14 | { 15 | if (!Debugger.EnableLog) 16 | { 17 | return; 18 | } 19 | 20 | Debugger.Log(GetLogTag(obj), GetLogCallerMethod(), (string)message); 21 | } 22 | 23 | [Conditional("ENABLE_LOG")] 24 | public static void Log(this object obj, string format, params object[] args) 25 | { 26 | if (!Debugger.EnableLog) 27 | { 28 | return; 29 | } 30 | 31 | Debugger.Log(GetLogTag(obj), GetLogCallerMethod(), string.Format(format, args)); 32 | } 33 | 34 | 35 | //---------------------------------------------------------------------- 36 | 37 | 38 | public static void LogError(this object obj, string message) 39 | { 40 | Debugger.LogError(GetLogTag(obj), GetLogCallerMethod(), (string)message); 41 | } 42 | 43 | public static void LogError(this object obj, string format, params object[] args) 44 | { 45 | Debugger.LogError(GetLogTag(obj), GetLogCallerMethod(), string.Format(format, args)); 46 | } 47 | 48 | 49 | 50 | //---------------------------------------------------------------------- 51 | 52 | public static void LogWarning(this object obj, string message) 53 | { 54 | Debugger.LogWarning(GetLogTag(obj), GetLogCallerMethod(), (string)message); 55 | } 56 | 57 | 58 | public static void LogWarning(this object obj, string format, params object[] args) 59 | { 60 | Debugger.LogWarning(GetLogTag(obj), GetLogCallerMethod(), string.Format(format, args)); 61 | } 62 | 63 | //---------------------------------------------------------------------- 64 | 65 | 66 | 67 | //---------------------------------------------------------------------- 68 | private static string GetLogTag(object obj) 69 | { 70 | FieldInfo fi = obj.GetType().GetField("LOG_TAG"); 71 | if (fi != null) 72 | { 73 | return (string) fi.GetValue(obj); 74 | } 75 | 76 | return obj.GetType().Name; 77 | } 78 | 79 | private static Assembly ms_Assembly; 80 | private static string GetLogCallerMethod() 81 | { 82 | StackTrace st = new StackTrace(2, false); 83 | if (st != null) 84 | { 85 | if (null == ms_Assembly) 86 | { 87 | ms_Assembly = typeof(Debugger).Assembly; 88 | } 89 | 90 | int currStackFrameIndex = 0; 91 | while (currStackFrameIndex < st.FrameCount) 92 | { 93 | StackFrame oneSf = st.GetFrame(currStackFrameIndex); 94 | MethodBase oneMethod = oneSf.GetMethod(); 95 | 96 | if (oneMethod.Module.Assembly != ms_Assembly) 97 | { 98 | return oneMethod.Name; 99 | } 100 | 101 | currStackFrameIndex++; 102 | } 103 | 104 | } 105 | 106 | return ""; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Assets/MGF/Debugger/DebuggerExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8afd562eef3b52248a354dbfe29e2626 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Math.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ca0b6e15623b0b47ba1094eb817b135 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Math/Fix64.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fdf046d59ec49ca4da28449689fb7651 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Math/Fix64SinLut.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9baec14b92c5d04887e9dc9e3af634d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Math/Fix64TanLut.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d21117a3770a7a54da334cb2a2d53647 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Math/Fix64Vector2.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace MGF.Math 6 | { 7 | public struct Fix64Vector2 8 | { 9 | public Fix64 X; 10 | public Fix64 Y ; 11 | 12 | public static Fix64Vector2 operator / (Fix64Vector2 a,Fix64 cs) 13 | { 14 | return new Fix64Vector2(a.X / cs, a.Y / cs); 15 | } 16 | 17 | public static Fix64Vector2 operator *(Fix64Vector2 a, Fix64 cs) 18 | { 19 | return new Fix64Vector2(a.X * cs, a.Y * cs); 20 | } 21 | 22 | 23 | public static Fix64Vector2 operator *(Fix64Vector2 a, int cs) 24 | { 25 | return new Fix64Vector2(a.X * (Fix64)cs, a.Y * (Fix64)cs); 26 | } 27 | 28 | public static Fix64Vector2 operator -(Fix64Vector2 a, Fix64Vector2 cs) 29 | { 30 | return new Fix64Vector2(a.X - cs.X, a.Y - cs.Y); 31 | } 32 | 33 | public static Fix64Vector2 operator -(Fix64Vector2 a) 34 | { 35 | return new Fix64Vector2(-a.X , -a.Y); 36 | } 37 | 38 | public static Fix64Vector2 operator +(Fix64Vector2 a, Fix64Vector2 cs) 39 | { 40 | return new Fix64Vector2(a.X + cs.X, a.Y + cs.Y); 41 | } 42 | 43 | public Fix64Vector2(int x, int y) 44 | { 45 | X = new Fix64(x); 46 | Y = new Fix64(y); 47 | } 48 | 49 | public Fix64Vector2(float x, float y) 50 | { 51 | X = new Fix64(x); 52 | Y = new Fix64(y); 53 | } 54 | 55 | public Fix64Vector2(Fix64 x, Fix64 y) 56 | { 57 | X = x; 58 | Y = y; 59 | } 60 | 61 | public Fix64 Magnitude() 62 | { 63 | return Fix64.Sqrt((X * X) + (Y * Y)); 64 | } 65 | 66 | public Fix64Vector2 Nomalize() 67 | { 68 | return this / this.Magnitude(); 69 | } 70 | 71 | public Vector2 ToVector2() 72 | { 73 | return new Vector2((float)X, (float)Y); 74 | } 75 | 76 | public Vector3 ToVector3() 77 | { 78 | return new Vector3((float)X ,1f ,(float)Y); 79 | } 80 | 81 | public Vector3 ToVector3Zero() 82 | { 83 | return new Vector3((float)X, 0, (float)Y); 84 | } 85 | 86 | public static Fix64 Distance(Fix64Vector2 a, Fix64Vector2 b) 87 | { 88 | Fix64 a2 = Fix64.FastAbs(a.X - b.X); 89 | Fix64 b2 = Fix64.FastAbs(a.Y - b.Y); 90 | 91 | return Fix64.Sqrt(a2 * a2 + b2 * b2); 92 | } 93 | 94 | public static Fix64 Dot(Fix64Vector2 a, Fix64Vector2 b) 95 | { 96 | return (a.X * b.X) + (a.Y * b.Y); 97 | } 98 | 99 | public static Fix64 Angle(Fix64Vector2 a, Fix64Vector2 b) 100 | { 101 | return Fix64.Acos(Dot(a.Nomalize(), b.Nomalize())); 102 | } 103 | 104 | public static Fix64Vector2 Rotate(Fix64Vector2 iA, Fix64 degrees) 105 | { 106 | degrees *= Fix64.DegreeToRad; 107 | Fix64Vector2 A = new Fix64Vector2(0, 0); 108 | A.X = (iA.X * Fix64.Cos(degrees) - iA.Y * Fix64.Sin(degrees)); 109 | A.Y = (iA.X * Fix64.Sin(degrees) + iA.Y * Fix64.Cos(degrees)); 110 | 111 | return A; 112 | } 113 | 114 | public static Fix64Vector2 SetVertex(Fix64 X, Fix64 Y) 115 | { 116 | return new Fix64Vector2(X, Y); 117 | } 118 | 119 | public override string ToString() 120 | { 121 | return "X:" + X.ToString() + System.Environment.NewLine + "Y:" + Y.ToString(); 122 | } 123 | 124 | } 125 | 126 | 127 | } 128 | 129 | 130 | -------------------------------------------------------------------------------- /Assets/MGF/Math/Fix64Vector2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 42e5bf4ceaed6b94cbbc57b770b6b5d5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02af18398ae813042821ca876f27ca9b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4264c551e21930a4d9ae601301f93932 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Example/ModuleExample.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF.Framework; 5 | using System; 6 | using MGF; 7 | 8 | namespace MGF.Framework.Example 9 | { 10 | public class ModuleExample : MonoBehaviour 11 | { 12 | // Start is called before the first frame update 13 | void Start() 14 | { 15 | ModuleManager.Instance.Init("MGF.Framework"); 16 | ModuleManager.Instance.CreateModule("ModuleA"); 17 | ModuleManager.Instance.CreateModule("ModuleB"); 18 | } 19 | 20 | // Update is called once per frame 21 | void Update() 22 | { 23 | 24 | } 25 | } 26 | 27 | 28 | 29 | public class ModuleA : BusinessModule 30 | { 31 | public override void Create(object args = null) 32 | { 33 | base.Create(args); 34 | 35 | 36 | 37 | //业务层通过ModuleManager通信 38 | ModuleManager.Instance.Event("ModuleB", "onModuleEventB").AddListener(OnModuleEventB); 39 | 40 | //业务层调用服务层 用过事件监听回调 41 | ModuleC.Instance.OnEvent.AddListener(OnModuleEventC); 42 | ModuleC.Instance.DoSomething(); 43 | 44 | } 45 | 46 | private void OnModuleEventC(object arg0) 47 | { 48 | this.Log("ModuleA Invoke Service ModuleC"); 49 | } 50 | 51 | private void OnModuleEventB(object arg0) 52 | { 53 | this.Log("ModuleB Receive Event From ModuleA: " + arg0); 54 | } 55 | } 56 | 57 | 58 | public class ModuleB : BusinessModule 59 | { 60 | public ModuleEvent onModuleEventB { get { return Event("onModuleEventB"); } } 61 | 62 | public override void Create(object args = null) 63 | { 64 | base.Create(args); 65 | onModuleEventB.Invoke("aaaa"); 66 | } 67 | 68 | } 69 | 70 | 71 | 72 | public class ModuleC : ServiceModule 73 | { 74 | public ModuleEvent OnEvent = new ModuleEvent(); 75 | 76 | public void DoSomething() 77 | { 78 | OnEvent.Invoke(null); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Example/ModuleExample.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 164ecde86044d414491fd4dac43d207e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 81317f6aabe90954fbc2e2e3371f1997 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/BusinessModule.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace MGF.Framework 4 | { 5 | public abstract class BusinessModule : Module 6 | { 7 | private string m_name = null; 8 | 9 | public string Name 10 | { 11 | get 12 | { 13 | if (m_name == null) 14 | { 15 | m_name = this.GetType().Name; 16 | } 17 | return m_name; 18 | } 19 | } 20 | 21 | public string Title; 22 | 23 | public BusinessModule() 24 | { 25 | 26 | } 27 | 28 | internal BusinessModule(string name) 29 | { 30 | m_name = name; 31 | } 32 | 33 | 34 | 35 | private EventTable m_tblEvent; 36 | 37 | /// 38 | /// 实现抽象事件功能 39 | /// 可以像这样使用:obj.Event("onLogin").AddListener(...) 40 | /// 事件的发送方法:this.Event("onLogin").Invoke(args) 41 | /// 而不需要在编码时先定义好,以提高模块的抽象程度 42 | /// 但是在模块内部的类不应该过于抽象,比如数据发生更新了, 43 | /// 在UI类这样使用:obj.onUpdate.AddListener(...) 44 | /// 这两种方法在使用形式上,保持了一致性! 45 | /// 46 | /// 47 | /// 48 | public ModuleEvent Event(string type) 49 | { 50 | return GetEventTable().GetEvent(type); 51 | } 52 | 53 | internal void SetEventTable(EventTable mgrEvent) 54 | { 55 | m_tblEvent = mgrEvent; 56 | } 57 | 58 | protected EventTable GetEventTable() 59 | { 60 | if (m_tblEvent == null) 61 | { 62 | m_tblEvent = new EventTable(); 63 | } 64 | return m_tblEvent; 65 | } 66 | 67 | 68 | 69 | /// 70 | /// 调用它以创建模块 71 | /// 72 | /// 73 | public virtual void Create(object args = null) 74 | { 75 | this.Log("Create() args = " + args); 76 | 77 | } 78 | 79 | 80 | /// 81 | /// 调用它以释放模块 82 | /// 83 | public override void Release() 84 | { 85 | if (m_tblEvent != null) 86 | { 87 | m_tblEvent.Clear(); 88 | m_tblEvent = null; 89 | } 90 | 91 | base.Release(); 92 | } 93 | 94 | 95 | /// 96 | /// 当模块收到消息后,对消息进行一些处理 97 | /// 98 | /// 99 | /// 100 | internal void HandleMessage(string msg, object[] args) 101 | { 102 | this.Log("HandleMessage() msg:{0}, args:{1}", msg, args); 103 | 104 | MethodInfo mi = this.GetType().GetMethod(msg, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); 105 | if (mi != null) 106 | { 107 | mi.Invoke(this, BindingFlags.NonPublic, null, args, null); 108 | } 109 | else 110 | { 111 | OnModuleMessage(msg, args); 112 | } 113 | } 114 | 115 | 116 | /// 117 | /// 由派生类去实现,用于处理消息 118 | /// 119 | /// 120 | /// 121 | protected virtual void OnModuleMessage(string msg, object[] args) 122 | { 123 | this.Log("OnModuleMessage() msg:{0}, args:{1}", msg, args); 124 | } 125 | 126 | 127 | /// 128 | /// 显示业务模块的主UI 129 | /// 一般业务模块都有UI,这是游戏业务模块的特点 130 | /// 131 | protected virtual void Show(object arg) 132 | { 133 | this.Log("Show() arg:{0}", arg); 134 | } 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/BusinessModule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed3d72f6fd24d0f4e8c38822d889c14b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/EventTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UnityEngine.Events; 7 | 8 | namespace MGF.Framework 9 | { 10 | public class ModuleEvent : UnityEvent 11 | { 12 | 13 | } 14 | 15 | public class ModuleEvent : UnityEvent 16 | { 17 | internal void AddListener(object connectRes) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } 22 | public class EventTable 23 | { 24 | private Dictionary m_mapEvents; 25 | 26 | 27 | /// 28 | /// 获取Type所指定的ModuleEvent(它其实是一个EventTable) 29 | /// 如果不存在,则实例化一个 30 | /// 31 | /// 32 | /// 33 | public ModuleEvent GetEvent(string type) 34 | { 35 | if (m_mapEvents == null) 36 | { 37 | m_mapEvents = new Dictionary(); 38 | } 39 | if (!m_mapEvents.ContainsKey(type)) 40 | { 41 | m_mapEvents.Add(type, new ModuleEvent()); 42 | } 43 | return m_mapEvents[type]; 44 | } 45 | 46 | public void Clear() 47 | { 48 | if (m_mapEvents != null) 49 | { 50 | foreach (var @event in m_mapEvents) 51 | { 52 | @event.Value.RemoveAllListeners(); 53 | } 54 | m_mapEvents.Clear(); 55 | } 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/EventTable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be74878c93777ee4298ec2ac8869c8f6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/LuaModule.cs: -------------------------------------------------------------------------------- 1 | namespace MGF.Framework 2 | { 3 | public class LuaModule : BusinessModule 4 | { 5 | private object m_args; 6 | 7 | /// 8 | /// 构造函数传入Name 9 | /// 是因为Lua模块无法通过反射来获取Name 10 | /// 11 | /// 12 | internal LuaModule(string name) : base(name) { } 13 | 14 | 15 | /// 16 | /// 这里应该去加载Lua脚本 17 | /// 并且将EventManager映射到Lua脚本中 18 | /// 19 | /// 20 | public override void Create(object args = null) 21 | { 22 | base.Create(args); 23 | this.Log("Create() Lua = " + Name); 24 | m_args = args; 25 | 26 | EventTable mgrEvent = GetEventTable(); 27 | //TODO 需要映射到Lua脚本中 28 | } 29 | 30 | 31 | 32 | /// 33 | /// 调用它以卸载Lua脚本 34 | /// 35 | public override void Release() 36 | { 37 | base.Release(); 38 | this.Log("Release() Lua = " + Name); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/LuaModule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 95381d461d186b44fa92eba9931a7d80 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/Module.cs: -------------------------------------------------------------------------------- 1 | using MGF; 2 | using System; 3 | using UnityEngine.Events; 4 | 5 | namespace MGF.Framework 6 | { 7 | 8 | public abstract class Module 9 | { 10 | /// 11 | /// 调用它以释放模块 12 | /// 13 | public virtual void Release() 14 | { 15 | this.Log("Release"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/Module.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8950d68ac60184d4695016af841ccfd5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/ModuleManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d07a72935dae25b4fb5c3d7c64265d6c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/ServiceModule.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 MGF.Framework 8 | { 9 | public abstract class ServiceModule : Module where T : ServiceModule, new() 10 | { 11 | private static T ms_instance = default(T); 12 | 13 | public static T Instance 14 | { 15 | get 16 | { 17 | if (ms_instance == null) 18 | { 19 | ms_instance = new T(); 20 | } 21 | return ms_instance; 22 | } 23 | 24 | } 25 | 26 | //public ServiceModule() 27 | //{ 28 | 29 | // var exp = new Exception("ServiceModule<" + typeof(T).Name + "> 无法直接实例化,因为它是一个单例!"); 30 | // throw exp; 31 | 32 | //} 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/ServiceModule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b009f35bd01e1a742ac901ed274cb048 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/Singleton.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | namespace MGF.Framework 5 | { 6 | public abstract class Singletom where T : new() 7 | { 8 | private static T _instance; 9 | private static object mutex = new object(); 10 | public static T Instance 11 | { 12 | get 13 | { 14 | if (_instance == null) 15 | { 16 | lock (mutex) 17 | { 18 | if (_instance == null) 19 | { 20 | _instance = new T(); 21 | } 22 | } 23 | } 24 | return _instance; 25 | } 26 | } 27 | } 28 | 29 | // Monobeavior: 声音, 网络 30 | // Unity单例 31 | 32 | public class UnitySingletom : MonoBehaviour 33 | where T : Component 34 | { 35 | private static T _instance = null; 36 | public static T Instance 37 | { 38 | get 39 | { 40 | if (_instance == null) 41 | { 42 | _instance = FindObjectOfType(typeof(T)) as T; 43 | if (_instance == null) 44 | { 45 | GameObject obj = new GameObject(); 46 | _instance = (T)obj.AddComponent(typeof(T)); 47 | obj.hideFlags = HideFlags.DontSave; 48 | // obj.hideFlags = HideFlags.HideAndDontSave; 49 | obj.name = typeof(T).Name; 50 | } 51 | } 52 | return _instance; 53 | } 54 | } 55 | 56 | public virtual void Awake() 57 | { 58 | DontDestroyOnLoad(this.gameObject); 59 | if (_instance == null) 60 | { 61 | _instance = this as T; 62 | } 63 | else 64 | { 65 | GameObject.Destroy(this.gameObject); 66 | } 67 | } 68 | } 69 | 70 | 71 | public class SceneSingletom : MonoBehaviour 72 | where T : Component 73 | { 74 | private static T _instance = null; 75 | public static T Instance 76 | { 77 | get 78 | { 79 | if (_instance == null) 80 | { 81 | _instance = FindObjectOfType(typeof(T)) as T; 82 | if (_instance == null) 83 | { 84 | GameObject obj = new GameObject(); 85 | _instance = (T)obj.AddComponent(typeof(T)); 86 | obj.hideFlags = HideFlags.DontSave; 87 | // obj.hideFlags = HideFlags.HideAndDontSave; 88 | obj.name = typeof(T).Name; 89 | } 90 | } 91 | return _instance; 92 | } 93 | } 94 | 95 | public virtual void Awake() 96 | { 97 | if (_instance == null) 98 | { 99 | _instance = this as T; 100 | } 101 | 102 | } 103 | } 104 | } 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Assets/MGF/Module/Framework/Singleton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92eeda72f17b7344c983f09c09234352 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Module/GlobalEvent.cs: -------------------------------------------------------------------------------- 1 | using MGF.Framework; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | public class GlobalEvent 7 | { 8 | public static ModuleEvent GlobalUpdate = new ModuleEvent(); 9 | } 10 | -------------------------------------------------------------------------------- /Assets/MGF/Module/GlobalEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a814448ef4f7b5a45a5efe2622e76d71 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Physics.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e07feb95bc15f9478466525f517f3d1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Physics/MGFPhysics.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF.Math; 5 | using MGF.Physics; 6 | 7 | namespace MGF.Physics 8 | { 9 | internal static class MGFPhysics 10 | { 11 | 12 | internal static bool lineIntersection(Fix64Vector2 p0, Fix64Vector2 p1, 13 | Fix64Vector2 p2, Fix64Vector2 p3, out Fix64Vector2 point) 14 | { 15 | Fix64 s02_x, s02_y, s10_x, s10_y, s32_x, s32_y, s_numer, t_numer, denom, t; 16 | s10_x = p1.X - p0.X; 17 | s10_y = p1.Y - p0.Y; 18 | s32_x = p3.X - p2.X; 19 | s32_y = p3.Y - p2.Y; 20 | point = new Fix64Vector2(0, 0); 21 | denom = s10_x * s32_y - s32_x * s10_y; 22 | if (denom == Fix64.Zero)//平行或共线 23 | return false; // Collinear 24 | bool denomPositive = denom > Fix64.Zero; 25 | 26 | s02_x = p0.X - p2.X; 27 | s02_y = p0.Y - p2.Y; 28 | s_numer = s10_x * s02_y - s10_y * s02_x; 29 | if ((s_numer < Fix64.Zero) == denomPositive)//参数是大于等于0且小于等于1的,分子分母必须同号且分子小于等于分母 30 | return false; // No collision 31 | 32 | t_numer = s32_x * s02_y - s32_y * s02_x; 33 | if ((t_numer < Fix64.Zero) == denomPositive) 34 | return false; // No collision 35 | 36 | if (((s_numer > denom) == denomPositive) || ((t_numer > denom) == denomPositive)) 37 | return false; // No collision 38 | // Collision detected 39 | t = t_numer / denom; 40 | point.X = p0.X + (t * s10_x); 41 | point.Y = p0.Y + (t * s10_y); 42 | return true; 43 | } 44 | 45 | internal static bool CheckBoundings(MGFObject a, MGFObject b) 46 | { 47 | Fix64Vector2 posA = a.GetPos(); 48 | Fix64Vector2 posB = b.GetPos(); 49 | return Fix64.Abs(posA.X - posB.X) < a.GetHalfSize().X + b.GetHalfSize().X && 50 | Fix64.Abs(posA.Y - posB.Y) < a.GetHalfSize().Y + b.GetHalfSize().Y; 51 | 52 | } 53 | 54 | public static bool GJK(MGFObject a, MGFObject b) 55 | { 56 | Simplex s = new Simplex(); 57 | Fix64Vector2 dir = a.GetPos() - b.GetPos(); 58 | s.Add(Support(a, b, dir)); 59 | dir = -dir; 60 | 61 | while (true) 62 | { 63 | s.Add(Support(a, b, dir)); 64 | if (Fix64Vector2.Dot(s.GetLast(), dir) <= Fix64.Zero) 65 | { 66 | return false; 67 | } 68 | else 69 | { 70 | if (ContainsOrigin(s, ref dir)) 71 | { 72 | return true; 73 | } 74 | } 75 | } 76 | } 77 | 78 | private static bool ContainsOrigin(Simplex s, ref Fix64Vector2 dir) 79 | { 80 | 81 | var a = s.GetLast(); 82 | var AO = -a; 83 | var b = s.GetB(); 84 | var AB = b - a; 85 | if (s.Count() == 3) 86 | { 87 | var c = s.GetC(); 88 | var AC = c - a; 89 | 90 | var abPerp = CalcNomal(AC, AB, AB); 91 | var acPerp = CalcNomal(AB, AC, AC); 92 | 93 | if (Fix64Vector2.Dot(abPerp, AO) > Fix64.Zero) 94 | { 95 | s.Remove(c); 96 | dir = abPerp; 97 | } 98 | else 99 | { 100 | if (Fix64Vector2.Dot(acPerp, AO) > Fix64.Zero) 101 | { 102 | s.Remove(b); 103 | dir = acPerp; 104 | } 105 | else 106 | { 107 | return true; 108 | } 109 | } 110 | } 111 | else 112 | { 113 | 114 | var abPerp = CalcNomal(AB, AO, AB); 115 | dir = abPerp; 116 | } 117 | return false; 118 | } 119 | 120 | private static Fix64Vector2 CalcNomal(Fix64Vector2 a, Fix64Vector2 b, Fix64Vector2 c) 121 | { 122 | Fix64 z = a.X * b.Y - a.Y * b.X; 123 | 124 | return new Fix64Vector2(-z * c.Y, z * c.X); 125 | } 126 | 127 | private static Fix64Vector2 Support(MGFObject a, MGFObject b, Fix64Vector2 d) 128 | { 129 | Fix64Vector2 InA = a.Support(d); 130 | Fix64Vector2 InB = b.Support(-d); 131 | return InA - InB; 132 | } 133 | 134 | private class Simplex 135 | { 136 | private List list = new List(); 137 | 138 | public void Add(Fix64Vector2 point) 139 | { 140 | list.Add(point); 141 | } 142 | 143 | 144 | public Fix64Vector2 GetLast() 145 | { 146 | return list[list.Count - 1]; 147 | } 148 | 149 | public Fix64Vector2 GetB() 150 | { 151 | return list[list.Count - 2]; 152 | } 153 | public Fix64Vector2 GetC() 154 | { 155 | return list[list.Count - 3]; 156 | } 157 | 158 | public void Remove(Fix64Vector2 point) 159 | { 160 | list.Remove(point); 161 | } 162 | 163 | public int Count() 164 | { 165 | return list.Count; 166 | } 167 | } 168 | } 169 | 170 | } 171 | 172 | -------------------------------------------------------------------------------- /Assets/MGF/Physics/MGFPhysics.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 11d4f84ab0b235845bf4b409f1bae2bf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Physics/PhysicsManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF.Framework; 5 | using MGF.Math; 6 | using System; 7 | 8 | namespace MGF.Physics 9 | { 10 | public class PhysicsManager : ServiceModule 11 | { 12 | 13 | 14 | private HashSet m_Objects = new HashSet(); 15 | private HashSet m_DynamicObjs = new HashSet(); 16 | private Quadtree m_Qt; 17 | 18 | /// 19 | /// 初始化 20 | /// 21 | /// 22 | /// 23 | public void Init(MGFObject[] mgfList, Rectangle planePos) 24 | { 25 | m_Qt = new Quadtree(0, planePos); 26 | if (mgfList != null && mgfList.Length != 0) 27 | { 28 | 29 | for (int i = 0; i < mgfList.Length; i++) 30 | { 31 | mgfList[i].Init(); 32 | mgfList[i].MGFEnable(); 33 | m_Objects.Add(mgfList[i]); 34 | if (mgfList[i].IsCollisionAble != false) 35 | { 36 | m_Qt.Insert(mgfList[i]); 37 | } 38 | if (mgfList[i].IsStatic == false) 39 | { 40 | m_DynamicObjs.Add(mgfList[i]); 41 | } 42 | } 43 | 44 | } 45 | } 46 | 47 | /// 48 | /// 添加物体 49 | /// 50 | /// 51 | public void AddObject(MGFObject mGFObject) 52 | { 53 | m_Qt.Insert(mGFObject); 54 | } 55 | 56 | /// 57 | /// 销毁物体 58 | /// 59 | /// 60 | public void DesObject(MGFObject mGFObject) 61 | { 62 | m_Qt.Remove(mGFObject); 63 | Quadtree.dic[mGFObject] = null; 64 | } 65 | 66 | /// 67 | /// 获得所有物体 68 | /// 69 | /// 70 | public IEnumerable GetAllObjects() 71 | { 72 | return m_Objects; 73 | } 74 | 75 | /// 76 | /// 获得所有动态物体 77 | /// 78 | /// 79 | public IEnumerable GetAllDynamicObjs() 80 | { 81 | return m_DynamicObjs; 82 | } 83 | 84 | /// 85 | /// 获得所有物体 86 | /// 87 | /// 88 | internal Quadtree GetQuadtree() 89 | { 90 | return m_Qt; 91 | } 92 | 93 | /// 94 | /// 射线 95 | /// 96 | /// 97 | /// 98 | /// 99 | public IEnumerable RayCast2D(Fix64Vector2 start, Fix64Vector2 end) 100 | { 101 | HashSet ls = new HashSet(); 102 | foreach (var item in m_Objects) 103 | { 104 | Fix64Vector2 hit; 105 | Fix64Vector2[] vertex = item.GetVertex(); 106 | Fix64Vector2[] vertexN = new Fix64Vector2[vertex.Length]; 107 | for (int j = 0; j < vertexN.Length; j++) 108 | { 109 | vertexN[j] = vertex[j] + item.GetPos(); 110 | 111 | } 112 | for (int j = 0; j < 4; j++) 113 | { 114 | int nt = j + 1; 115 | if (j == 3) 116 | { 117 | nt = 0; 118 | } 119 | if (MGFPhysics.lineIntersection(start, end, vertexN[j], vertexN[nt], out hit)) 120 | { 121 | Debug.Log(item.name + " line P1" + vertexN[j] + " P2 " + vertexN[nt] + " hit " + hit); 122 | ls.Add(item); 123 | break; 124 | } 125 | } 126 | } 127 | return ls; 128 | } 129 | 130 | private HashSet lcd = new HashSet(); 131 | /// 132 | /// 碰撞检测 133 | /// 134 | public void CheckCollision() 135 | { 136 | foreach (var item in m_DynamicObjs) 137 | { 138 | if (item.IsCollisionAble == false) 139 | { 140 | continue; 141 | } 142 | if (lcd.Count != 0) 143 | { 144 | lcd.Clear(); 145 | } 146 | //获得需要进行碰撞检测的list 147 | m_Qt.Retrieve(lcd, item); 148 | bool flag = false; 149 | foreach (var item2 in lcd) 150 | { 151 | if (MGFPhysics.CheckBoundings(item2, item)) 152 | { 153 | if (MGFPhysics.GJK(item, item2)) 154 | { 155 | flag = true; 156 | item.CalcCollisionDir(item2); 157 | item.OnMGFCollision(item2); 158 | Debug.Log(item.name + " " + item2.name); 159 | } 160 | } 161 | } 162 | item.IsCollsioning = flag; 163 | } 164 | 165 | } 166 | 167 | /// 168 | /// 物体移动时调用 169 | /// 170 | /// 171 | public void Move(MGFObject mgf) 172 | { 173 | m_Qt.Move(mgf); 174 | } 175 | } 176 | } 177 | 178 | -------------------------------------------------------------------------------- /Assets/MGF/Physics/PhysicsManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 956ab9ca1ee909747a5a2798411557a6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Physics/Quadtree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d38693654e9976439228fa5e532acc7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 711dba3342e7acb4c9bf6eeb5a62c672 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9b57f17bda187d4b931d77c7d63fec4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIExample.cs: -------------------------------------------------------------------------------- 1 | using MGF.Framework; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace MGF.Framework.Example 7 | { 8 | public class UIExample : MonoBehaviour 9 | { 10 | // Start is called before the first frame update 11 | void Start() 12 | { 13 | UIManager.Instance.Init("ui/"); 14 | UIManager.MainPage = "UIPage1"; 15 | UIManager.Instance.EnterMainPage(); 16 | } 17 | 18 | // Update is called once per frame 19 | void Update() 20 | { 21 | 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIExample.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7719fa3dea039704bb096be1e8f8ca8e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIPage1.cs: -------------------------------------------------------------------------------- 1 | using MGF.Framework; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | 7 | namespace MGF.Framework.Example 8 | { 9 | public class UIPage1 : UIPage 10 | { 11 | protected override void OnClose(object arg = null) 12 | { 13 | base.OnClose(arg); 14 | } 15 | 16 | protected override void OnOpen(object arg = null) 17 | { 18 | base.OnOpen(arg); 19 | } 20 | 21 | public void OnBtnOpenPage2() 22 | { 23 | UIManager.Instance.OpenPage("UIPage2"); 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIPage1.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a772917612f648b4383d80f0c4b3dd78 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIPage2.cs: -------------------------------------------------------------------------------- 1 | using MGF; 2 | using MGF.Framework; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using UnityEngine; 6 | 7 | 8 | namespace MGF.Framework.Example 9 | { 10 | public class UIPage2 : UIPage 11 | { 12 | public void OnBtnOpenWnd1() 13 | { 14 | UIManager.Instance.OpenWindow("UIWnd1").onClose += OnWnd1Close; 15 | } 16 | 17 | private void OnWnd1Close(object arg) 18 | { 19 | //this.Log("OnWnd1Close()"); 20 | } 21 | 22 | public void OnBtnOpenWidget1() 23 | { 24 | UIManager.Instance.OpenWidget("UIWidget1"); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIPage2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a14b42abddfa4f4a9b0aae7a1478c5d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIWidget1.cs: -------------------------------------------------------------------------------- 1 | using MGF.Framework; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | 7 | 8 | namespace MGF.Framework.Example 9 | { 10 | public class UIWidget1 : UIWidget 11 | { 12 | 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIWidget1.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f5bae1822c53da04a95988e062d2a7e5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIWnd1.cs: -------------------------------------------------------------------------------- 1 | using MGF; 2 | using MGF.Framework; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using UnityEngine; 6 | 7 | 8 | 9 | namespace MGF.Framework.Example 10 | { 11 | public class UIWnd1 : UIWindow 12 | { 13 | public void OnBtnOpenWnd1() 14 | { 15 | UIManager.Instance.OpenWindow("UIWnd1").onClose += OnWnd1Close; 16 | } 17 | 18 | private void OnWnd1Close(object arg) 19 | { 20 | //this.Log("OnWnd1Close()"); 21 | } 22 | 23 | public void OnBtnOpenWidget1() 24 | { 25 | UIManager.Instance.OpenWidget("UIWidget1"); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Example/UIWnd1.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b97cd8aaf89d9d41835bc71d28c7935 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92556486882a41b42962a07c83ea2139 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d7373f11e16f754b8933c51da6631c9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIPage.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | 4 | namespace MGF.Framework 5 | { 6 | public class UIPage : UIPanel 7 | { 8 | /// 9 | /// 返回按钮,大部分Page都会有返回按钮 10 | /// 11 | [SerializeField] 12 | private Button m_btnGoBack; 13 | 14 | /// 15 | /// 打开UI的参数 16 | /// 17 | protected object m_openArg; 18 | 19 | /// 20 | /// 该UI的当前实例是否曾经被打开过 21 | /// 22 | private bool m_isOpenedOnce; 23 | 24 | /// 25 | /// 当UIPage被激活时调用 26 | /// 27 | protected void OnEnable() 28 | { 29 | this.Log("OnEnable()"); 30 | if (m_btnGoBack != null) 31 | { 32 | m_btnGoBack.onClick.AddListener(OnBtnGoBack); 33 | } 34 | 35 | #if UNITY_EDITOR 36 | if (m_isOpenedOnce) 37 | { 38 | //如果UI曾经被打开过, 39 | //则可以通过UnityEditor来快速触发Open/Close操作 40 | //方便调试 41 | OnOpen(m_openArg); 42 | } 43 | #endif 44 | } 45 | 46 | /// 47 | /// 当UI不可用时调用 48 | /// 49 | protected void OnDisable() 50 | { 51 | this.Log("OnDisable()"); 52 | #if UNITY_EDITOR 53 | if (m_isOpenedOnce) 54 | { 55 | //如果UI曾经被打开过, 56 | //则可以通过UnityEditor来快速触发Open/Close操作 57 | //方便调试 58 | OnClose(); 59 | } 60 | #endif 61 | if (m_btnGoBack != null) 62 | { 63 | m_btnGoBack.onClick.RemoveAllListeners(); 64 | } 65 | } 66 | 67 | 68 | /// 69 | /// 当点击“返回”时调用 70 | /// 但是并不是每一个Page都有返回按钮 71 | /// 72 | private void OnBtnGoBack() 73 | { 74 | this.Log("OnBtnGoBack()"); 75 | UIManager.Instance.GoBackPage(); 76 | } 77 | 78 | /// 79 | /// 调用它打开UIPage 80 | /// 81 | /// 82 | public sealed override void Open(object arg = null) 83 | { 84 | this.Log("Open()"); 85 | m_openArg = arg; 86 | m_isOpenedOnce = false; 87 | 88 | if (!this.gameObject.activeSelf) 89 | { 90 | this.gameObject.SetActive(true); 91 | } 92 | 93 | OnOpen(arg); 94 | m_isOpenedOnce = true; 95 | } 96 | 97 | public sealed override void Close(object arg = null) 98 | { 99 | this.Log("Close()"); 100 | if (this.gameObject.activeSelf) 101 | { 102 | this.gameObject.SetActive(false); 103 | } 104 | 105 | OnClose(arg); 106 | } 107 | 108 | } 109 | } -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIPage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22135521881ce0d45a4156b39caf7632 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIPanel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.UI; 4 | 5 | namespace MGF.Framework 6 | { 7 | public abstract class UIPanel : MonoBehaviour 8 | { 9 | public bool IsOpen{ get { return gameObject.activeSelf; } } 10 | 11 | /// 12 | /// 用于UI框架逻辑的填写 13 | /// 14 | /// 15 | public virtual void Open(object arg = null) 16 | { 17 | this.Log("Open() arg:{0}", arg); 18 | } 19 | 20 | public virtual void Close(object arg = null) 21 | { 22 | this.Log("Close() arg:{0}", arg); 23 | } 24 | 25 | 26 | 27 | /// 28 | /// 当UI关闭时,会响应这个函数 29 | /// 该函数在重写时,需要支持可重复调用 30 | /// 用于填写业务逻辑的实现 31 | /// 32 | protected virtual void OnClose(object arg = null) 33 | { 34 | this.Log("OnClose()"); 35 | } 36 | 37 | /// 38 | /// 当UI打开时,会响应这个函数 39 | /// 40 | /// 41 | protected virtual void OnOpen(object arg = null) 42 | { 43 | this.Log("OnOpen() "); 44 | 45 | } 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIPanel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 506ffd39c8881514881444e34569dfda 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIRes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace MGF.Framework 5 | { 6 | public static class UIRes 7 | { 8 | public static string UIResRoot = "ui/"; 9 | 10 | /// 11 | /// 加载UI的Prefab 12 | /// 13 | /// 14 | /// 15 | public static GameObject LoadPrefab(string name) 16 | { 17 | GameObject asset = (GameObject)Resources.Load(UIResRoot + name); 18 | return asset; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIRes.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e0ce30ee6319fa49bc3c0ff5f8d7573 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIRoot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using MGF; 4 | 5 | namespace MGF.Framework 6 | { 7 | public class UIRoot: MonoBehaviour 8 | { 9 | public const string LOG_TAG = "UIRoot"; 10 | 11 | /// 12 | /// 从UIRoot下通过类型寻找一个组件对象 13 | /// 14 | /// 15 | /// 16 | public static T Find() where T : MonoBehaviour 17 | { 18 | string name = typeof(T).Name; 19 | GameObject obj = Find(name); 20 | if (obj != null) 21 | { 22 | return obj.GetComponent(); 23 | } 24 | 25 | 26 | return null; 27 | } 28 | 29 | /// 30 | /// 从UIRoot下通过名字&类型寻找一个组件对象 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static T Find(string name) where T : MonoBehaviour 36 | { 37 | GameObject obj = Find(name); 38 | if (obj != null) 39 | { 40 | return obj.GetComponent(); 41 | 42 | } 43 | 44 | return null; 45 | } 46 | 47 | /// 48 | /// 在UIRoot下通过名字寻找一个GameObject对象 49 | /// 50 | /// 51 | /// 52 | public static GameObject Find(string name) 53 | { 54 | Transform obj = null; 55 | GameObject root = FindUIRoot(); 56 | if (root != null) 57 | { 58 | obj = root.transform.Find(name); 59 | } 60 | 61 | if (obj != null) 62 | { 63 | return obj.gameObject; 64 | } 65 | 66 | //this.l(LOG_TAG, "Find()", "UI:{0} 不存在!",name); 67 | return null; 68 | } 69 | 70 | /// 71 | /// 当前场景中寻找UIRoot对象 72 | /// 73 | /// 74 | public static GameObject FindUIRoot() 75 | { 76 | GameObject root = GameObject.Find("UIRoot"); 77 | if (root != null && root.GetComponent() != null) 78 | { 79 | return root; 80 | } 81 | //Debugger.LogError(LOG_TAG, "FindUIRoot()", "UIRoot Is Not Exist!!!"); 82 | return null; 83 | } 84 | 85 | /// 86 | /// 当一个UIPage/UIWindow/UIWidget添加到UIRoot下面 87 | /// 88 | /// 89 | public static void AddChild(UIPanel child) 90 | { 91 | GameObject root = FindUIRoot(); 92 | if (root == null || child == null) 93 | { 94 | return; 95 | } 96 | 97 | 98 | child.transform.SetParent(root.transform, false); 99 | return; 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIRoot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a3afe0086a66e841aaed41bb2285bd9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UnityEngine.EventSystems; 7 | using UnityEngine.UI; 8 | using UnityEngine; 9 | 10 | namespace MGF.Framework 11 | { 12 | class UIUtils 13 | { 14 | /// 15 | /// 设置一个UI元素是否可见 16 | /// 17 | /// 18 | /// 19 | public static void SetActive(UIBehaviour ui, bool value) 20 | { 21 | if (ui != null && ui.gameObject != null) 22 | { 23 | ui.gameObject.SetActive(value); 24 | } 25 | } 26 | 27 | 28 | public static void SetButtonText(Button btn, string text) 29 | { 30 | Text objText = btn.transform.GetComponentInChildren(); 31 | if (objText != null) 32 | { 33 | objText.text = text; 34 | } 35 | } 36 | 37 | public static string GetButtonText(Button btn) 38 | { 39 | Text objText = btn.transform.GetComponentInChildren(); 40 | if (objText != null) 41 | { 42 | return objText.text; 43 | } 44 | return ""; 45 | } 46 | 47 | public static void SetChildText(UIBehaviour ui, string text) 48 | { 49 | Text objText = ui.transform.GetComponentInChildren(); 50 | if (objText != null) 51 | { 52 | objText.text = text; 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0bf9817a053d163479cf9b6db4760f24 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIWidget.cs: -------------------------------------------------------------------------------- 1 | namespace MGF.Framework 2 | { 3 | public class UIWidget : UIPanel 4 | { 5 | /// 6 | /// 打开UI的参数 7 | /// 8 | protected object m_openArg; 9 | 10 | /// 11 | /// 调用它打开UIWindow 12 | /// 13 | /// 14 | public sealed override void Open(object arg = null) 15 | { 16 | this.Log("Open() arg:{0}", arg); 17 | m_openArg = arg; 18 | if (!this.gameObject.activeSelf) 19 | { 20 | this.gameObject.SetActive(true); 21 | } 22 | 23 | OnOpen(arg); 24 | } 25 | 26 | /// 27 | /// 调用它以关闭UIWindow 28 | /// 29 | public sealed override void Close(object arg = null) 30 | { 31 | this.Log("Close() arg:{0}", arg); 32 | if (this.gameObject.activeSelf) 33 | { 34 | 35 | this.gameObject.SetActive(false); 36 | } 37 | 38 | OnClose(arg); 39 | } 40 | 41 | } 42 | } -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIWidget.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec8ff76326603d54dbf8f3749379e7ae 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | 4 | namespace MGF.Framework 5 | { 6 | public class UIWindow: UIPanel 7 | { 8 | 9 | 10 | public delegate void CloseEvent(object arg = null); 11 | 12 | //======================================================================= 13 | /// 14 | /// 关闭按钮,大部分窗口都会有关闭按钮 15 | /// 16 | [SerializeField] 17 | private Button m_btnClose; 18 | 19 | /// 20 | /// 窗口关闭事件 21 | /// 22 | public event CloseEvent onClose; 23 | 24 | /// 25 | /// 打开UI的参数 26 | /// 27 | protected object m_openArg; 28 | 29 | /// 30 | /// 该UI的当前实例是否曾经被打开过 31 | /// 32 | private bool m_isOpenedOnce = false; 33 | 34 | 35 | 36 | /// 37 | /// 当UI可用时调用 38 | /// 39 | protected void OnEnable() 40 | { 41 | this.Log("OnEnable()"); 42 | if (m_btnClose != null) 43 | { 44 | m_btnClose.onClick.AddListener(OnBtnClose); 45 | } 46 | } 47 | 48 | /// 49 | /// 当UI不可用时调用 50 | /// 51 | protected void OnDisable() 52 | { 53 | this.Log("OnDisable()"); 54 | 55 | if (m_btnClose != null) 56 | { 57 | m_btnClose.onClick.RemoveAllListeners(); 58 | } 59 | 60 | 61 | } 62 | 63 | /// 64 | /// 当点击关闭按钮时调用 65 | /// 但是并不是每一个Window都有关闭按钮 66 | /// 67 | private void OnBtnClose() 68 | { 69 | this.Log("OnBtnClose()"); 70 | Close(0); 71 | } 72 | 73 | 74 | /// 75 | /// UI第一次打开时调用,第一次调用不会触发OnOpen 76 | /// 77 | /// 78 | protected virtual void UIInit(object arg = null) 79 | { 80 | 81 | 82 | 83 | } 84 | 85 | 86 | 87 | /// 88 | /// 调用它打开UIWindow 89 | /// 90 | /// 91 | public sealed override void Open(object arg = null) 92 | { 93 | this.Log("Open() arg:{0}", arg); 94 | m_openArg = arg; 95 | this.gameObject.SetActive(true); 96 | if (m_isOpenedOnce == false) 97 | { 98 | UIInit(arg); 99 | } 100 | else 101 | { 102 | OnOpen(arg); 103 | } 104 | m_isOpenedOnce = true; 105 | } 106 | 107 | /// 108 | /// 调用它以关闭UIWindow 109 | /// 110 | public sealed override void Close(object arg = null) 111 | { 112 | this.Log("Close()"); 113 | 114 | //if (gameObject.activeSelf) 115 | //{ 116 | // gameObject.SetActive(false); 117 | //} 118 | 119 | OnClose(arg); 120 | if (onClose != null) 121 | { 122 | onClose(arg); 123 | onClose = null; 124 | } 125 | } 126 | 127 | } 128 | } -------------------------------------------------------------------------------- /Assets/MGF/UI/Framework/UIWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4ade7363ae191b4a963774ce1ae6741 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Utils.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13d9c7fb3f487cc43b2c86640fe69515 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/CoroutineTool.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MGF.Framework; 5 | 6 | public class CoroutineTool : UnitySingletom 7 | { 8 | public void Coroutine() 9 | { 10 | StartCoroutine(ICoroutine()); 11 | } 12 | 13 | 14 | IEnumerator ICoroutine() 15 | { 16 | yield return null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/CoroutineTool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6d7ce3b763cbbc9419672c499b58084e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/FileUtils.cs: -------------------------------------------------------------------------------- 1 |  2 | using MGF; 3 | using System; 4 | using System.IO; 5 | using System.Runtime.Serialization.Formatters.Binary; 6 | using System.Text; 7 | 8 | 9 | namespace MGF.Utils 10 | { 11 | public class FileUtils 12 | { 13 | private const string LOG_TAG = "FileUtils"; 14 | 15 | public static byte[] ReadFile(string fullpath) 16 | { 17 | byte[] buffer = null; 18 | if (File.Exists(fullpath)) 19 | { 20 | FileStream fs = null; 21 | try 22 | { 23 | using (fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read)) 24 | { 25 | buffer = new byte[fs.Length]; 26 | fs.Read(buffer, 0, buffer.Length); 27 | } 28 | 29 | } 30 | catch (Exception e) 31 | { 32 | Debugger.LogError(LOG_TAG, "ReadFile() Path:{0}, Error:{1}", fullpath, e.Message); 33 | } 34 | finally 35 | { 36 | if (fs != null) 37 | { 38 | fs.Close(); 39 | fs.Dispose(); 40 | } 41 | } 42 | } 43 | else 44 | { 45 | Debugger.LogError(LOG_TAG, "ReadFile() File is Not Exist: {0}", fullpath); 46 | } 47 | return buffer; 48 | } 49 | 50 | public static string ReadString(string fullpath) 51 | { 52 | byte[] buffer = ReadFile(fullpath); 53 | if (buffer != null) 54 | { 55 | return Encoding.UTF8.GetString(buffer); 56 | } 57 | return ""; 58 | } 59 | 60 | public static string ReadStringASCII(string fullpath) 61 | { 62 | byte[] buffer = ReadFile(fullpath); 63 | if (buffer != null) 64 | { 65 | return Encoding.ASCII.GetString(buffer); 66 | } 67 | return ""; 68 | } 69 | 70 | public static int SaveFile(string fullpath, byte[] content) 71 | { 72 | if (content == null) 73 | { 74 | content = new byte[0]; 75 | } 76 | 77 | string dir = PathUtils.GetParentDir(fullpath); 78 | 79 | if (!Directory.Exists(dir)) 80 | { 81 | try 82 | { 83 | Directory.CreateDirectory(dir); 84 | } 85 | catch (Exception e) 86 | { 87 | Debugger.LogError(LOG_TAG, "SaveFile() CreateDirectory Error! Dir:{0}, Error:{1}", dir, e.Message); 88 | return -1; 89 | } 90 | 91 | } 92 | 93 | FileStream fs = null; 94 | try 95 | { 96 | using (fs = new FileStream(fullpath, FileMode.OpenOrCreate, FileAccess.Write)) 97 | { 98 | fs.Write(content, 0, content.Length); 99 | } 100 | 101 | } 102 | catch (Exception e) 103 | { 104 | Debugger.LogError(LOG_TAG, "SaveFile() Path:{0}, Error:{1}", fullpath, e.Message); 105 | fs.Close(); 106 | fs.Dispose(); 107 | return -1; 108 | } 109 | return content.Length; 110 | } 111 | 112 | public static int SaveFile(string fullpath, string content) 113 | { 114 | byte[] buffer = Encoding.UTF8.GetBytes(content); 115 | return SaveFile(fullpath, buffer); 116 | } 117 | 118 | public static byte[] SerializeToBinary(object obj) 119 | { 120 | byte[] data; 121 | using (MemoryStream stream = new MemoryStream()) 122 | { 123 | BinaryFormatter bf = new BinaryFormatter(); 124 | bf.Serialize(stream, obj); 125 | data = stream.ToArray(); 126 | } 127 | return data; 128 | } 129 | 130 | public static T DeserializeWithBinary(byte[] data) 131 | { 132 | T obj; 133 | using (MemoryStream stream = new MemoryStream()) 134 | { 135 | stream.Write(data, 0, data.Length); 136 | stream.Position = 0; 137 | BinaryFormatter bf = new BinaryFormatter(); 138 | obj = (T)bf.Deserialize(stream); 139 | } 140 | return obj; 141 | } 142 | } 143 | } 144 | 145 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/FileUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d0eb25517f40014e87354dd18aa39d8 3 | timeCreated: 1489934439 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/MGF/Utils/IRecycleAble.cs: -------------------------------------------------------------------------------- 1 | public interface IRecycleAble 2 | { 3 | int InitNum(); 4 | string RecycleName(); 5 | } -------------------------------------------------------------------------------- /Assets/MGF/Utils/IRecycleAble.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b81c77ece7c10644b2234b15dccb782 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/ObjectPool.cs: -------------------------------------------------------------------------------- 1 | using MGF.Math; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using UnityEngine; 6 | using UnityEngine.Assertions; 7 | 8 | public class ObjectPool 9 | { 10 | 11 | private Dictionary> rcDic = new Dictionary>(); 12 | 13 | /// 14 | /// 增加一种新的对象 15 | /// 16 | /// 17 | /// 18 | public void AddNewObj(string name, Queue rc) 19 | { 20 | if (!rcDic.ContainsKey(name)) 21 | { 22 | rcDic.Add(name, rc); 23 | } 24 | else 25 | { 26 | for (int i = 0; i < rc.Count; i++) 27 | { 28 | rcDic[name].Enqueue(rc.Dequeue()); 29 | } 30 | } 31 | } 32 | 33 | /// 34 | /// 回收对象 35 | /// 36 | /// 37 | /// 38 | public void DestoryObj(string name, IRecycleAble rc) 39 | { 40 | Assert.IsTrue(rc != null); 41 | Assert.IsTrue(rcDic.ContainsKey(name)); 42 | rcDic[name].Enqueue(rc); 43 | } 44 | 45 | /// 46 | /// 创建对象 47 | /// 48 | /// 49 | /// 50 | /// 51 | public T CreateObj(string name) where T : MGFObject 52 | { 53 | Assert.IsTrue(rcDic.ContainsKey(name)); 54 | if (rcDic[name].Count > 0) 55 | { 56 | IRecycleAble ls = rcDic[name].Dequeue(); 57 | return (T)ls; 58 | } 59 | else 60 | { 61 | throw new Exception("no obj exist!!!"); 62 | } 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/ObjectPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d2b14480544328419609a58427ddb23 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/PathUtils.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | namespace MGF.Utils 6 | { 7 | 8 | public class PathUtils 9 | { 10 | public static readonly string[] PathHeadDefine = { "jar://", "jar:file:///", "file:///", "http://", "https://" }; 11 | 12 | public static bool IsSureDir(string path) 13 | { 14 | int i = path.LastIndexOf("/"); 15 | if (i >= 0) 16 | { 17 | return true; 18 | } 19 | i = path.LastIndexOf("\\"); 20 | if (i >= 0) 21 | { 22 | return true; 23 | } 24 | return false; 25 | } 26 | 27 | public static bool IsFullPath(string path) 28 | { 29 | int i = path.IndexOf(":/"); 30 | if (i >= 0) 31 | { 32 | return true; 33 | } 34 | 35 | i = path.IndexOf(":\\"); 36 | if (i >= 0) 37 | { 38 | return true; 39 | } 40 | 41 | return false; 42 | } 43 | 44 | 45 | public static string GetFileName(string path) 46 | { 47 | string parent = "", child = ""; 48 | SplitPath(path, ref parent, ref child, true); 49 | return child; 50 | } 51 | 52 | public static string GetParentDir(string path) 53 | { 54 | string parent = "", child = ""; 55 | SplitPath(path, ref parent, ref child, true); 56 | return parent; 57 | } 58 | 59 | public static string SplitPath(string path, ref string parent, ref string child, bool bSplitExt = false) 60 | { 61 | string ext = ""; 62 | string head = SplitPath(path, ref parent, ref child, ref ext); 63 | if (bSplitExt) 64 | { 65 | return head; 66 | } 67 | if (!string.IsNullOrEmpty(ext)) 68 | { 69 | child = child + "." + ext; 70 | } 71 | return head; 72 | } 73 | 74 | public static string SplitPath(string path, ref string parent, ref string child, ref string ext) 75 | { 76 | string head = GetPathHead(path); 77 | 78 | int index = path.LastIndexOf("/"); 79 | int index2 = path.LastIndexOf("\\"); 80 | index = System.Math.Max(index, index2); 81 | 82 | if (index == head.Length - 1) 83 | { 84 | parent = ""; 85 | child = path; 86 | } 87 | else 88 | { 89 | parent = path.Substring(0, index); 90 | child = path.Substring(index + 1); 91 | } 92 | 93 | index = child.LastIndexOf("."); 94 | if (index >= 0) 95 | { 96 | ext = child.Substring(index + 1); 97 | child = child.Substring(0, index); 98 | 99 | } 100 | 101 | return head; 102 | } 103 | 104 | public static string GetPathHead(string path) 105 | { 106 | for (int i = 0; i < PathHeadDefine.Length; i++) 107 | { 108 | if (path.StartsWith(PathHeadDefine[i])) 109 | { 110 | return PathHeadDefine[i]; 111 | } 112 | } 113 | 114 | return ""; 115 | } 116 | 117 | 118 | 119 | 120 | public static string MakePathFitPlatform(string path) 121 | { 122 | if (UnityEngine.Application.platform == UnityEngine.RuntimePlatform.IPhonePlayer || 123 | UnityEngine.Application.platform == UnityEngine.RuntimePlatform.OSXEditor || UnityEngine.Application.platform == UnityEngine.RuntimePlatform.OSXPlayer) 124 | { 125 | path = path.Replace("\\", "/"); 126 | } 127 | return path; 128 | } 129 | 130 | } 131 | 132 | 133 | 134 | } 135 | -------------------------------------------------------------------------------- /Assets/MGF/Utils/PathUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4cb2935d186ab74ea6e3d19605b8d36 3 | timeCreated: 1489934439 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 YouRenJee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 1024 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_SpatializerPlugin: 15 | m_AmbisonicDecoderPlugin: 16 | m_DisableAudio: 0 17 | m_VirtualizeEffects: 1 18 | -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 8 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 0 23 | m_ReuseCollisionCallbacks: 1 24 | m_ClothInterCollisionSettingsToggle: 0 25 | m_ContactPairsMode: 0 26 | m_BroadphaseType: 0 27 | m_WorldBounds: 28 | m_Center: {x: 0, y: 0, z: 0} 29 | m_Extent: {x: 250, y: 250, z: 250} 30 | m_WorldSubdivisions: 8 31 | -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: 8 | - enabled: 1 9 | path: Assets/Scenes/SampleScene.unity 10 | guid: 99c9720ab356a0642a771bea13969a05 11 | m_configObjects: {} 12 | -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_SpritePackerMode: 0 12 | m_SpritePackerPaddingPower: 1 13 | m_EtcTextureCompressorBehavior: 1 14 | m_EtcTextureFastCompressor: 1 15 | m_EtcTextureNormalCompressor: 2 16 | m_EtcTextureBestCompressor: 4 17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd 18 | m_ProjectGenerationRootNamespace: 19 | m_UserGeneratedProjectSuffix: 20 | m_CollabEditorSettings: 21 | inProgressEnabled: 1 22 | -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | - {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0} 39 | m_PreloadedShaders: [] 40 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 41 | type: 0} 42 | m_CustomRenderPipeline: {fileID: 0} 43 | m_TransparencySortMode: 0 44 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 45 | m_DefaultRenderingPath: 1 46 | m_DefaultMobileRenderingPath: 1 47 | m_TierSettings: [] 48 | m_LightmapStripping: 0 49 | m_FogStripping: 0 50 | m_InstancingStripping: 0 51 | m_LightmapKeepPlain: 1 52 | m_LightmapKeepDirCombined: 1 53 | m_LightmapKeepDynamicPlain: 1 54 | m_LightmapKeepDynamicDirCombined: 1 55 | m_LightmapKeepShadowMask: 1 56 | m_LightmapKeepSubtractive: 1 57 | m_FogKeepLinear: 1 58 | m_FogKeepExp: 1 59 | m_FogKeepExp2: 1 60 | m_AlbedoSwatchInfos: [] 61 | m_LightsUseLinearIntensity: 0 62 | m_LightsUseColorTemperature: 0 63 | -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_AutoSimulation: 1 23 | m_QueriesHitTriggers: 1 24 | m_QueriesStartInColliders: 1 25 | m_ChangeStopsCallbacks: 0 26 | m_CallbacksOnDisable: 1 27 | m_ReuseCollisionCallbacks: 1 28 | m_AutoSyncTransforms: 0 29 | m_AlwaysShowColliders: 0 30 | m_ShowColliderSleep: 1 31 | m_ShowColliderContacts: 0 32 | m_ShowColliderAABB: 0 33 | m_ContactArrowScale: 0.2 34 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 35 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 36 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 37 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 38 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 39 | -------------------------------------------------------------------------------- /ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | m_DefaultList: 7 | - type: 8 | m_NativeTypeID: 108 9 | m_ManagedTypePPtr: {fileID: 0} 10 | m_ManagedTypeFallback: 11 | defaultPresets: 12 | - m_Preset: {fileID: 2655988077585873504, guid: c1cf8506f04ef2c4a88b64b6c4202eea, 13 | type: 2} 14 | - type: 15 | m_NativeTypeID: 1020 16 | m_ManagedTypePPtr: {fileID: 0} 17 | m_ManagedTypeFallback: 18 | defaultPresets: 19 | - m_Preset: {fileID: 2655988077585873504, guid: 0cd792cc87e492d43b4e95b205fc5cc6, 20 | type: 2} 21 | - type: 22 | m_NativeTypeID: 1006 23 | m_ManagedTypePPtr: {fileID: 0} 24 | m_ManagedTypeFallback: 25 | defaultPresets: 26 | - m_Preset: {fileID: 2655988077585873504, guid: 7a99f8aa944efe94cb9bd74562b7d5f9, 27 | type: 2} 28 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 4 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | particleRaycastBudget: 4 33 | asyncUploadTimeSlice: 2 34 | asyncUploadBufferSize: 16 35 | resolutionScalingFixedDPIFactor: 1 36 | excludedTargetPlatforms: [] 37 | - serializedVersion: 2 38 | name: Low 39 | pixelLightCount: 0 40 | shadows: 0 41 | shadowResolution: 0 42 | shadowProjection: 1 43 | shadowCascades: 1 44 | shadowDistance: 20 45 | shadowNearPlaneOffset: 3 46 | shadowCascade2Split: 0.33333334 47 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 48 | shadowmaskMode: 0 49 | blendWeights: 2 50 | textureQuality: 0 51 | anisotropicTextures: 0 52 | antiAliasing: 0 53 | softParticles: 0 54 | softVegetation: 0 55 | realtimeReflectionProbes: 0 56 | billboardsFaceCameraPosition: 0 57 | vSyncCount: 0 58 | lodBias: 0.4 59 | maximumLODLevel: 0 60 | particleRaycastBudget: 16 61 | asyncUploadTimeSlice: 2 62 | asyncUploadBufferSize: 16 63 | resolutionScalingFixedDPIFactor: 1 64 | excludedTargetPlatforms: [] 65 | - serializedVersion: 2 66 | name: Medium 67 | pixelLightCount: 1 68 | shadows: 1 69 | shadowResolution: 0 70 | shadowProjection: 1 71 | shadowCascades: 1 72 | shadowDistance: 20 73 | shadowNearPlaneOffset: 3 74 | shadowCascade2Split: 0.33333334 75 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 76 | shadowmaskMode: 0 77 | blendWeights: 2 78 | textureQuality: 0 79 | anisotropicTextures: 1 80 | antiAliasing: 0 81 | softParticles: 0 82 | softVegetation: 0 83 | realtimeReflectionProbes: 0 84 | billboardsFaceCameraPosition: 0 85 | vSyncCount: 1 86 | lodBias: 0.7 87 | maximumLODLevel: 0 88 | particleRaycastBudget: 64 89 | asyncUploadTimeSlice: 2 90 | asyncUploadBufferSize: 16 91 | resolutionScalingFixedDPIFactor: 1 92 | excludedTargetPlatforms: [] 93 | - serializedVersion: 2 94 | name: High 95 | pixelLightCount: 2 96 | shadows: 2 97 | shadowResolution: 1 98 | shadowProjection: 1 99 | shadowCascades: 2 100 | shadowDistance: 40 101 | shadowNearPlaneOffset: 3 102 | shadowCascade2Split: 0.33333334 103 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 104 | shadowmaskMode: 1 105 | blendWeights: 2 106 | textureQuality: 0 107 | anisotropicTextures: 1 108 | antiAliasing: 2 109 | softParticles: 0 110 | softVegetation: 1 111 | realtimeReflectionProbes: 1 112 | billboardsFaceCameraPosition: 1 113 | vSyncCount: 1 114 | lodBias: 1 115 | maximumLODLevel: 0 116 | particleRaycastBudget: 256 117 | asyncUploadTimeSlice: 2 118 | asyncUploadBufferSize: 16 119 | resolutionScalingFixedDPIFactor: 1 120 | excludedTargetPlatforms: [] 121 | - serializedVersion: 2 122 | name: Very High 123 | pixelLightCount: 3 124 | shadows: 2 125 | shadowResolution: 2 126 | shadowProjection: 1 127 | shadowCascades: 2 128 | shadowDistance: 40 129 | shadowNearPlaneOffset: 3 130 | shadowCascade2Split: 0.33333334 131 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 132 | shadowmaskMode: 1 133 | blendWeights: 4 134 | textureQuality: 0 135 | anisotropicTextures: 1 136 | antiAliasing: 4 137 | softParticles: 1 138 | softVegetation: 1 139 | realtimeReflectionProbes: 1 140 | billboardsFaceCameraPosition: 1 141 | vSyncCount: 1 142 | lodBias: 1.5 143 | maximumLODLevel: 0 144 | particleRaycastBudget: 1024 145 | asyncUploadTimeSlice: 2 146 | asyncUploadBufferSize: 16 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Ultra 151 | pixelLightCount: 4 152 | shadows: 2 153 | shadowResolution: 2 154 | shadowProjection: 1 155 | shadowCascades: 4 156 | shadowDistance: 150 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 1 164 | antiAliasing: 4 165 | softParticles: 1 166 | softVegetation: 1 167 | realtimeReflectionProbes: 1 168 | billboardsFaceCameraPosition: 1 169 | vSyncCount: 1 170 | lodBias: 2 171 | maximumLODLevel: 0 172 | particleRaycastBudget: 4096 173 | asyncUploadTimeSlice: 2 174 | asyncUploadBufferSize: 16 175 | resolutionScalingFixedDPIFactor: 1 176 | excludedTargetPlatforms: [] 177 | m_PerPlatformDefaultQuality: 178 | Android: 2 179 | Nintendo 3DS: 5 180 | Nintendo Switch: 5 181 | PS4: 5 182 | PSP2: 2 183 | Standalone: 5 184 | Tizen: 2 185 | WebGL: 3 186 | WiiU: 5 187 | Windows Store Apps: 5 188 | XboxOne: 5 189 | iPhone: 2 190 | tvOS: 2 191 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - PostProcessing 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.1 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 1 7 | m_Enabled: 0 8 | m_TestMode: 0 9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events 10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events 11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com 12 | m_TestInitMode: 0 13 | CrashReportingSettings: 14 | m_EventUrl: https://perf-events.cloud.unity3d.com 15 | m_Enabled: 0 16 | m_LogBufferSize: 10 17 | m_CaptureEditorExceptions: 1 18 | UnityPurchasingSettings: 19 | m_Enabled: 0 20 | m_TestMode: 0 21 | UnityAnalyticsSettings: 22 | m_Enabled: 1 23 | m_TestMode: 0 24 | m_InitializeOnStartup: 1 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /ProjectSettings/VFXManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!937362698 &1 4 | VFXManager: 5 | m_ObjectHideFlags: 0 6 | m_IndirectShader: {fileID: 0} 7 | m_CopyBufferShader: {fileID: 0} 8 | m_SortShader: {fileID: 0} 9 | m_RenderPipeSettingsPath: 10 | m_FixedTimeStep: 0.016666668 11 | m_MaxDeltaTime: 0.05 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LockstepFundation 2 | =========================== 3 | 一个基于Unity的简单的帧同步基础,包含定点数学库,基于四叉树的多边形的碰撞检测以及射线检测 4 | 5 | 6 | 特性 7 | ------ 8 | - 实现了基于定点数的数学库以及简单的物理检测 9 | - 实现了基于2D平面的定制物理 10 | - 预留帧事件接口,方便多人游戏接入 11 | - 数据与视图的分离 12 | 13 | 入门及示例 14 | ------ 15 | 将整个工程直接使用Unity打开,其中MGF是核心文件与具体的业务无关,可以单独取出来使用,示例Demo场景存放在Demo/SampleScene.unity 16 | 17 | 使用版本:2018.3.2f1 18 | 19 | 20 | --------------------------------------------------------------------------------