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
|
||||
Reference in New Issue
Block a user