C# 光子rpc调用不正确(生成字符的光子rpc)
我正在尝试用脚本生成角色。 我在资源文件夹下有“C# 光子rpc调用不正确(生成字符的光子rpc),c#,unity3d,rpc,multiplayer,photon,C#,Unity3d,Rpc,Multiplayer,Photon,我正在尝试用脚本生成角色。 我在资源文件夹下有“playerObj”和“model”prefplayerObj具有所有与脚本相关的控制,以及photonView、Camera等。模型具有动画、皮肤渲染器和photonView 我想做的是,实例化playerObj并一起实例化模型对象。对于model obj,我想添加一些皮肤网格,使其具有角色的模型(我这样做是为了让玩家能够更改模型的装备),然后使用model为playerObj 问题是,它确实正确地实例化了自己的角色,但实例化其他角色是错误的。
playerObj
”和“model
”prefplayerObj
具有所有与脚本相关的控制,以及photonView
、Camera
等。模型具有动画
、皮肤渲染器
和photonView
我想做的是,实例化playerObj
并一起实例化模型对象。对于model obj,我想添加一些皮肤网格,使其具有角色的模型(我这样做是为了让玩家能够更改模型的装备),然后使用model为playerObj
问题是,它确实正确地实例化了自己的角色,但实例化其他角色是错误的。
它将实例化playerObj
和model Obj
。但它不会渲染蒙皮网格,也不会为这两个对象设置父对象。。。
我不知道我做错了什么或错过了什么
正如你们看到的脚本下面,我使用三种不同的脚本来生成角色
多谢各位
PlayerInit.cs
CharacterGenerator.cs
public IEnumerator CreateCharacter()
{
var co = CurrentCharacter.GetByGUI(dbid);
co.InitModel(character, dbid);
m_loaded = true;
m_loading = false;
}
public GameObject Generate(PhotonView pv)
{
int id1 = PhotonNetwork.AllocateViewID();
GameObject root = PhotonNetwork.Instantiate ("Model", new Vector3 (0, 0, 0), new Quaternion (0, 0, 0, 0),0);
root.name = "body";
Generate (pv, root);
return root;
}
public GameObject Generate(PhotonView pv, GameObject root)
{
int id1 = PhotonNetwork.AllocateViewID();
putSkin (root);
pv.RPC("putSkin", PhotonTargets.Others, root, id1, PhotonNetwork.player);
return root;
}
// Creates a character based on the currentConfiguration recycling a
// character base, this way the position and animation of the character
// are not changed.
[RPC]
public void putSkin(GameObject root){
float startTime = Time.realtimeSinceStartup;
// The SkinnedMeshRenderers that will make up a character will be
// combined into one SkinnedMeshRenderers using multiple materials.
// This will speed up rendering the resulting character.
List<CombineInstance> combineInstances = new List<CombineInstance>();
List<Material> materials = new List<Material>();
List<Transform> bones = new List<Transform>();
Transform[] transforms = root.GetComponentsInChildren<Transform>();
foreach (CharacterElement element in currentConfiguration.Values)
{
SkinnedMeshRenderer smr = element.GetSkinnedMeshRenderer();
materials.AddRange(smr.materials);
for (int sub = 0; sub < smr.sharedMesh.subMeshCount; sub++)
{
CombineInstance ci = new CombineInstance();
ci.mesh = smr.sharedMesh;
ci.subMeshIndex = sub;
combineInstances.Add(ci);
}
// As the SkinnedMeshRenders are stored in assetbundles that do not
// contain their bones (those are stored in the characterbase assetbundles)
// we need to collect references to the bones we are using
foreach (string bone in element.GetBoneNames())
{
foreach (Transform transform in transforms)
{
if (transform.name != bone) continue;
bones.Add(transform);
break;
}
}
Object.Destroy(smr.gameObject);
}
// Obtain and configure the SkinnedMeshRenderer attached to
// the character base.
SkinnedMeshRenderer r = root.GetComponent<SkinnedMeshRenderer>();
r.sharedMesh = new Mesh();
r.sharedMesh.CombineMeshes(combineInstances.ToArray(), false, false);
r.bones = bones.ToArray();
r.materials = materials.ToArray();
r.useLightProbes = true;
Debug.Log("Generating character took: "
+ (Time.realtimeSinceStartup - startTime) * 1000 + " ms");
}
[PunRPC]
public void InitModel(GameObject prefab, GameObject model, int id){
character = prefab;
InitModel (model, id);
}
public void InitModel(GameObject model, int id)
{
parenting (model, id);
_photonView.RPC ("parenting", PhotonTargets.Others, model, id);
}
[RPC]
void parenting(GameObject model, int id){
model.layer = LayerMask.NameToLayer ("Girl");
model.transform.parent = character.transform;
model.transform.localPosition = Vector3.zero;
InitMouseLook (model);
InitAnimations (model);
if (id == PersistentData.Instance.LoggedInUser.m_id) {
CurrentCharacter.persistentMainModel = model;
}
}