光子rpc没有正确调用(带有字符生成的Photon RPC)

时间:2015-07-06 17:45:10

标签: c# unity3d rpc multiplayer photon

我试图用脚本生成角色。 我有&#39; playerObj&#39;和&#39; model&#39;资源文件夹下的pref。 playerObj包含所有与脚本相关的控件,photonViewCamera等,模型包含animationskin rendererphotonView。< / p>

我想要做的是,实例化playerObj并一起实例化模型对象。并且使用模型obj,我想添加一些皮肤网格,因此它具有角色模型(我这样做,因此玩家能够改变模型的装备),然后用模型教育playerObj。 / p>

问题是它是否正确实例化了自己的角色,但是实例化其他角色是错误的。 它将实例化playerObjmodel Obj。但它没有渲染皮肤网格,也没有养育那两个... 我不知道我做错了什么或错过了什么......

当您看到脚本时,我使用三个不同的脚本来生成角色。

谢谢。

PlayerInit.cs

public IEnumerator CreateCharacter()
{
    var co = CurrentCharacter.GetByGUI(dbid);
    co.InitModel(character, dbid);

    m_loaded = true;
    m_loading = false;
}

CharacterGenerator.cs

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");

}

CurrentCharacter.cs

    [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;
    }
}

0 个答案:

没有答案