Exemplo n.º 1
0
 private void SpawnContent()
 {
     contentSpawner                = gameObject.AddComponent <PrefabSpawner>();
     contentSpawner.Prefab         = content;
     contentSpawner.SpawnTransform = contentParentTransform;
     contentSpawner.Spawn();
 }
Exemplo n.º 2
0
 // Token: 0x06001791 RID: 6033 RVA: 0x00014D67 File Offset: 0x00012F67
 public void SpawnPrefab(PrefabSpawner prefabSpawner)
 {
     if (prefabSpawner != null)
     {
         prefabSpawner.Spawn(null);
     }
 }
Exemplo n.º 3
0
    private void OnEnable()
    {
        source    = (PrefabSpawner)target;
        sourceRef = serializedObject;

        GetProperties();
    }
Exemplo n.º 4
0
 // Token: 0x06001793 RID: 6035 RVA: 0x00014DA3 File Offset: 0x00012FA3
 public void DestroyPrefab(PrefabSpawner prefabSpawner)
 {
     if (prefabSpawner != null)
     {
         prefabSpawner.DestroyInstance();
     }
 }
Exemplo n.º 5
0
    static void SpawnRocks(PrefabSpawner spawner)
    {
        var allowedNodeTypes = new MapGraph.NodeType[] {
            MapGraph.NodeType.Grass,
            MapGraph.NodeType.TallGrass,
            MapGraph.NodeType.Rocky
        };

        var rockNodes = mapGraph.FilterNodes(allowedNodeTypes).ToList();
        int numRocks  = (int)(rockNodes.Count * settings.rockAvgDensity);

        for (int i = 0; i < numRocks; i++)
        {
            // Randomly select a node. If it has more than the maximum number
            // of occupants, try again.
            var node = rockNodes.ElementAt(prng.Next(rockNodes.Count));
            if (node.numEnvironmentOccupants > 0)
            {
                i--;
                continue;
            }

            MeshRenderer obj = spawner.SpawnPrefab(
                settings.rockPrefab,
                RandomOffset(node.centerPoint, mapGraph.center, settings.rockPositionDeviation),
                RandomRotation(settings.rockRotationDeviation),
                RandomScaling(settings.rockScale, settings.rockScaleDeviation)
                );
            obj.transform.gameObject.AddComponent <MeshCollider>();

            // Increment the number of environmental occupants for the
            // current node.
            node.numEnvironmentOccupants++;
        }
    }
Exemplo n.º 6
0
        public override void Execute(ICommandSender sender, string[] args)
        {
            var prefabName = args[0].ToLower();

            if (!int.TryParse(args[1], out int amount))
            {
                sender.SendMessage("Not a number: " + args[1], MessageType.Error);
                return;
            }

            var animalType = animalTypeSet.values.SingleOrDefault(
                x => x.Name.Equals(prefabName, System.StringComparison.OrdinalIgnoreCase));

            if (animalType == null)
            {
                sender.SendMessage("Could not find \"" + prefabName + "\"");
                sender.SendMessage(GetAvailableAnimals());
                return;
            }

            var prefab = animalType.Baby;

            if (worldGridSystem == null)
            {
                worldGridSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <WorldGridSystem>();
            }

            PrefabSpawner.Spawn(prefab, amount, worldGridSystem);
            sender.SendMessage("Spawned " + amount + " " + prefab.name + "s");
        }
Exemplo n.º 7
0
        private static void SpawnPrefab(string prefab, MatrixD position)
        {
            Options options = new Options {
                Restock = true
            };

            PrefabSpawner.SpawnPrefab(prefab, position, options);
        }
Exemplo n.º 8
0
    public static GameObject SpawnWeaponPickupPrefab(GameObject prefab, int spawnerIndex, Vector3 pos, Quaternion rot, PickupType t, float v)
    {
        var go     = PrefabSpawner.SpawnPrefab(prefab, spawnerIndex, pos, rot);
        var pickup = go.GetComponent <Pickup>();

        pickup.myType = t;
        pickup.Value  = v;
        return(go);
    }
Exemplo n.º 9
0
    public static void Spawn(MapGraph mapGraph, Transform container, AnimalSettings settings, int seed)
    {
        AnimalSpawner.mapGraph = mapGraph;
        AnimalSpawner.prng     = new System.Random(seed);

        var spawner = new PrefabSpawner(container);

        settings.speciesSettings.ForEach(s => SpawnSpecies(spawner, s));
    }
