Ejemplo n.º 1
0
    public RaycastHit instanceRay(Transform position, Transform bulletOrigin, NetworkInstantiate networkInstantiate, int id)
    {
        RaycastHit hit = new RaycastHit();

        if (!canRaycast())
        {
            return(hit);
        }

        animator.ResetTrigger("shoot");
        animator.SetTrigger("shoot");

        reduceAmmo();
        animator.SetInteger("ammo", currentClipSize);
        Instantiate(bulletVFX, bulletOrigin.position, bulletOrigin.rotation);
        networkInstantiate.instantiate(NetworkInstantiate.prefabNames.bullet, bulletOrigin.position, bulletOrigin.rotation, id);
        if (Physics.Raycast(position.transform.position, position.forward, out hit, shotDistance))
        {
            //Debug.Log(hit.transform.gameObject.name);
            Debug.DrawRay(position.transform.position, position.forward * shotDistance, Color.red, 10);

            return(hit);
        }
        else
        {
            Debug.DrawRay(position.transform.position, position.forward * shotDistance, Color.red, 10);
        }

        return(hit);
    }
Ejemplo n.º 2
0
    public Client(ClientSceneManager sceneManager)
    {
        this.commandDictionary      = new CommandDictionary();
        this.remoteClients          = new List <RemoteClients>();
        this.mainThreadMessageQueue = new Queue <string>();

        this.sceneManager = sceneManager;
        networkInst       = sceneManager.GetComponent <NetworkInstantiate>();
    }
Ejemplo n.º 3
0
        void RemoveBufferedRPC(Messenger messenger, string key, RemoveBufferedRPC packet)
        {
            var buffer = _rpcBufferByWorld[_worldByUser[packet.caller]];

            for (int i = 0; i < buffer.Count; i++)
            {
                if (buffer[i].GetType().Name == packet.typeName)
                {
                    NetworkInstantiate ni = (NetworkInstantiate)buffer[i];
                    if (ni != null && ni.networkID == packet.networkID)
                    {
                        buffer.RemoveAt(i);
                    }
                }
            }
        }
Ejemplo n.º 4
0
    private void Start()
    {
        networkWeaponManager = gameObject.GetComponent <NetworkWeaponManager>();

        networkInstantiate = clientSceneManager.GetComponentInChildren <NetworkInstantiate>();

        foreach (Weapon weapon in weapons)
        {
            if (weapon != null)
            {
                weaponViewModels[0] = weapon.initialize(viewModelPosition, clientSceneManager.getID());
            }
            viewModelAnimators[0] = weaponViewModels[0].GetComponent <Animator>();
            weapons[0].setAnimator(viewModelAnimators[0]);
        }
    }
Ejemplo n.º 5
0
    public void NetworkInstantiate(NetworkInstantiate info)
    {
        var pf = Resources.Load <NetworkScript>("Prefabs/" + info.pfName);

        pf.enabled = false;
        var instance = Instantiate(pf);

        instance.networkID = info.networkID;
        instance.owner     = info.sender;
        instance.RegisterToProgram();
        instance.enabled = true;
        if (info.callbackArg.GetType() != typeof(NullPacket))
        {
            instance.SendMessage("OnNetInstantiate", info.callbackArg, SendMessageOptions.DontRequireReceiver);
        }
        if (info.callback != "")
        {
            SendMessage(info.callback, instance);
        }
    }
Ejemplo n.º 6
0
    private void Start()
    {
        portInput.text  = "3000";
        mainThreadQueue = new Queue <string>();

        //localRemoteController = playerTransform.gameObject.GetComponentInChildren<RemoteController>();
        raycastWeapons     = playerTransform.gameObject.GetComponent <NetworkWeaponManager>();
        playerMovement     = playerTransform.GetComponent <PlayerMovement>();
        playerHealth       = playerTransform.GetComponent <PlayerHealth>();
        networkInstantiate = GetComponent <NetworkInstantiate>();
        ragdollSpawner     = GetComponent <RagdollSpawner>();

        //localRemoteController.enabled = false;
        playerMovement.enabled = true;

        if (raycastWeapons != null)
        {
            raycastWeapons.enabled = true;
        }
    }
Ejemplo n.º 7
0
 void NetworkInstantiate(NetworkInstantiate rpc)
 {
     rpc.networkID = _currentNetworkID++;
 }
