diff options
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts')
142 files changed, 3558 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Affects.meta b/WorldlineKeepers/Assets/Scripts/Affects.meta new file mode 100644 index 0000000..29bdb1f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Affects.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d99d7a9649a0e3243a9d36cd0621eab1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Affects/AffectBase.cs b/WorldlineKeepers/Assets/Scripts/Affects/AffectBase.cs new file mode 100644 index 0000000..5180304 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Affects/AffectBase.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class AffectBases +{ + + + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Affects/AffectBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Affects/AffectBase.cs.meta new file mode 100644 index 0000000..1b2a4a7 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Affects/AffectBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 05189e41f11956d45a41655cb86f2fc7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Animation.meta b/WorldlineKeepers/Assets/Scripts/Animation.meta new file mode 100644 index 0000000..01a3fee --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Animation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6786608179d88f44a8c67db41ba38535 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Animation/AnimationCurveAsset.cs b/WorldlineKeepers/Assets/Scripts/Animation/AnimationCurveAsset.cs new file mode 100644 index 0000000..50a1c6e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Animation/AnimationCurveAsset.cs @@ -0,0 +1,7 @@ +using UnityEngine; + +[CreateAssetMenu(menuName = "WK/Animation Curve Asset")] +public class AnimationCurveAsset : ScriptableObject +{ + public AnimationCurve value; +} diff --git a/WorldlineKeepers/Assets/Scripts/Animation/AnimationCurveAsset.cs.meta b/WorldlineKeepers/Assets/Scripts/Animation/AnimationCurveAsset.cs.meta new file mode 100644 index 0000000..3fb00ea --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Animation/AnimationCurveAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9f666cda03edfd943861dc45bef602e0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/AssetCollection.cs b/WorldlineKeepers/Assets/Scripts/AssetCollection.cs new file mode 100644 index 0000000..2942f75 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/AssetCollection.cs @@ -0,0 +1,25 @@ +using System; +using UnityEngine; + +[CreateAssetMenu(menuName = "WK/AssetCollection")] +public class AssetCollection : ScriptableObject +{ + public UnityEngine.Object[] assets = Array.Empty<UnityEngine.Object>(); + + [ContextMenu("Add selected assets.")] + private void AddSelectedAssets() + { + UnityEngine.Object[] additionalAssets = Array.Empty<UnityEngine.Object>(); + AddAssets(additionalAssets); + } + + public void AddAssets(UnityEngine.Object[] additionalAssets) + { + int num = assets.Length; + Array.Resize(ref assets, assets.Length + additionalAssets.Length); + for (int i = 0; i < additionalAssets.Length; i++) + { + assets[num + i] = additionalAssets[i]; + } + } +} diff --git a/WorldlineKeepers/Assets/Scripts/AssetCollection.cs.meta b/WorldlineKeepers/Assets/Scripts/AssetCollection.cs.meta new file mode 100644 index 0000000..46d77a1 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/AssetCollection.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 77c80cd82f7aa5844bcb9001b4b7c676 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Battle.meta b/WorldlineKeepers/Assets/Scripts/Battle.meta new file mode 100644 index 0000000..446dac0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Battle.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 62800c830f138d1439e0974c0c683f76 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Battle/BattleManager.cs b/WorldlineKeepers/Assets/Scripts/Battle/BattleManager.cs new file mode 100644 index 0000000..8372139 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Battle/BattleManager.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BattleManager : Singleton<BattleManager> +{ + + + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Battle/BattleManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Battle/BattleManager.cs.meta new file mode 100644 index 0000000..a89b003 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Battle/BattleManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bea0e35a4b2fa264698b0e2816565545 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Battle/GridMap.cs b/WorldlineKeepers/Assets/Scripts/Battle/GridMap.cs new file mode 100644 index 0000000..c99bf4a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Battle/GridMap.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 鐢℅rid鎵樼闇瑕佸疄鐜拌繖涓帴鍙 +/// </summary> +public interface IGridMapObject +{ + // 鍧愭爣锛宼ransform.position + public Vector2 coordinate { get; } +} + +public class GridCell +{ + public List<IGridMapObject> m_Object; +} + +/// <summary> +/// 鐢ㄧ綉鏍煎垝鍒嗗満鏅紝涓嶄緷璧栧舰鐘讹紝鍙緷璧栦綅缃 +/// </summary> +public class GridMap +{ + + // 鍗曚釜cell鐨勫ぇ灏 + private Vector2 m_CellSize; + + // 鏁翠釜grid鐨勮寖鍥 x, y, xcount, ycount + private Vector4 m_Range; + + // 宸︿笂瑙掑紑濮嬬储寮 + private List<GridCell> m_GridCells; + + public GridMap() + { + m_GridCells = new List<GridCell>(); + } + + private int GetGridIndex(Vector2 pos) + { + + + return -1; + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Battle/GridMap.cs.meta b/WorldlineKeepers/Assets/Scripts/Battle/GridMap.cs.meta new file mode 100644 index 0000000..989a829 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Battle/GridMap.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 66e52a379c253b54d896c3a5631bfdfa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs b/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs new file mode 100644 index 0000000..9ed2fc9 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SceneManager : Singleton<SceneManager> +{ + + // 鍦烘櫙鍐呮墍鏈夊璞$敤杩欎釜缁撴瀯缁存姢 + private GridMap m_GridMap; + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs.meta new file mode 100644 index 0000000..fe1604c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Battle/SceneManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d3730897865ceb44a87a57742832f78 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Buffs.meta b/WorldlineKeepers/Assets/Scripts/Buffs.meta new file mode 100644 index 0000000..69bca8e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4580776bfe5403949b3aaf98b1a673d8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs b/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs new file mode 100644 index 0000000..430fa70 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using WK; +using WK.Data; + +/// <summary> +/// Buff结构 +/// </summary> +public abstract class Buff +{ + // 元数据 + public BuffMetadata metadata; + + // buff效果器 + public BuffEfectorBase effector; + +} diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs.meta b/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs.meta new file mode 100644 index 0000000..2028306 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/Buff.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f69d7d622acac0647a5981d9420a42d9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs b/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs new file mode 100644 index 0000000..b90beb8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BuffEfectorBase +{ + private CharacterBase m_Character; + + /// <summary> + /// buff鐢熸垚鏃跺 + /// </summary> + public virtual void OnCreate() + { + + } + + /// <summary> + /// 鏇存柊 + /// </summary> + public virtual void OnUpdate() + { + + } + + /// <summary> + /// 瑙掕壊姝讳骸 + /// </summary> + public virtual void OnCharacterDeath() + { + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs.meta new file mode 100644 index 0000000..a433744 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/BuffEfectorBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5dabb53754f969c4194ad10b2b9fc154 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffMetadata.cs b/WorldlineKeepers/Assets/Scripts/Buffs/BuffMetadata.cs new file mode 100644 index 0000000..de7c391 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/BuffMetadata.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Data +{ + + public class BuffMetadata + { + + public string uid; + + public string name_key; + + public string icon; + + // 暂留数据 + public string extra_data; + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Buffs/BuffMetadata.cs.meta b/WorldlineKeepers/Assets/Scripts/Buffs/BuffMetadata.cs.meta new file mode 100644 index 0000000..2fbd7ff --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Buffs/BuffMetadata.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 52d9cd8616a5d4d42a5f8241da35ec5e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Common.meta b/WorldlineKeepers/Assets/Scripts/Common.meta new file mode 100644 index 0000000..35d853d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Common.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6afe070a575363345baaaaac54806dc1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Common/Singleton.cs b/WorldlineKeepers/Assets/Scripts/Common/Singleton.cs new file mode 100644 index 0000000..bb382e2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Common/Singleton.cs @@ -0,0 +1,16 @@ +using System; + +public class Singleton<T> where T : class, new() +{ + private static T _instance; + + public static T Instance + { + get + { + if (_instance == null) + _instance = Activator.CreateInstance<T>(); + return _instance; + } + } +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Common/Singleton.cs.meta b/WorldlineKeepers/Assets/Scripts/Common/Singleton.cs.meta new file mode 100644 index 0000000..9a9cdf7 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Common/Singleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 02534dc90b1e47743969d14d9386660d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Common/SingletonMB.cs b/WorldlineKeepers/Assets/Scripts/Common/SingletonMB.cs new file mode 100644 index 0000000..5debe57 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Common/SingletonMB.cs @@ -0,0 +1,58 @@ +using Newtonsoft.Json.Utilities; +using UnityEngine; + +public abstract class SingletonMB<T> : MonoBehaviour where T : class +{ + protected static T m_Instance; + + public static T Instance + { + get { return m_Instance; } + set + { + if (m_Instance != null) + { + throw new System.ApplicationException("An instance was created duplicate!"); + } + + m_Instance = value; + } + } + + protected virtual void Awake() + { + //if (null != m_Instance) + //{ + // LogHelper.LogError(StringUtil.Concat("Exception: Duplicated Instance!! type is ", typeof(T).ToString(), ", plz send this error msg to hanjun!")); + //} + + m_Instance = gameObject.GetComponent<T>(); + } + + /// <summary> + /// CN: 鍔犺繖涓嚱鏁版槸涓轰簡鍚屼竴涓狦ameObject鎸備簡澶氫釜Manager绫伙紝鍐峅nDestroy閲岃缃嚜宸辩殑鍗曚緥涓簄ull + /// </summary> + protected virtual void OnDestroy() + { + //m_Instance = null; + DoWhenOnDestroy(); + } + + protected virtual void DoWhenOnDestroy() + { + + } + + public void ReleaseInstance() + { + if (m_Instance != null) + { + UnityEngine.Object.Destroy(this.gameObject); + //m_Instance = null; + } + else + { + Debug.LogError("m_Instance is already null!! type is " + typeof(T).ToString()); + } + } +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Common/SingletonMB.cs.meta b/WorldlineKeepers/Assets/Scripts/Common/SingletonMB.cs.meta new file mode 100644 index 0000000..2305ad2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Common/SingletonMB.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f80ac80ccf55c443ae18ec55cc8f37e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Data.meta b/WorldlineKeepers/Assets/Scripts/Data.meta new file mode 100644 index 0000000..3622fa8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Data.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9dac4e9417c4a4343926c0fd48551b07 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs new file mode 100644 index 0000000..e56c80b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +namespace WK.Data +{ + + public class DataManager : Singleton<DataManager> + { + + private Dictionary<string/*uid*/, CharacterStatsMetadata> m_CharacterStatsMetadata; + private Dictionary<string/*uid*/, BuffMetadata> m_BuffMetadata; + + public CharacterStatsMetadata GetCharacterStats(string uid) + { + CharacterStatsMetadata metadata; + if(m_CharacterStatsMetadata.TryGetValue(uid, out metadata)) + { + return metadata; + } + return null; + } + + public BuffMetadata GetBuffMetadata(string uid) + { + BuffMetadata metadata; + if(m_BuffMetadata.TryGetValue(uid, out metadata)) + { + return metadata; + } + return null; + } + + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs.meta new file mode 100644 index 0000000..e2f87df --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Data/DataManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 426d62970250f0f41b68370ced13105b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Effects.meta b/WorldlineKeepers/Assets/Scripts/Effects.meta new file mode 100644 index 0000000..d9d583c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Effects.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 47a5a6e09c8fc7041a7e79731b984bc2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Effects/FadeoutAndDestroy.cs b/WorldlineKeepers/Assets/Scripts/Effects/FadeoutAndDestroy.cs new file mode 100644 index 0000000..727f02b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Effects/FadeoutAndDestroy.cs @@ -0,0 +1,39 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FadeoutAndDestroy : MonoBehaviour +{ + #region 搴忓垪鍖 + public float m_LifeTime; + #endregion + + #region 鍏叡瀛楁 + + #endregion + + #region 绉佹湁瀛楁 + private float time = 0; + private SpriteRenderer m_SpriteRenderer; + #endregion + + private void Awake() + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + + } + + public void Update() + { + time += Time.deltaTime; + if(time > m_LifeTime) + { + Destroy(gameObject); + } + + Color c = m_SpriteRenderer.color; + c.a = 1 - time / m_LifeTime; + m_SpriteRenderer.color = c; + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Effects/FadeoutAndDestroy.cs.meta b/WorldlineKeepers/Assets/Scripts/Effects/FadeoutAndDestroy.cs.meta new file mode 100644 index 0000000..cd07093 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Effects/FadeoutAndDestroy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 985f0a4ee3cc7b745b4f2a49e7c76691 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/EntityBase.cs b/WorldlineKeepers/Assets/Scripts/EntityBase.cs new file mode 100644 index 0000000..3470d3c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/EntityBase.cs @@ -0,0 +1,52 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EntityBase : MonoBehaviour +{ + public SpriteRenderer m_Shadow; + + private SpriteRenderer m_SpriteRenderer; + + protected virtual void Awake() + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + + GameObject shadow = new GameObject("shadow"); + shadow.transform.parent = transform; + shadow.transform.localPosition = Vector3.zero; + shadow.transform.localScale = new Vector3(1, 0.5f, 1); + SpriteRenderer sr = shadow.AddComponent<SpriteRenderer>(); + sr.material = new Material(Shader.Find("UI/SpriteSkewShader")); + sr.material.SetFloat("_HorizontalSkew", 0.4f); + sr.color = new Color(0, 0, 0, 0.4f); + sr.sortingOrder = short.MinValue; + m_Shadow = sr; + } + + protected virtual void Update() + { + if (m_SpriteRenderer != null) + { + float y = transform.position.y; + int order = -(int)(y * 100); + if (order != m_SpriteRenderer.sortingOrder) + { + m_SpriteRenderer.sortingOrder = order; + } + } + } + + protected virtual void LateUpdate() + { + if (m_Shadow != null) + { + if (m_Shadow.sprite != m_SpriteRenderer.sprite) + { + //m_Shadow.sprite = m_SpriteRenderer.sprite; + //m_Shadow.flipX = m_SpriteRenderer.flipX; + } + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/EntityBase.cs.meta b/WorldlineKeepers/Assets/Scripts/EntityBase.cs.meta new file mode 100644 index 0000000..bea4770 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/EntityBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1cba851b7bdff1446b87fa2ce86ea799 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items.meta b/WorldlineKeepers/Assets/Scripts/Items.meta new file mode 100644 index 0000000..240e859 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9dd7c45b04c11bb41bb362f89e93c0d5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemBase.cs b/WorldlineKeepers/Assets/Scripts/Items/ItemBase.cs new file mode 100644 index 0000000..98f3c2a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemBase.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ItemBase : EntityBase +{ + protected virtual void Awake() + { + base.Awake(); + } + + protected virtual void Update() + { + base.Update(); + } + + protected virtual void LateUpdate() + { + base.LateUpdate(); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Items/ItemBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/ItemBase.cs.meta new file mode 100644 index 0000000..0893db8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/ItemBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cbf68306c31144f44a34335479353692 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Items/Item_Coin.cs b/WorldlineKeepers/Assets/Scripts/Items/Item_Coin.cs new file mode 100644 index 0000000..1549646 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/Item_Coin.cs @@ -0,0 +1,30 @@ +using MH; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering.Universal; + +public class Item_Coin : ItemBase +{ + + protected override void Update() + { + base.Update(); + + UnitBase hero = UnitManager.hero; + + Vector2 pos = transform.position; + Vector2 target = hero.transform.position; + + if(Vector2.Distance(pos, target) <= 0.1f) + { + this.gameObject.SetActive(false); + Destroy(this.gameObject); + return; + } + + Vector2 cur = Vector2.Lerp(pos, target, 0.01f); + transform.position = cur.ToVector3(); + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Items/Item_Coin.cs.meta b/WorldlineKeepers/Assets/Scripts/Items/Item_Coin.cs.meta new file mode 100644 index 0000000..9bc770a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Items/Item_Coin.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5979684bc57d8084d92d172dcf9f1080 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Managers.meta b/WorldlineKeepers/Assets/Scripts/Managers.meta new file mode 100644 index 0000000..4c87204 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Managers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9b80abdfc07d3d442917d0b5c531db6b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Managers/CameraManager.cs b/WorldlineKeepers/Assets/Scripts/Managers/CameraManager.cs new file mode 100644 index 0000000..b063bb2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Managers/CameraManager.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CameraManager : Singleton<CameraManager> +{ + + + +} diff --git a/WorldlineKeepers/Assets/Scripts/Managers/CameraManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Managers/CameraManager.cs.meta new file mode 100644 index 0000000..13e9a10 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Managers/CameraManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 99d25fcd0b568564c8f5530b957bdcb3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs b/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs new file mode 100644 index 0000000..4b318ca --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +#if UNITY_EDITOR +using UnityEditor; +#endif +using UnityEngine; + +namespace WK +{ + + public class ResourceManager : Singleton<ResourceManager> + { + + // 资源根目录是Assets/Bundle/,后续可能会把部分资源移动到streamingAssets目录 + public const string kAssetRoot = "Assets/Bundle/"; + + public T LoadAsset<T>(string relativePath) where T : UnityEngine.Object + { +#if UNITY_EDITOR + string path = kAssetRoot + relativePath; + T obj = AssetDatabase.LoadAssetAtPath(path, typeof(T)) as T; + return obj; +#else + return null ; +#endif + } + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs.meta new file mode 100644 index 0000000..b3c985b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 928e39b9448c1c74caa349620602617b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Mod.meta b/WorldlineKeepers/Assets/Scripts/Mod.meta new file mode 100644 index 0000000..d77af1d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Mod.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2342cf019bfec2d4fafccc1b3d7a7b4f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Mod/ModManager.cs b/WorldlineKeepers/Assets/Scripts/Mod/ModManager.cs new file mode 100644 index 0000000..4357a2a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Mod/ModManager.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace MH.Modding +{ + + public class ModManager : 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/Mod/ModManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Mod/ModManager.cs.meta new file mode 100644 index 0000000..d942c9d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Mod/ModManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f43b414cb894d984ab87c4ad0bf52604 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Modifier.meta b/WorldlineKeepers/Assets/Scripts/Modifier.meta new file mode 100644 index 0000000..c1fbb44 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Modifier.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: aa35e70f974403f4e92aaed6c8b6171b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Perks.meta b/WorldlineKeepers/Assets/Scripts/Perks.meta new file mode 100644 index 0000000..a4e7dd3 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Perks.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 36d94755fd8ae90469d7d48a4f743987 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Perks/PerkBase.cs b/WorldlineKeepers/Assets/Scripts/Perks/PerkBase.cs new file mode 100644 index 0000000..18e39ea --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Perks/PerkBase.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 琚姩鎶鑳絓鐘舵佸姞鎴 +/// </summary> +public class PerkBase +{ + + + +} diff --git a/WorldlineKeepers/Assets/Scripts/Perks/PerkBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Perks/PerkBase.cs.meta new file mode 100644 index 0000000..a1402e2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Perks/PerkBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 79b8e3a61f167c244a239a6efcca7cdc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics.meta b/WorldlineKeepers/Assets/Scripts/Physics.meta new file mode 100644 index 0000000..7aa2761 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1258c9912781eb5478bb754a2a37fb12 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs b/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs new file mode 100644 index 0000000..df84e0d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs @@ -0,0 +1,90 @@ +using mh; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FastBoxCollider : MonoBehaviour, IQuadTreeObject +{ + + [SerializeField] private ColliderType m_Type; + [SerializeField] private Vector2 m_Offset; + [SerializeField] private Vector2 m_Size; + + public Vector2 center + { + get + { + Vector3 pos = transform.position + m_Offset.ToVector3(); + return pos; + } + } + + public Vector2 offset => m_Offset; + public Vector2 size => m_Size; + + public Vector4 bound + { + get + { + Vector3 pos = transform.position + m_Offset.ToVector3(); + Vector4 b = new Vector4(); + b.x = pos.x; + b.y = pos.y; + b.z = size.x; + b.w = size.y; + return b; + } + } + + public Vector4 box + { + get + { + Vector2 c = center; + Vector4 b = new Vector4(); + b.x = c.x; + b.y = c.y; + b.z = size.x; + b.w = size.y; + return b; + } + } + + public void Awake() + { + if (m_Type == ColliderType.Collider) + { + PhysicsManager.Instance.AddCollider(this); + } + else if (m_Type == ColliderType.Hurtbox) + { + PhysicsManager.Instance.AddHurtboxes(this); + } + } + + public void OnDestroy() + { + if (m_Type == ColliderType.Collider) + { + PhysicsManager.Instance.RemoveCollider(this); + } + else if (m_Type == ColliderType.Hurtbox) + { + PhysicsManager.Instance.RemoveHurtbox(this); + } + } + + private void OnDrawGizmos() + { + Color c = Gizmos.color; + + if(m_Type == ColliderType.Hurtbox) + { + Gizmos.color = Color.red; + } + Gizmos.DrawWireCube(transform.position + m_Offset.ToVector3(), m_Size.ToVector3()); + + Gizmos.color = c; + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs.meta new file mode 100644 index 0000000..c4a5b19 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/FastBoxCollider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 310ae84e35289454197ed61078698811 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs b/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs new file mode 100644 index 0000000..dde49f9 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs @@ -0,0 +1,82 @@ +using mh; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FastCircleCollider : MonoBehaviour, IQuadTreeObject +{ + + [SerializeField] private ColliderType m_Type; + [SerializeField] private float m_Radius; + [SerializeField] private Vector2 m_Offset; + + public Vector2 center + { + get + { + Vector3 pos = transform.position + m_Offset.ToVector3(); + return pos; + } + } + + public float radius => m_Radius; + + public Vector4 bound + { + get + { + Vector3 pos = transform.position + m_Offset.ToVector3(); + Vector4 b = new Vector4(); + b.x = pos.x; + b.y = pos.y; + b.z = m_Radius * 2; + b.w = m_Radius * 2; + return b; + } + } + + public Vector3 circle + { + get + { + Vector3 c = new Vector3(); + Vector2 ct = center; + c.x = ct.x; + c.y = ct.y; + c.z = radius; + return c; + } + } + + public Vector2 offset => m_Offset; + + public void Awake() + { + if(m_Type == ColliderType.Collider) + { + PhysicsManager.Instance.AddCollider(this); + } + else if(m_Type == ColliderType.Hurtbox) + { + PhysicsManager.Instance.AddHurtboxes(this); + } + } + + public void OnDestroy() + { + if (m_Type == ColliderType.Collider) + { + PhysicsManager.Instance.RemoveCollider(this); + } + else if (m_Type == ColliderType.Hurtbox) + { + PhysicsManager.Instance.RemoveHurtbox(this); + } + } + + private void OnDrawGizmos() + { + Gizmos.DrawWireSphere(transform.position + m_Offset.ToVector3(), m_Radius); + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs.meta new file mode 100644 index 0000000..8457227 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/FastCircleCollider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: defd292dd15a961418d8ac5721b28712 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs new file mode 100644 index 0000000..279ebbb --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs @@ -0,0 +1,46 @@ +using mh; +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +public enum ColliderType +{ + Collider, + Hurtbox, +} + +public partial class PhysicsManager : Singleton<PhysicsManager> +{ + // 四叉树筛选结果 + public List<IQuadTreeObject> sharedRetriveResults => m_SharedRetriveResults; + private List<IQuadTreeObject> m_SharedRetriveResults = new List<IQuadTreeObject>(); + + public PhysicsManager() + { + m_CollisionQuadtree = new PhysicsQuadtree(new Vector4(0, 0, 30, 30)); + m_HurtboxQuadtree = new PhysicsQuadtree(new Vector4(0, 0, 30, 30)); + } + + public System.Func<Vector4, bool> GetRetriverByType(ColliderType type) + { + if (type == ColliderType.Collider) + return RetriveColliders; + else if (type == ColliderType.Hurtbox) + return RetriveHurtboxes; + else + return null; + } + + public void Update() + { + m_CollisionQuadtree.UpdateQuadtree(); + m_HurtboxQuadtree.UpdateQuadtree(); + } + + public void Debug() + { + m_CollisionQuadtree.Debug(); + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs.meta new file mode 100644 index 0000000..1bc7b8b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 309b3570728b5ca40b98a4799850238f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_Collide.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_Collide.cs new file mode 100644 index 0000000..4710b2e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_Collide.cs @@ -0,0 +1,186 @@ +using mh; +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting.Antlr3.Runtime.Tree; +using UnityEngine; +using UnityEngine.UIElements; + +/// <summary> +/// 物理查询 +/// </summary> +public partial class PhysicsManager : Singleton<PhysicsManager> +{ + // 碰撞检测结果 + private List<IQuadTreeObject> m_SharedCollideResults = new List<IQuadTreeObject>(); + + public static Vector4 GetCircleBound(Vector3 circle) + { + float size = circle.z * 2; + return new Vector4(circle.x, circle.y, size, size); + } + + public static Vector4 GetBoxBound(Vector4 box) + { + return box; + } + + public static Vector4 GetRayBound(Vector4 ray) + { + Vector2 tr = ray.xy() + ray.zw(); + Vector4 bound = new Vector4(); + bound.x = (tr.x + ray.x) / 2; + bound.y = (tr.y + ray.y) / 2; + bound.z = Mathf.Max(Mathf.Abs(tr.x - ray.x), 1); + bound.w = Mathf.Max(Mathf.Abs(tr.y - ray.y), 1); + return bound; + } + + public static Vector4 GetRaySegment(Vector4 ray) + { + Vector2 tr = ray.xy() + ray.zw(); + Vector4 seg = new Vector4(); + seg.x = ray.x; + seg.y = ray.y; + seg.z = tr.x; + seg.w = tr.y; + return seg; + } + + public static Vector4 GetPointBound(Vector2 point) + { + Vector4 bound = new Vector4(); + bound.x = point.x; + bound.y = point.y; + bound.z = 1; + bound.w = 1; + return bound; + } + + /// <summary> + /// 把x,y,w,h的box转换为lowerx,higherx,lowery,highery + /// </summary> + /// <returns></returns> + public static Vector4 GetBoxRange(Vector4 box) + { + Vector4 Range = new(); + Range.x = box.x - box.z / 2; + Range.y = box.x + box.z / 2; + Range.z = box.y - box.w / 2; + Range.w = box.y + box.w / 2; + return Range; + } + + public ref readonly List<IQuadTreeObject> CircleCast(ColliderType target, Vector3 circle) + { + m_SharedCollideResults.Clear(); + var retriver = GetRetriverByType(target); + if(retriver != null) + { + if (retriver(GetCircleBound(circle))) + { + for(int i = 0; i < m_SharedRetriveResults.Count; ++i) + { + var collider = m_SharedRetriveResults[i]; + if(collider != null) + { + if(collider is FastCircleCollider) + { + if(CircleVsCircle((collider as FastCircleCollider).circle, circle)) + { + m_SharedCollideResults.Add(collider); + } + } + else if(collider is FastBoxCollider) + { + if (BoxVsCircle((collider as FastBoxCollider).box, circle)) + { + m_SharedCollideResults.Add(collider); + } + } + } + } + } + } + return ref m_SharedCollideResults; + } + + public ref readonly List<IQuadTreeObject> BoxCast(ColliderType target, Vector4 box) + { + m_SharedCollideResults.Clear(); + var retriver = GetRetriverByType(target); + if (retriver != null) + { + if (retriver(GetBoxBound(box))) + { + for (int i = 0; i < m_SharedRetriveResults.Count; ++i) + { + var collider = m_SharedRetriveResults[i]; + if (collider != null) + { + if (collider is FastCircleCollider) + { + if (BoxVsCircle(box, (collider as FastCircleCollider).circle)) + { + m_SharedCollideResults.Add(collider); + } + } + else if (collider is FastBoxCollider) + { + if (BoxVsBox(box, (collider as FastBoxCollider).box)) + { + m_SharedCollideResults.Add(collider); + } + } + } + } + } + } + return ref m_SharedCollideResults; + } + + /// <summary> + /// x,y dir.x dir.y(dir带长度) + /// </summary> + /// <param name="target"></param> + /// <param name="line"></param> + /// <returns></returns> + public ref readonly List<IQuadTreeObject> RayCast(ColliderType target, Vector4 ray) + { + m_SharedCollideResults.Clear(); + var retriver = GetRetriverByType(target); + if(retriver != null) + { + if(retriver(GetRayBound(ray))) + { + for (int i = 0; i < m_SharedRetriveResults.Count; ++i) + { + var collider = m_SharedRetriveResults[i]; + if (collider != null) + { + if (collider is FastCircleCollider) + { + if (RayVsCircle(ray, (collider as FastCircleCollider).circle)) + { + m_SharedCollideResults.Add(collider); + } + } + else if (collider is FastBoxCollider) + { + if (RayVsBox(ray, (collider as FastBoxCollider).box)) + { + m_SharedCollideResults.Add(collider); + } + } + } + } + } + } + return ref m_SharedCollideResults; + } + + public ref readonly List<IQuadTreeObject> PointCast(ColliderType target, Vector2 point) + { + return ref m_SharedCollideResults; + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_Collide.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_Collide.cs.meta new file mode 100644 index 0000000..d5f9202 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_Collide.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2d0c6870f58c8c6469810ba2ca63cbc7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionDetection.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionDetection.cs new file mode 100644 index 0000000..d5fd913 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionDetection.cs @@ -0,0 +1,183 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 碰撞检测 +/// </summary> +public partial class PhysicsManager : Singleton<PhysicsManager> +{ + + /// <summary> + /// circle x,y,radius + /// </summary> + /// <param name="pos1"></param> + /// <param name="r1"></param> + /// <param name="pos2"></param> + /// <param name="r2"></param> + /// <returns></returns> + public static bool CircleVsCircle(Vector2 pos1, float r1, Vector2 pos2, float r2) + { + return (pos1 - pos2).magnitude <= r1 + r2; + } + + public static bool CircleVsCircle(Vector3 c1, Vector3 c2) + { + return (c1.xy() - c2.xy()).magnitude <= c1.z + c2.z; + } + + /// <summary> + /// intersection是r2对于r1 + /// </summary> + /// <param name="b1"></param> + /// <param name="b2"></param> + /// <param name="intersection"></param> + /// <returns></returns> + public static bool BoxVsBox(Vector4 b1, Vector4 b2, out Vector2 intersection) + { + float b1w = b1.z / 2f, b1h = b1.w / 2f, b2w = b2.z / 2f, b2h = b2.w / 2f; + float distX = b2.x - b1.x; + float distY = b2.y - b1.y; + if(Mathf.Abs(distX) < b1w + b2w && Mathf.Abs(distY) < b1h +b2h) + { + intersection = new Vector2(); + intersection.x = Mathf.Sign(distX) * (b1w + b2w - Mathf.Abs(distX)); + intersection.y = Mathf.Sign(distY) * (b1h + b2h - Mathf.Abs(distY)); + return true; + } + intersection = Vector2.zero; + return false; + } + + public static bool BoxVsBox(Vector4 b1, Vector4 b2) + { + float b1w = b1.z / 2f, b1h = b1.w / 2f, b2w = b2.z / 2f, b2h = b2.w / 2f; + float distX = b2.x - b1.x; + float distY = b2.y - b1.y; + if (Mathf.Abs(distX) < b1w + b2w && Mathf.Abs(distY) < b1h + b2h) + { + return true; + } + return false; + } + + public static bool BoxVsCircle(Vector4 box, Vector2 pos, float radius) + { + Vector4 boxScaled = box; + boxScaled.z = box.z + radius * 2; + boxScaled.w = box.w + radius * 2; + if (!IsPointInsideBox(boxScaled, pos)) + return false; + Vector2 v = MathUtils.Abs(pos - box.xy()); + Vector2 u = MathUtils.Max(v - box.zw(), 0); + return Vector2.Dot(u, u) < radius * radius; + } + + public static bool RayVsCircle(Vector4 ray, Vector3 circle) + { + Vector4 seg = GetRaySegment(ray); + Vector2 dir = ray.zw().normalized; + Vector2 center = circle.xy(); + float u = Vector2.Dot(center - seg.xy(), dir); + Vector2 near = new Vector2(); + if(u <= 0) + { + near = seg.xy(); + } + else if(u >= ray.zw().magnitude) + { + near = seg.zw(); + } + else + { + near = seg.xy() + dir * u; + } + return (near - center).sqrMagnitude <= circle.z * circle.z; + } + + + // From Real-time Collision Detection, p179 + // box2d + public static bool RayVsBox(Vector4 ray, Vector4 box) + { + float tmin = float.MinValue; + float tmax = float.MaxValue; + Vector2 dir = ray.zw().normalized; + Vector4 range = GetBoxRange(box); //lowerx,higherx,lowery,highery + Vector2 lowerBound = new Vector2(range.x, range.z); + Vector2 upperBound = new Vector2(range.y, range.w); + //Vector2 normal = new Vector2(); + Vector2 p = ray.xy(); + + for (int i = 0; i < 2; ++i) + { + + if (dir[i] < float.Epsilon) // 和x-slab平行 + { + if (p[i] < lowerBound[i] || p[i] > upperBound[i]) + { + return false; + } + } + else + { + float inv_d = 1f / dir[i]; + float t1 = (lowerBound[i] - p[i]) * inv_d; + float t2 = (upperBound[i] - p[i]) * inv_d; + float s = -1f; + if (t1 > t2) + { + MathUtils.Swap(ref t1, ref t2); + s = 1f; + } + if (t1 > tmin) + { + //normal = Vector2.zero; + //normal[i] = s; + tmin = t1; + } + + tmax = Mathf.Min(tmax, t2); + + if (tmin > tmax) + { + return false; + } + } + } + + // Does the ray start inside the box? + // Does the ray intersect beyond the max fraction? + if (tmin < 0 || ray.zw().magnitude < tmin) + { + if (IsPointInsideBox(box, p)) + return true; + return false; + } + //// Intersection. + //output->fraction = tmin; + //output->normal = normal; + + return true; + } + + /// <summary> + /// box x,y,w,h circle x,y,raduis + /// </summary> + /// <param name="box"></param> + /// <param name="circle"></param> + /// <returns></returns> + public static bool BoxVsCircle(Vector4 box, Vector3 circle) + { + return BoxVsCircle(box, circle.xy(), circle.z); + } + + public static bool IsPointInsideBox(Vector4 box, Vector2 point) + { + return point.x >= box.x - box.z / 2f + && point.x <= box.x + box.z / 2f + && point.y >= box.y - box.w / 2f + && point.y <= box.y + box.w / 2f; + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionDetection.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionDetection.cs.meta new file mode 100644 index 0000000..7be9116 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionDetection.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2577861427359c9459ea0fa471de4040 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionTree.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionTree.cs new file mode 100644 index 0000000..f372f3a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionTree.cs @@ -0,0 +1,45 @@ +using mh; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public partial class PhysicsManager : Singleton<PhysicsManager> +{ + + private PhysicsQuadtree m_CollisionQuadtree; + + public Vector4 collisionQuadtreeRange + { + set + { + m_CollisionQuadtree.quadtreeRange = value; + } + } + + public void AddCollider(IQuadTreeObject collider) + { + m_CollisionQuadtree.AddObject(collider); + } + + public void RemoveCollider(IQuadTreeObject collider) + { + m_CollisionQuadtree.RemoveObject(collider); + } + + public bool RetriveColliders(ref List<IQuadTreeObject> returnObjs, IQuadTreeObject obj) + { + return m_CollisionQuadtree.Retrive(ref returnObjs, obj); + } + + public bool RetriveColliders(ref List<IQuadTreeObject> returnObjs, Vector4 bound) + { + return m_CollisionQuadtree.Retrive(ref returnObjs, bound); + } + + public bool RetriveColliders(Vector4 bound) + { + m_SharedRetriveResults.Clear(); + return m_CollisionQuadtree.Retrive(ref m_SharedRetriveResults, bound); + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionTree.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionTree.cs.meta new file mode 100644 index 0000000..1ac4a70 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_CollisionTree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb174e1114e8e3d439bdb43fa7d609b8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_HurtboxTree.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_HurtboxTree.cs new file mode 100644 index 0000000..ca13935 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_HurtboxTree.cs @@ -0,0 +1,40 @@ +using mh; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public partial class PhysicsManager : Singleton<PhysicsManager> +{ + + private PhysicsQuadtree m_HurtboxQuadtree; + + public Vector4 hurtboxQuadtreeRange + { + set + { + m_HurtboxQuadtree.quadtreeRange = value; + } + } + + public void AddHurtboxes(IQuadTreeObject hurtbox) + { + m_HurtboxQuadtree.AddObject(hurtbox); + } + + public void RemoveHurtbox(IQuadTreeObject hurtbox) + { + m_HurtboxQuadtree.RemoveObject(hurtbox); + } + + public bool RetriveHurtboxes(ref List<IQuadTreeObject> returnObjs, Vector4 bound) + { + return m_HurtboxQuadtree.Retrive(ref returnObjs, bound); + } + + public bool RetriveHurtboxes(Vector4 bound) + { + m_SharedRetriveResults.Clear(); + return m_HurtboxQuadtree.Retrive(ref m_SharedRetriveResults, bound); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_HurtboxTree.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_HurtboxTree.cs.meta new file mode 100644 index 0000000..39cd699 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsManager_HurtboxTree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9fc247f3e6aafbd45a935ef4b1ced70c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs new file mode 100644 index 0000000..5cd374e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs @@ -0,0 +1,87 @@ +using mh; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 鍩轰簬鍥惧舰鐨勫洓鍙夋爲 +/// </summary> +class PhysicsQuadtree +{ + /// <summary> + /// 杈圭晫 + /// </summary> + public Vector4 quadtreeRange { set { m_QuadtreeRange = value; } } + private Vector4 m_QuadtreeRange; + + /// <summary> + /// 鏍硅妭鐐 + /// </summary> + private Quadtree m_Quadtree; + + /// <summary> + /// 鎵樼鐨勫叏閮ㄥ璞★紝浣嗕笉涓瀹氫細鍔犲叆鍒版爲閲岄潰锛堜腑蹇冪偣鍦ㄨ竟鐣屽鐨勪笉鍔犲叆鏍戯級 + /// </summary> + private List<IQuadTreeObject> m_Objects = new List<IQuadTreeObject>(); + + public PhysicsQuadtree(Vector4 range) + { + m_QuadtreeRange = range; + m_Quadtree = new Quadtree(0, range, true); + } + + public void AddObject(IQuadTreeObject obj) + { + m_Objects.Add(obj); + } + + public void RemoveObject(IQuadTreeObject obj) + { + m_Objects.Remove(obj); + } + + public void UpdateQuadtree() + { + m_Quadtree.Clear(false); + m_Quadtree.Rebound(m_QuadtreeRange); + InsertAllObjects(); + } + + private void InsertAllObjects() + { + Vector4 bound = m_Quadtree.bound; + for (int i = 0; i < m_Objects.Count; i++) + { + IQuadTreeObject obj = m_Objects[i]; + // 绠鍗曠殑蹇界暐涓績鍦ㄨ竟鐣屽鐨刼bject + if (PhysicsManager.IsPointInsideBox(bound, obj.bound.xy())) + { + m_Quadtree.Insert(obj); + } + } + } + + public void Debug() + { + Color c = Gizmos.color; + Gizmos.color = Color.green; + m_Quadtree?.Iterate((t) => + { + Vector3 pos = new Vector3(t.x, t.y, 0); + Vector3 size = new Vector3(t.w, t.h, 1); + Gizmos.DrawWireCube(pos, size); + }); + Gizmos.color = c; + } + + public bool Retrive(ref List<IQuadTreeObject> returnObjs, IQuadTreeObject obj) + { + return m_Quadtree.Retrieve(ref returnObjs, obj); + } + + public bool Retrive(ref List<IQuadTreeObject> returnObjs, Vector4 bound) + { + return m_Quadtree.Retrieve(ref returnObjs, bound); + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs.meta new file mode 100644 index 0000000..c9d1346 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsQuadtree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 07c60bb0f452e9a4a8cec80be4c6183a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsSystem.cs b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsSystem.cs new file mode 100644 index 0000000..5c7283f --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsSystem.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PhysicsSystem : SingletonMB<PhysicsSystem> +{ + + protected override void Awake() + { + base.Awake(); + } + + protected override void OnDestroy() + { + base.OnDestroy(); + } + + protected override void DoWhenOnDestroy() + { + base.DoWhenOnDestroy(); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Physics/PhysicsSystem.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsSystem.cs.meta new file mode 100644 index 0000000..098c3e2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/PhysicsSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 424982e85f480904d9712074785f9227 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/Quadtree.cs b/WorldlineKeepers/Assets/Scripts/Physics/Quadtree.cs new file mode 100644 index 0000000..a012d26 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/Quadtree.cs @@ -0,0 +1,292 @@ +using JetBrains.Annotations; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Unity.VisualScripting; +using UnityEngine; + +// https://gamedev.stackexchange.com/questions/6345/quad-tree-vs-grid-based-collision-detection + +namespace mh +{ + + public interface IQuadTreeObject + { + public Vector4 bound { get; } + } + + /// <summary> + /// 四叉树空间分割 + /// </summary> + public class Quadtree + { + public const int kMaxObjectsPerBlock = 4; + public const int kMaxLevel = 5; + + private int m_Level; + private Vector4 m_Bounds; // x,y,z,w => posx,posy,width,height + private Quadtree[] m_SubTrees; // 从右上角开始逆时针索引 + private List<IQuadTreeObject> m_Objects; // 非叶节点的为0 + private bool m_IsRoot; + + public Vector4 bound { get { return m_Bounds; } } + public float x { get { return m_Bounds.x; } } + public float y { get { return m_Bounds.y; } } + public float w { get { return m_Bounds.z; } } + public float h { get { return m_Bounds.w; } } + public float halfW { get { return w / 2; } } + public float halfH { get { return h / 2; } } + public float left { get { return x - halfW; } } + public float right { get { return x + halfW; } } + public float top { get { return y + halfH; } } + public float bottom { get { return y - halfH; } } + + public bool isRoot { get { return m_IsRoot; } } + + private static Queue<List<IQuadTreeObject>> m_QuadtreeObjPool = new Queue<List<IQuadTreeObject>>(); + private static Queue<Quadtree> m_QuadtreePool = new Queue<Quadtree>(); + + private Quadtree QueryQuadtree(int level, Vector4 bounds) + { + if(m_QuadtreePool.Count == 0) + { + return new Quadtree(level, bounds); + } + Quadtree tree = m_QuadtreePool.Dequeue(); + tree.m_Level = level; + tree.m_Bounds = bounds; + if (tree.m_Objects == null) + tree.m_Objects = QueryQuadtreeObjList(); + return tree; + } + + private void RecycleQuadtree(ref Quadtree tree) + { + tree.Clear(); + m_QuadtreePool.Enqueue(tree); + tree = null; + } + + private List<IQuadTreeObject> QueryQuadtreeObjList() + { + if(m_QuadtreeObjPool.Count == 0) + { + return new List<IQuadTreeObject>(); + } + List<IQuadTreeObject> list = m_QuadtreeObjPool.Dequeue(); + return list; + } + + private void RecycleQuadtreeObjList(ref List<IQuadTreeObject> list) + { + list.Clear(); + m_QuadtreeObjPool.Enqueue(list); + list = null; + } + + public Quadtree(int level, Vector4 bounds, bool isRoot = false) + { + m_Level = level; + m_Bounds = bounds; + m_SubTrees = new Quadtree[4]; + m_Objects = QueryQuadtreeObjList(); + m_IsRoot = isRoot; + } + + /// <summary> + /// 更改边界,只适用于最外层的tree + /// </summary> + /// <param name="bounds"></param> + public void Rebound(Vector4 bounds) + { + if(!m_IsRoot) + { + Debug.LogError("Quadtree.Rebound()只能运用于最外层"); + return; + } + m_Bounds = bounds; + } + + public void Clear(bool clearObjectList = true) + { + if (clearObjectList) + RecycleQuadtreeObjList(ref m_Objects); + else + m_Objects.Clear(); + for (int i = 0; i < m_SubTrees.Length; i++) + { + if (m_SubTrees[i] != null) + { + //m_SubTrees[i].Clear(); + //m_SubTrees[i] = null; + RecycleQuadtree(ref m_SubTrees[i]); + } + } + } + + public void Split() + { + float subWidth = (m_Bounds.z / 2); + float subHeight = (m_Bounds.w / 2); + float x = m_Bounds.x; + float y = m_Bounds.y; + m_SubTrees[0] = QueryQuadtree(m_Level + 1, new Vector4(x + subWidth / 2, y + subHeight / 2, subWidth, subHeight)); + m_SubTrees[1] = QueryQuadtree(m_Level + 1, new Vector4(x - subWidth / 2, y + subHeight / 2, subWidth, subHeight)); + m_SubTrees[2] = QueryQuadtree(m_Level + 1, new Vector4(x - subWidth / 2, y - subHeight / 2, subWidth, subHeight)); + m_SubTrees[3] = QueryQuadtree(m_Level + 1, new Vector4(x + subWidth / 2, y - subHeight / 2, subWidth, subHeight)); + } + + /// <summary> + /// 0表示没法完全放在一个subTree: subtree交界或者整个越界 + /// </summary> + /// <param name="bound"></param> + /// <returns></returns> + public int GetSubtreeIndices(Vector4 bound) + { + int indices = 0; + float halfw = bound.z / 2; + float halfh = bound.w / 2; + float lowerx = bound.x - halfw; + float higherx = bound.x + halfw; + float lowery = bound.y - halfh; + float highery = bound.y + halfh; + bool startIsNorth = highery > y; + bool startIsWest = lowerx < x; + bool endIsEast = higherx > x; + bool endIsSouth = lowery < y; + //top-right quad + if (startIsNorth && endIsEast) + { + indices |= 1; + } + + //top-left quad + if (startIsWest && startIsNorth) + { + indices |= 1 << 1; + } + + //bottom-left quad + if (startIsWest && endIsSouth) + { + indices |= 1 << 2; + } + + //bottom-right quad + if (endIsEast && endIsSouth) + { + indices |= 1 << 3; + } + + return indices; + } + + public void Insert(IQuadTreeObject obj) + { + if (m_SubTrees[0] != null) + { + int indices = GetSubtreeIndices(obj.bound); + for(int i = 0; i < 4; i++) + { + if((indices & (1 << i)) != 0) + { + m_SubTrees[i].Insert(obj); + } + } + return; + } + + m_Objects.Add(obj); + + if (m_Objects.Count > kMaxObjectsPerBlock && m_Level < kMaxLevel) // 本层满了之后重新排布层内对象 + { + if (m_SubTrees[0] == null) Split(); + + for (int i = m_Objects.Count - 1; i >= 0; i--) + { + int indices = GetSubtreeIndices(m_Objects[i].bound); + for (int j = 0; j < 4; j++) + { + if ((indices & (1 << j)) != 0) + { + m_SubTrees[j].Insert(m_Objects[i]); + } + } + } + + m_Objects.Clear(); + } + } + + /// <summary> + /// 获得可能和obj碰撞的对象(不包括自己) + /// </summary> + /// <param name="returnObjs"></param> + /// <param name="obj"></param> + /// <returns></returns> + public bool Retrieve(ref List<IQuadTreeObject> returnObjs, IQuadTreeObject obj) + { + for(int i = 0; i < m_Objects.Count; ++i) + { + if (!returnObjs.Contains(m_Objects[i]) && obj != m_Objects[i]) + { + returnObjs.Add(m_Objects[i]); + } + } + if (m_SubTrees[0] != null) + { + int indices = GetSubtreeIndices(obj.bound); + for (int i = 0; i < 4; i++) + { + if ((indices & (1 << i)) != 0) + { + m_SubTrees[i].Retrieve(ref returnObjs, obj); + } + } + } + return returnObjs.Count > 0; + } + + /// <summary> + /// 获得可能和obj碰撞的对象(不包括自己) + /// </summary> + /// <param name="returnObjs"></param> + /// <param name="obj"></param> + /// <returns></returns> + public bool Retrieve(ref List<IQuadTreeObject> returnObjs, Vector4 bound) + { + for (int i = 0; i < m_Objects.Count; ++i) // 根节点count==0 + { + if (!returnObjs.Contains(m_Objects[i])) + { + returnObjs.Add(m_Objects[i]); + } + } + if (m_SubTrees[0] != null) + { + int indices = GetSubtreeIndices(bound); + for (int i = 0; i < 4; i++) + { + if ((indices & (1 << i)) != 0) + { + m_SubTrees[i].Retrieve(ref returnObjs, bound); + } + } + } + return returnObjs.Count > 0; + } + + public void Iterate(System.Action<Quadtree> action) + { + action?.Invoke(this); + m_SubTrees[0]?.Iterate(action); + m_SubTrees[1]?.Iterate(action); + m_SubTrees[2]?.Iterate(action); + m_SubTrees[3]?.Iterate(action); + } + + } +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Physics/Quadtree.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/Quadtree.cs.meta new file mode 100644 index 0000000..89087fb --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/Quadtree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5df24784c1c96ae4c963844001b3ef30 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/TestQuadtree.cs b/WorldlineKeepers/Assets/Scripts/Physics/TestQuadtree.cs new file mode 100644 index 0000000..2ea967e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/TestQuadtree.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using mh; +using MH; +using Unity.VisualScripting; + +namespace mh +{ + [DefaultExecutionOrder(-1000)] + public class TestQuadtree : MonoBehaviour + { + + private void Awake() + { + } + + private void FixedUpdate() + { + var pos = UnitManager.hero.transform.position; + PhysicsManager.Instance.collisionQuadtreeRange = new Vector4(pos.x, pos.y, 30, 20); + PhysicsManager.Instance.hurtboxQuadtreeRange = new Vector4(pos.x, pos.y, 30, 20); + PhysicsManager.Instance.Update(); + } + + private void OnDrawGizmos() + { + PhysicsManager.Instance.Debug(); + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Physics/TestQuadtree.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/TestQuadtree.cs.meta new file mode 100644 index 0000000..ed81efe --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/TestQuadtree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f88bde6dc59a579488b9b0aa6906f913 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs b/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs new file mode 100644 index 0000000..3f313ae --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UIElements; + +public class TestSpirits : MonoBehaviour +{ + public SpiritScript prefab; + + public static List<SpiritScript> spirits = new List<SpiritScript>(); + + private const int kMaxCount = 500; + + // Start is called before the first frame update + void Start() + { + int count = kMaxCount - spirits.Count; + for (int i = 0; i < count; ++i) + { + float x = UnityEngine.Random.Range(-20, 10); + float y = UnityEngine.Random.Range(-20, 10); + SpiritScript go = Instantiate(prefab) as SpiritScript; + go.transform.position = new Vector3(x, y, 0); + go.transform.parent = this.transform; + go.gameObject.SetActive(true); + } + StartCoroutine(CoSpawn(5)); + } + + IEnumerator CoSpawn(float interval) + { + while (true) + { + int count = kMaxCount - spirits.Count; + for (int i = 0; i < count; ++i) + { + float x = UnityEngine.Random.Range(-20, 10); + float y = UnityEngine.Random.Range(-20, 10); + SpiritScript go = Instantiate(prefab) as SpiritScript; + go.transform.position = new Vector3(x, y, 0); + go.transform.parent = this.transform; + go.gameObject.SetActive(true); + } + + yield return new WaitForSeconds(interval); + } + } + + private void FixedUpdate() + { + for(int i = 0; i < spirits.Count; ++i) + { + spirits[i].Tick(); + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs.meta b/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs.meta new file mode 100644 index 0000000..479bb7a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/TestSpirits.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 339ab6a313449b84fb9f51c3b6a1980b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Physics/unity-quadtree-master.meta b/WorldlineKeepers/Assets/Scripts/Physics/unity-quadtree-master.meta new file mode 100644 index 0000000..cbdce18 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Physics/unity-quadtree-master.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2fb02811893802a4bb3f07b115453535 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs b/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs new file mode 100644 index 0000000..5721c58 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +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/ProjectileBase.cs.meta b/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs.meta new file mode 100644 index 0000000..92b6448 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/ProjectileBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 74df58658557802489ed9f3e15541e6b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Projectiles.meta b/WorldlineKeepers/Assets/Scripts/Projectiles.meta new file mode 100644 index 0000000..20b505d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Projectiles.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 16b65d64de8db1740a3397412410487c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Projectiles/BladeScript.cs b/WorldlineKeepers/Assets/Scripts/Projectiles/BladeScript.cs new file mode 100644 index 0000000..5a37e4a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Projectiles/BladeScript.cs @@ -0,0 +1,85 @@ +using mh; +using MH; +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BladeScript : ProjectileBase +{ + [NonSerialized] public float life; + + public Vector2 dir; + + private static List<IQuadTreeObject> collisions = new List<IQuadTreeObject>(); + + private FastCircleCollider collider; + + private SpriteRenderer sr + { + get + { + return this.gameObject.GetComponent<SpriteRenderer>(); + } + } + + public void Start() + { + collider = GetComponent<FastCircleCollider>(); + Invoke("DestroySelf", life); + // Attack(); + } + + void DestroySelf() + { + Destroy(this.gameObject); + } + + public void Update() + { + Color c = sr.color; + c.a *= 0.99f; + sr.color = c; + + transform.localRotation *= Quaternion.Euler(0, 0, 20); + + transform.position += (dir * Time.deltaTime * 10f).ToVector3(); + } + + public void SetFlip(bool flip) + { + sr.flipX = flip; + } + + public void Attack() + { + Vector3 pos = transform.position; + if (PhysicsManager.Instance.RetriveHurtboxes(ref collisions, new Vector4(pos.x, pos.y, 2, 2))) + { + for (int i = 0; i < collisions.Count; i++) + { + var col = collisions[i] as MonoBehaviour; + if (col != null) + { + if (col is FastBoxCollider) + { + var box = col as FastBoxCollider; + if (box != null) + { + if (PhysicsManager.BoxVsCircle(box.box, collider.circle)) + { + GameObject.Destroy(box.gameObject); + } + } + } + } + } + } + } + + public void FixedUpdate() + { + Attack(); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Projectiles/BladeScript.cs.meta b/WorldlineKeepers/Assets/Scripts/Projectiles/BladeScript.cs.meta new file mode 100644 index 0000000..11f43ed --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Projectiles/BladeScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a4c0b0adacc6e3148aab9ce0f1c0cca1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Props.meta b/WorldlineKeepers/Assets/Scripts/Props.meta new file mode 100644 index 0000000..3e1a2d7 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Props.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3e47f3c86e97913409a27a4db22e00e0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Props/PropBase.cs b/WorldlineKeepers/Assets/Scripts/Props/PropBase.cs new file mode 100644 index 0000000..f971ed5 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Props/PropBase.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PropBase : MonoBehaviour +{ + #region 搴忓垪鍖 + + #endregion + + #region 鍏叡瀛楁 + + #endregion + + #region 绉佹湁瀛楁 + + #endregion + + private void Awake() + { + // 绉佹湁瀛楁璧嬪 + + // 鍏叡瀛楁璧嬪 + + // 鍒濆鍖 + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Props/PropBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Props/PropBase.cs.meta new file mode 100644 index 0000000..1c13ca9 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Props/PropBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4e7eada06d21254489ab3e9d4830e800 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stats.meta b/WorldlineKeepers/Assets/Scripts/Stats.meta new file mode 100644 index 0000000..6a41c6d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stats.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ebd4258fc51f0a4428fe390c968ad7c7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs new file mode 100644 index 0000000..b4869cb --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs @@ -0,0 +1,58 @@ +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using UnityEngine; +using WK.Data; + +namespace WK +{ + + [System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)] + public struct CharacterStatsValue + { + [System.Runtime.InteropServices.FieldOffset(0)] + public int i; + [System.Runtime.InteropServices.FieldOffset(0)] + public float f; + [System.Runtime.InteropServices.FieldOffset(0)] + public bool boolean; + [System.Runtime.InteropServices.FieldOffset(0)] + public char c; + [System.Runtime.InteropServices.FieldOffset(0)] + public Vector2 v2; + [System.Runtime.InteropServices.FieldOffset(0)] + public Vector3 v3; + [System.Runtime.InteropServices.FieldOffset(0)] + public Vector4 v4; + [System.Runtime.InteropServices.FieldOffset(0)] + public Color color; + } + + + /// <summary> + /// 运行时角色基础属性 + /// </summary> + public abstract class CharacterStats + { + + /// <summary> + /// 表格数据 + /// </summary> + public CharacterStatsMetadata metadata; + + /// <summary> + /// 当前属性值 + /// </summary> + public CharacterStatsValue value; + + public string uid + { + get + { + return metadata.uid; + } + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs.meta new file mode 100644 index 0000000..758018e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 749cbea7742c65244b0d1a662be4fb9e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs new file mode 100644 index 0000000..3b0b13b --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Data +{ + + /// <summary> + /// 角色基础属性元数据 + /// </summary> + public class CharacterStatsMetadata + { + public string uid; + + public string name_key; + + public int type; + + // 暂留数据 + public string extra_data; + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs.meta b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs.meta new file mode 100644 index 0000000..a8d9a08 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Stats/CharacterStatsMetadata.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 63006c2b6a413714bb852f46b214df90 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/TestAABB.cs b/WorldlineKeepers/Assets/Scripts/TestAABB.cs new file mode 100644 index 0000000..ed33ab3 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/TestAABB.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +public class TestAABB : MonoBehaviour +{ + + public Vector4 ray; + + public Vector2 size; + + private void Awake() + { + + } + + private void OnDrawGizmos() + { + if(PhysicsManager.RayVsBox(ray, new Vector4(transform.position.x, transform.position.y, size.x, size.y))) + { + Gizmos.color = Color.red; + } + else + { + Gizmos.color = Color.white; + } + Gizmos.DrawLine(ray.xy().ToVector3(), ray.xy().ToVector3() + ray.zw().ToVector3()); + Gizmos.DrawCube(transform.position, size.ToVector3()); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/TestAABB.cs.meta b/WorldlineKeepers/Assets/Scripts/TestAABB.cs.meta new file mode 100644 index 0000000..042e981 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/TestAABB.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4ddedc9aac270da4eb59670351403718 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tests.meta b/WorldlineKeepers/Assets/Scripts/Tests.meta new file mode 100644 index 0000000..3219e35 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f6e9b28f26f6aee49be2a1c0676abaf1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs b/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs new file mode 100644 index 0000000..068d235 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Resources; +using System.Text; +using UnityEngine; +using yutokun; + +public class TestCSV : MonoBehaviour +{ + #region 搴忓垪鍖 + + #endregion + + #region 鍏叡瀛楁 + + #endregion + + #region 绉佹湁瀛楁 + + #endregion + + private void OnEnable() + { + // 绉佹湁瀛楁璧嬪 + + // 鍏叡瀛楁璧嬪 + + // 鍒濆鍖 + + TextAsset text = WK.ResourceManager.Instance.LoadAsset<TextAsset>("metadata/default_stats.csv"); + + var sheet = CSVParser.LoadFromString(text.text); + + var styled = new StringBuilder(); + foreach (var row in sheet) + { + styled.Append("| "); + + if (row[0][0] == '#') + continue; + + foreach (var cell in row) + { + styled.Append(cell); + styled.Append(" | "); + } + + styled.AppendLine(); + } + + Debug.Log(styled.ToString()); // Unity + Console.WriteLine(styled.ToString()); // C# + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs.meta b/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs.meta new file mode 100644 index 0000000..48e6de1 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tests/TestCSV.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e9d405b1bd5e604db9cc8638d465aaf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI.meta b/WorldlineKeepers/Assets/Scripts/UI.meta new file mode 100644 index 0000000..e8c5c97 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8905b9f5013df034fa3497bcfc2b3b90 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/HUD.meta b/WorldlineKeepers/Assets/Scripts/UI/HUD.meta new file mode 100644 index 0000000..6718031 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/HUD.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9200672dd82f81947a018b2e1fb32e51 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/HUD/HealthBar.meta b/WorldlineKeepers/Assets/Scripts/UI/HUD/HealthBar.meta new file mode 100644 index 0000000..b5188ad --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/HUD/HealthBar.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 94b2ee526d964994098f0fa18c97fde0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators.meta new file mode 100644 index 0000000..04f831c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1b42061718486264697cae9c36222d2f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/AlienHunter.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/AlienHunter.meta new file mode 100644 index 0000000..cdff466 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/AlienHunter.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 757a90f0c6e2c764396bff0250fb2277 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Commander.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Commander.meta new file mode 100644 index 0000000..9023d77 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Commander.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3cbe084a794b93142b2e7541e538c496 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Cowboy.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Cowboy.meta new file mode 100644 index 0000000..f20cf83 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Cowboy.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e7e9b9896e5430b49b06feb71678dd49 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Cyborg.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Cyborg.meta new file mode 100644 index 0000000..b813caa --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Cyborg.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 56060244647985942ad6c6d3f7756210 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Finisher.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Finisher.meta new file mode 100644 index 0000000..cff88d8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Finisher.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7957fa2127514fe4a8d02e5f20b91a6b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/KingArthur.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/KingArthur.meta new file mode 100644 index 0000000..9e43dc8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/KingArthur.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7449f91a91e57494ba0e816e5a7e024e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Master.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Master.meta new file mode 100644 index 0000000..4354f3e --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Master.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 398c4315e8ba4a14d818621cb751b0f7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Mechanic.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Mechanic.meta new file mode 100644 index 0000000..c4b77cf --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Mechanic.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 16a1722ad71874946b31a35b58b057ab +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Ronin.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Ronin.meta new file mode 100644 index 0000000..d7240d4 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Ronin.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7217df6ac87f3014db7ddc6dacdaf751 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Ryoma.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Ryoma.meta new file mode 100644 index 0000000..8ad1a71 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Ryoma.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b78714d9dd260334c8edc619bb2a1a75 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Sifu.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Sifu.meta new file mode 100644 index 0000000..8b28750 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Sifu.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5f340a3f330f3a243b64f70f37a1452c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Type2.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Type2.meta new file mode 100644 index 0000000..ba8e64a --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Type2.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f3f08e7594f9a73439f0d5a210ba7092 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/UI/Operators/Wizard.meta b/WorldlineKeepers/Assets/Scripts/UI/Operators/Wizard.meta new file mode 100644 index 0000000..c1da9fa --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/UI/Operators/Wizard.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fe38ee934744cf4469eaa82d6ffe2ab6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit.meta b/WorldlineKeepers/Assets/Scripts/Unit.meta new file mode 100644 index 0000000..27611bc --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f7d86c9dd803498419020ec35ef24b6a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Characters.meta b/WorldlineKeepers/Assets/Scripts/Unit/Characters.meta new file mode 100644 index 0000000..3fdf467 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Characters.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8cf6de6efdd45544187236b496a10b60 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: 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: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Enemies.meta b/WorldlineKeepers/Assets/Scripts/Unit/Enemies.meta new file mode 100644 index 0000000..0256866 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Enemies.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cc665e807c1d03e43b9b106fcb1ae902 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs new file mode 100644 index 0000000..7ebae9c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs @@ -0,0 +1,113 @@ +using mh; +using MH; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SpiritScript : UnitBase +{ + public float speed = 10f; + + public Item_Coin coinPrefab; + + public int count = 0; + public float avg = 0; + + private FastCircleCollider collider; + + private static List<IQuadTreeObject> collisions = new List<IQuadTreeObject>(); + + private SpriteRenderer m_SpriteRenderer; + + private int m_CollisionCheckerCount = 0; + + private static int sCount = 0; + private static float sAvg = 0; + + protected override void Awake() + { + base.Awake(); + collider = GetComponent<FastCircleCollider>(); + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + speed = 2; + TestSpirits.spirits.Add(this); + } + + protected override void Update() + { + base.Update(); + } + + public void Tick() + { + UnitBase hero = UnitManager.hero; + Vector2 pos = transform.position; + Vector2 heroPos = hero.transform.position; + Vector2 dir = (heroPos - pos).normalized; + Vector2 dist = dir * Time.deltaTime * speed; // 位移 + m_SpriteRenderer.flipX = dir.x < 0; + + collisions.Clear(); + + bool bCollide = false; + // 这个优化可能会导致穿透 + //if (m_CollisionCheckerCount == 0 && PhysicsManager.Instance.RetriveColliders(ref collisions, collider)) + if (/*m_CollisionCheckerCount == 0 &&*/ PhysicsManager.Instance.RetriveColliders(ref collisions, collider)) + { + count = collisions.Count; + sAvg = (sCount * sAvg + count) / (float)(sCount + 1); + avg = sAvg; + sCount++; + bool movable = true; + Vector2 seperate = new Vector2(); + for (int i = 0; i < collisions.Count; ++i) + { + FastCircleCollider col = collisions[i] as FastCircleCollider; + if (col == collider) + continue; + if (PhysicsManager.CircleVsCircle(col.center, col.radius, collider.center, collider.radius)) + { + bCollide = true; + movable = false; + Vector2 distance = collider.center - col.center; + seperate = distance.normalized * (col.radius + collider.radius - distance.magnitude); // + dist -= (distance.normalized * dist) * distance.normalized; // 去除这个方向的位移 + dist += seperate; + } + } + if (!movable) + { + } + } + if (bCollide) + { + m_CollisionCheckerCount = 0; + } + else + { + m_CollisionCheckerCount++; + m_CollisionCheckerCount %= 10; + } + // dist = dist.normalized * Time.deltaTime * speed; // 保持原速 + transform.position += dist.ToVector3(); + } + + private void FixedUpdate() + { + } + + public void OnDestroy() + { + TestSpirits.spirits.Remove(this); + } + + public void Die() + { + Item_Coin coin = Instantiate(coinPrefab) as Item_Coin; + coin.transform.position = this.transform.position; + + this.gameObject.SetActive(false); + Destroy(this.gameObject); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs.meta new file mode 100644 index 0000000..57d99b0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/Enemies/SpiritScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3f7267bb8a6746409b3dbbaf48a575b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Unit/UnitBase.cs b/WorldlineKeepers/Assets/Scripts/Unit/UnitBase.cs new file mode 100644 index 0000000..9c5f0d0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/UnitBase.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UnitBase : EntityBase +{ + protected virtual void Awake() + { + base.Awake(); + } + + protected virtual void Update() + { + base.Update(); + } + + protected virtual void LateUpdate() + { + base.LateUpdate(); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Unit/UnitBase.cs.meta b/WorldlineKeepers/Assets/Scripts/Unit/UnitBase.cs.meta new file mode 100644 index 0000000..8552c51 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Unit/UnitBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fab9edfa070295e4b832f046b18f279b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils.meta b/WorldlineKeepers/Assets/Scripts/Utils.meta new file mode 100644 index 0000000..d4a02c5 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 899e3f93ed14bfd4eb299d3ba068e350 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils/FPSScript.cs b/WorldlineKeepers/Assets/Scripts/Utils/FPSScript.cs new file mode 100644 index 0000000..9c9a444 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/FPSScript.cs @@ -0,0 +1,33 @@ +using UnityEngine; +using UnityEngine.UI; +using System.Collections; + +namespace FBCapture +{ + public class FPSScript : MonoBehaviour + { + /// <summary> + /// Delta time + /// </summary> + float deltaTime = 0.0f; + + /// <summary> + /// It will be used for printing out fps text on screen + /// </summary> + Text text; + + void Start() + { + text = GetComponent<Text>(); + } + + void Update() + { + deltaTime += (Time.deltaTime - deltaTime) * 0.1f; + float msec = deltaTime * 1000.0f; + float fps = 1.0f / deltaTime; + text.text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps); + } + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Utils/FPSScript.cs.meta b/WorldlineKeepers/Assets/Scripts/Utils/FPSScript.cs.meta new file mode 100644 index 0000000..d6119a8 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/FPSScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: db0f6a04d6782e54bafd5a1865a0dae5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils/MathUtils.cs b/WorldlineKeepers/Assets/Scripts/Utils/MathUtils.cs new file mode 100644 index 0000000..c997495 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/MathUtils.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class MathUtils +{ + + public static Vector2 Abs(Vector2 v) + { + return new Vector2(Mathf.Abs(v.x), Mathf.Abs(v.y)); + } + + public static Vector2 Max(Vector2 src, float v) + { + return new Vector2(Mathf.Max(src.x, v), Mathf.Max(src.y, v)); + } + + public static void Swap(ref float f1, ref float f2) + { + float t = f1; + f1 = f2; + f2 = t; + } + +}
\ No newline at end of file diff --git a/WorldlineKeepers/Assets/Scripts/Utils/MathUtils.cs.meta b/WorldlineKeepers/Assets/Scripts/Utils/MathUtils.cs.meta new file mode 100644 index 0000000..8e8b33c --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/MathUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b829e1e17fa796408f3a7b1a42ed1ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils/Vector2Extension.cs b/WorldlineKeepers/Assets/Scripts/Utils/Vector2Extension.cs new file mode 100644 index 0000000..aa96509 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/Vector2Extension.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEditor; +using UnityEngine; + +public static class Vector2Extension +{ + + public static Vector3 ConvertToVector3(Vector2 src) + { + Vector3 dst = new Vector3(); + dst.x = src.x; + dst.y = src.y; + dst.z = 0; + return dst; + } + + public static Vector3 ToVector3(this Vector2 src) + { + return ConvertToVector3(src); + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Utils/Vector2Extension.cs.meta b/WorldlineKeepers/Assets/Scripts/Utils/Vector2Extension.cs.meta new file mode 100644 index 0000000..3acd9ed --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/Vector2Extension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4919fc0478a262544b3b7149ec7a331d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils/Vector3Extension.cs b/WorldlineKeepers/Assets/Scripts/Utils/Vector3Extension.cs new file mode 100644 index 0000000..5afe941 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/Vector3Extension.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEditor; +using UnityEngine; + +public static class Vector3Extension +{ + + public static Vector2 xy(this Vector3 src) + { + Vector2 xy = new Vector2(); + xy.x = src.x; + xy.y = src.y; + return xy; + } + + public static Vector2 ToVector2(this Vector3 src) + { + Vector2 xy = new Vector2(); + xy.x = src.x; + xy.y = src.y; + return xy; + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Utils/Vector3Extension.cs.meta b/WorldlineKeepers/Assets/Scripts/Utils/Vector3Extension.cs.meta new file mode 100644 index 0000000..e563122 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/Vector3Extension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3ec9d2ccbb46814eaa97fe04f1089e9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Utils/Vector4Extension.cs b/WorldlineKeepers/Assets/Scripts/Utils/Vector4Extension.cs new file mode 100644 index 0000000..e4b9b35 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/Vector4Extension.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEditor; +using UnityEngine; + +public static class Vector4Extension +{ + + public static Vector2 xy(this Vector4 src) + { + Vector2 xy = new Vector2(); + xy.x = src.x; + xy.y = src.y; + return xy; + } + + public static Vector2 zw(this Vector4 src) + { + Vector2 zw = new Vector2(); + zw.x = src.z; + zw.y = src.w; + return zw; + } + + public static Vector2 ToVector2(this Vector4 src) + { + Vector2 xy = new Vector2(); + xy.x = src.x; + xy.y = src.y; + return xy; + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Utils/Vector4Extension.cs.meta b/WorldlineKeepers/Assets/Scripts/Utils/Vector4Extension.cs.meta new file mode 100644 index 0000000..b2d1dc0 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Utils/Vector4Extension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a622b0bd09ab0242af55f6fb5660eda +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/VampireScript.cs b/WorldlineKeepers/Assets/Scripts/VampireScript.cs new file mode 100644 index 0000000..2f993d3 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/VampireScript.cs @@ -0,0 +1,68 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace MH +{ + + public class VampireScript : UnitBase + { + public Camera m_Camera; + + private SpriteRenderer m_Sprite; + + private bool m_Moving; + + void Start() + { + m_Moving = true; + m_Sprite = GetComponent<SpriteRenderer>(); + } + + protected override void Update() + { + base.Update(); + + if (Input.GetMouseButtonDown(1)) + { + m_Moving = !m_Moving; + } + + GetComponent<Animator>().speed = m_Moving ? 1 : 0; + + if (!m_Moving) + return; + + 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*2; + + Vector3 camPos = m_Camera.transform.position; + camPos.x = pos.x; + camPos.y = pos.y; + m_Camera.transform.position = camPos; + + m_Sprite.flipX = dir.x <= 0; + + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/VampireScript.cs.meta b/WorldlineKeepers/Assets/Scripts/VampireScript.cs.meta new file mode 100644 index 0000000..0704d49 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/VampireScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9a61bc1447e0f5a43a2a45443a32cd50 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/WaypointScript.cs b/WorldlineKeepers/Assets/Scripts/WaypointScript.cs new file mode 100644 index 0000000..1012bc2 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/WaypointScript.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class WaypointScript : MonoBehaviour +{ + public float life; + + // Start is called before the first frame update + void Start() + { + StartCoroutine(CoUpdate()); + } + + + IEnumerator CoUpdate() { + float t = 0; + while (true) + { + Color c = this.gameObject.GetComponent<SpriteRenderer>().color; + c.a *= 0.99f; + this.gameObject.GetComponent<SpriteRenderer>().color = c; + this.transform.localScale *= 1.002f; + t+= Time.deltaTime; + if(t > life) + { + Destroy(this.gameObject); + yield break; + } + yield return null; + } + } + + +} diff --git a/WorldlineKeepers/Assets/Scripts/WaypointScript.cs.meta b/WorldlineKeepers/Assets/Scripts/WaypointScript.cs.meta new file mode 100644 index 0000000..f58f668 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/WaypointScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f30c6188a9717a44a8a44c46bfd45a1a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |