mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
优化属性更新逻辑
This commit is contained in:
3
JNFrame2/Assets/Scripts/Game/Data/State.meta
Normal file
3
JNFrame2/Assets/Scripts/Game/Data/State.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cecc61f462364f198db69cf70c6c557d
|
||||
timeCreated: 1726941153
|
@@ -10,6 +10,10 @@ using JNGame.Sync.System.Data;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
public enum EDPlayerValueCode : int
|
||||
{
|
||||
Auth = 201
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EDPlayerValue : GDataValue
|
||||
@@ -46,7 +50,11 @@ namespace Game.JNGState.Logic.Data
|
||||
public override void UData(EDPlayerValue data)
|
||||
{
|
||||
base.UData(data);
|
||||
if (data.Auth is not null) Value.Auth = data.Auth;
|
||||
if (data.Auth is not null)
|
||||
{
|
||||
Value.Auth = data.Auth;
|
||||
WriteUpdate((int)EDPlayerValueCode.Auth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,17 +9,41 @@ using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
using Plugins.JNGame.Util;
|
||||
using TouchSocket.Core;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
|
||||
public enum GDataValueCode : int
|
||||
{
|
||||
Position = 101
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class GDataValue
|
||||
{
|
||||
public DValuePosition Position = null;
|
||||
}
|
||||
|
||||
public abstract class IGDataBase : ISTileData
|
||||
{
|
||||
|
||||
//计入修改
|
||||
public readonly ConcurrentList<int> WriteCodes = new();
|
||||
|
||||
/// <summary>
|
||||
/// 计入修改
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
public void WriteUpdate(int code)
|
||||
{
|
||||
if (WriteCodes.Contains(code)) return;
|
||||
WriteCodes.Add(code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class GDataBase<Self,T,N> : ISTileData where Self : GDataBase<Self,T,N> where T : GDataValue,new() where N : JNTileEntity
|
||||
public class GDataBase<Self,T,N> : IGDataBase where Self : GDataBase<Self,T,N> where T : GDataValue,new() where N : JNTileEntity
|
||||
{
|
||||
|
||||
public readonly T Value = new ();
|
||||
@@ -93,7 +117,11 @@ namespace Game.JNGState.Logic.Data
|
||||
/// </summary>
|
||||
public virtual void UData(T data)
|
||||
{
|
||||
if (data.Position is not null) Value.Position = data.Position;
|
||||
if (data.Position is not null)
|
||||
{
|
||||
Value.Position = data.Position;
|
||||
WriteUpdate((int)GDataValueCode.Position);
|
||||
}
|
||||
}
|
||||
|
||||
public override LVector3 GetDataPosition()
|
@@ -12,29 +12,30 @@ using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
public class VDBoss : ViewData<EDBossData>
|
||||
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);
|
||||
}
|
||||
|
||||
public override void ViewUpdate(EDBossData data, GameObject view)
|
||||
private void OnUpdatePosition((GameObject View, EDBossData Data) tuple)
|
||||
{
|
||||
|
||||
view.name = $"Boss_{data.Id}";
|
||||
var (view, data) = tuple;
|
||||
if (data.Value.Position != null)
|
||||
{
|
||||
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override GameObject NewView(EDBossData data)
|
||||
{
|
||||
return Object.Instantiate(Boss, VWorld.transform);
|
||||
var view = Object.Instantiate(Boss, VWorld.transform);
|
||||
view.name = $"Boss_{data.Id}";
|
||||
return view;
|
||||
}
|
||||
|
||||
public override EDBossData[] GetData()
|
||||
|
@@ -10,28 +10,32 @@ using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
public class VDNodes : ViewData<EDNodeData>
|
||||
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);
|
||||
}
|
||||
|
||||
public override void ViewUpdate(EDNodeData data, GameObject view)
|
||||
/// <summary>
|
||||
/// 更新位置
|
||||
/// </summary>
|
||||
private void OnUpdatePosition((GameObject View, EDNodeData Data) tuple)
|
||||
{
|
||||
|
||||
view.name = $"Node_{data.Id}";
|
||||
var (view, data) = tuple;
|
||||
if (data.Value.Position != null)
|
||||
{
|
||||
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override GameObject NewView(EDNodeData data)
|
||||
{
|
||||
return Object.Instantiate(Player, VWorld.transform);
|
||||
var view = Object.Instantiate(Player, VWorld.transform);
|
||||
view.name = $"Node_{data.Id}";
|
||||
return view;
|
||||
}
|
||||
|
||||
public override EDNodeData[] GetData()
|
||||
|
@@ -9,7 +9,7 @@ using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
public class VDPlayers : ViewData<EDPlayerData>
|
||||
public class VDPlayers : VDEntityBasis<EDPlayerData>
|
||||
{
|
||||
public GameObject VWorld => App.Resource.VWorld;
|
||||
public GameObject Player => App.Resource.Player;
|
||||
@@ -17,17 +17,41 @@ namespace Game.JNGFrame.View.Entity
|
||||
|
||||
public VDPlayers(SViewSystem root) : base(root)
|
||||
{
|
||||
|
||||
Register((int)GDataValueCode.Position, OnUpdatePosition);
|
||||
Register((int)EDPlayerValueCode.Auth, OnUpdateAuth);
|
||||
|
||||
}
|
||||
|
||||
public override void ViewUpdate(EDPlayerData data, GameObject view)
|
||||
/// <summary>
|
||||
/// 更新坐标
|
||||
/// </summary>
|
||||
/// <param name="tuple"></param>
|
||||
private void OnUpdatePosition((GameObject View, EDPlayerData Data) tuple)
|
||||
{
|
||||
view.name = $"Player_{data.Id}";
|
||||
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)
|
||||
@@ -37,17 +61,14 @@ namespace Game.JNGFrame.View.Entity
|
||||
FreeLook.LookAt = view.transform;
|
||||
FreeLook.Follow = view.transform;
|
||||
|
||||
//更新玩家位置
|
||||
if (data.Value.Position != null) App.Game.GetClient<JNGTileClientSystem>()?.SetPlayerPosition(data.Value.Position.ToLVector3());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override GameObject NewView(EDPlayerData data)
|
||||
{
|
||||
var gameObject = Object.Instantiate(Player, VWorld.transform);
|
||||
// gameObject.transform.DOMove(gameObject.transform.position + new Vector3(0,0,1000), 100);
|
||||
gameObject.name = $"Player_{data.Id}";
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
|
54
JNFrame2/Assets/Scripts/Game/View/VDEntityBasis.cs
Normal file
54
JNFrame2/Assets/Scripts/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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
3
JNFrame2/Assets/Scripts/Game/View/VDEntityBasis.cs.meta
Normal file
3
JNFrame2/Assets/Scripts/Game/View/VDEntityBasis.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d099ea459fc642698d0c5dcdbb1fa64a
|
||||
timeCreated: 1726944240
|
Reference in New Issue
Block a user