started working on Building rework

This commit is contained in:
DerTyp187
2021-10-03 18:34:14 +02:00
parent 75a6f34ece
commit 881364449b
47 changed files with 523 additions and 416 deletions

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 798eecf368f882c46a67ab4e6354bc7e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Building : MonoBehaviour
{
public string title = "New Building";
public string description = "A cool new building";
public enum BuildingType
{
Housing,
Storage,
Decoration
}
public BuildingType buildingType;
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5c2ebc4f7d4eb064b814863e80d9bab0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,135 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class BuildingBlueprint : MonoBehaviour
{
public bool isColliding;
public GameObject constructionPrefab;
public Material collisionMat;
public Material blueprintMat;
private GameObject terrain;
private Canvas hud;
Ray ray;
public abstract void Init();
public abstract void WhileColliding();
public abstract void WhileNotColliding();
private void Start()
{
hud = GameObject.Find("HUD").GetComponent<Canvas>(); //Get HUD Canvas
terrain = GameObject.FindGameObjectWithTag("Terrain"); //Get Terrain
//Bug Fix Blueprints already existing
//Delete/CleanUp all objs with tag "Blueprint"
GameObject[] blueprints = GameObject.FindGameObjectsWithTag("Blueprint");
foreach (GameObject blueprint in blueprints)
Destroy(blueprint);
gameObject.tag = "Blueprint"; //Give Gameobject the tag "Blueprint" (after deleting all objs with this tag)
hud.enabled = false; //Hide HUD
Init(); //Call init callback function for children
}
public void Update()
{
FollowMouse();
Rotate();
//Collinding Callbacks
if (isColliding)
{
WhileColliding();
}
else
{
WhileNotColliding();
}
//PLACE
if (Input.GetMouseButtonDown(0) && !isColliding)
{
Place();
}
}
void FollowMouse()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitData;
if (terrain.GetComponent<Collider>().Raycast(ray, out hitData, Mathf.Infinity))
{
transform.position = hitData.point;
}
}
void Rotate()
{
if (Input.GetButtonDown("Rotate"))
{
Debug.Log("Rotate+");
if (Input.GetKey(KeyCode.LeftShift))
{
transform.Rotate(0, 5, 0);
}
else if (Input.GetKey(KeyCode.LeftControl))
{
transform.Rotate(0, 45, 0);
}
else
{
transform.Rotate(0, 22.5f, 0);
}
}
if (Input.GetButtonDown("CounterRotate"))
{
Debug.Log("Rotate-");
if (Input.GetKey(KeyCode.LeftShift))
{
transform.Rotate(0, -5, 0);
}
else if (Input.GetKey(KeyCode.LeftControl))
{
transform.Rotate(0, -45, 0);
}
else
{
transform.Rotate(0, -22.5f, 0);
}
}
}
void Place()
{
Instantiate(constructionPrefab, transform.position, transform.rotation);
Destroy(this.gameObject);
hud.enabled = true;
}
//Collision
public void OnCollisionEnter(Collision c)
{
isColliding = true;
Debug.Log("Colliding True");
}
public void OnCollisionStay(Collision c)
{
isColliding = true;
Debug.Log("Colliding True");
}
public void OnCollisionExit(Collision c)
{
isColliding = false;
Debug.Log("Colliding False");
}
}

View File

