예제 #1
0
 public void RemoveEntity(EntityDefinition entity)
 {
     if (entities.Remove(entity))
     {
         entity.factionId     = -1;
         entity.flightGroupId = -1;
     }
 }
예제 #2
0
        public Entity SceneEntityFromDefinitionId(int entityDefinitionId)
        {
            EntityDefinition ed = GetCurrentMission().GetEntities().Find((e) => e.id == entityDefinitionId);

            if (ed == null)
            {
                return(null);
            }
            return(FindSceneEntityById(ed.sceneEntityId));
        }
예제 #3
0
        private void UpdateSceneEntityBookKeeping(Entity sceneEntity, EntityDefinition entityDefinition)
        {
            if (sceneEntity == null && entityDefinition == null)
            {
                return;
            }

            sceneEntityToDefinitionMap.Set(sceneEntity, entityDefinition);
            entityDefinition.sceneEntityId = sceneEntity == null ? -1 : sceneEntity.id;
        }
예제 #4
0
 public void AddEntity(EntityDefinition entity, int index = -1)
 {
     entity.factionId     = factionId;
     entity.flightGroupId = id;
     if (index == -1)
     {
         entities.Add(entity);
     }
     else
     {
         entities.Insert(index, entity);
     }
 }
예제 #5
0
        public Asset DestroyAsset(Asset asset)
        {
            GetAssetMap(asset.GetType()).Remove(asset);
            switch (GetAssetType(asset.GetType()))
            {
            case AssetType.EntityDefinition:
                EntityDefinition ed = (EntityDefinition)asset;
                FindAsset <FlightGroupDefinition>(ed.flightGroupId)?.entities.Remove(ed);
                break;

            case AssetType.FlighGroupDefinition:
                FlightGroupDefinition fg = (FlightGroupDefinition)asset;
                FindAsset <FactionDefinition>(fg.factionId)?.flightGroups.Remove(fg);
                break;

            case AssetType.ShipType:
                ShipType shipType = (ShipType)asset;
                FindAsset <ShipTypeGroup>(shipType.shipGroupId)?.ships.Remove(shipType);
                break;
            }
            return(asset);
        }
예제 #6
0
        public void LinkSceneEntity(Entity sceneEntity, EntityDefinition entityDefinition)
        {
            Debug.Assert(entityDefinition != null, "entityDefinition != null");

            SetSceneEntityName(sceneEntity, entityDefinition);
            UpdateSceneEntityBookKeeping(sceneEntity, entityDefinition);

            if (sceneEntity == null)
            {
                return;
            }

            if (sceneEntity.id == entityDefinition.sceneEntityId)
            {
                // update
                SetChassisFromShipType(sceneEntity, entityDefinition.chassisGuid);
            }
            else
            {
                // new assignment
                SetShipTypeFromChassis(sceneEntity, entityDefinition);
            }
        }
예제 #7
0
        public void UpdateSceneEntities()
        {
            CollectSceneEntities();

            bool didChange = false;

            for (int i = 0; i < sceneEntities.Count; i++)
            {
                int storedId;

                Entity           sceneEntity = sceneEntities[i];
                EntityDefinition definition;

                Chassis entityChassis = sceneEntity.GetComponent <Chassis>();
                if (entityChassis != null)
                {
                    Debug.Log($"Removed Chassis from {sceneEntity.name} because you cannot have both an entity and a Chassis component");
                    Object.DestroyImmediate(entityChassis);
                }

                int currentId = sceneEntity.id;

                if (sceneEntityToSceneIdMap.TryGetValue(sceneEntity, out storedId))
                {
                    Debug.Assert(currentId == storedId, $"Should never hit this. Expected {currentId} to be {storedId}");
                    definition = GetEntityDefinitionForSceneEntity(sceneEntity);
                }
                else
                {
                    Debug.Log(sceneEntity.name);
                    didChange      = true;
                    sceneEntity.id = GetCurrentMission().AllocateEntityId();
                    EditorUtility.SetDirty(sceneEntity); // todo -- dev only
                    if (currentId != 0)
                    {
                        Debug.Log("Duplicated");
                        EntityDefinition toClone = GetEntityDefinitionForSceneEntity(currentId);
                        definition = currentMission.CloneEntityDefinition(toClone);
                    }
                    else
                    {
                        Debug.Log("Created");
                        definition = currentMission.CreateEntityDefinition();
                    }
                }

                // if a new one is created, add a definition and link
                // if a one is duplicated, clone definition and link
                // we *might* have unlinked scene entities which is ok

                sceneEntityToSceneIdMap.Set(sceneEntity, sceneEntity.id);
                sceneEntityToDefinitionMap.Set(sceneEntity, definition);

                SetSceneEntityName(sceneEntity, definition);
            }

            GetCurrentMission().Change();

            if (didChange)
            {
                EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
            }
        }