From 64be62f6be76dc45b70af1c139d3fb10de134964 Mon Sep 17 00:00:00 2001 From: zxl <168ssss8@360.com> Date: Thu, 11 Apr 2024 16:44:25 +0800 Subject: [PATCH] =?UTF-8?q?unity=E7=89=88=E6=9C=AC=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E4=B8=BA2021.3.22=EF=BC=9B=E4=BF=AE=E5=A4=8D=E6=89=80=E6=9C=89?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../骨骼动画/bossani/boss_Material.mat | 3 - .../骨骼动画/playerani/role_Material.mat | 3 - Assets/Scripts/BFS/BFS.cs | 467 +++++++++--------- Assets/Scripts/BFS/BFSManager.cs | 169 +++---- Assets/Scripts/BFS/WayPoint.cs | 15 +- Assets/Scripts/Boss/BossInfo.cs | 133 ++--- Assets/Scripts/Boss/IBoss.cs | 133 ++--- Assets/Scripts/Boss/IBossManager.cs | 79 +-- .../Event/Args/BossStartMoveEventArgs.cs | 27 +- .../Args/InitCurrentPlayerDataEventArgs.cs | 21 +- .../Event/Args/InputNameFinishEventArgs.cs | 21 +- .../Event/Args/InputObjectFinishEventArgs.cs | 21 +- .../Event/Args/JinBeiSettlementEventArgs.cs | 25 +- .../PlayerJinBeiChange_ToMainUIEventArgs.cs | 21 +- .../PlayerJinBeiChange_ToPlayerEventArgs.cs | 29 +- .../Event/Args/PlayerMoveToRoomEventArgs.cs | 25 +- .../Event/Args/PlayerUpdateDataEventArgs.cs | 21 +- .../Event/Args/ReturnPlayerJinBeiEventArgs.cs | 25 +- .../Event/Args/RoomJinBeiChangeEventArgs.cs | 29 +- Assets/Scripts/Log/Log.cs | 33 +- Assets/Scripts/Player/Player.cs | 203 ++++---- Assets/Scripts/Player/PlayerManager.cs | 91 ++-- .../Logic/EnterGameSceneProcedure.cs | 53 +- .../Logic/GameSceneKillPlayerProcedure.cs | 135 ++--- .../Logic/GameSceneSettlementProcedure.cs | 33 +- .../Scripts/Procedure/ProcedureAttribute.cs | 17 +- Assets/Scripts/RayCast/MouseInput.cs | 171 +++---- Assets/Scripts/RayCast/MouseInputManager.cs | 39 +- Assets/Scripts/Room/IRoomManager.cs | 323 ++++++------ Assets/Scripts/Room/Room.cs | 201 ++++---- Assets/Scripts/Spine/SpineAnimator.cs | 189 +++---- Assets/Scripts/UI/AssemblyManager.cs | 37 +- Assets/Scripts/UI/Logic/GameSceneHelpUI.cs | 39 +- Assets/Scripts/UI/Logic/GameSceneResultUI.cs | 63 +-- Assets/Scripts/UI/Logic/GlobalLogOnlyAppUI.cs | 35 +- Assets/Scripts/UI/Logic/InputNameUI.cs | 49 +- Assets/Scripts/WayPointFlag.cs | 7 +- .../TwoByTwoTransformEffectExample.cs | 2 +- .../Spine Skeletons/Dragon/dragon_dragon.mat | 3 - .../Spine Skeletons/Dragon/dragon_dragon2.mat | 3 - .../Spine Skeletons/Dragon/dragon_dragon3.mat | 3 - .../Spine Skeletons/Dragon/dragon_dragon4.mat | 3 - .../Spine Skeletons/Dragon/dragon_dragon5.mat | 3 - .../Spine Skeletons/Dragon/dragon_dragon6.mat | 3 - .../Spine Skeletons/Eyes/eyes_Material.mat | 3 - .../Equipment/Equipment_Material.mat | 3 - .../FootSoldier/FS_White_Material.mat | 3 - .../Spine Skeletons/Gauge/Gauge_Material.mat | 3 - .../Goblins/goblins_Material.mat | 3 - .../Hero/hero-pro_Material.mat | 3 - .../Raggedy Spineboy_Material.mat | 3 - .../Raptor/raptor_Material.mat | 3 - .../Spineunitygirl/Doi_Material.mat | 3 - .../stretchyman-diffuse-pma_Material.mat | 3 - .../mix-and-match-pma_Material.mat | 3 - .../raptor-pma_Material.mat | 3 - .../spineboy-pro/spineboy-pro_Material.mat | 3 - .../spineboy-unity/spineboy_Material.mat | 3 - .../whirlyblendmodes_Material.mat | 3 - Assets/csc.rsp | 1 - Assets/csc.rsp.meta | 3 - Packages/packages-lock.json | 57 ++- ProjectSettings/PackageManagerSettings.asset | 4 +- .../Settings.json | 2 + ProjectSettings/ProjectVersion.txt | 4 +- ProjectSettings/boot.config | 0 66 files changed, 1548 insertions(+), 1573 deletions(-) delete mode 100644 Assets/csc.rsp delete mode 100644 Assets/csc.rsp.meta create mode 100644 ProjectSettings/boot.config diff --git a/Assets/Hotfix/Art/da_tao_sha/骨骼动画/bossani/boss_Material.mat b/Assets/Hotfix/Art/da_tao_sha/骨骼动画/bossani/boss_Material.mat index d546b22..c215f9c 100644 --- a/Assets/Hotfix/Art/da_tao_sha/骨骼动画/bossani/boss_Material.mat +++ b/Assets/Hotfix/Art/da_tao_sha/骨骼动画/bossani/boss_Material.mat @@ -9,8 +9,6 @@ Material: m_PrefabAsset: {fileID: 0} m_Name: boss_Material m_Shader: {fileID: 4800000, guid: 1e8a610c9e01c3648bac42585e5fc676, type: 3} - m_Parent: {fileID: 0} - m_ModifiedSerializedProperties: 0 m_ValidKeywords: [] m_InvalidKeywords: - _USE8NEIGHBOURHOOD_ON @@ -20,7 +18,6 @@ Material: m_CustomRenderQueue: -1 stringTagMap: {} disabledShaderPasses: [] - m_LockedProperties: m_SavedProperties: serializedVersion: 3 m_TexEnvs: diff --git a/Assets/Hotfix/Art/da_tao_sha/骨骼动画/playerani/role_Material.mat b/Assets/Hotfix/Art/da_tao_sha/骨骼动画/playerani/role_Material.mat index 064b2c6..73264c7 100644 --- a/Assets/Hotfix/Art/da_tao_sha/骨骼动画/playerani/role_Material.mat +++ b/Assets/Hotfix/Art/da_tao_sha/骨骼动画/playerani/role_Material.mat @@ -9,8 +9,6 @@ Material: m_PrefabAsset: {fileID: 0} m_Name: role_Material m_Shader: {fileID: 4800000, guid: 1e8a610c9e01c3648bac42585e5fc676, type: 3} - m_Parent: {fileID: 0} - m_ModifiedSerializedProperties: 0 m_ValidKeywords: [] m_InvalidKeywords: - _USE8NEIGHBOURHOOD_ON @@ -20,7 +18,6 @@ Material: m_CustomRenderQueue: -1 stringTagMap: {} disabledShaderPasses: [] - m_LockedProperties: m_SavedProperties: serializedVersion: 3 m_TexEnvs: diff --git a/Assets/Scripts/BFS/BFS.cs b/Assets/Scripts/BFS/BFS.cs index f1bf389..75658d4 100644 --- a/Assets/Scripts/BFS/BFS.cs +++ b/Assets/Scripts/BFS/BFS.cs @@ -4,215 +4,215 @@ using Cysharp.Threading.Tasks; using JetBrains.Annotations; using UnityEngine; -namespace Game.Pathfinding; - -public class Node +namespace Game.Pathfinding { - public int index { get; private set; } - public T data { get; private set; } - - public Node(int index, T data) + public class Node { - this.index = index; - this.data = data; - } -} + public int index { get; private set; } + public T data { get; private set; } -class Edge -{ - public Node from { get; private set; } - public Node to { get; private set; } - public bool canTranslate { get; private set; } - - public Edge(Node from, Node to, bool canTranslate = true) - { - this.from = from; - this.to = to; - this.canTranslate = canTranslate; - } - - public Node GetAnotherNode(Node node) - { - return node == this.from ? to : to == node ? from : throw new InvalidOperationException(); - } -} - -public class WayPointGraph : Graph -{ - readonly struct UniqueWayPoint : IEquatable - { - private readonly WayPoint _wayPoint; - - public UniqueWayPoint(WayPoint wayPoint) + public Node(int index, T data) { - this._wayPoint = wayPoint; - } - - public bool Equals(UniqueWayPoint other) - { - return _wayPoint.position == other._wayPoint.position; - } - - public override bool Equals(object obj) - { - return obj is UniqueWayPoint other && Equals(other); - } - - public override int GetHashCode() - { - return _wayPoint.position.GetHashCode(); - } - - public static implicit operator WayPoint(UniqueWayPoint uniqueWayPoint) - { - return uniqueWayPoint._wayPoint; - } - - public static implicit operator UniqueWayPoint(WayPoint wayPoint) - { - return new UniqueWayPoint(wayPoint); + this.index = index; + this.data = data; } } - public void Initialize(GameGlobalConfig.NodeMap[] nodeMaps) + class Edge { - HashSet wayPoints = new HashSet(); - foreach (var nodeMap in nodeMaps) + public Node from { get; private set; } + public Node to { get; private set; } + public bool canTranslate { get; private set; } + + public Edge(Node from, Node to, bool canTranslate = true) { - wayPoints.Add(new WayPoint(nodeMap.node1)); - wayPoints.Add(new WayPoint(nodeMap.node2)); + this.from = from; + this.to = to; + this.canTranslate = canTranslate; } - Dictionary> position2NodeMap = new Dictionary>(); - _nodes = new Node[wayPoints.Count]; - using var enumerator = wayPoints.GetEnumerator(); - int index = 0; - while (enumerator.MoveNext()) + public Node GetAnotherNode(Node node) { - var enumeratorCurrent = (WayPoint)enumerator.Current; - var node = new Node(index, enumeratorCurrent); - this._nodes[index] = node; - position2NodeMap[enumeratorCurrent.position] = node; - index++; + return node == this.from ? to : to == node ? from : throw new InvalidOperationException(); } + } - _edges = new List>(nodeMaps.Length); - this._connection = new Dictionary, List>>(_edges.Count); - - foreach (var nodeMap in nodeMaps) + public class WayPointGraph : Graph + { + readonly struct UniqueWayPoint : IEquatable { - if (position2NodeMap.TryGetValue(nodeMap.node1, out var node1)) + private readonly WayPoint _wayPoint; + + public UniqueWayPoint(WayPoint wayPoint) { - if (position2NodeMap.TryGetValue(nodeMap.node2, out var node2)) + this._wayPoint = wayPoint; + } + + public bool Equals(UniqueWayPoint other) + { + return _wayPoint.position == other._wayPoint.position; + } + + public override bool Equals(object obj) + { + return obj is UniqueWayPoint other && Equals(other); + } + + public override int GetHashCode() + { + return _wayPoint.position.GetHashCode(); + } + + public static implicit operator WayPoint(UniqueWayPoint uniqueWayPoint) + { + return uniqueWayPoint._wayPoint; + } + + public static implicit operator UniqueWayPoint(WayPoint wayPoint) + { + return new UniqueWayPoint(wayPoint); + } + } + + public void Initialize(GameGlobalConfig.NodeMap[] nodeMaps) + { + HashSet wayPoints = new HashSet(); + foreach (var nodeMap in nodeMaps) + { + wayPoints.Add(new WayPoint(nodeMap.node1)); + wayPoints.Add(new WayPoint(nodeMap.node2)); + } + + Dictionary> position2NodeMap = new Dictionary>(); + _nodes = new Node[wayPoints.Count]; + using var enumerator = wayPoints.GetEnumerator(); + int index = 0; + while (enumerator.MoveNext()) + { + var enumeratorCurrent = (WayPoint)enumerator.Current; + var node = new Node(index, enumeratorCurrent); + this._nodes[index] = node; + position2NodeMap[enumeratorCurrent.position] = node; + index++; + } + + _edges = new List>(nodeMaps.Length); + this._connection = new Dictionary, List>>(_edges.Count); + + foreach (var nodeMap in nodeMaps) + { + if (position2NodeMap.TryGetValue(nodeMap.node1, out var node1)) { - var edge = new Edge(node1, node2); - _edges.Add(edge); - if (!this._connection.TryGetValue(node1, out var list1)) + if (position2NodeMap.TryGetValue(nodeMap.node2, out var node2)) { - this._connection[node1] = list1 = new List>(); - } + var edge = new Edge(node1, node2); + _edges.Add(edge); + if (!this._connection.TryGetValue(node1, out var list1)) + { + this._connection[node1] = list1 = new List>(); + } - list1.Add(edge); - if (!this._connection.TryGetValue(node2, out var list2)) - { - this._connection[node2] = list2 = new List>(); - } + list1.Add(edge); + if (!this._connection.TryGetValue(node2, out var list2)) + { + this._connection[node2] = list2 = new List>(); + } - list2.Add(edge); + list2.Add(edge); + } } } } } -} -public class Graph -{ - private protected Node[] _nodes; - private protected List> _edges; - private protected Dictionary, List>> _connection; - - internal Node GetNode(int index) + public class Graph { - if (index < 0 || index >= this._nodes.Length) - { - throw new IndexOutOfRangeException($"Index is {index}"); - } + private protected Node[] _nodes; + private protected List> _edges; + private protected Dictionary, List>> _connection; - return this._nodes[index]; - } - - [CanBeNull] - internal Node GetNode(Predicate> predicate) - { - foreach (var node in this._nodes) + internal Node GetNode(int index) { - if (predicate(node)) + if (index < 0 || index >= this._nodes.Length) { - return node; + throw new IndexOutOfRangeException($"Index is {index}"); } + + return this._nodes[index]; } - return null; - } - - internal IReadOnlyList> GetNeighbours(Node node) - { - if (this._connection.TryGetValue(node, out var edges)) + [CanBeNull] + internal Node GetNode(Predicate> predicate) { - return edges; + foreach (var node in this._nodes) + { + if (predicate(node)) + { + return node; + } + } + + return null; } - throw new ArgumentException($"GetNeighbours have error ! the id is {node.index}"); - } -} - -public class BFS -{ - private Graph _graph; - private List _closeList = new List(); - private Queue _openList = new Queue(); - private Dictionary, Node> _nodeMap = new Dictionary, Node>(); - private List ids = new List(); - - public BFS(Graph graph) - { - this._graph = graph; - } - - [CanBeNull] - public Node GetNode(Predicate> predicate) - { - return _graph.GetNode(predicate); - } - - public Path FindPath(Node begin, Node end) - { - Debug.Log($"begin is {begin.index}, end is {end.index}"); - if (begin == null) - throw new NullReferenceException("begin"); - if (end == null) - throw new NullReferenceException("end"); - _openList.Clear(); - _closeList.Clear(); - _nodeMap.Clear(); - this.ids.Clear(); - - _openList.Enqueue(begin.index); - while (this._openList.Count > 0) + internal IReadOnlyList> GetNeighbours(Node node) { - var nodeIndex = this._openList.Dequeue(); - var currNode = this._graph.GetNode(nodeIndex); - if (currNode.index == end.index) - break; - _closeList.Add(currNode.index); - Search(currNode); + if (this._connection.TryGetValue(node, out var edges)) + { + return edges; + } + + throw new ArgumentException($"GetNeighbours have error ! the id is {node.index}"); + } + } + + public class BFS + { + private Graph _graph; + private List _closeList = new List(); + private Queue _openList = new Queue(); + private Dictionary, Node> _nodeMap = new Dictionary, Node>(); + private List ids = new List(); + + public BFS(Graph graph) + { + this._graph = graph; } - Path path = new Path(); - path.AddNode(new PathNode(end.index, end.data)); - this.ids.Clear(); + [CanBeNull] + public Node GetNode(Predicate> predicate) + { + return _graph.GetNode(predicate); + } - bool isTrue = true; + public Path FindPath(Node begin, Node end) + { + Debug.Log($"begin is {begin.index}, end is {end.index}"); + if (begin == null) + throw new NullReferenceException("begin"); + if (end == null) + throw new NullReferenceException("end"); + _openList.Clear(); + _closeList.Clear(); + _nodeMap.Clear(); + this.ids.Clear(); + + _openList.Enqueue(begin.index); + while (this._openList.Count > 0) + { + var nodeIndex = this._openList.Dequeue(); + var currNode = this._graph.GetNode(nodeIndex); + if (currNode.index == end.index) + break; + _closeList.Add(currNode.index); + Search(currNode); + } + + Path path = new Path(); + path.AddNode(new PathNode(end.index, end.data)); + this.ids.Clear(); + + bool isTrue = true; // UniTask.Create(async () => // { // await UniTask.Delay(5000); @@ -222,94 +222,95 @@ public class BFS // Debug.LogError("没找到路径卡死了,强制跳出的"); // } // }).Forget(); - Node node = end; - while (isTrue) - { - if (this._nodeMap.TryGetValue(node, out node)) + Node node = end; + while (isTrue) { - if (!this.ids.Contains(node.index)) + if (this._nodeMap.TryGetValue(node, out node)) { - this.ids.Add(node.index); - path.AddNode(new PathNode(node.index, node.data)); + if (!this.ids.Contains(node.index)) + { + this.ids.Add(node.index); + path.AddNode(new PathNode(node.index, node.data)); + } } - } - if (node == null || node == begin) - { + if (node == null || node == begin) + { // Debug.Log("结束了"); - break; + break; + } } + + path.Reverse(); + return path; } - path.Reverse(); - return path; - } - - private void Search(Node node) - { - var readOnlyList = this._graph.GetNeighbours(node); - foreach (var edge in readOnlyList) + private void Search(Node node) { - if (!edge.canTranslate) - continue; - Node another = edge.GetAnotherNode(node); - if (!this._nodeMap.ContainsKey(another)) + var readOnlyList = this._graph.GetNeighbours(node); + foreach (var edge in readOnlyList) { - _nodeMap[another] = node; - } - - if (!this._closeList.Contains(another.index)) - { - if (!this._openList.Contains(another.index)) + if (!edge.canTranslate) + continue; + Node another = edge.GetAnotherNode(node); + if (!this._nodeMap.ContainsKey(another)) { - _openList.Enqueue(another.index); + _nodeMap[another] = node; + } + + if (!this._closeList.Contains(another.index)) + { + if (!this._openList.Contains(another.index)) + { + _openList.Enqueue(another.index); + } } } } } -} -public class Path -{ - private readonly List> _pathNodes = new List>(); - - public void Reverse() + public class Path { - this._pathNodes.Reverse(); - } + private readonly List> _pathNodes = new List>(); - public void AddNode(PathNode node) - { - if (this._pathNodes.Contains(node)) + public void Reverse() { - throw new ArgumentException($"{node.index}"); + this._pathNodes.Reverse(); } - this._pathNodes.Add(node); - } - - public IReadOnlyList> GetNodes() - { - return this._pathNodes; - } - - public void GetDatas(IList result) - { - foreach (var pathNode in this._pathNodes) + public void AddNode(PathNode node) { - result.Add(pathNode.data); + if (this._pathNodes.Contains(node)) + { + throw new ArgumentException($"{node.index}"); + } + + this._pathNodes.Add(node); + } + + public IReadOnlyList> GetNodes() + { + return this._pathNodes; + } + + public void GetDatas(IList result) + { + foreach (var pathNode in this._pathNodes) + { + result.Add(pathNode.data); + } } } -} -public class PathNode -{ - public int index { get; private set; } - public T data { get; private set; } - - public PathNode(int index, T data) + public class PathNode { - this.index = index; - this.data = data; + public int index { get; private set; } + public T data { get; private set; } + + public PathNode(int index, T data) + { + this.index = index; + this.data = data; + } } } \ No newline at end of file diff --git a/Assets/Scripts/BFS/BFSManager.cs b/Assets/Scripts/BFS/BFSManager.cs index 4d55cdf..06a05b4 100644 --- a/Assets/Scripts/BFS/BFSManager.cs +++ b/Assets/Scripts/BFS/BFSManager.cs @@ -4,25 +4,25 @@ using Game.Player; using JetBrains.Annotations; using UnityEngine; -namespace Game.Pathfinding; - -public interface IBFSManager +namespace Game.Pathfinding { - List FindPath(Vector2 startPos, Vector2 endPos); - List FindPath(Vector2 endPos); - - Node GetNode(Vector2 position); -// void Test(Vector2 position); -} - -public class BFSManager : ManagerBase, IBFSManager -{ - private BFS bfs; - private IPlayerManager _playerManager; - - protected override void OnInit() + public interface IBFSManager { - base.OnInit(); + List FindPath(Vector2 startPos, Vector2 endPos); + List FindPath(Vector2 endPos); + + Node GetNode(Vector2 position); +// void Test(Vector2 position); + } + + public class BFSManager : ManagerBase, IBFSManager + { + private BFS bfs; + private IPlayerManager _playerManager; + + protected override void OnInit() + { + base.OnInit(); // var gameGlobalConfig = GameObject.FindObjectOfType(); // bfs = new BFS(this.CreateGraph(gameGlobalConfig)); @@ -34,42 +34,42 @@ public class BFSManager : ManagerBase, IBFSManager // Debug.Log($"Indices:{string.Join(',', findPath.GetNodes().Select(x => x.index))}"); // Debug.Log($"Positions:{string.Join(',', findPath.GetNodes().Select(x => x.data.position))}"); - this._playerManager = Game.playerManager; - } - - protected override void OnUpdate(float dateTime) - { - base.OnUpdate(dateTime); - if (this.bfs == null) - { - var gameGlobalConfig = GameObject.FindObjectOfType(); - bfs = new BFS(this.CreateGraph(gameGlobalConfig)); + this._playerManager = Game.playerManager; } - } - public List FindPath(Vector2 startPos, Vector2 endPos) - { - var beginNode = GetNode(bfs, startPos); - var endNode = GetNode(bfs, endPos); - var findPath = bfs.FindPath(beginNode, endNode); - var wayPoints = new List(); - findPath.GetDatas(wayPoints); - return wayPoints; - } + protected override void OnUpdate(float dateTime) + { + base.OnUpdate(dateTime); + if (this.bfs == null) + { + var gameGlobalConfig = GameObject.FindObjectOfType(); + bfs = new BFS(this.CreateGraph(gameGlobalConfig)); + } + } - public List FindPath(Vector2 endPos) - { - var player = this._playerManager.currentPlayer; - var pos = player.self.transform.position; - var startPos = new Vector2(pos.x, pos.y); - var beginNode = GetNode(bfs, startPos); - var endNode = GetNode(bfs, endPos); + public List FindPath(Vector2 startPos, Vector2 endPos) + { + var beginNode = GetNode(bfs, startPos); + var endNode = GetNode(bfs, endPos); + var findPath = bfs.FindPath(beginNode, endNode); + var wayPoints = new List(); + findPath.GetDatas(wayPoints); + return wayPoints; + } + + public List FindPath(Vector2 endPos) + { + var player = this._playerManager.currentPlayer; + var pos = player.self.transform.position; + var startPos = new Vector2(pos.x, pos.y); + var beginNode = GetNode(bfs, startPos); + var endNode = GetNode(bfs, endPos); // UnityEngine.Debug.Log($"frome {beginNode.index} to {endNode.index} "); - var findPath = bfs.FindPath(beginNode, endNode); - var wayPoints = new List(); - findPath.GetDatas(wayPoints); - return wayPoints; - } + var findPath = bfs.FindPath(beginNode, endNode); + var wayPoints = new List(); + findPath.GetDatas(wayPoints); + return wayPoints; + } // public void Test(Vector2 endPos) // { @@ -81,48 +81,49 @@ public class BFSManager : ManagerBase, IBFSManager //// UnityEngine.Debug.Log($"frome {beginNode.index} to {endNode.index} "); // } - [CanBeNull] - public Node GetNode(Vector2 position) - { - float distance = float.MaxValue; - Node targetStartNode = null; - bfs.GetNode(node => + [CanBeNull] + public Node GetNode(Vector2 position) { - var magnitude = ((Vector2)node.data.position - position).magnitude; - if (magnitude < distance) + float distance = float.MaxValue; + Node targetStartNode = null; + bfs.GetNode(node => { - distance = magnitude; - targetStartNode = node; - } + var magnitude = ((Vector2)node.data.position - position).magnitude; + if (magnitude < distance) + { + distance = magnitude; + targetStartNode = node; + } - return false; - }); - return targetStartNode; - } + return false; + }); + return targetStartNode; + } - [CanBeNull] - private static Node GetNode(BFS bfs, Vector2 position) - { - float distance = float.MaxValue; - Node targetStartNode = null; - bfs.GetNode(node => + [CanBeNull] + private static Node GetNode(BFS bfs, Vector2 position) { - var magnitude = ((Vector2)node.data.position - position).magnitude; - if (magnitude < distance) + float distance = float.MaxValue; + Node targetStartNode = null; + bfs.GetNode(node => { - distance = magnitude; - targetStartNode = node; - } + var magnitude = ((Vector2)node.data.position - position).magnitude; + if (magnitude < distance) + { + distance = magnitude; + targetStartNode = node; + } - return false; - }); - return targetStartNode; - } + return false; + }); + return targetStartNode; + } - private Graph CreateGraph(GameGlobalConfig gameGlobalConfig) - { - var graph = new WayPointGraph(); - graph.Initialize(gameGlobalConfig.nodeMaps); - return graph; + private Graph CreateGraph(GameGlobalConfig gameGlobalConfig) + { + var graph = new WayPointGraph(); + graph.Initialize(gameGlobalConfig.nodeMaps); + return graph; + } } } \ No newline at end of file diff --git a/Assets/Scripts/BFS/WayPoint.cs b/Assets/Scripts/BFS/WayPoint.cs index 9942061..5d849b6 100644 --- a/Assets/Scripts/BFS/WayPoint.cs +++ b/Assets/Scripts/BFS/WayPoint.cs @@ -1,13 +1,14 @@ using UnityEngine; -namespace Game.Pathfinding; - -public class WayPoint +namespace Game.Pathfinding { - public Vector3 position { get; private set; } - - public WayPoint(Vector3 position) + public class WayPoint { - this.position = position; + public Vector3 position { get; private set; } + + public WayPoint(Vector3 position) + { + this.position = position; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Boss/BossInfo.cs b/Assets/Scripts/Boss/BossInfo.cs index f730b90..5b1c8e0 100644 --- a/Assets/Scripts/Boss/BossInfo.cs +++ b/Assets/Scripts/Boss/BossInfo.cs @@ -8,31 +8,31 @@ using Game.Spine; using Sirenix.OdinInspector; using UnityEngine; -namespace Game.Boss; - -[RequireComponent(typeof(SpineAnimator))] -public class BossInfo : MonoBehaviour +namespace Game.Boss { - [SerializeField] [ReadOnly] private IBoss _boss; - [SerializeField] private float speed = 1f; - private static readonly int _kill = Animator.StringToHash("Kill"); - [SerializeField] private Vector2 _birthPoint; - - private SpineAnimator _animator; - - public Vector2 birthPoint => this._birthPoint; - - private void Awake() + [RequireComponent(typeof(SpineAnimator))] + public class BossInfo : MonoBehaviour { - this._animator = this.GetComponent(); - } + [SerializeField] [ReadOnly] private IBoss _boss; + [SerializeField] private float speed = 1f; + private static readonly int _kill = Animator.StringToHash("Kill"); + [SerializeField] private Vector2 _birthPoint; - public void SetBoss(IBoss boss) - { - this._boss = boss; - this.gameObject.name = this._boss.name; - transform.position = _birthPoint; - } + private SpineAnimator _animator; + + public Vector2 birthPoint => this._birthPoint; + + private void Awake() + { + this._animator = this.GetComponent(); + } + + public void SetBoss(IBoss boss) + { + this._boss = boss; + this.gameObject.name = this._boss.name; + transform.position = _birthPoint; + } // public async UniTask MoveAsync(List wayPoint, Vector2 endPos, CancellationToken token) // { @@ -48,61 +48,62 @@ public class BossInfo : MonoBehaviour // return true; // } - public async UniTask MoveAsync(List wayPoint, CancellationToken token) - { - this._animator.PlayAni("walk", true); - // enter this room - foreach (var point in wayPoint) + public async UniTask MoveAsync(List wayPoint, CancellationToken token) { - await this.MoveAsync(point.position, token); - } + this._animator.PlayAni("walk", true); + // enter this room + foreach (var point in wayPoint) + { + await this.MoveAsync(point.position, token); + } - this._animator.PlayAni("idle", true); + this._animator.PlayAni("idle", true); - // enter room a point + // enter room a point // await this.MoveAsync(endPos, token); - return true; - } + return true; + } - async UniTask MoveAsync(Vector2 endPos, CancellationToken token) - { - var position = this.transform.position; - var distance = Vector3.Distance(position, endPos); - var time = distance / this.speed; - - CheckIsNeedTurn(position, endPos); + async UniTask MoveAsync(Vector2 endPos, CancellationToken token) + { + var position = this.transform.position; + var distance = Vector3.Distance(position, endPos); + var time = distance / this.speed; - this.transform.DOMove(endPos, time).SetEase(Ease.Linear); - float delayTimeSpan = time * 1000; - await UniTask.Delay((int)delayTimeSpan); // (int)delayTimeSpan + CheckIsNeedTurn(position, endPos); + + this.transform.DOMove(endPos, time).SetEase(Ease.Linear); + float delayTimeSpan = time * 1000; + await UniTask.Delay((int)delayTimeSpan); // (int)delayTimeSpan // Debug.Log($"time is {time}, await time is {delayTimeSpan}"); - } - - public async UniTask Kill(CancellationToken token) - { - this._animator.PlayAni("atk"); - await UniTask.Delay(500); - this._animator.PlayAni("idle", true); - } - - public void Dispose() - { - this._animator = null; - this._boss = null; - GameObject.DestroyImmediate(this.gameObject); - } - - void CheckIsNeedTurn(Vector2 str, Vector2 end) - { - if (str.x > end.x) - { - transform.localEulerAngles = new Vector3(0, 180, 0); } - else if (str.x < end.x) + + public async UniTask Kill(CancellationToken token) { - transform.localEulerAngles = new Vector3(0, 0, 0); + this._animator.PlayAni("atk"); + await UniTask.Delay(500); + this._animator.PlayAni("idle", true); + } + + public void Dispose() + { + this._animator = null; + this._boss = null; + GameObject.DestroyImmediate(this.gameObject); + } + + void CheckIsNeedTurn(Vector2 str, Vector2 end) + { + if (str.x > end.x) + { + transform.localEulerAngles = new Vector3(0, 180, 0); + } + else if (str.x < end.x) + { + transform.localEulerAngles = new Vector3(0, 0, 0); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/Boss/IBoss.cs b/Assets/Scripts/Boss/IBoss.cs index 96c674d..dda52d9 100644 --- a/Assets/Scripts/Boss/IBoss.cs +++ b/Assets/Scripts/Boss/IBoss.cs @@ -6,87 +6,88 @@ using Game.Player; using Game.Room; using UnityEngine; -namespace Game.Boss; - -public interface IBoss +namespace Game.Boss { - string name { get; } - GameObject self { get; } - BossData data { get; } - BossInfo info { get; } - IRoom room { get; } - bool isMoving { get; } - void SetGameObject(GameObject gameObject, IRoom room); + public interface IBoss + { + string name { get; } + GameObject self { get; } + BossData data { get; } + BossInfo info { get; } + IRoom room { get; } + bool isMoving { get; } + void SetGameObject(GameObject gameObject, IRoom room); - UniTask WaitMoveRoomAndKillAsync(CancellationToken token); + UniTask WaitMoveRoomAndKillAsync(CancellationToken token); // UniTask MoveAsync(List wayPoint, CancellationToken token); - void Init(); - void Dispose(); -} - -public class BossData -{ -} - -public class Boss : IBoss -{ - private string _name; - private GameObject _self; - private IRoom _room; - private bool _isMoving; - private BossInfo _info; - - public string name => this._name; - - public GameObject self => this._self; - - public BossData data { get; } - - public BossInfo info => this._info; - - public IRoom room => this._room; - - public bool isMoving => this._isMoving; - - public void SetGameObject(GameObject gameObject, IRoom room) - { - this._self = gameObject; - this._name = room.roomName; - this._room = room; - this._info = gameObject.GetComponent(); - this._info.SetBoss(this); - this._isMoving = true; + void Init(); + void Dispose(); } - public async UniTask WaitMoveRoomAndKillAsync(CancellationToken token) + public class BossData { - var wayPoints = Game.bfsManager.FindPath(this._info.birthPoint, _room.roomInfo.room_Center); - await this.MoveAsync(wayPoints, token); - Debug.Log("Move finish !!!"); - await this._info.Kill(token); - return 0; } - private async UniTask MoveAsync(List wayPoint, CancellationToken token) + public class Boss : IBoss { - if (!this._isMoving) return false; + private string _name; + private GameObject _self; + private IRoom _room; + private bool _isMoving; + private BossInfo _info; - _isMoving = false; + public string name => this._name; + + public GameObject self => this._self; + + public BossData data { get; } + + public BossInfo info => this._info; + + public IRoom room => this._room; + + public bool isMoving => this._isMoving; + + public void SetGameObject(GameObject gameObject, IRoom room) + { + this._self = gameObject; + this._name = room.roomName; + this._room = room; + this._info = gameObject.GetComponent(); + this._info.SetBoss(this); + this._isMoving = true; + } + + public async UniTask WaitMoveRoomAndKillAsync(CancellationToken token) + { + var wayPoints = Game.bfsManager.FindPath(this._info.birthPoint, _room.roomInfo.room_Center); + await this.MoveAsync(wayPoints, token); + Debug.Log("Move finish !!!"); + await this._info.Kill(token); + return 0; + } + + private async UniTask MoveAsync(List wayPoint, CancellationToken token) + { + if (!this._isMoving) return false; + + _isMoving = false; // var endPos = this._room.roomInfo.GetJoinPosition(); // await this._info.MoveAsync(wayPoint, endPos, token); - await this._info.MoveAsync(wayPoint, token); - this._isMoving = true; - return true; - } + await this._info.MoveAsync(wayPoint, token); + this._isMoving = true; + return true; + } - public virtual void Init() - { - } + public virtual void Init() + { + } - public virtual void Dispose() - { - this._info.Dispose(); + public virtual void Dispose() + { + this._info.Dispose(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Boss/IBossManager.cs b/Assets/Scripts/Boss/IBossManager.cs index 61b72f0..d303033 100644 --- a/Assets/Scripts/Boss/IBossManager.cs +++ b/Assets/Scripts/Boss/IBossManager.cs @@ -4,53 +4,54 @@ using Cysharp.Threading.Tasks; using Game.Room; using UnityEngine; -namespace Game.Boss; - -public interface IBossManager +namespace Game.Boss { - IReadOnlyList bosses { get; } - - UniTask MoveToKillPlayerAsync(IReadOnlyList rooms, CancellationToken token); - void DeleteBoss(); -} - -public class BossManager : ManagerBase, IBossManager -{ - private List _bosses; - - public IReadOnlyList bosses => this._bosses; - - public async UniTask MoveToKillPlayerAsync(IReadOnlyList rooms, CancellationToken token) + public interface IBossManager { - this._bosses = new List(); - foreach (var room in rooms) - { - IBoss boss = new Boss(); - var gameObject = Game.resourceManager.LoadGameObjectSync("boss1"); - boss.SetGameObject(gameObject, room); - boss.Init(); - _bosses.Add(boss); - } + IReadOnlyList bosses { get; } - List uniTasks = new List(); - foreach (var boss in this._bosses) - { - var uniTask = boss.WaitMoveRoomAndKillAsync(token); - uniTasks.Add(uniTask); - await UniTask.Delay(100); - } - - await UniTask.WhenAll(uniTasks); + UniTask MoveToKillPlayerAsync(IReadOnlyList rooms, CancellationToken token); + void DeleteBoss(); } - - public void DeleteBoss() + public class BossManager : ManagerBase, IBossManager { - foreach (var boss in this._bosses) + private List _bosses; + + public IReadOnlyList bosses => this._bosses; + + public async UniTask MoveToKillPlayerAsync(IReadOnlyList rooms, CancellationToken token) { - boss.Dispose(); + this._bosses = new List(); + foreach (var room in rooms) + { + IBoss boss = new Boss(); + var gameObject = Game.resourceManager.LoadGameObjectSync("boss1"); + boss.SetGameObject(gameObject, room); + boss.Init(); + _bosses.Add(boss); + } + + List uniTasks = new List(); + foreach (var boss in this._bosses) + { + var uniTask = boss.WaitMoveRoomAndKillAsync(token); + uniTasks.Add(uniTask); + await UniTask.Delay(100); + } + + await UniTask.WhenAll(uniTasks); } - this._bosses.Clear(); + + public void DeleteBoss() + { + foreach (var boss in this._bosses) + { + boss.Dispose(); + } + + this._bosses.Clear(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/BossStartMoveEventArgs.cs b/Assets/Scripts/Event/Args/BossStartMoveEventArgs.cs index 0d70355..3e5f9c5 100644 --- a/Assets/Scripts/Event/Args/BossStartMoveEventArgs.cs +++ b/Assets/Scripts/Event/Args/BossStartMoveEventArgs.cs @@ -1,17 +1,18 @@ -namespace Game; - -/// -/// boss开始行动了 -/// -public class BossStartMoveEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(BossStartMoveEventArgs).GetHashCode(); - public override int Id => EventId; - - public bool isMoveing { get; } - - public BossStartMoveEventArgs(bool isMoveing) + /// + /// boss开始行动了 + /// + public class BossStartMoveEventArgs : GameEventArgs { - this.isMoveing = isMoveing; + public static readonly int EventId = typeof(BossStartMoveEventArgs).GetHashCode(); + public override int Id => EventId; + + public bool isMoveing { get; } + + public BossStartMoveEventArgs(bool isMoveing) + { + this.isMoveing = isMoveing; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/InitCurrentPlayerDataEventArgs.cs b/Assets/Scripts/Event/Args/InitCurrentPlayerDataEventArgs.cs index b300c04..96a7d7c 100644 --- a/Assets/Scripts/Event/Args/InitCurrentPlayerDataEventArgs.cs +++ b/Assets/Scripts/Event/Args/InitCurrentPlayerDataEventArgs.cs @@ -1,16 +1,17 @@ using Game.Player; -namespace Game; - -public class InitCurrentPlayerDataEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(InitCurrentPlayerDataEventArgs).GetHashCode(); - public override int Id => EventId; - - public IPlayer player { get; } - - public InitCurrentPlayerDataEventArgs(IPlayer player) + public class InitCurrentPlayerDataEventArgs : GameEventArgs { - this.player = player; + public static readonly int EventId = typeof(InitCurrentPlayerDataEventArgs).GetHashCode(); + public override int Id => EventId; + + public IPlayer player { get; } + + public InitCurrentPlayerDataEventArgs(IPlayer player) + { + this.player = player; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/InputNameFinishEventArgs.cs b/Assets/Scripts/Event/Args/InputNameFinishEventArgs.cs index 59b56b1..a936fac 100644 --- a/Assets/Scripts/Event/Args/InputNameFinishEventArgs.cs +++ b/Assets/Scripts/Event/Args/InputNameFinishEventArgs.cs @@ -1,14 +1,15 @@ -namespace Game; - -public class InputNameFinishEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(InputNameFinishEventArgs).GetHashCode(); - public override int Id => EventId; - - public string playerName { get; } - - public InputNameFinishEventArgs(string name) + public class InputNameFinishEventArgs : GameEventArgs { - this.playerName = name; + public static readonly int EventId = typeof(InputNameFinishEventArgs).GetHashCode(); + public override int Id => EventId; + + public string playerName { get; } + + public InputNameFinishEventArgs(string name) + { + this.playerName = name; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/InputObjectFinishEventArgs.cs b/Assets/Scripts/Event/Args/InputObjectFinishEventArgs.cs index 16843db..06fddc1 100644 --- a/Assets/Scripts/Event/Args/InputObjectFinishEventArgs.cs +++ b/Assets/Scripts/Event/Args/InputObjectFinishEventArgs.cs @@ -1,14 +1,15 @@ -namespace Game; - -public class InputObjectFinishEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(InputObjectFinishEventArgs).GetHashCode(); - public override int Id => EventId; - - public object data { get; } - - public InputObjectFinishEventArgs(object data) + public class InputObjectFinishEventArgs : GameEventArgs { - this.data = data; + public static readonly int EventId = typeof(InputObjectFinishEventArgs).GetHashCode(); + public override int Id => EventId; + + public object data { get; } + + public InputObjectFinishEventArgs(object data) + { + this.data = data; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/JinBeiSettlementEventArgs.cs b/Assets/Scripts/Event/Args/JinBeiSettlementEventArgs.cs index e3349ec..46c8b5a 100644 --- a/Assets/Scripts/Event/Args/JinBeiSettlementEventArgs.cs +++ b/Assets/Scripts/Event/Args/JinBeiSettlementEventArgs.cs @@ -1,19 +1,20 @@ using System.Collections.Generic; using Game.Player; -namespace Game; - -public class JinBeiSettlementEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(JinBeiSettlementEventArgs).GetHashCode(); - public override int Id => EventId; - - public List players { get; } - public float jinbei { get; } - - public JinBeiSettlementEventArgs(List players, float jinbei) + public class JinBeiSettlementEventArgs : GameEventArgs { - this.players = players; - this.jinbei = jinbei; + public static readonly int EventId = typeof(JinBeiSettlementEventArgs).GetHashCode(); + public override int Id => EventId; + + public List players { get; } + public float jinbei { get; } + + public JinBeiSettlementEventArgs(List players, float jinbei) + { + this.players = players; + this.jinbei = jinbei; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToMainUIEventArgs.cs b/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToMainUIEventArgs.cs index 350636c..af2160b 100644 --- a/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToMainUIEventArgs.cs +++ b/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToMainUIEventArgs.cs @@ -1,16 +1,17 @@ using Game.Player; -namespace Game; - -public class PlayerJinBeiChange_ToMainUIEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(PlayerJinBeiChange_ToMainUIEventArgs).GetHashCode(); - public override int Id => EventId; - - public IPlayer player { get; } - - public PlayerJinBeiChange_ToMainUIEventArgs(IPlayer player) + public class PlayerJinBeiChange_ToMainUIEventArgs : GameEventArgs { - this.player = player; + public static readonly int EventId = typeof(PlayerJinBeiChange_ToMainUIEventArgs).GetHashCode(); + public override int Id => EventId; + + public IPlayer player { get; } + + public PlayerJinBeiChange_ToMainUIEventArgs(IPlayer player) + { + this.player = player; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToPlayerEventArgs.cs b/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToPlayerEventArgs.cs index 2b6fd47..d811049 100644 --- a/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToPlayerEventArgs.cs +++ b/Assets/Scripts/Event/Args/PlayerJinBeiChange_ToPlayerEventArgs.cs @@ -2,21 +2,22 @@ using Game.Player; using Game.Room; -namespace Game; - -public class PlayerJinBeiChange_ToPlayerEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(PlayerJinBeiChange_ToPlayerEventArgs).GetHashCode(); - public override int Id => EventId; - - public IPlayer player { get; } - public float jinbei { get; } - public Action callback { get; } - - public PlayerJinBeiChange_ToPlayerEventArgs(IPlayer player, float jinbei, Action callback) + public class PlayerJinBeiChange_ToPlayerEventArgs : GameEventArgs { - this.player = player; - this.jinbei = jinbei; - this.callback = callback; + public static readonly int EventId = typeof(PlayerJinBeiChange_ToPlayerEventArgs).GetHashCode(); + public override int Id => EventId; + + public IPlayer player { get; } + public float jinbei { get; } + public Action callback { get; } + + public PlayerJinBeiChange_ToPlayerEventArgs(IPlayer player, float jinbei, Action callback) + { + this.player = player; + this.jinbei = jinbei; + this.callback = callback; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/PlayerMoveToRoomEventArgs.cs b/Assets/Scripts/Event/Args/PlayerMoveToRoomEventArgs.cs index 132097d..1c18822 100644 --- a/Assets/Scripts/Event/Args/PlayerMoveToRoomEventArgs.cs +++ b/Assets/Scripts/Event/Args/PlayerMoveToRoomEventArgs.cs @@ -1,19 +1,20 @@ using Game.Player; using Game.Room; -namespace Game; - -public class PlayerMoveToRoomEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(PlayerMoveToRoomEventArgs).GetHashCode(); - public override int Id => EventId; - - public IPlayer player { get; } - public IRoom room { get; } - - public PlayerMoveToRoomEventArgs(IPlayer player, IRoom room) + public class PlayerMoveToRoomEventArgs : GameEventArgs { - this.player = player; - this.room = room; + public static readonly int EventId = typeof(PlayerMoveToRoomEventArgs).GetHashCode(); + public override int Id => EventId; + + public IPlayer player { get; } + public IRoom room { get; } + + public PlayerMoveToRoomEventArgs(IPlayer player, IRoom room) + { + this.player = player; + this.room = room; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/PlayerUpdateDataEventArgs.cs b/Assets/Scripts/Event/Args/PlayerUpdateDataEventArgs.cs index 2cf2b5f..d1391eb 100644 --- a/Assets/Scripts/Event/Args/PlayerUpdateDataEventArgs.cs +++ b/Assets/Scripts/Event/Args/PlayerUpdateDataEventArgs.cs @@ -1,16 +1,17 @@ using Game.Player; -namespace Game; - -public class PlayerUpdateDataEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(PlayerUpdateDataEventArgs).GetHashCode(); - public override int Id => EventId; - - public IPlayer player { get; } - - public PlayerUpdateDataEventArgs(IPlayer player) + public class PlayerUpdateDataEventArgs : GameEventArgs { - this.player = player; + public static readonly int EventId = typeof(PlayerUpdateDataEventArgs).GetHashCode(); + public override int Id => EventId; + + public IPlayer player { get; } + + public PlayerUpdateDataEventArgs(IPlayer player) + { + this.player = player; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/ReturnPlayerJinBeiEventArgs.cs b/Assets/Scripts/Event/Args/ReturnPlayerJinBeiEventArgs.cs index abaa636..dec9309 100644 --- a/Assets/Scripts/Event/Args/ReturnPlayerJinBeiEventArgs.cs +++ b/Assets/Scripts/Event/Args/ReturnPlayerJinBeiEventArgs.cs @@ -1,18 +1,19 @@ using Game.Player; -namespace Game; - -public class ReturnPlayerJinBeiEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(ReturnPlayerJinBeiEventArgs).GetHashCode(); - public override int Id => EventId; - - public IPlayer player { get; } - public float jinBei { get; } - - public ReturnPlayerJinBeiEventArgs(IPlayer player, float jinBei) + public class ReturnPlayerJinBeiEventArgs : GameEventArgs { - this.player = player; - this.jinBei = jinBei; + public static readonly int EventId = typeof(ReturnPlayerJinBeiEventArgs).GetHashCode(); + public override int Id => EventId; + + public IPlayer player { get; } + public float jinBei { get; } + + public ReturnPlayerJinBeiEventArgs(IPlayer player, float jinBei) + { + this.player = player; + this.jinBei = jinBei; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Event/Args/RoomJinBeiChangeEventArgs.cs b/Assets/Scripts/Event/Args/RoomJinBeiChangeEventArgs.cs index f606097..25bb086 100644 --- a/Assets/Scripts/Event/Args/RoomJinBeiChangeEventArgs.cs +++ b/Assets/Scripts/Event/Args/RoomJinBeiChangeEventArgs.cs @@ -1,21 +1,22 @@ using Game.Player; using Game.Room; -namespace Game; - -public class RoomJinBeiChangeEventArgs : GameEventArgs +namespace Game { - public static readonly int EventId = typeof(RoomJinBeiChangeEventArgs).GetHashCode(); - public override int Id => EventId; - - public IRoom room { get; } - public IPlayer player { get; } - public float jinBei { get; } - - public RoomJinBeiChangeEventArgs(IRoom room, IPlayer player, float jinBei) + public class RoomJinBeiChangeEventArgs : GameEventArgs { - this.room = room; - this.player = player; - this.jinBei = jinBei; + public static readonly int EventId = typeof(RoomJinBeiChangeEventArgs).GetHashCode(); + public override int Id => EventId; + + public IRoom room { get; } + public IPlayer player { get; } + public float jinBei { get; } + + public RoomJinBeiChangeEventArgs(IRoom room, IPlayer player, float jinBei) + { + this.room = room; + this.player = player; + this.jinBei = jinBei; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Log/Log.cs b/Assets/Scripts/Log/Log.cs index efda5ab..b267752 100644 --- a/Assets/Scripts/Log/Log.cs +++ b/Assets/Scripts/Log/Log.cs @@ -1,22 +1,23 @@ -namespace Game.Log; - -/// -/// 便于真机上取消log -/// -public static class Log +namespace Game.Log { - public static void Debug(object message) + /// + /// 便于真机上取消log + /// + public static class Log { - UnityEngine.Debug.Log(message); - } + public static void Debug(object message) + { + UnityEngine.Debug.Log(message); + } - public static void LogWarning(object message) - { - UnityEngine.Debug.LogWarning(message); - } + public static void LogWarning(object message) + { + UnityEngine.Debug.LogWarning(message); + } - public static void LogError(object message) - { - UnityEngine.Debug.LogError(message); + public static void LogError(object message) + { + UnityEngine.Debug.LogError(message); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Player/Player.cs b/Assets/Scripts/Player/Player.cs index 17155fe..9c3c8a6 100644 --- a/Assets/Scripts/Player/Player.cs +++ b/Assets/Scripts/Player/Player.cs @@ -5,120 +5,121 @@ using Game.Pathfinding; using Game.Room; using UnityEngine; -namespace Game.Player; - -public interface IPlayer +namespace Game.Player { - string playerName { get; } - GameObject self { get; } - PlayerData playerData { get; } - IRoom room { get; } - bool isMoving { get; } - void SetGameObject(GameObject gameObject, string name, float jinbei); - void SetRoom(IRoom roo); - UniTask WaitMoveRoomAsync(IRoom roo, CancellationToken token); - UniTask MoveAsync(List wayPoint, CancellationToken token); - void Init(); - void Dispose(); -} - -[System.Serializable] -internal class Player : IPlayer -{ - private GameObject _self; - private PlayerData _playerData; - private IRoom _room; - PlayerInfo playerInfo; - private bool _isMoving; - - public string playerName => this._playerData.playerName; - - public GameObject self => this._self; - - public PlayerData playerData => this._playerData; - - public IRoom room => this._room; - - public bool isMoving => this._isMoving; - - - public void SetGameObject(GameObject gameObject, string name, float jinbei) + public interface IPlayer { - this._self = gameObject; - this._playerData = new PlayerData(name, jinbei, 100); - - // view - playerInfo = this._self.GetComponent(); - playerInfo.SetPlayer(this); - this._isMoving = true; + string playerName { get; } + GameObject self { get; } + PlayerData playerData { get; } + IRoom room { get; } + bool isMoving { get; } + void SetGameObject(GameObject gameObject, string name, float jinbei); + void SetRoom(IRoom roo); + UniTask WaitMoveRoomAsync(IRoom roo, CancellationToken token); + UniTask MoveAsync(List wayPoint, CancellationToken token); + void Init(); + void Dispose(); } - public void SetRoom(IRoom roo) + [System.Serializable] + internal class Player : IPlayer { - this._room?.Quit(this); - this._room = roo; -// EventManager.Instance.FireNow(this, new PlayerMoveToRoomEventArgs(this, this._room)); - } + private GameObject _self; + private PlayerData _playerData; + private IRoom _room; + PlayerInfo playerInfo; + private bool _isMoving; - public async UniTask WaitMoveRoomAsync(IRoom roo, CancellationToken token) - { - this._room?.Quit(this); - this._room = roo; + public string playerName => this._playerData.playerName; + + public GameObject self => this._self; + + public PlayerData playerData => this._playerData; + + public IRoom room => this._room; + + public bool isMoving => this._isMoving; + + + public void SetGameObject(GameObject gameObject, string name, float jinbei) + { + this._self = gameObject; + this._playerData = new PlayerData(name, jinbei, 100); + + // view + playerInfo = this._self.GetComponent(); + playerInfo.SetPlayer(this); + this._isMoving = true; + } + + public void SetRoom(IRoom roo) + { + this._room?.Quit(this); + this._room = roo; +// EventManager.Instance.FireNow(this, new PlayerMoveToRoomEventArgs(this, this._room)); + } + + public async UniTask WaitMoveRoomAsync(IRoom roo, CancellationToken token) + { + this._room?.Quit(this); + this._room = roo; // EventManager.Instance.FireNow(this, new PlayerMoveToRoomEventArgs(this, this._room)); - var wayPoints = Game.bfsManager.FindPath(_room.roomInfo.room_Center); + var wayPoints = Game.bfsManager.FindPath(_room.roomInfo.room_Center); - await UniTask.Yield(); - var moveAsync = await this.MoveAsync(wayPoints, token); + await UniTask.Yield(); + var moveAsync = await this.MoveAsync(wayPoints, token); // Debug.Log("Move finish !!!"); - return moveAsync; - } - - public async UniTask MoveAsync(List wayPoint, CancellationToken token) - { - if (!this._isMoving) return false; - - _isMoving = false; - var endPos = this._room.roomInfo.GetJoinPosition(); - - await playerInfo.MoveAsync(wayPoint, endPos, token); - this._isMoving = true; - return true; - } - - public virtual void Init() - { - EventManager.Instance.Subscribe(PlayerJinBeiChange_ToPlayerEventArgs.EventId, PlayerJinbeiChangeEvent); - EventManager.Instance.Subscribe(ReturnPlayerJinBeiEventArgs.EventId, ReturnPlayerJinBeiEvent); - } - - public virtual void Dispose() - { - EventManager.Instance.Unsubscribe(PlayerJinBeiChange_ToPlayerEventArgs.EventId, PlayerJinbeiChangeEvent); - EventManager.Instance.Unsubscribe(ReturnPlayerJinBeiEventArgs.EventId, ReturnPlayerJinBeiEvent); - GameObject.DestroyImmediate(this.self); - } - - private void ReturnPlayerJinBeiEvent(object sender, GameEventArgs e) - { - var args = e as ReturnPlayerJinBeiEventArgs; - if (args.player == this) - { - this._playerData.ReturnJinBei(args.jinBei); - EventManager.Instance.FireNow(this, new PlayerJinBeiChange_ToMainUIEventArgs(this)); + return moveAsync; } - } - private void PlayerJinbeiChangeEvent(object sender, GameEventArgs e) - { - var args = e as PlayerJinBeiChange_ToPlayerEventArgs; - var jinbei = this._playerData.jinbei - args.jinbei; - if (jinbei >= 0) + public async UniTask MoveAsync(List wayPoint, CancellationToken token) { - this._playerData.jinbei = jinbei; - args.callback?.Invoke(true); + if (!this._isMoving) return false; + + _isMoving = false; + var endPos = this._room.roomInfo.GetJoinPosition(); + + await playerInfo.MoveAsync(wayPoint, endPos, token); + this._isMoving = true; + return true; + } + + public virtual void Init() + { + EventManager.Instance.Subscribe(PlayerJinBeiChange_ToPlayerEventArgs.EventId, PlayerJinbeiChangeEvent); + EventManager.Instance.Subscribe(ReturnPlayerJinBeiEventArgs.EventId, ReturnPlayerJinBeiEvent); + } + + public virtual void Dispose() + { + EventManager.Instance.Unsubscribe(PlayerJinBeiChange_ToPlayerEventArgs.EventId, PlayerJinbeiChangeEvent); + EventManager.Instance.Unsubscribe(ReturnPlayerJinBeiEventArgs.EventId, ReturnPlayerJinBeiEvent); + GameObject.DestroyImmediate(this.self); + } + + private void ReturnPlayerJinBeiEvent(object sender, GameEventArgs e) + { + var args = e as ReturnPlayerJinBeiEventArgs; + if (args.player == this) + { + this._playerData.ReturnJinBei(args.jinBei); + EventManager.Instance.FireNow(this, new PlayerJinBeiChange_ToMainUIEventArgs(this)); + } + } + + private void PlayerJinbeiChangeEvent(object sender, GameEventArgs e) + { + var args = e as PlayerJinBeiChange_ToPlayerEventArgs; + var jinbei = this._playerData.jinbei - args.jinbei; + if (jinbei >= 0) + { + this._playerData.jinbei = jinbei; + args.callback?.Invoke(true); + } + else + args.callback?.Invoke(false); } - else - args.callback?.Invoke(false); } } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerManager.cs b/Assets/Scripts/Player/PlayerManager.cs index 0814940..bdcc867 100644 --- a/Assets/Scripts/Player/PlayerManager.cs +++ b/Assets/Scripts/Player/PlayerManager.cs @@ -1,60 +1,61 @@ using System.Collections.Generic; -namespace Game.Player; - -public class PlayerManager : ManagerBase, IPlayerManager +namespace Game.Player { - private Dictionary _players = new Dictionary(); - private IPlayer _currentPlayer; - - public IPlayer currentPlayer => this._currentPlayer; - - protected override void OnInit() + public class PlayerManager : ManagerBase, IPlayerManager { - base.OnInit(); - _players = new Dictionary(); - this._currentPlayer = null; - } + private Dictionary _players = new Dictionary(); + private IPlayer _currentPlayer; - public void SetCurrentPlayer(IPlayer player) - { - this._currentPlayer ??= player; - } + public IPlayer currentPlayer => this._currentPlayer; - public IPlayer CreatePlayer(string playerName, string assetName, float jinbei) - { - var gameObject = Game.resourceManager.LoadGameObjectSync(assetName); - IPlayer player = new Player(); - player.SetGameObject(gameObject, playerName, jinbei); - this._players.Add(playerName, player); - player.Init(); - return player; - } - - public IPlayer GetPlayer(string playerName) - { - return this._players.GetValueOrDefault(playerName); - } - - public void DeletePlayer(string playerName) - { - if (this._players.TryGetValue(playerName, out var player)) + protected override void OnInit() { - player.Dispose(); + base.OnInit(); + _players = new Dictionary(); + this._currentPlayer = null; + } + + public void SetCurrentPlayer(IPlayer player) + { + this._currentPlayer ??= player; + } + + public IPlayer CreatePlayer(string playerName, string assetName, float jinbei) + { + var gameObject = Game.resourceManager.LoadGameObjectSync(assetName); + IPlayer player = new Player(); + player.SetGameObject(gameObject, playerName, jinbei); + this._players.Add(playerName, player); + player.Init(); + return player; + } + + public IPlayer GetPlayer(string playerName) + { + return this._players.GetValueOrDefault(playerName); + } + + public void DeletePlayer(string playerName) + { + if (this._players.TryGetValue(playerName, out var player)) + { + player.Dispose(); + } } } -} -public interface IPlayerManager -{ - IPlayer currentPlayer { get; } + public interface IPlayerManager + { + IPlayer currentPlayer { get; } - void SetCurrentPlayer(IPlayer player); + void SetCurrentPlayer(IPlayer player); - // - IPlayer CreatePlayer(string playerName, string assetName, float jinbei); + // + IPlayer CreatePlayer(string playerName, string assetName, float jinbei); - IPlayer GetPlayer(string playerName); + IPlayer GetPlayer(string playerName); - void DeletePlayer(string playerName); + void DeletePlayer(string playerName); + } } \ No newline at end of file diff --git a/Assets/Scripts/Procedure/Logic/EnterGameSceneProcedure.cs b/Assets/Scripts/Procedure/Logic/EnterGameSceneProcedure.cs index 2163a23..15d9c8d 100644 --- a/Assets/Scripts/Procedure/Logic/EnterGameSceneProcedure.cs +++ b/Assets/Scripts/Procedure/Logic/EnterGameSceneProcedure.cs @@ -2,40 +2,41 @@ using Cysharp.Threading.Tasks; using Game.Room; -namespace Game; - -[Procedure(ProcedureType.EnterGameSceneProcedure)] -class EnterGameSceneProcedure : ProcedureBase +namespace Game { - public override void OnEnter() + [Procedure(ProcedureType.EnterGameSceneProcedure)] + class EnterGameSceneProcedure : ProcedureBase { - base.OnEnter(); + public override void OnEnter() + { + base.OnEnter(); - var room = Game.roomManager.CreateRoom(RoomType.出生点); - Game.roomManager.CreateRoom(RoomType.伏龙阁); - Game.roomManager.CreateRoom(RoomType.杂物室); - Game.roomManager.CreateRoom(RoomType.训练堂); - Game.roomManager.CreateRoom(RoomType.先祖大厅); - Game.roomManager.CreateRoom(RoomType.圣龙残骸); - Game.roomManager.CreateRoom(RoomType.天池遗址); - Game.roomManager.CreateRoom(RoomType.沙慕龙阁); - Game.roomManager.CreateRoom(RoomType.英雄圣殿); + var room = Game.roomManager.CreateRoom(RoomType.出生点); + Game.roomManager.CreateRoom(RoomType.伏龙阁); + Game.roomManager.CreateRoom(RoomType.杂物室); + Game.roomManager.CreateRoom(RoomType.训练堂); + Game.roomManager.CreateRoom(RoomType.先祖大厅); + Game.roomManager.CreateRoom(RoomType.圣龙残骸); + Game.roomManager.CreateRoom(RoomType.天池遗址); + Game.roomManager.CreateRoom(RoomType.沙慕龙阁); + Game.roomManager.CreateRoom(RoomType.英雄圣殿); - var player = Game.playerManager.currentPlayer; - var joinPosition = room.roomInfo.GetJoinPosition(); + var player = Game.playerManager.currentPlayer; + var joinPosition = room.roomInfo.GetJoinPosition(); // var wayPoints = Game.bfsManager.FindPath(joinPosition); - UniTask.Create(async () => - { - await player.WaitMoveRoomAsync(room, new CancellationToken()); + UniTask.Create(async () => + { + await player.WaitMoveRoomAsync(room, new CancellationToken()); // await player.MoveAsync(wayPoints, new CancellationToken()); - Game.procedureManager.ChangeProcedure(ProcedureType.GameSceneLogicProcedure); - }); - } + Game.procedureManager.ChangeProcedure(ProcedureType.GameSceneLogicProcedure); + }); + } - public override void OnLeave() - { - base.OnLeave(); + public override void OnLeave() + { + base.OnLeave(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Procedure/Logic/GameSceneKillPlayerProcedure.cs b/Assets/Scripts/Procedure/Logic/GameSceneKillPlayerProcedure.cs index 8e8d3c6..347546b 100644 --- a/Assets/Scripts/Procedure/Logic/GameSceneKillPlayerProcedure.cs +++ b/Assets/Scripts/Procedure/Logic/GameSceneKillPlayerProcedure.cs @@ -7,97 +7,98 @@ using Game.Room; using UnityEngine; using Random = UnityEngine.Random; -namespace Game; - -[Procedure(ProcedureType.GameSceneKillPlayerProcedure)] -class GameSceneKillPlayerProcedure : ProcedureBase +namespace Game { - private float maxTime = 10f; - GameSceneMainUI sceneMainUI; - - public override void OnEnter() + [Procedure(ProcedureType.GameSceneKillPlayerProcedure)] + class GameSceneKillPlayerProcedure : ProcedureBase { - base.OnEnter(); + private float maxTime = 10f; + GameSceneMainUI sceneMainUI; - EventManager.Instance.Subscribe(InputObjectFinishEventArgs.EventId, this.InputObjectFinishEvent); - EventManager.Instance.FireNow(this, new BossStartMoveEventArgs(true)); - UniTask.Create(this.OpenWarningTips); - } + public override void OnEnter() + { + base.OnEnter(); - async UniTask OpenWarningTips() - { - sceneMainUI = Game.uiManager.GetUI(UIType.GameSceneMainUI); - await this.sceneMainUI.WaitTimeCloseTips(); + EventManager.Instance.Subscribe(InputObjectFinishEventArgs.EventId, this.InputObjectFinishEvent); + EventManager.Instance.FireNow(this, new BossStartMoveEventArgs(true)); + UniTask.Create(this.OpenWarningTips); + } - UniTask.Create(this.WaitKillFinish); + async UniTask OpenWarningTips() + { + sceneMainUI = Game.uiManager.GetUI(UIType.GameSceneMainUI); + await this.sceneMainUI.WaitTimeCloseTips(); + + UniTask.Create(this.WaitKillFinish); // UniTask.Create(this.WaitTimeGoNext); - isFinish = false; - } - - async UniTask WaitKillFinish() - { - string content = $"恐龙出没!"; - sceneMainUI.UpdateMessage(content); - - var roomData = Game.roomManager.GetAllRandomRoom(); - await Game.bossManager.MoveToKillPlayerAsync(roomData.killRoom, default); - - Game.bossManager.DeleteBoss(); - isFinish = true; - - float jinBei = 0; - foreach (var room in roomData.killRoom) - { - jinBei += room.roomData.jinBeiCount; + isFinish = false; } - Debug.Log($"杀掉了随机房间玩家,金贝数量总和为:{jinBei}"); - - List players = new List(); - foreach (var room in roomData.survivorRoom) + async UniTask WaitKillFinish() { - foreach (var roomPlayer in room.players) + string content = $"恐龙出没!"; + sceneMainUI.UpdateMessage(content); + + var roomData = Game.roomManager.GetAllRandomRoom(); + await Game.bossManager.MoveToKillPlayerAsync(roomData.killRoom, default); + + Game.bossManager.DeleteBoss(); + isFinish = true; + + float jinBei = 0; + foreach (var room in roomData.killRoom) { - Debug.Log($"幸存者:{roomPlayer.playerName}"); - players.Add(roomPlayer); + jinBei += room.roomData.jinBeiCount; } - } - if (players.Count > 0) - jinBei /= players.Count; + Debug.Log($"杀掉了随机房间玩家,金贝数量总和为:{jinBei}"); - Debug.Log($"胜利总金贝: is {jinBei}"); - EventManager.Instance.FireNow(this, new JinBeiSettlementEventArgs(players, jinBei)); + List players = new List(); + foreach (var room in roomData.survivorRoom) + { + foreach (var roomPlayer in room.players) + { + Debug.Log($"幸存者:{roomPlayer.playerName}"); + players.Add(roomPlayer); + } + } - var resultUI = Game.uiManager.GetUI(UIType.GameSceneResultUI); - if (players.Contains(Game.playerManager.currentPlayer)) - resultUI.SetResult($"恭喜你躲避成功,胜利总金贝:{jinBei},你得到的金贝:{jinBei}", true); - else - resultUI.SetResult($"躲避失败,胜利总金贝:{jinBei},你得到的金贝:0", false); + if (players.Count > 0) + jinBei /= players.Count; - //TODO: - UniTask.Create(async () => { await Game.roomManager.QuitAllRoomAsync(default); }); + Debug.Log($"胜利总金贝: is {jinBei}"); + EventManager.Instance.FireNow(this, new JinBeiSettlementEventArgs(players, jinBei)); + + var resultUI = Game.uiManager.GetUI(UIType.GameSceneResultUI); + if (players.Contains(Game.playerManager.currentPlayer)) + resultUI.SetResult($"恭喜你躲避成功,胜利总金贝:{jinBei},你得到的金贝:{jinBei}", true); + else + resultUI.SetResult($"躲避失败,胜利总金贝:{jinBei},你得到的金贝:0", false); + + //TODO: + UniTask.Create(async () => { await Game.roomManager.QuitAllRoomAsync(default); }); // await this.sceneMainUI.WaitTimeCloseTips(); - Game.procedureManager.ChangeProcedure(ProcedureType.GameSceneSettlementProcedure); - } + Game.procedureManager.ChangeProcedure(ProcedureType.GameSceneSettlementProcedure); + } - private bool isFinish; + private bool isFinish; - private void InputObjectFinishEvent(object sender, GameEventArgs e) - { - var args = e as InputObjectFinishEventArgs; + private void InputObjectFinishEvent(object sender, GameEventArgs e) + { + var args = e as InputObjectFinishEventArgs; // var inputData = args.data as MouseInputData; // var roomInfo = inputData.go.GetComponent(); - Debug.Log("未到选择房间时间!"); + Debug.Log("未到选择房间时间!"); // UniTask.Create(async () => { await Game.roomManager.JoinRoomAsync(roomInfo.roomType, Game.playerManager.currentPlayer, new CancellationToken()); }); - } + } - public override void OnLeave() - { - base.OnLeave(); - EventManager.Instance.Unsubscribe(InputObjectFinishEventArgs.EventId, this.InputObjectFinishEvent); + public override void OnLeave() + { + base.OnLeave(); + EventManager.Instance.Unsubscribe(InputObjectFinishEventArgs.EventId, this.InputObjectFinishEvent); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Procedure/Logic/GameSceneSettlementProcedure.cs b/Assets/Scripts/Procedure/Logic/GameSceneSettlementProcedure.cs index cc15cfa..849b640 100644 --- a/Assets/Scripts/Procedure/Logic/GameSceneSettlementProcedure.cs +++ b/Assets/Scripts/Procedure/Logic/GameSceneSettlementProcedure.cs @@ -1,25 +1,26 @@ using System.Threading; using Cysharp.Threading.Tasks; -namespace Game; - -[Procedure(ProcedureType.GameSceneSettlementProcedure)] -class GameSceneSettlementProcedure : ProcedureBase +namespace Game { - public override void OnEnter() + [Procedure(ProcedureType.GameSceneSettlementProcedure)] + class GameSceneSettlementProcedure : ProcedureBase { - base.OnEnter(); - var showUI = Game.uiManager.ShowUI(UIType.GameSceneResultUI); - var resultUI = showUI as GameSceneResultUI; - UniTask.Create(async () => + public override void OnEnter() { - await resultUI.WaitShowAndCloseResultAsync(default); - Game.procedureManager.ChangeProcedure(ProcedureType.GameSceneLogicProcedure); - }); - } + base.OnEnter(); + var showUI = Game.uiManager.ShowUI(UIType.GameSceneResultUI); + var resultUI = showUI as GameSceneResultUI; + UniTask.Create(async () => + { + await resultUI.WaitShowAndCloseResultAsync(default); + Game.procedureManager.ChangeProcedure(ProcedureType.GameSceneLogicProcedure); + }); + } - public override void OnLeave() - { - base.OnLeave(); + public override void OnLeave() + { + base.OnLeave(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Procedure/ProcedureAttribute.cs b/Assets/Scripts/Procedure/ProcedureAttribute.cs index 9609c39..ee0668b 100644 --- a/Assets/Scripts/Procedure/ProcedureAttribute.cs +++ b/Assets/Scripts/Procedure/ProcedureAttribute.cs @@ -1,14 +1,15 @@ using System; -namespace Game; - -[AttributeUsage(AttributeTargets.Class)] -class ProcedureAttribute: Attribute +namespace Game { - public ProcedureType ProcedureType { get; set; } - - public ProcedureAttribute(ProcedureType type) + [AttributeUsage(AttributeTargets.Class)] + class ProcedureAttribute: Attribute { - this.ProcedureType = type; + public ProcedureType ProcedureType { get; set; } + + public ProcedureAttribute(ProcedureType type) + { + this.ProcedureType = type; + } } } \ No newline at end of file diff --git a/Assets/Scripts/RayCast/MouseInput.cs b/Assets/Scripts/RayCast/MouseInput.cs index 9466c19..d6da4b4 100644 --- a/Assets/Scripts/RayCast/MouseInput.cs +++ b/Assets/Scripts/RayCast/MouseInput.cs @@ -3,105 +3,106 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; -namespace Game.RayCast; - -public class MouseInput : MonoBehaviour +namespace Game.RayCast { - public RayCastType rayCastType = RayCastType._2D; + public class MouseInput : MonoBehaviour + { + public RayCastType rayCastType = RayCastType._2D; - MouseInputData mouseInputData = new MouseInputData(); + MouseInputData mouseInputData = new MouseInputData(); // public event MouseInputEventHandle ev; - private void Update() - { - if (this.IsMouseOverUI()) return; - - switch (rayCastType) + private void Update() { - case RayCastType._3D: - // 3d - Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); - RaycastHit hit; - if (Physics.Raycast(ray, out hit)) - { - if (hit.collider != null) - { - Debug.Log(hit.collider.name); - } - } + if (this.IsMouseOverUI()) return; - break; - case RayCastType._2D: - //2d - var point = Camera.main.ScreenToWorldPoint(Input.mousePosition); - var hit2D = Physics2D.Raycast(point, -Vector2.up); - if (hit2D.collider != null) - { - if (Input.GetMouseButtonDown(0)) - { - UnityEngine.Debug.Log(hit2D.collider.name); - mouseInputData.rayCastType = this.rayCastType; - mouseInputData.point = hit2D.point; - mouseInputData.isPressDown = true; - mouseInputData.go = hit2D.collider.gameObject; - EventManager.Instance.FireNow(this, new InputObjectFinishEventArgs(mouseInputData)); - } - else if (Input.GetMouseButtonDown(2)) - { -// Game.bfsManager.Test(hit2D.point); - } - } - - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - private bool IsMouseOverUI() - { - PointerEventData eventData = new PointerEventData(EventSystem.current) - { - position = Input.mousePosition - }; - - List results = new List(); - EventSystem.current.RaycastAll(eventData, results); - - foreach (var result in results) - { - // 检查射线检测到的对象是否为UI元素,并且是否属于CanvasGroup - CanvasGroup canvasGroup = result.gameObject.GetComponentInParent(); - - if (canvasGroup != null) + switch (rayCastType) { - // 如果CanvasGroup不允许交互或不阻挡射线,我们认为鼠标不是位于UI上 - if (!canvasGroup.interactable || !canvasGroup.blocksRaycasts) + case RayCastType._3D: + // 3d + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit hit; + if (Physics.Raycast(ray, out hit)) + { + if (hit.collider != null) + { + Debug.Log(hit.collider.name); + } + } + + break; + case RayCastType._2D: + //2d + var point = Camera.main.ScreenToWorldPoint(Input.mousePosition); + var hit2D = Physics2D.Raycast(point, -Vector2.up); + if (hit2D.collider != null) + { + if (Input.GetMouseButtonDown(0)) + { + UnityEngine.Debug.Log(hit2D.collider.name); + mouseInputData.rayCastType = this.rayCastType; + mouseInputData.point = hit2D.point; + mouseInputData.isPressDown = true; + mouseInputData.go = hit2D.collider.gameObject; + EventManager.Instance.FireNow(this, new InputObjectFinishEventArgs(mouseInputData)); + } + else if (Input.GetMouseButtonDown(2)) + { +// Game.bfsManager.Test(hit2D.point); + } + } + + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + private bool IsMouseOverUI() + { + PointerEventData eventData = new PointerEventData(EventSystem.current) + { + position = Input.mousePosition + }; + + List results = new List(); + EventSystem.current.RaycastAll(eventData, results); + + foreach (var result in results) + { + // 检查射线检测到的对象是否为UI元素,并且是否属于CanvasGroup + CanvasGroup canvasGroup = result.gameObject.GetComponentInParent(); + + if (canvasGroup != null) { - continue; + // 如果CanvasGroup不允许交互或不阻挡射线,我们认为鼠标不是位于UI上 + if (!canvasGroup.interactable || !canvasGroup.blocksRaycasts) + { + continue; + } } + + // 如果找到至少一个允许交互且阻挡射线的UI元素,返回true + return true; } - // 如果找到至少一个允许交互且阻挡射线的UI元素,返回true - return true; + // 如果所有射线检测到的UI元素都不允许交互或不阻挡射线,返回false + return false; } - - // 如果所有射线检测到的UI元素都不允许交互或不阻挡射线,返回false - return false; } -} -public enum RayCastType -{ - _3D, - _2D, -} + public enum RayCastType + { + _3D, + _2D, + } -public class MouseInputData -{ - public RayCastType rayCastType; - public bool isPressDown; - public Vector3 point; - public GameObject go; + public class MouseInputData + { + public RayCastType rayCastType; + public bool isPressDown; + public Vector3 point; + public GameObject go; + } } \ No newline at end of file diff --git a/Assets/Scripts/RayCast/MouseInputManager.cs b/Assets/Scripts/RayCast/MouseInputManager.cs index dec01eb..b85841e 100644 --- a/Assets/Scripts/RayCast/MouseInputManager.cs +++ b/Assets/Scripts/RayCast/MouseInputManager.cs @@ -1,28 +1,29 @@ using System; -namespace Game.RayCast; - -public class MouseInputManager : ManagerBase, IMouseInputManager +namespace Game.RayCast { - private MouseInput _currentMouseInput; - - public MouseInput currentMouseInput => this._currentMouseInput; - - protected override void OnInit() + public class MouseInputManager : ManagerBase, IMouseInputManager { - base.OnInit(); - AddMouseInput(RayCastType._2D); + private MouseInput _currentMouseInput; + + public MouseInput currentMouseInput => this._currentMouseInput; + + protected override void OnInit() + { + base.OnInit(); + AddMouseInput(RayCastType._2D); + } + + public void AddMouseInput(RayCastType rayCastType) + { + _currentMouseInput ??= Game.self.AddComponent(); + this._currentMouseInput.rayCastType = rayCastType; + } } - public void AddMouseInput(RayCastType rayCastType) + public interface IMouseInputManager { - _currentMouseInput ??= Game.self.AddComponent(); - this._currentMouseInput.rayCastType = rayCastType; + MouseInput currentMouseInput { get; } + void AddMouseInput(RayCastType rayCastType); } -} - -public interface IMouseInputManager -{ - MouseInput currentMouseInput { get; } - void AddMouseInput(RayCastType rayCastType); } \ No newline at end of file diff --git a/Assets/Scripts/Room/IRoomManager.cs b/Assets/Scripts/Room/IRoomManager.cs index b4e29fd..5defb3b 100644 --- a/Assets/Scripts/Room/IRoomManager.cs +++ b/Assets/Scripts/Room/IRoomManager.cs @@ -5,190 +5,191 @@ using Cysharp.Threading.Tasks; using Game.Player; using UnityEngine; -namespace Game.Room; - -public interface IRoomManager +namespace Game.Room { - IRoom currentRoom { get; } - IRoom CreateRoom(RoomType roomType); - void SetCurrentRoom(RoomType roomType); - IRoom GetRoom(RoomType roomType); - RandomRoomData GetAllRandomRoom(); - UniTask JoinRoomAsync(RoomType roomType, IPlayer player, CancellationToken token); - bool QuitRoom(RoomType roomType, IPlayer player); - UniTask QuitAllRoomAsync(CancellationToken token); - void DeleteRoom(RoomType roomType); -} - -public class RoomManager : ManagerBase, IRoomManager -{ - private IRoom birthRoom; - private Dictionary _rooms = new Dictionary(); - private Dictionary tmp = new Dictionary(); - private IRoom _currentRoom; - - public IRoom currentRoom => this._currentRoom; - - protected override void OnInit() + public interface IRoomManager { - base.OnInit(); - EventManager.Instance.Subscribe(RoomJinBeiChangeEventArgs.EventId, RoomJinBeiChangeEvent); + IRoom currentRoom { get; } + IRoom CreateRoom(RoomType roomType); + void SetCurrentRoom(RoomType roomType); + IRoom GetRoom(RoomType roomType); + RandomRoomData GetAllRandomRoom(); + UniTask JoinRoomAsync(RoomType roomType, IPlayer player, CancellationToken token); + bool QuitRoom(RoomType roomType, IPlayer player); + UniTask QuitAllRoomAsync(CancellationToken token); + void DeleteRoom(RoomType roomType); } - protected override void OnDispose() + public class RoomManager : ManagerBase, IRoomManager { - base.OnDispose(); - EventManager.Instance.Unsubscribe(RoomJinBeiChangeEventArgs.EventId, RoomJinBeiChangeEvent); - } + private IRoom birthRoom; + private Dictionary _rooms = new Dictionary(); + private Dictionary tmp = new Dictionary(); + private IRoom _currentRoom; - private void RoomJinBeiChangeEvent(object sender, GameEventArgs e) - { - var args = e as RoomJinBeiChangeEventArgs; - args.room.InvestmentJinBei(args.player, args.jinBei); - } + public IRoom currentRoom => this._currentRoom; + + protected override void OnInit() + { + base.OnInit(); + EventManager.Instance.Subscribe(RoomJinBeiChangeEventArgs.EventId, RoomJinBeiChangeEvent); + } + + protected override void OnDispose() + { + base.OnDispose(); + EventManager.Instance.Unsubscribe(RoomJinBeiChangeEventArgs.EventId, RoomJinBeiChangeEvent); + } + + private void RoomJinBeiChangeEvent(object sender, GameEventArgs e) + { + var args = e as RoomJinBeiChangeEventArgs; + args.room.InvestmentJinBei(args.player, args.jinBei); + } + + public IRoom CreateRoom(RoomType roomType) + { + if (this._rooms.TryGetValue(roomType, out var room)) + return room; + + var gameObject = Game.resourceManager.LoadGameObjectSync(roomType.ToString()); + room = new Room(roomType, gameObject); + + this._rooms.Add(roomType, room); - public IRoom CreateRoom(RoomType roomType) - { - if (this._rooms.TryGetValue(roomType, out var room)) return room; - - var gameObject = Game.resourceManager.LoadGameObjectSync(roomType.ToString()); - room = new Room(roomType, gameObject); - - this._rooms.Add(roomType, room); - - return room; - } - - public void SetCurrentRoom(RoomType roomType) - { - if (roomType == RoomType.出生点) - return; - - if (this._rooms.TryGetValue(roomType, out var room)) - this._currentRoom = room; - } - - public IRoom GetRoom(RoomType roomType) - { - return this._rooms.GetValueOrDefault(roomType); - } - - public RandomRoomData GetAllRandomRoom() - { - if (this.tmp.Count <= 0 || this.tmp.ContainsKey(RoomType.出生点)) - { - this.tmp = new Dictionary(this._rooms); - this.tmp.Remove(RoomType.出生点); } - // kill - var killRoom = this.tmp.Values.ToList(); - ShuffleAndRemoveRooms(killRoom); - - // - var survivorRoom = this.tmp.Values.ToList().Except(killRoom).ToList(); - - // 标记一下 - foreach (var room in killRoom) + public void SetCurrentRoom(RoomType roomType) { - room.SetIsCanReturnJinBei(false); + if (roomType == RoomType.出生点) + return; + + if (this._rooms.TryGetValue(roomType, out var room)) + this._currentRoom = room; } - // 标记一下 - foreach (var room in survivorRoom) + public IRoom GetRoom(RoomType roomType) { - room.SetIsCanReturnJinBei(true); + return this._rooms.GetValueOrDefault(roomType); } - RandomRoomData roomData = new RandomRoomData(); - roomData.killRoom = killRoom; - roomData.survivorRoom = survivorRoom; - - return roomData; - } - - public void ShuffleAndRemoveRooms(List list) - { - ShuffleList(list); - - int removeCount = Random.Range(1, list.Count); - - for (int i = 0; i < removeCount; i++) + public RandomRoomData GetAllRandomRoom() { - list.RemoveAt(list.Count - 1); - } - } - - // 实现Fisher-Yates洗牌算法 - private void ShuffleList(List list) - { - for (int i = list.Count - 1; i > 0; i--) - { - int swapIndex = Random.Range(0, i + 1); - (list[i], list[swapIndex]) = (list[swapIndex], list[i]); - } - } - - public async UniTask JoinRoomAsync(RoomType roomType, IPlayer player, CancellationToken token) - { - if (!player.isMoving) - return false; - - foreach (IRoom roomsValue in this._rooms.Values) - { - var roomInfo = roomsValue.roomInfo; - roomInfo.SetSelect(false); - } - - if (this._rooms.TryGetValue(roomType, out var room)) - { - room.roomInfo.SetSelect(true); - await room.JoinAsync(player, token); - return true; - } - - return false; - } - - public bool QuitRoom(RoomType roomType, IPlayer player) - { - if (this._rooms.TryGetValue(roomType, out var room)) - { - room.Quit(player); - return true; - } - - return false; - } - - public async UniTask QuitAllRoomAsync(CancellationToken token) - { - List tasks = new List(); - foreach (IRoom room in this.tmp.Values) - { - var players = room.QuitAndClearAll(); - foreach (var player in players) + if (this.tmp.Count <= 0 || this.tmp.ContainsKey(RoomType.出生点)) { - Debug.Log($"正在安排{player}返回出生点"); - var task = this.JoinRoomAsync(RoomType.出生点, player, token); - tasks.Add(task); + this.tmp = new Dictionary(this._rooms); + this.tmp.Remove(RoomType.出生点); + } + + // kill + var killRoom = this.tmp.Values.ToList(); + ShuffleAndRemoveRooms(killRoom); + + // + var survivorRoom = this.tmp.Values.ToList().Except(killRoom).ToList(); + + // 标记一下 + foreach (var room in killRoom) + { + room.SetIsCanReturnJinBei(false); + } + + // 标记一下 + foreach (var room in survivorRoom) + { + room.SetIsCanReturnJinBei(true); + } + + RandomRoomData roomData = new RandomRoomData(); + roomData.killRoom = killRoom; + roomData.survivorRoom = survivorRoom; + + return roomData; + } + + public void ShuffleAndRemoveRooms(List list) + { + ShuffleList(list); + + int removeCount = Random.Range(1, list.Count); + + for (int i = 0; i < removeCount; i++) + { + list.RemoveAt(list.Count - 1); } } - await UniTask.WhenAll(tasks); - Debug.Log("全部返回了出生点"); + // 实现Fisher-Yates洗牌算法 + private void ShuffleList(List list) + { + for (int i = list.Count - 1; i > 0; i--) + { + int swapIndex = Random.Range(0, i + 1); + (list[i], list[swapIndex]) = (list[swapIndex], list[i]); + } + } + + public async UniTask JoinRoomAsync(RoomType roomType, IPlayer player, CancellationToken token) + { + if (!player.isMoving) + return false; + + foreach (IRoom roomsValue in this._rooms.Values) + { + var roomInfo = roomsValue.roomInfo; + roomInfo.SetSelect(false); + } + + if (this._rooms.TryGetValue(roomType, out var room)) + { + room.roomInfo.SetSelect(true); + await room.JoinAsync(player, token); + return true; + } + + return false; + } + + public bool QuitRoom(RoomType roomType, IPlayer player) + { + if (this._rooms.TryGetValue(roomType, out var room)) + { + room.Quit(player); + return true; + } + + return false; + } + + public async UniTask QuitAllRoomAsync(CancellationToken token) + { + List tasks = new List(); + foreach (IRoom room in this.tmp.Values) + { + var players = room.QuitAndClearAll(); + foreach (var player in players) + { + Debug.Log($"正在安排{player}返回出生点"); + var task = this.JoinRoomAsync(RoomType.出生点, player, token); + tasks.Add(task); + } + } + + await UniTask.WhenAll(tasks); + Debug.Log("全部返回了出生点"); + } + + public void DeleteRoom(RoomType roomType) + { + if (this._rooms.TryGetValue(roomType, out var room)) + room.Dispose(); + } } - public void DeleteRoom(RoomType roomType) + public struct RandomRoomData { - if (this._rooms.TryGetValue(roomType, out var room)) - room.Dispose(); + public IReadOnlyList killRoom; + public IReadOnlyList survivorRoom; } -} - -public struct RandomRoomData -{ - public IReadOnlyList killRoom; - public IReadOnlyList survivorRoom; } \ No newline at end of file diff --git a/Assets/Scripts/Room/Room.cs b/Assets/Scripts/Room/Room.cs index a2dc815..5fe121b 100644 --- a/Assets/Scripts/Room/Room.cs +++ b/Assets/Scripts/Room/Room.cs @@ -5,126 +5,127 @@ using Cysharp.Threading.Tasks; using Game.Player; using UnityEngine; -namespace Game.Room; - -public interface IRoom +namespace Game.Room { - string roomName { get; } - RoomData roomData { get; } - RoomInfo roomInfo { get; } - IReadOnlyList players { get; } - RoomType roomType { get; } + public interface IRoom + { + string roomName { get; } + RoomData roomData { get; } + RoomInfo roomInfo { get; } + IReadOnlyList players { get; } + RoomType roomType { get; } - UniTask JoinAsync(IPlayer player, CancellationToken token); - UniTask Quit(IPlayer player); + UniTask JoinAsync(IPlayer player, CancellationToken token); + UniTask Quit(IPlayer player); - void SetIsCanReturnJinBei(bool isCan); + void SetIsCanReturnJinBei(bool isCan); - List QuitAndClearAll(); + List QuitAndClearAll(); // float ClearAll(); - void Dispose(); + void Dispose(); - bool InvestmentJinBei(IPlayer player, float jinbei); -} - -[System.Serializable] -public class Room : IRoom -{ - private GameObject self; - private RoomInfo _roomInfo; - private RoomData _roomData; - private string _roomName; - private bool _isCanReturnJinBei; - - public RoomType roomType => this._roomData.roomType; - - public string roomName => this._roomName; - - - public RoomData roomData => this._roomData; - public RoomInfo roomInfo => this._roomInfo; - - public IReadOnlyList players => this._roomData.players; - - public Room(RoomType roomType, GameObject roomGo) - { - this._roomData = new RoomData(roomType); - _roomName = roomType.ToString(); - - // view - this._roomInfo = roomGo.GetComponent(); - this._roomInfo.SetRoom(this); - this.self = roomGo; - this._roomData.jinBeiCallback += this._roomInfo.UpdateNumber; + bool InvestmentJinBei(IPlayer player, float jinbei); } - public void Dispose() + [System.Serializable] + public class Room : IRoom { - this._roomData.jinBeiCallback -= this._roomInfo.UpdateNumber; - this._roomData.Reset(); + private GameObject self; + private RoomInfo _roomInfo; + private RoomData _roomData; + private string _roomName; + private bool _isCanReturnJinBei; - this.self = null; - this._roomInfo = null; - this._roomData = null; - this._roomName = null; - } + public RoomType roomType => this._roomData.roomType; - public async UniTask JoinAsync(IPlayer player, CancellationToken token) - { - if (this.players.Contains(player)) - return false; + public string roomName => this._roomName; + + + public RoomData roomData => this._roomData; + public RoomInfo roomInfo => this._roomInfo; + + public IReadOnlyList players => this._roomData.players; + + public Room(RoomType roomType, GameObject roomGo) + { + this._roomData = new RoomData(roomType); + _roomName = roomType.ToString(); + + // view + this._roomInfo = roomGo.GetComponent(); + this._roomInfo.SetRoom(this); + this.self = roomGo; + this._roomData.jinBeiCallback += this._roomInfo.UpdateNumber; + } + + public void Dispose() + { + this._roomData.jinBeiCallback -= this._roomInfo.UpdateNumber; + this._roomData.Reset(); + + this.self = null; + this._roomInfo = null; + this._roomData = null; + this._roomName = null; + } + + public async UniTask JoinAsync(IPlayer player, CancellationToken token) + { + if (this.players.Contains(player)) + return false; // Debug.Log($"{player.playerName} join {roomType} !!"); - bool res = await player.WaitMoveRoomAsync(this, token); - this._roomData.AddPlayer(player); - return true; - } + bool res = await player.WaitMoveRoomAsync(this, token); + this._roomData.AddPlayer(player); + return true; + } - public async UniTask Quit(IPlayer player) - { - if (!this.players.Contains(player)) - return false; - Debug.Log($"{player.playerName} quit {roomType} !!"); - - var f = this._roomData.RemovePlayer(player); - EventManager.Instance.FireNow(this, new ReturnPlayerJinBeiEventArgs(player, f)); - - await UniTask.Yield(); - return true; - } - - public void SetIsCanReturnJinBei(bool isCan) - { - this._isCanReturnJinBei = isCan; - } - - public List QuitAndClearAll() - { - if (this._isCanReturnJinBei) + public async UniTask Quit(IPlayer player) { - // 归还金贝 - var dictionary = this._roomData.ReturnPlayerAndJinBei(); - foreach (var player in dictionary.Keys) + if (!this.players.Contains(player)) + return false; + Debug.Log($"{player.playerName} quit {roomType} !!"); + + var f = this._roomData.RemovePlayer(player); + EventManager.Instance.FireNow(this, new ReturnPlayerJinBeiEventArgs(player, f)); + + await UniTask.Yield(); + return true; + } + + public void SetIsCanReturnJinBei(bool isCan) + { + this._isCanReturnJinBei = isCan; + } + + public List QuitAndClearAll() + { + if (this._isCanReturnJinBei) { - Debug.Log($"return player {player.playerName} jinBei : {dictionary[player]}"); - EventManager.Instance.FireNow(this, new ReturnPlayerJinBeiEventArgs(player, dictionary[player])); + // 归还金贝 + var dictionary = this._roomData.ReturnPlayerAndJinBei(); + foreach (var player in dictionary.Keys) + { + Debug.Log($"return player {player.playerName} jinBei : {dictionary[player]}"); + EventManager.Instance.FireNow(this, new ReturnPlayerJinBeiEventArgs(player, dictionary[player])); + } } + + var list = new List(_roomData.players); + this._roomData.Reset(); + return list; } - var list = new List(_roomData.players); - this._roomData.Reset(); - return list; - } - - public bool InvestmentJinBei(IPlayer player, float jinBei) - { - if (!this.players.Contains(player)) + public bool InvestmentJinBei(IPlayer player, float jinBei) { - Debug.LogWarning($"{roomType} dont have {player.playerName}"); - return false; - } + if (!this.players.Contains(player)) + { + Debug.LogWarning($"{roomType} dont have {player.playerName}"); + return false; + } - this._roomData.AddJinBei(player, jinBei); - return true; + this._roomData.AddJinBei(player, jinBei); + return true; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Spine/SpineAnimator.cs b/Assets/Scripts/Spine/SpineAnimator.cs index 6c630c4..8252af2 100644 --- a/Assets/Scripts/Spine/SpineAnimator.cs +++ b/Assets/Scripts/Spine/SpineAnimator.cs @@ -4,110 +4,111 @@ using Spine; using Spine.Unity; using UnityEngine; -namespace Game.Spine; - -public interface ISpineAnimator +namespace Game.Spine { - SkeletonAnimation skeletonAnimation { get; } - Action complete { get; set; } - void PlayAni(string animaName, bool isLoop); - UniTask PlayAniAsync(string animaName); - UniTask PlayAniAsync(string animaName, float time); - - /// - /// 从某一帧开始播放某个动画 - /// - /// - /// - /// - void PlayAniFromPoint(int index, string animaName, bool isLoop); - - void StopAni(); -} - -public class SpineAnimator : MonoBehaviour, ISpineAnimator -{ - [SerializeField] private SkeletonAnimation _skeletonAnimation; - private bool _isPlaying; - - public SkeletonAnimation skeletonAnimation => this._skeletonAnimation; - - public Action complete { get; set; } - - private void Awake() + public interface ISpineAnimator { - if (this._skeletonAnimation == null) - throw new NullReferenceException(); + SkeletonAnimation skeletonAnimation { get; } + Action complete { get; set; } + void PlayAni(string animaName, bool isLoop); + UniTask PlayAniAsync(string animaName); + UniTask PlayAniAsync(string animaName, float time); - complete = null; - _isPlaying = false; + /// + /// 从某一帧开始播放某个动画 + /// + /// + /// + /// + void PlayAniFromPoint(int index, string animaName, bool isLoop); + + void StopAni(); } - private void Start() + public class SpineAnimator : MonoBehaviour, ISpineAnimator { - this._skeletonAnimation.state.Complete += Finish; - this.StopAni(); - } + [SerializeField] private SkeletonAnimation _skeletonAnimation; + private bool _isPlaying; - private void OnDestroy() - { - this._skeletonAnimation.state.Complete -= Finish; - } + public SkeletonAnimation skeletonAnimation => this._skeletonAnimation; - private void Finish(TrackEntry trackentry) - { -// Debug.Log("动画播放完成: " + trackentry.Animation.Name); - _isPlaying = false; - complete?.Invoke(trackentry); - } + public Action complete { get; set; } - public virtual void PlayAni(string animaName, bool isLoop = false) - { - _skeletonAnimation.AnimationName = animaName; - this._skeletonAnimation.loop = isLoop; - } - - /// - /// 仅适用于一次性播放动画,循环动画勿用 - /// - /// - /// - public async UniTask PlayAniAsync(string animaName) - { - _isPlaying = true; - this._skeletonAnimation.loop = false; - this._skeletonAnimation.AnimationName = animaName; - - while (_isPlaying) + private void Awake() { - await UniTask.Yield(); + if (this._skeletonAnimation == null) + throw new NullReferenceException(); + + complete = null; + _isPlaying = false; + } + + private void Start() + { + this._skeletonAnimation.state.Complete += Finish; + this.StopAni(); + } + + private void OnDestroy() + { + this._skeletonAnimation.state.Complete -= Finish; + } + + private void Finish(TrackEntry trackentry) + { +// Debug.Log("动画播放完成: " + trackentry.Animation.Name); + _isPlaying = false; + complete?.Invoke(trackentry); + } + + public virtual void PlayAni(string animaName, bool isLoop = false) + { + _skeletonAnimation.AnimationName = animaName; + this._skeletonAnimation.loop = isLoop; + } + + /// + /// 仅适用于一次性播放动画,循环动画勿用 + /// + /// + /// + public async UniTask PlayAniAsync(string animaName) + { + _isPlaying = true; + this._skeletonAnimation.loop = false; + this._skeletonAnimation.AnimationName = animaName; + + while (_isPlaying) + { + await UniTask.Yield(); + } + } + + /// + /// 播放某个动画多少秒 + /// + /// + /// + public async UniTask PlayAniAsync(string animaName, float time) + { + this._skeletonAnimation.loop = true; + this._skeletonAnimation.AnimationName = animaName; + float f = 0; + f = time * 1000; + + await UniTask.Delay((int)f); + this._skeletonAnimation.loop = false; + StopAni(); + } + + public void PlayAniFromPoint(int index, string animaName, bool isLoop) + { + throw new NotImplementedException(); + } + + public void StopAni() + { + _skeletonAnimation.AnimationName = default; } } - - /// - /// 播放某个动画多少秒 - /// - /// - /// - public async UniTask PlayAniAsync(string animaName, float time) - { - this._skeletonAnimation.loop = true; - this._skeletonAnimation.AnimationName = animaName; - float f = 0; - f = time * 1000; - - await UniTask.Delay((int)f); - this._skeletonAnimation.loop = false; - StopAni(); - } - - public void PlayAniFromPoint(int index, string animaName, bool isLoop) - { - throw new NotImplementedException(); - } - - public void StopAni() - { - _skeletonAnimation.AnimationName = default; - } } \ No newline at end of file diff --git a/Assets/Scripts/UI/AssemblyManager.cs b/Assets/Scripts/UI/AssemblyManager.cs index 0096842..1ba418c 100644 --- a/Assets/Scripts/UI/AssemblyManager.cs +++ b/Assets/Scripts/UI/AssemblyManager.cs @@ -2,28 +2,29 @@ using System.Collections.Generic; using Sirenix.Utilities; -namespace Game; - -public static class AssemblyManager +namespace Game { - private static List _types ; - - public static void Initialize() + public static class AssemblyManager { - var types = typeof(AssemblyManager).Assembly.GetTypes(); - _types = new List(types); - } + private static List _types ; - public static void GetTypesInhertType(Type baseType, List<(Type, T)> types) where T : Attribute - { - foreach (var type in _types) + public static void Initialize() { - if (!baseType.IsAssignableFrom(type)) - continue; - var attribute = type.GetCustomAttribute(); - if (attribute == null) - continue; - types.Add((type, attribute)); + var types = typeof(AssemblyManager).Assembly.GetTypes(); + _types = new List(types); + } + + public static void GetTypesInhertType(Type baseType, List<(Type, T)> types) where T : Attribute + { + foreach (var type in _types) + { + if (!baseType.IsAssignableFrom(type)) + continue; + var attribute = type.GetCustomAttribute(); + if (attribute == null) + continue; + types.Add((type, attribute)); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/UI/Logic/GameSceneHelpUI.cs b/Assets/Scripts/UI/Logic/GameSceneHelpUI.cs index b912a84..527a74d 100644 --- a/Assets/Scripts/UI/Logic/GameSceneHelpUI.cs +++ b/Assets/Scripts/UI/Logic/GameSceneHelpUI.cs @@ -1,28 +1,29 @@ using UnityEngine.UI; -namespace Game; - -[UIType(UIType.GameSceneHelpUI)] -public class GameSceneHelpUI : UIBase +namespace Game { - private Button btn_Back; - - public override void Init() + [UIType(UIType.GameSceneHelpUI)] + public class GameSceneHelpUI : UIBase { - base.Init(); - this.btn_Back = this.self.transform.FindChildDeep