Ejemplo n.º 1
0
        private List <Entity> SpawnEntitiesFromBlueprints(Entity parent, GameObject potentialBlueprintGameObject)
        {
            var entitiesSpawned = new List <Entity>();

            Entity entity = null;

            var possibleBlueprint = potentialBlueprintGameObject.GetComponent <IEntityBlueprint>();

            if (possibleBlueprint != null)
            {
                entity = entitySystem.CreateEntity(possibleBlueprint.EntityToSpawn(), false, false);
                var entityGameObject = entity.GameObject;
                if (parent != null)
                {
                    entityGameObject.transform.SetParent(parent.GameObject.transform, true);
                }
                entitiesSpawned.Add(entity);
            }

            var newParent = entity ?? parent;

            foreach (Transform child in potentialBlueprintGameObject.transform)
            {
                var childEntities = SpawnEntitiesFromBlueprints(newParent, child.gameObject);
                entitiesSpawned.AddRange(childEntities);
            }

            return(entitiesSpawned);
        }
Ejemplo n.º 2
0
 public static Entity SpawnNpc(EntityStateSystem entitySystem, NpcTemplate npcTemplate, Vector3 position)
 {
     return(entitySystem.CreateEntity(new List <IState>
     {
         new ActionBlackboardState(null),
         new PrefabState(Prefabs.Person),
         new NameState(npcTemplate.Name.ToString(), 2.0f),
         new PositionState(position),
         new PathfindingState(position, null),
         new InventoryState(),
         new VisibleSlotState(),
         new IsPersonState(),
         new MoodState(Mood.Happy),
         new ConversationState(null),
         new RelationshipState(),
         new DialogueOutcomeState(),
         new PersonAnimationState(),
         new ClothingState(npcTemplate.Top, npcTemplate.Bottom),
         new HairState(npcTemplate.Hair),
         new FaceState(npcTemplate.Face),
         new LifecycleState(),
         new InteractiveState(),
         new SpeciesState(npcTemplate.Species),
         new JobState(npcTemplate.Job)
     }));
 }
Ejemplo n.º 3
0
        public void OnInit()
        {
            var sub = entitySystem.CreateEntity(
                new List <IState>
            {
                new EntityTypeState("The World"),
                new PhysicalState(null, new List <Entity>(), new GridCoordinate(0, 0), 28, 13, true, true)
            },
                null,
                new GridCoordinate(0, 0)
                );

            StaticStates.Get <ActiveEntityState>().ActiveEntity = sub;
            StaticStates.Get <WorldEntityState>().World         = sub;
        }
Ejemplo n.º 4
0
        private void CreateNewItemInStack(Entity stack)
        {
            var states = stack.GameObject.GetComponent <ItemStackVisualizer>().GetNewStackItem();

            var newItem = entitySystem.CreateEntity(states);

            EventSystem.ParentingRequestEvent.Invoke(new ParentingRequest {
                EntityFrom = null, EntityTo = stack, Mover = newItem
            });

            if (stack.GetState <InventoryState>().Child != newItem)
            {
                Debug.LogError("Tried to add the newly created item to the stack but it failed!");
                EntityStateSystem.Instance.RemoveEntity(newItem);
            }
        }
Ejemplo n.º 5
0
        private void SingleClick(int button, GridCoordinate currentlySelectedGrid)
        {
            if (button == 0)
            {
                entitySystem.CreateEntity(
                    StaticStates.Get <EntityLibraryState>().GetSelectedEntity(),
                    StaticStates.Get <ActiveEntityState>().ActiveEntity, currentlySelectedGrid);
            }

            if (button == 1)
            {
                var selectedGrid     = StaticStates.Get <SelectedState>().Grid;
                var activeEntity     = StaticStates.Get <ActiveEntityState>().ActiveEntity;
                var selectedEntities = activeEntity.GetState <PhysicalState>().GetEntitiesAtGrid(selectedGrid).ToList();
                selectedEntities.ForEach(entitySystem.RemoveEntity);
            }
        }