Exemplo n.º 10
0
    public static void Spawn(MapGraph mapGraph, Transform container, EnvironmentSettings settings, int seed)
    {
        EnvironmentSpawner.mapGraph = mapGraph;
        EnvironmentSpawner.prng     = new System.Random(seed);
        EnvironmentSpawner.settings = settings;

        var spawner = new PrefabSpawner(container);

        SpawnTrees(spawner);
        SpawnRocks(spawner);
    }
Exemplo n.º 11
0
    public void DrawMapInEditor()
    {
        //Used to store prefab objects in edit mode and delete them when changes are made (is a bit buggy)
        if (_biomeContainer != null)
        {
            DestroyImmediate(_biomeContainer.gameObject);
        }
        _biomeContainer = new GameObject("DELETE ME IF MANY OF ME").transform;

        //Apply material to mesh
        _textureData.ApplyToMaterial(_terrainMaterial);
        _textureData.UpdateMeshHeights(_terrainMaterial, _heightMapSettings.MinHeight, _heightMapSettings.MaxHeight);

        //Generate the heightmap for the chunk at origin
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(_meshSettings.NumVertsPerLine, _meshSettings.NumVertsPerLine, _heightMapSettings, _chunkCoord);

        Vector2 sampleCenter = _chunkCoord * _meshSettings.MeshWorldSize / _meshSettings.MeshScale;

        float[,] noise1 = Noise.GenerateNoiseMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _meshSettings.NumVertsPerLine * _noiseViewSize, 1, _noiseSettingsData_1.NoiseSettingsDataMerge, _chunkCoord);
        noise1          = Noise.Clamp(noise1, _noiseSettingsData_1);
        float[,] noise2 = Noise.GenerateNoiseMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _meshSettings.NumVertsPerLine * _noiseViewSize, 1, _noiseSettingsData_2.NoiseSettingsDataMerge, _chunkCoord);
        noise2          = Noise.Clamp(noise2, _noiseSettingsData_2);

        float[,] noise = _noiseMergeType == NoiseMergeType.ONLY_FIRST ? noise1 : noise2;



        if (_drawMode == DrawMode.NOISE_MAP)
        {
            DrawTexture(TextureGenerator.TextureFromNoise(noise));
        }
        else if (_drawMode == DrawMode.MESH)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.heightMap, _meshSettings, _editorPreviewLevelOfDetail));
        }
        else if (_drawMode == DrawMode.FALL_OF_MAP)
        {
            float[,] fallOf = (new HeightMap(FallofGenerator.GenerateFallofMap(_meshSettings.NumVertsPerLine), 1, 1).heightMap);
            DrawTexture(TextureGenerator.TextureFromNoise(fallOf));
        }
        else if (_drawMode == DrawMode.BIOME)
        {
            MeshData meshData = MeshGenerator.GenerateTerrainMesh(heightMap.heightMap, _meshSettings, _editorPreviewLevelOfDetail);
            DrawMesh(meshData);
            PrefabSpawner    prefabSpawner = new PrefabSpawner();
            List <SpawnInfo> spawnInfo     = prefabSpawner.SpawnOnChunk(2, 0, _biome, heightMap, meshData, _meshSettings, new Vector2(sampleCenter.x, -sampleCenter.y), _chunkCoord);
            prefabSpawner.SpawnSpawnInfo(spawnInfo, _biomeContainer, true);
        }
        else if (_drawMode == DrawMode.MAP)
        {
            TextureChunkData data = TextureGenerator.DrawMap(_meshSettings.NumVertsPerLine * _noiseViewSize, _mapSettings, new Vector2(sampleCenter.x, -sampleCenter.y), _chunkCoord);
            DrawTexture(TextureGenerator.TextureFromColorMap(data.colorMap, data.width, data.height));
        }
    }
Exemplo n.º 12
0
    public override void OnInspectorGUI()
    {
        PrefabSpawner prefabSpawner = (PrefabSpawner)target;

        DrawDefaultInspector();

        if (GUILayout.Button("Generate"))
        {
            prefabSpawner.GeneratePrefabs();
        }
    }
