diff options
Diffstat (limited to 'SurvivalTest/Assets/Scripts')
138 files changed, 3694 insertions, 0 deletions
diff --git a/SurvivalTest/Assets/Scripts/Editor.meta b/SurvivalTest/Assets/Scripts/Editor.meta new file mode 100644 index 0000000..58829a3 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d4ca91bb615252040a8e7572963b172a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Editor/TransformInspectorOverride.cs b/SurvivalTest/Assets/Scripts/Editor/TransformInspectorOverride.cs new file mode 100644 index 0000000..76cb48c --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Editor/TransformInspectorOverride.cs @@ -0,0 +1,68 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +[CanEditMultipleObjects, CustomEditor(typeof(Transform), true)] +public class TransformInspectorOverride : InspectorExt +{ + protected override string defaultEditorName => "UnityEditor.TransformInspector, UnityEditor"; + + Tool LastTool = Tool.None; + + public override void OnEnable() + { + base.OnEnable(); + + if(HasTopDownTransform()) + HideDefaultTools(); + } + + public override void OnDisable() + { + base.OnDisable(); + + if(LastTool != Tool.None) + RestoreTools(); + } + + void HideDefaultTools() + { + if(Tools.current != Tool.None) + LastTool = Tools.current; + Tools.current = Tool.None; + } + + void RestoreTools() + { + Tools.current = LastTool; + } + + public override void OnInspectorGUI() + { + if (HasTopDownTransform()) + { + EditorGUILayout.HelpBox("Override by TopDownTransform", MessageType.Warning); + GUI.enabled = false; + HideDefaultTools(); + } + + base.OnInspectorGUI(); + + if (HasTopDownTransform()) + GUI.enabled = true; + } + + bool HasTopDownTransform() + { + Transform transform = target as Transform; + TopDownTransform topdown = transform.GetComponent<TopDownTransform>(); + return topdown != null; + } + + public override void OnSceneGUI() + { + base.OnSceneGUI(); + } + +} diff --git a/SurvivalTest/Assets/Scripts/Editor/TransformInspectorOverride.cs.meta b/SurvivalTest/Assets/Scripts/Editor/TransformInspectorOverride.cs.meta new file mode 100644 index 0000000..c9f0922 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Editor/TransformInspectorOverride.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8027cfacc5652a6459adfbe2d9522671 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/GameApp.cs b/SurvivalTest/Assets/Scripts/GameApp.cs new file mode 100644 index 0000000..d5f9d70 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/GameApp.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[DisallowMultipleComponent] +public class GameApp : MonoBehaviour +{ + + void Start() + { + + } + + void Update() + { + GameLoop.Instance.Update(); + TinyCountDown.Instance.Update(); + } + + void LateUpdate() + { + + } + +} diff --git a/SurvivalTest/Assets/Scripts/GameApp.cs.meta b/SurvivalTest/Assets/Scripts/GameApp.cs.meta new file mode 100644 index 0000000..3c64a3e --- /dev/null +++ b/SurvivalTest/Assets/Scripts/GameApp.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4a8eff5fd2fd4e34e8896ce4c086ba44 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: -1100 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics.meta b/SurvivalTest/Assets/Scripts/Physics.meta new file mode 100644 index 0000000..cfe079d --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7e5fc1a856751be4286cf39720d597cb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics/AABBShape.cs b/SurvivalTest/Assets/Scripts/Physics/AABBShape.cs new file mode 100644 index 0000000..abff597 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/AABBShape.cs @@ -0,0 +1,45 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +[RequireComponent(typeof(TopDownTransform))] +public class AABBShape : ShapeBase +{ + + [Tooltip("中心点(相对此节点的偏移)")] + [SerializeField] private Vector2 m_Centre; + public Vector2 centre { get { return m_Centre;} set { m_Centre = value; } } + + [Tooltip("大小(TopDown空间下)")] + [SerializeField] private Vector2 m_Size; + public Vector2 size { get { return m_Size; } set { m_Size = value; } } + + private TopDownTransform m_TopDownTransform; + private TopDownTransform topdownTransform + { + get + { + if(m_TopDownTransform == null) + { + m_TopDownTransform = GetComponent<TopDownTransform>(); + } + + return m_TopDownTransform; + } + } + +#if UNITY_EDITOR + + private void OnDrawGizmos() + { + Vector3 pos = topdownTransform.GetProjectedPosition(); + Handles.color = Color.green; + Handles.DrawWireCube(pos + new Vector3(m_Centre.x, m_Centre.y, 0), new Vector3(size.x, size.y, 0)); + } + +#endif + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Physics/AABBShape.cs.meta b/SurvivalTest/Assets/Scripts/Physics/AABBShape.cs.meta new file mode 100644 index 0000000..e7c4f4f --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/AABBShape.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b0b865519e5d4f647a0dd9ea2df1236e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics/BoxShape.cs b/SurvivalTest/Assets/Scripts/Physics/BoxShape.cs new file mode 100644 index 0000000..b5a4e7b --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/BoxShape.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(TopDownTransform))] +public class BoxShape : ShapeBase +{ + + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Physics/BoxShape.cs.meta b/SurvivalTest/Assets/Scripts/Physics/BoxShape.cs.meta new file mode 100644 index 0000000..03de3e1 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/BoxShape.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bdcf6431eefbc384b8c38c8323bb1c89 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics/CircleShape.cs b/SurvivalTest/Assets/Scripts/Physics/CircleShape.cs new file mode 100644 index 0000000..3626598 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/CircleShape.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(TopDownTransform))] +public class CircleShape : ShapeBase +{ + [Tooltip("圆心(相对此节点的偏移)")] + [SerializeField] private Vector2 m_Centre; + public Vector2 centre { get { return m_Centre; } set { m_Centre = value; } } + + [Tooltip("半径(TopDown空间下)")] + [SerializeField] private float m_Radius; + public float radius { get { return m_Radius; } set { m_Radius = value; } } + + + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Physics/CircleShape.cs.meta b/SurvivalTest/Assets/Scripts/Physics/CircleShape.cs.meta new file mode 100644 index 0000000..814087d --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/CircleShape.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2a0bd7154c667b741961ea5ed11902e5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics/PhysicsHelper.cs b/SurvivalTest/Assets/Scripts/Physics/PhysicsHelper.cs new file mode 100644 index 0000000..907ca05 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/PhysicsHelper.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PhysicsHelper : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/Physics/PhysicsHelper.cs.meta b/SurvivalTest/Assets/Scripts/Physics/PhysicsHelper.cs.meta new file mode 100644 index 0000000..8fa3233 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/PhysicsHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7f9f362c9de0e554a86367b068464b72 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics/PolygonShape.cs b/SurvivalTest/Assets/Scripts/Physics/PolygonShape.cs new file mode 100644 index 0000000..ce17bfe --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/PolygonShape.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PolygonShape : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/Physics/PolygonShape.cs.meta b/SurvivalTest/Assets/Scripts/Physics/PolygonShape.cs.meta new file mode 100644 index 0000000..6116bdb --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/PolygonShape.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0cb3172194a30a741861e9cbb48bfb67 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics/README.txt b/SurvivalTest/Assets/Scripts/Physics/README.txt new file mode 100644 index 0000000..759fc01 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/README.txt @@ -0,0 +1 @@ +topdown physics module
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Physics/README.txt.meta b/SurvivalTest/Assets/Scripts/Physics/README.txt.meta new file mode 100644 index 0000000..c7df70e --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/README.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3b644e307740eba429bf19c41ea90b36 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Physics/ShapeBase.cs b/SurvivalTest/Assets/Scripts/Physics/ShapeBase.cs new file mode 100644 index 0000000..a0eba25 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/ShapeBase.cs @@ -0,0 +1,9 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ShapeBase : MonoBehaviour +{ + + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Physics/ShapeBase.cs.meta b/SurvivalTest/Assets/Scripts/Physics/ShapeBase.cs.meta new file mode 100644 index 0000000..3942766 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Physics/ShapeBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 765f0727121051042866a2c615ab2560 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Rendering.meta b/SurvivalTest/Assets/Scripts/Rendering.meta new file mode 100644 index 0000000..5983da2 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Rendering.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f708dc500b39f5b47b15cab2502b39ee +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test.meta b/SurvivalTest/Assets/Scripts/Test.meta new file mode 100644 index 0000000..77f1e2b --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 52be12b547ad9fd4bb3108d3411818c0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestAstro.cs b/SurvivalTest/Assets/Scripts/Test/TestAstro.cs new file mode 100644 index 0000000..3b4df18 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestAstro.cs @@ -0,0 +1,77 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestAstro : MonoBehaviour +{ + [SerializeField] private Transform m_Camera; + + [SerializeField] private float m_Speed; + + [SerializeField] private SpriteRenderer m_Shadow; + + private SpriteRenderer m_SpriteRenderer; + private TestFakeHeight m_FakeHeight; + + + + void Start() + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + m_FakeHeight = GetComponent<TestFakeHeight>(); + } + + void Update() + { + float x = Input.GetAxisRaw("Horizontal"); + float y = Input.GetAxisRaw("Vertical"); + + Vector3 targetZoom = Vector3.one; + + if(x != 0 || y != 0) + { + targetZoom = new Vector3(1f, 1f, 1); + + Vector2 direction = new Vector2(x, y).normalized; + + Vector3 position = transform.position; + position.x += direction.x * m_Speed * Time.deltaTime; + position.y += direction.y * m_Speed * Time.deltaTime; + + transform.position = position; + + if (x > 0) + { + m_SpriteRenderer.flipX = false; + m_Shadow.flipX = false; + } + else if (x < 0) + { + m_SpriteRenderer.flipX = true; + m_Shadow.flipX = true; + } + } + else + { + targetZoom = new Vector3(0.5f, 0.5f, 1); + } + + Vector3 zoom = m_Camera.localScale; + m_Camera.localScale = Vector3.Lerp(zoom, targetZoom, Time.deltaTime); + + CameraFollow(); + } + + void CameraFollow() + { + Vector3 pos = m_Camera.position; + pos.x = m_FakeHeight.x; + pos.y = m_FakeHeight.y; + + if(Vector3.Distance(pos, m_Camera.position) > 0.1f) + { + m_Camera.position = Vector3.Lerp(m_Camera.position, pos, 3 * Time.deltaTime); + } + + } +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestAstro.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestAstro.cs.meta new file mode 100644 index 0000000..a96a9b4 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestAstro.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dc04e45eaa06e994a806119e4fd0701c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestB2.cs b/SurvivalTest/Assets/Scripts/Test/TestB2.cs new file mode 100644 index 0000000..532c254 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestB2.cs @@ -0,0 +1,79 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestB2 : MonoBehaviour +{ + [SerializeField] private TestBomb m_Bomb; + [SerializeField] private float m_Speed; + + private Vector3 m_From; + private Vector3 m_To; + + private Coroutine m_CoBomb; + + Vector3 direction + { + get + { + return (m_To - m_From).normalized; + } + } + + /// <summary> + /// from to 在3d空间 + /// </summary> + /// <param name="from"></param> + /// <param name="to"></param> + public void Set(Vector3 from, Vector3 to, float speed, float lifeTime) + { + m_From = from; + m_To = to; + m_Speed = speed; + + transform.position = from; + + this.gameObject.SetActive(true); + + m_CoBomb = StartCoroutine(coBomb(0.1f)); + + Invoke("DestroySelf", lifeTime); + } + + void DestroySelf() + { + if (m_CoBomb != null) + { + StopCoroutine(m_CoBomb); + m_CoBomb = null; + } + this.gameObject.SetActive(false); + Destroy(this.gameObject); + } + + private void Update() + { + Vector3 pos = transform.position; + pos += direction * m_Speed * Time.deltaTime; + + transform.position = pos; + } + + IEnumerator coBomb(float interval) + { + while (true) + { + Vector3 pos = transform.position; + for(int i = 0; i < 1; ++i) + { + TestBomb grenade = Instantiate<TestBomb>(m_Bomb); + Vector3 position = new Vector3(pos.x + Random.Range(-3, 3), pos.y + Random.Range(-5f, 5f), 7f); + grenade.Set(position, new Vector3(0, 0, -1f), Random.Range(8f, 10f)); + grenade.gameObject.SetActive(true); + } + + yield return new WaitForSeconds(interval); + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestB2.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestB2.cs.meta new file mode 100644 index 0000000..1e507c7 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestB2.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a908894d8ef917543ad67959640ec30b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestBeamBullet.cs b/SurvivalTest/Assets/Scripts/Test/TestBeamBullet.cs new file mode 100644 index 0000000..17d0005 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBeamBullet.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestBeamBullet : MonoBehaviour +{ + public Vector3 direction; + public float speed; + + // Start is called before the first frame update + void Start() + { + Invoke("Dead", 3); + } + + void Dead() + { + if (this.gameObject) + { + GameObject.Destroy(this.gameObject); + } + } + + // Update is called once per frame + void Update() + { + Vector3 position = transform.position; + position += direction * speed * Time.deltaTime; + transform.position = position; + } + + private void OnTriggerEnter2D(Collider2D collision) + { + GameObject go = collision.gameObject; + + if (!go.CompareTag("enemy")) + { + return; + } + + GameObject.Destroy( collision.gameObject); + + //this.gameObject.SetActive(false); + + if (this.gameObject) + { + GameObject.Destroy(this.gameObject); + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestBeamBullet.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestBeamBullet.cs.meta new file mode 100644 index 0000000..b1551a7 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBeamBullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ca62ef044d3b4104eac135eea37e0c03 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestBeamGun.cs b/SurvivalTest/Assets/Scripts/Test/TestBeamGun.cs new file mode 100644 index 0000000..69225b6 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBeamGun.cs @@ -0,0 +1,79 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestBeamGun : MonoBehaviour +{ + public TestBeamBullet bullet; + + public Transform start; + + public float speed = 1; + + SpriteRenderer sprite; + + // Start is called before the first frame update + void Start() + { + sprite = GetComponent<SpriteRenderer>(); + + // StartCoroutine(coFire()); + } + + // Update is called once per frame + void Update() + { + + Vector3 screenPos = Input.mousePosition; + + Vector2 target = Camera.main.ScreenToWorldPoint(screenPos); + + Vector2 dir = Vector2.ClampMagnitude(target - (Vector2)transform.position, 1); + Vector3 move = dir * speed * Time.deltaTime; + + float x = move.x; + if (x > 0) + { + sprite.flipY = false; + } + else if (x < 0) + { + sprite.flipY = true; + } + + transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x)); + + Shot(); + } + + void Shot() + { + if (Input.GetButtonDown("Fire1")) + { + //Debug.Log("Shoot"); + + TestBeamBullet b = TestBeamBullet.Instantiate(bullet); + b.gameObject.SetActive(true); + + b.transform.position = start.position; + + b.direction = transform.right; + } + } + + IEnumerator coFire() + { + while (true) + { + TestBeamBullet b = TestBeamBullet.Instantiate(bullet); + b.gameObject.SetActive(true); + + b.transform.position = start.position; + + b.direction = transform.right; + + yield return new WaitForSeconds(0.5f); + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestBeamGun.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestBeamGun.cs.meta new file mode 100644 index 0000000..cfeb8f2 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBeamGun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 058a2b89691b2f94d912ff341719edd9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestBomb.cs b/SurvivalTest/Assets/Scripts/Test/TestBomb.cs new file mode 100644 index 0000000..77933f4 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBomb.cs @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestBomb : MonoBehaviour +{ + + [SerializeField] private float m_GravityScale = 1f; + + [SerializeField] private GameObject m_ExplosionEffect; + + private TopDownTransform m_Coords; + + private Vector3 GRAVITY = new Vector3(0, 0, -9.8f); + + private Vector3 m_Velocity; // x, y, fakeHeight + + /// <summary> + /// 设置初始参数,都在fake空间下 + /// </summary> + /// <param name="initPosition"></param> + /// <param name="initDirection"></param> + /// <param name="initSpeed"></param> + public void Set(Vector3 initPosition, Vector3 initDirection, float initSpeed) + { + m_Coords = GetComponent<TopDownTransform>(); + m_Coords.position = initPosition; + + m_Velocity = initDirection * initSpeed; + } + + private void Update() + { + Vector3 move = m_Velocity * Time.deltaTime; + + if (m_Velocity.magnitude > 0 && m_Coords.z + move.z >= 0) + { + m_Coords.x += move.x; + m_Coords.y += move.y; + m_Coords.z += move.z; + m_Velocity += GRAVITY * Time.deltaTime; + + //transform.rotation *= Quaternion.Euler(0, 0, 20 * m_Velocity.magnitude * Time.deltaTime); + } + else + { + m_Velocity = Vector3.zero; + + this.gameObject.SetActive(false); + Destroy(this.gameObject); + PlayExplosion(); + } + } + + private void PlayExplosion() + { + GameObject exp = Instantiate<GameObject>(m_ExplosionEffect); + + TopDownTransform coord = exp.GetComponent<TopDownTransform>(); + coord.position = m_Coords.position; + + exp.GetComponent<TopDownSorting>().Sorting(); + + exp.SetActive(true); + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestBomb.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestBomb.cs.meta new file mode 100644 index 0000000..06d61d2 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBomb.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0bb267c6728269489ed4f713b032db5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestBrokenPiece.cs b/SurvivalTest/Assets/Scripts/Test/TestBrokenPiece.cs new file mode 100644 index 0000000..4399886 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBrokenPiece.cs @@ -0,0 +1,107 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestBrokenPiece : MonoBehaviour +{ + [SerializeField] private List<Sprite> m_Pieces; + + private TestFakeHeight m_Coord; + + private Vector3 m_Velocity; + + private Vector3 m_Gravity = new Vector3(0, 0, -9.8f); + + private float m_Damp = 0.5f; + + private SpriteRenderer m_SpriteRenderer; + + enum State + { + Avlie , + Dead , + } + + State m_State; + + private void Awake() + { + m_Coord = GetComponent<TestFakeHeight>(); + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + } + + public void Set(Vector3 position, Vector3 dir, float speed, int index) + { + m_Coord = GetComponent<TestFakeHeight>(); + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + + m_Coord.x = position.x; + m_Coord.y = position.y; + m_Coord.height = position.z; + + m_Velocity = dir * speed; + + m_SpriteRenderer.sprite = m_Pieces[index % m_Pieces.Count]; + + m_State = State.Avlie; + } + + private void Update() + { + if(m_State == State.Avlie) + { + m_Velocity += m_Gravity * Time.deltaTime; + + m_Coord.x += m_Velocity.x * Time.deltaTime; + m_Coord.y += m_Velocity.y * Time.deltaTime; + m_Coord.height += m_Velocity.z * Time.deltaTime; + + if (m_Coord.height < 0) + { + m_Coord.height = 0; + + // bounce + m_Velocity.x = m_Velocity.x * m_Damp; + m_Velocity.y = m_Velocity.y * m_Damp; + m_Velocity.z = -m_Velocity.z * m_Damp; + + if (m_Velocity.magnitude < 0.1f) + { + m_State = State.Dead; + StartCoroutine(coDead(Random.Range(1f, 3f))); + } + } + } + else if(m_State == State.Dead) + { + } + } + + IEnumerator coDead( float time) + { + Color c = m_SpriteRenderer.color; + + float t = 0; + while (true) + { + t += Time.deltaTime; + + c.a = (time - t) / time; + + m_SpriteRenderer.color = c; + + if(t > time) + { + break; + } + + yield return null; + } + + this.gameObject.SetActive(false); + Destroy(this.gameObject); + + yield break; + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestBrokenPiece.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestBrokenPiece.cs.meta new file mode 100644 index 0000000..73da026 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBrokenPiece.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c7182d8bf5ade5c47a2a98ae355119f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestBucket.cs b/SurvivalTest/Assets/Scripts/Test/TestBucket.cs new file mode 100644 index 0000000..c3e28f4 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBucket.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestBucket : MonoBehaviour +{ + [SerializeField] private TestBrokenPiece m_Piece; + + private TopDownTransform m_Coord; + + private void Awake() + { + m_Coord = GetComponent<TopDownTransform>(); + } + + public void Broken() + { + for(int i = 0; i < 10; ++i) + { + TestBrokenPiece piece = Instantiate<TestBrokenPiece>(m_Piece); + piece.Set(m_Coord.position + new Vector3(0,0,1f), + new Vector3(Random.Range(-1f,1f), Random.Range(-1f, 1f), Random.Range(0.5f, 2f)).normalized, Random.Range(1f, 3f) + , i); + } + + this.gameObject.SetActive(false); + Destroy(this.gameObject); + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestBucket.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestBucket.cs.meta new file mode 100644 index 0000000..3d9e92b --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestBucket.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3861aac24d796348936aa3f51d27a97 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestCameraSortByY.cs b/SurvivalTest/Assets/Scripts/Test/TestCameraSortByY.cs new file mode 100644 index 0000000..585f2c3 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestCameraSortByY.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(Camera))] +public class TestCameraSortByY : MonoBehaviour +{ + private Camera camera; + + // Start is called before the first frame update + void Start() + { + camera = GetComponent<Camera>(); + camera.transparencySortMode = TransparencySortMode.CustomAxis; + camera.transparencySortAxis = Vector3.up; + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestCameraSortByY.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestCameraSortByY.cs.meta new file mode 100644 index 0000000..210a02e --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestCameraSortByY.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b692e7619b71ada41b02f616b9a6134d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestCannon.cs b/SurvivalTest/Assets/Scripts/Test/TestCannon.cs new file mode 100644 index 0000000..22b168b --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestCannon.cs @@ -0,0 +1,44 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestCannon : MonoBehaviour +{ + public TestBeamBullet bullet; + + public Transform start; + + public float speed = 1; + + SpriteRenderer sprite; + + // Start is called before the first frame update + void Start() + { + sprite = GetComponent<SpriteRenderer>(); + + StartCoroutine(coFire(1f)); + } + + // Update is called once per frame + void Update() + { + + } + + IEnumerator coFire(float interval) + { + while (true) + { + TestBeamBullet b = TestBeamBullet.Instantiate(bullet); + b.gameObject.SetActive(true); + + b.transform.position = start.position; + + b.direction = -transform.right; + + yield return new WaitForSeconds(interval); + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestCannon.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestCannon.cs.meta new file mode 100644 index 0000000..52c902c --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestCannon.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 14e80cec1a94a5449b2081ac81bea639 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestCharacterMovement.cs b/SurvivalTest/Assets/Scripts/Test/TestCharacterMovement.cs new file mode 100644 index 0000000..8911ea9 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestCharacterMovement.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestCharacterMovement : MonoBehaviour +{ + public SpriteRenderer sprite; + + public float speed; + + // Start is called before the first frame update + void Start() + { + sprite = GetComponent<SpriteRenderer>(); + + } + + // Update is called once per frame + void Update() + { + float x = Input.GetAxis("Horizontal"); + float y = Input.GetAxis("Vertical"); + + Vector3 position = transform.position; + position.x += x * speed * Time.deltaTime; + position.y += y * speed * Time.deltaTime; + + transform.position = position; + + if (x > 0) + { + sprite.flipX = false; + } + else if(x < 0) + { + sprite.flipX = true; + } + + } +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestCharacterMovement.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestCharacterMovement.cs.meta new file mode 100644 index 0000000..606b4cc --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestCharacterMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2fd7e5c6f466b7448001599a97c5b58 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestDestroySelf.cs b/SurvivalTest/Assets/Scripts/Test/TestDestroySelf.cs new file mode 100644 index 0000000..e0457cd --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestDestroySelf.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestDestroySelf : MonoBehaviour +{ + public float lifeTime; + + public AnimationCurve alphaCurve; + + private float time; + + private SpriteRenderer sr; + + void Start() + { + Invoke("DestroySelf", lifeTime); + time = 0; + sr = GetComponent<SpriteRenderer>(); + } + + void DestroySelf() + { + this.gameObject.SetActive(false); + Destroy(this.gameObject); + } + + void Update() + { + time += Time.deltaTime; + + if (sr) + { + Color c = sr.color; + c.a = alphaCurve.Evaluate(time / lifeTime); + sr.color = c; + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestDestroySelf.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestDestroySelf.cs.meta new file mode 100644 index 0000000..c1dc2b5 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestDestroySelf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6bde42b3ff5cbc44ca4e036544c3cde9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestEnforceTransform0.cs b/SurvivalTest/Assets/Scripts/Test/TestEnforceTransform0.cs new file mode 100644 index 0000000..57b777d --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestEnforceTransform0.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestEnforceTransform0 : MonoBehaviour +{ + void Update() + { +// transform.localToWorldMatrix = Matrix4x4.identity; + } +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestEnforceTransform0.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestEnforceTransform0.cs.meta new file mode 100644 index 0000000..3371029 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestEnforceTransform0.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 666db70fcce7c7e4a94cc321eb68e307 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestFakeCube.cs b/SurvivalTest/Assets/Scripts/Test/TestFakeCube.cs new file mode 100644 index 0000000..5d8f2c5 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestFakeCube.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestFakeCube : MonoBehaviour +{ + public float z; // fake height + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestFakeCube.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestFakeCube.cs.meta new file mode 100644 index 0000000..83c3602 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestFakeCube.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 84033172d3ac67f4eb3eb8586b6ecb11 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestFakeHeight.cs b/SurvivalTest/Assets/Scripts/Test/TestFakeHeight.cs new file mode 100644 index 0000000..4cc13d1 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestFakeHeight.cs @@ -0,0 +1,132 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +//[ExecuteInEditMode] +public class TestFakeHeight : MonoBehaviour +{ + [SerializeField] private Transform m_Shadow; + [SerializeField] private Vector3 m_Coord; + + + public float height { + get + { + return m_Height; + } + set + { + m_Height = value; + } + } + [SerializeField] private float m_Height; // current fake height + + public float x + { + get + { + return transform.position.x; + } + + set + { + Vector3 pos = transform.position; + pos.x = value; + transform.position = pos; + } + } + + public float y + { + get + { + return transform.position.y - m_Height; + } + set + { + Vector3 pos = transform.position; + pos.y = value + m_Height; + transform.position = pos; + } + } + + public Vector3 position + { + get + { + Vector3 pos = new Vector3(x, y, height); + return pos; + } + set + { + height = value.z; // height先设置 + x = value.x; + y = value.y; + } + } + + public Vector2 positionOnGround + { + get + { + Vector2 pos = new Vector2(x, y); + return pos; + } + set + { + x = value.x; + y = value.y; + } + } + + private SpriteRenderer m_SpriteRenderer; + + private void OnEnable() + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + } + + private void Start() + { + Project(); + } + + void Project() + { + Vector3 pos = transform.position; + pos.y = y + height; + transform.position = pos; + + if (m_Shadow != null) + { + m_Shadow.position = new Vector3(transform.position.x, transform.position.y - m_Height, transform.position.z); + } + + // 根据y设置sortOrder + m_SpriteRenderer.sortingOrder = (int)(-y * 100); + } + + void Update() + { + Project(); + } + +#if UNITY_EDITOR + + private void OnDrawGizmos() + { + // dash line + Vector3 start = transform.position; + Vector3 end = start - new Vector3(0, m_Height, 0); + + Handles.DrawDottedLine(start, end, 1f); + Handles.DrawWireCube(end, new Vector3(0.1f, 0.1f, 0f)); + + } + +#endif + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestFakeHeight.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestFakeHeight.cs.meta new file mode 100644 index 0000000..a91173e --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestFakeHeight.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 780072e6ea35d1f4abd930754c5e9c9f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestGrenade.cs b/SurvivalTest/Assets/Scripts/Test/TestGrenade.cs new file mode 100644 index 0000000..a1434d8 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestGrenade.cs @@ -0,0 +1,107 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestPseudoVec3 +{ + public float x; + public float y; + public float h; + public TestPseudoVec3(float x, float y, float h) + { + this.x = x; + this.y = y; + this.h = h; + } +} + +public class TestGrenade : MonoBehaviour +{ + public bool useGravity; + + public float gravity = -9.8f; + + public TestPseudoVec3 velocity; + public TestPseudoVec3 pseudoPos; + + public Transform shadow; + + private bool m_IsGround + { + get + { + return pseudoPos.h <= 0; + } + } + + // Start is called before the first frame update + void Start() + { + //Invoke("Dead", 3); + } + + void Dead() + { + if (this.gameObject) + { + GameObject.Destroy(this.gameObject); + } + } + + // Update is called once per frame + void Update() + { + if(useGravity && !m_IsGround) + { + velocity.h += gravity * Time.deltaTime; + } + + pseudoPos.x += velocity.x * Time.deltaTime; + pseudoPos.y += velocity.y * Time.deltaTime; + pseudoPos.h += velocity.h * Time.deltaTime; + + if(m_IsGround) + { + velocity.h = -velocity.h; + pseudoPos.h = 0; + } + + Vector3 position = transform.position; + + position.x = pseudoPos.x; + position.y = pseudoPos.y + pseudoPos.h; + + transform.position = position; + + if (shadow) + { + // shadow position + shadow.rotation = Quaternion.identity; + Vector3 shadowPos = Vector3.zero; + shadowPos.x = pseudoPos.x; + shadowPos.y = pseudoPos.y; + shadowPos.z = 0; + shadow.position = shadowPos; + } + } + + private void OnTriggerEnter2D(Collider2D collision) + { + //GameObject go = collision.gameObject; + + //if (!go.CompareTag("enemy")) + //{ + // return; + //} + + //GameObject.Destroy(collision.gameObject); + + ////this.gameObject.SetActive(false); + + //if (this.gameObject) + //{ + // GameObject.Destroy(this.gameObject); + //} + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestGrenade.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestGrenade.cs.meta new file mode 100644 index 0000000..f5d87e9 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestGrenade.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76da92161ea22274996c5bc1d0bdea94 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestLauncher.cs b/SurvivalTest/Assets/Scripts/Test/TestLauncher.cs new file mode 100644 index 0000000..f053854 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestLauncher.cs @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestLauncher : MonoBehaviour +{ + public TestGrenade bullet; + + public Transform shadow; + + public Transform start; + + public float speed = 1; + + SpriteRenderer sprite; + + // Start is called before the first frame update + void Start() + { + sprite = GetComponent<SpriteRenderer>(); + } + + // Update is called once per frame + void Update() + { + + Vector3 screenPos = Input.mousePosition; + + Vector2 target = Camera.main.ScreenToWorldPoint(screenPos); + + Vector2 dir = Vector2.ClampMagnitude(target - (Vector2)transform.position, 1); + Vector3 move = dir * speed * Time.deltaTime; + + float x = move.x; + if (x > 0) + { + sprite.flipY = false; + } + else if (x < 0) + { + sprite.flipY = true; + } + + transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x)); + + Shot(); + } + + void Shot() + { + if (Input.GetButtonDown("Fire1")) + { + //Debug.Log("Shoot"); + + TestGrenade b = TestGrenade.Instantiate(bullet); + b.gameObject.SetActive(true); + + b.transform.position = start.position; + + b.pseudoPos = new TestPseudoVec3(start.position.x, start.position.y, 0.1f); + + float speed = 5; + b.velocity = new TestPseudoVec3(transform.right.x * speed, transform.right.y * speed, 3f); + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestLauncher.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestLauncher.cs.meta new file mode 100644 index 0000000..8688fc3 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestLauncher.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45111da1fa00b2a4192afc01c5be0873 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestMathHelper.cs b/SurvivalTest/Assets/Scripts/Test/TestMathHelper.cs new file mode 100644 index 0000000..239d8ed --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestMathHelper.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestMathHelper : MonoBehaviour +{ + + public static Vector2 Rotate(Vector2 v, float delta) + { + return new Vector2( + v.x * Mathf.Cos(delta) - v.y * Mathf.Sin(delta), + v.x * Mathf.Sin(delta) + v.y * Mathf.Cos(delta) + ); + } + + /// <summary> + /// 返回角度 + /// </summary> + /// <param name="vector2"></param> + /// <returns></returns> + public static float Angle(Vector2 vector2) + { + return 360 - (Mathf.Atan2(vector2.y, vector2.x) * Mathf.Rad2Deg * Mathf.Sign(vector2.y)); + } + + public static int Check(bool condition) + { + return condition ? 1 : 0; + } + + //public static float Angle(Vector2 vector2) + //{ + // if (vector2.x < 0) + // { + // return 360 - (Mathf.Atan2(vector2.x, vector2.y) * Mathf.Rad2Deg * -1); + // } + // else + // { + // return Mathf.Atan2(vector2.x, vector2.y) * Mathf.Rad2Deg; + // } + //} + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Test/TestMathHelper.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestMathHelper.cs.meta new file mode 100644 index 0000000..872d038 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestMathHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c40b8edb8d6570e419f024263e4cc43a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestMirror.cs b/SurvivalTest/Assets/Scripts/Test/TestMirror.cs new file mode 100644 index 0000000..832c785 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestMirror.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestMirror : MonoBehaviour +{ + HashSet<GameObject> m_Mirrored = new HashSet<GameObject>(); + + private void OnTriggerEnter2D(Collider2D collision) + { + GameObject go = collision.gameObject; + if (go && go.CompareTag("bullet") && !m_Mirrored.Contains(go)) + { + //Debug.Log("mirror"); + + go.GetComponent<TestBeamBullet>().direction.x = -go.GetComponent<TestBeamBullet>().direction.x; + + m_Mirrored.Add(go); + } + } + + private void OnTriggerExit2D(Collider2D collision) + { + GameObject go = collision.gameObject; + if (go && go.CompareTag("bullet") && m_Mirrored.Contains(go)) + { + m_Mirrored.Remove(go); + } + } +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestMirror.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestMirror.cs.meta new file mode 100644 index 0000000..6fdba29 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestMirror.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bfd61ceb1fbec0944a66ace63dcd8e02 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestMoveToTarget.cs b/SurvivalTest/Assets/Scripts/Test/TestMoveToTarget.cs new file mode 100644 index 0000000..4b5f637 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestMoveToTarget.cs @@ -0,0 +1,45 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestMoveToTarget : MonoBehaviour +{ + public float speed = 1; + + Vector2 target; + + SpriteRenderer sprite; + + private void Start() + { + sprite = GetComponent<SpriteRenderer>(); + + } + + private void Update() + { + if (Input.GetButtonDown("Fire2")) + { + Vector3 screenPos = Input.mousePosition; + + target = Camera.main.ScreenToWorldPoint(screenPos); + //Debug.Log(target); + } + + Vector2 dir = Vector2.ClampMagnitude(target - (Vector2)transform.position, 1); + Vector3 move = dir * speed * Time.deltaTime; + transform.position = transform.position + move; + + float x = move.x; + if (x > 0) + { + sprite.flipX = false; + } + else if (x < 0) + { + sprite.flipX = true; + } + + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestMoveToTarget.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestMoveToTarget.cs.meta new file mode 100644 index 0000000..6f68458 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestMoveToTarget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2283c114a7cfbd1429d3e2a0d5e6a957 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs new file mode 100644 index 0000000..11f76ba --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs @@ -0,0 +1,314 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Events; + +public class TestPeaceMaker : MonoBehaviour +{ + + [SerializeField] private Transform m_Camera; + [SerializeField] private float m_Speed; + [SerializeField] private Transform m_Centre; + [SerializeField] private SpriteRenderer m_Arrow; + [SerializeField] private float m_ArrowRadius; + [SerializeField] private TestPeaceMakerBullet m_Bullet; + [SerializeField] private TestPeaceMakerGrenade m_Grenade; + [SerializeField] private Vector2 m_Zoom; + [SerializeField] private GameObject m_LaunchVfx; + [SerializeField] private Transform m_LaunchPoint; + [SerializeField] private TestB2 m_B2; + [SerializeField] private TestSpaceBeam m_SpaceBeam; + + private Vector3 zoomIn + { + get + { + Vector3 zin = new Vector3(m_Zoom.x, m_Zoom.x, 1); + return zin; + } + } + private Vector3 zoomOut + { + get + { + Vector3 zout = new Vector3(m_Zoom.y, m_Zoom.y, 1); + return zout; + } + } + + private TopDownShadowCaster m_Shadow; + + private SpriteRenderer m_SpriteRenderer; + private TopDownTransform m_Coord; + private Coroutine m_CoFire; + private Coroutine m_CoLaunchGrenade; + + private Vector3 m_PreMouse; + + private Vector2 m_AimDirection; + + private Vector3 m_TargetZoom; + + private enum ControlMode + { + Mouse, + Joystick, + } + private ControlMode m_ControlMode; + + void Start() + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + m_Coord = GetComponent<TopDownTransform>(); + + m_ControlMode = ControlMode.Mouse; + m_AimDirection = Vector2.zero; + + m_TargetZoom = new Vector3(m_Zoom.x, m_Zoom.x, 1); + + m_Shadow = GetComponent<TopDownShadowCaster>(); + } + + void Update() + { + bool isMove = Move(); + + SetAim(); + + bool isFire = Fire(); + bool isGrenade = LaunchGrenade(); + bool isBeam = SpaceBeam(); + + CallB2(); + + CameraFollow(); + + CameraZoom(/*isMove ||*/ isFire || isGrenade /*|| isBeam*/); + } + + void CameraZoom(bool zout) + { + if(zout) + { + m_TargetZoom = zoomOut; + m_Camera.localScale = Vector3.Lerp(m_Camera.localScale, m_TargetZoom, 0.25f); + } + else + { + m_TargetZoom = zoomIn; + m_Camera.localScale = Vector3.Lerp(m_Camera.localScale, m_TargetZoom, /*Time.deltaTime * 2f*/0.25f); + } + } + + void CameraFollow() + { + Vector3 pos = m_Camera.position; + pos.x = m_Coord.x; + pos.y = m_Coord.y; + + if (Vector3.Distance(pos, m_Camera.position) > 0.1f) + { + m_Camera.position = Vector3.Lerp(m_Camera.position, pos, 3 * Time.deltaTime); + } + } + + bool Move() + { + float x = Input.GetAxisRaw("Horizontal"); + float y = Input.GetAxisRaw("Vertical"); + + bool isMove = x != 0 || y != 0; + + if (isMove) + { + Vector2 direction = new Vector2(x, y).normalized; + + Vector3 position = m_Coord.position; + position.x += direction.x * m_Speed * Time.deltaTime; + position.y += direction.y * m_Speed * Time.deltaTime; + + m_Coord.position = position; + + if (x > 0) + { + m_SpriteRenderer.flipX = false; + m_Shadow.Flip(false); + } + else if (x < 0) + { + m_SpriteRenderer.flipX = true; + m_Shadow.Flip(true); + } + } + + return isMove; + } + + void SetAim() + { + float xAxis = Input.GetAxisRaw("AimHorizontal"); + float yAxis = Input.GetAxisRaw("AimVertical"); + + bool bJoytick = xAxis != 0 || yAxis != 0; + + bool bMouse = (Input.mousePosition - m_PreMouse).magnitude > 0.01f; + m_PreMouse = Input.mousePosition; + + if(bJoytick) + { + m_ControlMode = ControlMode.Joystick; + } + if(bMouse) + { + m_ControlMode = ControlMode.Mouse; + } + + Vector2 centrePos = m_Centre.position; + Vector2 dir = Vector2.zero; + if (m_ControlMode == ControlMode.Mouse) + { + Vector2 camPos = GetCameraPosition(); + dir = (camPos - centrePos).normalized; + } + else + { + dir = new Vector2(xAxis, -yAxis).normalized; + } + + if(dir.magnitude > 0) + { + m_AimDirection = dir; + Vector2 arrowPos = centrePos + m_ArrowRadius * m_AimDirection; + m_Arrow.transform.position = new Vector3(arrowPos.x, arrowPos.y, m_Arrow.transform.position.z); + m_Arrow.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(m_AimDirection.y, m_AimDirection.x) * Mathf.Rad2Deg); + } + } + + Vector2 GetCameraPosition() + { + Vector3 screenPos = Input.mousePosition; + Vector2 target = Camera.main.ScreenToWorldPoint(screenPos); + return target; + } + + bool Fire() + { + if (Input.GetButtonDown("Fire1") || (Input.GetAxis("GunTrigger") == 1)) + { + if (m_CoFire == null) + { + m_CoFire = StartCoroutine(coFire(0.1f)); + } + } + if (!Input.GetButton("Fire1") && (Input.GetAxis("GunTrigger") == 0)) + { + if(m_CoFire != null) + { + StopCoroutine(m_CoFire); + m_CoFire = null; + } + return false; + } + return true; + } + + bool LaunchGrenade() + { + if (Input.GetButtonDown("Fire2") || (Input.GetAxis("BombTrigger") == 1)) + { + if (m_CoLaunchGrenade == null) + { + m_CoLaunchGrenade = StartCoroutine(coLaunchGrenade(0.2f)); + } + } + if (!Input.GetButton("Fire2") && (Input.GetAxis("BombTrigger") == 0)) + { + if (m_CoLaunchGrenade != null) + { + StopCoroutine(m_CoLaunchGrenade); + m_CoLaunchGrenade = null; + } + return false; + } + return true; + } + + IEnumerator coFire(float interval) + { + while (true) + { + CreateBullet(m_AimDirection, 12f, 2f); + //CreateBullet(TestMathHelper.Rotate(m_AimDirection, 10 * Mathf.Deg2Rad), 12f, 2f); + //CreateBullet(TestMathHelper.Rotate(m_AimDirection, -10 * Mathf.Deg2Rad), 12f, 2f); + + yield return new WaitForSeconds(interval); + } + } + + TestPeaceMakerBullet CreateBullet(Vector2 dir, float speed, float lifeTime) + { + TestPeaceMakerBullet bullet = Instantiate<TestPeaceMakerBullet>(m_Bullet); + + bullet.transform.position = m_Arrow.transform.position + new Vector3(m_AimDirection.x, m_AimDirection.y, 0) * -0.3f; + + bullet.Set(dir, speed, lifeTime); + bullet.gameObject.SetActive(true); + + return bullet; + } + + + Vector3 GetRandomLaunchGrenadeDirection() + { + Vector3 dirOnPlane = Quaternion.Euler(0, 0, Random.Range(-15f, 15f)) * new Vector3(m_AimDirection.x, m_AimDirection.y, 0); + dirOnPlane = dirOnPlane.normalized; + Vector3 dir = new Vector3(dirOnPlane.x, dirOnPlane.y, Random.Range(0f, 1f)).normalized; + return dir.normalized; + } + + IEnumerator coLaunchGrenade(float interval) + { + while (true) + { + // grenade + TestPeaceMakerGrenade grenade = Instantiate<TestPeaceMakerGrenade>(m_Grenade); + Vector3 position = m_Coord.position + new Vector3(0, 0, 1.8f); + grenade.Set(position, GetRandomLaunchGrenadeDirection(), Random.Range(8f, 10f)); + grenade.gameObject.SetActive(true); + + // vfx + GameObject eff = Instantiate<GameObject>(m_LaunchVfx, this.transform); + eff.transform.position = m_LaunchPoint.transform.position; + eff.SetActive(true); + + yield return new WaitForSeconds(interval); + } + } + + void CallB2() + { + if(Input.GetButtonDown("Fire3")) + { + TestB2 b2 = Instantiate<TestB2>(m_B2); + + Vector3 pos3D = m_Coord.GetProjectedPosition(); + b2.Set(pos3D + new Vector3(-15, 0,0 ), pos3D + new Vector3(15, 0,0 ), 20f, 3f); + } + } + + bool SpaceBeam() + { + if (Input.GetButtonDown("SpaceBeam")) + { + TestSpaceBeam beam = Instantiate<TestSpaceBeam>(m_SpaceBeam); + + Vector3 pos3D = m_Coord.position; + beam.Set(pos3D + new Vector3(3, 0, 0)); + + TinyCountDown.Instance.Set("SpaceBeam", 0.1f); + return true; + } + return TinyCountDown.Instance.Get("SpaceBeam") > 0; + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs.meta new file mode 100644 index 0000000..e8f0316 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMaker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e1b4df1c072214a4f947497f833281d9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerBullet.cs b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerBullet.cs new file mode 100644 index 0000000..8229753 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerBullet.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestPeaceMakerBullet : MonoBehaviour +{ + + private Vector2 m_Direction; + + private float m_Speed; + + private float m_LifeTime; + + public void Set(Vector2 dir, float speed, float lifeTime) + { + m_Direction = dir; + m_Speed = speed; + m_LifeTime = lifeTime; + transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg); + } + + void Update() + { + m_LifeTime -= Time.deltaTime; + if(m_LifeTime <= 0) + { + Destroy(this.gameObject); + return; + } + + Vector2 move = m_Direction * m_Speed * Time.deltaTime; + + Vector3 pos = transform.position; + pos.x += move.x; + pos.y += move.y; + + transform.position = pos; + } + + private void OnTriggerEnter2D(Collider2D collision) + { + TestBucket bucket = collision.gameObject.GetComponent<TestBucket>(); + + if (bucket) + { + bucket.Broken(); + } + + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerBullet.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerBullet.cs.meta new file mode 100644 index 0000000..c3bce5a --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerBullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf74c7651403bc449b55858cefd8debb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerGrenade.cs b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerGrenade.cs new file mode 100644 index 0000000..021eda7 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerGrenade.cs @@ -0,0 +1,67 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestPeaceMakerGrenade : MonoBehaviour +{ + + [SerializeField] private float m_GravityScale = 1f; + + [SerializeField] private GameObject m_ExplosionEffect; + + private TopDownTransform m_Coords; + + private Vector3 GRAVITY = new Vector3(0, 0, -9.8f); + + private Vector3 m_Velocity; // x, y, fakeHeight + + /// <summary> + /// 设置初始参数,都在fake空间下 + /// </summary> + /// <param name="initPosition"></param> + /// <param name="initDirection"></param> + /// <param name="initSpeed"></param> + public void Set(Vector3 initPosition, Vector3 initDirection, float initSpeed) + { + m_Coords = GetComponent<TopDownTransform>(); + m_Coords.position = initPosition; + + m_Velocity = initDirection * initSpeed; + } + + private void Update() + { + Vector3 move = m_Velocity * Time.deltaTime; + + if(m_Velocity.magnitude > 0 && m_Coords.z + move.z >= 0) + { + m_Coords.x += move.x; + m_Coords.y += move.y; + m_Coords.z += move.z; + m_Velocity += GRAVITY * Time.deltaTime; + + transform.rotation *= Quaternion.Euler(0, 0, 100 * m_Velocity.magnitude * Time.deltaTime); + } + else + { + m_Velocity = Vector3.zero; + + this.gameObject.SetActive(false); + Destroy(this.gameObject); + PlayExplosion(); + } + } + + private void PlayExplosion() + { + GameObject exp = Instantiate<GameObject>(m_ExplosionEffect); + + TopDownTransform coord = exp.GetComponent<TopDownTransform>(); + coord.position = m_Coords.position; + + exp.GetComponent<TopDownSorting>().Sorting(); + + exp.SetActive(true); + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerGrenade.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerGrenade.cs.meta new file mode 100644 index 0000000..7b95df6 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPeaceMakerGrenade.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 40fc919f136c67e41a3608549bab3217 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestPhysicsHelper.cs b/SurvivalTest/Assets/Scripts/Test/TestPhysicsHelper.cs new file mode 100644 index 0000000..a1606f2 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPhysicsHelper.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestPhysicsHelper : TestSingleton<TestPhysicsHelper> +{ + public TestPhysicsHelper() + { + } + + + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestPhysicsHelper.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestPhysicsHelper.cs.meta new file mode 100644 index 0000000..47ba3fc --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestPhysicsHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8031513d870e5e54e942664031efe406 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestRobot1.cs b/SurvivalTest/Assets/Scripts/Test/TestRobot1.cs new file mode 100644 index 0000000..367a661 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestRobot1.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestRobot1 : MonoBehaviour +{ + public Transform shadow; + + public float x = 0; + public float y = -0.628f; + public float z; // fake height + + public AnimationCurve curve; + public AnimationCurve curveX; + public AnimationCurve curveY; + + private void Update() + { + x = curveX.Evaluate(Time.time % 1f); + y = curveY.Evaluate(Time.time % 1f); + z = curve.Evaluate(Time.time % 1f); + + Vector3 pos = transform.position; + pos.x = x; + pos.y = y + z; + + transform.position = pos; + + pos.y = y; + shadow.transform.position = pos; + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestRobot1.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestRobot1.cs.meta new file mode 100644 index 0000000..554affe --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestRobot1.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04de5fad9d56a774498cac6d58b2f231 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestSceneViewShaderHelper.cs b/SurvivalTest/Assets/Scripts/Test/TestSceneViewShaderHelper.cs new file mode 100644 index 0000000..fca1bff --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSceneViewShaderHelper.cs @@ -0,0 +1,46 @@ +using System; +using UnityEngine; + +[ExecuteInEditMode] +public class TestSceneViewShaderHelper : MonoBehaviour +{ +#if UNITY_EDITOR + private int _isSceneViewID = Shader.PropertyToID("_IsSceneView"); + + public void OnEnable() + { + Camera.onPreRender += SetIfSceneViewCamera; + } + + public void OnDisable() + { + Camera.onPreRender -= SetIfSceneViewCamera; + } + + public void SetIfSceneViewCamera(Camera cam) + { + // Scene View camera is named "SceneCamera" + if (cam.gameObject.name == "SceneCamera") + { + Shader.EnableKeyword("SCENE_VIEW"); + Shader.SetGlobalFloat(_isSceneViewID, 1f); + } + // Inspector preview for materials, models, and prefabs is named "Preview Scene Camera" + // else if (cam.gameObject.name == "Preview Scene Camera") + // { + // Shader.EnableKeyword("SCENE_VIEW"); + // Shader.SetGlobalFloat(_isSceneViewID, 2f); + // } + // Otherwise this is a game view or other user camera + else + { + Shader.DisableKeyword("SCENE_VIEW"); + Shader.SetGlobalFloat(_isSceneViewID, 0f); + } + + // You can double check the camera names if something breaks in the future + // Debug.Log(cam); + } +#endif +} +
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Test/TestSceneViewShaderHelper.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestSceneViewShaderHelper.cs.meta new file mode 100644 index 0000000..4b846fc --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSceneViewShaderHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8b08476505e1d804994534220f308b69 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestSeperator.cs b/SurvivalTest/Assets/Scripts/Test/TestSeperator.cs new file mode 100644 index 0000000..d1819c0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSeperator.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestSeperator : MonoBehaviour +{ + HashSet<GameObject> m_Seperated = new HashSet<GameObject>(); + + private void OnTriggerEnter2D(Collider2D collision) + { + GameObject go = collision.gameObject; + if (go && go.CompareTag("bullet") && !m_Seperated.Contains(go)) + { + //Debug.Log("seperate"); + + TestBeamBullet bullet1 = TestBeamBullet.Instantiate(go.GetComponent<TestBeamBullet>()); + bullet1.direction = Quaternion.Euler(0,0, 30) * bullet1.direction; + bullet1.enabled = true; + bullet1.gameObject.SetActive(true); + + TestBeamBullet bullet2 = TestBeamBullet.Instantiate(go.GetComponent<TestBeamBullet>()); + bullet2.direction = Quaternion.Euler(0, 0, -30) * bullet2.direction; + bullet2.enabled = true; + bullet2.gameObject.SetActive(true); + + m_Seperated.Add(go); + m_Seperated.Add(bullet1.gameObject); + m_Seperated.Add(bullet2.gameObject); + } + } + + private void OnTriggerExit2D(Collider2D collision) + { + GameObject go = collision.gameObject; + if (go.CompareTag("bullet") && m_Seperated.Contains(go)) + { + m_Seperated.Remove(go); + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestSeperator.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestSeperator.cs.meta new file mode 100644 index 0000000..58f5ccb --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSeperator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ec780be79a9ec774b80c4ba5593c3a39 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestSingleton.cs b/SurvivalTest/Assets/Scripts/Test/TestSingleton.cs new file mode 100644 index 0000000..d522653 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSingleton.cs @@ -0,0 +1,20 @@ +public class TestSingleton<T> where T : class, new() +{ + private static T _instance; + private static readonly object syslock = new object(); + + public static T getInstance() + { + if (_instance == null) + { + lock (syslock) + { + if (_instance == null) + { + _instance = new T(); + } + } + } + return _instance; + } +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Test/TestSingleton.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestSingleton.cs.meta new file mode 100644 index 0000000..8035c63 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSingleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0e4486fb2a577bb4fa367c939cd96141 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestSorting.cs b/SurvivalTest/Assets/Scripts/Test/TestSorting.cs new file mode 100644 index 0000000..7a2cf54 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSorting.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestSorting : MonoBehaviour +{ + //private void Update() + //{ + // Vector3 pos = transform.position; + // pos.z = pos.y - 5; + + // if(transform.position.z != pos.z) + // { + // transform.position = pos; + // } + //} + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestSorting.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestSorting.cs.meta new file mode 100644 index 0000000..56c5ed0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSorting.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c6f36e1896ea64642b621e21a00a6488 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestSortingByDepth.cs b/SurvivalTest/Assets/Scripts/Test/TestSortingByDepth.cs new file mode 100644 index 0000000..6e346ec --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSortingByDepth.cs @@ -0,0 +1,9 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestSortingByDepth : MonoBehaviour +{ + + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Test/TestSortingByDepth.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestSortingByDepth.cs.meta new file mode 100644 index 0000000..934c164 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSortingByDepth.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 540605b09e537394f84b35d5bd77a505 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestSortingByY.cs b/SurvivalTest/Assets/Scripts/Test/TestSortingByY.cs new file mode 100644 index 0000000..59f44b7 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSortingByY.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestSortingByY : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestSortingByY.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestSortingByY.cs.meta new file mode 100644 index 0000000..5074c7f --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSortingByY.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9a346df7f7a231e46bfeb3dbc1a63116 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestSpaceBeam.cs b/SurvivalTest/Assets/Scripts/Test/TestSpaceBeam.cs new file mode 100644 index 0000000..b8ce07b --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSpaceBeam.cs @@ -0,0 +1,70 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 太空射线 +/// </summary> +public class TestSpaceBeam : MonoBehaviour +{ + [SerializeField] private GameObject m_Beam; + + TopDownTransform m_Coord; + + List<GameObject> m_Beams = new List<GameObject>(); + + float m_RotateSpeed = 5f; + + float m_Radius = 1f; + + int count = 8; + + float m_CurrentAngle = 0; + + private void Awake() + { + m_Coord = GetComponent<TopDownTransform>(); + } + + public void Set(Vector3 posTDS) + { + m_Coord.position = posTDS; + + Vector3 groundPos = m_Coord.positionOnGround; + + for(int i = 0; i < count; ++i) + { + float angle = Mathf.PI * 2f / (float)count * i; + Vector3 pos = /*groundPos +*/ new Vector3(m_Radius * Mathf.Cos(angle), m_Radius * Mathf.Sin(angle), 0f); + GameObject beam = Instantiate<GameObject>(m_Beam, this.transform); + beam.GetComponent<TopDownTransform>().localPosition = pos; + beam.SetActive(true); + m_Beams.Add(beam); + } + } + + void Update() + { + m_CurrentAngle += m_RotateSpeed * Time.deltaTime; + + RotateBeams(m_CurrentAngle); + } + + /// <summary> + /// 旋转 + /// </summary> + /// <param name="angle">弧度</param> + void RotateBeams(float angle) + { + Vector3 groundPos = m_Coord.positionOnGround; + + for (int i = 0; i < m_Beams.Count; ++i) + { + float rad = angle + Mathf.PI * 2f / (float)count * i; + Vector3 pos = /*groundPos + */new Vector3(m_Radius * Mathf.Cos(rad), m_Radius * Mathf.Sin(rad), 0f); + m_Beams[i].GetComponent<TopDownTransform>().localPosition = pos; + } + + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestSpaceBeam.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestSpaceBeam.cs.meta new file mode 100644 index 0000000..3e008d2 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestSpaceBeam.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 345857a5337aab0458bb084b716eccdc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestTopDown2DTransform.cs b/SurvivalTest/Assets/Scripts/Test/TestTopDown2DTransform.cs new file mode 100644 index 0000000..acfac68 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestTopDown2DTransform.cs @@ -0,0 +1,78 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestTopDown2DTransform : MonoBehaviour +{ + public bool useGravity = false; + + public Vector3 position // x, y, h + { + get + { + Vector3 topdownPos = transform.position; + topdownPos.y -= h; + topdownPos.z = h; + return topdownPos; + } + set + { + h = value.z; + Vector3 realPos = transform.position; + realPos.y = value.y + h; + transform.position = realPos; + } + } + + public float x + { + get + { + return position.x; + } + } + + public float y + { + get + { + return position.y; + } + } + + public float h = 0; + + public float z + { + get + { + return transform.position.z; + } + } + + public float depth + { + get + { + return this.z; + } + } + + private float vy = 0; + + private void Update() + { + if (useGravity) + { + Vector3 pos = position; + vy += -9.8f * Time.deltaTime; + pos.z = Mathf.Max(pos.z + vy * Time.deltaTime, 0f); + if(pos.z == 0) + { + vy = 0; + } + position = pos; + } + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestTopDown2DTransform.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestTopDown2DTransform.cs.meta new file mode 100644 index 0000000..b8279be --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestTopDown2DTransform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 65a986ca41323a44c910b7d7660abf9c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Test/TestWaspRobot.cs b/SurvivalTest/Assets/Scripts/Test/TestWaspRobot.cs new file mode 100644 index 0000000..3a73d21 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestWaspRobot.cs @@ -0,0 +1,145 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestWaspRobot : MonoBehaviour +{ + [SerializeField] private TopDownTransform m_Follow; + + [SerializeField] private float m_MoveSpeed; + + private SpriteRenderer m_SpriteRenderer; + private TopDownTransform m_Coords; + + // wasp环绕 + [SerializeField] private float m_Radius; + + [SerializeField] private List<Sprite> m_Sprites; + + private bool m_Following; + + private float m_Angle; + + private float m_OrbitSpeed = 3f; + + enum State + { + None, + Move, + Orbit, + } + + private State m_State = State.None; + + private Coroutine m_Coroutine; + + private void Start() + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + m_Coords = GetComponent<TopDownTransform>(); + + m_Following = false; + m_Angle = 0; + + ChangeState(State.Move); + } + + private void ChangeState(State state) + { + if(m_State != state) + { + //Debug.Log(m_State.ToString() + "->" + state.ToString()); + + if(m_Coroutine != null) + { + StopCoroutine(m_Coroutine); + } + m_State = state; + m_Coroutine = StartCoroutine("co" + m_State.ToString()); + } + } + + void Update() + { + + float distance = (m_Follow.positionOnGround - m_Coords.positionOnGround).magnitude; + m_Following = distance > m_Radius + 0.1f; + + if(m_Following) + { + ChangeState(State.Move); + } + else + { + ChangeState(State.Orbit); + } + + } + + IEnumerator coMove() + { + while (true) + { + if (m_Following) + { + Vector2 dir = (m_Follow.positionOnGround - m_Coords.positionOnGround).normalized; + + Vector2 posOnGround = m_Coords.positionOnGround; + posOnGround.x += m_MoveSpeed * Time.deltaTime * dir.x; + posOnGround.y += m_MoveSpeed * Time.deltaTime * dir.y; + + m_Coords.positionOnGround = posOnGround; + + float rad = GetAngleToTarget(); + + int index = GetSpriteIndex(rad); + SetSprite(index); + } + + yield return null; + } + } + + IEnumerator coOrbit() + { + m_Angle = GetAngleToTarget(); + + while (true) + { + m_Angle += Time.deltaTime * m_OrbitSpeed; + + Vector2 centre = m_Follow.positionOnGround; + centre += new Vector2(Mathf.Cos(m_Angle), Mathf.Sin(m_Angle)).normalized * m_Radius; + m_Coords.positionOnGround = Vector2.Lerp(m_Coords.positionOnGround, centre, 0.25f); + + int index = GetSpriteIndex(m_Angle); + SetSprite(index); + + yield return null; + } + } + + float GetAngleToTarget() + { + Vector2 posOnGround = m_Coords.positionOnGround; + Vector2 target = m_Follow.positionOnGround; + + Vector2 dir = (posOnGround - target).normalized; + + return Mathf.Atan2(dir.y, dir.x) + 2 * Mathf.PI * TestMathHelper.Check(dir.y < 0); + } + + // angle rad + int GetSpriteIndex(float rad) + { + int index = ((int)Mathf.Floor(((rad * Mathf.Rad2Deg) % 360) / 30)) % 12; + index = Mathf.Clamp(index, 0, m_Sprites.Count - 1); + return index; + } + + void SetSprite(int index) + { + m_SpriteRenderer.sprite = m_Sprites[index]; + } + +} diff --git a/SurvivalTest/Assets/Scripts/Test/TestWaspRobot.cs.meta b/SurvivalTest/Assets/Scripts/Test/TestWaspRobot.cs.meta new file mode 100644 index 0000000..9bd17eb --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Test/TestWaspRobot.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 37e797e79063cdf4883cf54509d9ddc3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/TopDown.meta b/SurvivalTest/Assets/Scripts/TopDown.meta new file mode 100644 index 0000000..e81c7d0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 42550630c8f16584fa0e12e91bd6db2a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/TopDown/Editor.meta b/SurvivalTest/Assets/Scripts/TopDown/Editor.meta new file mode 100644 index 0000000..fa70114 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 80c8d9ba082ca27419e9d6e6bbb39f6d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/TopDown/Editor/TopDownTransformInspector.cs b/SurvivalTest/Assets/Scripts/TopDown/Editor/TopDownTransformInspector.cs new file mode 100644 index 0000000..1e4f6e0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/Editor/TopDownTransformInspector.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + + +[CustomEditor(typeof(TopDownTransform))] +public class TopDownTransformInspector : Editor +{ + + TopDownTransform m_TopDownTransform; + + private void OnEnable() + { + m_TopDownTransform = target as TopDownTransform; + } + + private void OnDisable() + { + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + } + + protected override void OnHeaderGUI() + { + base.OnHeaderGUI(); + } + + //https://answers.unity.com/questions/463207/how-do-you-make-a-custom-handle-respond-to-the-mou.html + private void OnSceneGUI() + { + Vector3 pos3d = m_TopDownTransform.GetProjectedPosition(); + + float arrowSize = 2f; + + Handles.color = Handles.xAxisColor; + m_TopDownTransform.x += EditorHandlesHelper.PositionArrow(pos3d + new Vector3(0, -m_TopDownTransform.z, 0), Vector3.right, 1f, arrowSize).x; + + Handles.color = Handles.yAxisColor; + m_TopDownTransform.y -= EditorHandlesHelper.PositionArrow(pos3d + new Vector3(0, -m_TopDownTransform.z, 0), Vector3.up, 1f, arrowSize).y; + + Handles.color = Handles.zAxisColor; + m_TopDownTransform.z -= EditorHandlesHelper.PositionArrow(pos3d /*+ new Vector3(-0.3f, 0, 0)*/, Vector3.up, 1.4f, arrowSize).y; + + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/TopDown/Editor/TopDownTransformInspector.cs.meta b/SurvivalTest/Assets/Scripts/TopDown/Editor/TopDownTransformInspector.cs.meta new file mode 100644 index 0000000..09d9899 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/Editor/TopDownTransformInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a1871ab3b887e6b41ba4a43777b53192 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownShadowCaster.cs b/SurvivalTest/Assets/Scripts/TopDown/TopDownShadowCaster.cs new file mode 100644 index 0000000..ed17323 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownShadowCaster.cs @@ -0,0 +1,70 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +//[ExecuteInEditMode] +[DisallowMultipleComponent] +[RequireComponent(typeof(TopDownTransform))] +[RequireComponent(typeof(SpriteRenderer))] +public class TopDownShadowCaster : MonoBehaviour +{ + [SerializeField] private Color m_Color = new Color32(0,0,0, 58); + [SerializeField] private Vector2 m_Scale = new Vector2(1, 0.5f); + + private GameObject m_Shadow; + private SpriteRenderer m_ShadowRenderer; + + private TopDownTransform m_Coord; + private SpriteRenderer m_SpriteRenderer; + + public void Flip(bool flip) + { + m_ShadowRenderer.flipX = flip; + } + + private void Awake() + { + m_Coord = GetComponent<TopDownTransform>(); + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + + // + for(int i = this.transform.childCount - 1; i >= 0 ; --i) + { + GameObject child = this.transform.GetChild(i).gameObject; + if (child.name == "shadow") + { + Destroy(child); + } + } + + if (m_Shadow == null) + { + m_Shadow = new GameObject("shadow"); +// m_Shadow.hideFlags = HideFlags.HideAndDontSave; + + m_Shadow.transform.SetParent(transform); + m_Shadow.transform.localScale = m_Scale; + + m_ShadowRenderer = m_Shadow.AddComponent<SpriteRenderer>(); + m_ShadowRenderer.color = m_Color; + m_ShadowRenderer.sprite = m_SpriteRenderer.sprite; + m_ShadowRenderer.sortingLayerName = "Shadow"; + } + } + + //private void Update() + private void LateUpdate() + { + m_ShadowRenderer.color = m_Color; + m_ShadowRenderer.sprite = m_SpriteRenderer.sprite; + + SetPosition(); + } + + public void SetPosition() + { + Vector3 pos = m_Coord.GetProjectedGroundPosition(); + m_Shadow.transform.position = pos; + } + +} diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownShadowCaster.cs.meta b/SurvivalTest/Assets/Scripts/TopDown/TopDownShadowCaster.cs.meta new file mode 100644 index 0000000..24ecda5 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownShadowCaster.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f1ce201566412034c99687a8c5b94075 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 9 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownSorting.cs b/SurvivalTest/Assets/Scripts/TopDown/TopDownSorting.cs new file mode 100644 index 0000000..3ee2f0a --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownSorting.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[DisallowMultipleComponent] +[RequireComponent(typeof(SpriteRenderer))] +[RequireComponent(typeof(TopDownTransform))] +public class TopDownSorting : MonoBehaviour +{ + private SpriteRenderer m_SpriteRenderer; + private TopDownTransform m_Coord; + + private void Awake() + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + m_Coord = GetComponent<TopDownTransform>(); + } + + private void Update() + { + Sorting(); + } + + public void Sorting() + { + if(m_SpriteRenderer == null) + { + m_SpriteRenderer = GetComponent<SpriteRenderer>(); + } + + if(m_Coord == null) + { + m_Coord = GetComponent<TopDownTransform>(); + } + + // 根据y设置sortOrder + m_SpriteRenderer.sortingOrder = (int)(-m_Coord.position.y * 100); + } + +} diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownSorting.cs.meta b/SurvivalTest/Assets/Scripts/TopDown/TopDownSorting.cs.meta new file mode 100644 index 0000000..33f3c75 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownSorting.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a9f0293bd6e86e43bbbefc99b5e2722 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 8 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownTransform.cs b/SurvivalTest/Assets/Scripts/TopDown/TopDownTransform.cs new file mode 100644 index 0000000..103e214 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownTransform.cs @@ -0,0 +1,224 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +/// <summary> +/// 用于TopDown的Transform,支持模拟垂直高度,不允许旋转和缩放 +/// TopDownTransform的父节点必须也是TopDownTransform,Transform的父节点可以是TopDownTransform +/// </summary> +[ExecuteInEditMode] +[RequireComponent(typeof(Transform))] +public class TopDownTransform : MonoBehaviour +{ + // 右手系 + // z + // | + // | /y + // | / + // |/______x + + // x, y, z ( z = height) + [SerializeField] private Vector3 m_LocalPosition; + + // 只能绕一个虚拟轴旋转 + //[SerializeField] private float m_LocalRotation; + + // x, z + //[SerializeField] private Vector2 m_LocalScale; + + public Vector3 localPosition + { + get + { + return m_LocalPosition; + } + set + { + m_LocalPosition = value; + Project(); + } + } + + public float x + { + get + { + return m_LocalPosition.x; + } + set + { + m_LocalPosition.x = value; + Project(); + } + } + public float y + { + get + { + return m_LocalPosition.y; + } + set + { + m_LocalPosition.y = value; + Project(); + } + } + + public float z + { + get + { + return m_LocalPosition.z; + } + set + { + m_LocalPosition.z = value; + Project(); + } + } + + public float height + { + get + { + return z; + } + set + { + z = value; + } + } + + /// <summary> + /// 全局坐标 + /// </summary> + public Vector3 position + { + get + { + Vector3 pos = m_LocalPosition; + Transform self = this.transform; + while(self.parent != null) + { + TopDownTransform parentTransform = self.parent.GetComponent<TopDownTransform>(); + if (parentTransform == null) + { + Debug.LogError("Parent is not TopDownTransform"); + continue; + } + pos += parentTransform.m_LocalPosition; + self = self.parent; + } + return pos; + } + set + { + Vector3 pos = value; + Transform self = this.transform; + while (self.parent != null) + { + TopDownTransform parentTransform = self.parent.GetComponent<TopDownTransform>(); + if (parentTransform == null) + { + Debug.LogError("Parent is not TopDownTransform"); + continue; + } + pos -= parentTransform.m_LocalPosition; + self = self.parent; + } + m_LocalPosition = pos; + Project(); + } + } + + /// <summary> + /// 地表坐标(Topdown空间) + /// </summary> + public Vector3 positionOnGround + { + get + { + Vector3 pos = position; + pos.z = 0; + return pos; + } + set + { + Vector3 pos = position; + pos.x = value.x; + pos.y = value.y; + position = pos; + Project(); + } + } + + /// <summary> + /// “投影”,把坐标转换到Transform上 + /// </summary> + public void Project() + { + Vector3 pos = transform.localPosition; + pos.x = m_LocalPosition.x; + pos.y = m_LocalPosition.y + m_LocalPosition.z; + + transform.localPosition = pos; + } + + private void Awake() + { + SpriteRenderer sr = GetComponent<SpriteRenderer>(); + if (sr) + { + gameObject.AddOrGetComponent<TopDownSorting>(); + //gameObject.AddOrGetComponent<TopDownShadowCaster>(); + } + } + + private void Update() + { + Project(); + } + + #region 转换到Transform坐标 + public Vector3 GetProjectedPosition() + { + Vector3 posTD = position; + + Vector3 pos = new Vector3(); + pos.x = posTD.x; + pos.y = posTD.y + posTD.z; + pos.z = transform.position.z; + return pos; + } + + /// <summary> + /// 注意是在3D空间下 + /// </summary> + /// <returns></returns> + public Vector3 GetProjectedGroundPosition() + { + Vector3 posTD = position; + + Vector3 pos = new Vector3(); + pos.x = posTD.x; + pos.y = posTD.y; + pos.z = transform.position.z; + return pos; + } + #endregion + +#if UNITY_EDITOR + private void OnDrawGizmos() + { + Vector3 start = TopDownUtils.Project(position); + Vector3 end = TopDownUtils.Project(positionOnGround); + + Handles.DrawDottedLine(start, end, 1f); + Handles.DrawWireCube(end, new Vector3(0.1f, 0.1f, 0f)); + } +#endif + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownTransform.cs.meta b/SurvivalTest/Assets/Scripts/TopDown/TopDownTransform.cs.meta new file mode 100644 index 0000000..2853e32 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownTransform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2b1fbd797bf03674e9d1b81edc11e3f1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 5 + icon: {fileID: 2800000, guid: b7cb09ba3d43de2418ea93e3aa9cd4e4, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownUtils.cs b/SurvivalTest/Assets/Scripts/TopDown/TopDownUtils.cs new file mode 100644 index 0000000..f42e123 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownUtils.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TopDownUtils +{ + + /// <summary> + /// 从TopDown空间转到3D空间下(TopDownTransform -> Transform) + /// </summary> + /// <param name="topDownCoord"></param> + /// <param name="z"></param> + /// <returns></returns> + public static Vector3 Project(Vector3 topDownCoord, float z = 0) + { + Vector3 pos = new Vector3(); + + pos.x = topDownCoord.x; + pos.y = topDownCoord.y + topDownCoord.z; + pos.z = z; + + return pos; + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/TopDown/TopDownUtils.cs.meta b/SurvivalTest/Assets/Scripts/TopDown/TopDownUtils.cs.meta new file mode 100644 index 0000000..f60e1ef --- /dev/null +++ b/SurvivalTest/Assets/Scripts/TopDown/TopDownUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c60891307755afb4fb72033ed1cd557d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI.meta b/SurvivalTest/Assets/Scripts/UI.meta new file mode 100644 index 0000000..6c132b2 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c4535944b9a836e4f82d8c62ee419f04 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Common.meta b/SurvivalTest/Assets/Scripts/UI/Common.meta new file mode 100644 index 0000000..eddb809 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Common.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5caa56ebd16dfc541a4d9cd54b9e8de7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel.meta b/SurvivalTest/Assets/Scripts/UI/Panel.meta new file mode 100644 index 0000000..508ebdd --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 802ba1a461809b340be6bcdd0919371a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs new file mode 100644 index 0000000..421ff37 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[DisallowMultipleComponent] +public class PanelBase : MonoBehaviour +{ + + public virtual void Set(object param) + { + } + + void Start() + { + + } + + void Update() + { + + } + + protected virtual void OnSecondUpdate() + { + + } + +} diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs.meta new file mode 100644 index 0000000..09e29ef --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e770971f2e591fe4d872d6ce24941695 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs new file mode 100644 index 0000000..61f99e5 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PanelEquipBar : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs.meta new file mode 100644 index 0000000..8ef34db --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelEquipBar.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 19d70a7fc1ff38c4cb6ae04cf1530b7b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar.cs new file mode 100644 index 0000000..04bb2d9 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PanelItemBar : PanelBase +{ + + + +} diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar.cs.meta new file mode 100644 index 0000000..3925db5 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelItemBar.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3e9f15745561dd4f9119ac8f893dbfc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelLevelBar.cs b/SurvivalTest/Assets/Scripts/UI/Panel/PanelLevelBar.cs new file mode 100644 index 0000000..74fbbd9 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelLevelBar.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class PanelLevelBar : PanelBase +{ + public Image m_LevelImage; + public Text m_TextLevel; + + public override void Set(object param) + { + + } + +} diff --git a/SurvivalTest/Assets/Scripts/UI/Panel/PanelLevelBar.cs.meta b/SurvivalTest/Assets/Scripts/UI/Panel/PanelLevelBar.cs.meta new file mode 100644 index 0000000..9a7779d --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Panel/PanelLevelBar.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2be251ff144c0a74c807ebb0d7123c51 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/UIManager.cs b/SurvivalTest/Assets/Scripts/UI/UIManager.cs new file mode 100644 index 0000000..a9c85c0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/UIManager.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public partial class UIManager : Singleton<UIManager> +{ + + public UIManager() + { + } + + + +} diff --git a/SurvivalTest/Assets/Scripts/UI/UIManager.cs.meta b/SurvivalTest/Assets/Scripts/UI/UIManager.cs.meta new file mode 100644 index 0000000..6a1443f --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/UIManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 112b672f814aaa44c8a13e7546a37e34 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs new file mode 100644 index 0000000..e3914d3 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum PanelType +{ + None, + + PanelLevelBar, +} + +public partial class UIManager : Singleton<UIManager> +{ + private Dictionary<PanelType, string> m_Panels = new Dictionary<PanelType, string>(); + + void SetPanels() + { + m_Panels.Add(PanelType.PanelLevelBar, ""); + } + + void OpenPanel(PanelType type, object param) + { + + } + +} diff --git a/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs.meta b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs.meta new file mode 100644 index 0000000..3e05678 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/UIManager_Panels.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f4b4e5ebd1f46448aa13ba17678f09c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Widget.meta b/SurvivalTest/Assets/Scripts/UI/Widget.meta new file mode 100644 index 0000000..c0a26ea --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Widget.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bcd93f44480b22b4a9062a12135fc4c8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs b/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs new file mode 100644 index 0000000..616b69d --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class UIButton : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs.meta b/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs.meta new file mode 100644 index 0000000..41e16d0 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/UI/Widget/UIButton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 44f10b713a72b6d43a08cab3b90d6939 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit.meta b/SurvivalTest/Assets/Scripts/Unit.meta new file mode 100644 index 0000000..88ae4af --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 20ed300e486cd294f8270cf7e5da1a80 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew.meta b/SurvivalTest/Assets/Scripts/Unit/Crew.meta new file mode 100644 index 0000000..5f3ee2c --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 830ea73e55463584989d031951c697cc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/Captain.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/Captain.meta new file mode 100644 index 0000000..895a619 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/Captain.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9668cc289cdd6a6418701280b3a069ae +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/Commander.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/Commander.meta new file mode 100644 index 0000000..7c30320 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/Commander.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d1aaba11f56306c4886bd1493c551bb8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/CowBoy.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/CowBoy.meta new file mode 100644 index 0000000..3a77cbf --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/CowBoy.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e949a0b45780f29468c197512dda33ce +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/Engineer.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/Engineer.meta new file mode 100644 index 0000000..1d96208 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/Engineer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ae700a8de34b44a46ae4abd28758c186 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/Messenger.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/Messenger.meta new file mode 100644 index 0000000..5bb4bb2 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/Messenger.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 82605833fec9b254a9c8f02acdd5d8ed +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/Professor.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/Professor.meta new file mode 100644 index 0000000..dd53146 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/Professor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 65cd3bae8bee1674fa2bee61b70bdfd7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/V1.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/V1.meta new file mode 100644 index 0000000..1e5cd83 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/V1.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: edca9b39c2e2ec546b935ad9a7151433 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Crew/V2.meta b/SurvivalTest/Assets/Scripts/Unit/Crew/V2.meta new file mode 100644 index 0000000..4770a33 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Crew/V2.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4245a0b35b1bc66438a3d3fd80d63e48 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Unit/Enemy.meta b/SurvivalTest/Assets/Scripts/Unit/Enemy.meta new file mode 100644 index 0000000..76fd12f --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Unit/Enemy.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b7b0f093dc957ce4886c6cf59b32e9da +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Utils.meta b/SurvivalTest/Assets/Scripts/Utils.meta new file mode 100644 index 0000000..8866322 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c8b3daee7311a114c9b54fedba31b631 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs new file mode 100644 index 0000000..6ae7d87 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GameLoop : Singleton<GameLoop> +{ + + public GameLoop() + { + indexOfUpdate = 0; + } + + public int indexOfUpdate { get; private set; } = 0; + + public void Update() + { + ++indexOfUpdate; + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta new file mode 100644 index 0000000..fa6fa0e --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5ce4c552f3823e842853a52a52d3cc3b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: -1100 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs new file mode 100644 index 0000000..416f097 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class GameObjectUtils +{ + + public static T AddOrGetComponent<T>(this GameObject go) where T : MonoBehaviour + { + T comp = go.GetComponent<T>(); + if(comp == null) + { + comp = go.AddComponent<T>(); + } + return comp; + } + +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta new file mode 100644 index 0000000..eb4979a --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2cfaa149609631408d5f2f301a232fe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Utils/Singleton.cs b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs new file mode 100644 index 0000000..d7aad49 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs @@ -0,0 +1,24 @@ +public class Singleton<T> where T : class, new() +{ + private static T _instance; + private static readonly object syslock = new object(); + + public static T Instance + { + get + { + if (_instance == null) + { + lock (syslock) + { + if (_instance == null) + { + _instance = new T(); + } + } + } + return _instance; + + } + } +}
\ No newline at end of file diff --git a/SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta new file mode 100644 index 0000000..ff0aab9 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b80a3ccdebef4b4db85130a4bde2d00 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs b/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs new file mode 100644 index 0000000..dbeae55 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs @@ -0,0 +1,48 @@ +using System.Linq; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TinyCountDown :Singleton<TinyCountDown> +{ + + private Dictionary<string, float> m_CountDown = new Dictionary<string, float>(); + public TinyCountDown() + { + } + + public void Set(string key, float time) + { + if (!m_CountDown.ContainsKey(key)) + { + m_CountDown.Add(key, time); + } + else + { + m_CountDown[key] = time; + } + } + + public float Get(string key) + { + if (m_CountDown.ContainsKey(key)) + { + return m_CountDown[key]; + } + return 0; + } + + public void Update() + { + List<string> keys = new List<string>(m_CountDown.Keys); + foreach (var key in keys) + { + m_CountDown[key] -= Time.deltaTime; + if(m_CountDown[key] <= 0) + { + m_CountDown.Remove(key); + } + } + + } +} diff --git a/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta b/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta new file mode 100644 index 0000000..c9f5545 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de0d1a4a5baf48a4083e5d7f457ea8b0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |