private void CreateBehaviourComponent(NetworkEntityGuid entityGuid) { BaseEntityBehaviourComponent behaviourComponent = BehaviourFactory.Create(entityGuid); if (behaviourComponent is IBehaviourComponentInitializable init) { init.Initialize(); } }
public void Load() { gameState = JsonUtility.FromJson <GameState> ( PlayerPrefs.GetString(Key) ); entityManager.Clear(); foreach (var entity in gameState.entities) { var e = entityGenerator.Generate(entity.type); e.ID = entity.id; var t = e.GameObject.transform; t.position = new Vector3( entity.positionX, entity.positionY, entity.positionZ ); t.localScale = new Vector3( entity.scale, entity.scale, entity.scale ); e.Behaviours.Clear(); foreach (var behaviour in entity.behaviours) { e.Behaviours.Add(behaviourFactory.Create(behaviour.type)); } } if (verbose) { Debug.Log("Scene loaded."); } }
/// <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); }
/// <summary> /// Add specific behaviour for the selected entity. /// </summary> private void AddBehaviour( BehaviourType type) { selector.Selected?.Behaviours.Add(factory.Create(type)); }