Forráskód Böngészése

暂存,屏幕震动

SZAND\msx_2 6 hónapja
szülő
commit
73964eabe0

+ 25 - 19
ActionTowerDefense/Assets/Scenes/Game.unity

@@ -17800,20 +17800,31 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   mainCam: {fileID: 519420031}
-  player0Cam: {fileID: 815407867}
-  player1Cam: {fileID: 850878590}
-  isHeavyShake: 0
-  addShakeTime: 0.2
-  heavyShakeLevel: 2
-  heavyShakeFps: 20
-  maxShineSpeed: 0.8
-  onceShakeTime: 0.3
-  shakeLevel: 0.5
-  shakeFps: 10
-  shakeTime: 0
-  redEffect: {fileID: 262847337454929620}
-  minShineSpeed: 0.2
-  maxAlpha: 0.2
+  shakeInfos:
+  - level: 0
+    onceShakeFrame: 0
+    shakePoses: []
+  - level: 1
+    onceShakeFrame: 60
+    shakePoses:
+    - shakeFrame: 1
+      camPos: {x: 0.02, y: 0.03}
+    - shakeFrame: 9
+      camPos: {x: -0.01, y: 0.04}
+    - shakeFrame: 17
+      camPos: {x: 0.02, y: -0.01}
+    - shakeFrame: 25
+      camPos: {x: 0.04, y: 0.02}
+    - shakeFrame: 33
+      camPos: {x: -0.03, y: 0.06}
+    - shakeFrame: 41
+      camPos: {x: -0.02, y: 0.01}
+    - shakeFrame: 49
+      camPos: {x: 0.03, y: -0.04}
+    - shakeFrame: 57
+      camPos: {x: 0.02, y: 0.03}
+    - shakeFrame: 60
+      camPos: {x: -0.01, y: 0.02}
 --- !u!1 &1079295321
 GameObject:
   m_ObjectHideFlags: 0
@@ -30611,11 +30622,6 @@ RectTransform:
   m_CorrespondingSourceObject: {fileID: 2752529019334082401, guid: 9c3b104af86784d45bacf5a872189165, type: 3}
   m_PrefabInstance: {fileID: 262847337454929618}
   m_PrefabAsset: {fileID: 0}
---- !u!1 &262847337454929620 stripped
-GameObject:
-  m_CorrespondingSourceObject: {fileID: 7021976709591116431, guid: 9c3b104af86784d45bacf5a872189165, type: 3}
-  m_PrefabInstance: {fileID: 262847337454929618}
-  m_PrefabAsset: {fileID: 0}
 --- !u!1001 &693438331479669851
 PrefabInstance:
   m_ObjectHideFlags: 0

+ 0 - 1
ActionTowerDefense/Assets/Scripts/Characters/MoveCharacter.cs

@@ -292,7 +292,6 @@ public class MoveCharacter : Character
             }
         }
 