@@ -1,14 +0,0 @@
fileFormatVersion: 2
guid: 76f9b3b57e22ab047b8f95bcb552289a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- constructionPrefab: {instanceID: 0}
- collisionMat: {fileID: 2100000, guid: a1e8fb1ea637c0e45bed70dd7d1feaab, type: 2}
- blueprintMat: {fileID: 2100000, guid: 78d3985cb7b88204b930cd05567c0c61, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,26 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class BuildingConstruction : MonoBehaviour
{
public GameObject building;
public abstract bool CheckForResources();
public abstract void Init();
private void Start()
{
Init();
}
private void Update()
{
if (CheckForResources())
{
Instantiate(building, gameObject.transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 891ae650cdb2a6a438a2fd1bbb520db2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,26 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BuildingPlacement : MonoBehaviour
{
[SerializeField] private GameObject terrain;
[SerializeField] private GameObject prefab;
Ray ray;
void Update()
{
// Build Button Handler
if (Input.GetButtonDown("Build"))
{ // Wenn man den Button 'B'
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitData;
if (terrain.GetComponent<Collider>().Raycast(ray, out hitData, Mathf.Infinity))
{
Instantiate(prefab, hitData.point, Quaternion.identity);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 2fe01a752f991734aa307cc7b7665015
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 67b1c241d94696c409ad579573961232
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e0c8f7012e4cce54bb00c3edeac83c65
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,31 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HouseBlueprint : BuildingBlueprint
{
private Transform houseCube;
public override void Init()
{
//Haus cube <20>m Obj -> hier wird es benutzt zum material <20>ndern
houseCube = gameObject.transform.Find("HouseCube");
}
public override void WhileColliding()
{
//Wenn es collidet soll der HouseCube IM Object ver<65>ndert werden!
//Das ist bei jedem Building anders
houseCube.GetComponent<MeshRenderer>().material = collisionMat;
}
public override void WhileNotColliding()
{
//Das selbe wie bei "WhileColliding"
houseCube.GetComponent<MeshRenderer>().material = blueprintMat;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 6d49e2868fa536c4fac8ec278501f38b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,14 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HouseBuildingScript : Building
{
private void Start()
{
title = "House";
description = "A place to live in";
buildingType = BuildingType.Housing;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 255558bfba6648641822c24b4555e7db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,26 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HouseConstruction : BuildingConstruction
{
[Header("Needed Resources")]
[SerializeField] private int neededWood = 10;
[Header("Having Resources")]
[SerializeField] private int havingWood = 0;
public override void Init()
{
}
public override bool CheckForResources()
{
if (havingWood == neededWood)
{
return true;
}
return false;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b49d2e0b5f1b960469b9dc34355fcc5f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 03d0b1e434e28de4f9f37f90abf6d095
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,34 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WarehouseBlueprint : BuildingBlueprint
{
private MeshRenderer[] childrenMeshRenderer;
public override void Init()
{
//Haus cube <20>m Obj -> hier wird es benutzt zum material <20>ndern
childrenMeshRenderer = gameObject.GetComponentsInChildren<MeshRenderer>();
}
public override void WhileColliding()
{
//Wenn es collidet soll der HouseCube IM Object ver<65>ndert werden!
//Das ist bei jedem Building anders
foreach(MeshRenderer r in childrenMeshRenderer)
{
r.material = collisionMat;
}
}
public override void WhileNotColliding()
{
//Das selbe wie bei "WhileColliding"
foreach (MeshRenderer r in childrenMeshRenderer)
{
r.material = blueprintMat;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c08df78a8e2e51d4c80019a27fc2cc5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,15 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WarehouseBuilding : StorageBuilding
{
private void Start()
{
title = "Warehouse";
description = "A place to store your resources";
inventorySpace = 500;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8a48bc1459390b4459fbf54ad16b50f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,25 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WarehouseConstruction : BuildingConstruction
{
[Header("Needed Resources")]
[SerializeField] private int neededWood = 10;
[Header("Having Resources")]
[SerializeField] private int havingWood = 0;
public override void Init()
{
}
public override bool CheckForResources()
{
if (havingWood == neededWood)
{
return true;
}
return false;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c290e17b16e818841aabd5083a3475db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,25 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InfoSign : Interactable
{
private Building parentBuilding;
private void Start()
{
parentBuilding = this.transform.parent.gameObject.GetComponent<Building>();
}
public override string GetDescription()
{
return "Press [E] to get <color=blue>info</color>.";
}
public override void Interact()
{
Debug.Log("interact");
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 0b83755523bca294c8ebaacb9bfd6f02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: efcc2aca90f2a2b4eb81b54c475f3df4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,105 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StorageBuilding : Building
{
[SerializeField] private List<Item> inventory = new List<Item>();
public int inventorySpace;
public void Awake()
{
buildingType = BuildingType.Storage;
}
public void Add(Item item)
{
if(GetFreeSpace() >= item.count)
{
bool added = false;
//Check if the Item can get stacked
foreach (Item i in inventory)
{
if (i.uuid == item.uuid)
{
i.count += item.count;
added = true;
return;
}
added = false;
}
//If foreach does not work just ADD (List is empty)
if (!added)
{
inventory.Add(item);
}
}
else
{
Debug.Log("Inventory Full");
}
//TODO mach wenn nicht ganz voll, dass dann so viele items added werden wie platz ist
//Sonst wird bei 20 Holz KOMPLETT nein gesagt weil/obowhl 19 Space noch da ist
}
public void Remove(Item item)
{
//Check if the Item can get stacked
foreach (Item i in inventory)
{
if (i.uuid == item.uuid)
{
if(i.count > item.count)
{
i.count -= item.count;
}else if(i.count <= item.count)
{
//!!!Muss eventuell sp<73>ter anders gehandelt werden!!!
inventory.Remove(i); //Wenn du mehr entfernst als im Inventar ist, dann wird das Item einfach komplett removed
}
}
}
}
public int GetCountOfItem(Item item)
{
int count = 0;
foreach(Item i in inventory)
{
if(i.uuid == item.uuid)
{
count += i.count;
}
}
return count;
}
public int GetUsedSpace()
{
int usedSpace = 0;
foreach(Item item in inventory)
{
usedSpace += item.count;
}
return usedSpace;
}
public int GetFreeSpace()
{
return inventorySpace - GetUsedSpace();
}
public List<Item> Getinventory()
{
return inventory;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9cd3101a861849b4f97e2f4f499d7d46
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: