add project files

This commit is contained in:
Boris Nikolaev
2026-08-14 01:58:31 +03:00
parent 9134cad79b
commit 5f1e94b653
4399 changed files with 12286903 additions and 0 deletions
@@ -0,0 +1,240 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using OHM.UnityToolkit;
using UnityEngine.Serialization;
namespace Ambiance
{
public class AmbianceController : UniqueInstance<AmbianceController>
{
[SerializeField]
public AmbiancesDef ambiancesDef;
[SerializeField]
[FormerlySerializedAs("skyMatRef")]
private Material _skyMatRef;
[SerializeField]
[FormerlySerializedAs("dirLight")]
private Light _dirLight;
private Camera camera;
public Dictionary<string, Color> debugColors = new Dictionary<string, Color>();
public int changeAmbianceSectionCount = 1;
private AmbianceDef _forcedAmbiance;
private bool currentlyOnFire;
public UnityEvent OnAmbianceChange;
public AmbianceDef CurrentAmbiance { get; private set; }
public AmbianceDef CurrentAmbianceToUse { get; private set; }
public int CurrentLevelIdx { get; private set; }
public int CurrentAmbianceIdx { get; private set; }
public int CurrentAmbianceRealIdx { get; private set; }
public Material SkyMat { get; private set; }
public Dictionary<string, Material> SpecialMats { get; private set; }
public bool Flip { get; set; }
public string _debugSkyColorKey { get; private set; } = "debug_sky_color";
public string GetFlippedId(string id)
{
return id + "_f";
}
protected override void AwakeInstance()
{
SpecialMats = new Dictionary<string, Material>();
foreach (SpecialMatDef def in ambiancesDef.specialsMatRef)
{
var mat = new Material(def.materialRef);
mat.name = mat.name + "_" + def.id;
SpecialMats[def.id] = mat;
if (!def.flippable)
{
continue;
}
var flipped = new Material(def.materialRef);
string flippedId = GetFlippedId(def.id);
flipped.name = flipped.name + "_" + flippedId;
flipped.mainTextureScale = new Vector2(flipped.mainTextureScale.x, 0f - flipped.mainTextureScale.y);
SpecialMats[flippedId] = flipped;
}
if (_skyMatRef != null)
{
SkyMat = new Material(_skyMatRef);
RenderSettings.skybox = SkyMat;
}
}
public void UpdateCameraAmbiance(Camera camera)
{
this.camera = camera;
SetAmbiance(CurrentAmbiance, currentlyOnFire);
}
public void ForceAmbiance(AmbianceDef amb)
{
_forcedAmbiance = amb;
SetLevelIdx(CurrentLevelIdx, currentlyOnFire, forceReload: true);
}
public void SetLevelIdx(int levelIdx, bool onFire, bool forceReload)
{
if (!forceReload && CurrentLevelIdx == levelIdx && currentlyOnFire == onFire)
{
return;
}
CurrentLevelIdx = levelIdx;
currentlyOnFire = onFire;
if (_forcedAmbiance != null)
{
SetAmbiance(_forcedAmbiance, onFire);
return;
}
CurrentAmbianceIdx = levelIdx / changeAmbianceSectionCount;
List<AmbianceDef> ambiances = ambiancesDef.GetAmbiancesList();
CurrentAmbianceRealIdx = CurrentAmbianceIdx % ambiances.Count;
SetAmbiance(ambiances[CurrentAmbianceRealIdx], onFire);
}
public void TryAmbiance(AmbianceDef ambianceDef, bool onFire)
{
SetAmbiance(ambianceDef, onFire);
}
public Material GetSpecialMat(string id, bool allowFlip = false)
{
if (SpecialMats == null)
{
return null;
}
if (Flip && allowFlip)
{
string flippedId = GetFlippedId(id);
if (SpecialMats.ContainsKey(flippedId))
{
return SpecialMats[flippedId];
}
}
if (SpecialMats.ContainsKey(id))
{
return SpecialMats[id];
}
return null;
}
private void SetAmbiance(AmbianceDef def, bool fire)
{
CurrentAmbiance = def;
AmbianceDef toUse = (fire && def != null && def.fireAmbiance != null) ? def.fireAmbiance : def;
CurrentAmbianceToUse = toUse;
if (toUse == null)
{
return;
}
RenderSettings.fogColor = toUse.fogColor;
ApplySpecialColor(toUse);
if (SkyMat != null)
{
if (debugColors.ContainsKey(_debugSkyColorKey))
{
Color debugColor = debugColors[_debugSkyColorKey];
SkyMat.SetColor("_SkyColor1", debugColor);
SkyMat.SetColor("_SkyColor2", debugColor);
SkyMat.SetColor("_SkyColor3", debugColor);
}
else
{
SkyMat.SetTexture("_MainTex", def.skyPano);
}
}
FogDistance fog = (def.fogDistance != null) ? def.fogDistance : ambiancesDef.defaultFogDistance;
RenderSettings.fogStartDistance = fog.start;
RenderSettings.fogEndDistance = fog.end;
OnAmbianceChange.Invoke();
}
private void ApplySpecialColor(AmbianceDef def)
{
if (def == null || def.specialColors == null)
{
return;
}
foreach (SpecialColorDef sc in def.specialColors)
{
Material mat = GetSpecialMat(sc.id);
if (mat != null)
{
ApplySpecialColorToMat(mat, sc);
}
else
{
Debug.LogErrorFormat(
"Ambiance {0} is trying to set undefined special material {1}. Please check ambiance or def",
def.name, sc.id);
}
Material flipped = GetSpecialMat(GetFlippedId(sc.id));
if (flipped != null)
{
ApplySpecialColorToMat(flipped, sc);
}
}
}
private void ApplySpecialColorToMat(Material specMat, SpecialColorDef sc)
{
if (debugColors.ContainsKey(sc.id))
{
Color debugColor = debugColors[sc.id];
specMat.SetColor("_TintColor", debugColor);
specMat.SetColor("_ColorAdd", debugColor);
specMat.SetColor("_EmissionColor", debugColor);
specMat.mainTexture = null;
return;
}
specMat.color = sc.color;
if (specMat.HasProperty("_TintColor"))
{
specMat.SetColor("_TintColor", sc.color);
}
if (specMat.HasProperty("_ColorAdd"))
{
specMat.SetColor("_ColorAdd", sc.colorAdd);
}
if (specMat.HasProperty("_EmissionColor"))
{
specMat.EnableKeyword("_EMISSION");
specMat.SetColor("_EmissionColor", sc.colorEmission);
}
if (specMat.HasProperty("_EmissionMap") && sc.textureEmission != null)
{
specMat.SetTexture("_EmissionMap", sc.textureEmission);
}
if (sc.texture != null)
{
specMat.mainTexture = sc.texture;
return;
}
SpecialMatDef matDef = ambiancesDef.specialsMatRef.Find((SpecialMatDef d) => d.id == sc.id);
if (matDef != null)
{
specMat.mainTexture = matDef.materialRef.mainTexture;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7c4cac1f1af73cb2609e0a302aa19a09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 200
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using UnityEngine;
namespace Ambiance
{
[CreateAssetMenu(fileName = "AmbianceDef", menuName = "GameSqueleton/New Ambiance Def")]
public class AmbianceDef : ScriptableObject
{
public Sprite thumb;
public FogDistance fogDistance;
[Header("Skybox")]
public Texture skyPano;
public Color fogColor;
[Header("Special Color")]
public List<SpecialColorDef> specialColors;
[Header("Special Prefabs")]
public List<SpecialPrefabDef> specialPrefabs;
[Header("Show elements")]
public List<string> showElementsIds;
[Header("Hide elements")]
public List<string> hiddenElementsIds;
[Header("FIRE")]
public AmbianceDef fireAmbiance;
[ContextMenu("Try default")]
private void Try()
{
AmbianceController.Instance.TryAmbiance(this, onFire: false);
}
[ContextMenu("Try on fire")]
private void TryFire()
{
AmbianceController.Instance.TryAmbiance(this, onFire: true);
}
public SpecialColorDef GetSpecialColor(string id)
{
return specialColors.Find((SpecialColorDef c) => c.id == id);
}
public SpecialPrefabDef GetSpecialPrefab(string id)
{
return specialPrefabs.Find((SpecialPrefabDef p) => p.id == id);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: daffb0eeda04a1cb814b5a7ac7d4b688
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
using UnityEngine;
namespace Ambiance
{
public class AmbianceHide : AmbianceSpecialBase
{
[SerializeField]
private string id;
public override void OnStart()
{
base.OnStart();
AmbianceController.Instance.OnAmbianceChange.AddListener(Apply);
}
public override void Apply()
{
Renderer renderer = GetComponent<Renderer>();
if (renderer == null || AmbianceController.Instance.CurrentAmbianceToUse == null)
{
return;
}
renderer.enabled = !AmbianceController.Instance.CurrentAmbianceToUse.hiddenElementsIds.Contains(id);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e490207be0cec601ce6768721850d6eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using OHM.UnityToolkit.Pooling;
using UnityEngine.Serialization;
namespace Ambiance
{
public class AmbianceShow : AmbianceSpecialBase
{
[Serializable]
public class OptionalObject
{
public Transform position;
public PooledObject objectToInstantiate;
}
[SerializeField]
private string id;
[SerializeField]
[FormerlySerializedAs("randomShow")]
private bool _randomShow;
[SerializeField]
[Tooltip("position, prefab")]
[FormerlySerializedAs("objectsList")]
private List<OptionalObject> _objectsList;
public override void OnStart()
{
base.OnStart();
AmbianceController.Instance.OnAmbianceChange.AddListener(Apply);
}
public override void Apply()
{
if (GetComponent<Renderer>() == null && AmbianceController.Instance == null)
{
return;
}
AmbianceDef ambiance = AmbianceController.Instance.CurrentAmbianceToUse;
if (ambiance == null)
{
return;
}
bool show = ambiance.showElementsIds.Contains(id);
DisableObject();
if (!show)
{
return;
}
int index = _randomShow ? UnityEngine.Random.Range(0, _objectsList.Count) : 0;
if (_objectsList.Count == 0)
{
return;
}
OptionalObject slot = _objectsList[index];
if (slot == null || slot.objectToInstantiate == null || slot.position == null)
{
return;
}
PoolsManager.InstantiatePrefab(slot.objectToInstantiate, slot.position,
slot.position.position, slot.position.rotation, startActive: true);
}
private void DisableObject()
{
for (int i = 0; i < base.transform.childCount; i++)
{
base.transform.GetChild(i).gameObject.SetActive(false);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11d94c18dc7ae664bd2b7c65c19848fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace Ambiance
{
public class AmbianceSpecialBase : MonoBehaviour
{
[SerializeField]
[FormerlySerializedAs("autoApply")]
private bool _autoApply = true;
private void Start()
{
OnStart();
}
public virtual void OnStart()
{
if (_autoApply)
{
Apply();
}
}
public virtual void Apply()
{
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 173e8ce0439a4cf1e757b77a050776ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,40 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace Ambiance
{
public class AmbianceSpecialColor : AmbianceSpecialBase
{
[SerializeField]
public string id;
[SerializeField]
[FormerlySerializedAs("matIdx")]
private int _matIdx;
[SerializeField]
private bool allowFlip;
public override void Apply()
{
Renderer renderer = GetComponent<Renderer>();
if (renderer == null)
{
return;
}
Material specialMat = AmbianceController.Instance.GetSpecialMat(id, allowFlip);
if (specialMat == null)
{
Debug.LogErrorFormat("AmbianceSpecialColor failed to find special material id {0}", id);
return;
}
Material[] materials = renderer.sharedMaterials;
if (_matIdx >= materials.Length)
{
return;
}
materials[_matIdx] = specialMat;
renderer.sharedMaterials = materials;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: add998f88bbbe1cc326e7b4db3730d7c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ambiance
{
[CreateAssetMenu(fileName = "AmbiancesDef", menuName = "GameSqueleton/New Ambiances Def")]
public class AmbiancesDef : ScriptableObject
{
[SerializeField]
public FogDistance defaultFogDistance;
[SerializeField]
[FormerlySerializedAs("ambiances")]
private List<AmbianceDef> _ambiances;
public List<SpecialMatDef> specialsMatRef;
public List<AmbianceDef> GetAmbiancesList()
{
return _ambiances;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 922a2bac4ec8e83ea7ae4d7712140826
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
using UnityEngine;
namespace Ambiance
{
[CreateAssetMenu(fileName = "AmbiancesDef", menuName = "GameSqueleton/New Fog Distance")]
public class FogDistance : ScriptableObject
{
public float start = 240f;
public float end = 500f;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebea53ccbf2d9ef2d6c35d9b388c724d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
using System;
using UnityEngine;
namespace Ambiance
{
[Serializable]
public class SpecialColorDef
{
public string id;
public Color color;
public Color colorAdd;
public Texture texture;
[ColorUsage(true, true)]
public Color colorEmission;
public Texture textureEmission;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 835ee94a5c1f7fc458fa297e3ad0d697
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
using System;
using UnityEngine;
namespace Ambiance
{
[Serializable]
public class SpecialMatDef
{
public string id;
public Material materialRef;
public bool flippable;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 288eb634727de864f8b47efadb0a1dc7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
using System;
using UnityEngine;
namespace Ambiance
{
[Serializable]
public class SpecialPrefabDef
{
public string id;
public Transform prefab;
public Vector3 offsetMin;
public Vector3 offsetMax;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df1ca367ac7e23141b42998fa285d2e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: