Ver.0.3.0.33
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LayeredMouseFollowEffect : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b9cff36fb1634846bdb805afde8401d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,188 +1,187 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using TMPro;
|
||||
using AibisDream;
|
||||
using Cinemachine;
|
||||
|
||||
public class MouseFollowAndZoom : MonoBehaviour
|
||||
namespace AibisDream
|
||||
{
|
||||
public CinemachineVirtualCamera virtualCamera;
|
||||
public GameObject targetIndicator; // UI 目标框
|
||||
public TMP_Text targetNameText; // 显示目标名称的文本
|
||||
public float zoomInScale = 1.5f; // 缩放倍数
|
||||
public float zoomDuration = 1.0f; // 缩放持续时间(减慢)
|
||||
public Vector2 sceneBoundsMin; // 场景边界的左下角
|
||||
public Vector2 sceneBoundsMax; // 场景边界的右上角
|
||||
private EyeSystem eyemanager;
|
||||
private EyeTarget currentTarget; // 当前目标
|
||||
private bool isActive = false;
|
||||
private bool isLocked = false;
|
||||
|
||||
public Camera viewCamera;
|
||||
public float parallaxEffectMultiplier = 0.1f;
|
||||
public Vector2 maxOffset = new Vector2(2f, 2f);
|
||||
|
||||
private Vector3 initialPosition;
|
||||
|
||||
private float viewOffset = 0;
|
||||
|
||||
// 读写访问
|
||||
public void SetIsActive(bool value)
|
||||
public class MouseFollowAndZoom : MonoBehaviour
|
||||
{
|
||||
isActive = value;
|
||||
}
|
||||
public GameObject targetIndicator; // UI 目标框
|
||||
public TMP_Text targetNameText; // 显示目标名称的文本
|
||||
public Vector2 sceneBoundsMin; // 场景边界的左下角
|
||||
public Vector2 sceneBoundsMax; // 场景边界的右上角
|
||||
private EyeSystem eyemanager;
|
||||
private EyeTarget currentTarget; // 当前目标
|
||||
private bool isActive = false;
|
||||
private bool isLocked = false;
|
||||
|
||||
public void SetIsLock(bool value)
|
||||
{
|
||||
isLocked = value;
|
||||
}
|
||||
public Camera viewCamera;
|
||||
public float parallaxEffectMultiplier = 0.1f;
|
||||
public Vector2 maxOffset = new Vector2(2f, 2f);
|
||||
|
||||
private Vector3 initialPosition;
|
||||
|
||||
void Start()
|
||||
{
|
||||
initialPosition = transform.position;
|
||||
targetIndicator.SetActive(false); // 初始时隐藏目标框
|
||||
eyemanager = FindObjectOfType<EyeSystem>();
|
||||
if (eyemanager == null)
|
||||
private float viewOffset = 0;
|
||||
|
||||
// 读写访问
|
||||
public void SetIsActive(bool value)
|
||||
{
|
||||
Debug.LogError("EyeManager instance not found in the scene.");
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isActive)
|
||||
{
|
||||
targetIndicator.SetActive(false);
|
||||
return;
|
||||
isActive = value;
|
||||
}
|
||||
|
||||
HandleTargetIndicator(); // 显示指示器
|
||||
if (isLocked) return;
|
||||
HandleMouseMovement();
|
||||
UpdateCurrentTarget(); // 更新当前目标
|
||||
}
|
||||
|
||||
private Vector3 currentOffset; // 当前的偏移量
|
||||
|
||||
void HandleMouseMovement()
|
||||
{
|
||||
// 获取鼠标位置
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
Vector3 worldMousePosition = viewCamera.ScreenToWorldPoint(mousePosition);
|
||||
worldMousePosition.z = 0; // 确保 z 为 0
|
||||
|
||||
// 计算目标偏移量并反向
|
||||
Vector3 targetOffset = (viewCamera.transform.position - worldMousePosition) * parallaxEffectMultiplier;
|
||||
targetOffset.x = Mathf.Clamp(targetOffset.x, -maxOffset.x, maxOffset.x);
|
||||
targetOffset.y = Mathf.Clamp(targetOffset.y, -maxOffset.y, maxOffset.y);
|
||||
|
||||
// 平滑处理偏移量
|
||||
float smoothFactor = 0.01f; // 平滑系数,值越小平滑效果越强,响应越慢
|
||||
currentOffset = Vector3.Lerp(currentOffset, targetOffset, smoothFactor);
|
||||
|
||||
// 计算目标位置
|
||||
Vector3 targetPosition = initialPosition + currentOffset;
|
||||
|
||||
// 限制目标位置在场景边界范围内
|
||||
targetPosition.x = Mathf.Clamp(targetPosition.x, sceneBoundsMin.x, sceneBoundsMax.x);
|
||||
targetPosition.y = Mathf.Clamp(targetPosition.y, sceneBoundsMin.y, sceneBoundsMax.y);
|
||||
|
||||
// 使用插值(Lerp)平滑更新位置
|
||||
float followSpeed = 0.1f; // 跟随速度,值越小延迟越大
|
||||
Vector3 smoothedPosition = Vector3.Lerp(transform.position, targetPosition, followSpeed);
|
||||
|
||||
// 应用平滑后的位置
|
||||
transform.position = smoothedPosition;
|
||||
|
||||
}
|
||||
|
||||
void UpdateCurrentTarget()
|
||||
{
|
||||
// 获取鼠标位置
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(mousePosition);
|
||||
RaycastHit2D hit = Physics2D.Raycast(worldPosition+viewCamera.transform.position-Camera.main.transform.position, Vector2.zero);
|
||||
|
||||
// 检查是否有目标
|
||||
if (hit.collider != null && hit.collider.CompareTag("EyeTarget"))
|
||||
public void SetIsLock(bool value)
|
||||
{
|
||||
currentTarget = hit.collider.GetComponent<EyeTarget>(); // 更新当前目标
|
||||
isLocked = value;
|
||||
}
|
||||
|
||||
// 处理鼠标点击事件
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
|
||||
void Start()
|
||||
{
|
||||
initialPosition = transform.position;
|
||||
targetIndicator.SetActive(false); // 初始时隐藏目标框
|
||||
eyemanager = FindObjectOfType<EyeSystem>();
|
||||
if (eyemanager == null)
|
||||
{
|
||||
Debug.Log("点击目标触发了");
|
||||
if (currentTarget != null)
|
||||
{
|
||||
eyemanager.SetTarget(currentTarget); // 设置目标
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("The collider does not have an EyeTarget component.");
|
||||
}
|
||||
Debug.LogError("EyeManager instance not found in the scene.");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
void Update()
|
||||
{
|
||||
currentTarget = null; // 如果没有目标,设置为 null
|
||||
if (!isActive)
|
||||
{
|
||||
targetIndicator.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
HandleTargetIndicator(); // 显示指示器
|
||||
if (isLocked) return;
|
||||
HandleMouseMovement();
|
||||
UpdateCurrentTarget(); // 更新当前目标
|
||||
}
|
||||
|
||||
private Vector3 currentOffset; // 当前的偏移量
|
||||
|
||||
void HandleMouseMovement()
|
||||
{
|
||||
// 获取鼠标位置
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
mousePosition.x -= 40f; // 为x坐标加上40.3
|
||||
Vector3 worldMousePosition = viewCamera.ScreenToWorldPoint(mousePosition);
|
||||
worldMousePosition.z = 0; // 确保 z 为 0
|
||||
|
||||
// 计算目标偏移量并反向
|
||||
Vector3 targetOffset = (viewCamera.transform.position - worldMousePosition) * parallaxEffectMultiplier;
|
||||
targetOffset.x = Mathf.Clamp(targetOffset.x, -maxOffset.x, maxOffset.x);
|
||||
targetOffset.y = Mathf.Clamp(targetOffset.y, -maxOffset.y, maxOffset.y);
|
||||
|
||||
// 平滑处理偏移量
|
||||
float smoothFactor = 0.01f; // 平滑系数,值越小平滑效果越强,响应越慢
|
||||
currentOffset = Vector3.Lerp(currentOffset, targetOffset, smoothFactor);
|
||||
|
||||
// 计算目标位置
|
||||
Vector3 targetPosition = initialPosition + currentOffset;
|
||||
|
||||
// 限制目标位置在场景边界范围内
|
||||
targetPosition.x = Mathf.Clamp(targetPosition.x, sceneBoundsMin.x, sceneBoundsMax.x);
|
||||
targetPosition.y = Mathf.Clamp(targetPosition.y, sceneBoundsMin.y, sceneBoundsMax.y);
|
||||
|
||||
// 使用插值(Lerp)平滑更新位置
|
||||
float followSpeed = 0.1f; // 跟随速度,值越小延迟越大
|
||||
Vector3 smoothedPosition = Vector3.Lerp(transform.position, targetPosition, followSpeed);
|
||||
|
||||
// 应用平滑后的位置
|
||||
transform.position = smoothedPosition;
|
||||
}
|
||||
|
||||
void UpdateCurrentTarget()
|
||||
{
|
||||
// 获取鼠标位置
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
mousePosition.x -= 40f; // 为x坐标加上40.3
|
||||
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(mousePosition);
|
||||
RaycastHit2D hit =
|
||||
Physics2D.Raycast(worldPosition + viewCamera.transform.position - Camera.main.transform.position,
|
||||
Vector2.zero);
|
||||
|
||||
// 检查是否有目标
|
||||
if (hit.collider != null && hit.collider.CompareTag("EyeTarget"))
|
||||
{
|
||||
currentTarget = hit.collider.GetComponent<EyeTarget>(); // 更新当前目标
|
||||
|
||||
// 处理鼠标点击事件
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Debug.Log("点击目标触发了");
|
||||
if (currentTarget != null)
|
||||
{
|
||||
eyemanager.SetTarget(currentTarget); // 设置目标
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("The collider does not have an EyeTarget component.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTarget = null; // 如果没有目标,设置为 null
|
||||
}
|
||||
}
|
||||
|
||||
void HandleTargetIndicator()
|
||||
{
|
||||
if (currentTarget == null)
|
||||
{
|
||||
targetIndicator.SetActive(false); // 隐藏指示器
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取目标的 BoxCollider2D
|
||||
BoxCollider2D boxCollider = currentTarget.GetComponent<BoxCollider2D>();
|
||||
if (boxCollider != null)
|
||||
{
|
||||
Vector3 boxCenter = boxCollider.bounds.center;
|
||||
Vector3 boxSize = boxCollider.bounds.size;
|
||||
|
||||
// 转换为世界空间坐标
|
||||
Vector3 worldCenter = boxCenter;
|
||||
Vector3 worldSize = boxSize;
|
||||
|
||||
// 设置目标框的位置
|
||||
RectTransform indicatorRectTransform = targetIndicator.GetComponent<RectTransform>();
|
||||
indicatorRectTransform.position = worldCenter;
|
||||
indicatorRectTransform.sizeDelta = new Vector2(worldSize.x, worldSize.y);
|
||||
|
||||
// 设置目标名称
|
||||
targetNameText.text = currentTarget.name + " " +
|
||||
"R" + currentTarget._color.r.ToString("F1") +
|
||||
" G" + currentTarget._color.g.ToString("F1") +
|
||||
" B" + currentTarget._color.b.ToString("F1");
|
||||
|
||||
// 显示指示器
|
||||
targetIndicator.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIndicatorTarget(EyeTarget target)
|
||||
{
|
||||
currentTarget = target;
|
||||
}
|
||||
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
// 设置 Gizmos 颜色
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
// 绘制场景边界
|
||||
Vector3 bottomLeft = new Vector3(sceneBoundsMin.x, sceneBoundsMin.y, 0);
|
||||
Vector3 topRight = new Vector3(sceneBoundsMax.x, sceneBoundsMax.y, 0);
|
||||
|
||||
// 绘制边界框
|
||||
Gizmos.DrawLine(bottomLeft, new Vector3(bottomLeft.x, topRight.y, 0));
|
||||
Gizmos.DrawLine(bottomLeft, new Vector3(topRight.x, bottomLeft.y, 0));
|
||||
Gizmos.DrawLine(topRight, new Vector3(bottomLeft.x, topRight.y, 0));
|
||||
Gizmos.DrawLine(topRight, new Vector3(topRight.x, bottomLeft.y, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void HandleTargetIndicator()
|
||||
{
|
||||
if (currentTarget == null)
|
||||
{
|
||||
targetIndicator.SetActive(false); // 隐藏指示器
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取目标的 BoxCollider2D
|
||||
BoxCollider2D boxCollider = currentTarget.GetComponent<BoxCollider2D>();
|
||||
if (boxCollider != null)
|
||||
{
|
||||
Vector3 boxCenter = boxCollider.bounds.center;
|
||||
Vector3 boxSize = boxCollider.bounds.size;
|
||||
|
||||
// 转换为世界空间坐标
|
||||
Vector3 worldCenter = boxCenter;
|
||||
Vector3 worldSize = boxSize;
|
||||
|
||||
// 设置目标框的位置
|
||||
RectTransform indicatorRectTransform = targetIndicator.GetComponent<RectTransform>();
|
||||
indicatorRectTransform.position = worldCenter;
|
||||
indicatorRectTransform.sizeDelta=new Vector2(worldSize.x, worldSize.y);
|
||||
|
||||
// 设置目标名称
|
||||
targetNameText.text = currentTarget.name + " " +
|
||||
"R" + currentTarget._color.r.ToString("F1") +
|
||||
" G" + currentTarget._color.g.ToString("F1") +
|
||||
" B" + currentTarget._color.b.ToString("F1");
|
||||
|
||||
// 显示指示器
|
||||
targetIndicator.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIndicatorTarget(EyeTarget target)
|
||||
{
|
||||
currentTarget = target;
|
||||
}
|
||||
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
// 设置 Gizmos 颜色
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
// 绘制场景边界
|
||||
Vector3 bottomLeft = new Vector3(sceneBoundsMin.x, sceneBoundsMin.y, 0);
|
||||
Vector3 topRight = new Vector3(sceneBoundsMax.x, sceneBoundsMax.y, 0);
|
||||
|
||||
// 绘制边界框
|
||||
Gizmos.DrawLine(bottomLeft, new Vector3(bottomLeft.x, topRight.y, 0));
|
||||
Gizmos.DrawLine(bottomLeft, new Vector3(topRight.x, bottomLeft.y, 0));
|
||||
Gizmos.DrawLine(topRight, new Vector3(bottomLeft.x, topRight.y, 0));
|
||||
Gizmos.DrawLine(topRight, new Vector3(topRight.x, bottomLeft.y, 0));
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,16 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using Yarn.Unity;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using System.Collections;
|
||||
|
||||
public class ScreenEffectManager : MonoBehaviour
|
||||
{
|
||||
public static ScreenEffectManager Instance { get; private set; }
|
||||
|
||||
public Image blackoutPanel; // 黑屏面板
|
||||
public Image redFlashPanel; // 红色闪烁面板
|
||||
private float shakeDuration = 0.5f; // 震屏持续时间
|
||||
private float shakeIntensity = 0.04f; // 震屏强度
|
||||
|
||||
public Volume saturation;
|
||||
|
||||
private ColorAdjustments colorAdjustments;
|
||||
|
||||
private Vector3 originalCameraPosition;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 确保单例模式
|
||||
@@ -37,8 +27,6 @@ public class ScreenEffectManager : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 保存初始相机位置
|
||||
originalCameraPosition = Camera.main.transform.localPosition;
|
||||
// 获取 ColorAdjustments 设置
|
||||
if (saturation.profile.TryGet(out colorAdjustments))
|
||||
{
|
||||
@@ -50,48 +38,6 @@ public class ScreenEffectManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// 震屏效果
|
||||
[YarnCommand("shakeScreen")]
|
||||
public IEnumerator ShakeScreen()
|
||||
{
|
||||
yield return Camera.main.transform.DOPunchPosition(new Vector3(1, 0, 0) * shakeIntensity, shakeDuration, 8, 1f)
|
||||
.WaitForCompletion();
|
||||
}
|
||||
|
||||
// 黑屏淡入淡出效果
|
||||
[YarnCommand("fadeIn")]
|
||||
public IEnumerator FadeIn(float duration)
|
||||
{
|
||||
blackoutPanel.gameObject.SetActive(true);
|
||||
Sequence fadeInSequence = DOTween.Sequence();
|
||||
fadeInSequence.Append(blackoutPanel.DOFade(1f, duration));
|
||||
//fadeInSequence.AppendInterval(waitTime);
|
||||
yield return fadeInSequence.WaitForCompletion();
|
||||
}
|
||||
|
||||
[YarnCommand("fadeOut")]
|
||||
public IEnumerator FadeOut(float duration)
|
||||
{
|
||||
Sequence fadeOutSequence = DOTween.Sequence();
|
||||
fadeOutSequence.Append(blackoutPanel.DOFade(0f, duration).OnComplete(() =>
|
||||
{
|
||||
blackoutPanel.gameObject.SetActive(false);
|
||||
}));
|
||||
yield return fadeOutSequence.WaitForCompletion();
|
||||
}
|
||||
|
||||
// 红色闪烁效果
|
||||
[YarnCommand("flashRed")]
|
||||
public IEnumerator FlashRed(float duration)
|
||||
{
|
||||
redFlashPanel.gameObject.SetActive(true);
|
||||
yield return redFlashPanel.DOFade(1, duration / 2).WaitForCompletion();
|
||||
yield return redFlashPanel.DOFade(0, duration / 2).OnComplete(() =>
|
||||
{
|
||||
redFlashPanel.gameObject.SetActive(false);
|
||||
}).WaitForCompletion();
|
||||
}
|
||||
|
||||
// 动态调整饱和度
|
||||
public Tween TweenSaturation(float targetSaturation, float duration)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user