Initial commit
Basic plant generation and lifecycle implemented.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Core : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public NutrientController nutrientCont;
|
||||
[SerializeField] public PlantController plantCont;
|
||||
[SerializeField] public Terrain ground;
|
||||
|
||||
public static Core instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cd62492e09975242bf83bc1a18d458d
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5452b02ced2e98e4ca75c1ec896ae274
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimalController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] List<_IAnimal> animalPrefabs;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57bdcc6b5435f73478e14cc53eacec2f
|
||||
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimalRabbit : _IAnimal
|
||||
{
|
||||
[SerializeField] GameObject visualPrefab;
|
||||
public AnimalRabbit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7307a57df8e8a93418bff241ef45a13d
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class _IAnimal : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject model;
|
||||
|
||||
// Inherent values
|
||||
public int foodChainPlacement;
|
||||
public int gender;
|
||||
public float speed;
|
||||
public float sightDist;
|
||||
|
||||
public float weightHunger;
|
||||
public float weightBreed;
|
||||
|
||||
// Current values for need of each
|
||||
public float health;
|
||||
public float breed;
|
||||
|
||||
Collider sightSphere;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Eat()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Breed()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d547cd47e0ec2545925c3496ddd02fa
|
||||
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class NutrientController : MonoBehaviour
|
||||
{
|
||||
private float[,] nutrientMap;
|
||||
[SerializeField, Range(10, 100)] int sizeX;
|
||||
[SerializeField, Range(10, 100)] int sizeY;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
nutrientMap = new float[sizeX, sizeY];
|
||||
for(int r = 0; r < sizeX; r ++)
|
||||
{
|
||||
for(int c = 0; c < sizeY; c++)
|
||||
{
|
||||
nutrientMap[r, c] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public float GetNutrients(float x, float y)
|
||||
{
|
||||
int locX = Mathf.FloorToInt(x * sizeX);
|
||||
int locY = Mathf.FloorToInt(y * sizeY);
|
||||
|
||||
return nutrientMap[locX, locY];
|
||||
}
|
||||
|
||||
public void UseNutrients(float x, float y, float used)
|
||||
{
|
||||
int locX = Mathf.FloorToInt(x * sizeX);
|
||||
int locY = Mathf.FloorToInt(y * sizeY);
|
||||
|
||||
nutrientMap[locX, locY] -= used;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 881bafe4bc0f5d747a4fa68fb5fc9126
|
||||
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Plant : MonoBehaviour
|
||||
{
|
||||
private float healthMax;
|
||||
private float healthCurrent;
|
||||
private float nutrientNeed;
|
||||
private float growthRate;
|
||||
public bool isAlive;
|
||||
|
||||
private GameObject visualPrefab;
|
||||
public GameObject visual;
|
||||
|
||||
public void SetVisual(GameObject visualPrefab)
|
||||
{
|
||||
this.visualPrefab = visualPrefab;
|
||||
}
|
||||
|
||||
public void SetValues(float healthMax, float nutrientNeed, float growthRate)
|
||||
{
|
||||
this.healthMax = healthMax;
|
||||
this.nutrientNeed = nutrientNeed;
|
||||
this.growthRate = growthRate;
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
private void Start()
|
||||
{
|
||||
visual = Instantiate(visualPrefab, transform);
|
||||
healthCurrent = healthMax;
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Terrain terrain = Core.instance.ground;
|
||||
NutrientController nutrientCont = Core.instance.nutrientCont;
|
||||
float x = transform.position.x / terrain.terrainData.size.x;
|
||||
float y = transform.position.y / terrain.terrainData.size.y;
|
||||
float nutrientsAvailable = nutrientCont.GetNutrients(x, y);
|
||||
|
||||
if(nutrientNeed > nutrientsAvailable)
|
||||
{
|
||||
healthCurrent -= Time.deltaTime * (0.1f * healthMax);
|
||||
}
|
||||
else
|
||||
{
|
||||
visual.transform.localScale += visual.transform.localScale * (growthRate * Time.deltaTime);
|
||||
nutrientCont.UseNutrients(x, y, (nutrientNeed * Time.deltaTime));
|
||||
}
|
||||
|
||||
if (healthCurrent <= 0)
|
||||
{
|
||||
isAlive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78a4559363f05014eb7e00692e5865b6
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlantController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject plantPrefab;
|
||||
[SerializeField] List<GameObject> plantModels;
|
||||
List<GameObject> plants;
|
||||
float xBound;
|
||||
float zBound;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
plants = new List<GameObject>();
|
||||
Terrain terrain = Core.instance.ground;
|
||||
xBound = terrain.GetComponent<Terrain>().terrainData.size.x;
|
||||
zBound = terrain.GetComponent<Terrain>().terrainData.size.z;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GameObject newPlant = Instantiate(plantPrefab, transform);
|
||||
newPlant.GetComponent<Plant>().SetVisual(plantModels[Random.Range(0, plantModels.Count - 1)]);
|
||||
newPlant.GetComponent<Plant>().SetValues(Random.Range(10f, 100f), Random.Range(0f, 0.5f), Random.Range(0f, 0.5f));
|
||||
float x = Random.Range(0, xBound);
|
||||
float z = Random.Range(0, zBound);
|
||||
float y = terrain.SampleHeight(new Vector3(x, 0, z));
|
||||
Vector3 normal = terrain.terrainData.GetInterpolatedNormal(x / xBound, z / zBound);
|
||||
newPlant.transform.LookAt(normal);
|
||||
newPlant.transform.Rotate(new Vector3(90, 0, 0));
|
||||
Vector3 newPlantPos = new Vector3(x, y, z);
|
||||
newPlant.transform.position = newPlantPos;
|
||||
plants.Add(newPlant);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
for(int i = 0; i < plants.Count; i ++)
|
||||
{
|
||||
GameObject currentPlant = plants[i];
|
||||
Plant plantI = currentPlant.GetComponent<Plant>();
|
||||
if(!plantI.isAlive)
|
||||
{
|
||||
currentPlant.SetActive(false);
|
||||
plants.Remove(currentPlant);
|
||||
Destroy(currentPlant);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9529d38afda2d141bd48565721ab95f
|
||||
Reference in New Issue
Block a user