Base Scene

This commit is contained in:
2020-02-03 00:21:00 +00:00
parent 446510acc4
commit 739f87a1e4
142 changed files with 20574 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
using Exsersewo.UI.Canvas;
using UnityEditor;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public PlayerCanvasManager playerCanvas;
public Exsersewo.UI.Canvas.CanvasManager GameCanvasManager;
#if UNITY_EDITOR
public bool DefaultToSceneView = false;
#endif
// Start is called before the first frame update
void Start()
{
#if UNITY_EDITOR
if (DefaultToSceneView)
{
EditorWindow.FocusWindowIfItsOpen(typeof(SceneView));
}
#endif
if (instance == null)
instance = this;
GameCanvasManager.ChangeToCanvas(MenuType.Game);
}
// Update is called once per frame
void Update()
{
}
}

View File

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

View File

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

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InventoryManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

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

View File

@@ -0,0 +1,120 @@
using Exsersewo.Nydaliv.Utilities;
using System;
using UnityEngine;
public class PlayerManager : MonoBehaviour
{
[InspectorButton(nameof(TestGiveExperience), 250f)]
public bool button;
[SerializeField]
private string playerName;
[SerializeField]
private float health = 100;
private float maxHealth = 100;
[SerializeField]
private ulong experience = 0;
[SerializeField]
private ulong totalExperience = 0;
[SerializeField]
private ulong level = 1;
/// <summary>
/// <para>OnLevelUp Subscribable Function</para>
/// <para>ulong = level currently at</para>
/// </summary>
public Action<ulong> OnLevelUp;
public string GetName()
=> playerName;
public float GetHealth()
=> health;
public float GetMaxHealth()
=> maxHealth;
public ulong GetExperience()
=> experience;
public ulong GetExperienceToNextLevel()
=> NumberUtilities.GetXPLevelRequirement(level + 1, Props.PHI);
public ulong GetTotalExperience()
=> totalExperience;
public ulong GetLevel()
=> level;
public string SetName(string value)
=> playerName = value;
public float SetHealth(float amount)
{
health = amount;
if (health > maxHealth)
health = maxHealth;
return health;
}
public float AddHealth(float amount)
{
health += amount;
if (health > maxHealth)
health = maxHealth;
return health;
}
public void AddExperience(ulong amount)
{
totalExperience += amount;
experience += amount;
HandleExperience();
}
void HandleExperience()
{
ulong backUpExperience = experience;
ulong lvl = level;
ulong requiredXp = NumberUtilities.GetXPLevelRequirement(lvl + 1, Props.PHI);
while (backUpExperience >= requiredXp)
{
backUpExperience -= requiredXp;
requiredXp = NumberUtilities.GetXPLevelRequirement(lvl + 1, Props.PHI);
lvl++;
maxHealth = (float)Math.Ceiling(maxHealth *= Props.PHI);
health = maxHealth;
if (OnLevelUp != null)
{
OnLevelUp.Invoke(level);
}
}
GameManager.instance.playerCanvas.SetExperienceBar(backUpExperience, requiredXp);
experience = backUpExperience;
level = lvl;
}
void TestGiveExperience()
{
AddExperience((ulong)UnityEngine.Random.Range(1, 500));
}
void Update()
{
GameManager.instance.playerCanvas.SetNameText(GetName());
GameManager.instance.playerCanvas.SetHealthValue((ulong)GetHealth(), (ulong)GetMaxHealth());
GameManager.instance.playerCanvas.SetLevelValue($"{GetLevel()}");
}
}

View File

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

View File

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

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StoryManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

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

8
Assets/Scripts/UI.meta Normal file
View File

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

View File

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

View File

