コード例 #1
0
        public void OnEntityCreated(SpatialOSEntityInfo entityInfo, GameObject prefab, EntityManager entityManager, EntityGameObjectLinker linker)
        {
            var transformInternal = entityManager.GetComponentData <TransformInternal.Component>(entityInfo.Entity);
            var position          = transformInternal.Location.ToUnityVector() + workerOrigin;
            var rotation          = transformInternal.Rotation.ToUnityQuaternion();

            var gameObject = Object.Instantiate(prefab, position, rotation);

            gameObject.name = $"{prefab.name}(SpatialOS: {entityInfo.SpatialOSEntityId}, Worker: {workerType})";

            entityIdToGameObject.Add(entityInfo.SpatialOSEntityId, gameObject);
            linker.LinkGameObjectToSpatialOSEntity(entityInfo.SpatialOSEntityId, gameObject, componentsToAdd);
        }
コード例 #2
0
        public void OnEntityCreated(SpatialOSEntity entity, EntityGameObjectLinker linker)
        {
            if (!entity.HasComponent <Metadata.Component>())
            {
                return;
            }

            var metadata      = entity.GetComponent <Metadata.Component>();
            var isPlayer      = metadata.EntityType == "Player";                                   // 玩家
            var isTree        = metadata.EntityType == SimulationSettings.TreePrefabName;          // 树
            var isDinoBrachio = metadata.EntityType == SimulationSettings.Dino_Brachio_PrefabName; // Dino Brachiosaurus
            var isDinoTRex    = metadata.EntityType == SimulationSettings.Dino_TRex_PrefabName;    // Dino T-Rex
            var isEgg         = metadata.EntityType == SimulationSettings.Egg_PrefabName;          // Dino Eggs
            var hasAuthority  = PlayerLifecycleHelper.IsOwningWorker(entity.SpatialOSEntityId, _world);

            if (isPlayer && hasAuthority)
            {
                var pathPrefab       = $"Prefabs/{_WorkerType}/Authoritative/Player";
                var prefab           = Resources.Load(pathPrefab);
                var playerGameObject = UnityEngine.Object.Instantiate(prefab, AnimalManager.Instance.Roots[(int)AnimalManager.ANIMAL_TYPE.PLAYER]);
                linker.LinkGameObjectToSpatialOSEntity(entity.SpatialOSEntityId, (GameObject)playerGameObject);
                //Debug.Log("EntityGameObjectCreator OnEntityCreated - A Player GameObject created!");
            }
            else if (isTree)
            {
                var pathPrefab       = $"Prefabs/{_WorkerType}/" + SimulationSettings.TreePrefabName;
                var prefab           = Resources.Load(pathPrefab);
                var entityGameObject = UnityEngine.Object.Instantiate(prefab, AnimalManager.Instance.Roots[(int)AnimalManager.ANIMAL_TYPE.TREE]);
                entityGameObject.name = SimulationSettings.TreePrefabName + "Client (ID:" + entity.SpatialOSEntityId + ", Worker: " + _WorkerType + ")";
                linker.LinkGameObjectToSpatialOSEntity(entity.SpatialOSEntityId, (GameObject)entityGameObject);
                //Debug.Log("EntityGameObjectCreator OnEntityCreated - A tree GameObject created");
            }
            else if (isDinoBrachio)
            {
                var pathPrefab       = $"Prefabs/{_WorkerType}/" + SimulationSettings.Dino_Brachio_PrefabName;
                var prefab           = Resources.Load(pathPrefab);
                var entityGameObject = UnityEngine.Object.Instantiate(prefab, AnimalManager.Instance.Roots[(int)AnimalManager.ANIMAL_TYPE.BRACHIO]) as GameObject;
                entityGameObject.name = SimulationSettings.Dino_Brachio_PrefabName + "Client (ID:" + entity.SpatialOSEntityId + ", Worker: " + _WorkerType + ")";
                entityGameObject.transform.position = new Vector3(0, -100, 0);
                linker.LinkGameObjectToSpatialOSEntity(entity.SpatialOSEntityId, (GameObject)entityGameObject);
                //Debug.Log("EntityGameObjectCreator OnEntityCreated - A Dinosauer Brachiosaurus GameObject created<"+entity.SpatialOSEntityId+">");
            }
            else if (isDinoTRex)
            {
                var pathPrefab       = $"Prefabs/{_WorkerType}/" + SimulationSettings.Dino_TRex_PrefabName;
                var prefab           = Resources.Load(pathPrefab);
                var entityGameObject = UnityEngine.Object.Instantiate(prefab, AnimalManager.Instance.Roots[(int)AnimalManager.ANIMAL_TYPE.TREX]) as GameObject;
                entityGameObject.name = SimulationSettings.Dino_TRex_PrefabName + "Client (ID:" + entity.SpatialOSEntityId + ", Worker: " + _WorkerType + ")";
                entityGameObject.transform.position = new Vector3(0, -100, 0);
                linker.LinkGameObjectToSpatialOSEntity(entity.SpatialOSEntityId, (GameObject)entityGameObject);
                //Debug.Log("EntityGameObjectCreator OnEntityCreated - A Dinosauer T-Rex GameObject created<"+entity.SpatialOSEntityId+">");
            }
            else if (isEgg)
            {
                var pathPrefab       = $"Prefabs/{_WorkerType}/" + SimulationSettings.Egg_PrefabName;
                var prefab           = Resources.Load(pathPrefab);
                var entityGameObject = UnityEngine.Object.Instantiate(prefab, AnimalManager.Instance.Roots[(int)AnimalManager.ANIMAL_TYPE.EGG]) as GameObject;
                entityGameObject.name = SimulationSettings.Egg_PrefabName + "Client (ID:" + entity.SpatialOSEntityId + ", Worker: " + _WorkerType + ")";
                entityGameObject.transform.position = new Vector3(0, -100, 0);
                linker.LinkGameObjectToSpatialOSEntity(entity.SpatialOSEntityId, (GameObject)entityGameObject);
                //Debug.Log("EntityGameObjectCreator OnEntityCreated - An Egg GameObject created");
            }
            else
            {
                _fallbackCreator.OnEntityCreated(entity, linker);
            }
        }
コード例 #3
0
 public void OnEntityCreated(string entityType, SpatialOSEntity entity, EntityGameObjectLinker linker)
 {
     throw new NotImplementedException();
 }
コード例 #4
0
 public void OnEntityCreated(SpatialOSEntity entity, EntityGameObjectLinker linker)
 {
     throw new System.NotImplementedException();
 }
コード例 #5
0
        public void OnEntityCreated(SpatialOSEntityInfo entityInfo, GameObject prefab, EntityManager entityManager, EntityGameObjectLinker linker)
        {
            var spatialOSPosition = entityManager.GetComponentData <Position.Component>(entityInfo.Entity);
            var position          = spatialOSPosition.Coords.ToUnityVector() + workerOrigin;

            var gameObject = Object.Instantiate(prefab, position, Quaternion.identity);

            gameObject.name = $"{prefab.name}(SpatialOS: {entityInfo.SpatialOSEntityId}, Worker: {workerType})";

            entityIdToGameObject.Add(entityInfo.SpatialOSEntityId, gameObject);
            linker.LinkGameObjectToSpatialOSEntity(entityInfo.SpatialOSEntityId, gameObject, componentsToAdd);
        }
コード例 #6
0
 public void OnEntityCreated(SpatialOSEntityInfo entityInfo, GameObject prefab, EntityManager entityManager,
                             EntityGameObjectLinker linker)
 {
     throw new NotImplementedException();
 }