diff options
Diffstat (limited to 'SurvivalTest/Assets/Scripts')
14 files changed, 266 insertions, 52 deletions
diff --git a/SurvivalTest/Assets/Scripts/Buff.meta b/SurvivalTest/Assets/Scripts/Buff.meta new file mode 100644 index 0000000..e60844c --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Buff.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4433b6b2b33098a4cb8751a508e130de +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Buff/BuffBase.cs b/SurvivalTest/Assets/Scripts/Buff/BuffBase.cs new file mode 100644 index 0000000..4e8149a --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Buff/BuffBase.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BuffBase : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/Buff/BuffBase.cs.meta b/SurvivalTest/Assets/Scripts/Buff/BuffBase.cs.meta new file mode 100644 index 0000000..863f7d5 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Buff/BuffBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e9640ba90ab79b046a3a331f704dfaf2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs b/SurvivalTest/Assets/Scripts/Items/ItemBase.cs index 7e4414f..e7cecd6 100644 --- a/SurvivalTest/Assets/Scripts/Items/ItemBase.cs +++ b/SurvivalTest/Assets/Scripts/Items/ItemBase.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using UnityEngine; /// <summary> -/// 饰品,加BUFF +/// 物品,可以加Buff、提升属性、技能附加效果 /// </summary> public class ItemBase : MonoBehaviour { diff --git a/SurvivalTest/Assets/Scripts/Items/Item_Boot.cs b/SurvivalTest/Assets/Scripts/Items/Item_Boot.cs index 1421a35..4a31d57 100644 --- a/SurvivalTest/Assets/Scripts/Items/Item_Boot.cs +++ b/SurvivalTest/Assets/Scripts/Items/Item_Boot.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using UnityEngine; /// <summary> -/// 靴子 +/// 靴子,提升移动速度、冲刺 /// </summary> public class Item_Boot : ItemBase { diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs index 57bd46f..e4e3879 100644 --- a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs @@ -72,9 +72,13 @@ public class TestPeaceMaker : CrewScript private Vector3 m_PreMouse; private Vector2 m_AimDirection; + private Vector2 m_MoveDirection; private Vector3 m_TargetZoom; + // 锁定瞄准,以移动方向为准 + private bool m_LockAim; + private enum ControlMode { Mouse, @@ -99,6 +103,8 @@ public class TestPeaceMaker : CrewScript void Update() { + LockAim(); + bool isMove = Move(); SetAim(); @@ -110,6 +116,14 @@ public class TestPeaceMaker : CrewScript CameraZoom(isFire); } + void LockAim() + { + if(Input.GetButtonDown("LockAim")) + { + m_LockAim = !m_LockAim; + } + } + void CameraZoom(bool zout) { if(zout) @@ -147,6 +161,8 @@ public class TestPeaceMaker : CrewScript { Vector2 direction = new Vector2(x, y).normalized; + m_MoveDirection = direction; + Vector3 position = m_Coord.position; position.x += direction.x * m_Speed * Time.deltaTime; position.y += direction.y * m_Speed * Time.deltaTime; @@ -170,6 +186,9 @@ public class TestPeaceMaker : CrewScript void SetAim() { + Vector2 dir = Vector2.zero; + Vector2 centrePos = m_Centre.position; + float xAxis = Input.GetAxisRaw("AimHorizontal"); float yAxis = Input.GetAxisRaw("AimVertical"); @@ -178,28 +197,35 @@ public class TestPeaceMaker : CrewScript bool bMouse = (Input.mousePosition - m_PreMouse).magnitude > 0.01f; m_PreMouse = Input.mousePosition; - if(bJoytick) - { - m_ControlMode = ControlMode.Joystick; - } - if(bMouse) - { - m_ControlMode = ControlMode.Mouse; - } - - Vector2 centrePos = m_Centre.position; - Vector2 dir = Vector2.zero; - if (m_ControlMode == ControlMode.Mouse) + if (m_LockAim && !bJoytick && !bMouse) { - Vector2 camPos = GetCameraPosition(); - dir = (camPos - centrePos).normalized; + dir = m_MoveDirection; } else { - dir = new Vector2(xAxis, -yAxis).normalized; + m_LockAim = false; + + if (bJoytick) + { + m_ControlMode = ControlMode.Joystick; + } + if (bMouse) + { + m_ControlMode = ControlMode.Mouse; + } + + if (m_ControlMode == ControlMode.Mouse) + { + Vector2 camPos = GetCameraPosition(); + dir = (camPos - centrePos).normalized; + } + else + { + dir = new Vector2(xAxis, -yAxis).normalized; + } } - if(dir.magnitude > 0) + if (dir.magnitude > 0) { m_AimDirection = dir; Vector2 arrowPos = centrePos + m_ArrowRadius * m_AimDirection; diff --git a/SurvivalTest/Assets/Scripts/Weapons/Boomerang.meta b/SurvivalTest/Assets/Scripts/Weapons/Boomerang.meta new file mode 100644 index 0000000..3ed9b00 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/Boomerang.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ec5e14b226b545d4fb3041c338d56321 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Boomerang.cs b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Boomerang.cs new file mode 100644 index 0000000..5d2a5bb --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Boomerang.cs @@ -0,0 +1,73 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 回旋镖 +/// </summary> +public class Boomerang : MonoBehaviour +{ + public BoomerangAfterImage m_AfterImage; + + private Vector2 m_Direction; + + // 当前速度 + private float m_Speed; + + // 最大飞行距离 + private float m_MaxDist; + + private float m_RotateSpeed = 500f; + + Coroutine m_CoAfterImage; + + public void Set(Vector2 dir, float speed, float maxDist) + { + m_Direction = dir; + m_Speed = speed; + m_MaxDist = maxDist; + + m_CoAfterImage = StartCoroutine(CoAfterImage(0.05f)); + } + + private void Update() + { + Vector2 move = m_Direction * m_Speed * Time.deltaTime; + + m_MaxDist -= move.magnitude; + if(m_MaxDist <= 0) + { + Destroy(this.gameObject); + + if (m_CoAfterImage != null) + { + StopCoroutine(m_CoAfterImage); + } + + return; + } + + Vector3 pos = transform.position; + pos += new Vector3(move.x, move.y, 0); + + transform.position = pos; + + transform.rotation *= Quaternion.Euler(0,0,m_RotateSpeed * Time.deltaTime); + } + + IEnumerator CoAfterImage(float interval) + { + while (true) + { + BoomerangAfterImage afterImage = BoomerangAfterImage.Instantiate(m_AfterImage); + afterImage.Set(this); + afterImage.transform.position = this.transform.position; + afterImage.transform.localScale= new Vector3(0.5f, 0.5f, 1f); + afterImage.transform.rotation = this.transform.rotation; + afterImage.gameObject.SetActive(true); + + yield return new WaitForSeconds(interval); + } + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Boomerang.cs.meta b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Boomerang.cs.meta new file mode 100644 index 0000000..d400625 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Boomerang.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4679a949f0f94fe47b708ff7b0d7ffb9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Weapons/Boomerang/BoomerangAfterImage.cs b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/BoomerangAfterImage.cs new file mode 100644 index 0000000..25461ae --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/BoomerangAfterImage.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BoomerangAfterImage : MonoBehaviour +{ + public SpriteRenderer sr; + + + Boomerang m_Boomerang; + + public void Set(Boomerang boomerang) + { + m_Boomerang = boomerang; + } + + private void Update() + { + //sr.sprite = m_Boomerang.GetComponent<SpriteRenderer>().sprite; + if(m_Boomerang != null) + { + //this.transform.rotation = m_Boomerang.transform.rotation; + } + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Weapons/Boomerang/BoomerangAfterImage.cs.meta b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/BoomerangAfterImage.cs.meta new file mode 100644 index 0000000..28b5eba --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/BoomerangAfterImage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a6a150d5108a43f4386bda3a1707d743 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Weapon_Boomerang.cs b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Weapon_Boomerang.cs new file mode 100644 index 0000000..f5588cd --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Weapon_Boomerang.cs @@ -0,0 +1,56 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 回旋镖 +/// </summary> +public class Weapon_Boomerang : WeaponBase +{ + public override AutoMode autoMode => AutoMode.Condition; + + public override string name => "回旋镖"; + + public override string iconPath => "art/ui/weaponicon/boomerang"; + + string prefabPath = "prefabs/weapon/boomerang"; + + Boomerang boomerang; + + /// 接到回旋镖后重新掷出,否则间隔一段时间投掷 + /// </summary> + /// <param name="owner"></param> + /// <returns></returns> + public override bool CheckCondition(GameObject owner) + { + return true; + } + + public override void OnInitialize(GameObject owner) + { + base.OnInitialize(owner); + boomerang = null; + } + + public override void OnTrigger(GameObject owner) + { + if (boomerang == null) + { + boomerang = UnityEngine.Object.Instantiate<Boomerang>(ResourceManager.Instance.Load<Boomerang>(prefabPath)); + CrewScript crew = owner.GetComponent<CrewScript>(); + Vector3 pos = crew.centre.position + new Vector3(crew.aimDirection.x, crew.aimDirection.y, 0) * 0.3f; + boomerang.transform.position = pos; + boomerang.Set(crew.aimDirection, 10f, 10f); + } + } + + public override void OnStop(GameObject owner) + { + + } + + public override void Update(GameObject owner) + { + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Weapons/Weapon_Boomerang.cs.meta b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Weapon_Boomerang.cs.meta index 401fde6..401fde6 100644 --- a/SurvivalTest/Assets/Scripts/Weapons/Weapon_Boomerang.cs.meta +++ b/SurvivalTest/Assets/Scripts/Weapons/Boomerang/Weapon_Boomerang.cs.meta diff --git a/SurvivalTest/Assets/Scripts/Weapons/Weapon_Boomerang.cs b/SurvivalTest/Assets/Scripts/Weapons/Weapon_Boomerang.cs deleted file mode 100644 index d701c83..0000000 --- a/SurvivalTest/Assets/Scripts/Weapons/Weapon_Boomerang.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -/// <summary> -/// 回旋镖 -/// </summary> -public class Weapon_Boomerang : WeaponBase -{ - public override AutoMode autoMode => AutoMode.Condition; - - public override string name => "回旋镖"; - - public override string iconPath => "art/ui/weaponicon/boomerang"; - - /// <summary> - /// 接到回旋镖后重新掷出,否则间隔一段时间投掷 - /// </summary> - /// <param name="owner"></param> - /// <returns></returns> - public override bool CheckCondition(GameObject owner) - { - return false; - } - - public override void OnTrigger(GameObject owner) - { - } - - public override void Update(GameObject owner) - { - } - -}
\ No newline at end of file |