提交bug 艰难先这样

This commit is contained in:
PC-20230316NUNE\Administrator
2024-08-22 20:37:39 +08:00
parent 5858bd2407
commit 8932528f5e
118 changed files with 5271 additions and 4939 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using JNGame.Sync.Entity;
using JNGame.Sync.Frame.Entity;
using JNGame.Sync.Frame.Entity.Components;
using UnityEngine;
namespace JNGame.Sync.State.Tile.Entity
{
@@ -44,6 +45,17 @@ namespace JNGame.Sync.State.Tile.Entity
public T TileSyncCreate(long id)
{
//判断是否有这个Id实体
foreach (var data in GetEntities())
{
if (data.Id == id)
{
Debug.Log("重复Id实体创建");
return null;
}
}
var entity = NewEntity();
entity.OnInit(this,id);
entity.IsHost = false;

View File

@@ -26,55 +26,10 @@ namespace JNGame.Sync.State.Tile
/// 区块大小
/// </summary>
protected abstract int TileSize { get; }
public bool IsTileIndex((int X, int Y) xTuple)
{
if (xTuple.X >= 0 && xTuple.Y >= 0)
{
return xTuple.Y < Tiles.Length && xTuple.X < Tiles[0].Length;
}
return false;
}
public int GetTileIndex(LVector3 pos)
{
(int x, int y) = GetXYIndex(pos);
return Tiles[y][x];
}
public (int X, int Y) GetXYIndex(LVector3 pos)
{
// 遍历数组
for (int y = 0; y < Tiles.Length; y++)
{
for (int x = 0; x < Tiles[y].Length; x++)
{
// 检查当前元素是否非零
if (Tiles[y][x] != 0)
{
//判断是否所在区块
var min = new LVector2(x.ToLFloat() * TileSize,y.ToLFloat() * TileSize);
var max = new LVector2((x + 1).ToLFloat() * TileSize,(y + 1).ToLFloat() * TileSize);
// 假设LVector2是一个包含X和Y属性的结构体或类
// 检查X坐标是否在范围内
if (pos.x < min.x || pos.x >= max.x)
{
continue; // X坐标不在范围内
}
// 检查Y坐标是否在范围内
if (pos.z < min.y || pos.z >= max.y)
{
continue; // Y坐标不在范围内
}
return (x,y);
}
}
}
return (0,0);
return JNSSTileTool.GetTileIndex(Tiles, TileSize, pos);
}
/// <summary>
@@ -83,23 +38,7 @@ namespace JNGame.Sync.State.Tile
/// <returns></returns>
public List<int> GetTileGridIndex(LVector3 pos)
{
(int x, int y) = GetXYIndex(pos);
List<int> grid = new List<int>();
// 填充九宫格
for (int i = -1; i <= 1; i++)
{
for (int j = -1; j <= 1; j++)
{
int tempX = x + i;
int tempY = y + j; // 注意这里j+1+1是因为数组第二维存储的是y坐标
if (IsTileIndex((tempX,tempY))) grid.Add(Tiles[tempY][tempX]);
}
}
return grid;
return JNSSTileTool.GetTileGridIndex(Tiles, TileSize,pos);
}
public void AddTileShow(int index)

View File

@@ -70,7 +70,7 @@ namespace JNGame.Sync.State.Tile
{
//根据区块设置Id 起始值
var random = base.CreateRandom();
random.SetIdValue(100000000000L * TID);
random.SetIdValue(100000000000L * TID,(100000000000L * (TID + 1) - 1));
return random;
}
@@ -78,15 +78,6 @@ namespace JNGame.Sync.State.Tile
{
return new JNTileContexts();
}
public bool IsTileIndex((int X, int Y) xTuple)
{
if (xTuple.X >= 0 && xTuple.Y >= 0)
{
return xTuple.Y < Tiles.Length && xTuple.X < Tiles[0].Length;
}
return false;
}
/// <summary>
/// 更新区块范围
@@ -110,6 +101,11 @@ namespace JNGame.Sync.State.Tile
}
}
public int GetTileIndex(LVector3 pos)
{
return JNSSTileTool.GetTileIndex(Tiles, TileSize, pos);
}
/// <summary>
/// 判断位置是否在区块内
@@ -117,16 +113,20 @@ namespace JNGame.Sync.State.Tile
/// <param name="pos"></param>
/// <returns></returns>
public bool IsContains(LVector3 position)
{
return IsContains(position,MaxContains,MinContains);
}
public bool IsContains(LVector3 position,LVector3 Max,LVector3 Min)
{
// 假设LVector2是一个包含X和Y属性的结构体或类
// 检查X坐标是否在范围内
if (position.x < MinContains.x || position.x >= MaxContains.x)
if (position.x < Min.x || position.x >= Max.x)
{
return false; // X坐标不在范围内
}
// 检查Y坐标是否在范围内
if (position.z < MinContains.y || position.z >= MaxContains.y)
if (position.z < Min.y || position.z >= Max.y)
{
return false; // Y坐标不在范围内
}
@@ -141,35 +141,7 @@ namespace JNGame.Sync.State.Tile
/// <returns></returns>
public (LVector2 Max,LVector2 Min) GetTileContains(int index)
{
(int X, int Y) = GetTileIDXY(index);
var min = new LVector2(X.ToLFloat() * TileSize,Y.ToLFloat() * TileSize);
var max = new LVector2((X + 1).ToLFloat() * TileSize,(Y + 1).ToLFloat() * TileSize);
return (max,min);
}
/// <summary>
/// 获取TileID X Y
/// </summary>
/// <returns></returns>
public (int X, int Y) GetTileIDXY(int index)
{
// 遍历数组
for (int y = 0; y < Tiles.Length; y++)
{
for (int x = 0; x < Tiles[y].Length; x++)
{
// 检查当前元素是否非零
if (Tiles[y][x] != 0 && Tiles[y][x] == index)
{
// 返回找到的坐标
return (x,y);
}
}
}
throw new Exception();
return JNSSTileTool.GetTileContains(Tiles,TileSize,index);
}
/// <summary>
@@ -178,22 +150,7 @@ namespace JNGame.Sync.State.Tile
/// <returns></returns>
public List<int> GetTileGridIndex(int index)
{
List<int> grid = new List<int>();
(int X, int Y) = GetTileIDXY(index);
// 填充九宫格
for (int i = -1; i <= 1; i++)
{
for (int j = -1; j <= 1; j++)
{
int tempX = X + i;
int tempY = Y + j; // 注意这里j+1+1是因为数组第二维存储的是y坐标
if (IsTileIndex((tempX,tempY))) grid.Add(Tiles[tempY][tempX]);
}
}
return grid;
return JNSSTileTool.GetTileGridIndex(Tiles,TileSize,index);
}
/// <summary>

View File

@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using JNGame.Math;
namespace JNGame.Sync.State.Tile
{
public class JNSSTileTool
{
public static bool IsTileIndex(int[][] Tiles,(int X, int Y) xTuple)
{
if (xTuple.X >= 0 && xTuple.Y >= 0)
{
return xTuple.Y < Tiles.Length && xTuple.X < Tiles[0].Length;
}
return false;
}
/// <summary>
/// 获取TileID X Y
/// </summary>
/// <returns></returns>
public static (int X, int Y) GetTileIDXY(int[][] Tiles,int index)
{
// 遍历数组
for (int y = 0; y < Tiles.Length; y++)
{
for (int x = 0; x < Tiles[y].Length; x++)
{
// 检查当前元素是否非零
if (Tiles[y][x] != 0 && Tiles[y][x] == index)
{
// 返回找到的坐标
return (x,y);
}
}
}
throw new Exception();
}
/// <summary>
/// 根据TileId 获取最大最小范围
/// </summary>
/// <returns></returns>
public static (LVector2 Max,LVector2 Min) GetTileContains(int[][] Tiles, int TileSize,int index)
{
(int X, int Y) = GetTileIDXY(Tiles,index);
var min = new LVector2(X.ToLFloat() * TileSize,Y.ToLFloat() * TileSize);
var max = new LVector2((X + 1).ToLFloat() * TileSize,(Y + 1).ToLFloat() * TileSize);
return (max,min);
}
/// <summary>
/// 获取九宫格Index
/// </summary>
/// <returns></returns>
public static List<int> GetTileGridIndex(int[][] Tiles, int TileSize, (int X, int Y) xTuple)
{
List<int> grid = new List<int>();
// 填充九宫格
for (int i = -1; i <= 1; i++)
{
for (int j = -1; j <= 1; j++)
{
int tempX = xTuple.X + i;
int tempY = xTuple.Y + j; // 注意这里j+1+1是因为数组第二维存储的是y坐标
if (IsTileIndex(Tiles,(tempX,tempY))) grid.Add(Tiles[tempY][tempX]);
}
}
return grid;
}
public static List<int> GetTileGridIndex(int[][] Tiles, int TileSize, int index)
{
return GetTileGridIndex(Tiles,TileSize,GetTileIDXY(Tiles,index));
}
public static List<int> GetTileGridIndex(int[][] Tiles,int TileSize,LVector3 pos)
{
return GetTileGridIndex(Tiles,TileSize,GetXYIndex(Tiles,TileSize,pos));
}
/// <summary>
/// 获取Index
/// </summary>
/// <param name="Tiles"></param>
/// <param name="TileSize"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static int GetTileIndex(int[][] Tiles,int TileSize,LVector3 pos)
{
(int x, int y) = JNSSTileTool.GetXYIndex(Tiles,TileSize,pos);
return Tiles[y][x];
}
/// <summary>
/// 获取XY
/// </summary>
/// <param name="Tiles"></param>
/// <param name="TileSize"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static (int X, int Y) GetXYIndex(int[][] Tiles,int TileSize,LVector3 pos)
{
// 遍历数组
for (int y = 0; y < Tiles.Length; y++)
{
for (int x = 0; x < Tiles[y].Length; x++)
{
// 检查当前元素是否非零
if (Tiles[y][x] != 0)
{
//判断是否所在区块
var min = new LVector2(x.ToLFloat() * TileSize,y.ToLFloat() * TileSize);
var max = new LVector2((x + 1).ToLFloat() * TileSize,(y + 1).ToLFloat() * TileSize);
// 假设LVector2是一个包含X和Y属性的结构体或类
// 检查X坐标是否在范围内
if (pos.x < min.x || pos.x >= max.x)
{
continue; // X坐标不在范围内
}
// 检查Y坐标是否在范围内
if (pos.z < min.y || pos.z >= max.y)
{
continue; // Y坐标不在范围内
}
return (x,y);
}
}
}
return (0,0);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 44baac66240645d887c8996de748dd0c
timeCreated: 1724315108