Implement hand menu features

This commit is contained in:
2024-09-07 20:42:45 +02:00
parent f690fb53c8
commit 3357191134
621 changed files with 410674 additions and 3861 deletions

View File

@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM && DNP_NewInputSystem
using UnityEngine.InputSystem;
#endif
namespace DamageNumbersPro.Demo
{
public class DNP_2DDemo : MonoBehaviour
{
float nextShotTime;
void Start()
{
nextShotTime = 0;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
void Update()
{
HandleShooting();
}
void HandleShooting()
{
if (DNP_InputHandler.GetLeftClick())
{
Shoot();
nextShotTime = Time.time + 0.3f;
}
else if (DNP_InputHandler.GetRightHeld() && Time.time > nextShotTime)
{
Shoot();
nextShotTime = Time.time + 0.06f;
}
}
void Shoot()
{
Vector2 mousePosition = Vector2.zero;
#if ENABLE_INPUT_SYSTEM && DNP_NewInputSystem
if (Mouse.current != null) {
mousePosition = Mouse.current.position.ReadValue();
}
#else
mousePosition = Input.mousePosition;
#endif
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(mousePosition);
worldPosition.z = 0;
RaycastHit2D hit = Physics2D.Raycast(worldPosition, Vector2.down, 0.2f);
//Select Damage Number:
DNP_PrefabSettings settings = DNP_DemoManager.instance.GetSettings();
DamageNumber prefab = DNP_DemoManager.instance.GetCurrent();
//Number:
float number = 1 + Mathf.Pow(Random.value, 2.2f) * settings.numberRange;
if (prefab.digitSettings.decimals == 0)
{
number = Mathf.Floor(number);
}
//Create Damage Number:
DamageNumber newDamageNumber = prefab.Spawn(worldPosition, number);
if (hit.collider != null)
{
newDamageNumber.SetFollowedTarget(hit.collider.transform);
}
//Apply Demo Settings:
settings.Apply(newDamageNumber);
}
}
}

View File

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

View File

@@ -0,0 +1,225 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_Camera : MonoBehaviour
{
//Instance:
public static DNP_Camera instance;
//Shooting:
GameObject cubeHighlight;
float nextShotTime;
float nextRaycastTime;
float lookTime;
//Movement:
Vector3 velocity;
void Awake()
{
instance = this;
cubeHighlight = GameObject.Find("Special").transform.Find("Prefabs/Other/Cube Highlight").gameObject;
}
void Update()
{
HandleMovement();
HandleShooting();
//Escape:
if(DNP_InputHandler.GetEscape())
{
ShowMouse();
Invoke("ShowMouse", 0.1f);
Invoke("ShowMouse", 0.2f);
Invoke("ShowMouse", 0.25f);
Invoke("ShowMouse", 0.3f);
CancelInvoke("HideMouse");
}
}
void ShowMouse()
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
void HideMouse()
{
if(DNP_InputHandler.GetLeftHeld())
{
Invoke("HideMouse", 0.1f);
}
else
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
}
void LateUpdate()
{
HandleLooking();
}
//Functions:
void HandleShooting()
{
if(DNP_InputHandler.GetLeftClick())
{
Shoot();
nextShotTime = Time.time + 0.3f;
} else if(DNP_InputHandler.GetRightHeld() && Time.time > nextShotTime)
{
Shoot();
nextShotTime = Time.time + 0.06f;
}
//Detection:
if (Time.time > nextRaycastTime)
{
nextRaycastTime = Time.time + 0.11f;
RaycastHit raycast;
if (Physics.Raycast(transform.position, transform.forward, out raycast, 100))
{
DNP_Crosshair.targetEnemy = raycast.collider.gameObject.layer == 1;
}
}
}
void Shoot()
{
if (Cursor.visible)
{
if(!IsInvoking("HideMouse"))
{
Invoke("HideMouse", 0.1f);
lookTime = Time.time + 0.3f;
}
return;
}
RaycastHit raycast;
if(Physics.Raycast(transform.position, transform.forward, out raycast, 100))
{
//Create Damage Number:
DNP_PrefabSettings settings = DNP_DemoManager.instance.GetSettings();
DamageNumber prefab = DNP_DemoManager.instance.GetCurrent();
float number = 1 + Mathf.Pow(Random.value, 2.2f) * settings.numberRange;
if(prefab.digitSettings.decimals == 0)
{
number = Mathf.Floor(number);
}
DamageNumber newDamageNumber = prefab.Spawn(raycast.point, number);
//Apply Demo Settings:
settings.Apply(newDamageNumber);
//Create Cube:
if (raycast.collider.gameObject.layer != 1)
{
Vector3 cubePosition = raycast.point - raycast.normal * 0.1f;
cubePosition.x = Mathf.FloorToInt(cubePosition.x) + 0.5f;
cubePosition.y = Mathf.FloorToInt(cubePosition.y) + 0.5f;
cubePosition.z = Mathf.FloorToInt(cubePosition.z) + 0.5f;
GameObject newCube = Instantiate<GameObject>(cubeHighlight);
newCube.transform.position = cubePosition;
newCube.SetActive(true);
DNP_Crosshair.instance.HitWall();
}
else
{
DNP_Enemy enemy = raycast.collider.GetComponent<DNP_Enemy>();
DNP_Crosshair.instance.HitEnemy();
if (enemy != null)
{
if(settings.damage > 0)
{
enemy.Hurt(settings.damage);
}
if(newDamageNumber.spamGroup != "")
{
newDamageNumber.spamGroup += enemy.GetInstanceID();
}
newDamageNumber.enableFollowing = true;
newDamageNumber.followedTarget = enemy.GetPelvis();
}
}
}
}
void HandleLooking()
{
if (Time.time < lookTime || Cursor.visible) return;
Vector2 mouseDelta = DNP_InputHandler.GetMouseDelta();
Vector3 eulerAngles = transform.eulerAngles;
eulerAngles.y += mouseDelta.x;
eulerAngles.x -= mouseDelta.y;
if (eulerAngles.x > 180)
{
eulerAngles.x -= 360;
}
eulerAngles.x = Mathf.Clamp(eulerAngles.x, -80f, 80f);
transform.eulerAngles = eulerAngles;
}
void HandleMovement()
{
Vector3 desiredDirection = Vector3.zero;
if (DNP_InputHandler.GetRight())
{
desiredDirection.x += 1;
}
if (DNP_InputHandler.GetLeft())
{
desiredDirection.x += -1;
}
if (DNP_InputHandler.GetForward())
{
desiredDirection.z += 1;
}
if (DNP_InputHandler.GetBack())
{
desiredDirection.z += -1;
}
if (DNP_InputHandler.GetUp())
{
desiredDirection.y += 1;
}
if (DNP_InputHandler.GetDown())
{
desiredDirection.y += -1;
}
if(desiredDirection.magnitude > 0.1f)
{
desiredDirection.Normalize();
}
velocity = Vector3.Lerp(velocity, (desiredDirection.z * transform.forward + desiredDirection.x * transform.right + desiredDirection.y * Vector3.up) * 7f, Time.deltaTime * 6f);
Vector3 position = transform.position;
Vector3 clampedPosition = new Vector3(Mathf.Clamp(position.x, -4f, 4f), Mathf.Clamp(position.y, 1f, 6f), Mathf.Clamp(position.z, -12f, 4f));
position = Vector3.Lerp(position, clampedPosition, Time.deltaTime * 15f) + velocity * Time.deltaTime;
//Apply:
transform.position = position;
}
}
}

