This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-10-14 03:07:34 +08:00
parent edafe4a058
commit d56c133a75
5989 changed files with 8767 additions and 441137 deletions

View File

@@ -0,0 +1,9 @@
namespace JNGame.Sync.View
{
public interface IViewData
{
public void Execute();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 480622cdae584eda8bf3d2eb1d37176c
timeCreated: 1721188091

View 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
{
protected Dictionary<ulong, 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<ulong> deletes = new List<ulong>();
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>();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e18d400c170f47439cdbb511f330b7a4
timeCreated: 1721188075