예제 #1
0
 void OnDisconnectedFromServer(NetworkDisconnection info)
 {
     Destroy(vaisseau);
     NetworkView.Destroy(vaisseau);
 }
예제 #2
0
    void CloneObject(string name, NetworkViewID viewID, Vector3 location, Vector3 forward, Vector3 color)
    {
        GameObject clone = null;
        GameObject model = null;

        foreach (NAObject o in NA.instanciables)
        {
            if (o.name == name)
            {
                model = o.go;
                if (o.downloading)
                {
                    LogManager.LogWarning("clone command received but model is still downloading !");
                }
            }
        }
        //instead of cloning the root, we clone the first child (for synchronization purpose on physicallized objects)
        //this is where we have an issue (Island animals vs Coffe pot)
        NAAnimalBehavior animal = model.GetComponentInChildren <NAAnimalBehavior>();

        if (model.transform.childCount > 0 && animal)
        {
            model = model.transform.GetChild(0).gameObject;
        }

        clone = GameObject.Instantiate(model, Vector3.zero, Quaternion.identity) as GameObject;

        LogManager.Log("clone " + name);

        //reset position of main child
        if (clone.transform.childCount > 0 && animal)
        {
            clone.transform.GetChild(0).gameObject.transform.localPosition = Vector3.zero;
        }

        //remove previous network view
        NetworkView nViewOriginal = clone.GetComponent <NetworkView>();

        if (nViewOriginal)
        {
            NetworkView.Destroy(nViewOriginal);
        }

        NetworkView nView = clone.AddComponent <NetworkView>();

        nView.viewID = viewID;
        nView.stateSynchronization = NetworkStateSynchronization.Unreliable;

        clone.transform.position = location;


        MeshRenderer renderer = clone.GetComponent <MeshRenderer>();

        if (renderer != null)
        {
            renderer.material.color = new Color(color.x, color.y, color.z);
        }
        //apply forward world orientation
        clone.transform.forward = forward;
        //clone.transform.forward = transform.rotation * Vector3.Normalize(forward) ;

        //clone.transform.forward = forward;


        //Rigidbody rb = clone.AddComponent<Rigidbody>();
        if (NA.isServer() || NA.isStandalone())
        {
            /*Rigidbody rb = clone.AddComponent<Rigidbody>();
             * rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
             * rb.AddForce(forward*200f);
             */
        }
        else
        {
            //client, we need the RB for local collisions but in kinematic mode only
            //rb.isKinematic = true;
        }
        NA.player_objects.Add(clone);
    }