View File

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

View File

@@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace DamageNumbersPro.Demo
{
public class DNP_Crosshair : MonoBehaviour
{
public static DNP_Crosshair instance;
public static bool targetEnemy;
public Color defaultColor = new Color(1, 1, 1, 0.6f);
public float defaultScale = 1f;
public Color enemyColor = new Color(1, 0.2f, 0.2f, 0.8f);
public float enemyScale = 1.15f;
Image image;
void Awake()
{
instance = this;
image = GetComponent<Image>();
}
void FixedUpdate()
{
if(Cursor.visible)
{
image.color = Color.Lerp(image.color, new Color(1,1,1,0), Time.fixedDeltaTime * 7f);
}
else if(targetEnemy)
{
image.color = Color.Lerp(image.color, enemyColor, Time.fixedDeltaTime * 7f);
float scale = Mathf.Lerp(transform.localScale.x, enemyScale, Time.fixedDeltaTime * 7f);
transform.localScale = new Vector3(scale, scale, 1);
}
else
{
image.color = Color.Lerp(image.color, defaultColor, Time.fixedDeltaTime * 7f);
float scale = Mathf.Lerp(transform.localScale.x, defaultScale, Time.fixedDeltaTime * 7f);
transform.localScale = new Vector3(scale, scale, 1);
}
}
public void HitEnemy()
{
transform.localScale = new Vector3(1.7f, 1.7f, 1f);
image.color = Color.red;
}
public void HitWall()
{
transform.localScale = new Vector3(1.5f, 1.5f, 1f);
image.color = Color.white;
}
}
}

