Equip Multiplayer With Photon Mixamo and Unity 3D
Equip Multiplayer With Photon Mixamo and Unity 3D
Code:
public class boneCombinePhoton : MonoBehaviour
{
public readonly Dictionary<int, Transform> _RootBoneDictionary = new Dictionary<int, Transform>();
[SerializeField]private readonly Transform[] _boneTransforms= new Transform[67];
public Transform _transform;
[SerializeField] private Transform Trousers;
[SerializeField] private Transform shirt;
[SerializeField] private Transform hair;
[SerializeField] private Transform shoe;
[SerializeField] private Transform glove;
[SerializeField] private SkinnedMeshRenderer meshRenderer;
[SerializeField] private Transform[] bones;
Transform EquipmentPosition;
private PhotonView pv;
SkinnedMeshRenderer renderers;
private void Start()
{
pv =GetComponent<PhotonView>();
if(pv.IsMine)
pv.RPC("TraverseHierarchy",RpcTarget.AllBuffered);
kiemtrado();
}
void kiemtrado()
{
if(lkhoquanao.instance.dangmac_quan.Length >0)
hiendomac_photon(lkhoquanao.instance.dangmac_quan,"Trousers");
if(lkhoquanao.instance.dangmac_ao.Length >0)
hiendomac_photon(lkhoquanao.instance.dangmac_ao,"shirt");
if(lkhoquanao.instance.dangmac_toc.Length >0)
hiendomac_photon(lkhoquanao.instance.dangmac_toc,"hair");
if(lkhoquanao.instance.dangmac_gangtay.Length >0)
hiendomac_photon(lkhoquanao.instance.dangmac_gangtay,"glove");
if(lkhoquanao.instance.dangmac_giay.Length >0)
hiendomac_photon(lkhoquanao.instance.dangmac_giay,"shoe");
}
void hiendomac_photon (string EquipmentName,string Type) {
AddLimb(EquipmentName,Type);
}
public void AddLimb(string bonedObj,string Type)
{
if(pv.IsMine)
{
if(Type=="Trousers")
{
pv.RPC("ProcessBonedObject",RpcTarget.AllBuffered,bonedObj,"Trousers");
}
if(Type=="shirt")
{
pv.RPC("ProcessBonedObject",RpcTarget.AllBuffered,bonedObj,"shirt");
}
if(Type=="hair")
{
pv.RPC("ProcessBonedObject",RpcTarget.AllBuffered,bonedObj,"hair");
}
if(Type=="shoe")
{
pv.RPC("ProcessBonedObject",RpcTarget.AllBuffered,bonedObj,"shoe");
}
if(Type=="glove")
{
pv.RPC("ProcessBonedObject",RpcTarget.AllBuffered,bonedObj,"glove");
}
}
}
void setupgiatri(Transform transform)
{
foreach(Transform child in transform)
{
_RootBoneDictionary.Add(child.name.GetHashCode(),child);
setupgiatri(child);
}
}
[PunRPC]
private void TraverseHierarchy()
{
_transform = this.gameObject.transform;
setupgiatri(_transform);
}
[PunRPC]
private Transform ProcessBonedObject(string EquipmentName,string Type)
{
foreach (GameObject bonedObj in lkhoquanao.instance.doituongtranbi)
{
if(bonedObj.name.Contains(EquipmentName))
{
renderers = bonedObj.GetComponent<SkinnedMeshRenderer>();
}
}
if(Type=="Trousers")
{
EquipmentPosition= Trousers;
}
if(Type=="shirt")
{
EquipmentPosition= shirt;
}
if(Type=="hair")
{
EquipmentPosition= hair;
}
if(Type=="shoe")
{
EquipmentPosition= shoe;
}
if(Type=="glove")
{
EquipmentPosition= glove;
}
meshRenderer = EquipmentPosition.gameObject.AddComponent<SkinnedMeshRenderer>();
bones = renderers.bones;
for (int i = 0; i < bones.Length; i++)
{
_boneTransforms[i] = _RootBoneDictionary[bones[i].name.GetHashCode()];
}
meshRenderer.bones = _boneTransforms;
meshRenderer.sharedMesh = renderers.sharedMesh;
meshRenderer.materials = renderers.sharedMaterials;
EquipmentPosition.SetParent(_transform);
return EquipmentPosition;
}
}
Post a Comment