1
This repository has been archived on 2025-03-15. You can view files and clone it, but cannot push or open issues or pull requests.
unity-vr-portoflio/Assets/04 - Scripts/View/Components/VarnishMaterialChangeComponent.cs

81 lines
2.4 KiB
C#
Raw Normal View History

2025-03-15 20:02:21 +01:00
using System;
using UnityEngine;
using EvolutStudio.tinysAPI.BaseClasses;
namespace EvolutStudio
{
namespace VRPortfolioWork
{
namespace Components
{
public class VarnishMaterialChangeComponent : BaseClassComponent
{
#region Public Attributes
// reference to the current selected material color
public Material selectedMaterial;
// reference to the proxyObject to change the material on
public GameObject proxyObject;
#endregion
#region Private Attributes
// private reference to the game object renderer instance
private Renderer _renderer;
#endregion
#region Public Functions
public override void ValidationFailed(string notification)
{
throw new NotImplementedException();
}
public override void ValidationSucceeded(string notification)
{
if (notification.Equals(BaseClassNotification.POINTERCLICKEVENT))
{
// getting the materials array
Material[] proxyObjectMats = _renderer.materials;
// changing the old material with the new one
proxyObjectMats[3] = selectedMaterial;
// overwritting the materials array
_renderer.materials = proxyObjectMats;
}
}
// Use this for initialization
public override void Init()
{
_ComponentsArrayIndex = modulInstance.View.RegisterComponent(this);
// save the reference
_renderer = proxyObject.GetComponent<Renderer>();
// getting the materials array
Material[] proxyObjectMats = _renderer.materials;
// changing the old material with the new one
proxyObjectMats[3] = selectedMaterial;
// overwritting the materials array
_renderer.materials = proxyObjectMats;
}
#endregion
#region Private Functions
// Add your private functions
#endregion
}
}
}
}