View File

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

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_CubeHighlight : MonoBehaviour
{
public string propertyName = "_Color";
public AnimationCurve propertyCurve;
public float destructionDelay = 0.2f;
Material mat;
int propertyID;
float startTime;
void Start()
{
startTime = Time.time;
propertyID = Shader.PropertyToID(propertyName);
MeshRenderer mr = GetComponent<MeshRenderer>();
mat = mr.material;
Destroy(gameObject, destructionDelay);
}
void FixedUpdate()
{
mat.SetColor(propertyID, new Color(1, 0, 0, propertyCurve.Evaluate(Time.time - startTime)));
}
}
}

View File

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

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_CubeSpawner : MonoBehaviour
{
public float delay = 0.2f;
public GameObject cube;
void Start()
{
InvokeRepeating("SpawnCube", 0, delay);
}
void SpawnCube()
{
GameObject newCube = Instantiate<GameObject>(cube);
newCube.SetActive(true);
newCube.transform.SetParent(transform, true);
newCube.transform.localScale = Vector3.one;
}
}
}

View File

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

View File

@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_CursorHint : MonoBehaviour
{
CanvasGroup cg;
void Start()
{
cg = GetComponent<CanvasGroup>();
}
void FixedUpdate()
{
if(Cursor.visible)
{
cg.alpha = Mathf.Max(cg.alpha - Time.deltaTime * 2f, 0);
}else
{
cg.alpha = Mathf.Min(cg.alpha + Time.deltaTime * 2f, 1);
}
}
}
}

View File

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

View File

