mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
// 进入视野通知
|
||||
[Event(SceneType.Map)]
|
||||
public class UnitEnterSightRange_NotifyClient: AEvent<Scene, EventType.UnitEnterSightRange>
|
||||
{
|
||||
protected override async ETTask Run(Scene scene, EventType.UnitEnterSightRange args)
|
||||
{
|
||||
AOIEntity a = args.A;
|
||||
AOIEntity b = args.B;
|
||||
if (a.Id == b.Id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Unit ua = a.GetParent<Unit>();
|
||||
if (ua.Type != UnitType.Player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Unit ub = b.GetParent<Unit>();
|
||||
|
||||
MessageHelper.NoticeUnitAdd(ua, ub);
|
||||
|
||||
await ETTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92a7bfbd50423e64b994beb9fe3ddad2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
public static partial class UnitFactory
|
||||
{
|
||||
public static Unit Create(Scene scene, long id, UnitType unitType)
|
||||
{
|
||||
UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
|
||||
switch (unitType)
|
||||
{
|
||||
case UnitType.Player:
|
||||
{
|
||||
Unit unit = unitComponent.AddChildWithId<Unit, int>(id, 1001);
|
||||
unit.AddComponent<MoveComponent>();
|
||||
unit.Position = new float3(-10, 0, -10);
|
||||
|
||||
NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
|
||||
numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒
|
||||
numericComponent.Set(NumericType.AOI, 15000); // 视野15米
|
||||
|
||||
unitComponent.Add(unit);
|
||||
// 加入aoi
|
||||
unit.AddComponent<AOIEntity, int, float3>(9 * 1000, unit.Position);
|
||||
return unit;
|
||||
}
|
||||
default:
|
||||
throw new Exception($"not such unit type: {unitType}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 359d93a0f7fdfa44bbc572328e9742f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[FriendOf(typeof(MoveComponent))]
|
||||
[FriendOf(typeof(NumericComponent))]
|
||||
public static partial class UnitHelper
|
||||
{
|
||||
public static UnitInfo CreateUnitInfo(Unit unit)
|
||||
{
|
||||
UnitInfo unitInfo = new();
|
||||
NumericComponent nc = unit.GetComponent<NumericComponent>();
|
||||
unitInfo.UnitId = unit.Id;
|
||||
unitInfo.ConfigId = unit.ConfigId;
|
||||
unitInfo.Type = (int)unit.Type;
|
||||
unitInfo.Position = unit.Position;
|
||||
unitInfo.Forward = unit.Forward;
|
||||
|
||||
MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
|
||||
if (moveComponent != null)
|
||||
{
|
||||
if (!moveComponent.IsArrived())
|
||||
{
|
||||
unitInfo.MoveInfo = new MoveInfo();
|
||||
unitInfo.MoveInfo.Points.Add(unit.Position);
|
||||
for (int i = moveComponent.N; i < moveComponent.Targets.Count; ++i)
|
||||
{
|
||||
float3 pos = moveComponent.Targets[i];
|
||||
unitInfo.MoveInfo.Points.Add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((int key, long value) in nc.NumericDic)
|
||||
{
|
||||
unitInfo.KV.Add(key, value);
|
||||
}
|
||||
|
||||
return unitInfo;
|
||||
}
|
||||
|
||||
// 获取看见unit的玩家,主要用于广播
|
||||
public static Dictionary<long, AOIEntity> GetBeSeePlayers(this Unit self)
|
||||
{
|
||||
return self.GetComponent<AOIEntity>().GetBeSeePlayers();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcdc9f9c96c0ff146ac609ff97b4903a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
namespace ET.Server
|
||||
{
|
||||
// 离开视野
|
||||
[Event(SceneType.Map)]
|
||||
public class UnitLeaveSightRange_NotifyClient: AEvent<Scene, EventType.UnitLeaveSightRange>
|
||||
{
|
||||
protected override async ETTask Run(Scene scene, EventType.UnitLeaveSightRange args)
|
||||
{
|
||||
await ETTask.CompletedTask;
|
||||
AOIEntity a = args.A;
|
||||
AOIEntity b = args.B;
|
||||
if (a.Unit.Type != UnitType.Player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MessageHelper.NoticeUnitRemove(a.GetParent<Unit>(), b.GetParent<Unit>());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10a2365c686050546995d6a3897b9038
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user