This commit is contained in:
juliuse98
2021-10-01 23:19:42 +02:00
51 changed files with 1026 additions and 170 deletions

View File

@@ -4,9 +4,15 @@ using UnityEngine;
public abstract class Building : MonoBehaviour
{
public string title = "New Building";
public string description = "A cool new building";
public abstract string GetTitle();
public abstract string GetDescription();
public enum BuildingType
{
Housing,
Storage,
Decoration
}
public BuildingType buildingType;
}

View File

@@ -14,6 +14,7 @@ public abstract class BuildingBlueprint : MonoBehaviour
Ray ray;
public abstract void Init();
public abstract void WhileColliding();
public abstract void WhileNotColliding();

View File

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

View File

@@ -4,23 +4,29 @@ using UnityEngine;
public class HouseBlueprint : BuildingBlueprint
{
public Material collisionMat;
public Material collisionMat;
public Material blueprintMat;
private Transform houseCube;
public override void Init()
{
//Haus cube ím Obj -> hier wird es benutzt zum material ändern
houseCube = gameObject.transform.Find("HouseCube");
}
public override void WhileColliding()
{
//Wenn es collidet soll der HouseCube IM Object verä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

@@ -0,0 +1,14 @@
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

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

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WarehouseBuilding : StorageBuilding
{
private void Start()
{
inventorySpace = 500;
}
}

View File

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

View File

@@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HouseBuildingScript : Building
{
[SerializeField] private string title = "House";
[SerializeField] private string description = "A place for people to live in.";
public override string GetTitle()
{
return title;
}
public override string GetDescription()
{
return description;
}
}

View File

@@ -19,8 +19,6 @@ public class InfoSign : Interactable
public override void Interact()
{
Debug.Log(parentBuilding.GetTitle());
Debug.Log("interact");
}
}

View File

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

View File

@@ -0,0 +1,102 @@
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 Start()
{
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

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

View File

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

View File

@@ -0,0 +1,108 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[Header("Force Modifier")]
[SerializeField] private float speed = 12f;
[SerializeField] private float sneakSpeedModifier = 0.7f;
[SerializeField] private float sprintSpeedModifier = 1.4f;
[SerializeField] private float jumpSprintSpeedModifier = 20f;
[SerializeField] private float jumpForce = 3.5f;
[SerializeField] private float fallMultiplier = 2.5f;
[Header("Ground Check")]
[SerializeField] private Transform groundCheck;
[SerializeField] private float groundDistance = 0.4f;
[SerializeField] private LayerMask groundMask;
public bool isSprinting = false;
public bool isSneaking = false;
private Rigidbody rb;
private bool isGrounded;
private float modifiedSpeed;
private bool isJumpSprinting = false;
float x;
float z;
Vector3 movement;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
Grounded();
Jump();
MovementSpeed();
}
private void FixedUpdate()
{
rb.velocity = movement;
}
private void Grounded()
{
//Check every frame if the player stands on the ground
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded)
{
isJumpSprinting = false;
}
}
private void MovementSpeed()
{
modifiedSpeed = speed; //RESET speed
//Sprint
if (Input.GetButton("Sprint") && isGrounded)
{
isSprinting = true;
modifiedSpeed *= sprintSpeedModifier;
}
else
{
isSprinting = false;
//Sneak
if (Input.GetButton("Sneak") && isGrounded)
{
isSneaking = true;
modifiedSpeed *= sneakSpeedModifier;
}
else
{
isSneaking = false;
}
}
x = Input.GetAxis("Horizontal");
z = Input.GetAxis("Vertical");
movement = x * modifiedSpeed * transform.right + new Vector3(0, rb.velocity.y, 0) + z * modifiedSpeed * transform.forward;
}
private void Jump()
{
//Better Falling
if(rb.velocity.y < 0)
{
rb.velocity += Vector3.up * Physics.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
}
if (Input.GetButtonDown("Jump") && isGrounded)
{
//Add Force Up To Jump
rb.AddForce(Vector3.up * jumpForce * 100); //Times 100 -> so we can use smaller numbers in the editor
}
}
}

View File

@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPSCounter : MonoBehaviour
{
public TMPro.TextMeshProUGUI fpsText;
public float deltaTime;
void Start()
{
fpsText = gameObject.GetComponent<TMPro.TextMeshProUGUI>();
}
void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
float fps = 1.0f / deltaTime;
fpsText.text = Mathf.Ceil(fps).ToString() + "FPS";
}
}

View File

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

View File

@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TerrainGenerator : MonoBehaviour
{
public (float y, bool isTerrain) GetTerrainHit(float x, float z)
{
float y = 0;
bool isTerrain = false;
Vector3 position = new Vector3(x, 50, z);
RaycastHit hit;
if(Physics.Raycast(position, Vector3.down, out hit, Mathf.Infinity))
{
if(hit.transform.tag == "Terrain")
{
Debug.Log("Terrain Hit");
y = hit.point.y;
Debug.Log(hit.point.y);
isTerrain = true;
}
else
{
y = hit.point.y;
}
}
else
{
Debug.Log("Terrain not Hit");
}
return (y, isTerrain);
}
}

View File

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

View File