@@ -0,0 +1,170 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace DamageNumbersPro.Demo
{
public class DNP_DemoManager : MonoBehaviour
{
public static DNP_DemoManager instance;
Text currentPrefabText;
Text currentIndexText;
DamageNumber[] prefabs;
int currentIndex;
DNP_PrefabSettings currentSettings;
CanvasGroup fade;
bool fadeOut;
string loadScene;
void Awake()
{
//Reference Single Instance:
instance = this;
//Get All Prefabs:
Transform parent = GameObject.Find("Special").transform.Find("Prefabs/Damage Numbers");
prefabs = new DamageNumber[parent.childCount];
for(int n = 0; n < parent.childCount; n++)
{
prefabs[n] = parent.GetChild(n).GetComponent<DamageNumber>();
}
parent.gameObject.SetActive(false);
//Text Components:
Transform guiParent = GameObject.Find("Special").transform.Find("GUI");
currentPrefabText = guiParent.Find("Background/Current").GetComponent<Text>();
currentIndexText = guiParent.Find("Background/Index").GetComponent<Text>();
Transform fadeTransform = transform.Find("GUI/Fade");
if (fadeTransform != null)
{
fade = fadeTransform.GetComponent<CanvasGroup>();
}
//Reset Index:
currentIndex = 0;
UpdateCurrent();
#if !UNITY_EDITOR && UNITY_WEBGL
WebGLInput.captureAllKeyboardInput = true;
#endif
}
void Start()
{
if(fade != null)
{
fade.alpha = 1f;
}
}
void Update()
{
float scroll = DNP_InputHandler.GetMouseScroll();
if (scroll != 0 && (!Cursor.visible || DNP_Camera.instance == null))
{
if(scroll > 0.001f)
{
currentIndex--;
if(currentIndex < 0)
{
currentIndex = prefabs.Length - 1;
}
UpdateCurrent();
}
else if(scroll < 0.001f)
{
currentIndex++;
if(currentIndex > prefabs.Length - 1)
{
currentIndex = 0;
}
UpdateCurrent();
}
}
if(fade != null)
{
if(fadeOut)
{
fade.alpha += Time.deltaTime * 4;
if(fade.alpha >= 0.999f)
{
SceneManager.LoadScene(loadScene);
enabled = false;
}
return;
}
else
{
if(fade.alpha > 0)
{
fade.alpha -= Time.deltaTime * 3;
}
}
}
}
public void SwitchScene(string sceneName)
{
fadeOut = true;
loadScene = sceneName;
/*foreach(DamageNumber dn in FindObjectsOfType<DamageNumber>())
{
dn.DestroyDNP();
}*/
if(DNP_Camera.instance != null)
{
DNP_Camera.instance.enabled = false;
}
DNP_2DDemo demo2D = FindObjectOfType<DNP_2DDemo>();
if(demo2D)
{
demo2D.enabled = false;
}
if (DNP_GUI.instance != null)
{
DNP_GUI.instance.enabled = false;
}
}
void UpdateCurrent()
{
currentPrefabText.text = "➞ " + prefabs[currentIndex].name;
currentIndexText.text = (currentIndex + 1) + "/" + prefabs.Length;
currentSettings = prefabs[currentIndex].GetComponent<DNP_PrefabSettings>();
}
public DamageNumber GetCurrent()
{
return prefabs[currentIndex];
}
public DNP_PrefabSettings GetSettings()
{
if(currentSettings == null)
{
currentSettings = prefabs[currentIndex].gameObject.AddComponent<DNP_PrefabSettings>();
}
return currentSettings;
}
}
}

View File

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

View File

@@ -0,0 +1,156 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_Enemy : MonoBehaviour
{
public static int count;
public float speed = 5f;
public float acceleration = 8f;
//References:
CharacterController controller;
Animation anim;
Transform pathPoints;
Transform pelvis;
//State:
Vector3 velocity;
Vector3 targetPosition;
bool isWalkingToPath;
int pathsLeft;
float inactiveUntil;
float walkStartTime;
int hitsTaken;
float nextHurtTime;
bool firstIdle;
bool isDead;
void Start()
{
count++;
//References:
anim = GetComponent<Animation>();
controller = GetComponent<CharacterController>();
pathPoints = GameObject.Find("Special").transform.Find("Path Points");
pelvis = transform.Find("Bip001");
//State:
targetPosition = pathPoints.GetChild(0).position;
isWalkingToPath = true;
pathsLeft = 1 + Mathf.RoundToInt(Random.value * 2f);
inactiveUntil = 0;
walkStartTime = Time.time;
hitsTaken = 0;
firstIdle = true;
isDead = false;
//Colors:
SkinnedMeshRenderer meshRenderer = transform.Find("Medieve").GetComponent<SkinnedMeshRenderer>();
Material[] materials = meshRenderer.materials;
Color clothingColor = Color.HSVToRGB(Random.value, 0.4f + Random.value * 0.2f, 0.7f + Random.value * 0.3f);
Color leatherColor = Color.Lerp(Color.white, clothingColor, Random.value * 0.4f);
materials[0].SetColor("_Color", clothingColor);
materials[1].SetColor("_Color", leatherColor);
materials[6].SetColor("_Color", leatherColor);
materials[2].SetColor("_Color", Color.HSVToRGB(0.02f + 0.05f * Random.value, Random.value * 0.45f, 0.8f + Random.value * 0.35f));
materials[4].SetColor("_Color", Color.HSVToRGB(Random.value, Random.value * 0.8f, Random.value * 0.6f));
meshRenderer.materials = materials;
}
void FixedUpdate()
{
if (Time.time < inactiveUntil) return;
if (isDead)
{
if(controller.enabled)
{
controller.enabled = false;
}
transform.position += new Vector3(0, - Time.fixedDeltaTime * 0.2f, 0);
return;
}
if (isWalkingToPath)
{
Quaternion lookRotation = Quaternion.LookRotation(targetPosition - transform.position, Vector3.up);
lookRotation.x = 0;
lookRotation.z = 0;
transform.rotation = Quaternion.Lerp(transform.rotation, lookRotation, Time.fixedDeltaTime * 8f);
velocity = Vector3.Lerp(velocity, transform.forward * speed, Time.fixedDeltaTime * acceleration);
controller.Move(velocity * Time.fixedDeltaTime);
if (Vector3.Distance(transform.position, targetPosition) < (Time.time - walkStartTime) * 0.5f)
{
isWalkingToPath = false;
if(firstIdle)
{
firstIdle = false;
}
else
{
anim.CrossFade("Villager_Idle", 0.2f);
inactiveUntil = Time.time + 1f + Random.value;
}
}
else
{
anim.CrossFade("Villager_Walk", 0.2f);
}
}
else
{
velocity = Vector3.zero;
if(pathsLeft > 0)
{
pathsLeft--;
targetPosition = pathPoints.GetChild(Random.Range(1, 21)).position;
isWalkingToPath = true;
inactiveUntil = 0;
walkStartTime = Time.time;
}
else
{
anim.CrossFade("Villager_Idle", 0.3f);
inactiveUntil = Time.time + 0.2f;
}
}
}
public void Hurt(int damage)
{
if (Time.time < nextHurtTime || isDead || transform.position.z > 8) return;
nextHurtTime = Time.time + 0.55f;
hitsTaken += damage;
if(hitsTaken >= 5)
{
anim.CrossFade("Villager_Death", 0.05f);
inactiveUntil = Time.time + 2f;
isDead = true;
Destroy(gameObject, 7f);
count--;
}
else
{
inactiveUntil = Time.time + 1f + hitsTaken * 0.1f;
anim.CrossFade("Villager_Hurt", 0.05f);
anim.CrossFadeQueued("Villager_Idle", 0.5f);
}
}
public Transform GetPelvis()
{
return pelvis;
}
}
}

