Beispiel #1
0
    public void SelectLevel()
    {
        int selection = levelDropdown.value;

        AllLevels.currentLevel = selection;

        if (selection < AllLevels.BuiltInLevels.Count)
        {
            BuiltInLevel selectedLevel = AllLevels.BuiltInLevels[selection];

            preview.preserveAspect = true;

            name.text        = selectedLevel.Name;
            description.text = selectedLevel.Description;
            AllLevels.currentLevelPositions = selectedLevel.PiecePositions;
            AllLevels.currentLevelPrefabs   = selectedLevel.Prefabs;
        }
        else
        {
            CustomLevel selectedLevel = AllLevels.CustomLevels[selection - AllLevels.BuiltInLevels.Count];

            preview.preserveAspect = true;

            name.text        = selectedLevel.Name;
            description.text = selectedLevel.Description;
            AllLevels.currentLevelPositions = selectedLevel.PiecePositions;
            AllLevels.currentLevelPrefabs   = selectedLevel.Prefabs;
        }

        ChangeLevel();
    }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        AllLevels allLevels =
            GameObject.Find("Persistent Data").GetComponent <AllLevels>();

        BuildingBlockManager buildingBlockManager =
            GameObject.Find("Persistent Data").GetComponent <BuildingBlockManager>();

        int currentLevelIndex = allLevels.currentLevel;


        if (currentLevelIndex < allLevels.BuiltInLevels.Count)
        {
            BuiltInLevel currentLevel = allLevels.BuiltInLevels[currentLevelIndex];

            for (int i = 0; i < currentLevel.Prefabs.Count; i++)
            {
                Vector3 piecePosition = currentLevel.PiecePositions[i];

                Quaternion pieceRotation =
                    Quaternion.Euler(
                        0f,
                        0f,
                        currentLevel.PieceRotations[i]);

                string tag = currentLevel.Prefabs[i];

                Instantiate(
                    buildingBlockManager.searchBuiltInPrefabs(tag),
                    piecePosition,
                    pieceRotation);
            }
        }
        else if (currentLevelIndex >= allLevels.BuiltInLevels.Count)
        {
            CustomLevel currentLevel = allLevels.CustomLevels[currentLevelIndex];

            for (int i = 0; i < currentLevel.Prefabs.Count; i++)
            {
                Vector3 piecePosition = currentLevel.PiecePositions[i];

                Quaternion pieceRotation =
                    Quaternion.Euler(
                        0f,
                        0f,
                        currentLevel.PieceRotations[i]);

                string tag = currentLevel.Prefabs[i];

                Instantiate(
                    buildingBlockManager.searchBuiltInPrefabs(tag),
                    piecePosition,
                    pieceRotation);
            }
        }
    }
Beispiel #3
0
    private IEnumerator addLevelToAssetsFolder(string pName, string pDescription, Transform pStructure)
    {
        yield return(new WaitForEndOfFrame());

        //RenderTexture.active = rendTex;
        //Texture2D tex2D = new Texture2D(rendTex.width, rendTex.height, TextureFormat.ARGB32, true);
        //Graphics.CopyTexture(rendTex, tex2D);
        //Rect rect = new Rect(0, 0, rendTex.width, rendTex.height);
        //tex2D.ReadPixels(rect, 0, 0, true);


        if (true)
        {
            string builtInLevelPath = "Assets/Prefabs/Prebuilt Levels/" + pName + ".asset";
            string structurePath    = "Assets/Resources/" + pName + ".prefab";

            // Add New Custom Level To List
            customLevels.Add(new CustomLevel(pName, pDescription, pStructure));

            // USE THIS FOR CREATING PREBUILT LEVELS
            // Create structure prefab
            UnityEditor.PrefabUtility.CreatePrefab(
                structurePath,
                pStructure.gameObject);

            // Load structure prefab
            //Transform structureToLoad = Resources.Load<Transform>(structurePath);
            GameObject structureToLoad = Resources.Load <GameObject>(pName);
            Debug.Log(structureToLoad);
            // Construct built in level
            BuiltInLevel builtInLevel = ScriptableObject.CreateInstance <BuiltInLevel>();
            builtInLevel.initializeLevel(pName, pDescription, structureToLoad.transform);
            AssetDatabase.Refresh();
            AssetDatabase.CreateAsset(builtInLevel, builtInLevelPath);
            AssetDatabase.SaveAssets();
        }
    }
Beispiel #4
0
    public void ChangeLevel()
    {
        AllLevels allLevels =
            GameObject.Find("Persistent Data").GetComponent <AllLevels>();

        BuildingBlockManager buildingBlockManager =
            GameObject.Find("Persistent Data").GetComponent <BuildingBlockManager>();

        Transform levelContainer = GameObject.Find("Level Container").transform;

        foreach (Transform child in levelContainer)
        {
            Destroy(child.gameObject);
        }

        int currentLevelIndex = allLevels.currentLevel;


        if (currentLevelIndex < allLevels.BuiltInLevels.Count)
        {
            BuiltInLevel currentLevel = allLevels.BuiltInLevels[currentLevelIndex];

            for (int i = 0; i < currentLevel.Prefabs.Count; i++)
            {
                Vector3 piecePosition = currentLevel.PiecePositions[i];

                Quaternion pieceRotation =
                    Quaternion.Euler(
                        0f,
                        0f,
                        currentLevel.PieceRotations[i]);

                string tag = currentLevel.Prefabs[i];

                Transform piece = Instantiate(
                    buildingBlockManager.searchBuiltInPrefabs(tag),
                    piecePosition,
                    pieceRotation);

                piece.parent = levelContainer;
            }
        }
        else if (currentLevelIndex >= allLevels.BuiltInLevels.Count)
        {
            CustomLevel currentLevel = allLevels.CustomLevels[currentLevelIndex];

            for (int i = 0; i < currentLevel.Prefabs.Count; i++)
            {
                Vector3 piecePosition = currentLevel.PiecePositions[i];

                Quaternion pieceRotation =
                    Quaternion.Euler(
                        0f,
                        0f,
                        currentLevel.PieceRotations[i]);

                string tag = currentLevel.Prefabs[i];

                Transform piece = Instantiate(
                    buildingBlockManager.searchBuiltInPrefabs(tag),
                    piecePosition,
                    pieceRotation);

                piece.parent = levelContainer;
            }
        }
    }