4 using System.Collections;
5 using System.Collections.Generic;
6 using System.Diagnostics;
8 using System.Threading.Tasks;
10 using SiliconStudio.Core.Mathematics;
11 using SiliconStudio.Core.Serialization.Converters;
12 using SiliconStudio.Paradox.Engine;
13 using SiliconStudio.Core;
14 using SiliconStudio.Core.Serialization.Contents;
15 using SiliconStudio.Core.Serialization.Serializers;
17 namespace SiliconStudio.
Paradox.EntityModel
24 [DebuggerTypeProxy(typeof(EntityDebugView))]
25 [
DataConverter(AutoGenerate =
false, ContentReference =
true)]
26 [DataSerializer(typeof(EntitySerializer))]
27 [ContentSerializer(typeof(DataContentConverterSerializer<Entity>))]
31 internal List<Task> prepareTasks;
35 PropertyContainer.AddAccessorProperty(typeof(
Entity), TransformationComponent.Key);
63 Tags.PropertyUpdated += EntityPropertyUpdated;
66 transformation.Translation = position;
75 get {
return transformation; }
78 var transformationOld = transformation;
79 transformation = value;
80 Tags.RaisePropertyContainerUpdated(TransformationComponent.Key, transformation, transformationOld);
91 var key = EntityComponent.GetDefaultKey<T>();
92 var component = Tags.Get(key);
93 if (component == null)
96 Tags.SetObject(key, component);
110 var component = Tags.Get(key);
111 if (component == null)
114 Tags.Set(key, component);
125 public void Add(EntityComponent component)
127 if (component == null)
throw new ArgumentNullException(
"component");
128 Tags.SetObject(component.DefaultKey, component);
137 public T Get<T>() where T : EntityComponent,
new()
139 return (T)Tags.Get(EntityComponent.GetDefaultKey<T>());
151 if (key == null)
throw new ArgumentNullException(
"key");
152 return Tags.Get(key);
164 if (key == null)
throw new ArgumentNullException(
"key");
165 Tags.SetObject(key, value);
175 [Obsolete(
"Use Add() method instead")]
178 if (key == null)
throw new ArgumentNullException(
"key");
179 Tags.SetObject(key, value);
185 if (oldValue is EntityComponent)
187 ((EntityComponent)oldValue)
.Entity = null;
191 if (newValue is EntityComponent)
193 ((EntityComponent)newValue).Entity =
this;
197 internal class EntityDebugView
199 private readonly Entity entity;
201 public EntityDebugView(Entity entity)
203 this.entity = entity;
208 get {
return entity.Name; }
215 var transformationComponent = entity.Transformation;
216 if (transformationComponent == null)
219 return transformationComponent.Children.Select(x => x.Entity).ToArray();
223 public EntityComponent[] Components
227 return entity.Tags.Select(x => x.Value).OfType<EntityComponent>().ToArray();
234 return string.Format(
"Entity {0}", Name);
237 IEnumerator IEnumerable.GetEnumerator()
239 return Tags.Values.OfType<EntityComponent>().GetEnumerator();
242 string IContentUrl.Url {
get; set; }
Interface for serializable object having an url (so referenceable by other assets and saved into a si...
Game entity. It usually aggregates multiple EntityComponent
Entity(string name)
Create a new Entity instance having the provided name.
Represents a container that can hold properties, lightweight to embed (lazy initialized).
Base class for converters to/from a data type.
Represents a three dimensional mathematical vector.
Entity()
Create a new Entity instance.
Base class for a framework component.
A class that represents a typed tag propety.
TransformationComponent transformation
Entity(Vector3 position, string name=null)
Create a new Entity instance having the provided name and initial position.
override string ToString()
void Add(EntityComponent component)
Adds the specified component using the EntityComponent.DefaultKey.
A class that represents a tag propety.