90 lines
2.0 KiB
C#
90 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class RefreshIceFishing : MonoBehaviour
|
|
{
|
|
public bool activeNormal = true;
|
|
|
|
public bool activeIce = true;
|
|
|
|
public Material materialNormal;
|
|
|
|
public Material materialIce;
|
|
|
|
public int materialID;
|
|
|
|
public List<Material> materialsNormal = new List<Material>();
|
|
|
|
public List<Material> materialsIce = new List<Material>();
|
|
|
|
public bool updateSnow;
|
|
|
|
public void Start()
|
|
{
|
|
if (GameController.Instance == null)
|
|
{
|
|
return;
|
|
}
|
|
bool iceLevel = GameController.Instance.iceLevel;
|
|
base.gameObject.SetActive((iceLevel && activeIce) || (!iceLevel && activeNormal));
|
|
if (iceLevel && !activeIce)
|
|
{
|
|
Object.DestroyImmediate(base.gameObject, true);
|
|
return;
|
|
}
|
|
if (!iceLevel && !activeNormal)
|
|
{
|
|
Object.DestroyImmediate(base.gameObject, true);
|
|
return;
|
|
}
|
|
MeshRenderer[] componentsInChildren = GetComponentsInChildren<MeshRenderer>(true);
|
|
for (int i = 0; i < componentsInChildren.Length; i++)
|
|
{
|
|
if (!iceLevel && (bool)materialNormal)
|
|
{
|
|
if (materialID == 0)
|
|
{
|
|
componentsInChildren[i].material = materialNormal;
|
|
}
|
|
else
|
|
{
|
|
componentsInChildren[i].materials[materialID] = materialNormal;
|
|
}
|
|
}
|
|
else if (iceLevel && (bool)materialIce)
|
|
{
|
|
if (materialID == 0)
|
|
{
|
|
componentsInChildren[i].material = materialIce;
|
|
}
|
|
else
|
|
{
|
|
componentsInChildren[i].materials[materialID] = materialIce;
|
|
}
|
|
}
|
|
}
|
|
if (updateSnow && GetComponent<MeshRenderer>().material.HasProperty("_Snow"))
|
|
{
|
|
GetComponent<MeshRenderer>().material.SetFloat("_Snow", (!iceLevel) ? 0f : 1f);
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void SetIceMaterials()
|
|
{
|
|
MeshRenderer[] componentsInChildren = GetComponentsInChildren<MeshRenderer>(true);
|
|
for (int i = 0; i < componentsInChildren.Length; i++)
|
|
{
|
|
if (materialID == 0)
|
|
{
|
|
componentsInChildren[i].material = materialIce;
|
|
}
|
|
else
|
|
{
|
|
componentsInChildren[i].materials[materialID] = materialIce;
|
|
}
|
|
}
|
|
}
|
|
}
|