-
         uiHp.Show(hp, totalHp);
         if (hp <= 0)
         {

+ 3 - 64
ActionTowerDefense/Assets/Scripts/Characters/PlayerController.cs

@@ -1,16 +1,7 @@
-using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
-using Spine;
 using Spine.Unity;
-using UnityEngine.LowLevel;
-using UnityEngine.Playables;
-using System.ComponentModel;
-using Unity.VisualScripting;
-using System;
-using Base.Common;
-using cfg;
-using static UnityEngine.EventSystems.EventTrigger;
+using Sirenix.OdinInspector;
 using UnityEngine.InputSystem;
 using TMPro;
 
@@ -28,7 +19,6 @@ public class PlayerController : MoveCharacter
     public int playerId;
     public Vector2 pos;
     public bool canJump;
-    public bool endTranSummon;  //是否在结束变身后召唤英灵
     public Animator aniCollider;
 
     [Header("玩家组件")]
@@ -39,10 +29,6 @@ public class PlayerController : MoveCharacter
     private SpiritSystem spiritSystem;
     private ScreenShake ss;
 
-    [Header("血量")]
-    private int curHp;
-    private int curTotalHp;
-
     [Header("蓝耗")]
     public float mp;
     public float totalMp;
@@ -74,12 +60,7 @@ public class PlayerController : MoveCharacter
     [HideInInspector]
     public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
     public float totalCacheRushTime = 0.1f;
-
-    [Header("链条属性")]
     public float sprintCostMp = 5;
-    [HideInInspector]
-    public float cachePullRopeTime;
-    public float totalCachePullRopeTime = 0.1f;
 
     [Header("跳跃属性")]
     public float jumpSpeed = 10;
@@ -441,40 +422,6 @@ public class PlayerController : MoveCharacter
         {
             isKeepBtnRush = true;
         }
-        /*  //到时间自动解除变身
-        if (endChange != 0)
-        {
-            pastChangeTime += Time.deltaTime;
-            if (pastChangeTime >= changeTime)
-            {
-                EndTransfiguration(endChange);
-                endChange = 0;
-                pastChangeTime = 0;
-            }
-        }
-        */
-        //if (isTransfiguration)
-        //{
-        //    bodyTrans.position = spiritObj.transform.position;
-        //}
-        if (isInvisible)
-        {
-            invisibleTime -= Time.deltaTime;
-            if (invisibleTime <= 0)
-            {
-                isInvisible = false;
-                ChangeMat(1);
-            }
-        }
-        if (haveTransmit)
-        {
-            transmitTime -= Time.deltaTime;
-            if (transmitTime <= 0)
-            {
-                haveTransmit = false;
-                portalsController.rbs.Remove(rb);
-            }
-        }
     }
 
 
@@ -951,14 +898,6 @@ public class PlayerController : MoveCharacter
         else
         {
             airJumped = 0;
-            //if (btnNorthPress || cacheAttackTime > 0)
-            //{
-            //    if (excludeState != CharacterState.Attack)
-            //    {
-            //        Attack_summon();
-            //        return true;
-            //    }
-            //}
             if (CheckSummon())
             {
                 if (excludeState == CharacterState.Summon)
@@ -1984,7 +1923,7 @@ public class PlayerController : MoveCharacter
         ss.enabled = true;
         if (isSustainedInjury || damage >= heavyDamage)
         {
-            ss.HeavyShakeShine();
+            ss.ShakeScreen(1);
         }
     }
 
@@ -1999,7 +1938,7 @@ public class PlayerController : MoveCharacter
         ss.enabled = true;
         if (isSustainedInjury || attackInfo.damage >= heavyDamage)
         {
-            ss.HeavyShakeShine();
+            ss.ShakeScreen(1);
         }
     }
 }

+ 0 - 8
ActionTowerDefense/Assets/Scripts/HapticResponce.meta

@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 53af740a325812b44bf7fdb72b0cec8a
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 50 - 103
ActionTowerDefense/Assets/Scripts/SystemReflect/ScreenShake.cs

