62 lines
1.2 KiB
C#
62 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class HeadOcclude : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class MaterialSlot
|
|
{
|
|
public int slot;
|
|
|
|
public Material material;
|
|
|
|
public MaterialSlot(int slot, Material material)
|
|
{
|
|
this.slot = slot;
|
|
this.material = material;
|
|
}
|
|
}
|
|
|
|
public CameraViewTypeVariable cameraViewType;
|
|
|
|
public List<GameObject> headObjects;
|
|
|
|
public Material headTransparentMaterial;
|
|
|
|
public SkinnedMeshRenderer headRenderer;
|
|
|
|
public Material[] slotsChange;
|
|
|
|
private Material[] _defaultMaterials;
|
|
|
|
private bool _isOccluded;
|
|
|
|
private void Awake()
|
|
{
|
|
_defaultMaterials = headRenderer.sharedMaterials;
|
|
CameraViewTypeOnOnValueChanged(cameraViewType.Value);
|
|
cameraViewType.OnValueChanged += CameraViewTypeOnOnValueChanged;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
cameraViewType.OnValueChanged -= CameraViewTypeOnOnValueChanged;
|
|
}
|
|
|
|
private void CameraViewTypeOnOnValueChanged(CameraViewType obj)
|
|
{
|
|
ToggleOcclude(obj == CameraViewType.FPP);
|
|
}
|
|
|
|
private void ToggleOcclude(bool value)
|
|
{
|
|
_isOccluded = value;
|
|
headObjects.ForEach(delegate(GameObject x)
|
|
{
|
|
x.SetActive(!_isOccluded);
|
|
});
|
|
headRenderer.materials = ((!_isOccluded) ? _defaultMaterials : slotsChange);
|
|
}
|
|
}
|