@@ -0,0 +1,56 @@
using Exsersewo.Nydaliv.Extensions;
using System.Collections;
using UnityEngine;
namespace Exsersewo.UI.Canvas
{
public class CanvasFader : MonoBehaviour
{
public MenuType MenuType;
public bool Visible => GetComponent<CanvasGroup>().alpha > 0.9f;
IEnumerator ChangeVisibility(bool lerp, bool show, float TimeToLerp)
{
float timeLerped = 0;
var group = GetComponent<CanvasGroup>();
group.interactable = group.blocksRaycasts = show;
if (lerp)
{
while (timeLerped < TimeToLerp)
{
var lerped = Mathf.Lerp(0, 1, timeLerped / TimeToLerp);
if (lerped > 0.9)
lerped = 1;
else if (lerped < 0.1)
lerped = 0;
group.alpha = show ? lerped : 1 - lerped;
timeLerped += Time.unscaledDeltaTime;
yield return null;
}
}
else
{
group.alpha = show ? 1 : 0;
}
yield return null;
}
public void HidePanel(bool lerp, float TimeToLerp)
{
StartCoroutine(ChangeVisibility(lerp, false, TimeToLerp));
}
public void ShowPanel(bool lerp, float TimeToLerp)
{
StartCoroutine(ChangeVisibility(lerp, true, TimeToLerp));
}
}
}

View File

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

View File

@@ -0,0 +1,49 @@
using System.Linq;
using UnityEngine;
namespace Exsersewo.UI.Canvas
{
[RequireComponent(typeof(CanvasGroup))]
public class CanvasManager : MonoBehaviour
{
public CanvasFader[] Canvases;
public float TimeToLerp;
void ChangeCanvas(MenuType menu, bool lerp)
{
var toZero = Canvases.Where(x => x.MenuType != menu).ToList();
var toOne = Canvases.FirstOrDefault(x => x.MenuType == menu);
toZero.ForEach(x =>
{
var fader = x.GetComponent<CanvasFader>();
if (fader.Visible)
{
fader.HidePanel(lerp, TimeToLerp);
}
});
toOne.GetComponent<CanvasFader>().ShowPanel(lerp, TimeToLerp);
}
public void ChangeToCanvas(CanvasFader menu)
=> ChangeToCanvas(menu.MenuType);
public void ChangeToCanvas(MenuType menu)
=> ChangeCanvas(menu, false);
public void LerpToCanvas(CanvasFader menu)
=> LerpToCanvas(menu.MenuType);
public void LerpToCanvas(MenuType menu)
=> ChangeCanvas(menu, true);
}
[System.Serializable]
public enum MenuType
{
Game = 0,
Stats = 1,
Codex = 2
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CanvasManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

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

View File

@@ -0,0 +1,8 @@
using TMPro;
using UnityEngine;
public class LabelValueHolder : MonoBehaviour
{
public TextMeshProUGUI Label;
public TextMeshProUGUI Value;
}

View File

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

View File

@@ -0,0 +1,30 @@
using Exsersewo.UI.ProgressBar;
using TMPro;
using UnityEngine;
public class PlayerCanvasManager : MonoBehaviour
{
[SerializeField]
TextMeshProUGUI Name;
[SerializeField]
LabelValueHolder Level;
[SerializeField]
ProgressBar HealthBar;
[SerializeField]
ProgressBar ExperienceBar;
public void SetNameText(string text)
=> Name.SetText(text);
public void SetLevelValue(string text)
=> Level.Value.SetText(text);
public void SetHealthValue(ulong value, ulong maxValue)
=> HealthBar.SetValue(value, maxValue);
public void SetExperienceBar(ulong value, ulong maxValue)
=> ExperienceBar.SetValue(value, maxValue);
}

View File

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

View File

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

View File

@@ -0,0 +1,116 @@
using Exsersewo.Nydaliv.Extensions;
using System.Collections;
using UnityEngine;
namespace Exsersewo.UI.ProgressBar
{
public class ProgressBar : MonoBehaviour
{
[SerializeField]
RectTransform ValueSlider;
public ProgressBarType FillType;
[Tooltip("X=Left Y=Right")]
public Vector2 Padding;
[SerializeField]
ProgressTransitionType Transition;
[SerializeField]
float TransitionTime = .5f;
[SerializeField]
float previousValue;
RectTransform RectTransform;
void Start()
{
RectTransform = GetComponent<RectTransform>();
previousValue = ValueSlider.rect.width;
}
IEnumerator SetWidth(ulong value, ulong maxValue)
{
float hori = RectTransform.rect.width;
var width = ((float)value).Remap(0, maxValue, 0, hori-(Padding.x+Padding.y));
switch (Transition)
{
case ProgressTransitionType.Lerp:
case ProgressTransitionType.SmoothStep:
{
float TimeLerped = 0f;
while (TimeLerped <= TransitionTime)
{
float lerpVal = 0;
switch (Transition)
{
case ProgressTransitionType.SmoothStep:
lerpVal = Mathf.SmoothStep(previousValue, width, TimeLerped / TransitionTime);
break;
case ProgressTransitionType.Lerp:
lerpVal = Mathf.Lerp(previousValue, width, TimeLerped / TransitionTime);
break;
}
SetSliderPosition(lerpVal);
TimeLerped += Time.deltaTime;
yield return null;
}
}
break;
case ProgressTransitionType.Instant:
default:
{
SetSliderPosition(width);
}
break;
}
previousValue = width;
}
void SetSliderPosition(float val)
{
switch (FillType)
{
case ProgressBarType.FillFromCenter:
ValueSlider.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, val);
break;
case ProgressBarType.FillFromLeft:
ValueSlider.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, val);
ValueSlider.SetLeft(Padding.x);
break;
case ProgressBarType.FillFromRight:
ValueSlider.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, val);
ValueSlider.SetRight(Padding.y);
break;
}
}
public void SetValue(ulong value, ulong maxValue)
{
StartCoroutine(SetWidth(value, maxValue));
}
}
public enum ProgressBarType
{
FillFromCenter,
FillFromLeft,
FillFromRight
}
public enum ProgressTransitionType
{
Instant,
Lerp,
SmoothStep
}
}

