zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/Model/Core/Entity/Scene.cs

110 lines
2.6 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System.Linq;
namespace ET
{
public sealed class Scene: Entity
{
public int Zone
{
get;
}
public SceneType SceneType
{
get;
}
public string Name
{
get;
set;
}
public Scene(long id, int zone, SceneType sceneType, string name)
{
this.Id = id;
this.InstanceId = id;
this.Zone = zone;
this.SceneType = sceneType;
this.Name = name;
this.IsCreate = true;
Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
}
public Scene(long id, long instanceId, int zone, SceneType sceneType, string name)
{
this.Id = id;
this.InstanceId = instanceId;
this.Zone = zone;
this.SceneType = sceneType;
this.Name = name;
this.IsCreate = true;
Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
}
public override void Dispose()
{
base.Dispose();
Log.Info($"scene dispose: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
}
public Scene Get(long id)
{
if (this.Children == null)
{
return null;
}
if (!this.Children.TryGetValue(id, out Entity entity))
{
return null;
}
return entity as Scene;
}
public Scene Get(string name)
{
if (this.Children == null)
{
return null;
}
Entity entity= Children.FirstOrDefault(t => t.Value.As<Scene>().Name == name).Value;
return entity as Scene;
}
public new Entity Domain
{
get => this.domain;
set => this.domain = value;
}
public new Entity Parent
{
get
{
return this.parent;
}
set
{
if (value == null)
{
this.parent = this;
return;
}
this.parent = value;
this.parent.Children.Add(this.Id, this);
#if UNITY_EDITOR && VIEWGO
if (this.ViewGO != null)
{
this.ViewGO.transform.SetParent(this.parent.ViewGO.transform, false);
}
#endif
}
}
}
}