mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交Unity 联机Pro
This commit is contained in:
9
JNFrame2/Assets/JNGame/Sync/View/IViewData.cs
Normal file
9
JNFrame2/Assets/JNGame/Sync/View/IViewData.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace JNGame.Sync.View
|
||||
{
|
||||
public interface IViewData
|
||||
{
|
||||
|
||||
public void Execute();
|
||||
|
||||
}
|
||||
}
|
3
JNFrame2/Assets/JNGame/Sync/View/IViewData.cs.meta
Normal file
3
JNFrame2/Assets/JNGame/Sync/View/IViewData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 480622cdae584eda8bf3d2eb1d37176c
|
||||
timeCreated: 1721188091
|
84
JNFrame2/Assets/JNGame/Sync/View/ViewData.cs
Normal file
84
JNFrame2/Assets/JNGame/Sync/View/ViewData.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
using JNGame.Sync.System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Sync.View
|
||||
{
|
||||
public class ViewGameObject
|
||||
{
|
||||
//更新
|
||||
public int Update;
|
||||
public GameObject Data;
|
||||
}
|
||||
|
||||
public abstract class ViewData<T> : IViewData where T : ISData
|
||||
{
|
||||
|
||||
private Dictionary<long, ViewGameObject> views = new();
|
||||
private SViewSystem root;
|
||||
public SViewSystem Root => root;
|
||||
|
||||
private int Update = 0;
|
||||
|
||||
public ViewData(SViewSystem root)
|
||||
{
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public virtual void Execute()
|
||||
{
|
||||
Update++;
|
||||
|
||||
var dataList = GetData();
|
||||
|
||||
bool isRest = dataList.Length != views.Count;
|
||||
|
||||
foreach (var data in dataList){
|
||||
|
||||
ViewGameObject view;
|
||||
if (!views.TryGetValue(data.Id,out view))
|
||||
{
|
||||
isRest = true;
|
||||
view = new(){Data = NewView(data)};
|
||||
views.Add(data.Id, view);
|
||||
}
|
||||
|
||||
view.Update = Update;
|
||||
ViewUpdate(data,view.Data);
|
||||
|
||||
}
|
||||
|
||||
if (isRest)
|
||||
{
|
||||
List<long> deletes = new List<long>();
|
||||
foreach (var child in views)
|
||||
{
|
||||
if (child.Value.Update != Update)
|
||||
{
|
||||
deletes.Add(child.Key);
|
||||
}
|
||||
}
|
||||
foreach (var delete in deletes)
|
||||
{
|
||||
ViewRemove(views[delete].Data);
|
||||
views.Remove(delete);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public abstract void ViewUpdate(T data,GameObject view);
|
||||
public abstract GameObject NewView(T data);
|
||||
public abstract T[] GetData();
|
||||
|
||||
public abstract void ViewRemove(GameObject view);
|
||||
|
||||
public T GetService<T>() where T : SBaseSystem
|
||||
{
|
||||
return root.GetSystem<T>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
3
JNFrame2/Assets/JNGame/Sync/View/ViewData.cs.meta
Normal file
3
JNFrame2/Assets/JNGame/Sync/View/ViewData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e18d400c170f47439cdbb511f330b7a4
|
||||
timeCreated: 1721188075
|
Reference in New Issue
Block a user