diff --git a/Assets/Prefab/Environment/Wall.prefab b/Assets/Prefab/Environment/Wall.prefab new file mode 100644 index 0000000..52a5f0b Binary files /dev/null and b/Assets/Prefab/Environment/Wall.prefab differ diff --git a/Assets/Prefab/Floor.prefab b/Assets/Prefab/Floor.prefab deleted file mode 100644 index 66cda0d..0000000 Binary files a/Assets/Prefab/Floor.prefab and /dev/null differ diff --git a/Assets/Prefab/Player.prefab b/Assets/Prefab/Player.prefab index 66cda0d..9cf492f 100644 Binary files a/Assets/Prefab/Player.prefab and b/Assets/Prefab/Player.prefab differ diff --git a/Assets/Prefab/PlayerCamera.prefab b/Assets/Prefab/PlayerCamera.prefab new file mode 100644 index 0000000..f179fc6 Binary files /dev/null and b/Assets/Prefab/PlayerCamera.prefab differ diff --git a/Assets/Scene/GeneratedScene.unity b/Assets/Scene/GeneratedScene.unity new file mode 100644 index 0000000..41a2ae8 Binary files /dev/null and b/Assets/Scene/GeneratedScene.unity differ diff --git a/Assets/Scene/SceneGenerator.unity b/Assets/Scene/SceneGenerator.unity new file mode 100644 index 0000000..55858f9 Binary files /dev/null and b/Assets/Scene/SceneGenerator.unity differ diff --git a/Assets/Scene/SceneTest.unity b/Assets/Scene/SceneTest.unity deleted file mode 100644 index c4a098f..0000000 Binary files a/Assets/Scene/SceneTest.unity and /dev/null differ diff --git a/Assets/Scripts/ProceduralGeneration/TestSceneGenerator.cs b/Assets/Scripts/ProceduralGeneration/TestSceneGenerator.cs new file mode 100644 index 0000000..08425a8 --- /dev/null +++ b/Assets/Scripts/ProceduralGeneration/TestSceneGenerator.cs @@ -0,0 +1,87 @@ +using UnityEngine; +using UnityEditor; +using System.Collections; + +public class TestSceneGenerator : MonoBehaviour { + + [Tooltip("Put here Player Prefab ! ")] + public Transform player; + [Tooltip("Put here Player Camera Prefab ! ")] + public Transform playerCamera; + [Tooltip("Put here Wall Prefab ! ")] + public Transform wall; + + private Transform environment; // Stores the roo object for the environment + + // Use this for initialization + void Start () { + + /* Temporary hard coded parameters */ + int width = 100; + int height = 40; + Vector2 spawnPosition = new Vector2 (10, 2); + + /* Create the root environment transform which will contain all the walls */ + GameObject obj = new GameObject ("Environment"); + environment = obj.GetComponent (); + + /* Generate the scene */ + generateSquare (width, height, Vector2.zero); + generatePlatform (10, new Vector2(10, 20)); + generatePlatform (10, new Vector2(25, 10)); + generatePlatform (30, new Vector2(50, 25)); + + /* Instantiate the player */ + spawnPlayer (spawnPosition); + + /* Save the scene to a file */ + //saveGeneratedScene ("./Assets/Scene/GeneratedScene.unity"); + } + + /** + * Generate a bordered square (not filled) beginning at position + */ + private void generateSquare(int width, int height, Vector2 position) { + + for (int i = 0; i <= width; i++) { + for (int j = 0; j <= height; j++) { + if(i == 0 || i == width || j == 0 || j == height) { + + Transform wallInstance = (Transform) Instantiate(wall, new Vector3(i + position.x, j + position.y, 0), Quaternion.identity); + wallInstance.SetParent(environment); + } + } + } + } + + /** + * Generate Horizontal platform beginning at position + */ + private void generatePlatform(int width, Vector2 position) { + + for (int i = 0; i <= width; i++) { + Transform wallInstance = (Transform) Instantiate(wall, new Vector3(i + position.x, position.y, 0), Quaternion.identity); + wallInstance.SetParent(environment); + } + } + + /** + * Instantiate the player and camera at given spawn position + */ + private void spawnPlayer(Vector2 spawnPosition) { + Transform playerInstance = (Transform) Instantiate (player, new Vector3 (spawnPosition.x, spawnPosition.y, 0), Quaternion.identity); + Transform playerCameraInstance = (Transform) Instantiate (playerCamera, new Vector3 (spawnPosition.x, spawnPosition.y, playerCamera.position.z), Quaternion.identity); + + playerCameraInstance.SetParent (playerInstance); + } + + /** + * Save the current scene to a scene file + * Stores all previously instantiated GameObject + */ + private void saveGeneratedScene(string path) { + // path example : "./Assets/Scene/test.unity" + EditorApplication.SaveScene (path); + } +} + \ No newline at end of file diff --git a/ProjectSettings/NavMeshAreas.asset b/ProjectSettings/NavMeshAreas.asset new file mode 100644 index 0000000..885f616 Binary files /dev/null and b/ProjectSettings/NavMeshAreas.asset differ diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 2199b39..3d8cfe5 100644 Binary files a/ProjectSettings/QualitySettings.asset and b/ProjectSettings/QualitySettings.asset differ