@@ -1,102 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private CharacterController controller;
//[SerializeField] private Transform playerTransform;
[SerializeField] private float speed = 12f;
[SerializeField] private float airSpeed = 0.6f;
[SerializeField] private float sneakSpeed = 0.4f;
[SerializeField] private float sprintSpeed = 1.8f;
[SerializeField] private float sprintAirSpeed = 1.4f;
[SerializeField] private float gravity = -9.81f;
[SerializeField] private float jumpHeight = 3f;
[SerializeField] private Transform groundCheck;
[SerializeField] private float groundDistance = 0.4f;
[SerializeField] private LayerMask groundMask;
private Vector3 velocity;
private bool isGrounded;
private bool isSprinting = false;
private bool isSneaking = false;
void Update()
{
//GROUND CHECK
//Creates an invisible sphere on the bottom of our player
//And checks if it's colliding with something !with the "ground"-Mask in Unity!
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
//Reset velocity if grounded
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
//MOVEMENT
//Input.GetAxis is based on the Unity Input settings (edit -> Project Settings -> Input Manager)
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
//Create move vector !in look direction!
Vector3 move;
if (isGrounded)//for air control
{
move = transform.right * x + transform.forward * z;
//SPRINT
if (Input.GetButton("Sprint"))
{
move *= sprintSpeed;
isSprinting = true;
}
else
{
//SNEAK
if (Input.GetButton("Sneak"))
{
move *= sneakSpeed;
isSneaking = true;
//Kommt mit character model und animations
}
else
{
isSneaking = false;
}
isSprinting = false;
}
//JUMP
if (Input.GetButtonDown("Jump"))
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
}
else//Air control
{
if (isSprinting)
{
move = transform.right * x * airSpeed * sprintAirSpeed + transform.forward * z * airSpeed * sprintAirSpeed;
}
else
{
move = transform.right * x * airSpeed + transform.forward * z * airSpeed;
}
}
//Apply move vector
controller.Move(move * speed * Time.deltaTime);
//Add gravity to current velocity
velocity.y += gravity * Time.deltaTime;
//apply gravity
controller.Move(velocity * Time.deltaTime);//nochmal time.deltatime wegen irgendwas mit physikalischer Formel und so
}
}

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ResourceUiTextScript : MonoBehaviour
{
private ResourceManager resourceManager;
private string str = "";
private TMPro.TextMeshProUGUI textResource;
private void Start()
{
resourceManager = GameObject.Find("GameManager").GetComponent<ResourceManager>();
textResource = GetComponent<TMPro.TextMeshProUGUI>();
}
void Update()
{
List<Item> inventory = new List<Item>();
inventory = resourceManager.GetAllResources();
str = "";
foreach(Item i in inventory)
{
if(i != null)
{
str += i.count.ToString() + " " + i.name + "\n";
}
}
textResource.text = str;
}
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StoneItem : Item
{
public StoneItem(int c = 1)
{
count = c;
name = "Stone";
uuid = "item_stone";
}
}

View File

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

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WoodItem : Item
{
public WoodItem(int c = 1)
{
count = c;
name = "Wood";
uuid = "item_wood";
}
}

View File

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

View File

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

View File

@@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Item
{
public string name = "New Item";
public string uuid = "new_item";
public Sprite icon = null;
public int count = 1;
public Item(int c = 1)
{
count = c;
}
}

View File

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

View File

@@ -0,0 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResourceManager: MonoBehaviour
{
[SerializeField] private GameObject[] storageBuildings;
private void Start()
{
storageBuildings = GameObject.FindGameObjectsWithTag("StorageBuilding");
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.K))
{
Item wood = new WoodItem(10);
storageBuildings[0].GetComponent<StorageBuilding>().Add(wood);
}
if (Input.GetKeyDown(KeyCode.I))
{
Item stone = new StoneItem(12);
storageBuildings[0].GetComponent<StorageBuilding>().Add(stone);
}
if (Input.GetKeyDown(KeyCode.L))
{
GetAllResources();
}
}
public List<Item> GetAllResources()
{
List<Item> inventory = new List<Item>();
//F<>r jedes StorageBuilding
foreach(GameObject b in storageBuildings)
{
List<Item> buildingInv = b.GetComponent<StorageBuilding>().Getinventory();
//Add items to already existing item +=
foreach (Item item in buildingInv)
{
foreach(Item i in inventory)
{
if(i.uuid == item.uuid)
{
i.count += item.count;
buildingInv.Remove(item);
}
}
}
//Add den Rest
foreach(Item item in buildingInv)
{
inventory.Add(item);
}
}
/*
Debug.Log(inventory);
Debug.Log(inventory[0].count);
Debug.Log(inventory[1].count);*/
return inventory;
}
}

View File

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

View File

@@ -5,18 +5,19 @@ using UnityEngine.UI;
public class TimeTextScript : MonoBehaviour
{
[SerializeField] private GameObject GamerManager;
private GameObject GameManager;
private string timeStr = "";
private Text timeText;
private void Start()
{
GameManager = GameObject.Find("GameManager");
timeText = GetComponent<Text>();
}
void Update()
{
timeStr = GamerManager.GetComponent<TimeManager>().GetTimeString();
timeStr = GameManager.GetComponent<TimeManager>().GetTimeString();
timeText.text = timeStr;
}
}