备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,284 @@
using GameCore;
using asap.core;
using UnityEngine;
using UnityEngine.Playables;
using System;
using UniRx;
using System.Threading.Tasks;
public enum EBuildingType
{
UpgradeBuilding = 0,
Pause = 1,
Continue = 2,
Next = 3,
OpenFix = 4,
CampPhoto = 5,
}
public class SwitchBuildingData
{
}
public class OnUpgradeBuildingData
{
public OnUpgradeBuildingData(EBuildingType buildingType, bool CanContinue = true)
{
this.type = buildingType;
this.CanContinue = CanContinue;
}
public EBuildingType type;//0-UpgradeBuilding1-暂停2-继续3-下一步 -1-打开修复)
public bool CanContinue;//是否可以继续
public int TimelineId;
public float StartTime;
public float Duration;
public float Speed = 1;
public string NextPrefab;
public string CurrentPrefab;
}
public class OnUpgradeBuildingFix
{
public TaskCompletionSource<bool> ts = new TaskCompletionSource<bool>();
}
public class SwitchVirtualCameraEvent
{
public int type;
public bool isDrag = true;
}
public class Building : MonoBehaviour
{
public PlayableDirector[] directors;
public PlayableDirector fix;
public PlayableDirector fade;
public PlayableDirector enter;
double _targetTime;
PlayableDirector _currentDirector;
private OnUpgradeBuildingData _upgradeBuildingData;
private void Awake()
{
if (fix == null && transform.parent != null)
{
fix = transform.parent.Find("Fix")?.GetComponent<PlayableDirector>();
}
if (directors != null && directors.Length > 0)
{
for (int i = 0; i < directors.Length; i++)
{
var director = directors[i];
director.initialTime = 0;
director.Evaluate();
}
}
}
public void SetTimelineDone(int index)
{
if (index >= directors.Length)
{
Debug.LogError($"[Building::SetTimelineDone] index {index} is out of range, directors length is {directors.Length}");
index = directors.Length - 1;
}
var director = directors[index];
director.time = director.duration;
director.initialTime = director.time;
}
public void SetTimelineAllDone()
{
for (int i = 0; i < directors.Length; i++)
{
var director = directors[i];
director.time = director.duration;
director.initialTime = director.time;
director.Evaluate();
}
}
public void SetCurrentTimeLine(int index, float startTime, float duration, bool evaluate)
{
if (index >= directors.Length)
{
Debug.LogError($"[Building::SetCurrentTimeLine] index {index} is out of range, directors length is {directors.Length}");
index = directors.Length - 1;
}
var director = directors[index];
if (!evaluate)
{
director.time = 0;
director.initialTime = 0;
}
if (director.time >= startTime + duration)
{
return;
}
director.time = startTime;
director.initialTime = startTime;
_targetTime = startTime + duration;
if (_targetTime > director.duration + 0.01f)
{
Debug.LogError($"[Building::SetCurrentTimeLine] _targetTime {startTime + duration} is greater than director duration {director.duration}, clamping to duration.");
_targetTime = (float)director.duration;
}
if (evaluate)
{
director.Evaluate();
_currentDirector = director;
}
}
public void EvaluateAllDrictors()
{
for (int i = 0; i < directors.Length; i++)
{
var director = directors[i];
director.Evaluate();
}
}
public void Show(CampDataMM campData)
{
if (_currentDirector != null)
_currentDirector.Pause();
if (campData != null && campData.TimelineId >= 0 && campData.TimelineId < directors.Length)
{
_currentDirector = directors[campData.TimelineId];
}
else
{
_currentDirector = directors[^1];
Debug.LogError($"[Building::Show] campData is null or TimelineId {campData?.TimelineId} is out of range, directors length is {directors.Length}");
}
_currentDirector.gameObject.SetActive(true);
_currentDirector.Evaluate();
// _currentDirector.time = campData.StepInfo.StartTime;
// _currentDirector.initialTime = campData.StepInfo.StartTime;
// _currentDirector.Evaluate();
// _targetTime = MathF.Min(
// campData.StepInfo.StartTime + campData.StepInfo.PlayTime,
// (float)_currentDirector.duration);
// Debug.Log($"[Building::Show] director {_currentDirector.state} {_currentDirector.name} time {_currentDirector.time} {_targetTime}");
}
public void ShowFix()
{
if (fix != null)
{
fix.initialTime = 0;
fix.Evaluate();
fix.gameObject.SetActive(true);
}
else
{
Debug.LogError("fix is null");
}
}
public void OnUpgradeBuilding(OnUpgradeBuildingData data)
{
switch (data.type)
{
case EBuildingType.UpgradeBuilding:
//Debug.Log($"[Building::OnUpgradeBuilding update] director {_currentDirector.state} {_currentDirector.name} time {_currentDirector.time} {_targetTime}");
_currentDirector.Play();
_currentDirector.playableGraph.GetRootPlayable(0).SetSpeed(data.Speed);
_upgradeBuildingData = data;
break;
case EBuildingType.Pause:
_currentDirector.Pause();
break;
case EBuildingType.Continue:
_currentDirector.Resume();
break;
case EBuildingType.Next:
OnNext(data.TimelineId, data.StartTime, data.Duration);
break;
#if UNITY_EDITOR
case EBuildingType.OpenFix:
ShowFix();
break;
#endif
default:
break;
}
}
private void OnNext(int TimelineId, float startTime, float duration)
{
SetCurrentTimeLine(TimelineId, startTime, duration, true);
}
public async void OnFix(OnUpgradeBuildingFix onUpgradeBuildingFix, Action onFixed)
{
if (fix)
{
fix.Play();
await Awaiters.Seconds((float)fix.duration);
if (fix)
{
fix.Stop();
fix.gameObject.SetActive(false);
}
onFixed?.Invoke();
}
}
public double Fade()
{
if (fade == null)
return 0;
fade.time = 0;
fade.initialTime = 0;
_currentDirector = null;
fade.Play();
return fade.duration;
}
public double Enter()
{
if (enter == null)
return 0;
enter.time = 0;
enter.initialTime = 0;
enter.Play();
return enter.duration;
}
//public double GetRestTime()
//{
//if(_currentDirector == null)
//return 0;
//if(_currentDirector.state != PlayState.Playing)
//return 0;
//return _targetTime - _currentDirector.time;
//}
private void Update()
{
if (_currentDirector != null && _currentDirector.state == PlayState.Playing)
{
if (_targetTime - _currentDirector.time < 0.001f)
{
_currentDirector.Pause();
_currentDirector.time = _targetTime;
if (_upgradeBuildingData != null)
{
_upgradeBuildingData.CanContinue = true;
_upgradeBuildingData = null;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0d05d5f803bb584098ed1956b129609
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,333 @@
using asap.core;
using Cinemachine;
using System;
using UniRx;
using UnityEngine;
public class BuildingCameraController : MonoBehaviour
{
//public Transform mainCameraTr;
public CinemachineVirtualCamera cameraVirtual;
public CinemachineFreeLook[] cameraFreeLook;
public GameObject cameraMove;
string inputAxisXName = "Mouse X";
string inputAxisYName = "Mouse Y";
// public CinemachineVirtualCameraBase vcam;
private int index = 0;
bool photo;
private CinemachineVirtualCameraBase currentCamera;
float zoomSpeed = 0.2f;
private Vector2[] lastTouchPositions = new Vector2[2];
private Vector2[] currentTouchPositions = new Vector2[2];
private float lastTouchDistance;
private float currentTouchDistance;
//方向 圆心
private Vector2 circle;
private Vector2 touchDelta0;
private Vector2 touchDelta1;
private Vector2 currentDelta0;
private Vector2 currentDelta1;
float signedAngle0;
float signedAngle1;
float angle0;
float angle1;
public Transform lookAt;
public Transform boundary1;
public Transform boundary2;
private Vector3 minVec;
private Vector3 maxVec;
//是否双指
private bool isTouchTwo = false;
//双指拖动开始阈值
public float touchTwoThreshold = 50;
public CinemachineDollyCart cinemachineDollyCart;
public CinemachineVirtualCamera cameraPhotoVirtual;
bool isMove = false;
bool isTransfer = false;
Vector3 startPos;
IDisposable disposable;
bool isDrag = false;
void Start()
{
transform.Find("CameraMain").gameObject.SetActive(false);
startPos = lookAt.localPosition;
cameraMove.SetActive(false);
minVec = new Vector3(Mathf.Min(boundary1.localPosition.x, boundary2.localPosition.x), lookAt.localPosition.y, Mathf.Min(boundary1.localPosition.z, boundary2.localPosition.z));
maxVec = new Vector3(Mathf.Max(boundary1.localPosition.x, boundary2.localPosition.x), lookAt.localPosition.y, Mathf.Max(boundary1.localPosition.z, boundary2.localPosition.z));
//Zoom = cameraVirtual.m_Lens.FieldOfView;
currentCamera = cameraVirtual;
cameraVirtual.gameObject.SetActive(true);
for (int i = 0; i < cameraFreeLook.Length; i++)
{
cameraFreeLook[i].gameObject.SetActive(false);
}
//mainCameraTr.gameObject.SetActive(false);
}
private void OnEnable()
{
disposable = GContext.OnEvent<SwitchVirtualCameraEvent>().Subscribe(OnSwitchVirtualCamera);
}
private void OnDisable()
{
disposable?.Dispose();
disposable = null;
}
//切换虚拟相机
void SwitchVirtualCamera(int _index)
{
if (index != _index)
{
CinemachineVirtualCameraBase nextCamera;
if (_index != 0)
{
nextCamera = cameraFreeLook[_index - 1];
nextCamera.transform.position = currentCamera.transform.position;
}
else
{
nextCamera = cameraVirtual;
lookAt.localPosition = startPos;
}
currentCamera.gameObject.SetActive(false);
currentCamera = nextCamera;
currentCamera.gameObject.SetActive(true);
if (isMove && _index == 0)
{
cameraMove.SetActive(false);
isMove = false;
}
}
index = _index;
}
void OnSwitchVirtualCamera(SwitchVirtualCameraEvent eventData)
{
isDrag = eventData.isDrag;
if (eventData.type > 10)
{
photo = true;
if (eventData.type == 11)
{
SetPhotoVirtual();
}
else if (eventData.type == 12)
{
SetCinemachineDollyCart();
}
index = eventData.type;
return;
}
if (isDrag || eventData.type == 0)
{
if (index > 10)
{
if (cameraPhotoVirtual != null)
{
cameraPhotoVirtual.gameObject.SetActive(false);
}
cinemachineDollyCart.transform.parent.gameObject.SetActive(false);
}
SwitchVirtualCamera(eventData.type);
}
}
void SetPhotoVirtual()
{
if (cameraPhotoVirtual == null)
{
Debug.LogError("cameraPhotoVirtual is null");
return;
}
currentCamera.gameObject.SetActive(false);
cameraPhotoVirtual.gameObject.SetActive(true);
}
void SetCinemachineDollyCart()
{
if (cameraPhotoVirtual != null)
{
cameraPhotoVirtual.gameObject.SetActive(false);
}
currentCamera.gameObject.SetActive(false);
cinemachineDollyCart.transform.parent.gameObject.SetActive(true);
cinemachineDollyCart.m_Speed = 0;
}
void Update()
{
if (!isDrag)
{
return;
}
if (photo)
{
if (Input.GetMouseButton(0) || Input.touchCount == 1)
{
if (cinemachineDollyCart.transform.parent.gameObject.activeSelf)
{
cinemachineDollyCart.m_Position -= Input.GetAxis(inputAxisXName);
}
}
return;
}
#if UNITY_EDITOR
if (Input.GetMouseButton(0) && index == 1)
#else
if (Input.touchCount==1&& index==1)
#endif
{
if (!isTouchTwo)
{
//SwitchVirtualCamera(1);
cameraFreeLook[index - 1].m_XAxis.m_InputAxisValue = Input.GetAxis(inputAxisXName);
cameraFreeLook[index - 1].m_YAxis.m_InputAxisValue = Input.GetAxis(inputAxisYName);
}
}
else if (Input.touchCount == 2)
{
if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
{
currentTouchPositions[0] = Input.GetTouch(0).position;
currentTouchPositions[1] = Input.GetTouch(1).position;
if (!isTouchTwo)
{
isTouchTwo = true;
lastTouchPositions[0] = currentTouchPositions[0];
lastTouchPositions[1] = currentTouchPositions[1];
}
if (Vector2.Distance(currentTouchPositions[0], lastTouchPositions[0]) + Vector2.Distance(currentTouchPositions[1], lastTouchPositions[1]) > touchTwoThreshold && index != 2)
{
SwitchVirtualCamera(2);
}
if (!isTransfer && !isMove && (Vector2.Distance(currentTouchPositions[0], lastTouchPositions[0]) < touchTwoThreshold && Vector2.Distance(currentTouchPositions[1], lastTouchPositions[1]) < touchTwoThreshold))
{
return;
}
if (index == 2)
{
circle = (lastTouchPositions[0] + lastTouchPositions[1]) / 2;
touchDelta0 = lastTouchPositions[0] - circle;
touchDelta1 = lastTouchPositions[1] - circle;
currentDelta0 = (currentTouchPositions[0] - lastTouchPositions[0]);
currentDelta1 = (currentTouchPositions[1] - lastTouchPositions[1]);
signedAngle0 = Vector2.SignedAngle(touchDelta0, currentDelta0);
signedAngle1 = Vector2.SignedAngle(touchDelta1, currentDelta1);
angle0 = Vector2.Angle(touchDelta0, currentDelta0);
angle1 = Vector2.Angle(touchDelta1, currentDelta1);
if ((Vector2.Angle(currentDelta0, currentDelta1) > 30) && !isMove || isTransfer)
{
TransferPOrR();
}
else if ((!isTransfer && Vector2.Angle(currentDelta0, currentDelta1) < 20) || (isMove && (Vector2.Angle(currentDelta0, currentDelta1) < 50)))
{
Move();
}
else
{
cameraFreeLook[index - 1].m_YAxis.m_InputAxisValue = 0;
cameraFreeLook[index - 1].m_XAxis.m_InputAxisValue = 0;
}
lastTouchPositions[0] = currentTouchPositions[0];
lastTouchPositions[1] = currentTouchPositions[1];
}
}
else if (index != 0)
{
cameraFreeLook[index - 1].m_YAxis.m_InputAxisValue = 0;
cameraFreeLook[index - 1].m_XAxis.m_InputAxisValue = 0;
}
}
else if (Input.touchCount == 0 && index != 0)
{
isTouchTwo = false;
isTransfer = false;
if (isMove)
{
cameraFreeLook[1].transform.position = cameraMove.transform.position;
currentCamera.gameObject.SetActive(true);
cameraMove.SetActive(false);
isMove = false;
}
cameraFreeLook[index - 1].m_XAxis.m_InputAxisValue = 0;
cameraFreeLook[index - 1].m_YAxis.m_InputAxisValue = 0;
}
}
//旋转缩放
void TransferPOrR()
{
isTransfer = true;
if (signedAngle0 * signedAngle1 > 0 && ((angle0 > 60 && angle0 < 120) || (angle1 > 60 && angle1 < 120)))
{
float delta = currentDelta0.magnitude + currentDelta1.magnitude;
if (signedAngle0 > 0)
{
cameraFreeLook[index - 1].m_XAxis.m_InputAxisValue = delta * zoomSpeed;
}
else
{
cameraFreeLook[index - 1].m_XAxis.m_InputAxisValue = -delta * zoomSpeed;
}//旋转
}
else if ((angle0 > 150 && angle1 > 150) || (angle0 < 30 && angle1 < 30))
{
currentTouchDistance = Vector2.Distance(currentTouchPositions[0], currentTouchPositions[1]);
lastTouchDistance = Vector2.Distance(lastTouchPositions[0], lastTouchPositions[1]);//缩放
float delta = currentTouchDistance - lastTouchDistance;
if (delta < 0)
{
cameraFreeLook[index - 1].m_YAxis.m_InputAxisValue = delta * zoomSpeed;
}
else
{
cameraFreeLook[index - 1].m_YAxis.m_InputAxisValue = delta * zoomSpeed;
}
}
}
//移动
void Move()
{
if (!isMove)
{
isMove = true;
cameraMove.transform.position = cameraFreeLook[index - 1].transform.position;
cameraMove.SetActive(true);
currentCamera.gameObject.SetActive(false);
}
//方向
Vector2 offset;
if (currentDelta0.magnitude > currentDelta1.magnitude)
{
offset = currentDelta0;
}
else
{
offset = currentDelta1;
}
//同方向移动
//Vector2 offset = (currentDelta0 + currentDelta1).normalized;
//offst在相机坐标系下的向量
Vector3 vector = Camera.main.transform.TransformDirection(offset.x, 0, offset.y);
vector.y = 0;
lookAt.localPosition += vector.normalized * Time.deltaTime * 30;
lookAt.localPosition = new Vector3(Mathf.Clamp(lookAt.localPosition.x, minVec.x, maxVec.x), lookAt.localPosition.y, Mathf.Clamp(lookAt.localPosition.z, minVec.z, maxVec.z));
//cameraFreeLook[index - 1].m_Orbits[0].m_Radius += vector.magnitude;
//cameraFreeLook[index - 1].m_Orbits[1].m_Radius += vector.magnitude;
//cameraFreeLook[index - 1].m_Orbits[2].m_Radius += vector.magnitude;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3484f749a8cc4eea8c633986b81b33e8
timeCreated: 1694414241

View File

@@ -0,0 +1,31 @@
using System.Collections;
using UnityEngine;
public class CampPlayAudio : MonoBehaviour
{
AudioSource audioSource;
float audioTime = 0;
//private void Awake()
//{
// audioSource = GetComponent<AudioSource>();
// if (audioSource)
// {
// audioTime = audioSource.clip.length;
// }
//}
//private void OnEnable()
//{
// if (audioSource)
// {
// audioSource.Play();
// StartCoroutine(Stop());
// }
//}
//IEnumerator Stop()
//{
// yield return new WaitForSeconds(audioTime);
// gameObject.SetActive(false);
//}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae44b2fc925374c45ab6b93f7260cd52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: