KROYSDOCS
HomeWhat's newv0.1.0
PLUGIN SDK / Scene / World

World

A scene: the editor document (PluginHost.Document). Reading needs permission scene.read, editing scene.write. Edits of the document are undoable: each call is one undo step, or use PluginHost.Transaction to group several. Calls fail with a KroysException (for example while Play runs, KROYS_E_STATE).

Kindclass
NamespaceKroys.Plugins
Members21
SourceWorld.cs
EXAMPLE

In a plugin

A complete plugin that uses World.

Guides.cs
public sealed class DropToGround : EditorPlugin
{
    public override void OnLoad() =>
        Host.AddCommand(new CommandOptions("Drop", "Drop to Y = 0") { Menu = "Level" }, () =>
        {
            World scene = Host.Document ?? throw new InvalidOperationException("Open a scene first.");
            using (Host.Transaction("Drop to Y = 0"))
            {
                foreach (Entity entity in Host.Selection)
                {
                    Transform transform = scene.GetTransform(entity);
                    transform.Position = transform.Position with { Y = 0.0f };
                    scene.SetTransform(entity, transform);
                    Host.Log($"{scene.GetName(entity)} dropped");
                }
            }
        });
}
REFERENCE

Members

Properties
#public nint Handle { get; }
The raw KroysWorld handle.
property
#public int EntityCount { get; }
Number of entities.
property
#public IReadOnlyList<Entity> Entities { get; }
Every entity (a snapshot).
property
Methods
#public bool IsAlive(Entity entity)
True while the entity exists.
method
#public Entity FindByName(string name)
The first entity with this name (or Entity.None).
method
#public Entity FindByGuid(Guid guid)
The entity with this GUID (or Entity.None).
method
#public Entity CreateEntity(string name, Entity parent = default)
Creates an entity (permission scene.write; undoable).
method
#public void DestroyEntity(Entity entity)
Destroys an entity and its children (undoable).
method
#public string GetName(Entity entity)
The entity's name.
method
#public void SetName(Entity entity, string name)
Renames an entity (undoable).
method
#public Guid GetGuid(Entity entity)
The entity's persistent GUID.
method
#public Entity GetParent(Entity entity)
The parent (or Entity.None).
method
#public void SetParent(Entity entity, Entity parent)
Re-parents an entity (undoable).
method
#public Transform GetTransform(Entity entity)
The local transform.
method
#public void SetTransform(Entity entity, Transform transform)
Sets the local transform (undoable).
method
#public bool HasComponent(Entity entity, ComponentType type)
True when the entity has the component.
method
#public void AddComponent(Entity entity, ComponentType type)
Adds a component (undoable).
method
#public void RemoveComponent(Entity entity, ComponentType type)
Removes a component (undoable).
method
#public object? GetField(Entity entity, ComponentType type, string path)
A reflected field ("speed", "transform.position"): bool, int, float, Vector2/3/4, string, Guid or Entity.
method
#public void SetField(Entity entity, ComponentType type, string path, object value)
Sets a reflected field (undoable).
method
#public IReadOnlyList<Entity> Query(ComponentType type)
Entities with the component.
method
Signatures
public nint Handle { get; }
public int EntityCount { get; }
public IReadOnlyList<Entity> Entities { get; }
public bool IsAlive(Entity entity)
public Entity FindByName(string name)
public Entity FindByGuid(Guid guid)
public Entity CreateEntity(string name, Entity parent = default)
public void DestroyEntity(Entity entity)
public string GetName(Entity entity)
public void SetName(Entity entity, string name)
public Guid GetGuid(Entity entity)
public Entity GetParent(Entity entity)
public void SetParent(Entity entity, Entity parent)
public Transform GetTransform(Entity entity)
public void SetTransform(Entity entity, Transform transform)
public bool HasComponent(Entity entity, ComponentType type)
public void AddComponent(Entity entity, ComponentType type)
public void RemoveComponent(Entity entity, ComponentType type)
public object? GetField(Entity entity, ComponentType type, string path)
public void SetField(Entity entity, ComponentType type, string path, object value)
public IReadOnlyList<Entity> Query(ComponentType type)

KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.