This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathMaterialsFader.cs
More file actions
66 lines (56 loc) · 2.39 KB
/
MaterialsFader.cs
File metadata and controls
66 lines (56 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using UnityEngine;
namespace GalaxyExplorer
{
public class MaterialsFader : Fader
{
public Material[] materials;
private MaterialSettings[] settings;
private void Start()
{
settings = new MaterialSettings[materials.Length];
for (int materialIndex = 0; materialIndex < materials.Length; ++materialIndex)
{
Material material = materials[materialIndex];
settings[materialIndex].material = material;
if (material != null)
{
settings[materialIndex].originalSourceBlend = material.HasProperty("_SRCBLEND") ? material.GetInt("_SRCBLEND") : -1;
settings[materialIndex].originalDestinationBlend = material.HasProperty("_DSTBLEND") ? material.GetInt("_DSTBLEND") : -1;
}
else
{
Debug.LogWarning("MaterialsFader: Material #" + materialIndex + " of '" + name + "' is missing - delete from list.");
}
}
}
private void OnDestroy()
{
// since the material is shared our settings will persist; loaded scenes should have full transition alpha
for (int materialIndex = 0; materialIndex < materials.Length; ++materialIndex)
{
if (materials[materialIndex] != null && settings != null)
{
MaterialSettings matset = settings[materialIndex];
if (matset.material != null)
{
matset.material.SetFloat("_TransitionAlpha", 1.0f);
if (matset.originalSourceBlend != -1)
{
matset.material.SetInt("_SRCBLEND", matset.originalSourceBlend);
}
if (matset.originalDestinationBlend != -1)
{
matset.material.SetInt("_DSTBLEND", matset.originalDestinationBlend);
}
}
}
}
}
protected override MaterialSettings[] Materials
{
get { return settings ?? new MaterialSettings[0]; }
}
}
}