Simple project setup
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnvironmentGenerator : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Width of the whole ground plane")]
|
||||
public float width = 1;
|
||||
[Tooltip("Height of the whole ground plane")]
|
||||
public float height = 1;
|
||||
|
||||
[Tooltip("Amount of planes drawn horizontally in the whole plane area.")]
|
||||
[Range(1, 20)]
|
||||
public uint amountOfHorizontalElements = 5;
|
||||
[Tooltip("Amount of planes drawn vertically in the whole plane area.")]
|
||||
[Range(1, 20)]
|
||||
public uint amountOfVerticalElements = 5;
|
||||
[Tooltip("The material the ground uses")]
|
||||
public Material groundMaterial;
|
||||
[Tooltip("Only for testing.")]
|
||||
public bool testDestroy = false;
|
||||
|
||||
public GameObject[,] CurrentEnvironment { get; private set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
CreateNewEnvironment();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
TestEnvironmentCreation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only for testing, can be deleted if not needed anymore
|
||||
/// </summary>
|
||||
private void TestEnvironmentCreation()
|
||||
{
|
||||
if (testDestroy)
|
||||
{
|
||||
UpdateEnvironment();
|
||||
testDestroy = !testDestroy;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a grid of planes
|
||||
/// </summary>
|
||||
public void CreateNewEnvironment()
|
||||
{
|
||||
CurrentEnvironment = new GameObject[amountOfHorizontalElements, amountOfVerticalElements];
|
||||
|
||||
float widthSingleEleme = width / amountOfHorizontalElements; //width of a single quad
|
||||
float heightSingleElem = height / amountOfVerticalElements; //height of a single quad
|
||||
|
||||
// calculate the left-upper-point of the whole environment plane to use it as a startpoint for creating the grid
|
||||
Vector3 leftUpperPoint = transform.position + (Vector3.left * (width / 2) + (Vector3.forward * (height / 2)));
|
||||
|
||||
Vector3 currentStartPoint = leftUpperPoint + new Vector3(widthSingleEleme / 2, 0, -heightSingleElem / 2);
|
||||
|
||||
//First draw all horizontal planes than do the next line in the grid
|
||||
for (int idxX = 0; idxX < amountOfVerticalElements; idxX++)
|
||||
{
|
||||
CreateHorizontalPlaneLine(currentStartPoint, widthSingleEleme, heightSingleElem, idxX);
|
||||
currentStartPoint += Vector3.back * heightSingleElem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create a horizontal line of Planes
|
||||
private void CreateHorizontalPlaneLine(Vector3 startPoint, float widthPlane = 1, float heightPlane = 1, int idxX = 1)
|
||||
{
|
||||
Vector3 currentStartPoint = startPoint;
|
||||
|
||||
for (int idxY = 0; idxY < amountOfHorizontalElements; idxY++)
|
||||
{
|
||||
CreatePlane(widthPlane, heightPlane, idxX, currentStartPoint, idxY);
|
||||
currentStartPoint += Vector3.right * widthPlane;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a single Plane
|
||||
private void CreatePlane(float widthPlane, float heightPlane, int idxX, Vector3 currentStartPoint, int idxY)
|
||||
{
|
||||
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Quad);
|
||||
plane.transform.localEulerAngles = new Vector3(90, 0, 0);
|
||||
plane.transform.position = currentStartPoint;
|
||||
plane.transform.localScale = new Vector3(widthPlane, heightPlane, 1);
|
||||
plane.transform.SetParent(this.transform);
|
||||
plane.GetComponent<Renderer>().material = groundMaterial;
|
||||
|
||||
CurrentEnvironment[idxX, idxY] = plane;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroy all Planes and set the environment array back to null
|
||||
/// </summary>
|
||||
public void DeleteCurrentEnvironment()
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
if (child != this)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
CurrentEnvironment = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the current environment if there is any and creates a new one
|
||||
/// </summary>
|
||||
public void UpdateEnvironment()
|
||||
{
|
||||
DeleteCurrentEnvironment();
|
||||
CreateNewEnvironment();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6279e2499d1811045a857f890736f7ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LineGenerator : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d204f699bf0f397419a5f40c948ff063
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c7eb7dc728d65c49b1b20f4c37fb8c7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using MLAgents;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CozmoAcademy : Academy
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23300f50ba861924c93dc5008ffb90d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using MLAgents;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CozmoAgent : Agent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 234fd6e10ef55ad4b82b3153890ab5d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user