@@ -7,123 +7,70 @@ public class ScreenShake : MonoBehaviour
 {
 	[Header("摄像机")]
     public Camera mainCam;
-    public Camera player0Cam;
-    public Camera player1Cam;
-	private CameraController cc;
 
-	[Header("受重击/连续受伤时强震强闪")]
-	public bool isHeavyShake;
-	public float addShakeTime;
-	public float heavyShakeLevel;
-	public float heavyShakeFps;
-	public float maxShineSpeed;
+	[System.Serializable]
+	public struct ShakePos
+    {
+		[Header("第几帧震动到哪儿")]
+		public int shakeFrame;
+		public Vector2 camPos;
+    }
 
-	[Header("震动参数")]
-	public float onceShakeTime;         //单次震动时长
-	public float shakeLevel;			//震动幅度
-	public float shakeFps;				//震动帧率
-	private bool isShakeCamera;
-	private bool isRedShine;
-	private float curShakeLevel;
-	private float fps;
-	private float frameTime;
-	private float shakeDelta = 0.005f;
-	public float shakeTime;				//本次震动时长
+	[System.Serializable]
+	public struct ShakeInfo
+    {
+		[Header("震动等级,按顺序排,从0开始")]
+		public int level;
+		[Header("震动参数")]
+		public int onceShakeFrame;			//单次震动帧数
+		public List<ShakePos> shakePoses;
+    }
 
-	[Header("红闪参数")]
-	public GameObject redEffect;
-	private Image red;
-	public float minShineSpeed;
-	public float maxAlpha;
-	private float shineSpeed;
-	private int shineChange;
+    private bool isShakeCamera;
+    public List<ShakeInfo> shakeInfos;
 
-	void OnEnable()
-	{
-        if (cc == null)
-        {
-			cc = GetComponent<CameraController>();
-        }
-        if (red == null)
-        {
-			red = redEffect.GetComponent<Image>();
-        }
-		redEffect.SetActive(true);
-		isShakeCamera = true;
-		isRedShine = true;
-		shakeTime = onceShakeTime;
-		curShakeLevel = shakeLevel;
-		fps = shakeFps;
-		frameTime = 0.03f;
-		shineChange = 1;
-		shineSpeed = minShineSpeed;
-	}
+	//当前震动信息
+	private List<ShakePos> shakePoses;
 
-	void OnDisable()
-	{
-		mainCam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
-		player0Cam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
-		player1Cam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
-		isShakeCamera = false;
-		redEffect.SetActive(false);
-		isRedShine = false;
-		shineSpeed = minShineSpeed;
-		isHeavyShake = false;
-	}
+	private float shakeFrame; 
+	private int curGameFrame;
+	private int pastGameFrame;
 
-	public void HeavyShakeShine()
+	private void SetCurShakeInfo(int level)
     {
-		shakeTime += addShakeTime;
-		isHeavyShake = true;
-		fps = heavyShakeFps;
-		curShakeLevel = heavyShakeLevel;
-		shineSpeed = maxShineSpeed;
-	}
+		shakePoses = shakeInfos[level].shakePoses;
+		shakeFrame = shakeInfos[level].onceShakeFrame;
+    }
 
-	// Update is called once per frame
-	void Update()
-	{
-        if (isRedShine)
-        {
-			float a = red.color.a;
-            if (a >= maxAlpha)
-            {
-				shineChange = -1;
-            }
-            if (a <= 0)
-            {
-				shineChange = 1;
-            }
-			a += shineChange * shineSpeed * Time.deltaTime;
-			Color r = red.color;
-			r.a = a;
-			red.color = r;
-        }
+	public void ShakeScreen(int level)
+    {
+		SetCurShakeInfo(level);
+		isShakeCamera = true;
+		curGameFrame = Time.frameCount;
+    }
 
+    void Update()
+	{
 		if (isShakeCamera)
 		{
-			shakeTime -= Time.deltaTime;
-			if (shakeTime <= 0)
+			if (pastGameFrame > shakeFrame)
 			{
-				enabled = false;
+				isShakeCamera = false;
+				mainCam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
 			}
-
-			frameTime += Time.deltaTime;
-			if (frameTime > 1.0 / fps)
+			else
 			{
-				frameTime = 0;
-				mainCam.rect = new Rect(shakeDelta * (-1.0f + curShakeLevel * Random.value), shakeDelta * (-1.0f + curShakeLevel * Random.value), 1.0f, 1.0f);
-				//if (cc.isSplit)
-				//{
-				//	player0Cam.rect = new Rect(shakeDelta * (-1.0f + curShakeLevel * Random.value), shakeDelta * (-1.0f + curShakeLevel * Random.value), 1.0f, 1.0f);
-				//	player1Cam.rect = new Rect(shakeDelta * (-1.0f + curShakeLevel * Random.value), shakeDelta * (-1.0f + curShakeLevel * Random.value), 1.0f, 1.0f);
-				//}
-				//else
-				//{
-				//	mainCam.rect = new Rect(shakeDelta * (-1.0f + curShakeLevel * Random.value), shakeDelta * (-1.0f + curShakeLevel * Random.value), 1.0f, 1.0f);
-				//}
-			}
+				foreach (ShakePos sp in shakePoses)
+                {
+                    if (pastGameFrame >= sp.shakeFrame)
+                    {
+						float x = sp.camPos.x;
+						float y = sp.camPos.y;
+						mainCam.rect = new Rect(x, y, 1.0f, 1.0f);
+					}
+                }
+            }
+			pastGameFrame = Time.frameCount - curGameFrame;
 		}
 	}
-
 }