View File

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

View File

@@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace DamageNumbersPro.Demo
{
public class DNP_FallingCube : MonoBehaviour
{
public float fallSpeed = 100f;
RectTransform rect;
Image image;
float currentSpeed;
bool isBroken;
void Start()
{
rect = GetComponent<RectTransform>();
image = GetComponent<Image>();
float speedAndSize = Random.value * 0.4f + 0.8f;
currentSpeed = fallSpeed * speedAndSize;
transform.localScale = Vector3.one * speedAndSize;
rect.anchoredPosition3D = new Vector3(Random.value * 560 - 280f, 260f, 0);
rect.localEulerAngles = new Vector3(0, 0, Random.value * 360f);
image.color = Color.Lerp(new Color(0.5f, 0.5f, 0.5f), image.color, speedAndSize - 0.2f);
}
void FixedUpdate()
{
rect.anchoredPosition += new Vector2(0, currentSpeed * Time.fixedDeltaTime);
if(isBroken)
{
currentSpeed = Mathf.Lerp(currentSpeed, 0, Time.fixedDeltaTime * 3f);
transform.localScale += Vector3.one * Time.fixedDeltaTime * 3f;
Color color = image.color;
color.a -= Time.fixedDeltaTime * 5f;
if(color.a <= 0)
{
Destroy(gameObject);
}
else
{
image.color = color;
}
}
if(rect.anchoredPosition.y < -270f)
{
Destroy(gameObject);
}
}
public void Break()
{
isBroken = true;
image.raycastTarget = false;
}
}
}

View File

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

View File

