备份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,133 @@
using cfg;
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace game
{
public class WashingGameAssembling : WashingGameRemove
{
#region
protected Transform m_OriginalTransform;
private LongPressStuffBase m_NewItem;
protected override void OperatedItemExecuteOverAction(LongPressStuffBase stuffBase)
{
// 道具飞回展示区
m_Tool.MoveToExhibition();
m_CurOperatedItem.StopAction();
m_OriginalTransform = m_CurOperatedItem.transform;
m_NewItem = m_CurOperatedItem;
m_CurOperatedItem.gameObject.SetActive(false);
m_CurOperatedItem = null;
m_Status = EventWashingActionStatus.Ending;
NewItemFallOff();
int count = m_OperatedItems.Count;
for (int i = 0; i < count; i++)
{
if (stuffBase == m_OperatedItems[i])
{
m_DataManager.WashingData.StepItems[i] = 1f;
break;
}
}
m_DataManager.SyncData();
}
private void NewItemFallOff()
{
m_NewItem.transform.position = m_NewItem.transform.position + new Vector3(0f, m_BouncingDistance, 0f);
m_NewItem.gameObject.SetActive(true);
m_NewItem.transform.GetComponent<Collider>().enabled = false;
((StuffAssembling)m_NewItem).RestoreMaterial();
((StuffAssembling)m_NewItem).StopBreathing();
var tmp = m_NewItem;
m_NewItem.transform.DOMoveY(m_NewItem.transform.position.y - m_BouncingDistance, m_BouncingTime).SetEase(Ease.OutQuad).OnComplete(() =>
{
tmp = null;
m_Status = EventWashingActionStatus.Ending;
if (OperatedItemProgress >= 0.999f)
{
if (m_DataManager != null)
{
m_DataManager.WashingData.Percent = 1f;
m_DataManager.WashingData.IsOver = true;
m_DataManager.SyncData();
}
FishingYachtAct.Publish<EventWashingConclusionData>(new EventWashingConclusionData());
}
});
}
#endregion
#region
protected override void SyncGameData()
{
if (m_DataManager == null) return;
EventWashingData washingData = m_DataManager.WashingData;
bool syncData = false;
int count = m_OperatedItems.Count;
if (washingData.StepItems.Count == 0 && washingData.Percent == 0f && washingData.IsOver == false)
{
for (int i = 0; i < count; i++)
{
washingData.StepItems.Add(0f);
}
syncData = true;
}
else
{
for (int i = 0; i < count; i++)
{
if (washingData.StepItems.Count == i)
{
washingData.StepItems.Add(0f);
m_OperatedItems[i].SetHaveExecutedTime(0f);
m_OperatedItems[i].gameObject.SetActive(true);
syncData = true;
}
else if (washingData.StepItems[i] >= 1f)
{
m_OperatedItems[i].SetHaveExecutedTime(m_OperatedItems[i].ConsumeTime);
//if (!washingData.IsOver)
//{
// m_OperatedItems[i].gameObject.SetActive(false);
//}
((StuffAssembling)m_OperatedItems[i]).RestoreMaterial();
((StuffAssembling)m_OperatedItems[i]).StopBreathing();
}
else
{
m_OperatedItems[i].SetHaveExecutedTime(washingData.StepItems[i] * m_OperatedItems[i].ConsumeTime);
m_OperatedItems[i].gameObject.SetActive(true);
}
}
}
if (syncData) m_DataManager.SyncData();
}
#endregion
#region
public override void InitGame(string name)
{
base.InitGame(name);
this.m_GameType = EventWashingOperation.Installing;
this.m_Status = EventWashingActionStatus.Invalid;
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,449 @@
using asap.core;
using cfg;
using Cinemachine;
using GameCore;
using System;
using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
namespace game
{
public class WashingGameBase : MonoBehaviour
{
[Tooltip("游戏ID")]
public int m_GameID = 0;
[Tooltip("摄像机跟随路径")]
public CinemachinePath m_CameraPath;
[Tooltip("路径停歇点索引,循环执行。eg:5个点执行到最后一个位置会从移动到初始位置开始。")]
public List<int> m_RestIndexList = new List<int>();
[Tooltip("摄像机移动速度")]
public float m_CameraSpeed = 4f;
[Tooltip("磁性距离,距离目标点一定距离,即认为到达目标点。")]
public float m_MagneticDistance = 0.01f;
[Tooltip("摄像机聚焦的位置(Transform)。")]
[SerializeField] protected Transform m_CameraFocusedTransform;
#region
protected CameraFollowPathMoveController m_CameraMoveController;
/// <summary>
/// 停靠点数量
/// </summary>
/// <returns></returns>
protected int GetCameraPathRestCount()
{
if (m_CameraMoveController == null) return 0;
return m_CameraMoveController.RestCount;
}
/// <summary>
/// 摄像机跳转停靠点索引
/// </summary>
/// <param name="index"></param>
protected void JumpCameraToRestIndex(int index)
{
if (m_CameraMoveController == null) return;
m_CameraMoveController.JumpToRestIndex(index);
}
/// <summary>
/// 摄像机向前移动到下一个停靠点
/// </summary>
protected void ForwardCameraToNextRest()
{
if (m_CameraMoveController is null) return;
m_CameraMoveController.ForwardToNextRest();
}
/// <summary>
/// 摄像机向后移动到下一个停靠点
/// </summary>
protected void BackwardCameraToNextRest()
{
if (m_CameraMoveController is null) return;
m_CameraMoveController.BackwardToNextRest();
}
/// <summary>
/// 当前停靠点索引
/// </summary>
/// <returns></returns>
public int GetCameraCurrentMoveIndex()
{
if (m_CameraMoveController is null) return 0;
return m_CameraMoveController.MoveIndex;
}
/// <summary>
/// 向前跳到下一个停靠点
/// </summary>
protected void JumpCameraToNextRestForward()
{
if (m_CameraMoveController is null) return;
m_CameraMoveController.JumpToNextRestForward();
}
/// <summary>
/// 向后跳到下一个停靠点
/// </summary>
protected void JumpCameraToNextRestBackward()
{
if (m_CameraMoveController is null) return;
int index = m_CameraMoveController.JumpToNextRestBackward();
}
#endregion
#region &
// 游戏类型
protected EventWashingOperation m_GameType = EventWashingOperation.None;
public EventWashingOperation GameType { get => m_GameType; }
protected string m_GameName;
//private bool m_IsGamePausing = false;
protected CinemachineVirtualCamera m_VirtualCamera;
public int GameID { get => m_GameID; }
protected EventWashingDataManager m_DataManager;
/// <summary>
/// 设置数据
/// </summary>
/// <param name="virtualCamera"></param>
/// <param name="cameraFollowPathMoveController"></param>
/// <param name="tool"></param>
public virtual void ResetAndInitData(CinemachineVirtualCamera virtualCamera, CameraFollowPathMoveController cameraFollowPathMoveController, OperatingToolsBase tool)
{
if (virtualCamera != null)
{
m_VirtualCamera = virtualCamera;
if (m_CameraFocusedTransform != null)
{
m_VirtualCamera.LookAt = m_CameraFocusedTransform;
}
}
else
{
Debug.LogError("--- WashingGameBase ResetAndInitData 找不到虚拟相机virtualCamera");
}
if (cameraFollowPathMoveController != null && m_CameraPath != null && m_RestIndexList != null)
{
m_CameraMoveController = cameraFollowPathMoveController;
m_CameraMoveController.ResetAndInit(m_CameraPath, m_RestIndexList, m_MagneticDistance);
m_CameraMoveController.JumpToRestIndex(0);
m_CameraMoveController.enabled = true;
m_CameraMoveController.Speed = m_CameraSpeed;
}
else
{
Debug.LogError("--- WashingGameBase ResetAndInitData 找不到正确的路径配置PathMoveControlle、CameraPath 或者 RestIndexList");
}
if (tool != null)
{
m_Tool = tool;
m_Tool.gameObject.SetActive(true);
m_Tool.JumpToExhibition();
m_Tool.StopExecuting();
}
else
{
Debug.LogError("--- WashingGameBase ResetAndInitData 找不到工具包");
}
}
protected EventWashingActionStatus m_Status = EventWashingActionStatus.Invalid;
/// <summary>
/// 切换状态
/// </summary>
/// <param name="status"></param>
protected void ChangeStatus(EventWashingActionStatus status)
{
m_Status = status;
}
#endregion
#region
protected List<UpdateOperationSet> m_UpdateOperationSets = new List<UpdateOperationSet>();
private bool m_IsShowingTokenNotEnough = false;
private float m_ShowingTokenNotEnoughCD = 0.0f;
/// <summary>
/// 代币是否足够消费
/// </summary>
/// <param name="spend"></param>
/// <returns></returns>
protected bool IsTokenEnough(int spend)
{
if (m_DataManager == null) return false;
bool isEnough = m_DataManager.IsEnough(spend);
if (isEnough == false && m_IsShowingTokenNotEnough == false)
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_89"));
m_IsShowingTokenNotEnough = true;
}
m_ShowingTokenNotEnoughCD = 0.3f;
return isEnough;
}
protected bool ConsumeTokens(int count)
{
if (m_DataManager == null) return false;
bool isEnough = m_DataManager.ConsumeTokens(count);
if (isEnough == false)
{
if (m_IsShowingTokenNotEnough == false)
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_89"));
m_IsShowingTokenNotEnough = true;
}
m_ShowingTokenNotEnoughCD = 0.3f;
m_DataManager.SetEnergy(0f, 0f);
SetEnergyShortage();
PauseGame();
}
else
{
ResumeGame();
SetEnergyEnough();
float step = 1f / m_DataManager.WashingData.StepEnergyConsume;
m_DataManager.SetEnergy(1f, step);
UpdateOperationSet updateOperationSet = GetUpdateOperationSet();
if (updateOperationSet != null) m_UpdateOperationSets.Add(updateOperationSet);
}
return isEnough;
}
protected virtual void UpdateTokenConsume()
{
if (m_DataManager == null || m_DataManager.WashingData == null) return;
if (m_DataManager.WashingData.Energy <= 0f || m_DataManager.WashingData.EnergyConsumptionSpeed <= 0f) return;
ResumeGame();
SetEnergyEnough();
UpdateOperationSet updateOperationSet = GetUpdateOperationSet();
if (updateOperationSet != null) m_UpdateOperationSets.Add(updateOperationSet);
}
protected virtual UpdateOperationSet GetUpdateOperationSet()
{
if (m_DataManager == null) return null;
UpdateOperationSet updateOperationSet = new UpdateOperationSet();
updateOperationSet.Update = m_DataManager.UpdateToken;
updateOperationSet.IsUpdateOver = m_DataManager.IsUpdateTokenOver;
updateOperationSet.Callback = ConsumeTokens;
return updateOperationSet;
}
protected virtual void SetEnergyShortage()
{
}
protected virtual void SetEnergyEnough()
{
}
protected bool HaveEnergy()
{
if (m_DataManager != null && m_DataManager.WashingData != null) return m_DataManager.WashingData.Energy > 0f;
return false;
}
#endregion
#region
// 操作工具
protected OperatingToolsBase m_Tool;
public OperatingToolsBase ToolsBase { get => m_Tool; }
/// <summary>
/// 工具跳转到展示区
/// </summary>
public void JumpToolToExhibition()
{
if (m_Tool == null) return;
m_Tool.JumpToExhibition();
}
/// <summary>
/// 工具移动到操作区 Transform
/// </summary>
/// <param name="transform"></param>
public void MoveToolToTransform(Transform transform)
{
if (m_Tool is null) return;
m_Tool.MoveToTransform(transform);
}
/// <summary>
/// 工具移动到展示区
/// </summary>
public void MoveToolToExhibition()
{
if (m_Tool is null) return;
m_Tool.MoveToExhibition();
}
#endregion
#region
protected bool m_IsGuiding = false;
#endregion
#region
protected virtual void OnEnable()
{
}
protected virtual void OnDisable()
{
disposables.Dispose();
}
protected virtual void OnDestroy()
{
disposables.Dispose();
disposables = null;
}
protected virtual void Update()
{
if (m_ShowingTokenNotEnoughCD > 0f)
{
m_ShowingTokenNotEnoughCD -= Time.deltaTime;
if (m_ShowingTokenNotEnoughCD <= 0f)
{
m_ShowingTokenNotEnoughCD = 0f;
m_IsShowingTokenNotEnough = false;
}
}
}
protected virtual void LateUpdate()
{
int count = m_UpdateOperationSets.Count;
for (int i = count - 1; i >= 0; i--)
{
var updateOperationSet = m_UpdateOperationSets[i];
if (updateOperationSet != null)
{
updateOperationSet.Update(Time.deltaTime);
if (updateOperationSet.IsUpdateOver())
{
if (!IsGameOver())
updateOperationSet.Callback(1);
m_UpdateOperationSets.Remove(updateOperationSet);
}
}
}
}
public virtual void InitGame(string name)
{
this.m_GameName = name;
this.m_GameType = EventWashingOperation.None;
this.m_Status = EventWashingActionStatus.Invalid;
}
public virtual void EnterGame()
{
}
protected virtual void AfterEnterGame()
{
if (m_DataManager != null)
{
if (m_DataManager.IsEnough(1)) SetEnergyEnough();
else SetEnergyShortage();
}
}
public virtual void SaveContext()
{
}
public virtual void LoadContext()
{
}
public virtual void SyncData()
{
if (m_DataManager != null)
{
m_DataManager.SyncData();
}
}
protected virtual void PauseGame()
{
//m_IsGamePausing = true;
}
protected virtual void ResumeGame()
{
//m_IsGamePausing = false;
}
public virtual void Fresh(EventWashingDataManager dataManager)
{
m_DataManager = dataManager;
SyncData();
UpdateTokenConsume();
if (m_DataManager != null && dataManager.WashingData != null) dataManager.WashingData.ClearLocalDataExceptGroup(m_GameName);
}
public virtual void GameOver()
{
SyncData();
if (m_CameraMoveController != null)
{
m_CameraMoveController.enabled = false;
}
if (m_Tool != null)
{
m_Tool.MoveToExhibition();
m_Tool.StopExecuting();
}
m_UpdateOperationSets.Clear();
}
public bool IsGameOver()
{
if (m_DataManager == null || m_DataManager.WashingData == null) return true;
bool isOver = m_DataManager.IsGameOver();
if (isOver) GameOver();
return isOver;
}
#endregion
#region
protected CompositeDisposable disposables = new CompositeDisposable();
public void Subscribe<T>(Action<T> eventAction, string eventId = null)
{
IObservable<T> observable = FishingYachtAct.GetEvent<T>(eventId);
if (observable != null)
{
observable.Subscribe<T>(eventAction).AddTo(disposables);
}
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,66 @@
using cfg;
using Cinemachine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace game
{
public class WashingGameCleanBarnacles : WashingGameRemove
{
[Tooltip("摄像机移动路径停止位置索引")]
[SerializeField] private int m_PathStopIndex = 1;
#region
protected override void OperatedItemExecuteOverAction(LongPressStuffBase stuffBase)
{
base.OperatedItemExecuteOverAction(stuffBase);
// 道具飞回展示区
m_Tool.MoveToExhibition();
m_CurOperatedItem.StopAction();
m_CurOperatedItem.gameObject.SetActive(false);
}
public override void ResetAndInitData(CinemachineVirtualCamera virtualCamera, CameraFollowPathMoveController cameraFollowPathMoveController, OperatingToolsBase tool)
{
if (virtualCamera != null)
{
m_VirtualCamera = virtualCamera;
if (m_CameraFocusedTransform != null)
{
m_VirtualCamera.LookAt = m_CameraFocusedTransform;
}
}
if (cameraFollowPathMoveController != null && m_CameraPath != null && m_RestIndexList != null)
{
m_CameraMoveController = cameraFollowPathMoveController;
m_CameraMoveController.ResetAndInit(m_CameraPath, m_RestIndexList, m_MagneticDistance);
m_CameraMoveController.JumpToRestIndex(0);
m_CameraMoveController.enabled = true;
m_CameraMoveController.Speed = m_CameraSpeed;
m_CameraMoveController.GoToPositionIndex(m_PathStopIndex);
}
if (tool != null)
{
m_Tool = tool;
m_Tool.gameObject.SetActive(true);
m_Tool.JumpToExhibition();
m_Tool.StopExecuting();
}
}
#endregion
#region
public override void InitGame(string name)
{
base.InitGame(name);
this.m_GameType = EventWashingOperation.Barnacle;
this.m_Status = EventWashingActionStatus.Invalid;
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,65 @@
using asap.core;
using cfg;
using GameCore;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace game
{
public class WashingGameCleanFoam : WashingGamePainting
{
#region
protected override void StartConclusion(EventWashingConclusionData data)
{
if (m_PaintTexture != null)
{
//SetPaintTextureColor(Color.white);
SetPaintTextureColor(new Color(1f, 1f, 1f, 0f), true);
}
base.StartConclusion(data);
}
#endregion
#region
protected override void InitPanel()
{
base.InitPanel();
// 关闭笔刷填充进度
panel.ResetBrushChannelCounterFillAndInverse(true, true);
this.StartCoroutine(StartCountingFill());
}
private IEnumerator StartCountingFill()
{
int index = 0;
while (index < 10)
{
yield return null;
index++;
}
panel.StartCountingFill();
}
#endregion
#region
public override void InitGame(string name)
{
base.InitGame(name);
this.m_GameType = EventWashingOperation.Washing;
}
public override void Fresh(EventWashingDataManager dataManager)
{
SetPaintTextureColor(Color.white);
ChangePaintSphereBlendModeToSubtractiveSoft();
m_PainterColor = new Color(1f, 1f, 1f, 0f);
base.Fresh(dataManager);
if (m_PaintTexture != null) m_PaintTexture.gameObject.SetActive(true);
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,613 @@
using asap.core;
using GameCore;
using PaintCore;
using PaintIn3D;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using asap.core.common;
using CW.Common;
using UniRx;
namespace game
{
public class WashingGamePainting : WashingGameBase
{
[Tooltip("绘制用笔刷,主要用于喷洗泡沫等")]
public CwPaintSphere m_PaintSphere;
[Tooltip("绘制用纹理,主要用于喷洗泡沫等")]
public CwPaintableMeshTexture m_PaintTexture;
[Tooltip("玩家停止喷涂/清理后,持续播放动画时间")]
[SerializeField] private float m_ToolPlayingEffectTimeAfterStoppedPainting = 0.1f;
[Tooltip("飞溅动画预制体")]
[SerializeField]
private SplashAnimation m_SplashPrefab = null;
[Tooltip("飞溅特效延迟播放时间")]
[SerializeField]
private float m_SplashDelayTime = 0.2f;
[Tooltip("飞溅特特效显示时间")]
[SerializeField]
private float m_SplashDisplayTime = 0.1f;
[Tooltip("喷涂省略的比例范围0.0 - 1.0")]
[SerializeField] private float m_OmitPercentage = 0.1f;
IObjectPoolService m_ObjectPoolService;
#region
private float m_Timer = 0f;
#endregion
#region
private IObjectPool m_ObjectPool = null;
private IEnumerator CreateSplashClone(EventWashingCleanerFollowPositionData data)
{
yield return new WaitForSeconds(m_SplashDelayTime);
SplashAnimation clone = GetObjectPoolService().SpawnObject<SplashAnimation>();
clone.transform.position = data.position;
clone.transform.up = data.normal;
clone.SetTimer(m_SplashDisplayTime);
}
private IObjectPoolService GetObjectPoolService()
{
if (m_ObjectPoolService != null) return m_ObjectPoolService;
m_ObjectPoolService = GContext.container.Resolve<IObjectPoolService>();
m_ObjectPoolService.CreatePool<SplashAnimation>(m_SplashPrefab, 8, 32);
return m_ObjectPoolService;
}
private void DestroyObjectPool()
{
if (m_ObjectPoolService == null) return;
m_ObjectPoolService.DestroyPool<SplashAnimation>();
}
#endregion
#region
protected EventWashingPanel panel;
protected virtual void InitPanel()
{
panel.ResetBrushChannelCounterData();
panel.SetDataManager(m_DataManager);
if (m_DataManager.WashingData.IsAllGameOver == true)
{
panel.ShowForAllGameOver();
// 设置关闭按钮
panel.SetBtnCloseClickListener(OnBtnCloseClickListener);
return;
}
panel.StopCountingFill();
panel.ShowForPainting();
// 设置预览按钮
panel.SetBtnPreviewClickListener(null);
// 设置关闭按钮
panel.SetBtnCloseClickListener(OnBtnCloseClickListener);
// 设置左右箭头
panel.SetBtnArrayClickListener(OnBtnLeftClick, OnBtnRightClick);
m_IsGuiding = panel.InitGuidance();
if (m_IsGuiding == true)
{
StopInputOperation();
}
else
{
ResumeInputOperation();
}
}
private void OnBtnLeftClick()
{
// 向左移动机位
FishingYachtAct.Publish<EventWashingCameraMoveData>(new EventWashingCameraMoveData(EventWashingCameraMoveDirection.Backward));
}
private void OnBtnRightClick()
{
// 向右移动机位
FishingYachtAct.Publish<EventWashingCameraMoveData>(new EventWashingCameraMoveData(EventWashingCameraMoveDirection.Forward));
}
private void OnBtnCloseClickListener()
{
//SaveRenderTexture(m_PaintTexture.Current, Application.dataPath + "/../SavedScreen.png");
//return;
// 关闭当前Act
GContext.Publish(new UnloadActToNextAct());
}
private float m_PowerConsumptionTime = 0.4f;
private float m_PowerConsumptionCD = 0f;
private void HideElectricityConsumption()
{
if (m_PowerConsumptionCD > 0f) return;
panel.SetElectricityConsumptionVisible(false);
}
private void ShowElectricityConsumption()
{
m_PowerConsumptionCD = m_PowerConsumptionTime;
panel.SetElectricityConsumptionVisible(true);
}
#endregion
#region
protected void InitShipMaterial()
{
//if (m_ShipMaterials == null || m_ShipRenderer == null) return;
//m_ShipRenderer.sharedMaterials = m_ShipMaterials;
}
#endregion
#region
private bool m_IsDetectedAsInOperation = false;
#endregion
#region Paint in 3D
private void SaveRenderTexture(RenderTexture renderTexture, string file)
{
RenderTexture.active = renderTexture;
Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false, false);
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
texture.Apply();
byte[] bytes = texture.EncodeToPNG();
UnityEngine.Object.Destroy(texture);
System.IO.File.WriteAllBytes(file, bytes);
Debug.Log("write to File over");
//UnityEditor.AssetDatabase.Refresh(); //自动刷新资源
}
/// <summary>
/// 设置CwPaintSphere混合模式为AdditiveSoft
/// </summary>
public void ChangePaintSphereBlendModeToAdditiveSoft()
{
if (m_PaintSphere == null) return;
m_PaintSphere.enabled = true;
m_PaintSphere.gameObject.SetActive(true);
m_PaintSphere.BlendMode = CwBlendMode.AdditiveSoft(Vector4.one);
}
/// <summary>
/// 设置CwPaintSphere混合模式为SubtractiveSoft
/// </summary>
public void ChangePaintSphereBlendModeToSubtractiveSoft()
{
if (m_PaintSphere == null) return;
m_PaintSphere.enabled = true;
m_PaintSphere.gameObject.SetActive(true);
m_PaintSphere.BlendMode = CwBlendMode.SubtractiveSoft(Vector4.one);
}
/// <summary>
/// 清空绘制用纹理
/// </summary>
public void ClearPaintTexture()
{
if (m_PaintTexture == null) return;
m_PaintTexture.Clear();
}
public void SetPaintTextureColor(Color color, bool isReplace = false)
{
if (m_PaintTexture == null) return;
m_PaintTexture.Color = color;
if (isReplace == true) m_PaintTexture.Replace();
BHitScreenBase.SetTargetTransform(m_PaintTexture.transform);
}
private void StopPainting(bool isInOperation = true)
{
if (m_PaintSphere == null) return;
//m_PaintSphere.gameObject.SetActive(false);
if (m_Tool != null)
{
m_Tool.NotAuthorizedAnimation();
}
BHitScreen bHitScreen = m_PaintSphere.transform.transform.GetComponent<BHitScreen>();
if (bHitScreen != null)
{
bHitScreen.NotAuthorizedDrawing();
}
m_IsDetectedAsInOperation = isInOperation;
}
private void ResumePainting()
{
if (m_PaintSphere == null) return;
if (m_Tool != null)
{
m_Tool.AuthorizedAnimation();
}
BHitScreen bHitScreen = m_PaintSphere.transform.GetComponent<BHitScreen>();
if (bHitScreen != null && HaveEnergy())
{
bHitScreen.AuthorizedDrawing();
}
m_IsDetectedAsInOperation = false;
}
private void StopInputOperation()
{
var pointers = m_PaintSphere.transform.GetComponents<CwPointer>();
if (pointers != null)
{
foreach (var pointer in pointers)
{
pointer.enabled = false;
}
}
}
private void ResumeInputOperation()
{
var pointers = m_PaintSphere.transform.GetComponents<CwPointer>();
if (pointers != null)
{
foreach (var pointer in pointers)
{
pointer.enabled = true;
}
}
}
#endregion
#region
private void InitEvent()
{
this.Subscribe<EventWashingGestureFollowPositionData>(SetGestureFollowPosition);
this.Subscribe<EventWashingConclusionData>(StartConclusion);
this.Subscribe<EventWashingStepOverData>(StepOver);
this.Subscribe<EventWashingCleanerFollowPositionData>(SetCleanerFollowPosition);
this.Subscribe<EventWashingCameraMoveData>(EventCameraForwardListener); // 摄像机移动处理
this.Subscribe<EventWashingCameraStopData>(EventWashingCameraStopListener);
this.Subscribe<EventWashingMonitoringFoamProgressData>(EventMonitoringFoamProgressListener);
this.Subscribe<EventWashingAllGameOverData>(AllGameOver);
this.Subscribe<EventWashingTokenUpdateData>(UpdateBatteryInfo);
GContext.OnEvent<AddIndexEvent>().Subscribe(GuideListener).AddTo(this.disposables);
}
private void GuideListener(AddIndexEvent addIndexEvent)
{
if (addIndexEvent.CompleteGuide == true && panel != null)
{
panel.CompleteGuidance();
m_IsGuiding = false;
ResumeInputOperation();
}
}
private bool m_IsUpdateBatteryInfo = true;
private void UpdateBatteryInfo(EventWashingTokenUpdateData data)
{
if (panel != null && m_IsUpdateBatteryInfo == true)
{
panel.SetBatteryInfo();
}
}
private void AllGameOver(EventWashingAllGameOverData data)
{
if (panel != null)
{
panel.ShowForAllGameOver();
}
}
private void EventMonitoringFoamProgressListener(EventWashingMonitoringFoamProgressData data)
{
if (m_DataManager != null)
{
m_DataManager.WashingData.Percent = data.progress;
m_DataManager.WashingData.OmitPercent = m_OmitPercentage;
}
}
private void EventCameraForwardListener(EventWashingCameraMoveData data)
{
if (m_CameraMoveController != null)
{
if (data.direction == EventWashingCameraMoveDirection.Forward)
{
m_CameraMoveController.ForwardToNextRest();
}
else if (data.direction == EventWashingCameraMoveDirection.Backward)
{
m_CameraMoveController.BackwardToNextRest();
}
StopPainting();
}
}
private void EventWashingCameraStopListener(EventWashingCameraStopData data)
{
ResumePainting();
}
private void SetGestureFollowPosition(EventWashingGestureFollowPositionData data)
{
if (data.isFollowing)
{
ShowElectricityConsumption();
//Vector3 worldPosition = Vector3.zero;
RectTransformUtility.ScreenPointToWorldPointInRectangle(
panel.gestureFollow.transform.GetComponent<RectTransform>(),
data.position,
UIManager.Instance.UICanvas.worldCamera,
out Vector3 worldPosition);
panel.SetGestureFollowPosition(worldPosition);
}
else
{
HideElectricityConsumption();
}
}
private void SetCleanerFollowPosition(EventWashingCleanerFollowPositionData data)
{
if (!IsGameOver() && (HaveEnergy() || ConsumeTokens(1)))
{
ResumePainting();
}
else
{
// 停止游戏
StopPainting(false);
}
if (m_Tool != null)
{
((ToolForFollowerAndNormalPosition)m_Tool).Follow(data.position, data.normal);
m_Tool.StartExecuting();
m_Timer = m_ToolPlayingEffectTimeAfterStoppedPainting;
if (m_SplashPrefab != null && m_Tool.IsAuthorizedAnimation)
{
StartCoroutine(CreateSplashClone(data));
}
}
}
protected virtual void StartConclusion(EventWashingConclusionData data)
{
if (m_DataManager != null)
{
m_DataManager.WashingData.IsOver = true;
m_DataManager.SyncData();
}
panel.StopCountingFill();
panel.StartConclusion();
}
private void StepOver(EventWashingStepOverData data)
{
m_IsUpdateBatteryInfo = false;
GameOver();
FishingYachtAct.Publish<EventWashingGameOverData>(new EventWashingGameOverData());
}
#endregion
#region
protected void UpdateToken(float deltaTime)
{
if (m_DataManager == null || m_DataManager.WashingData == null) return;
float step = 1f / m_DataManager.WashingData.StepEnergyConsume;
float tmpProgress = 1f - m_DataManager.WashingData.OmitPercent;
float realProgress = m_DataManager.WashingData.Percent / tmpProgress;
if (realProgress > 1) realProgress = 1;
float nextEnergy = 1f - math.frac(realProgress / step);
if (m_DataManager.WashingData.Energy < nextEnergy) m_DataManager.WashingData.Energy = 0f;
if (m_DataManager.WashingData.Energy > 0) m_DataManager.WashingData.Energy = nextEnergy;
if (m_DataManager.WashingData.Energy < 0) m_DataManager.WashingData.Energy = 0;
}
protected bool IsUpdateTokenOver()
{
if (m_DataManager == null || m_DataManager.WashingData == null) return true;
float step = 1f / m_DataManager.WashingData.StepEnergyConsume;
float tmpProgress = 1f - m_DataManager.WashingData.OmitPercent;
float realProgress = m_DataManager.WashingData.Percent / tmpProgress;
if (realProgress > 1) realProgress = 1;
int belongStep = (int)math.floor(realProgress / step) + 1;
if (belongStep > m_DataManager.WashingData.StepEnergyConsume) m_DataManager.WashingData.IsOver = true;
if (belongStep > m_DataManager.WashingData.ConsumedToken) return true;
return false;
}
protected override UpdateOperationSet GetUpdateOperationSet()
{
if (m_DataManager == null) return null;
UpdateOperationSet updateOperationSet = new UpdateOperationSet();
updateOperationSet.Update = UpdateToken;
updateOperationSet.IsUpdateOver = IsUpdateTokenOver;
updateOperationSet.Callback = ConsumeTokens;
return updateOperationSet;
}
#endregion
#region
protected Color m_PainterColor = Color.white;
private void SyncGameData()
{
if (m_DataManager == null || m_DataManager.WashingData == null) return;
if (m_PaintTexture == null) return;
if (m_PaintSphere == null) return;
if (m_PaintTexture.SaveLoad == PaintCore.CwPaintableTexture.SaveLoadType.Automatic && string.IsNullOrEmpty(m_PaintTexture.SaveName) == false)
{
m_DataManager.WashingData.AddLocalDataKey(m_GameName, m_PaintTexture.SaveName);
if (m_DataManager.WashingData.Percent <= 0) return;
bool isExists = CwCommon.SaveExists(m_PaintTexture.SaveName);
if (isExists == false)
{
int total = (int)(m_PaintTexture.Width * m_PaintTexture.Height * m_DataManager.WashingData.Percent);
int index = 0;
Texture2D texture = new Texture2D(m_PaintTexture.Width, m_PaintTexture.Height, TextureFormat.ARGB32, false, false);
for (int i = 0; i < texture.width; i++)
{
for (int j = 0; j < texture.height; j++)
{
if (index < total) texture.SetPixel(i, j, m_PainterColor);
else texture.SetPixel(i, j, m_PaintTexture.Color);
++index;
}
}
texture.Apply();
var data = texture.EncodeToPNG();
CwHelper.Destroy(texture);
CwCommon.SaveBytes(m_PaintTexture.SaveName, data);
}
}
}
protected override void SetEnergyEnough()
{
base.SetEnergyEnough();
if (panel != null) panel.SetEnergyEnough();
}
protected override void SetEnergyShortage()
{
base.SetEnergyShortage();
if (panel != null) panel.SetEnergyShortage();
}
#endregion
#region
public async override void EnterGame()
{
base.EnterGame();
m_IsUpdateBatteryInfo = true;
BrushChannelCounterFill.OmitPercentage = this.m_OmitPercentage;
StopPainting(false);
// 打开页面(UI)
GameObject pannelObj = await UIManager.Instance.ShowUI(UITypes.EventWashingPanel);
if (pannelObj == null) return;
panel = pannelObj.transform.GetComponent<EventWashingPanel>();
InitPanel();
InitEvent();
AfterEnterGame();
}
protected override void ResumeGame()
{
base.ResumeGame();
ResumePainting();
}
protected override void PauseGame()
{
base.PauseGame();
StopPainting(false);
}
public override void Fresh(EventWashingDataManager dataManager)
{
base.Fresh(dataManager);
m_IsGuiding = true;
StopInputOperation();
if (dataManager == null || dataManager.WashingData == null) return;
//if (m_PaintTexture != null) m_PaintTexture.DefaultFillRatio = dataManager.WashingData.Percent;
}
public override void SyncData()
{
SyncGameData();
base.SyncData();
}
protected override void OnEnable()
{
base.OnEnable();
GetObjectPoolService();
}
protected override void OnDisable()
{
base.OnDisable();
DestroyObjectPool();
}
protected override void Update()
{
base.Update();
m_Timer -= Time.deltaTime;
if (m_Timer <= 0)
{
m_Timer = 0f;
if (m_Tool != null) m_Tool.StopExecuting();
}
if (m_IsDetectedAsInOperation == true)
{
if (panel != null)
{
panel.ContinuousOperation();
}
}
m_PowerConsumptionCD -= Time.deltaTime;
if (m_PowerConsumptionCD <= 0)
{
m_PowerConsumptionCD = 0;
}
}
public override void GameOver()
{
base.GameOver();
if (panel != null) panel.StopCountingFill();
StopPainting();
// 关闭笔刷填充进度
if (panel != null)
{
panel.ResetBrushChannelCounterFillAndInverse(true, false);
}
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,565 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using asap.core;
using GameCore;
using cfg;
using UniRx;
namespace game
{
public class WashingGameRemove : WashingGameBase
{
[Tooltip("弹跳距离。如:清理藤壶游戏中,清理藤壶后,藤壶向上方弹跳的距离,然后消失。安装座椅游戏中,新座椅从上方弹跳距离移动到椅子的位置。")]
public float m_BouncingDistance = 0.2f;
[Tooltip("弹跳时间。")]
public float m_BouncingTime = 0.1f;
[Tooltip("被操作的物品。如:清理藤壶游戏中的藤壶等。")]
public List<LongPressStuffBase> m_OperatedItems = new List<LongPressStuffBase>();
[Tooltip("操作区。如:清理藤壶游戏,铲子铲藤壶时,需要移动到的位置。")]
public List<Transform> m_OperationAreas = new List<Transform>();
#region
private EventWashingPanel panel;
private void InitPanel()
{
panel.SetDataManager(m_DataManager);
if (m_DataManager.WashingData.IsAllGameOver == true)
{
panel.ShowForAllGameOver();
// 设置关闭按钮
panel.SetBtnCloseClickListener(OnBtnCloseClickListener);
return;
}
panel.ShowForRemove();
// 设置预览按钮
panel.SetBtnPreviewClickListener(null);
// 设置关闭按钮
panel.SetBtnCloseClickListener(OnBtnCloseClickListener);
// 关闭笔刷填充进度
panel.ResetBrushChannelCounterFillAndInverse(false, false);
m_IsGuiding = panel.InitGuidance();
}
private void HideElectricityConsumption()
{
if (panel == null) return;
panel.SetElectricityConsumptionVisible(false);
}
private void ShowElectricityConsumption()
{
if (panel == null) return;
panel.SetElectricityConsumptionVisible(true);
}
private void OnBtnCloseClickListener()
{
// 关闭当前Act
GContext.Publish(new UnloadActToNextAct());
}
private void UpdatePanelProgress()
{
if (panel != null)
{
float progress = OperatedItemProgress;
if (progress == 0f)
{
panel.UpdateSingleProgress(progress);
return;
}
if (m_DataManager != null)
{
m_DataManager.WashingData.Percent = progress;
}
panel.UpdateSingleProgress(progress);
}
}
private void SetGestureFollowPosition(Vector2 position)
{
if (panel == null) return;
ShowElectricityConsumption();
//Vector3 worldPosition = Vector3.zero;
RectTransformUtility.ScreenPointToWorldPointInRectangle(
panel.gestureFollow.transform.GetComponent<RectTransform>(),
position,
UIManager.Instance.UICanvas.worldCamera,
out Vector3 worldPosition);
panel.SetGestureFollowPosition(worldPosition);
}
#endregion
#region
public List<LongPressStuffBase> OperatedItems
{
get { return m_OperatedItems; }
}
public List<Transform> OperationAreas
{
get { return m_OperationAreas; }
}
protected virtual void SyncGameData()
{
if (m_DataManager == null) return;
EventWashingData washingData = m_DataManager.WashingData;
bool syncData = false;
int count = m_OperatedItems.Count;
if (washingData.StepItems.Count == 0 && washingData.Percent == 0f && washingData.IsOver == false)
{
for (int i = 0; i < count; i++)
{
washingData.StepItems.Add(0f);
}
syncData = true;
}
else
{
for (int i = 0;i < count; i++)
{
if (washingData.StepItems.Count == i)
{
washingData.StepItems.Add(0f);
m_OperatedItems[i].SetHaveExecutedTime(0f);
m_OperatedItems[i].gameObject.SetActive(true);
syncData = true;
}
else if (washingData.StepItems[i] >= 1f)
{
m_OperatedItems[i].SetHaveExecutedTime(m_OperatedItems[i].ConsumeTime);
//if (!washingData.IsOver)
//{
// m_OperatedItems[i].gameObject.SetActive(false);
//}
m_OperatedItems[i].gameObject.SetActive(false);
}
else
{
m_OperatedItems[i].SetHaveExecutedTime(washingData.StepItems[i] * m_OperatedItems[i].ConsumeTime);
m_OperatedItems[i].gameObject.SetActive(true);
}
}
}
if (syncData) m_DataManager.SyncData();
}
protected override void SetEnergyEnough()
{
base.SetEnergyEnough();
if (panel != null) panel.SetEnergyEnough();
}
protected override void SetEnergyShortage()
{
base.SetEnergyShortage();
if (panel != null) panel.SetEnergyShortage();
}
protected void CheckIsOver()
{
if (OperatedItemProgress >= 0.999f)
{
if (m_DataManager != null)
{
m_DataManager.WashingData.Percent = 1f;
m_DataManager.WashingData.IsOver = true;
m_DataManager.SyncData();
}
FishingYachtAct.Publish<EventWashingConclusionData>(new EventWashingConclusionData());
}
}
#endregion
#region
/// <summary>
/// 工具准备工作结束回调
/// </summary>
/// <param name="operatingToolsBase"></param>
protected void OperatingToolsReadyAction(OperatingToolsBase operatingToolsBase)
{
if (m_Tool == null || m_CurOperatedItem == null) return;
if (operatingToolsBase.Status == EventWashingActionStatus.Preparing)
{
if (!IsGameOver() && (HaveEnergy() || ConsumeTokens(1)))
{
m_Tool.StartExecuting();
m_CurOperatedItem.StartAction(OperatedItemExecuteOverAction);
m_Status = EventWashingActionStatus.Executing;
}
}
}
/// <summary>
/// 杂物操作完成回调
/// </summary>
/// <param name="stuffBase"></param>
protected virtual void OperatedItemExecuteOverAction(LongPressStuffBase stuffBase)
{
// 道具飞回展示区
m_Tool.MoveToExhibition();
m_CurOperatedItem.StopAction();
int count = m_OperatedItems.Count;
for (int i = 0; i < count; i++)
{
if (stuffBase == m_OperatedItems[i])
{
m_DataManager.WashingData.StepItems[i] = 1f;
break;
}
}
m_DataManager.SyncData();
var tmp = m_CurOperatedItem;
m_CurOperatedItem.transform.DOMoveY(m_CurOperatedItem.transform.position.y + m_BouncingDistance, m_BouncingTime).SetEase(Ease.OutQuad).OnComplete(() =>
{
tmp.gameObject.SetActive(false);
tmp = null;
m_Status = EventWashingActionStatus.Ending;
if (OperatedItemProgress >= 0.999f)
{
if (m_DataManager != null)
{
m_DataManager.WashingData.Percent = 1f;
m_DataManager.WashingData.IsOver = true;
m_DataManager.SyncData();
}
FishingYachtAct.Publish<EventWashingConclusionData>(new EventWashingConclusionData());
}
});
}
protected void ChangeState2InvalidFromExecuting()
{
// 停止消耗电量
// 工具停止播放操作动画
// 道具飞回展示区
m_Tool.StopExecuting();
m_Tool.MoveToExhibition();
if (m_CurOperatedItem != null)
m_CurOperatedItem.StopAction();
m_Status = EventWashingActionStatus.Invalid;
}
protected void ChangeState2InvalidFromPreparing()
{
// 工具停止播放准备动画
// 道具飞回展示区
m_Tool.StopExecuting();
m_Tool.MoveToExhibition();
if (m_CurOperatedItem != null)
m_CurOperatedItem.StopAction();
m_Status = EventWashingActionStatus.Invalid;
}
protected void ChangeState2Invalid()
{
if (m_Tool != null && m_Tool.Status != EventWashingActionStatus.Invalid)
{
m_Tool.StopExecuting();
m_Tool.MoveToExhibition();
}
if (m_CurOperatedItem != null)
m_CurOperatedItem.StopAction();
m_Status = EventWashingActionStatus.Invalid;
}
#endregion
#region
protected LongPressStuffBase m_CurOperatedItem = null;
/// <summary>
/// 设置被操作物品已消耗时间
/// </summary>
/// <param name="time"></param>
public void SetOperatedItemHaveExecutedTime(int index, float time)
{
int count = m_OperatedItems.Count;
if (index < 0 || index >= count) return;
for (int i = 0; i < index; i++)
{
m_OperatedItems[i].SetOver();
}
m_OperatedItems[index].SetHaveExecutedTime(time);
for (int i = 0; i < count; i++)
{
m_OperatedItems[i].SetHaveExecutedTime(0f);
}
}
/// <summary>
/// 当前被操作物品进度
/// </summary>
public float OperatedItemProgress
{
get
{
float total = 0f;
float cumulativeTime = 0f;
int count = m_OperatedItems.Count;
EventWashingData washingData = null;
if (m_DataManager != null) washingData = m_DataManager.WashingData;
for (int i = 0; i < count; ++i)
{
var item = m_OperatedItems[i];
total += item.ConsumeTime;
cumulativeTime += item.CumulativeConsumeTime;
if (washingData != null) washingData.StepItems[i] = item.CumulativeConsumeTime / item.ConsumeTime;
}
return cumulativeTime / total;
}
}
protected void StopAllItemAction()
{
int count = m_OperatedItems.Count;
for (int i = 0; i < count; i++)
{
m_OperatedItems[i].StopAction();
}
}
#endregion
#region
private void InitEvent()
{
this.Subscribe<EventWashingConclusionData>(StartConclusion);
this.Subscribe<EventWashingStepOverData>(StepOver);
this.Subscribe<EventWashingAllGameOverData>(AllGameOver);
this.Subscribe<EventWashingTokenUpdateData>(UpdateBatteryInfo);
this.Subscribe<EventWashingToolEnter1stStageData>(ToolEnter1stStage);
this.Subscribe<EventWashingToolExit1stStageData>(ToolExit1stStage);
this.Subscribe<EventWashingToolEnter2ndStageData>(ToolEnter2ndStage);
this.Subscribe<EventWashingToolExit2ndStageData>(ToolExit2ndStage);
GContext.OnEvent<AddIndexEvent>().Subscribe(GuideListener).AddTo(this.disposables);
}
private void GuideListener(AddIndexEvent addIndexEvent)
{
if (addIndexEvent.CompleteGuide == true && panel != null)
{
panel.CompleteGuidance();
m_IsGuiding = false;
}
}
private void ToolEnter1stStage(EventWashingToolEnter1stStageData data)
{
if (m_Tool == null) return;
m_Tool.Enter1stStage();
}
private void ToolExit1stStage(EventWashingToolExit1stStageData data)
{
if (m_Tool == null) return;
m_Tool.Exit1stStage();
}
private void ToolEnter2ndStage(EventWashingToolEnter2ndStageData data)
{
if (m_Tool == null) return;
m_Tool.Enter2ndStage();
}
private void ToolExit2ndStage(EventWashingToolExit2ndStageData data)
{
if (m_Tool == null) return;
m_Tool.Exit2ndStage();
}
private bool m_IsUpdateBatteryInfo = true;
private void UpdateBatteryInfo(EventWashingTokenUpdateData data)
{
if (panel != null && m_IsUpdateBatteryInfo == true)
{
panel.SetBatteryInfo();
}
}
protected virtual void StartConclusion(EventWashingConclusionData data)
{
panel.StartConclusion();
}
private void StepOver(EventWashingStepOverData data)
{
m_IsUpdateBatteryInfo = false;
GameOver();
FishingYachtAct.Publish<EventWashingGameOverData>(new EventWashingGameOverData());
}
private void AllGameOver(EventWashingAllGameOverData data)
{
if (panel != null)
{
panel.ShowForAllGameOver();
}
}
#endregion
#region
public override void InitGame(string name)
{
base.InitGame(name);
int count = m_OperatedItems.Count;
for (int i = 0; i < count; i++)
{
m_OperatedItems[i].InitStuff();
}
m_IsGuiding = true;
}
public async override void EnterGame()
{
base.EnterGame();
m_IsUpdateBatteryInfo = true;
// 打开页面(UI)
GameObject pannelObj = await UIManager.Instance.ShowUI(UITypes.EventWashingPanel);
panel = pannelObj.transform.GetComponent<EventWashingPanel>();
InitPanel();
InitEvent();
AfterEnterGame();
CheckIsOver();
}
protected override void Update()
{
base.Update();
UpdatePanelProgress();
if (m_IsGuiding == true) return;
//bool showPowerConsumption = false;
Vector2 screenPosition = Vector2.zero;
if (m_OperatedItems != null && m_Tool != null)
{
if (Input.GetMouseButtonDown(0) || Input.GetMouseButton(0))
{
screenPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
bool needChange = false;
if (m_CurOperatedItem != null)
{
if (hit.transform != m_CurOperatedItem.transform)
needChange = true;
}
else
{
needChange = true;
}
if (needChange)
{
if (m_Status == EventWashingActionStatus.Executing)
{
ChangeState2InvalidFromExecuting();
}
else if (m_Status == EventWashingActionStatus.Preparing)
{
ChangeState2InvalidFromPreparing();
}
m_CurOperatedItem = null;
int count = m_OperatedItems.Count;
for (int i = 0; i < count; i++)
{
if (hit.transform == m_OperatedItems[i].transform)
{
m_CurOperatedItem = m_OperatedItems[i];
if (!m_CurOperatedItem.IsOver())
{
m_Tool.PrepareAction(m_OperationAreas[i].transform, OperatingToolsReadyAction);
m_Status = EventWashingActionStatus.Preparing;
}
}
}
}
//if (m_CurOperatedItem != null)
//{
// if (hit.transform == m_CurOperatedItem.transform)
// showPowerConsumption = true;
//}
}
}
else
{
if (m_Status == EventWashingActionStatus.Executing)
{
ChangeState2InvalidFromExecuting();
}
else if (m_Status == EventWashingActionStatus.Preparing)
{
ChangeState2InvalidFromPreparing();
}
else
{
ChangeState2Invalid();
}
m_CurOperatedItem = null;
}
}
//if (showPowerConsumption)
//{
// SetGestureFollowPosition(screenPosition);
//}
//else
//{
// // 隐藏电量消耗
// HideElectricityConsumption();
//}
}
protected override void PauseGame()
{
base.PauseGame();
StopAllItemAction();
}
public override void SyncData()
{
SyncGameData();
base.SyncData();
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,124 @@
using asap.core;
using cfg;
using Cinemachine;
using GameCore;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace game
{
public class WashingGameReview : WashingGameBase
{
#region
private EventWashingPanel panel;
private void InitPanel()
{
panel.SetDataManager(m_DataManager);
if (m_DataManager.HaveNextEventStep())
{
panel.ShowForShipOver();
}
else
{
m_DataManager.WashingData.IsAllGameOver = true;
panel.ShowForAllGameOver();
}
// 设置预览按钮
panel.SetBtnPreviewClickListener(null);
bool have = m_DataManager.HaveNextEventStep();
bool haveNextEventStep = false;
if (m_DataManager != null && m_DataManager.WashingData != null)
haveNextEventStep = m_DataManager.HaveNextEventStep();
// 设置关闭按钮
panel.SetBtnCloseClickListener(haveNextEventStep ? GoToNextStep : OnBtnCloseClickListener);
// 关闭笔刷填充进度
panel.ResetBrushChannelCounterFillAndInverse(false, false);
m_IsGuiding = panel.InitGuidance();
}
private void GoToNextStep()
{
GContext.Publish(new RewardPanelClose());
}
private void OnBtnCloseClickListener()
{
// 关闭当前Act
GContext.Publish(new UnloadActToNextAct());
}
#endregion
#region
public override void InitGame(string name)
{
base.InitGame(name);
this.m_GameType = EventWashingOperation.Review;
}
public async override void EnterGame()
{
base.EnterGame();
// 打开页面(UI)
GameObject pannelObj = await UIManager.Instance.ShowUI(UITypes.EventWashingPanel);
panel = pannelObj.transform.GetComponent<EventWashingPanel>();
InitPanel();
if (m_CameraMoveController != null)
{
m_CameraMoveController.enabled = true;
}
AfterEnterGame();
}
public override void ResetAndInitData(CinemachineVirtualCamera virtualCamera, CameraFollowPathMoveController cameraFollowPathMoveController, OperatingToolsBase tool)
{
if (virtualCamera != null)
{
m_VirtualCamera = virtualCamera;
if (m_CameraFocusedTransform != null)
{
m_VirtualCamera.LookAt = m_CameraFocusedTransform;
}
}
if (cameraFollowPathMoveController != null && m_CameraPath != null && m_RestIndexList != null)
{
m_CameraMoveController = cameraFollowPathMoveController;
m_CameraMoveController.ResetAndInit(m_CameraPath, m_RestIndexList, m_MagneticDistance);
if (m_CameraMoveController.Path.Looped == true)
{
m_CameraMoveController.IsAlwaysMoving = true;
}
m_CameraMoveController.Speed = m_CameraSpeed;
}
}
public override void GameOver()
{
if (m_CameraMoveController.Path.Looped == true)
{
m_CameraMoveController.IsAlwaysMoving = false;
}
base.GameOver();
}
protected override void Update()
{
base.Update();
if (panel != null)
panel.ContinuousOperation();
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,61 @@
using cfg;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace game
{
public class WashingGameSprayFoam : WashingGamePainting
{
#region
protected override void StartConclusion(EventWashingConclusionData data)
{
if (m_PaintTexture != null)
{
SetPaintTextureColor(Color.white, true);
}
base.StartConclusion(data);
}
#endregion
#region
protected override void InitPanel()
{
base.InitPanel();
// 关闭笔刷填充进度
panel.ResetBrushChannelCounterFillAndInverse(false, true);
this.StartCoroutine(StartCountingFill());
}
private IEnumerator StartCountingFill()
{
int index = 0;
while (index < 10)
{
yield return null;
index++;
}
panel.StartCountingFill();
}
#endregion
#region
public override void InitGame(string name)
{
base.InitGame(name);
this.m_GameType = EventWashingOperation.Foaming;
}
public override void Fresh(EventWashingDataManager dataManager)
{
SetPaintTextureColor(new Color(1f, 1f, 1f, 0f));
ChangePaintSphereBlendModeToAdditiveSoft();
m_PainterColor = Color.white;
base.Fresh(dataManager);
if (m_PaintTexture != null) m_PaintTexture.gameObject.SetActive(true);
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,19 @@
using cfg;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace game
{
public class WashingGameUnload : WashingGameRemove
{
#region
public override void InitGame(string name)
{
base.InitGame(name);
this.m_GameType = EventWashingOperation.Removing;
this.m_Status = EventWashingActionStatus.Invalid;
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,472 @@
using asap.core;
using cfg;
using Cinemachine;
using GameCore;
using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
namespace game
{
public class WashingGameVacuumCleaner : WashingGameBase
{
[Tooltip("清洁区域")]
[SerializeField]
private List<StuffCleaningArea> m_CleaningAreas = new List<StuffCleaningArea>();
[Tooltip("垃圾")]
[SerializeField]
private List<StuffTrash> m_Trashes = new List<StuffTrash>();
[Tooltip("屏幕点坐标偏移")]
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[Tooltip("垃圾消失时间")]
[SerializeField] private float m_TrashDisappearTime = 0.1f;
[Tooltip("垃圾消失距离")]
[SerializeField] private float m_TrashDisappearDistance = 0.1f;
#region
private EventWashingPanel panel;
private void InitPanel()
{
panel.SetDataManager(m_DataManager);
if (m_DataManager.WashingData.IsAllGameOver == true)
{
panel.ShowForAllGameOver();
// 设置关闭按钮
panel.SetBtnCloseClickListener(OnBtnCloseClickListener);
return;
}
panel.ShowForCleaning();
// 设置预览按钮
panel.SetBtnPreviewClickListener(null);
// 设置关闭按钮
panel.SetBtnCloseClickListener(OnBtnCloseClickListener);
m_IsGuiding = panel.InitGuidance();
}
private void HideElectricityConsumption()
{
if (panel == null) return;
panel.SetElectricityConsumptionVisible(false);
}
private void ShowElectricityConsumption()
{
panel.SetElectricityConsumptionVisible(true);
}
private void SetGestureFollowPosition(Vector2 position, float time = 0.1f)
{
if (panel == null) return;
ShowElectricityConsumption();
//Vector3 worldPosition = Vector3.zero;
RectTransformUtility.ScreenPointToWorldPointInRectangle(
panel.gestureFollow.transform.GetComponent<RectTransform>(),
position,
UIManager.Instance.UICanvas.worldCamera,
out Vector3 worldPosition);
panel.SetGestureFollowPosition(worldPosition);
}
private void OnBtnCloseClickListener()
{
// 关闭当前Act
GContext.Publish(new UnloadActToNextAct());
}
private bool m_HasPublishConclusion = false;
private void UpdatePanelProgress()
{
if (panel != null)
{
float progress = CleaningProgress;
panel.UpdateSingleProgress(progress);
if (m_DataManager != null) m_DataManager.WashingData.Percent = progress;
if (progress >= 0.999f)
{
if (m_HasPublishConclusion == false)
{
if (m_DataManager != null)
{
m_DataManager.WashingData.Percent = 1f;
m_DataManager.WashingData.IsOver = true;
m_DataManager.SyncData();
}
FishingYachtAct.Publish<EventWashingConclusionData>(new EventWashingConclusionData());
m_HasPublishConclusion = true;
}
}
else
{
m_HasPublishConclusion = false;
}
}
}
public float CleaningProgress
{
get
{
int count = m_Trashes.Count;
int num = 0;
EventWashingData washingData = null;
if (m_DataManager != null) washingData = m_DataManager.WashingData;
for (int i = 0; i < count; ++i)
{
if (m_Trashes[i].IsOver())
{
num += 1;
if (washingData != null) washingData.StepItems[i] = 1f;
}
else
{
if (washingData != null) washingData.StepItems[i] = 0f;
}
}
return (float)num / count;
}
}
#endregion
#region
private void StopAllTrashesAction()
{
int count = m_Trashes.Count;
for (int i = 0; i < count; ++i)
{
m_Trashes[i].StopAction();
}
}
private void ResumeAllTrashesAction()
{
int count = m_Trashes.Count;
for (int i = 0; i < count; ++i)
{
m_Trashes[i].StartAction(null);
}
}
#endregion
#region &
public override void ResetAndInitData(CinemachineVirtualCamera virtualCamera, CameraFollowPathMoveController cameraFollowPathMoveController, OperatingToolsBase tool)
{
base.ResetAndInitData(virtualCamera, cameraFollowPathMoveController, tool);
if (tool != null)
{
int count = m_Trashes.Count;
for (int i = 0; i < count; i++)
{
var trash = m_Trashes[i];
trash.SetCleaner((ToolForFollowerAndNormalPosition)tool, ((ToolForFollowerAndNormalPosition)tool).RangeCoverage, m_TrashDisappearTime, OnTrashItemCompleteAction);
}
}
}
private void OnTrashItemCompleteAction(StuffTrash stuffTrash)
{
if (m_DataManager == null) return;
EventWashingData washingData = m_DataManager.WashingData;
int count = m_Trashes.Count;
for (int i = 0; i < count; ++i)
{
if (m_Trashes[i] == stuffTrash)
{
washingData.StepItems[i] = 1f;
break;
}
}
m_DataManager.SyncData();
}
public static float ScaleFactor
{
get
{
var dpi = Screen.dpi;
if (dpi <= 0)
{
dpi = 200.0f;
}
return 200.0f / dpi;
}
}
protected void CheckIsOver()
{
float progress = CleaningProgress;
panel.UpdateSingleProgress(progress);
if (m_DataManager != null) m_DataManager.WashingData.Percent = progress;
if (progress >= 0.999f)
{
if (m_HasPublishConclusion == false)
{
if (m_DataManager != null)
{
m_DataManager.WashingData.Percent = 1f;
m_DataManager.WashingData.IsOver = true;
m_DataManager.SyncData();
}
FishingYachtAct.Publish<EventWashingConclusionData>(new EventWashingConclusionData());
m_HasPublishConclusion = true;
}
}
}
#endregion
#region
private void InitEvent()
{
this.Subscribe<EventWashingConclusionData>(StartConclusion);
this.Subscribe<EventWashingStepOverData>(StepOver);
this.Subscribe<EventWashingAllGameOverData>(AllGameOver);
this.Subscribe<EventWashingTokenUpdateData>(UpdateBatteryInfo);
GContext.OnEvent<AddIndexEvent>().Subscribe(GuideListener).AddTo(this.disposables);
}
private void GuideListener(AddIndexEvent addIndexEvent)
{
if (addIndexEvent.CompleteGuide == true && panel != null)
{
panel.CompleteGuidance();
m_IsGuiding = false;
}
}
private bool m_IsUpdateBatteryInfo = true;
private void UpdateBatteryInfo(EventWashingTokenUpdateData data)
{
if (panel != null && m_IsUpdateBatteryInfo == true)
{
panel.SetBatteryInfo();
}
}
protected virtual void StartConclusion(EventWashingConclusionData data)
{
panel.StartConclusion();
}
private void StepOver(EventWashingStepOverData data)
{
m_IsUpdateBatteryInfo = false;
GameOver();
FishingYachtAct.Publish<EventWashingGameOverData>(new EventWashingGameOverData());
}
private void AllGameOver(EventWashingAllGameOverData data)
{
if (panel != null)
{
panel.ShowForAllGameOver();
}
}
#endregion
#region
private void SyncGameData()
{
if (m_DataManager == null) return;
EventWashingData washingData = m_DataManager.WashingData;
bool syncData = false;
int count = m_Trashes.Count;
if (washingData.StepItems.Count == 0 && washingData.Percent == 0f && washingData.IsOver == false)
{
for (int i = 0; i < count; i++)
{
washingData.StepItems.Add(0f);
m_Trashes[i].gameObject.SetActive(true);
}
syncData = true;
}
else
{
for (int i = 0; i < count; i++)
{
if (washingData.StepItems.Count == i)
{
washingData.StepItems.Add(0f);
m_Trashes[i].gameObject.SetActive(true);
syncData = true;
}
else if (washingData.StepItems[i] >= 1f)
{
m_Trashes[i].SetStatus(EventWashingActionStatus.Ending);
m_Trashes[i].gameObject.SetActive(false);
}
else
{
m_Trashes[i].SetStatus(EventWashingActionStatus.Invalid);
m_Trashes[i].gameObject.SetActive(true);
}
}
}
if (syncData) m_DataManager.SyncData();
}
protected override void SetEnergyEnough()
{
base.SetEnergyEnough();
if (panel != null) panel.SetEnergyEnough();
}
protected override void SetEnergyShortage()
{
base.SetEnergyShortage();
if (panel != null) panel.SetEnergyShortage();
}
#endregion
#region
public override void InitGame(string name)
{
base.InitGame(name);
this.m_GameType = EventWashingOperation.Cleaning;
m_IsGuiding = true;
}
public async override void EnterGame()
{
base.EnterGame();
m_IsUpdateBatteryInfo = true;
// 打开页面(UI)
GameObject pannelObj = await UIManager.Instance.ShowUI(UITypes.EventWashingPanel);
panel = pannelObj.transform.GetComponent<EventWashingPanel>();
InitPanel();
InitEvent();
AfterEnterGame();
CheckIsOver();
}
protected override void Update()
{
base.Update();
if (m_Tool == null) return;
int count = m_CleaningAreas.Count;
if (count < 1) return;
UpdatePanelProgress();
if (m_IsGuiding == true) return;
bool showPowerConsumption = false;
Vector2 screenPosition = Vector2.zero;
if (Input.GetMouseButtonDown(0) || Input.GetMouseButton(0))
{
screenPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y) + m_Offset * ScaleFactor;
Ray ray = Camera.main.ScreenPointToRay(screenPosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
for (int i = 0; i < count; i++)
{
if (hit.transform == m_CleaningAreas[i].transform)
{
if (!IsGameOver() && (HaveEnergy() || ConsumeTokens(1)))
{
var normal = hit.normal;
var point = hit.point;
((ToolForFollowerAndNormalPosition)m_Tool).Follow(point, normal);
showPowerConsumption = true;
}
}
}
}
}
if (showPowerConsumption)
{
SetGestureFollowPosition(screenPosition);
m_Tool.StartExecuting();
}
else
{
// 隐藏电量消耗
HideElectricityConsumption();
m_Tool.StopExecuting();
}
}
protected override void PauseGame()
{
base.PauseGame();
StopAllTrashesAction();
}
protected override void ResumeGame()
{
base.ResumeGame();
ResumeAllTrashesAction();
}
public override void Fresh(EventWashingDataManager dataManager)
{
base.Fresh(dataManager);
int count = m_CleaningAreas.Count;
for (int i = 0;i < count;i++)
{
m_CleaningAreas[i].gameObject.SetActive(true);
}
//count = m_Trashes.Count;
//for (int i = 0; i < count; i++)
//{
// m_Trashes[i].gameObject.SetActive(true);
//}
m_HasPublishConclusion = false;
}
public override void GameOver()
{
base.GameOver();
int count = m_CleaningAreas.Count;
for (int i = 0; i < count; i++)
{
m_CleaningAreas[i].gameObject.SetActive(false);
}
count = m_Trashes.Count;
for (int i = 0; i < count; i++)
{
m_Trashes[i].gameObject.SetActive(false);
}
}
public override void SyncData()
{
SyncGameData();
base.SyncData();
}
#endregion
}
}

View File

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