예제 #1
0
    private void LoadObjectsWithOverride(Level.ItemSave[] levelParts)
    {
        DestroyObjects();

        for (int i = 0; i < levelParts.Length; i++)
        {
            LevelItem item = itemsDatabase.GetItem(levelParts[i].Item);

            if (item != null)
            {
                GameObject prefab = Instantiate(item.Prefab);
                prefab.transform.position    = levelParts[i].Position;
                prefab.transform.eulerAngles = levelParts[i].Rotation;

                LevelItemBehaviour itemBehaviour = prefab.GetComponent <LevelItemBehaviour>();
                itemBehaviour.transform.localScale = levelParts[i].Scale;
                itemBehaviour.Init(levelParts[i].Type);

                prefab.transform.SetParent(objectsContainer.transform);

                prefab.isStatic = levelParts[i].IsStatic;
            }
            else
            {
                Debug.LogError("[LevelEditor] Can't find item: \"" + levelParts[i].Item + "\"");
            }
        }
    }
예제 #2
0
    public void LoadLevel(int levelNumber)
    {
        for (int i = 0; i < itemsPools.Count; i++)
        {
            itemsPools[i].ReturnToPoolEverything();
        }

        int   firstStageItemsAmount  = 0;
        int   secondStageItemsAmount = 0;
        float firstStageHighestZ     = GroundGenerator.PLAYGROUND_HEIGHT;
        float secondStageLowestZ     = GroundGenerator.PLAYGROUND_HEIGHT + GroundGenerator.GROUNDS_OFFSET;

        firstStageObstaclesList.Clear();
        CloseGates();

        Level level = levelsDatabase.GetLevel(levelNumber - 1);

        for (int i = 0; i < level.Items.Length; i++)
        {
            Level.ItemSave     itemSave = level.Items[i];
            LevelItemBehaviour item     = itemsPools[(int)itemSave.Item].GetPooledObject(itemSave.Position).GetComponent <LevelItemBehaviour>();

            item.Transform.eulerAngles = itemSave.Rotation;
            item.Transform.localScale  = itemSave.Scale;

            item.Init(itemSave.Type);

            if (item.Type == LevelItemBehaviour.ItemType.Normal)
            {
                if (itemSave.Position.z < firstStageHighestZ)
                {
                    firstStageItemsAmount++;
                }
                else if (itemSave.Position.z > secondStageLowestZ)
                {
                    secondStageItemsAmount++;
                }
            }
            else
            {
                if (itemSave.Position.z < firstStageHighestZ)
                {
                    firstStageObstaclesList.Add(item);
                }
            }
        }

        GameController.FirstStageItemsAmount  = firstStageItemsAmount;
        GameController.SecondStageItemsAmount = secondStageItemsAmount;

        int     sphereId       = (int)Level.Item.Sphere;
        Vector3 positionOffset = pathSpheresPrefabTransform.position;
        Vector3 itemsScale     = pathSpheresPrefabTransform.GetChild(0).localScale;

        for (int i = 0; i < pathSpheresPrefabTransform.childCount; i++)
        {
            LevelItemBehaviour item = itemsPools[sphereId].GetPooledObject(pathSpheresPrefabTransform.GetChild(i).localPosition + positionOffset).GetComponent <LevelItemBehaviour>();

            item.Transform.localScale = itemsScale;
            item.Transform.rotation   = new Quaternion();

            item.Init(LevelItemBehaviour.ItemType.Normal);
        }
    }