@@ -0,0 +1,79 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_GUI : MonoBehaviour
{
public static DNP_GUI instance;
float nextShotTime;
RectTransform canvasRect;
void Awake()
{
instance = this;
canvasRect = GetComponent<RectTransform>();
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
void Update()
{
HandleShooting();
}
void HandleShooting()
{
if (DNP_UIArea.CanSpawn() == false) return;
if (DNP_InputHandler.GetLeftClick())
{
Shoot();
nextShotTime = Time.time + 0.3f;
}
else if (DNP_InputHandler.GetRightHeld() && Time.time > nextShotTime)
{
Shoot();
nextShotTime = Time.time + 0.06f;
}
}
void Shoot()
{
//Select Damage Number:
DNP_PrefabSettings settings = DNP_DemoManager.instance.GetSettings();
DamageNumber prefab = DNP_DemoManager.instance.GetCurrent();
DNP_UIArea.OnSpawn();
//Number:
float number = 1 + Mathf.Pow(Random.value, 2.2f) * settings.numberRange;
if (prefab.digitSettings.decimals == 0)
{
number = Mathf.Floor(number);
}
//Get Parent:
RectTransform rectParent = DNP_UIArea.GetRect();
if (rectParent == null)
{
rectParent = canvasRect;
}
//Create Damage Number:
DamageNumber newDamageNumber = prefab.Spawn(Vector3.zero, number);
newDamageNumber.SetToMousePosition(rectParent, Camera.main);
if(rectParent != canvasRect)
{
newDamageNumber.enableFollowing = true;
newDamageNumber.followedTarget = rectParent;
}
//Apply Demo Settings:
settings.Apply(newDamageNumber);
}
}
}

View File

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

View File

