You've already forked taptap2024_GJ_chidouren
updat core
This commit is contained in:
62
Assets/Scripts/Game/Component/CameraManager.cs
Normal file
62
Assets/Scripts/Game/Component/CameraManager.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Cinemachine;
|
||||
using Framework.Timer;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component
|
||||
{
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
public enum CameraState
|
||||
{
|
||||
Normal = 0, // 正常
|
||||
Player_Near, // 在玩家附近
|
||||
Player_Far, // 在玩家远处
|
||||
CloseUp // 特写镜头
|
||||
}
|
||||
|
||||
[SerializeField] private Camera mainCamera;
|
||||
[SerializeField] private Animator cameraAnimator;
|
||||
[SerializeField] private Transform closeUpTarget;
|
||||
[SerializeField] private PolygonCollider2D boxBorder;
|
||||
|
||||
public CameraState cameraState = CameraState.Normal;
|
||||
private static readonly int TriggerState = Animator.StringToHash ("TriggerState");
|
||||
private TimeHandler _closeUpTimeHandler;
|
||||
|
||||
|
||||
public void SetCameraState (CameraState state)
|
||||
{
|
||||
this.cameraState = state;
|
||||
this.cameraAnimator.SetInteger (TriggerState , (int)state);
|
||||
}
|
||||
|
||||
public void SetCloseUpTarget (Transform target , float duration = 3)
|
||||
{
|
||||
this._closeUpTimeHandler?.Kill ();
|
||||
var lastState = this.cameraState;
|
||||
this.closeUpTarget.position = target.position;
|
||||
SetCameraState (CameraState.CloseUp);
|
||||
this._closeUpTimeHandler = GameUpdateMgr.Instance.CreateTimer (duration , () =>
|
||||
{
|
||||
SetCameraState (lastState);
|
||||
this._closeUpTimeHandler = null;
|
||||
});
|
||||
}
|
||||
|
||||
public void SetBoxCollider (PolygonCollider2D box)
|
||||
{
|
||||
this.boxBorder.offset = box.offset;
|
||||
this.boxBorder.pathCount = box.pathCount;
|
||||
this.boxBorder.points = box.points;
|
||||
this.transform.GetComponentsInChildren<CinemachineConfiner2D> ().ForEach (d => d.InvalidateCache ());
|
||||
}
|
||||
|
||||
public static CameraManager Instance { get; private set; }
|
||||
|
||||
private void Awake ()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Component/CameraManager.cs.meta
Normal file
3
Assets/Scripts/Game/Component/CameraManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4f8145a01fd4f7ba6c04e2faccca4d2
|
||||
timeCreated: 1729479839
|
||||
@@ -1,11 +1,15 @@
|
||||
using System;
|
||||
using Framework.Timer;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component
|
||||
{
|
||||
public class MapContent : MonoBehaviour
|
||||
{
|
||||
public PlayerEntity PlayerEntity;
|
||||
public PlayerEntity PlayerEntity;
|
||||
[HideInInspector] public ScenePart ScenePart;
|
||||
public AstarPath Pathfinder;
|
||||
|
||||
//玩家位置
|
||||
public Vector2 PlayerPosition { private set; get; }
|
||||
|
||||
@@ -16,13 +20,55 @@ namespace Game.Component
|
||||
{
|
||||
//全局特殊单例
|
||||
Instance = this;
|
||||
var componentInChildren = this.transform.GetComponentInChildren<ScenePart> ();
|
||||
if (componentInChildren != null)
|
||||
{
|
||||
SetPart (componentInChildren);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update ()
|
||||
|
||||
private void OnEnable ()
|
||||
{
|
||||
this.PlayerPosition = PlayerEntity.transform.position;
|
||||
GameUpdateMgr.Instance.AddUpdater (DoUpdate);
|
||||
}
|
||||
|
||||
private void OnDisable ()
|
||||
{
|
||||
GameUpdateMgr.Instance.RemoveUpdater (DoUpdate);
|
||||
}
|
||||
|
||||
private void DoUpdate ()
|
||||
{
|
||||
this.PlayerPosition = this.PlayerEntity.transform.position;
|
||||
}
|
||||
|
||||
public void SetPart (ScenePart scenePart)
|
||||
{
|
||||
if (this.ScenePart != null)
|
||||
{
|
||||
GameObject.Destroy (this.ScenePart.gameObject);
|
||||
}
|
||||
|
||||
this.ScenePart = scenePart;
|
||||
this.Pathfinder.data.SetData (this.ScenePart.mapCacheData.bytes);
|
||||
CameraManager.Instance.SetBoxCollider (this.ScenePart.cameraCollider);
|
||||
ResetPlayer ();
|
||||
CameraManager.Instance.SetCameraState (CameraManager.CameraState.Player_Near);
|
||||
}
|
||||
|
||||
public void ResetPlayer ()
|
||||
{
|
||||
this.PlayerEntity.transform.position = this.ScenePart.createPos.position;
|
||||
this.PlayerEntity.gameObject.SetActive (true);
|
||||
this.PlayerEntity.RefreshInit ();
|
||||
//播放特效
|
||||
}
|
||||
|
||||
public void OverlyCoin (int messageOverlyCoin)
|
||||
{
|
||||
// ReSharper disable once Unity.NoNullPropagation
|
||||
this.ScenePart?.AddConditionNumber (messageOverlyCoin);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -45,5 +45,13 @@ namespace Game.Component
|
||||
{
|
||||
this.transform.rotation = Quaternion.Euler (0 , 0 , this.transform.rotation.eulerAngles.z);
|
||||
}
|
||||
|
||||
public void RefreshInit ()
|
||||
{
|
||||
this.speedBuffTimer?.Kill ();
|
||||
this.speedBuffTimer = null;
|
||||
this.speedBuffOffset = 0;
|
||||
//主角出生初始化
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Assets/Scripts/Game/Component/ScenePart.cs
Normal file
26
Assets/Scripts/Game/Component/ScenePart.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component
|
||||
{
|
||||
public class ScenePart : MonoBehaviour
|
||||
{
|
||||
public TextAsset mapCacheData;
|
||||
public PolygonCollider2D cameraCollider;
|
||||
public Transform createPos;
|
||||
|
||||
public int completeConditionNumber = 10;
|
||||
public float playerBaseSpeed = 4f;
|
||||
|
||||
[LabelText ("当前完成数:")] private int _currentConditionNumber = 0;
|
||||
|
||||
|
||||
public bool IsComplete => _currentConditionNumber >= completeConditionNumber;
|
||||
|
||||
public bool AddConditionNumber (int number = 1)
|
||||
{
|
||||
this._currentConditionNumber += number;
|
||||
return _currentConditionNumber >= completeConditionNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Component/ScenePart.cs.meta
Normal file
3
Assets/Scripts/Game/Component/ScenePart.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2198455a7d46404bab676464cf70ce14
|
||||
timeCreated: 1729478564
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEditor;
|
||||
using Game.Component.Map;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component.SceneProp.Editor
|
||||
@@ -135,7 +136,7 @@ namespace Game.Component.SceneProp.Editor
|
||||
}
|
||||
|
||||
//创建敌人b
|
||||
[MenuItem("GameObject/场景角色/创建敌人b" , false, 10)]
|
||||
[MenuItem("GameObject/场景敌人/创建敌人b" , false, 10)]
|
||||
public static void CreateEnemyB (MenuCommand menuCommand)
|
||||
{
|
||||
var prefab = LoadPrefab ("Assets/GameRes/GamePool/enemy_B.prefab");
|
||||
@@ -153,7 +154,7 @@ namespace Game.Component.SceneProp.Editor
|
||||
}
|
||||
|
||||
//创建敌人c
|
||||
[MenuItem("GameObject/场景角色/创建敌人c" , false, 10)]
|
||||
[MenuItem("GameObject/场景敌人/创建敌人c" , false, 10)]
|
||||
public static void CreateEnemyC (MenuCommand menuCommand)
|
||||
{
|
||||
var prefab = LoadPrefab ("Assets/GameRes/GamePool/enemy_C.prefab");
|
||||
@@ -171,7 +172,7 @@ namespace Game.Component.SceneProp.Editor
|
||||
}
|
||||
|
||||
//创建敌人witch
|
||||
[MenuItem("GameObject/场景角色/创建敌人witch" , false, 10)]
|
||||
[MenuItem("GameObject/场景敌人/创建敌人witch" , false, 10)]
|
||||
public static void CreateEnemyWitch (MenuCommand menuCommand)
|
||||
{
|
||||
var prefab = LoadPrefab ("Assets/GameRes/GamePool/enemy_Witch.prefab");
|
||||
@@ -187,5 +188,22 @@ namespace Game.Component.SceneProp.Editor
|
||||
Selection.activeObject = prop;
|
||||
Selection.activeTransform = prop.transform;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/场景道具/创建地图链接" , false, 10)]
|
||||
public static void CreateMapLink ()
|
||||
{
|
||||
var pos = CreatePos ();
|
||||
var prop = new GameObject("mapLink");
|
||||
prop.transform.position = pos;
|
||||
prop.AddComponent<MovePathGroup> ();
|
||||
var target = Selection.activeTransform;
|
||||
if (target != null)
|
||||
{
|
||||
prop.transform.SetParent (target);
|
||||
}
|
||||
Undo.RegisterCreatedObjectUndo(prop, "Create " + prop.name);
|
||||
Selection.activeObject = prop;
|
||||
Selection.activeTransform = prop.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Assets/Scripts/Game/Component/SceneProp/EventTriggerProp.cs
Normal file
35
Assets/Scripts/Game/Component/SceneProp/EventTriggerProp.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Game.EventDefine;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Component.SceneProp
|
||||
{
|
||||
public class EventTriggerProp : BaseProp
|
||||
{
|
||||
public enum TriggerType
|
||||
{
|
||||
None = 0,
|
||||
GameComplete,
|
||||
CloseUp
|
||||
}
|
||||
|
||||
public TriggerType _triggerType = TriggerType.None;
|
||||
|
||||
[ShowIf ("_triggerType", TriggerType.CloseUp)]
|
||||
public Transform _closeUpTarget = null;
|
||||
|
||||
|
||||
protected override void OnTrigger (PlayerEntity entity)
|
||||
{
|
||||
switch (this._triggerType)
|
||||
{
|
||||
case TriggerType.CloseUp:
|
||||
GameEventDefine.CloseUp.SendMessage (this._closeUpTarget);
|
||||
break;
|
||||
case TriggerType.GameComplete:
|
||||
GameEventDefine.GameComplete.SendMessage ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 697c44ed14a44a66949bc556020b2960
|
||||
timeCreated: 1729479036
|
||||
@@ -106,5 +106,25 @@ namespace Game.EventDefine
|
||||
UniEvent.SendMessage (showTipBox);
|
||||
}
|
||||
}
|
||||
|
||||
public class GameComplete : IEventMessage
|
||||
{
|
||||
private GameComplete ()
|
||||
{
|
||||
}
|
||||
|
||||
public static void SendMessage () => UniEvent.SendMessage (new GameComplete ());
|
||||
}
|
||||
|
||||
public class CloseUp : IEventMessage
|
||||
{
|
||||
public Transform Target { get; private set; }
|
||||
|
||||
private CloseUp ()
|
||||
{
|
||||
}
|
||||
|
||||
public static void SendMessage (Transform target) => UniEvent.SendMessage (new CloseUp () { Target = target });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using Framework.Audio;
|
||||
using Framework.FSMLite;
|
||||
using Framework.UI;
|
||||
using Game.EventDefine;
|
||||
using IcecreamView;
|
||||
using UnityEngine;
|
||||
using Views;
|
||||
|
||||
namespace Game.FsmNode
|
||||
{
|
||||
public class GamePart : StateMachine<GameState>
|
||||
{
|
||||
private int _lastPartLayer = -1;
|
||||
private int _lastLevelIndex = -1;
|
||||
|
||||
protected override void OnEnter (params object[] args)
|
||||
{
|
||||
AudioManager.Instance.PlayBGM(BgmAudio.NormalBgm , 0.65f);
|
||||
}
|
||||
|
||||
protected override void OnExit ()
|
||||
{
|
||||
UIManager.Instance.CloseViewWithGroup (this.GetType ().FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33084e8a307b49648b468d7ae4123115
|
||||
timeCreated: 1717040492
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using Framework.Audio;
|
||||
using Framework.FSMLite;
|
||||
using Framework.UI;
|
||||
using Game.EventDefine;
|
||||
using Game.Manager;
|
||||
using Views;
|
||||
|
||||
namespace Game.FsmNode
|
||||
{
|
||||
public class GameRelax : StateMachine<GameState>
|
||||
{
|
||||
protected override async void OnEnter (params object[] args)
|
||||
{
|
||||
AudioManager.Instance.PlayBGM(BgmAudio.NormalBgm , 0.65f);
|
||||
//如果是从游戏关卡选择中返回休息,不刷新商店
|
||||
var isRefreshShop = this.stateMachineRunner.LastState != GameState.PartGame;
|
||||
if (isRefreshShop)
|
||||
{
|
||||
RefreshShop ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void RefreshShop ()
|
||||
{
|
||||
if (this.stateMachineRunner.LastState != GameState.PartGame)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit ()
|
||||
{
|
||||
UIManager.Instance.CloseViewWithGroup (this.GetType ().FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72a83c4ee54e44ea8fd35c8f522ad3b7
|
||||
timeCreated: 1717040477
|
||||
@@ -7,7 +7,7 @@ namespace Game.FsmNode
|
||||
{
|
||||
protected override void OnEnter (params object[] args)
|
||||
{
|
||||
this.stateMachineRunner.OpenState (GameState.RelaxGame);
|
||||
this.stateMachineRunner.OpenState (GameState.StartGame);
|
||||
}
|
||||
|
||||
protected override void OnExit ()
|
||||
|
||||
@@ -13,11 +13,8 @@ namespace Game.FsmNode
|
||||
protected override async void OnEnter (params object[] args)
|
||||
{
|
||||
AudioManager.Instance.PlayBGM(BgmAudio.NormalBgm , 0.65f);
|
||||
GameEventDefine.ChangeGameFsm.SendMessage (GameState.PartGame , true);
|
||||
GameEventDefine.ChangeGameFsm.SendMessage (GameState.FightGame , true);
|
||||
UIManager.Instance.CloseLoading (null);
|
||||
if (Account.Instance.AccountGameData.InitCardIds.Count > 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit ()
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace Game
|
||||
AppendState<GameInit>(GameState.InitGame);
|
||||
AppendState<GameStart>(GameState.StartGame);
|
||||
AppendState<GameContinue>(GameState.ContinueGame);
|
||||
AppendState<GameRelax>(GameState.RelaxGame);
|
||||
AppendState<GamePart>(GameState.PartGame);
|
||||
AppendState<GameFight>(GameState.FightGame);
|
||||
AppendState<GameRevert>(GameState.RevertGame);
|
||||
AppendState<GameSuccess>(GameState.SuccessGame);
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
InitGame = 0,
|
||||
StartGame,
|
||||
ContinueGame,
|
||||
RelaxGame,
|
||||
PartGame,
|
||||
FightGame,
|
||||
RevertGame,
|
||||
SuccessGame,
|
||||
|
||||
@@ -4,11 +4,13 @@ using System.Linq;
|
||||
using System.ScriptListener;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using FJson;
|
||||
using Framework.Asset;
|
||||
using Framework.Audio;
|
||||
using Framework.GamePool.manager;
|
||||
using Framework.Timer;
|
||||
using Framework.UI;
|
||||
using Framework.Utils.SingletonTemplate;
|
||||
using Game.Component;
|
||||
using Game.Data;
|
||||
using Game.EventDefine;
|
||||
using IcecreamView;
|
||||
@@ -16,6 +18,7 @@ using StateSystem;
|
||||
using UniFramework.Event;
|
||||
using UnityEngine;
|
||||
using Views;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
@@ -38,6 +41,8 @@ namespace Game
|
||||
|
||||
public GameState CurrentGameState => this._gameFsm.CurrentState;
|
||||
|
||||
public int PartIndex = 1;
|
||||
|
||||
public RoomGlobalData RoomGlobalData
|
||||
{
|
||||
get => _roomGlobalData;
|
||||
@@ -50,6 +55,10 @@ namespace Game
|
||||
this._gameFsm.Active (GameState.InitGame , args);
|
||||
GameUpdateMgr.Instance.AddUpdater (DoUpdate);
|
||||
this.BindEvent ();
|
||||
if (MapContent.Instance.ScenePart == null)
|
||||
{
|
||||
LoadScenePart (this.PartIndex);
|
||||
}
|
||||
this._gameFsm.OpenState (GameState.StartGame);
|
||||
}
|
||||
|
||||
@@ -102,6 +111,14 @@ namespace Game
|
||||
this.HasLock = false;
|
||||
}
|
||||
|
||||
public void LoadScenePart (int partIndex)
|
||||
{
|
||||
var loadName = $"AutoSource/Part/part{partIndex}.prefab";
|
||||
var scenePart = AssetManager.Instance.LoadAsset<GameObject> (loadName).GetComponent<ScenePart> ();
|
||||
var instantiate = Object.Instantiate (scenePart, MapContent.Instance.transform, true);
|
||||
MapContent.Instance.SetPart (instantiate);
|
||||
}
|
||||
|
||||
#region 事件
|
||||
|
||||
private void BindEvent ()
|
||||
@@ -122,7 +139,7 @@ namespace Game
|
||||
if (obj is GameEventDefine.OverlyCoin message)
|
||||
{
|
||||
AudioManager.Instance.PlaySoundEffect (SeAudio.Gaming_GetCoin);
|
||||
this.RoomGlobalData.OverlyCoin (message.overlyCoin , message.hasEcho);
|
||||
MapContent.Instance.OverlyCoin (message.overlyCoin);
|
||||
GlobalEventDefine.RefreshView.SendMessage ();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user