public void createBehaviour(Metadata metadata, BehaviourFactory behaviourFactory) { if (gameObject.GetComponent <ComponentBehaviour>()) { Debug.LogWarning("ComponentBehaviour is already attached.", transform); } else { foreach (var key in Enum.GetValues(typeof(environmentKeys))) { if (metadata.containsMetatagKey(key: key.ToString())) { componentBehaviour = behaviourFactory .CreateBehaviour(gameObject, BaseType.Environment); return; } } if (metadata.containsMetatagKey(key: "highway")) { componentBehaviour = behaviourFactory .CreateBehaviour(gameObject, BaseType.Road); } else { componentBehaviour = behaviourFactory .CreateBehaviour(gameObject, BaseType.Unknown); } } }
private void CreateBehaviourComponent(NetworkEntityGuid entityGuid) { BaseEntityBehaviourComponent behaviourComponent = BehaviourFactory.Create(entityGuid); if (behaviourComponent is IBehaviourComponentInitializable init) { init.Initialize(); } }
public void AddComponent(ComponentDescriptor componentDescriptor) { Type vmType = componentDescriptor.ComponentType; Type componentType = BehaviourViewModelFactory.GetBehaviourFromViewModelProxy(vmType); BehaviourComponent component = BehaviourFactory.CreateFromType(componentType, entityData); entityData.AddComponent(component); //Create a viewmodel proxy for our new component BehaviourViewModel vm = BehaviourViewModelFactory.GetViewModelProxy(component); ComponentAdded?.Invoke(vm); }
static void Main(string[] args) { ICombatHandler combatHandler = new CombatHandler(); IOutputWriter writer = new OutputWriter(); IInputReader reader = new InputReader(); IBehaviourFactory behaviourFactory = new BehaviourFactory(); IBlobFactory blobFactory = new BlobFactory(); IAttackFactory attackFactory = new AttackFactory(); IEngine engine = new Engine.Engine(reader, writer, blobFactory, behaviourFactory, attackFactory, combatHandler); engine.Run(); }
/// <summary> /// Deserializes a given XElement into an entity, with the optional parent /// </summary> /// <param name="element">The xml element to derserialize into an entity</param> /// <param name="parent">The parent of the entity if any</param> /// <remarks>The method uses recursion to deserialize any children</remarks> /// <returns>The Deserialized version of the entity provided in the XElement</returns> private Entity DeserializeSceneEntity(XElement element, Entity parent = null) { Entity entity = new Entity(parent); entity.Name = element.Attribute(nameof(entity.Name))?.Value; string guidAttribute = element.Attribute(nameof(entity.GUID))?.Value; Guid guid; if (guidAttribute != null && Guid.TryParse(guidAttribute, out guid)) { entity.GUID = guid; } else { entity.GUID = Guid.NewGuid(); } IEnumerable <XElement> behaviours = element.Element("Components")?.Elements(); if (behaviours != null) { foreach (XElement behaviourElement in behaviours) { BehaviourComponent behaviour = BehaviourFactory.CreateWithName(behaviourElement.Name.LocalName, entity); if (behaviour != null) { behaviour.Deserialize(behaviourElement); entity.Components.Add(behaviour); } } } IEnumerable <XElement> children = element.Element("Children")?.Elements(); if (children != null) { foreach (XElement childElement in children) { Entity childEntity = DeserializeSceneEntity(childElement, entity); entity.Children.Add(childEntity); } } return(entity); }
static void Main(string[] args) { IDatabase database = new Database.Database(); IAttackFactory attackFactory = new AttackFactory(); IBehaviourFactory behaviourFactory = new BehaviourFactory(); IBlobFactory blobFactory = new BlobFactory(); IController controller = new Controller(database, blobFactory, attackFactory, behaviourFactory); ICommandHandler commandHandler = new CommandHandler(controller); IReader reader = new Reader(); IWriter writer = new Writer(); IEngine engine = new Engine(commandHandler, reader, writer); engine.Run(); }
/// <summary> /// Instantiate the entity game object at specified position. /// </summary> public IEntity Spawn( Vector3 position, Transform parent) { var gameObject = Instantiate( prefab, position, Random.rotationUniform, parent ); // Random scale to spice it up .. var scale = Random.Range(0.5f, 1.0f); gameObject.transform.localScale = new Vector3(scale, scale, scale); var entity = gameObject. GetComponentInChildren <IEntity> (); // Initialize configuration for this instance to // provide data at run-time but keep immutable. if (entity != null) { entity.Config = this; if (initialBehaviour != null) { entity.Behaviours.Add( BehaviourFactory.Create(initialBehaviour) ); } } return(entity); }