@@ -0,0 +1,247 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM && DNP_NewInputSystem
using UnityEngine.InputSystem;
namespace DamageNumbersPro.Demo
{
public static class DNP_InputHandler
{
//Directions:
public static bool GetRight()
{
if(Keyboard.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.D].isPressed || Keyboard.current[Key.RightArrow].isPressed;
}
}
public static bool GetLeft()
{
if (Keyboard.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.A].isPressed || Keyboard.current[Key.LeftArrow].isPressed;
}
}
public static bool GetBack()
{
if (Keyboard.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.S].isPressed || Keyboard.current[Key.DownArrow].isPressed;
}
}
public static bool GetForward()
{
if (Keyboard.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.W].isPressed || Keyboard.current[Key.UpArrow].isPressed;
}
}
//Vertical:
public static bool GetJump()
{
if (Keyboard.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.Space].isPressed;
}
}
public static bool GetUp()
{
if (Keyboard.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.E].isPressed || Keyboard.current[Key.Space].isPressed;
}
}
public static bool GetDown()
{
if (Keyboard.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.Q].isPressed || Keyboard.current[Key.LeftShift].isPressed;
}
}
//Mouse:
public static bool GetLeftClick()
{
if (Mouse.current == null)
{
return false;
}
else
{
return Mouse.current.leftButton.wasPressedThisFrame;
}
}
public static bool GetLeftHeld()
{
if (Mouse.current == null)
{
return false;
}
else
{
return Mouse.current.leftButton.isPressed;
}
}
public static bool GetRightClick()
{
if (Mouse.current == null)
{
return false;
}
else
{
return Mouse.current.rightButton.wasPressedThisFrame;
}
}
public static bool GetRightHeld()
{
if (Mouse.current == null)
{
return false;
}
else
{
return Mouse.current.rightButton.isPressed;
}
}
public static Vector2 GetMouseDelta()
{
if (Mouse.current == null)
{
return Vector2.zero;
}
else
{
return 100f * Mouse.current.delta.ReadValue() / (float) Screen.height;
}
}
public static float GetMouseScroll()
{
if (Mouse.current == null)
{
return 0;
}
else
{
return Mouse.current.scroll.ReadValue().y;
}
}
//Escape:
public static bool GetEscape()
{
if (Mouse.current == null)
{
return false;
}
else
{
return Keyboard.current[Key.Escape].wasPressedThisFrame;
}
}
}
}
#else
namespace DamageNumbersPro.Demo
{
public static class DNP_InputHandler
{
//Directions:
public static bool GetRight()
{
return Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
}
public static bool GetLeft()
{
return Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
}
public static bool GetBack()
{
return Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);
}
public static bool GetForward()
{
return Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
}
//Vertical:
public static bool GetJump()
{
return Input.GetKey(KeyCode.Space);
}
public static bool GetUp()
{
return Input.GetKey(KeyCode.E) || Input.GetKey(KeyCode.Space);
}
public static bool GetDown()
{
return Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.LeftShift);
}
//Other:
public static bool GetLeftClick()
{
return Input.GetMouseButtonDown(0);
}
public static bool GetLeftHeld()
{
return Input.GetMouseButton(0);
}
public static bool GetRightClick()
{
return Input.GetMouseButtonDown(1);
}
public static bool GetRightHeld()
{
return Input.GetMouseButton(1);
}
public static Vector2 GetMouseDelta()
{
return new Vector2(Input.GetAxisRaw("Mouse X") * 2f, Input.GetAxisRaw("Mouse Y") * 2f);
}
public static float GetMouseScroll()
{
return Input.mouseScrollDelta.y;
}
//Escape:
public static bool GetEscape()
{
return Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.I);
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,202 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_Player : MonoBehaviour
{
public static DNP_Player instance;
[Header("Settings:")]
public float speed = 5f;
public float acceleration = 8f;
public float jumpStrength = 5f;
[Header("Sprite Sheets:")]
public List<Sprite> idle;
public List<Sprite> run;
public List<Sprite> jump;
public List<Sprite> land;
//References:
SpriteRenderer sprite;
Rigidbody2D rig;
CapsuleCollider2D cc;
//Internal:
List<Sprite> currentAnimation;
bool isGrounded;
float lastJumpTime;
float lastAirTime;
int currentIndex;
float horizontal = 0f;
void Awake()
{
instance = this;
sprite = transform.Find("Sprite").GetComponent<SpriteRenderer>();
rig = GetComponent<Rigidbody2D>();
cc = GetComponent<CapsuleCollider2D>();
IncreaseIndex();
}
public CapsuleCollider2D GetCollider()
{
return cc;
}
void IncreaseIndex()
{
if (currentAnimation == idle || currentAnimation == jump)
{
Invoke("IncreaseIndex", 0.06f);
}else if (currentAnimation == land)
{
Invoke("IncreaseIndex", 0.06f);
}
else
{
Invoke("IncreaseIndex", 0.04f);
}
if (currentAnimation == null)
{
currentIndex = 0;
return;
}
currentIndex++;
if(currentIndex > currentAnimation.Count - 1)
{
if(currentAnimation == land)
{
currentAnimation = idle;
}
if(currentAnimation == jump)
{
currentIndex = currentAnimation.Count - 1;
}
else
{
currentIndex = 0;
}
}
sprite.sprite = currentAnimation[currentIndex];
}
void Update()
{
HandleMovement();
}
void FixedUpdate()
{
CheckGrounded();
}
void LateUpdate()
{
HandleAnimations();
}
void HandleMovement()
{
horizontal = 0f;
if (DNP_InputHandler.GetLeft())
{
horizontal -= 1;
}
if (DNP_InputHandler.GetRight())
{
horizontal += 1;
}
if (currentAnimation == land) horizontal = 0;
Vector2 desiredSpeed = new Vector2(horizontal * speed, rig.velocity.y);
rig.velocity = Vector2.Lerp(rig.velocity, desiredSpeed, Time.deltaTime * acceleration);
if (horizontal > 0)
{
transform.eulerAngles = new Vector3(0, 0, 0);
}
else if (horizontal < 0)
{
transform.eulerAngles = new Vector3(0, 180, 0);
}
if(DNP_InputHandler.GetUp() || DNP_InputHandler.GetJump() || DNP_InputHandler.GetForward())
{
if(Time.time > lastJumpTime + 0.2f && Time.time > lastAirTime + 0.1f)
{
lastJumpTime = Time.time;
rig.velocity = new Vector2(rig.velocity.x, jumpStrength);
//Jump:
currentAnimation = jump;
currentIndex = 0;
}
}
}
void CheckGrounded(){
Vector2 position = transform.position;
gameObject.layer = 2; //Ignore Raycast
RaycastHit2D hit = Physics2D.Raycast(position + Vector2.down * cc.size.y * 0.49f, Vector2.down, 0.04f);
gameObject.layer = 0;
if(hit.collider != null)
{
isGrounded = true;
}
else
{
isGrounded = false;
lastAirTime = Time.time;
}
}
void HandleAnimations()
{
List<Sprite> newAnimation = null;
if (isGrounded)
{
if(currentAnimation == jump && Time.time > lastJumpTime + 0.3f)
{
newAnimation = land;
}
else if(currentAnimation == land)
{
//Nothing:
}
else if(Time.time > lastJumpTime + 0.2f)
{
if (horizontal == 0)
{
newAnimation = idle;
}
else
{
newAnimation = run;
}
}
}
if(newAnimation != currentAnimation && newAnimation != null)
{
currentAnimation = newAnimation;
currentIndex = 0;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5971a698aed24244a86be7ad4a5b5408
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;
using TMPro;
namespace DamageNumbersPro.Demo
{
public class DNP_PrefabSettings : MonoBehaviour
{
public int damage = 1;
public int numberRange = 100;
public List<string> texts;
public List<TMP_FontAsset> fonts;
public bool randomColor;
public void Apply(DamageNumber target)
{
if (texts != null && texts.Count > 0)
{
int randomIndex = Random.Range(0, texts.Count);
target.leftText = texts[randomIndex];
if(fonts != null && randomIndex < fonts.Count)
{
target.SetFontMaterial(fonts[randomIndex]);
}
if(texts.Count > 1)
{
target.enableNumber = false;
}
}
if (randomColor)
{
target.SetColor(Color.HSVToRGB(Random.value, 0.5f, 1f));
}
}
}
}

View File

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

View File

@@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace DamageNumbersPro.Demo
{
public class DNP_SineFadeText : MonoBehaviour
{
public float fromAlpha = 0.5f;
public float toAlpha = 0.8f;
public float speed = 4f;
public float startTimeBonus = 0f;
Text text;
void Awake()
{
text = GetComponent<Text>();
}
void FixedUpdate()
{
Color color = text.color;
color.a = fromAlpha + (toAlpha - fromAlpha) * (Mathf.Sin(speed * Time.unscaledTime + startTimeBonus) * 0.5f + 0.5f);
text.color = color;
}
}
}

View File

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

View File

@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace DamageNumbersPro.Demo
{
public class DNP_UIArea : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public static DNP_UIArea currentArea;
public DNP_UIArea otherArea;
public bool noSpawnArea = false;
public bool breakCube = false;
RectTransform rectTransform;
void Start()
{
rectTransform = GetComponent<RectTransform>();
}
public void OnPointerEnter(PointerEventData eventData)
{
currentArea = this;
}
public void OnPointerExit(PointerEventData eventData)
{
if(currentArea == this)
{
currentArea = null;
}
}
public static RectTransform GetRect()
{
return currentArea != null ? (currentArea.otherArea == null ? currentArea.rectTransform : currentArea.otherArea.rectTransform) : null;
}
public static bool CanSpawn()
{
return currentArea == null || currentArea.noSpawnArea == false;
}
public static void OnSpawn()
{
if(currentArea != null && currentArea.breakCube)
{
DNP_FallingCube cube = currentArea.GetComponent<DNP_FallingCube>();
cube.Break();
}
}
}
}

View File

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

View File

@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DNP_UIMove : MonoBehaviour
{
public Vector2 fromPosition;
public Vector2 toPosition;
public float frequency = 4f;
RectTransform rectTransform;
void Start()
{
rectTransform = GetComponent<RectTransform>();
}
void FixedUpdate()
{
rectTransform.anchoredPosition = Vector2.Lerp(fromPosition, toPosition, Mathf.Sin(Time.time * frequency) * 0.5f + 0.5f);
}
}

View File

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

View File

@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DamageNumbersPro.Demo
{
public class DNP_VillagerSpawner : MonoBehaviour
{
public GameObject prefab;
public Vector3 fromPosition;
public Vector3 toPosition;
float nextSpawnTime;
void Start()
{
nextSpawnTime = Time.time + 1f;
DNP_Enemy.count = 0;
}
void FixedUpdate()
{
if(Time.time > nextSpawnTime && DNP_Enemy.count < 4)
{
SpawnVillager();
}
}
void SpawnVillager()
{
nextSpawnTime = Time.time + 2f * Random.value + 3f;
GameObject newVillager = Instantiate<GameObject>(prefab);
newVillager.transform.position = Vector3.Lerp(fromPosition, toPosition, Random.value);
newVillager.SetActive(true);
}
}
}

View File

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