I have a prefab for my main character that has the player character as a child. The player character as the biped skeleton and a skinnedmesh renderer object as children.
The SkinnedMesh object has 4 materials attached.
One the highest parent I have added a ClothesManager Class that manages when this changes that looks like this:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MageClothesManager : MonoBehaviour {
public GameObject WizardObject;
[Header("Body Parts Colours")]
public GameManager.Colours HatColour;
public GameManager.Colours CapeColour;
public GameManager.Colours LeftHandColour;
public GameManager.Colours RightHandColour;
[Header("Body Parts")]
public GameManager.BodyParts FocusedBodyPart;
[Header("Material References")]
public Material GreenHatMat;
public Material RedHatMat;
public Material BlueHatMat;
public Material YellowHatMat;
public Material GreenBodyMat;
public Material RedBodyMat;
public Material BlueBodyMat;
public Material YellowBodyMat;
public Material GreenLeftHandMat;
public Material RedLeftHandMat;
public Material BlueLeftHandMat;
public Material YellowLeftHandMat;
public Material GreenRightHandMat;
public Material RedRightHandMat;
public Material BlueRightHandMat;
public Material YellowRightHandMat;
void OnEnable()
{
EventManager.HatChange += ChangeHat;
EventManager.CapeChange += ChangeCape;
EventManager.LeftHandChange += ChangeLeftHand;
EventManager.RightHandChange += ChangeRightHand;
EventManager.FocusBodyPartChange += changeFocus;
}
void OnDisable()
{
EventManager.HatChange -= ChangeHat;
EventManager.CapeChange -= ChangeCape;
EventManager.LeftHandChange -= ChangeLeftHand;
EventManager.RightHandChange -= ChangeRightHand;
EventManager.FocusBodyPartChange -= changeFocus;
}
public void ChangeHat(GameManager.Colours C)
{
HatColour = C;
switch (C)
{
case GameManager.Colours.Blue:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[3] = BlueBodyMat;
break;
case GameManager.Colours.Red:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[3] = RedBodyMat;
break;
case GameManager.Colours.Green:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[3] = GreenBodyMat;
break;
case GameManager.Colours.Yellow:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[3] = YellowBodyMat;
break;
}
}
public void ChangeCape(GameManager.Colours C)
{
CapeColour = C;
switch (C)
{
case GameManager.Colours.Blue:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[0] = BlueBodyMat;
break;
case GameManager.Colours.Red:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[0] = RedBodyMat;
break;
case GameManager.Colours.Green:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[0] = GreenBodyMat;
break;
case GameManager.Colours.Yellow:
WizardObject.GetComponent<SkinnedMeshRenderer>().materials[0] = YellowBodyMat;
break;
}
}
public void ChangeLeftHand(GameManager.Colours C)
{
LeftHandColour = C;
}
public void ChangeRightHand(GameManager.Colours C)
{
RightHandColour = C;
}
public void changeFocus(GameManager.BodyParts newFocus)
{
FocusedBodyPart = newFocus;
}
}
I have an EventManager that works and tells this when a change is made and what colour to change to.
The GameManager defines an enum for Colours, I know the areas are being called as the variable in the inspector (for the enum) changes to match.
When I removed the “s” from materials that can change the first entry though I need to change the others as well.