Esempio n. 1
0
    void handleStates(List <RStateUpdate> states)
    {
        RStateUpdate su    = null;
        Other        ot    = null;
        bool         known = false;

        for (int s = 0; s < states.Count; s++)
        {
            known = false;
            su    = states[s];
            for (int o = 0; o < Others.Count; o++)
            {
                ot = Others[o];
                if (su.clientId == ot.ClientId)
                {
                    known = true;
                    applyStateToGameObject(su, ot.GObject);
                    break;
                }
            }

            if (!known)
            {
                GameObject tclone = new GameObject();
                Transform  transf = tclone.transform;

                transf.position = new Vector3(
                    (float)su.position.x,
                    (float)su.position.y,
                    (float)su.position.z);

                transf.rotation = Quaternion.Euler(
                    (float)su.rotation.x,
                    (float)su.rotation.y,
                    (float)su.rotation.z);

                Debug.Log("spawning other.");
                Other newOther = new Other(
                    su.clientId,
                    GameObject.Instantiate(OthersPrefab, transf));

                newOther.GObject.transform.parent = null;                 //remove parent from child before destroying it
                GameObject.DestroyImmediate(tclone);
                Others.Add(newOther);
            }
        }
    }
Esempio n. 2
0
    void applyStateToGameObject(RStateUpdate state, GameObject go)
    {
        Vector3 position = new Vector3(
            (float)state.position.x,
            (float)state.position.y,
            (float)state.position.z);

        Quaternion rotation = Quaternion.Euler(
            (float)state.rotation.x,
            (float)state.rotation.y,
            (float)state.rotation.z);

        go.transform.position = position;
        go.transform.rotation = rotation;
        //TODO move & rotate smooth
        //TODO play animations
    }