Пример #1
0
    private GameObject Spawn(SpawnPopulation population, Vector3 pos, Quaternion rot)
    {
        Prefab <Spawnable> randomPrefab = population.GetRandomPrefab();

        if (randomPrefab == null)
        {
            return((GameObject)null);
        }
        if (Object.op_Equality((Object)randomPrefab.Component, (Object)null))
        {
            Debug.LogError((object)("[Spawn] Missing component 'Spawnable' on " + randomPrefab.Name));
            return((GameObject)null);
        }
        Vector3 one = Vector3.get_one();

        DecorComponent[] all = PrefabAttribute.server.FindAll <DecorComponent>(randomPrefab.ID);
        randomPrefab.Object.get_transform().ApplyDecorComponents(all, ref pos, ref rot, ref one);
        if (!randomPrefab.ApplyTerrainAnchors(ref pos, rot, one, TerrainAnchorMode.MinimizeMovement, population.Filter))
        {
            return((GameObject)null);
        }
        if (!randomPrefab.ApplyTerrainChecks(pos, rot, one, population.Filter))
        {
            return((GameObject)null);
        }
        if (!randomPrefab.ApplyTerrainFilters(pos, rot, one, (SpawnFilter)null))
        {
            return((GameObject)null);
        }
        if (!randomPrefab.ApplyWaterChecks(pos, rot, one))
        {
            return((GameObject)null);
        }
        if (!this.CheckBounds(randomPrefab, pos, rot, one))
        {
            return((GameObject)null);
        }
        if ((BaseScriptableObject)randomPrefab.Component.Population != (BaseScriptableObject)population)
        {
            randomPrefab.Component.Population = population;
        }
        if (Global.developer > 1)
        {
            Debug.Log((object)("[Spawn] Spawning " + randomPrefab.Name));
        }
        BaseEntity baseEntity = randomPrefab.SpawnEntity(pos, rot);

        if (Object.op_Equality((Object)baseEntity, (Object)null))
        {
            Debug.LogWarning((object)("[Spawn] Couldn't create prefab as entity - " + randomPrefab.Name));
            return((GameObject)null);
        }
        baseEntity.Spawn();
        return(((Component)baseEntity).get_gameObject());
    }
    private GameObject Spawn(SpawnPopulation population, Vector3 pos, Quaternion rot)
    {
        Prefab <Spawnable> randomPrefab = population.GetRandomPrefab();

        if (randomPrefab == null)
        {
            return(null);
        }
        if (randomPrefab.Component == null)
        {
            UnityEngine.Debug.LogError(string.Concat("[Spawn] Missing component 'Spawnable' on ", randomPrefab.Name));
            return(null);
        }
        Vector3 vector3 = Vector3.one;

        DecorComponent[] decorComponentArray = PrefabAttribute.server.FindAll <DecorComponent>(randomPrefab.ID);
        randomPrefab.Object.transform.ApplyDecorComponents(decorComponentArray, ref pos, ref rot, ref vector3);
        if (!randomPrefab.ApplyTerrainAnchors(ref pos, rot, vector3, TerrainAnchorMode.MinimizeMovement, population.Filter))
        {
            return(null);
        }
        if (!randomPrefab.ApplyTerrainChecks(pos, rot, vector3, population.Filter))
        {
            return(null);
        }
        if (!randomPrefab.ApplyTerrainFilters(pos, rot, vector3, null))
        {
            return(null);
        }
        if (!randomPrefab.ApplyWaterChecks(pos, rot, vector3))
        {
            return(null);
        }
        if (!this.CheckBounds(randomPrefab, pos, rot, vector3))
        {
            return(null);
        }
        if (randomPrefab.Component.Population != population)
        {
            randomPrefab.Component.Population = population;
        }
        if (Global.developer > 1)
        {
            UnityEngine.Debug.Log(string.Concat("[Spawn] Spawning ", randomPrefab.Name));
        }
        BaseEntity baseEntity = randomPrefab.SpawnEntity(pos, rot);

        if (baseEntity != null)
        {
            baseEntity.Spawn();
            return(baseEntity.gameObject);
        }
        UnityEngine.Debug.LogWarning(string.Concat("[Spawn] Couldn't create prefab as entity - ", randomPrefab.Name));
        return(null);
    }