View File

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

View File

@@ -0,0 +1,6 @@
namespace Exsersewo.UI.ProgressBar
{
public class ProgressBarWithLabel : ProgressBar
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e0785dbea1b3654298637a11a0fff80
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 TMPro;
using UnityEngine;
public class SplitSectionInHalf : MonoBehaviour
{
[Tooltip("X=Left Y=Right")]
public Vector2 Padding;
public TextMeshProUGUI left;
public TextMeshProUGUI right;
IEnumerator SetWidth()
{
yield return new WaitForFixedUpdate();
float hori = GetComponent<RectTransform>().rect.width;
left.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, hori / 2);
right.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, hori / 2);
left.rectTransform.SetRight(-(hori / 2) + Padding.x);
right.rectTransform.SetLeft(-(hori / 2) + Padding.y);
}
void FixedUpdate()
{
StartCoroutine(SetWidth());
}
}

View File

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

View File

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

View File

@@ -0,0 +1,8 @@
namespace Exsersewo.Nydaliv.Extensions
{
public static class Extensions
{
public static float Remap(this float value, float min1, float max1, float min2, float max2)
=> min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
}
}

View File

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

View File

@@ -0,0 +1,13 @@
using System;
namespace Exsersewo.Nydaliv.Utilities
{
public static class NumberUtilities
{
public static ulong GetXPLevelRequirement(ulong level, double growthmod)
=> (ulong)Math.Round(Math.Pow(level, 2) * 50 * growthmod, MidpointRounding.AwayFromZero);
public static ulong GetLevelFromTotalXP(ulong totalxp, double growthmod)
=> (ulong)(Math.Sqrt(totalxp / (50 * growthmod)));
}
}

View File

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

View File

@@ -0,0 +1,7 @@
namespace Exsersewo.Nydaliv.Utilities
{
public static class Props
{
public const float PHI = 1.618f;
}
}

View File

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