-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor mesh materials into a manager class
- Loading branch information
Showing
3 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
UnityClient/Packages/vbl.urchin/Scripts/Utils/MaterialManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
public class MaterialManager : MonoBehaviour | ||
{ | ||
[SerializeField] private List<Material> _meshMaterials; | ||
[SerializeField] private List<string> _materialNames; | ||
|
||
private static MaterialManager Instance; | ||
private Dictionary<string, Material> _materialsDict; | ||
|
||
private void Awake() | ||
{ | ||
if (Instance != null) | ||
throw new Exception("Only a single instance of MaterialManager should exist in the scene."); | ||
|
||
if (_meshMaterials.Count != _materialNames.Count) | ||
Debug.LogWarning("Mesh material and name count should be equal"); | ||
|
||
_materialsDict = new(); | ||
foreach (var zip in _meshMaterials.Zip(_materialNames, (material, name) => (material, name))) | ||
_materialsDict.Add(zip.name, zip.material); | ||
} | ||
|
||
public static Dictionary<string, Material> MeshMaterials { get { return Instance._materialsDict; } } | ||
} |
11 changes: 11 additions & 0 deletions
11
UnityClient/Packages/vbl.urchin/Scripts/Utils/MaterialManager.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.