Ejemplo n.º 8
0
    public List <RaycastHit> multiRaycast(Transform transform, Transform bulletOrigin, NetworkInstantiate networkInstantiate, int id)
    {
        RaycastHit        hit;
        List <RaycastHit> hitObjects = new List <RaycastHit>();

        if (!canRaycast() || isReloading)
        {
            return(hitObjects);
        }

        animator.ResetTrigger("shoot");
        animator.SetTrigger("shoot");

        Debug.DrawRay(transform.position, transform.forward * shotDistance, Color.red, fireRate);
        for (int ray = 0; ray < numberOfRays; ray++)
        {
            Vector3 rayDirection = Vector3.forward;
            float   spread       = Random.Range(0f, bulletSpread);
            float   angle        = Random.Range(0f, 360f);
            rayDirection = Quaternion.AngleAxis(spread, Vector3.up) * rayDirection;
            rayDirection = Quaternion.AngleAxis(angle, Vector3.forward) * rayDirection;
            rayDirection = transform.rotation * rayDirection;

            Debug.DrawRay(transform.position, rayDirection * shotDistance, Color.blue, fireRate);
            //var bullet = Instantiate(bulletVFX, bulletOrigin.position, bulletOrigin.rotation);
            var rBulletx = Random.Range(-bulletSpread, bulletSpread);
            var rBulletY = Random.Range(-bulletSpread, bulletSpread);
            var rBulletZ = Random.Range(-bulletSpread, bulletSpread);
            //bullet.transform.Rotate(rBulletx, rBulletY, rBulletZ);

            Quaternion rotate = Quaternion.Euler(rBulletx, rBulletY, rBulletZ);

            networkInstantiate.instantiate(NetworkInstantiate.prefabNames.bullet, bulletOrigin.position, bulletOrigin.rotation * rotate, id);

            if (Physics.Raycast(transform.position, rayDirection, out hit, shotDistance))
            {
                hitObjects.Add(hit);
            }
        }
        reduceAmmo();
        return(hitObjects);
    }
Ejemplo n.º 9
0
    public void NetworkInstantiate(NetworkScript prefab, IAutoSerializable callbackArg, string callback)
    {
        var ni = new NetworkInstantiate(prefab.name, callbackArg, callback);

        Send(ni);
    }
Ejemplo n.º 10
0
    public void NetworkInstantiate(NetworkScript prefab, string callback)
    {
        var ni = new NetworkInstantiate(prefab.name, new NullPacket(), callback);

        Send(ni);
    }
Ejemplo n.º 11
0
    public void NetworkInstantiate(NetworkScript prefab)
    {
        var ni = new NetworkInstantiate(prefab.name, new NullPacket(), "");

        Send(ni);
    }
Ejemplo n.º 12
0
 public void NetworkInstantiate(NetworkScript prefab, string callback)
 {
     var ni = new NetworkInstantiate(prefab.name, new NullPacket(), callback);
     Send(ni);
 }
Ejemplo n.º 13
0
 public void NetworkInstantiate(NetworkScript prefab, IAutoSerializable callbackArg)
 {
     var ni = new NetworkInstantiate(prefab.name, callbackArg, "");
     NetworkProgramUnity.currentInstance.Send(ni);
 }
Ejemplo n.º 14
0
 public void NetworkInstantiate(NetworkScript prefab)
 {
     var ni = new NetworkInstantiate(prefab.name, new NullPacket(), "");
     Send(ni);
 }
Ejemplo n.º 15
0
 public void NetworkInstantiate(NetworkInstantiate info)
 {
     var pf = Resources.Load<NetworkScript>("Prefabs/" + info.pfName);
     pf.enabled = false;
     var instance = Instantiate(pf);
     instance.networkID = info.networkID;
     instance.owner = info.sender;
     instance.RegisterToProgram();
     instance.enabled = true;
     if (info.callbackArg.GetType() != typeof(NullPacket))
         instance.SendMessage("OnNetInstantiate", info.callbackArg, SendMessageOptions.DontRequireReceiver);
     if (info.callback != "")
         SendMessage(info.callback, instance);
 }
Ejemplo n.º 16
0
 public void NetworkInstantiate(NetworkScript prefab, IAutoSerializable callbackArg, string callback)
 {
     var ni = new NetworkInstantiate(prefab.name, callbackArg, callback);
     Send(ni);
 }