Exemplo n.º 13
0
        public static void SpawnGroup(string group)
        {
            const string prefix         = "spawngroup";
            MatrixD      initialMatrixD = MyAPIGateway.Session.Player.Character.WorldMatrix;

            Core.GeneralLog.WriteToLog("SpawnGroup", $"Spawn Group:\t{group}");
            initialMatrixD.Translation += initialMatrixD.Forward * 50;
            Options options = new Options {
                OwnerId = 0, Restock = true
            };

            PrefabSpawner.SpawnSpawmGroup(group.Replace(prefix, "").Trim(), initialMatrixD, options);
        }
Exemplo n.º 14
0
    public override void OnInspectorGUI()
    {
        PrefabSpawner script = (PrefabSpawner)target;

        base.OnInspectorGUI();

        //script.prefab = (GameObject)EditorGUILayout.ObjectField(script.prefab, typeof(GameObject));
        //script.spawnCount = EditorGUILayout.IntField("Spawn Count", script.spawnCount);
        //script.relativeOffset = EditorGUILayout.Vector3Field("Relative Offset", script.relativeOffset);

        //if (GUILayout.Button("Spawn"))
        //{
        //    script.SpawnObjects(script.prefab, script.spawnCount, script.offset);
        //}
    }
Exemplo n.º 15
0
    static void SpawnTreePrefab(PrefabSpawner spawner, MapGraph.Node node, MeshRenderer prefab, float scale)
    {
        MeshRenderer obj = spawner.SpawnPrefab(
            prefab,
            RandomOffset(node.centerPoint, mapGraph.center, settings.treePositionDeviation),
            RandomRotation(settings.treeRotationDeviation),
            RandomScaling(scale, settings.treeScaleDeviation)
            );

        obj.transform.gameObject.AddComponent <MeshCollider>();

        // Increment the number of environment occupants for the
        // current node.
        node.numEnvironmentOccupants++;
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        PrefabSpawner pS = (PrefabSpawner)target;         //PrefabSpawner pS = target as PrefabSpawner;

        if (GUILayout.Button("Instantiate Prefabs"))
        {
            pS.InstantiatePrefabs();
        }

        if (GUILayout.Button("Delete all Prefabs"))
        {
            pS.DeletePrefabs();
        }
    }
Exemplo n.º 17
0
        public static void SpawnPrefab(string prefab)
        {
            const string prefix = "spawnprefab";

            if (!prefab.StartsWith(prefix))
            {
                return;
            }
            Core.GeneralLog.WriteToLog("SpawnPrefab", $"Prefab:\t{prefab}");
            Options options = new Options {
                Restock = true
            };
            MatrixD initialMatrixD = MyAPIGateway.Session.Player.Character.WorldMatrix;

            initialMatrixD.Translation += initialMatrixD.Forward * 250;
            PrefabSpawner.SpawnPrefab(prefab.Replace(prefix, "").Trim(), initialMatrixD, options);
        }
Exemplo n.º 18
0
    static void SpawnSpecies(PrefabSpawner spawner, AnimalSpeciesSettings settings)
    {
        int initialPopulationSize = prng.Next(
            settings.minStartingPopulation,
            settings.maxStartingPopulation
            );

        // Select an initial spawn point prior to starting the loop
        MapGraph.Node spawnPoint = SelectSpawnPoint();

        for (int i = 0; i < initialPopulationSize; i++)
        {
            // Spawn a new instance of the prefab.
            MeshRenderer obj = spawner.SpawnPrefab(settings.prefab, spawnPoint.centerPoint - mapGraph.center, RandomRotation());

            // Mark the node as occupied.
            spawnPoint.numAnimalOccupants++;

            // Randomize the neighbours so that we're not just iterating
            // through linearly.
            var neighbours = spawnPoint.GetNeighbourNodes()
                             .OrderBy(_ => prng.Next())
                             .ToList();

            // Attempt to select a random neighbouring node as the next spawn
            // point.
            int j;
            for (j = 0; j < neighbours.Count; j++)
            {
                if (allowedNodeTypes.Contains(neighbours[j].nodeType) &&
                    !neighbours[j].occupied)
                {
                    spawnPoint = neighbours[j];
                    break;
                }
            }

            // If none of the neighbouring nodes are valid candidates, just
            // randomly select a new one instead.
            if (j >= neighbours.Count)
            {
                spawnPoint = SelectSpawnPoint();
            }
        }
    }
