public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent)
        {
            TechType       techType = entity.TechType.Enum();
            GameObject     prefab;
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId);

            if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);
                if (prefab == null)
                {
                    return(Optional <GameObject> .Of(Utils.CreateGenericLoot(techType)));
                }
            }

            GameObject gameObject = Utils.SpawnFromPrefab(prefab, null);

            gameObject.transform.position   = entity.Position;
            gameObject.transform.localScale = entity.Scale;

            if (parent.IsPresent())
            {
                gameObject.transform.SetParent(parent.Get().transform, true);
            }

            gameObject.transform.localRotation = entity.Rotation;
            gameObject.SetActive(true);

            NitroxIdentifier.SetNewId(gameObject, entity.Id);
            LargeWorldEntity.Register(gameObject);
            CrafterLogic.NotifyCraftEnd(gameObject, techType);

            return(Optional <GameObject> .Of(gameObject));
        }
Exemple #2
0
        private GameObject CreateGameObject(TechType techType, string classId)
        {
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(classId);

            if (!prefabRequest.TryGetPrefab(out GameObject prefab))
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);

                if (prefab == null)
                {
                    return(Utils.CreateGenericLoot(techType));
                }
            }

            return(Utils.SpawnFromPrefab(prefab, null));
        }
Exemple #3
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            TechType       techType = entity.TechType.Enum();
            GameObject     prefab;
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId);

            if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);
                if (prefab == null)
                {
                    return(Optional.Of(Utils.CreateGenericLoot(techType)));
                }
            }

            GameObject gameObject = Utils.SpawnFromPrefab(prefab, null);

            gameObject.transform.position   = entity.Transform.Position;
            gameObject.transform.rotation   = entity.Transform.Rotation;
            gameObject.transform.localScale = entity.Transform.LocalScale;

            NitroxEntity.SetNewId(gameObject, entity.Id);
            CrafterLogic.NotifyCraftEnd(gameObject, techType);

            if (parent.HasValue)
            {
                gameObject.transform.SetParent(parent.Value.transform, true);
            }

            if (parent.HasValue && !parent.Value.GetComponent <LargeWorldEntityCell>())
            {
                LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
            }
            else
            {
                gameObject.SetActive(true);
            }

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
Exemple #4
0
        IEnumerator GetPrefabAsync(IOut <GameObject> gameObject)
        {
            GameObject obj = null;

            if (spawnInfo.spawnType == SpawnInfo.SpawnType.ClassId) // Spawn is via ClassID.
            {
                var request = PrefabDatabase.GetPrefabAsync(spawnInfo.classId);
                yield return(request);

                request.TryGetPrefab(out obj);
            }
            else // spawn is via TechType.
            {
                var task = CraftData.GetPrefabForTechTypeAsync(spawnInfo.techType);
                yield return(task);

                obj = task.GetResult();
            }

            gameObject.Set(obj);
        }