Initial commit
This commit is contained in:
153
Assets/Scripts/Age/AgingController.cs
Normal file
153
Assets/Scripts/Age/AgingController.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AgingController : MonoBehaviour
|
||||
{
|
||||
[Header("Ìàòåð³àëè øê³ðè")]
|
||||
public Material faceMaterial;
|
||||
public Material neckMaterial;
|
||||
public Material bodyMaterial;
|
||||
|
||||
[Header("Çà÷³ñêè")]
|
||||
public GameObject youngHair;
|
||||
public GameObject oldHaircut;
|
||||
|
||||
[Header("Áîðîäà")]
|
||||
public GameObject beard;
|
||||
|
||||
[Header("Blend Shapes")]
|
||||
public SkinnedMeshRenderer bodyMesh;
|
||||
public int bellyBlendIndex = 4;
|
||||
public int overweightBlendIndex = 1;
|
||||
|
||||
[Header("×àñ")]
|
||||
public float agingDuration = 20f;
|
||||
|
||||
[HideInInspector] public float currentAge = 25f;
|
||||
[HideInInspector] public bool isFinished = false;
|
||||
|
||||
private Material[] oldHairMats;
|
||||
private Material[] youngHairMats;
|
||||
private Material[] beardMats;
|
||||
private float timer = 0f;
|
||||
private Color currentHairColor = new Color(0.80f, 0.80f, 0.80f);
|
||||
private Color _lastAppliedColor = Color.clear;
|
||||
private int _currentPlanetIndex = 2;
|
||||
|
||||
private HairColorSettings hairColorSettings;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
hairColorSettings = FindObjectOfType<HairColorSettings>();
|
||||
youngHairMats = GetMaterials(youngHair);
|
||||
oldHairMats = GetMaterials(oldHaircut);
|
||||
beardMats = GetMaterials(beard);
|
||||
RestartAging();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isFinished) return;
|
||||
|
||||
if (hairColorSettings != null)
|
||||
{
|
||||
Color newColor = hairColorSettings.GetHairColor(_currentPlanetIndex);
|
||||
if (newColor != _lastAppliedColor)
|
||||
{
|
||||
_lastAppliedColor = newColor;
|
||||
currentHairColor = newColor;
|
||||
ApplyColorToMats(oldHairMats);
|
||||
ApplyColorToMats(beardMats);
|
||||
}
|
||||
}
|
||||
|
||||
timer += Time.deltaTime;
|
||||
float t = Mathf.Clamp01(timer / agingDuration);
|
||||
currentAge = Mathf.Lerp(25f, 70f, t);
|
||||
|
||||
faceMaterial.SetFloat("_AgingProgress", t);
|
||||
bodyMesh.SetBlendShapeWeight(bellyBlendIndex, t * 100f);
|
||||
bodyMesh.SetBlendShapeWeight(overweightBlendIndex, t * 10f);
|
||||
|
||||
SetAlpha(youngHairMats, 1f - t);
|
||||
|
||||
if (t >= 0.4f)
|
||||
{
|
||||
float hairT = Mathf.Clamp01((t - 0.4f) / 0.6f);
|
||||
SetAlphaWithColor(oldHairMats, hairT);
|
||||
SetAlphaWithColor(beardMats, hairT);
|
||||
}
|
||||
|
||||
if (t >= 1f) isFinished = true;
|
||||
}
|
||||
|
||||
public void RestartAging()
|
||||
{
|
||||
faceMaterial.SetFloat("_AgingProgress", 0f);
|
||||
SetAlpha(oldHairMats, 0f);
|
||||
SetAlpha(beardMats, 0f);
|
||||
SetAlpha(youngHairMats, 1f);
|
||||
bodyMesh.SetBlendShapeWeight(bellyBlendIndex, 0f);
|
||||
bodyMesh.SetBlendShapeWeight(overweightBlendIndex, 0f);
|
||||
timer = 0f;
|
||||
currentAge = 25f;
|
||||
isFinished = false;
|
||||
_lastAppliedColor = Color.clear;
|
||||
}
|
||||
|
||||
public void ApplyHairColor(int planetIndex)
|
||||
{
|
||||
if (hairColorSettings == null) return;
|
||||
_currentPlanetIndex = planetIndex;
|
||||
currentHairColor = hairColorSettings.GetHairColor(planetIndex);
|
||||
_lastAppliedColor = currentHairColor;
|
||||
ApplyColorToMats(oldHairMats);
|
||||
ApplyColorToMats(beardMats);
|
||||
}
|
||||
|
||||
void ApplyColorToMats(Material[] mats)
|
||||
{
|
||||
foreach (var m in mats)
|
||||
{
|
||||
Color c = m.GetColor("_BaseColor");
|
||||
c.r = currentHairColor.r;
|
||||
c.g = currentHairColor.g;
|
||||
c.b = currentHairColor.b;
|
||||
m.SetColor("_BaseColor", c);
|
||||
}
|
||||
}
|
||||
|
||||
Material[] GetMaterials(GameObject obj)
|
||||
{
|
||||
var renderers = obj.GetComponentsInChildren<Renderer>();
|
||||
var list = new List<Material>();
|
||||
foreach (var r in renderers)
|
||||
foreach (var m in r.materials)
|
||||
list.Add(m);
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
void SetAlpha(Material[] mats, float alpha)
|
||||
{
|
||||
foreach (var m in mats)
|
||||
{
|
||||
Color c = m.GetColor("_BaseColor");
|
||||
c.a = alpha;
|
||||
m.SetColor("_BaseColor", c);
|
||||
}
|
||||
}
|
||||
|
||||
void SetAlphaWithColor(Material[] mats, float alpha)
|
||||
{
|
||||
foreach (var m in mats)
|
||||
{
|
||||
Color c = m.GetColor("_BaseColor");
|
||||
c.r = currentHairColor.r;
|
||||
c.g = currentHairColor.g;
|
||||
c.b = currentHairColor.b;
|
||||
c.a = alpha;
|
||||
m.SetColor("_BaseColor", c);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Age/AgingController.cs.meta
Normal file
11
Assets/Scripts/Age/AgingController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49e589cdd4d181045ab5adda62877ab3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/Age/AgingUI.cs
Normal file
18
Assets/Scripts/Age/AgingUI.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class AgingUI : MonoBehaviour
|
||||
{
|
||||
public AgingController agingController;
|
||||
public TextMeshProUGUI ageText;
|
||||
public TextMeshProUGUI planetText;
|
||||
|
||||
void Update()
|
||||
{
|
||||
int age = Mathf.RoundToInt(agingController.currentAge);
|
||||
ageText.text = "³ê: " + age + " ³ç 70 ðîê³â";
|
||||
planetText.text = "Íà Çåìë³ ïðîéøëî: 70 ðîê³â";
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Age/AgingUI.cs.meta
Normal file
11
Assets/Scripts/Age/AgingUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a416d6325763bd94992f465ce1466203
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Scripts/Age/HairColorSettings.cs
Normal file
43
Assets/Scripts/Age/HairColorSettings.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class HairColorSettings : MonoBehaviour
|
||||
{
|
||||
[Header("Ęîëłđ ńčâčíč íŕ đłçíčő ďëŕíĺňŕő")]
|
||||
public bool useDefaultGray = true;
|
||||
|
||||
[Header("Ęîëüîđč ńčâčíč äë˙ ęîćíîż ďëŕíĺňč")]
|
||||
public Color mercuryHairColor = new Color(0.85f, 0.85f, 0.85f);
|
||||
public Color venusHairColor = new Color(0.95f, 0.90f, 0.80f);
|
||||
public Color earthHairColor = new Color(0.80f, 0.80f, 0.80f);
|
||||
public Color moonHairColor = new Color(0.90f, 0.90f, 0.95f);
|
||||
public Color marsHairColor = new Color(0.85f, 0.75f, 0.70f);
|
||||
public Color jupiterHairColor = new Color(0.80f, 0.85f, 0.90f);
|
||||
public Color saturnHairColor = new Color(0.90f, 0.85f, 0.75f);
|
||||
public Color uranusHairColor = new Color(0.75f, 0.90f, 0.90f);
|
||||
public Color neptuneHairColor = new Color(0.70f, 0.75f, 0.95f);
|
||||
public Color plutoHairColor = new Color(0.80f, 0.80f, 0.90f);
|
||||
|
||||
private static readonly Color defaultGray = Color.white;
|
||||
|
||||
public Color GetHairColor(int planetIndex)
|
||||
{
|
||||
if (useDefaultGray) return defaultGray;
|
||||
|
||||
switch (planetIndex)
|
||||
{
|
||||
case 0: return mercuryHairColor;
|
||||
case 1: return venusHairColor;
|
||||
case 2: return earthHairColor;
|
||||
case 3: return moonHairColor;
|
||||
case 4: return marsHairColor;
|
||||
case 5: return jupiterHairColor;
|
||||
case 6: return saturnHairColor;
|
||||
case 7: return uranusHairColor;
|
||||
case 8: return neptuneHairColor;
|
||||
case 9: return plutoHairColor;
|
||||
default: return defaultGray;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Age/HairColorSettings.cs.meta
Normal file
11
Assets/Scripts/Age/HairColorSettings.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2e109373c9aed240a398aabb35c34dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
133
Assets/Scripts/Age/PlanetSelector.cs
Normal file
133
Assets/Scripts/Age/PlanetSelector.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class PlanetSelector : MonoBehaviour
|
||||
{
|
||||
public AgingController agingController;
|
||||
public TimeManager timeManager;
|
||||
|
||||
public Button previousButton;
|
||||
public Button nextButton;
|
||||
public TextMeshProUGUI ageText;
|
||||
public TextMeshProUGUI planetText;
|
||||
|
||||
public Material skyboxMaterial;
|
||||
|
||||
private int currentPlanetIndex = 2;
|
||||
|
||||
private string[] planetNames = {
|
||||
"Ìåðêóð³¿", "Âåíåð³", "Çåìë³", "̳ñÿö³",
|
||||
"Ìàðñ³", "Þï³òåð³", "Ñàòóðí³", "Óðàí³", "Íåïòóí³", "Ïëóòîí³"
|
||||
};
|
||||
|
||||
private float[] dayLengthHours = {
|
||||
1407.6f, 5832.5f, 24f, 708.7f,
|
||||
24.6f, 9.9f, 10.7f, 17.2f, 16.1f, 153.3f
|
||||
};
|
||||
|
||||
private float[] daysInYear = {
|
||||
88f, 225f, 365f, 365f,
|
||||
687f, 4333f, 10759f, 30687f, 60190f, 90560f
|
||||
};
|
||||
|
||||
private float[] agingDurations = {
|
||||
5f, 10f, 20f, 20f, 28f, 40f, 40f, 40f, 40f, 40f
|
||||
};
|
||||
|
||||
private float[] orbitalYears = {
|
||||
0.24f, 0.62f, 1f, 1f, 1.88f, 11.86f, 29.46f, 84.01f, 164.8f, 248f
|
||||
};
|
||||
|
||||
private Color[] skyboxColors =
|
||||
{
|
||||
new Color(0.75f,0.78f,0.85f),
|
||||
new Color(1.25f,0.85f,0.55f),
|
||||
new Color(1f,1f,1f),
|
||||
new Color(0.75f,0.85f,1.2f),
|
||||
new Color(1.35f,0.55f,0.45f),
|
||||
new Color(0.7f,1.15f,1.25f),
|
||||
new Color(0.95f,0.65f,1.35f),
|
||||
new Color(0.55f,1.25f,1.1f),
|
||||
new Color(0.45f,0.65f,1.35f),
|
||||
new Color(0.7f,0.7f,1.35f)
|
||||
};
|
||||
|
||||
private float[] skyboxExposure =
|
||||
{
|
||||
0.7f,
|
||||
0.8f,
|
||||
0.9f,
|
||||
0.95f,
|
||||
1.15f,
|
||||
0.9f,
|
||||
0.8f,
|
||||
0.7f,
|
||||
0.6f,
|
||||
0.9f
|
||||
};
|
||||
|
||||
private float[] skyboxRotation =
|
||||
{
|
||||
10f, 25f, 0f, 5f, 15f,
|
||||
40f, 60f, 90f, 120f, 160f
|
||||
};
|
||||
|
||||
void Start()
|
||||
{
|
||||
ApplyPlanet();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (timeManager.showAge)
|
||||
{
|
||||
int earthAge = Mathf.RoundToInt(agingController.currentAge);
|
||||
ageText.text = "³ê: " + earthAge + " ³ç 70 ðîê³â";
|
||||
|
||||
float planetAge = timeManager.fromBeginning
|
||||
? agingController.currentAge / orbitalYears[currentPlanetIndex]
|
||||
: (agingController.currentAge - 25f) / orbitalYears[currentPlanetIndex];
|
||||
|
||||
planetText.text = "Íà " + planetNames[currentPlanetIndex] + " ïðîéøëî: " + planetAge.ToString("F1") + " ðîê³â";
|
||||
}
|
||||
else
|
||||
{
|
||||
ageText.text = "Òðèâàë³ñòü äîáè íà " + planetNames[currentPlanetIndex] + ": " + dayLengthHours[currentPlanetIndex].ToString("F1") + " ãîäèí";
|
||||
planetText.text = "Ó ðîö³ íà " + planetNames[currentPlanetIndex] + ": " + daysInYear[currentPlanetIndex].ToString("F0") + " ä³á";
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNextButton()
|
||||
{
|
||||
if (currentPlanetIndex < planetNames.Length - 1)
|
||||
{
|
||||
currentPlanetIndex++;
|
||||
ApplyPlanet();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPreviousButton()
|
||||
{
|
||||
if (currentPlanetIndex > 0)
|
||||
{
|
||||
currentPlanetIndex--;
|
||||
ApplyPlanet();
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyPlanet()
|
||||
{
|
||||
agingController.agingDuration = agingDurations[currentPlanetIndex];
|
||||
agingController.RestartAging();
|
||||
agingController.ApplyHairColor(currentPlanetIndex);
|
||||
skyboxMaterial.SetColor("_Tint", skyboxColors[currentPlanetIndex]);
|
||||
skyboxMaterial.SetFloat("_Exposure", skyboxExposure[currentPlanetIndex]);
|
||||
skyboxMaterial.SetFloat("_Rotation", skyboxRotation[currentPlanetIndex]);
|
||||
DynamicGI.UpdateEnvironment();
|
||||
previousButton.interactable = currentPlanetIndex > 0;
|
||||
nextButton.interactable = currentPlanetIndex < planetNames.Length - 1;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Age/PlanetSelector.cs.meta
Normal file
11
Assets/Scripts/Age/PlanetSelector.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a51db86c8a5cf5049b54adefdf69354f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/Age/TimeManager.cs
Normal file
19
Assets/Scripts/Age/TimeManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TimeManager : MonoBehaviour
|
||||
{
|
||||
public bool showAge = true;
|
||||
public bool fromBeginning = false;
|
||||
|
||||
public void ToggleMode(bool value)
|
||||
{
|
||||
showAge = value;
|
||||
}
|
||||
|
||||
public void ToggleFromBeginning(bool value)
|
||||
{
|
||||
fromBeginning = value;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Age/TimeManager.cs.meta
Normal file
11
Assets/Scripts/Age/TimeManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d5f0adf8bd0cb840bc2cdd81739a4fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user