public WaitForConnected(ConnectionSystem connectionManager, bool state = true, float newTimeout = 10)
 {
     this.connectionManager = connectionManager;
     this.targetState       = state;
     this.timeout           = newTimeout;
     this.startTime         = Time.realtimeSinceStartup;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Command to start connecting to the server
        /// </summary>
        public void ConnectToServer()
        {
            // Setup variables
            string    networkAddress = serverAddress.text;
            IPAddress parsedAddress;
            ushort    networkPort;

            try
            {
                // Parse parameters
                IPAddress.TryParse(networkAddress, out parsedAddress);
                ushort.TryParse(serverPort.text, out networkPort);

                // Verify parameters
                // TODO: write verify code

                // Assign connection parameters
                PropHunt.Game.ProphuntClientServerControlSystem.NetworkAddress = networkAddress;
                PropHunt.Game.ProphuntClientServerControlSystem.NetworkPort    = networkPort;

                ConnectionSystem.ConnectToServer();
            }
            catch
            {
                UnityEngine.Debug.Log($"Failed to parse IP Address {serverAddress.text} and Port {serverPort.text}");
            }
        }
Exemplo n.º 3
0
        public IEnumerator ConnectionTest()
        {
            ConnectionSystem connectionManager = this.clientWorld.GetExistingSystem <ConnectionSystem>();

            yield return(null);

            // Make a connect request
            ConnectionSystem.ConnectToServer();
            yield return(new WaitForConnected(connectionManager));

            Assert.IsTrue(ConnectionSystem.IsConnected);

            yield return(null);

            // Make a disconnect request
            ConnectionSystem.DisconnectFromServer();
            yield return(new WaitForConnected(connectionManager, state: false));

            Assert.IsFalse(ConnectionSystem.IsConnected);
        }
Exemplo n.º 4
0
 // Start is called before the first frame update
 void Start()
 {
     cs = GetComponent <ConnectionSystem>();
 }
Exemplo n.º 5
0
    // if the object touches the ship (or its connected parts), connect to it
    private void OnTriggerEnter(Collider other)
    {
        if (isConnectable && currState == ConnectionSystem.State.loose)
        {
            ConnectionSystem otherCS = other.gameObject.GetComponent <ConnectionSystem>();
            //Debug.Log(otherCS);
            if (otherCS != null && otherCS.currState == ConnectionSystem.State.connected && GM.gm.player.GetComponent <ConnectionSystem>().isConnectable)
            {
                //transform.SetParent(other.gameObject.transform);
                localRot = transform.localRotation;
                Debug.Log(localRot);
                if (other.tag == "Player")
                {
                    Debug.Log("parent transform");
                    transform.SetParent(other.transform);
                    GM.gm.SetMass(GM.gm.GetMassWithChildren());
                    GM.gm.RefreshLargestRadius();
                    isAttached       = true;
                    currState        = ConnectionSystem.State.connected;
                    gameObject.layer = 8;
                    tag                = "connected";
                    rb.velocity        = Vector3.zero;
                    rb.angularVelocity = Vector3.zero;
                    rb.constraints     = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePosition;

                    if (click != null)
                    {
                        click.Play();
                    }
                }
                else
                {
                    /*if (otherCS.isAttached)
                     * {
                     *  Debug.Log("other cs");
                     *  transform.SetParent(other.transform);
                     *  currState = ConnectionSystem.State.connected;
                     *              gameObject.layer = 8;
                     *              rb.velocity = Vector3.zero;
                     *              rb.angularVelocity = Vector3.zero;
                     *              rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePosition;
                     *
                     * }
                     * else
                     * {
                     *  if (isAttached)
                     *  {
                     *      //V1
                     *      Debug.Log("current cs");
                     *      other.transform.SetParent(transform);
                     *      currState = ConnectionSystem.State.connected;
                     *              gameObject.layer = 8;
                     *              rb.velocity = Vector3.zero;
                     *              rb.angularVelocity = Vector3.zero;
                     *              rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePosition;
                     *
                     *      //V2
                     *      transform.parent.SetParent(other.transform.parent);
                     *      GM.gm.SetMass(GM.gm.GetMassWithChildren());
                     *      GM.gm.RefreshLargestRadius();
                     *      if (click != null)
                     *      {
                     *          click.Play();
                     *      }
                     *  }
                     * }
                     *      /*if (otherCS.isAttached)
                     *      {
                     *              Debug.Log("firing off " + other.gameObject);
                     *
                     *
                     *              other.transform.gameObject.GetComponent<Rigidbody>().angularVelocity = new Vector3(0, 0, 0);
                     *              other.transform.gameObject.GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0);
                     *              other.transform.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                     *              transform.SetParent(other.transform);
                     *              GM.gm.SetMass(GM.gm.GetMassWithChildren());
                     *              GM.gm.RefreshLargestRadius();
                     *
                     *              sleep = true;
                     *              randomObj = other.transform.gameObject.GetComponent<Rigidbody>();
                     *              currState = ConnectionSystem.State.connected;
                     *              gameObject.layer = 8;
                     *              rb.velocity = Vector3.zero;
                     *              rb.angularVelocity = Vector3.zero;
                     *              rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePosition;
                     *
                     *
                     *      }*/
                    if (other.tag == "connected")
                    {
                        transform.SetParent(other.transform);
                        isAttached         = true;
                        currState          = ConnectionSystem.State.connected;
                        gameObject.layer   = 8;
                        other.tag          = "connected";
                        rb.velocity        = Vector3.zero;
                        rb.angularVelocity = Vector3.zero;
                        rb.constraints     = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePosition;
                    }
                }
                currState          = ConnectionSystem.State.connected;
                gameObject.layer   = 8;
                rb.velocity        = Vector3.zero;
                rb.angularVelocity = Vector3.zero;
                rb.constraints     = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePosition;
                if (other.tag == "Player")
                {
                    other.gameObject.GetComponent <WeaponSystem>().addnewWeapon(GetComponent <WeaponLogic>());
                }
                else
                {
                }
                //other.gameObject.GetComponentInParent<WeaponSystem>().addnewWeapon(GetComponent<WeaponLogic>());
            }
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// Action to disconnect the client from the server.
 /// </summary>
 public void DisconnectClient()
 {
     ConnectionSystem.DisconnectFromServer();
 }
Exemplo n.º 7
0
 // Use this for initialization
 void Awake()
 {
     rb = GetComponent <Rigidbody>();
     cs = gameObject.GetComponent <ConnectionSystem>();
 }
Exemplo n.º 8
0
 // Start is called before the first frame update
 void Start()
 {
     rb     = GetComponent <Rigidbody>();
     cs     = GetComponent <ConnectionSystem>();
     height = transform.position.y;
 }