mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Shared.GameObjects
|
|
{
|
|
[CopyByRef, Serializable]
|
|
public sealed class IEntity
|
|
{
|
|
#region Members
|
|
|
|
[ViewVariables]
|
|
public EntityUid Uid { get; }
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public string Name
|
|
{
|
|
get => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Uid).EntityName;
|
|
set => IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Uid).EntityName = value;
|
|
}
|
|
|
|
[ViewVariables]
|
|
public TransformComponent Transform => IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Uid);
|
|
|
|
#endregion Members
|
|
|
|
#region Initialization
|
|
|
|
public IEntity(EntityUid uid)
|
|
{
|
|
Uid = uid;
|
|
}
|
|
|
|
#endregion Initialization
|
|
|
|
#region Components
|
|
|
|
public bool HasComponent<T>()
|
|
{
|
|
return IoCManager.Resolve<IEntityManager>().HasComponent<T>(Uid);
|
|
}
|
|
|
|
public bool HasComponent(Type type)
|
|
{
|
|
return IoCManager.Resolve<IEntityManager>().HasComponent(Uid, type);
|
|
}
|
|
|
|
public bool TryGetComponent<T>([NotNullWhen(true)] out T? component) where T : class
|
|
{
|
|
return IoCManager.Resolve<IEntityManager>().TryGetComponent(Uid, out component);
|
|
}
|
|
|
|
public T? GetComponentOrNull<T>() where T : class, IComponent
|
|
{
|
|
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<T>(Uid);
|
|
}
|
|
|
|
public bool TryGetComponent(Type type, [NotNullWhen(true)] out IComponent? component)
|
|
{
|
|
return IoCManager.Resolve<IEntityManager>().TryGetComponent(Uid, type, out component);
|
|
}
|
|
|
|
#endregion Components
|
|
}
|
|
}
|