Jelajahi Sumber

优化的流程控制

龙腾猫跃 4 tahun lalu
induk
melakukan
2338b99213

File diff ditekan karena terlalu besar
+ 0 - 0
Assets/Plugins/TextMesh Pro/Resources/Fonts & Materials/SOURCEHANSANSCN-NORMAL SDF.asset


+ 3 - 3
Assets/Resources/Dice/DiceEntity.cs

@@ -34,19 +34,19 @@ public class DiceEntity : MonoBehaviour {
     }
     IEnumerator Roll() {
         for (int i = 0; i < rollTime * 8; i++) {
-            currentLetter = Module.RandomOne("wasdlr".ToList()).ToString();
+            currentLetter = Modules.RandomOne("wasdlr".ToList()).ToString();
             UpdateSpriteText();
             yield return new WaitForSeconds(0.1f);
         }
         for (int i = 0; i < Mathf.RoundToInt(rollTime * 0.333f); i++) {
-            currentLetter = Module.RandomOne("wasdlr".ToList()).ToString();
+            currentLetter = Modules.RandomOne("wasdlr".ToList()).ToString();
             UpdateSpriteText();
             yield return new WaitForSeconds(0.333f);
         }
         // ×îÖÕÈ·¶¨
         string possible = InputM.GetPossibleResults(key, canRestore);
         Debug.Log(possible);
-        currentLetter = Module.RandomOne(possible.ToCharArray().ToList()).ToString();
+        currentLetter = Modules.RandomOne(possible.ToCharArray().ToList()).ToString();
         UpdateSpriteText();
         yield return new WaitForSeconds(0.5f);
         // Ç¿µ÷¶¯»­

+ 12 - 5
Assets/Resources/Entities/EnemyHeavy.cs

@@ -8,11 +8,18 @@ public class EnemyHeavy : EnemyBase {
     internal override bool isPressDownJump() => false;
     internal override bool isPressingLeft() => movingLeft;
     internal override bool isPressingRight() => !movingLeft;
-    //internal override void OnUpdate() {
-    //    bool shouldTurn = false;
-    //    if (Mathf.Abs(rb.velocity.x) > 0.001f && (rb.velocity.x > 0 == movingLeft)) shouldTurn = true;
-    //    if (shouldTurn) movingLeft = !movingLeft;
-    //}
+    private float turnCooldown = 0f;
+    internal override void OnUpdate() {
+        bool shouldTurn =
+            (movingLeft && Physics2D.Linecast(transform.position, transform.position + Vector3.left * 0.5f, LayerMask.GetMask("Marker"))) ||
+            (!movingLeft && Physics2D.Linecast(transform.position, transform.position + Vector3.right * 0.5f, LayerMask.GetMask("Marker")));
+        if (Mathf.Abs(rb.velocity.x) > 0.0001f && (rb.velocity.x > 0 == movingLeft)) shouldTurn = true;
+        turnCooldown -= Time.deltaTime;
+        if (shouldTurn && turnCooldown <= 0f) {
+            movingLeft = !movingLeft;
+            turnCooldown = 0.5f;
+        }
+    }
 
     public float knockbackForceH = 30f, knockbackForceV = 15f;
     internal override void OnHitEnemy(Collision2D collision) {

+ 3 - 2
Assets/Resources/Entities/EnemyHeavy.prefab

@@ -99,7 +99,7 @@ Rigidbody2D:
   m_Simulated: 1
   m_UseFullKinematicContacts: 0
   m_UseAutoMass: 0
-  m_Mass: 3
+  m_Mass: 5
   m_LinearDrag: 0
   m_AngularDrag: 0.05
   m_GravityScale: 1
@@ -156,9 +156,10 @@ MonoBehaviour:
   jumpThreshold: 0.1
   downA: 0.4
   fallA: 0
-  filpSpeed: 10000
+  filpSpeed: 0.3
   jumpBufferTime: 0.15
   jumpWolfTime: 0.2
+  baseMass: 3
   movingLeft: 0
   hp: 15
   knockbackForceH: 30

+ 2 - 1
Assets/Resources/Entities/EnemyMover.prefab

@@ -149,7 +149,7 @@ MonoBehaviour:
   spriteNormal: {fileID: 21300000, guid: 10f7659f313c52a4da5e95cf35f7955b, type: 3}
   spriteDown: {fileID: 0}
   canCrouch: 0
-  movementSpeed: 8
+  movementSpeed: 10
   jumpForce: 22
   horizontalF: 0.8
   horizontalA: 0.07
@@ -159,6 +159,7 @@ MonoBehaviour:
   filpSpeed: 0.3
   jumpBufferTime: 0.15
   jumpWolfTime: 0.2
+  baseMass: 1
   movingLeft: 0
   hp: 6
   knockbackForceH: 40

+ 3 - 1
Assets/Resources/Entities/EntityBase.cs

@@ -17,7 +17,8 @@ public abstract class EntityBase : MonoBehaviour {
 
     public bool canCrouch = false;
     public float movementSpeed = 10f, jumpForce = 20f, horizontalF = 0.9f, horizontalA = 0.3f, jumpThreshold = 0.1f, downA = 0.3f, fallA = 0.1f, filpSpeed = 0.3f;
-    public float jumpBufferTime = 0.2f, jumpWolfTime = 0.2f; internal float jumpBuffer = 0f, jumpWolf = 0f, jumping = 0f;
+    public float jumpBufferTime = 0.2f, jumpWolfTime = 0.2f, baseMass = 1f;
+    internal float jumpBuffer = 0f, jumpWolf = 0f, jumping = 0f;
     internal bool towardsRight = true, isLand = false;
     void Update() {
         OnUpdate();
@@ -64,6 +65,7 @@ public abstract class EntityBase : MonoBehaviour {
         }
         // ÉèÖÃ
         rb.velocity = new Vector2(speedX, speedY);
+        rb.mass = baseMass * (towardsRight ? 1.2f : 0.8f);
         if (towardsRight != (Mathf.Abs(speedX) > filpSpeed ? speedX > 0 : towardsRight)) {
             // ·´Ïò
             towardsRight = !towardsRight;

+ 1 - 1
Assets/Resources/System/Modules.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using UnityEngine;
 
-public static class Module {
+public static class Modules {
 
     public static System.Random randomDefault = new();
     /// <summary>

+ 3 - 0
Assets/Resources/System/Spawner.cs

@@ -11,5 +11,8 @@ public class Spawner : MonoBehaviour {
         GameObject obj = Instantiate(prefeb, transform);
         obj.transform.parent = parent.transform;
         obj.GetComponent<EnemyBase>().movingLeft = transform.localScale.x < 0;
+        if (type == EnemyType.Arrow) {
+            obj.transform.position += Mathf.RoundToInt((float) Modules.randomDefault.NextDouble() - 0.15f) * Vector3.down * 0.8f;
+        }
     }
 }

+ 55 - 17
Assets/Resources/System/StoryM.cs

@@ -4,26 +4,36 @@ using DG.Tweening;
 using UnityEngine;
 using UnityEngine.Localization.Settings;
 using UnityEngine.UI;
+using System.Linq;
 
 public class StoryM : MonoBehaviour {
 
     // 文本
     public TMPro.TextMeshProUGUI textStory;
     public RectTransform shapeBack;
-    IEnumerator SetStoryText(string textCh, string textEn = "English", float hideTime = 2f) {
-        textStory.text = LocalizationSettings.SelectedLocale.LocaleName == "Chinese (Simplified) (zh-CN)" ? textCh : textEn;
+    /// <summary>
+    /// 设置旁白,并返回预期时间。旁白字幕将在预期时间后消失。
+    /// </summary>
+    public float SetStoryText(string textCn, string textEn = "English") {
+        bool isCn = LocalizationSettings.SelectedLocale.LocaleName == "Chinese (Simplified) (zh-CN)";
+        textStory.text = isCn ? textCn : textEn;
         LayoutRebuilder.ForceRebuildLayoutImmediate(textStory.rectTransform);
         // 动画
-        DOTween.Kill("StoryFont");
         textStory.color = Color.black;
-        textStory.DOColor(Color.white, 0.2f).SetId("StoryFont");
-        DOTween.Kill("StoryBackground");
-        shapeBack.DOScaleX((textStory.rectTransform.rect.width + 40f) / 100f, 0.1f).SetId("StoryBackground");
-        yield return new WaitForSeconds(hideTime);
+        DOTween.Kill("StoryFont"); textStory.DOColor(Color.white, 0.25f).SetId("StoryFont");
+        DOTween.Kill("StoryBackground"); shapeBack.DOScaleX((textStory.rectTransform.rect.width + 40f) / 100f, 0.15f).SetId("StoryBackground");
+        // 消失
+        float time = 1.5f + (isCn ? textCn.Length / 1.5f : textEn.Split(" ").Length / 2f);
+        StopCoroutine(nameof(WaitForHideStoryText)); StartCoroutine(WaitForHideStoryText(time));
+        return time;
     }
-    public void HideStoryText() {
+    IEnumerator WaitForStoryText(string textCh, string textEn = "English") {
+        yield return new WaitForSeconds(SetStoryText(textCh, textEn));
+    }
+    IEnumerator WaitForHideStoryText(float delay) {
+        yield return new WaitForSeconds(delay);
         textStory.text = "";
-        shapeBack.DOScaleX(0, 0.06f);
+        DOTween.Kill("StoryBackground"); shapeBack.DOScaleX(0, 0.2f).SetId("StoryBackground");
     }
 
     // 刷怪
@@ -47,20 +57,48 @@ public class StoryM : MonoBehaviour {
         }
     }
 
+    // 流程控制
+    IEnumerator WaitUntilClear(int remain = 0) {
+        while (FindObjectsOfType<EnemyBase>().Length - FindObjectsOfType<EnemyArrow>().Length > remain) { // 要算上自己
+            yield return new WaitForSeconds(0.1f);
+        }
+    }
+    IEnumerator WaitUntilPickDice() {
+        while (FindObjectsOfType<DiceEntity>().Length > 0) {
+            yield return new WaitForSeconds(0.1f);
+        }
+    }
+
+    // 故事
+    public int stage = 0;
     void Start() {
         StartCoroutine(test());
+        StartCoroutine(spawnArrow());
     }
+    bool canSpawnArrow = true;
     IEnumerator test() {
         while (true) {
-            Spawn(Spawner.EnemyType.Mover);
-            yield return StartCoroutine(SetStoryText("先刷一个瞎晃悠的", "Eng" , 3f));
-            Spawn(Spawner.EnemyType.Arrow, 3);
-            yield return StartCoroutine(SetStoryText("再刷……三个戳脑门的", "", 3f));
-            Spawn(Spawner.EnemyType.Heavy);
-            yield return StartCoroutine(SetStoryText("最后是一个贼硬的,完事", "", 3f));
-            HideStoryText();
+            canSpawnArrow = true;
+            Spawn(Spawner.EnemyType.Mover, 3);
+            SetStoryText("先刷几个瞎晃悠的", "");
+            yield return new WaitForSeconds(4f);
+
+            Spawn(Spawner.EnemyType.Heavy, 2);
+            SetStoryText("然后是两个贼硬的……", "");
+            yield return StartCoroutine(WaitUntilClear(2));
+
+            canSpawnArrow = false;
+            InputM.DropDice(Modules.RandomOne(InputM.keyTypes.ToList()));
+            SetStoryText("来一个骰子吧……?", "");
+            yield return StartCoroutine(WaitUntilPickDice());
+
+            yield return StartCoroutine(WaitForStoryText("准备好,下一轮要来了!", ""));
+        }
+    }
+    IEnumerator spawnArrow() {
+        while (true) {
             yield return new WaitForSeconds(5f);
-            yield return StartCoroutine(SetStoryText("准备下一轮……", "", 3f));
+            if (canSpawnArrow) Spawn(Spawner.EnemyType.Arrow, 2);
         }
     }
 

+ 17 - 15
Assets/Scenes/SceneMain.unity

@@ -1131,8 +1131,8 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 0, y: 1}
-  m_AnchoredPosition: {x: 160, y: -30}
-  m_SizeDelta: {x: 53, y: 45}
+  m_AnchoredPosition: {x: 190, y: -40}
+  m_SizeDelta: {x: 72, y: 65}
   m_Pivot: {x: 0, y: 1}
 --- !u!114 &543358880
 MonoBehaviour:
@@ -1326,6 +1326,7 @@ MonoBehaviour:
   filpSpeed: 0.6
   jumpBufferTime: 0.15
   jumpWolfTime: 0.2
+  baseMass: 1
   hearts:
   - {fileID: 181884992}
   - {fileID: 40480623}
@@ -1333,8 +1334,8 @@ MonoBehaviour:
   knockbackForceH: 40
   knockbackForceV: 10
   healTime: 4
-  maxBullet: 25
-  currentBullet: 25
+  maxBullet: 20
+  currentBullet: 20
   shootDelay: 0.1
   reloadDelay: 2
   bulletSpeed: 50
@@ -3127,7 +3128,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 0, y: 1}
-  m_AnchoredPosition: {x: 40, y: -94}
+  m_AnchoredPosition: {x: 55.6, y: -126}
   m_SizeDelta: {x: 1000, y: 50}
   m_Pivot: {x: 0, y: 1}
 --- !u!114 &583505891
@@ -3177,8 +3178,8 @@ MonoBehaviour:
   m_faceColor:
     serializedVersion: 2
     rgba: 4294967295
-  m_fontSize: 30
-  m_fontSizeBase: 30
+  m_fontSize: 35
+  m_fontSizeBase: 35
   m_fontWeight: 400
   m_enableAutoSizing: 0
   m_fontSizeMin: 18
@@ -4029,7 +4030,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 0, y: 1}
-  m_AnchoredPosition: {x: 40, y: -94}
+  m_AnchoredPosition: {x: 55.6, y: -126}
   m_SizeDelta: {x: 1000, y: 50}
   m_Pivot: {x: 0, y: 1}
 --- !u!114 &971033487
@@ -4052,7 +4053,7 @@ MonoBehaviour:
   m_OnCullStateChanged:
     m_PersistentCalls:
       m_Calls: []
-  m_text: '|||||||||||||||||||||||||'
+  m_text: '||||||||||||||||||||'
   m_isRightToLeft: 0
   m_fontAsset: {fileID: 11400000, guid: 657c8f12eebe4e44a801288bc506d2a1, type: 2}
   m_sharedMaterial: {fileID: 2859847126084961081, guid: 657c8f12eebe4e44a801288bc506d2a1, type: 2}
@@ -4079,8 +4080,8 @@ MonoBehaviour:
   m_faceColor:
     serializedVersion: 2
     rgba: 4294967295
-  m_fontSize: 30
-  m_fontSizeBase: 30
+  m_fontSize: 35
+  m_fontSizeBase: 35
   m_fontWeight: 400
   m_enableAutoSizing: 0
   m_fontSizeMin: 18
@@ -4341,8 +4342,8 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 0, y: 1}
-  m_AnchoredPosition: {x: 40, y: -30}
-  m_SizeDelta: {x: 53, y: 45}
+  m_AnchoredPosition: {x: 50, y: -40}
+  m_SizeDelta: {x: 72, y: 65}
   m_Pivot: {x: 0, y: 1}
 --- !u!114 &1040107766
 MonoBehaviour:
@@ -4518,8 +4519,8 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 0, y: 1}
-  m_AnchoredPosition: {x: 100, y: -30}
-  m_SizeDelta: {x: 53, y: 45}
+  m_AnchoredPosition: {x: 120, y: -40}
+  m_SizeDelta: {x: 72, y: 65}
   m_Pivot: {x: 0, y: 1}
 --- !u!114 &1140112351
 MonoBehaviour:
@@ -5442,6 +5443,7 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   textStory: {fileID: 1797852847}
   shapeBack: {fileID: 2088920593}
+  stage: 0
 --- !u!114 &1378097951
 MonoBehaviour:
   m_ObjectHideFlags: 0

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini