public void ChangeMeshMaterial(CharacterMeshMaterial cmm) { Material[] mats = PC.Instance.characterMaterialMesh.renderer.materials; for(int cnt = 0; cnt < PC.Instance.characterMaterialMesh.renderer.materials.Length; cnt++) mats[cnt] = PC.Instance.characterMaterialMesh.renderer.materials[cnt]; switch(cmm) { case CharacterMeshMaterial.Feet: if(_feetMaterialIndex > ca.feetMaterial.Length - 1) _feetMaterialIndex = 0; else if(_feetMaterialIndex < 0) _feetMaterialIndex = ca.feetMaterial.Length - 1; mats[(int)cmm] = ca.feetMaterial[_feetMaterialIndex]; break; case CharacterMeshMaterial.Legs: if(_legMaterialIndex > ca.legMaterial.Length - 1) _legMaterialIndex = 0; else if(_legMaterialIndex < 0) _legMaterialIndex = ca.legMaterial.Length - 1; mats[(int)cmm] = ca.legMaterial[_legMaterialIndex]; break; case CharacterMeshMaterial.Hands: if(_handMaterialIndex > ca.handsMaterial.Length - 1) _handMaterialIndex = 0; else if(_handMaterialIndex < 0) _handMaterialIndex = ca.handsMaterial.Length - 1; mats[(int)cmm] = ca.handsMaterial[_handMaterialIndex]; break; case CharacterMeshMaterial.Torso: if(_torsoMaterialIndex > ca.torsoMaterial.Length - 1) _torsoMaterialIndex = 0; else if(_torsoMaterialIndex < 0) _torsoMaterialIndex = ca.torsoMaterial.Length - 1; mats[(int)cmm] = ca.torsoMaterial[_torsoMaterialIndex]; break; case CharacterMeshMaterial.Face: if(_faceMaterialIndex > ca.faceMaterial.Length - 1) _faceMaterialIndex = 0; else if(_faceMaterialIndex < 0) _faceMaterialIndex = ca.faceMaterial.Length - 1; mats[(int)cmm] = ca.faceMaterial[_faceMaterialIndex]; break; } DestroyImmediate(PC.Instance.characterMaterialMesh.renderer.materials[(int)cmm]); PC.Instance.characterMaterialMesh.renderer.materials = mats; // Debug.Log(mats.Length); // Debug.Log("Wearing:" +PC.Instance.characterMaterialMesh.renderer.materials[2].name + " Should be wearing: " + ca.torsoMaterial[_torsoMaterialIndex].name ); // Resources.UnloadUnusedAssets(); }
// Change Materials void ChangeMeshMaterial(CharacterMeshMaterial cmm) { int cmmHash = cmm.GetHashCode(); Material[] mats = pc.characterMaterialMesh.GetComponent <Renderer>().materials; for (int i = 0; i < pc.characterMaterialMesh.GetComponent <Renderer>().materials.Length; i++) { mats[i] = pc.characterMaterialMesh.GetComponent <Renderer>().materials[i]; } switch (cmm) { case CharacterMeshMaterial.Chest: if (_chestMaterialIndex > ca.chestMaterial.Length - 1) { _chestMaterialIndex = 0; } else if (_chestMaterialIndex < 0) { _chestMaterialIndex = ca.chestMaterial.Length - 1; } mats[cmmHash] = ca.chestMaterial[_chestMaterialIndex]; break; case CharacterMeshMaterial.Head: if (_headMaterialIndex > ca.headMaterial.Length - 1) { _headMaterialIndex = 0; } else if (_headMaterialIndex < 0) { _headMaterialIndex = ca.headMaterial.Length - 1; } mats[cmmHash] = ca.headMaterial[_headMaterialIndex]; break; } DestroyImmediate(pc.characterMaterialMesh.GetComponent <Renderer>().materials[cmmHash]); pc.characterMaterialMesh.GetComponent <Renderer>().materials = mats; }
public void ChangeMeshMaterial(CharacterMeshMaterial cmm) { Material[] mats = PC.Instance.characterMaterialMesh.renderer.materials; for (int cnt = 0; cnt < PC.Instance.characterMaterialMesh.renderer.materials.Length; cnt++) { mats[cnt] = PC.Instance.characterMaterialMesh.renderer.materials[cnt]; } switch (cmm) { case CharacterMeshMaterial.Feet: if (_feetMaterialIndex > ca.feetMaterial.Length - 1) { _feetMaterialIndex = 0; } else if (_feetMaterialIndex < 0) { _feetMaterialIndex = ca.feetMaterial.Length - 1; } mats[(int)cmm] = ca.feetMaterial[_feetMaterialIndex]; break; case CharacterMeshMaterial.Legs: if (_legMaterialIndex > ca.legMaterial.Length - 1) { _legMaterialIndex = 0; } else if (_legMaterialIndex < 0) { _legMaterialIndex = ca.legMaterial.Length - 1; } mats[(int)cmm] = ca.legMaterial[_legMaterialIndex]; break; case CharacterMeshMaterial.Hands: if (_handMaterialIndex > ca.handsMaterial.Length - 1) { _handMaterialIndex = 0; } else if (_handMaterialIndex < 0) { _handMaterialIndex = ca.handsMaterial.Length - 1; } mats[(int)cmm] = ca.handsMaterial[_handMaterialIndex]; break; case CharacterMeshMaterial.Torso: if (_torsoMaterialIndex > ca.torsoMaterial.Length - 1) { _torsoMaterialIndex = 0; } else if (_torsoMaterialIndex < 0) { _torsoMaterialIndex = ca.torsoMaterial.Length - 1; } mats[(int)cmm] = ca.torsoMaterial[_torsoMaterialIndex]; break; case CharacterMeshMaterial.Face: if (_faceMaterialIndex > ca.faceMaterial.Length - 1) { _faceMaterialIndex = 0; } else if (_faceMaterialIndex < 0) { _faceMaterialIndex = ca.faceMaterial.Length - 1; } mats[(int)cmm] = ca.faceMaterial[_faceMaterialIndex]; break; } DestroyImmediate(PC.Instance.characterMaterialMesh.renderer.materials[(int)cmm]); PC.Instance.characterMaterialMesh.renderer.materials = mats; // Debug.Log(mats.Length); // Debug.Log("Wearing:" +PC.Instance.characterMaterialMesh.renderer.materials[2].name + " Should be wearing: " + ca.torsoMaterial[_torsoMaterialIndex].name ); // Resources.UnloadUnusedAssets(); }