Exemplo n.º 19
0
 public void EnsureSpawned()
 {
     if (prefab == null)
     {
         return;
     }
     if (prefabSpawner == null)
     {
         prefabSpawner                  = gameObject.GetOrAddComponent <PrefabSpawner>();
         prefabSpawner.Prefab           = prefab;
         prefabSpawner.AfterSpawnAction = ChildrenSetup;
         prefabSpawner.Respawn();
     }
     else if (!prefabSpawner.ArePrefabsSpawned)
     {
         prefabSpawner.Spawn();
     }
 }
Exemplo n.º 20
0
    static void SpawnTrees(PrefabSpawner spawner)
    {
        var tallGrassNodes = mapGraph.FilterNodes(MapGraph.NodeType.TallGrass).ToList();
        int numConiferous  = (int)(tallGrassNodes.Count * settings.coniferousAvgDensity);

        var grassNodes   = mapGraph.FilterNodes(MapGraph.NodeType.Grass).ToList();
        int numDeciduous = (int)(grassNodes.Count * settings.deciduousAvgDensity);

        // Spawn coniferous trees.
        for (int i = 0; i < numConiferous; i++)
        {
            // Randomly select a node. If it has more than the maximum number
            // of occupants, or any of the neighbouring nodes are FreshWater,
            // try again.
            var node = tallGrassNodes.ElementAt(prng.Next(tallGrassNodes.Count));
            if (node.numEnvironmentOccupants >= settings.maxOccupantsPerNode ||
                node.GetNeighbourNodes().Any(neighbour => neighbour.nodeType == MapGraph.NodeType.FreshWater))
            {
                i--;
                continue;
            }

            SpawnTreePrefab(spawner, node, settings.coniferousTreePrefab, settings.coniferousTreeScale);
        }

        // Spawn deciduous trees.
        for (int i = 0; i < numDeciduous; i++)
        {
            // Randomly select a node. If it has more than the maximum number
            // of occupants, try again.
            var node = grassNodes.ElementAt(prng.Next(grassNodes.Count));
            if (node.numEnvironmentOccupants >= settings.maxOccupantsPerNode)
            {
                i--;
                continue;
            }

            SpawnTreePrefab(spawner, node, settings.deciduousTreePrefab, settings.deciduousTreeScale);
        }
    }
