diff options
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Unit/Characters')
7 files changed, 359 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBase.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBase.cs new file mode 100644 index 0000000..d27d853 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBase.cs @@ -0,0 +1,8 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CharacterBase +{ + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBase.cs.meta new file mode 100644 index 0000000..87e3ef5 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4997650a838b19e4a963da681b75b2d0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterInfo.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterInfo.cs new file mode 100644 index 0000000..950b7ae --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterInfo.cs @@ -0,0 +1,94 @@ +using JetBrains.Annotations; +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; +using WK.Data; +using WK; + +namespace WK +{ + + public class CharacterStatsCollection + { + + } + + public class CharacterBuffsCollection + { + + } + + public class CharacterPerksCollection + { + + } + + /// <summary> + /// 角色当前状态 + /// </summary> + public class CharacterInfo + { + + /// <summary> + /// 角色当前所有属性 + /// </summary> + private List<CharacterStats> m_Stats; + + public CharacterStatsCollection stats { get { return m_AllStats; } } + private CharacterStatsCollection m_AllStats; + + /// <summary> + /// 角色当前所有buff + /// </summary> + private List<Buff> m_Buffs; + + /// <summary> + /// 角色当前所有被动 + /// </summary> + private List<PerkBase> m_Perks; + + public CharacterStats this[string statsUID] + { + get + { + if (m_Stats == null) + { + return null; + } + return GetStats(statsUID); + } + } + + public CharacterStats GetStats(string statsUID) + { + for (int i = 0; i < m_Stats.Count; ++i) + { + if (m_Stats[i].uid == statsUID) + { + return m_Stats[i]; + } + } + return null; + } + + public bool HasStats(string statsUID) + { + for (int i = 0; i < m_Stats.Count; ++i) + { + if (m_Stats[i].uid == statsUID) + { + return true; + } + } + return false; + } + + public bool HasBuff(string buffUID) + { + return false; + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterInfo.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterInfo.cs.meta new file mode 100644 index 0000000..b3d2f04 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/CharacterInfo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 546d4837ddb2405438fd9a65adc9c5ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai.meta new file mode 100644 index 0000000..0900ff5 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0a0f49eb0a90f474e8dc4f85f08e20fd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai/SamuraiScript.cs b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai/SamuraiScript.cs new file mode 100644 index 0000000..966c3d0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai/SamuraiScript.cs @@ -0,0 +1,216 @@ +using JetBrains.Annotations; +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UIElements; + +namespace MH +{ + + public class UnitManager + { + public static UnitBase hero; + } + + public class SamuraiScript : UnitBase + { + [SerializeField] private WaypointScript m_Waypoint; + [SerializeField] private float m_Speed; + [SerializeField] private BladeScript m_Blade; + [SerializeField] private GameObject m_GroundBreak; + + private SpriteRenderer m_Sprite; + private bool m_Moving; + private Camera m_Camera; + private float m_TimeSinceLastMove; + private const float kKeepMovingThreshold = 0.4f; + private bool m_IsKeepMoving = false; + private Coroutine m_CoWaypoint; + private bool m_Attacking = false; + private bool m_IsKeepAttacking = false; + + private void Awake() + { + UnitManager.hero = this; + } + + void Start() + { + m_Camera = Camera.main; + m_Moving = true; + m_Sprite = GetComponent<SpriteRenderer>(); + m_TimeSinceLastMove = float.MaxValue; + StartCoroutine(CoAttack(1f)); + StartCoroutine(CoStrike(1f)); + } + + protected override void Update() + { + base.Update(); + Move(); + LookAt(); + } + + private void LookAt() + { + Vector3 pos = transform.position; + Vector3 camPos = m_Camera.transform.position; + camPos.x = pos.x; + camPos.y = pos.y; + m_Camera.transform.position = camPos; + } + + private void Move() + { + if(Input.GetMouseButtonDown(0)) + { + float dt = Time.time - m_TimeSinceLastMove; + if(dt > 0 && dt < kKeepMovingThreshold) + { + m_IsKeepMoving = true; + } + else + { + m_IsKeepMoving = false; + } + } + + m_Attacking = true;//Input.GetMouseButton(1); + + if (Input.GetMouseButton(0) || m_IsKeepMoving) + { + m_Moving = true; + + Vector3 mousePos = Input.mousePosition; + Vector3 mousePos3D = m_Camera.ScreenToWorldPoint(mousePos); + mousePos3D.z = 0; + + Vector3 pos = transform.position; + pos.z = 0; + + Vector3 toward = mousePos3D - pos; + toward.z = 0; + + if (toward.magnitude < 0.1f) + { + return; + } + + Vector3 dir = (mousePos3D - pos).normalized; + dir.z = 0; + + //pos.x += Time.deltaTime; + transform.position += dir * Time.deltaTime * m_Speed; + + m_Sprite.flipX = dir.x <= 0; + + if(m_CoWaypoint == null) + { + m_CoWaypoint = StartCoroutine(CoShowWaypoint(0.05f)); + } + } + else + { + if(m_CoWaypoint != null) + { + StopCoroutine(m_CoWaypoint); + m_CoWaypoint = null; + } + + m_Moving = false; + } + + GetComponent<Animator>().speed = m_Moving ? 1 : 0; + + if(Input.GetMouseButtonUp(0)) + { + m_TimeSinceLastMove = Time.time; + } + } + + IEnumerator CoShowWaypoint(float dt) + { + while (true) + { + WaypointScript waypoint = Instantiate(m_Waypoint) as WaypointScript; + Vector3 mousePos = Input.mousePosition; + Vector3 mousePos3D = m_Camera.ScreenToWorldPoint(mousePos); + mousePos3D.z = 0; + waypoint.transform.position = mousePos3D; + waypoint.life = 1; + yield return new WaitForSeconds(dt); + } + } + + IEnumerator CoAttack(float interval) + { + int fac = 1; + while (true) + { + if (!m_Attacking) + { + yield return null; + } + else + { + Vector3 mousePos = Input.mousePosition; + Vector3 mousePos3D = m_Camera.ScreenToWorldPoint(mousePos); + Vector2 dir = (mousePos3D.xy() - transform.position.xy()).normalized; + BladeScript blade = Instantiate(m_Blade); + blade.life = 5f; + blade.transform.position = transform.position + new Vector3(1 * fac, 1f, 0); + blade.SetFlip(fac == -1); + blade.dir = dir; + fac *= -1; + yield return new WaitForSeconds(interval); + } + } + } + + IEnumerator CoStrike(float interval) + { + int fac = 1; + while (true) + { + if (!m_Attacking) + { + yield return null; + } + else + { + yield return new WaitForSeconds(interval); + yield return new WaitForFixedUpdate(); + Strike(); + } + } + } + + private void Strike() + { + Vector3 pos = transform.position; + + float radius = 2; + + var go = Instantiate(m_GroundBreak); + go.transform.position = pos; + go.gameObject.SetActive(true); + go.transform.localScale *= radius / 1.7f; + + var colliders = PhysicsManager.Instance.CircleCast(ColliderType.Hurtbox, new Vector3(pos.x, pos.y, radius)); + if (colliders.Count != 0) + { + for(int i = 0; i < colliders.Count; ++i) + { + go = (colliders[i] as MonoBehaviour).gameObject; + if(go != this.gameObject) + { + GameObject.Destroy(go); + } + } + } + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai/SamuraiScript.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai/SamuraiScript.cs.meta new file mode 100644 index 0000000..9f84435 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters/Samurai/SamuraiScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aebd1bb3a775f7748832acc6222117cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |