diff options
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts')
11 files changed, 106 insertions, 27 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs b/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs index ae5a132..b4de592 100644 --- a/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs +++ b/WorldlineKeepers/Assets/Scripts/Common/CommonFunction.cs @@ -1,7 +1,11 @@ +using System; +using System.Reflection; +using System.Reflection.Emit; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; +using System.Linq; public static class CommonFunction { @@ -22,4 +26,27 @@ public static class CommonFunction File.WriteAllText(file, content); } + public static Type GetTypeByName(string name) + { + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Reverse()) + { + var tt = assembly.GetType(name); + if (tt != null) + { + return tt; + } + } + + return null; + } + + public static System.Object CreateInstance(string typeName) + { + Type t = GetTypeByName(typeName); + if (t == null) + return null; + var obj = Activator.CreateInstance(t); + return obj; + } + } diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs index 6e12d6e..9b29871 100644 --- a/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs +++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager_Data.cs @@ -15,9 +15,6 @@ namespace WK.Data private Dictionary<string/*uid*/, CharacterStatsMetadata> m_CharacterStatsMetadata = new Dictionary<string, CharacterStatsMetadata>(); private Dictionary<string/*uid*/, BuffMetadata> m_BuffMetadata = new Dictionary<string, BuffMetadata>(); - private Dictionary<string/*uid*/, CharacterMetadata> m_CharacterMetadata = new Dictionary<string, CharacterMetadata>(); - - } diff --git a/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs b/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs index 0fd18df..4f63517 100644 --- a/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs @@ -28,6 +28,17 @@ namespace WK #endif } + public T LoadAssetFullPath<T>(string fullPath) where T : UnityEngine.Object + { +#if UNITY_EDITOR + string path = fullPath; + T obj = AssetDatabase.LoadAssetAtPath(path, typeof(T)) as T; + return obj; +#else + return null ; +#endif + } + /// <summary> /// 根据filekey读资源 /// </summary> diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs index 61c7f7d..d84619d 100644 --- a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs @@ -24,6 +24,10 @@ public partial class PhysicsManager : Singleton<PhysicsManager> m_StaticCollisionQuadtree = new PhysicsQuadtree(new Vector4(0, 0, 30, 30)); } + public void Initialize() + { + } + public System.Func<Vector4, bool> GetRetriverByType(ColliderType type) { if (type == ColliderType.Collider) diff --git a/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs b/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs index 5721c58..963bc29 100644 --- a/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs +++ b/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs @@ -4,15 +4,7 @@ using UnityEngine; public class ProjectileBase : MonoBehaviour { - // Start is called before the first frame update - void Start() - { - - } - // Update is called once per frame - void Update() - { - - } + + } diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Berserker/BerserkerBuilder.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Berserker/BerserkerBuilder.cs index 9601783..4887062 100644 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Berserker/BerserkerBuilder.cs +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Berserker/BerserkerBuilder.cs @@ -8,9 +8,9 @@ namespace WK public class BerserkerBuilder : CharacterBuilder { - protected override PlayerController BuildPhaseController() + protected override PlayerController BuildPhase_Controller() { - return base.BuildPhaseController(); + return base.BuildPhase_Controller(); } } diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBuilder.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBuilder.cs index c51d565..3293db4 100644 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBuilder.cs +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBuilder.cs @@ -11,29 +11,42 @@ namespace WK protected GameObject m_Root; protected CharacterMetadata m_Metadata; - public GameObject Build(CharacterMetadata metadata) + public PlayerController Build(CharacterMetadata metadata) { m_Metadata = metadata; - m_Root = BuildPhaseRootGameObject(); + PlayerController controller = BuildPhase_Controller(); - return m_Root; + m_Root = BuildPhase_RootGameObject(); + controller.SetGameObject(m_Root); + + CharacterBehaviour behaviour = BuildPhase_Behaviour(); + controller.SetBehaviour(behaviour); + + return controller; } - protected virtual GameObject BuildPhaseRootGameObject() + protected virtual GameObject BuildPhase_RootGameObject() { GameObject go = new GameObject(); + TransformUtils.ResetLocal(go.transform); + go.name = m_Metadata.uid; + + GameObject prefab = ResourceManager.Instance.LoadAssetFullPath<GameObject>(m_Metadata.prefab); + GameObject model = GameObject.Instantiate<GameObject>(prefab); + model.transform.SetParent(go.transform); return go; } - protected virtual PlayerController BuildPhaseController() + protected virtual CharacterBehaviour BuildPhase_Behaviour() { - return null; + CharacterBehaviour behaviour = CommonFunction.CreateInstance(m_Metadata.behaviour) as CharacterBehaviour; + return behaviour; } - protected virtual void BuildPhaseSpriteRenderer() + protected virtual PlayerController BuildPhase_Controller() { - + return null; } } diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs index c8409da..c33e9fc 100644 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterMetadata.cs @@ -6,6 +6,9 @@ using UnityEngine; namespace WK.Data { + /// <summary> + /// 角色json + /// </summary> public class CharacterMetadata { public string uid; @@ -20,6 +23,8 @@ namespace WK.Data public string level_stats; + public string prefab; + public Dictionary<string, string> extra_data; } diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs index de13acb..0156045 100644 --- a/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/PlayerController.cs @@ -5,6 +5,7 @@ using UnityEngine; namespace WK { // 玩家角色数据结构 + // // PlayerController // CharacterInfo // CharacterStats @@ -40,20 +41,30 @@ namespace WK { } + public void SetGameObject(GameObject go) + { + m_GameObject = go; + } + + public void SetBehaviour(CharacterBehaviour behaviour) + { + m_CharacterBehaviour = behaviour; + } + /// <summary> /// 逻辑更新 /// </summary> public void OnUpdate() { // preupdate - behaviour.OnPreUpdate(); + behaviour?.OnPreUpdate(); // update - info.OnUpdate(); - behaviour.OnUpdate(); + info?.OnUpdate(); + behaviour?.OnUpdate(); // post update - behaviour.OnPostUpdate(); + behaviour?.OnPostUpdate(); } } diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Enemies/EnemyBase.cs b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/EnemyBase.cs new file mode 100644 index 0000000..dbc2966 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/EnemyBase.cs @@ -0,0 +1,8 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EnemyBase +{ + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Enemies/EnemyBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/EnemyBase.cs.meta new file mode 100644 index 0000000..6d07655 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/EnemyBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a3b6053f1824a04bb95605f81d5d5fb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |