Merged the other utility and remove meta files

This commit is contained in:
Martin 2020-12-09 01:36:26 -05:00
parent 33bc524297
commit 4e7f047ed7
33 changed files with 353 additions and 308 deletions

63
.gitignore vendored
View File

@ -1,63 +0,0 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Mm]emoryCaptures/
# Never ignore Asset meta data
!/[Aa]ssets/**/*.meta
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# TextMesh Pro files
[Aa]ssets/TextMesh*Pro/
# Autogenerated Jetbrains Rider plugin
[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
# Builds
*.apk
*.unitypackage
# Crashlytics generated file
crashlytics-build.properties

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,20 @@
using UnityEngine;
public class UpdateChild{
public static void recursiveCallOnChild (GameObject _obj)
{
if (_obj == null)
return;
//Changes to the current object
foreach (Transform _child in _obj.transform)
{
if (_child == null)
continue;
recursiveCallOnChild(_child.gameObject);
}
}
}

View File

@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ApplyRandForce : MonoBehaviour {
public string buttonName = "Fire1";
public float forceAmount = 10.0f;
public float torqueAmount = 10.0f;
public ForceMode forceMode;
public float maxAngularVelocity;
public Rigidbody rb;
void Start() {
rb.maxAngularVelocity = maxAngularVelocity;
}
void FixedUpdate ()
{
if(Input.GetButtonDown(buttonName))
{
rb.AddForce(Random.onUnitSphere*forceAmount,forceMode);
rb.AddTorque(Random.onUnitSphere * torqueAmount, forceMode);
}
}
}

11
DiceRolling/DieValue.cs Normal file
View File

@ -0,0 +1,11 @@
using UnityEngine;
public class DieValue : MonoBehaviour
{
public int value;
public int getValue() {
return value;
}
}

View File

@ -0,0 +1,31 @@
using UnityEngine;
public class DisplayCurrentDieValue : MonoBehaviour
{
public LayerMask dieValueColliderLayer;
public Rigidbody rb;
private int currentValue;
private bool rollComplete = false;
void Update () {
if (rb.IsSleeping() && !rollComplete)
{
rollComplete = true;
Debug.Log("Dice stopped rolling, result is: " + currentValue.ToString());
}
else if(!rb.IsSleeping())
{
rollComplete = false;
}
RaycastHit hit;
if(Physics.Raycast(transform.position,Vector3.up,out hit,Mathf.Infinity,dieValueColliderLayer)){
// Reading the value of the collider on the die top face
currentValue = hit.collider.GetComponent<DieValue>().getValue();
}
}
}

226
Grid System/GridSystem.cs Normal file
View File

@ -0,0 +1,226 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridSystem : MonoBehaviour {
public LayerMask mask;
public GameObject prefab;
public float nodeSize = 1f;
private Grid grid;
private GameObject currentPrefab;
private int gridSizeX;
private int gridSizeZ;
private Boolean currentPrefabOnMat = false;
// Use this for initialization
void Start () {
//Get Size of the gameMat
GetGridSize();
//Create the grid of nodes to the size of the mat
CreateGrid();
}
void Update () {
CheckKeyDown();
CheckMouseDown();
currentPrefabOnMat = MovePrefabToMouse();
}
private Boolean MovePrefabToMouse() {
int x;
int y;
if (MouseOnTableMat(out x, out y)) {
if (currentPrefab != null) {
if (x != -1 && y != -1) {
MoveCurrentPrefab(x, y);
return prefabOnMat();
}
}
}
return false;
}
private bool prefabOnMat() {
Boolean onMat = true;
foreach (Transform child in currentPrefab.transform) {
int x = Mathf.FloorToInt(currentPrefab.transform.position.x -
nodeSize / 2 +
child.localPosition.x / nodeSize +
gridSizeX / 2 -
transform.position.x);
int y = Mathf.FloorToInt(currentPrefab.transform.position.z -
nodeSize / 2 +
child.localPosition.z / nodeSize +
gridSizeZ / 2 -
transform.position.z);
if (!(Mathf.Clamp(x, 0, gridSizeX - 1) == x &&
Mathf.Clamp(y, 0, gridSizeZ - 1) == y)) {
onMat = false;
} else {
if (grid.grid[x, y].occupied) {
onMat = false;
}
}
}
return onMat;
}
private void CheckMouseDown() {
if (Input.GetMouseButtonDown(0) && currentPrefabOnMat) {
foreach (Transform child in currentPrefab.transform) {
int x = Mathf.Clamp(
Mathf.FloorToInt(currentPrefab.transform.position.x -
nodeSize / 2 +
child.localPosition.x / nodeSize +
gridSizeX / 2 -
transform.position.x),
0, gridSizeX - 1);
int y = Mathf.Clamp(
Mathf.FloorToInt(currentPrefab.transform.position.z -
nodeSize / 2 +
child.localPosition.z / nodeSize +
gridSizeZ / 2 -
transform.position.z),
0, gridSizeZ - 1);
grid.grid[x, y].occupied = true;
}
currentPrefab = null;
}
}
private void CheckKeyDown() {
if (Input.GetKeyDown(KeyCode.A)) {
if (currentPrefab == null) {
currentPrefab = Instantiate(prefab)
} else {
Destroy(currentPrefab);
}
}
}
private void MoveCurrentPrefab(int x, int y) {
currentPrefab.transform.position = grid.grid[x,y].centerWorldPosition;
}
private bool MouseOnTableMat(out int x, out int y) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitPoint;
if (Physics.Raycast(ray, out hitPoint, Mathf.Infinity, mask)) {
if (hitPoint.collider == GetComponent<Collider>()) {
x = Mathf.Clamp(
Mathf.FloorToInt(hitPoint.point.x - transform.position.x + gridSizeX / 2),
0, gridSizeX - 1);
y = Mathf.Clamp(
Mathf.FloorToInt(hitPoint.point.z - transform.position.z + gridSizeZ / 2),
0, gridSizeZ - 1);
return true;
}
}
x = -1;
y = -1;
return false;
}
private void GetGridSize() {
Bounds borders = GetComponent<Renderer>().bounds;
gridSizeX = Mathf.RoundToInt(borders.size.x);
gridSizeZ = Mathf.RoundToInt(borders.size.z);
}
private void CreateGrid() {
grid = new Grid(transform.position, gridSizeX, gridSizeZ, nodeSize);
}
}
public class Node{
public Vector3 centerWorldPosition;
public bool occupied;
public Node(Vector3 centerWorldPosition)
{
this.centerWorldPosition = centerWorldPosition;
occupied = false;
}
}
public class Grid{
public Node[,] grid;
public Grid(Vector3 gridCenter, int gridSizeX, int gridSizeZ, float NodeSize){
grid = new Node[gridSizeX, gridSizeZ];
for (int row = 0 ; row < gridSizeX; row++){
for (int collumn = 0; collumn < gridSizeZ ; collumn++){
Vector3 centerWorldPosition = gridCenter - (Vector3.right * gridSizeX / 2) -
(Vector3.forward * gridSizeZ / 2) +
(Vector3.right * NodeSize * row) +
(Vector3.forward * NodeSize * collumn) +
(Vector3.right * NodeSize / 2) +
(Vector3.forward * NodeSize / 2);
grid[row,collumn] = new Node(centerWorldPosition);
}
}
}
public String toString() {
String str = "";
for (int i = 0; i < 8; i++) {
for (int y = 0; y < 4; y++) {
str += $"\n[{i},{y}] : {grid[i, y].centerWorldPosition} - {grid[i, y].occupied}";
}
}
return str;
}
}

