|
|
@@ -1,5 +1,6 @@
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
+using UnityEditor;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
@@ -8,6 +9,10 @@ public class ScreenShake : MonoBehaviour
|
|
|
[Header("摄像机")]
|
|
|
public Camera mainCam;
|
|
|
|
|
|
+ [Header("预览")]
|
|
|
+ public int previewLevel;
|
|
|
+ public bool isPreview;
|
|
|
+
|
|
|
[System.Serializable]
|
|
|
public struct ShakePos
|
|
|
{
|
|
|
@@ -26,15 +31,15 @@ public class ScreenShake : MonoBehaviour
|
|
|
public List<ShakePos> shakePoses;
|
|
|
}
|
|
|
|
|
|
- private bool isShakeCamera;
|
|
|
+ [Header("震动预设")]
|
|
|
public List<ShakeInfo> shakeInfos;
|
|
|
+ private bool isShakeCamera;
|
|
|
|
|
|
//当前震动信息
|
|
|
private List<ShakePos> shakePoses;
|
|
|
|
|
|
- private float shakeFrame;
|
|
|
- private int curGameFrame;
|
|
|
- private int pastGameFrame;
|
|
|
+ private float shakeFrame;
|
|
|
+ private float pastFrame;
|
|
|
|
|
|
private void SetCurShakeInfo(int level)
|
|
|
{
|
|
|
@@ -46,31 +51,37 @@ public class ScreenShake : MonoBehaviour
|
|
|
{
|
|
|
SetCurShakeInfo(level);
|
|
|
isShakeCamera = true;
|
|
|
- curGameFrame = Time.frameCount;
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
|
{
|
|
|
+ if (isPreview)
|
|
|
+ {
|
|
|
+ isPreview = false;
|
|
|
+ SetCurShakeInfo(previewLevel);
|
|
|
+ isShakeCamera = true;
|
|
|
+ }
|
|
|
if (isShakeCamera)
|
|
|
{
|
|
|
- if (pastGameFrame > shakeFrame)
|
|
|
+ if (pastFrame > shakeFrame)
|
|
|
{
|
|
|
isShakeCamera = false;
|
|
|
- mainCam.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
|
|
|
+ transform.position = Vector2.zero;
|
|
|
+ pastFrame = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (ShakePos sp in shakePoses)
|
|
|
{
|
|
|
- if (pastGameFrame >= sp.shakeFrame)
|
|
|
+ if (pastFrame == sp.shakeFrame)
|
|
|
{
|
|
|
float x = sp.camPos.x;
|
|
|
float y = sp.camPos.y;
|
|
|
- mainCam.rect = new Rect(x, y, 1.0f, 1.0f);
|
|
|
+ transform.position = new Vector2(x, y);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- pastGameFrame = Time.frameCount - curGameFrame;
|
|
|
+ pastFrame += 1;
|
|
|
}
|
|
|
}
|
|
|
}
|