@@ -1,10 +0,0 @@
-namespace ET.Client
-{
- public class SessionComponentDestroySystem: DestroySystem<SessionComponent>
- {
- protected override void Destroy(SessionComponent self)
- self.Session?.Dispose();
- }
-}
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 2a5119adf4d729744980440346d1414e
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
@@ -3,17 +3,17 @@
[ComponentOf(typeof(Scene))]
public class SessionComponent: Entity, IAwake, IDestroy
{
- private long sessionInstanceId;
+ private EntityRef<Session> session;
public Session Session
get
- return Root.Instance.Get(this.sessionInstanceId) as Session;
+ return this.session;
}
set
- this.sessionInstanceId = value.InstanceId;
+ this.session = value;
[ComponentOf(typeof(Player))]
public class PlayerSessionComponent : Entity, IAwake
[ComponentOf(typeof(Session))]
public class SessionPlayerComponent : Entity, IAwake, IDestroy
- private long playerInstanceId;
+ private EntityRef<Player> player;
public Player Player
- return Root.Instance.Get(this.playerInstanceId) as Player;
+ return this.player;
- this.playerInstanceId = value.InstanceId;
+ this.player = value;
@@ -10,17 +10,17 @@ namespace ET.Server
public int ViewDistance;
- private long cellInstanceId;
+ private EntityRef<Cell> cell;
public Cell Cell
- return Root.Instance.Get(this.cellInstanceId) as Cell;
+ return this.cell;
- this.cellInstanceId = value.InstanceId;
+ this.cell = value;
@@ -10,18 +10,18 @@ namespace ET
public SceneType SceneType { get; set; } = SceneType.Room;
public string Name { get; set; }
- private long lsWorldInstanceId;
+ private EntityRef<LSWorld> lsWorld;
public LSWorld LSWorld
- return Root.Instance.Get(this.lsWorldInstanceId) as LSWorld;
+ return this.lsWorld;
this.AddChild(value);
- this.lsWorldInstanceId = value.InstanceId;
+ this.lsWorld = value;
@@ -4,17 +4,17 @@
public class CurrentScenesComponent: Entity, IAwake
- private long sceneInstanceId;
+ private EntityRef<Scene> scene;
public Scene Scene
- return Root.Instance.Get(this.sceneInstanceId) as Scene;
+ return this.scene;
- this.sceneInstanceId = value.InstanceId;
+ this.scene = value;
@@ -23,21 +23,17 @@ namespace ET.Client
- private long unitViewInstanceId;
+ private EntityRef<LSUnitView> unitView;
public LSUnitView MyUnitView
- return Root.Instance.Get(this.unitViewInstanceId) as LSUnitView;
+ return this.unitView;
- if (value == null)
- return;
- this.unitViewInstanceId = value.InstanceId;
+ this.unitView = value;
@@ -0,0 +1,42 @@
+using System;
+
+namespace ET
+{
+ public readonly struct EntityRef<T> where T: Entity
+ {
+ private readonly long instanceId;
+ private readonly T entity;
+ private EntityRef(T t)
+ this.instanceId = t.InstanceId;
+ this.entity = t;
+ }
+ private T UnWrap
+ get
+ if (this.entity == null)
+ return null;
+ if (this.entity.InstanceId != this.instanceId)
+ return this.entity;
+ public static implicit operator EntityRef<T>(T t)
+ return new EntityRef<T>(t);
+ public static implicit operator T(EntityRef<T> v)
+ return v.UnWrap;
+}
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 2119824a0cfc4b7ab9717faf0884210d
+timeCreated: 1683204652