Exemplo n.º 21
0
        public static void SpawnEemTradePrefabs(string s)
        {
            List <string> tradePrefabs = new List <string>
            {
                "Dromedary_Trader", "Helios_Wheel_Trader", "Phaeton_Trading_Outpost", "PE_XMC_718_Trading_Outpost", "PE_XMC_603_Factory",
                "PE_XMC_99_Refinery", "PE_IMDC_1781_Service_Platform", "PE_Mahriane_8724_Service_Platform", "PE_Mahriane_34_Trading_Outpost",
                "PE_Mahriane_56_Trading_Outpost"
            };

            Options options = new Options {
                OwnerId = 0, Restock = true
            };

            MatrixD initialMatrixD = MyAPIGateway.Session.Player.Character.WorldMatrix;

            initialMatrixD.Translation += initialMatrixD.Forward * 50;

            MyAPIGateway.Parallel.Start(delegate
            {
                for (int i = 0; i < (tradePrefabs.Count / 5); i++)
                {
                    initialMatrixD.Translation += initialMatrixD.Down * (100 * i);
                    for (int j = 0; j < 5; j++)
                    {
                        if (i % 2 == 0)
                        {
                            initialMatrixD.Translation += initialMatrixD.Right * (100 * j);
                        }
                        else
                        {
                            initialMatrixD.Translation += initialMatrixD.Left * (100 * j);
                        }

                        PrefabSpawner.SpawnPrefab(tradePrefabs[i], initialMatrixD, options);
                        MyAPIGateway.Parallel.Sleep(1000);
                    }
                }
            });
        }
    public void HandleCustomProperties(GameObject gameObject,
                                       IDictionary <string, string> keyValuePairs)
    {
        if (keyValuePairs.ContainsKey("PortalTo"))
        {
            MapPortal portal = gameObject.AddComponent <MapPortal>();
            string[]  parts  = keyValuePairs["PortalTo"].Split(new char[] { ':' }, 2);
            portal.target = new MapPath(parts[0], parts.Length > 1 ? parts[1] : "default");

            gameObject.GetComponent <Collider2D>().isTrigger = true;
        }

        if (keyValuePairs.ContainsKey("PortalFrom"))
        {
            StartingPoint portal = gameObject.AddComponent <StartingPoint>();
            portal.locationName = keyValuePairs["PortalFrom"];
            Collider2D collider = gameObject.GetComponent <Collider2D>();

            gameObject.transform.position = collider.bounds.center;
            GameObject.DestroyImmediate(collider);
        }

        if (keyValuePairs.ContainsKey("ObjectName"))
        {
            PrefabSpawner spawner = gameObject.AddComponent <PrefabSpawner>();
            PrefabNames   names   = getPrefabMapping();
            if (names != null)
            {
                spawner.toSpawn    = names.GetEntry(keyValuePairs["ObjectName"]).prefab;
                spawner.condition  = keyValuePairs.ContainsKey("When") ? keyValuePairs["When"] : "";
                spawner.properties = keyValuePairs;
            }

            Debug.Log(gameObject.transform.rotation);

            BoxCollider2D collider = gameObject.GetComponent <BoxCollider2D>();

            if (collider != null)
            {
                spawner.size += new Vector3(collider.offset.x, collider.offset.y, 0.0f);
                Object.DestroyImmediate(collider);
            }

            Tiled2Unity.TileObject tileObject = gameObject.GetComponent <Tiled2Unity.TileObject>();

            if (tileObject != null)
            {
                spawner.size += new Vector3(tileObject.TileWidth * 0.5f, tileObject.TileHeight * 0.5f, 0.0f);
                Object.DestroyImmediate(tileObject);
            }

            while (gameObject.transform.childCount > 0)
            {
                Object.DestroyImmediate(gameObject.transform.GetChild(0).gameObject);
            }
        }

        if (sideAttributes.Any((key) => keyValuePairs.ContainsKey(key)))
        {
            MapAttachements attatchments = gameObject.AddComponent <MapAttachements>();
            attatchments.attachments = sideAttributes.Select((name) => {
                if (keyValuePairs.ContainsKey(name))
                {
                    return(keyValuePairs[name]);
                }
                else
                {
                    return(null);
                }
            }).ToArray();
        }

        Tiled2Unity.TiledMap map = gameObject.GetComponent <Tiled2Unity.TiledMap>();

        if (map != null)
        {
            if (keyValuePairs.ContainsKey("Name"))
            {
                mapName = keyValuePairs["Name"];
            }
            else
            {
                mapName = null;
            }
            Pathfinding pathfinding = gameObject.AddComponent <Pathfinding>();
            pathfinding.width    = map.NumTilesWide;
            pathfinding.height   = map.NumTilesHigh;
            pathfinding.tileSize = new Vector2(map.TileWidth, map.TileHeight) * map.ExportScale;
            pathfinding.layers   = new List <PathfindingLayer> {
                new PathfindingLayer(PathingTypes.Walking, (1 << LayerMask.NameToLayer("L1: Barrier")) | (1 << LayerMask.NameToLayer("L1: ProjectilePassible")) | (1 << LayerMask.NameToLayer("L1: Water"))),
                new PathfindingLayer(PathingTypes.Flying, 1 << LayerMask.NameToLayer("L1: Barrier")),
            };
        }
    }
Exemplo n.º 23
0
 private void Awake()
 {
     Instance = this;
 }
Exemplo n.º 24
0
 // Token: 0x06001B7F RID: 7039 RVA: 0x00018064 File Offset: 0x00016264
 public WormMortarShootingState(WormEnemy worm, MortarWormDirectionalAnimations shoot, PrefabSpawner shootEffect, SoundSource shootSound, ProjectileSpawner projectileSpawner, float shootDelay, float projectileDamage) : base(worm)
 {
     this.m_shoot             = shoot;
     this.m_shootEffect       = shootEffect;
     this.m_shootSound        = shootSound;
     this.m_projectileSpawner = projectileSpawner;
     this.m_shootDelay        = shootDelay;
     this.m_projectileDamage  = projectileDamage;
 }