View File

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

View File

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

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 763c15382e59a164ebdff5864aecb39e
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,15 +0,0 @@
{
"name": "johnsonutils",
"references": [
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 81a2d0c288f3eb34abca706b734ef42c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

38
Utility/PopupMessage.cs Normal file
View File

@ -0,0 +1,38 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// This class sets the text and image of the popup message
/// </summary>
public class PopupMessage : MonoBehaviour
{
public TextMeshProUGUI popupMessage;
private Image image;
/// <summary>
/// Gets the X mark image in the child object
/// </summary>
private void Awake()
{
image = GetComponentsInChildren<Image>()[1];
}
/// <summary>
/// Sets the new test and shows or hides the X mark image.
/// Hides the whole gameObject after 2 seconds
/// </summary>
/// <param name="newText"></param>
/// <param name="enabled"></param>
/// <returns></returns>
public IEnumerator Reset(string newText, bool enabled = false)
{
popupMessage.text = newText;
image.gameObject.SetActive(enabled);
yield return new WaitForSeconds(2f);
gameObject.SetActive(false);
}
}

View File

@ -1,11 +0,0 @@
{
"name": "com.johnson-utils",
"version": "1.0.1",
"displayName": "Johnson Utils",
"description": "Utility used in prototypes and game dev",
"unity": "2019.3",
"author":{
"name": "Martin Johnson",
"email": "martinjohnson@live.ca"
}
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 3f5fd77dea328bc47b5c1f706630fddb
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: