mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
41
JNFrame2/Assets/Scripts/Samples/Game/View/DViewSystem.cs
Normal file
41
JNFrame2/Assets/Scripts/Samples/Game/View/DViewSystem.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Game.JNGFrame.View.Entity;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.View;
|
||||
using JNGame.Util;
|
||||
|
||||
namespace Game.JNGFrame.View
|
||||
{
|
||||
public class DViewSystem : SViewSystem
|
||||
{
|
||||
|
||||
private readonly IViewData[] views;
|
||||
|
||||
public DViewSystem()
|
||||
{
|
||||
views = new IViewData[] {
|
||||
new VDNodes(this), //显示Demo实体
|
||||
new VDPlayers(this), //显示玩家实体
|
||||
new VDBoss(this), //显示Boss实体
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
base.OnSyncUpdate(dt);
|
||||
foreach (var view in views)
|
||||
{
|
||||
//视图逻辑交给主线程运行
|
||||
UnityMainThreadDispatcher.Instance.Enqueue(view.Execute);
|
||||
}
|
||||
}
|
||||
// public override void Execute()
|
||||
// {
|
||||
// foreach (var view in views)
|
||||
// {
|
||||
// view.Execute();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b957e5e22fd84759a0ece337922e616d
|
||||
timeCreated: 1712750046
|
3
JNFrame2/Assets/Scripts/Samples/Game/View/Entity.meta
Normal file
3
JNFrame2/Assets/Scripts/Samples/Game/View/Entity.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7723835c77a04a6f98cf04c58f01b9c1
|
||||
timeCreated: 1712750018
|
52
JNFrame2/Assets/Scripts/Samples/Game/View/Entity/VDBoss.cs
Normal file
52
JNFrame2/Assets/Scripts/Samples/Game/View/Entity/VDBoss.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using AppGame;
|
||||
using AppGame.Sync;
|
||||
using Cinemachine;
|
||||
using DG.Tweening;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.View;
|
||||
using Service;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
public class VDBoss : VDEntityBasis<EDBossData>
|
||||
{
|
||||
public GameObject VWorld => App.Resource.VWorld;
|
||||
public GameObject Boss => App.Resource.Boss;
|
||||
|
||||
public VDBoss(SViewSystem root) : base(root)
|
||||
{
|
||||
Register((int)GDataValueCode.Position, OnUpdatePosition);
|
||||
}
|
||||
|
||||
private void OnUpdatePosition((GameObject View, EDBossData Data) tuple)
|
||||
{
|
||||
var (view, data) = tuple;
|
||||
if (data.Value.Position != null)
|
||||
{
|
||||
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
public override GameObject NewView(EDBossData data)
|
||||
{
|
||||
var view = Object.Instantiate(Boss, VWorld.transform);
|
||||
view.name = $"Boss_{data.Id}";
|
||||
return view;
|
||||
}
|
||||
|
||||
public override EDBossData[] GetData()
|
||||
{
|
||||
return GetService<EDBossDataSystem>().Datas;
|
||||
}
|
||||
|
||||
public override void ViewRemove(GameObject view)
|
||||
{
|
||||
view.transform.DOKill();
|
||||
Object.Destroy(view);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 211b4062ef0644d583693f4b36358c40
|
||||
timeCreated: 1724724729
|
52
JNFrame2/Assets/Scripts/Samples/Game/View/Entity/VDNodes.cs
Normal file
52
JNFrame2/Assets/Scripts/Samples/Game/View/Entity/VDNodes.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using AppGame;
|
||||
using DG.Tweening;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.View;
|
||||
using Service;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
public class VDNodes : VDEntityBasis<EDNodeData>
|
||||
{
|
||||
public GameObject VWorld => App.Resource.VWorld;
|
||||
public GameObject Player => App.Resource.Player;
|
||||
public VDNodes(SViewSystem root) : base(root)
|
||||
{
|
||||
Register((int)GDataValueCode.Position, OnUpdatePosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新位置
|
||||
/// </summary>
|
||||
private void OnUpdatePosition((GameObject View, EDNodeData Data) tuple)
|
||||
{
|
||||
var (view, data) = tuple;
|
||||
if (data.Value.Position != null)
|
||||
{
|
||||
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
public override GameObject NewView(EDNodeData data)
|
||||
{
|
||||
var view = Object.Instantiate(Player, VWorld.transform);
|
||||
view.name = $"Node_{data.Id}";
|
||||
return view;
|
||||
}
|
||||
|
||||
public override EDNodeData[] GetData()
|
||||
{
|
||||
return GetService<EDNodeDataSystem>().Datas;
|
||||
}
|
||||
|
||||
public override void ViewRemove(GameObject view)
|
||||
{
|
||||
view.transform.DOKill();
|
||||
Object.Destroy(view);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 658e1c8925f546749725181702b989e9
|
||||
timeCreated: 1715169861
|
103
JNFrame2/Assets/Scripts/Samples/Game/View/Entity/VDPlayers.cs
Normal file
103
JNFrame2/Assets/Scripts/Samples/Game/View/Entity/VDPlayers.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using AppGame;
|
||||
using AppGame.Sync;
|
||||
using Cinemachine;
|
||||
using DG.Tweening;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.View;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
public class VDPlayers : VDEntityBasis<EDPlayerData>
|
||||
{
|
||||
public GameObject VWorld => App.Resource.VWorld;
|
||||
public GameObject Player => App.Resource.Player;
|
||||
public CinemachineFreeLook FreeLook => App.Resource.FreeLook;
|
||||
|
||||
//本地玩家 视图
|
||||
private GameObject LocalView;
|
||||
|
||||
public VDPlayers(SViewSystem root) : base(root)
|
||||
{
|
||||
|
||||
Register((int)GDataValueCode.Position, OnUpdatePosition);
|
||||
Register((int)EDPlayerValueCode.Auth, OnUpdateAuth);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新坐标
|
||||
/// </summary>
|
||||
/// <param name="tuple"></param>
|
||||
private void OnUpdatePosition((GameObject View, EDPlayerData Data) tuple)
|
||||
{
|
||||
var (view, data) = tuple;
|
||||
|
||||
//更新位置
|
||||
if (data.Value.Position != null)
|
||||
{
|
||||
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
||||
}
|
||||
|
||||
if (data.Value.Auth == App.ClientID)
|
||||
{
|
||||
//更新本地玩家位置
|
||||
if (data.Value.Position != null) App.Game.GetClient<JNGTileClientSystem>()?.SetPlayerPosition(data.Value.Position.ToLVector3());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新权限
|
||||
/// </summary>
|
||||
private void OnUpdateAuth((GameObject View, EDPlayerData Data) tuple)
|
||||
{
|
||||
|
||||
var (view, data) = tuple;
|
||||
|
||||
//权限操作
|
||||
if (App.IsClient() && data.Value.Auth == App.ClientID)
|
||||
{
|
||||
|
||||
//绑定相机
|
||||
FreeLook.LookAt = view.transform;
|
||||
FreeLook.Follow = view.transform;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override GameObject NewView(EDPlayerData data)
|
||||
{
|
||||
GameObject view;
|
||||
//如果这个角色是自己 则 直接拿自己的 View
|
||||
if (App.IsClient() && data.Value.Auth == App.ClientID)
|
||||
{
|
||||
if (LocalView is null) LocalView = Object.Instantiate(Player, VWorld.transform);
|
||||
view = LocalView;
|
||||
}
|
||||
else
|
||||
{
|
||||
view = Object.Instantiate(Player, VWorld.transform);
|
||||
}
|
||||
|
||||
view.name = $"Player_{data.Id}";
|
||||
return view;
|
||||
}
|
||||
|
||||
public override EDPlayerData[] GetData()
|
||||
{
|
||||
return GetService<EDPlayerDataSystem>().Datas;
|
||||
}
|
||||
|
||||
public override void ViewRemove(GameObject view)
|
||||
{
|
||||
view.transform.DOKill();
|
||||
if (LocalView != view)
|
||||
{
|
||||
Object.Destroy(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c45ed812046443709890cdd79dfdcb19
|
||||
timeCreated: 1722252921
|
54
JNFrame2/Assets/Scripts/Samples/Game/View/VDEntityBasis.cs
Normal file
54
JNFrame2/Assets/Scripts/Samples/Game/View/VDEntityBasis.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.View;
|
||||
using Plugins.JNGame.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View
|
||||
{
|
||||
|
||||
public abstract class VDEntityBasis<T> : ViewData<T> where T : IGDataBase
|
||||
{
|
||||
|
||||
private readonly Dictionary<int, Action<(GameObject View, T Data)>> Event = new();
|
||||
|
||||
protected VDEntityBasis(SViewSystem root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
base.Execute();
|
||||
|
||||
//调用改动
|
||||
var dataList = GetData();
|
||||
|
||||
foreach (var data in dataList){
|
||||
|
||||
if (views.TryGetValue(data.Id,out var view))
|
||||
{
|
||||
data.WriteCodes.ForEach(code =>
|
||||
{
|
||||
Event[code]?.Invoke((view.Data,data));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void ViewUpdate(T data, GameObject view)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Register(int code,Action<(GameObject View, T Data)> action)
|
||||
{
|
||||
Event[code] = action;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d099ea459fc642698d0c5dcdbb1fa64a
|
||||
timeCreated: 1726944240
|
Reference in New Issue
Block a user