Пример #1
0
 private void Connect()
 {
     try
     {
         IPEndPoint ipPoint = null;
         try
         {
             ipPoint = new IPEndPoint(IPAddress.Parse(textBox1.Text), port);
         }
         catch (Exception ex)
         {
             MessageBox.Show("Connection error. Wrong IP address\n" + ex.Message);
         }
         if (ipPoint != null)
         {
             CClientSocket socket = new CClientSocket();
             CPool         cPool  = new CPool(socket);
             cPool.Init(ipPoint);
             cPool.Send(textBoxString.Text);
             richTextBox1.AppendText(cPool.ProcessRead() + "\n");
         }
     }
     catch (Exception ex)
     {
         richTextBox1.AppendText("Communication error" + ex.Message + "\n");
     }
 }
Пример #2
0
        void Connect()
        {
            int port = 8005;

            Log("Getting machine name...");
            string host = Dns.GetHostName();

            Log("Machine name " + host);

            Log("Getting ip-address... ");
            IPAddress IP = Dns.GetHostAddresses(host)[1];

            Log("IP addresses: " + IP.ToString());

            Log("Getting address for starting socket...");
            IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(IP.ToString()), port);

            Log("Address: " + ipPoint);

            var listenSocket = new CListeningSocket();

            try
            {
                CPool cPool = new CPool(listenSocket);
                listenSocket.Bind(ipPoint);
                listenSocket.Listen(10);

                label2.Invoke(new Action(() => { label2.Text = "Server has been started"; }));
                Log(IP.ToString() + "Server started. Waiting for client connection...");

                while (true)
                {
                    var res = cPool.ProcessAccept();
                    Log($"Received message: {res.StringResult}");

                    //Sending to client
                    cPool.Send($"We received message {res.StringResult} from you. You are very COOOOl", res.handler);
                    cPool.ProcessClose(res.Item2);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
    // ------------------------------
    void Awake()
    {
        // Too hardcoded for my taste, but it's what comes to mind:
        if(this.tag == "enemy"){
            bp = GameObject.FindGameObjectWithTag("enemyPool").GetComponent<CPool>();
        }
        else if(this.tag == "user"){
            bp = GameObject.FindGameObjectWithTag("userPool").GetComponent<CPool>();
        }

        if(goesUp){
            dir = this.transform.up;
        }
        else{
            dir = this.transform.up * -1;
        }
        dir.z = 0.0f;
        dir.Normalize();
    }
Пример #4
0
    /// <summary>
    /// Called by each Pool on its own, this adds it to the dictionary.
    /// </summary>
    public static void Add(CPool pool)
    {
        //check if the Pool does not contain a prefab
        if (pool.prefab == null)
        {
            Debug.LogError("Prefab of pool: " + pool.gameObject.name + " is empty! Can't add pool to Pools Dictionary.");
            return;
        }

        //check if the Pool has been added already
        if (Pools.ContainsKey(pool.prefab))
        {
            Debug.LogError("Pool with prefab " + pool.prefab.name + " has already been added to Pools Dictionary.");
            return;
        }

        //add it to dictionary
        Pools.Add(pool.prefab, pool);
    }
Пример #5
0
    /// <summary>
    /// Creates a new Pool at runtime. This is being called for prefabs which have not been linked
    /// to a Pool in the scene in the editor, but are called via Spawn() nonetheless.
    /// </summary>
    public static void CreatePool(GameObject prefab, int preLoad, bool limit, int maxCount)
    {
        //debug error if pool was already added before
        if (Pools.ContainsKey(prefab))
        {
            Debug.LogError("Pool Manager already contains Pool for prefab: " + prefab.name);
            return;
        }

        //create new gameobject which will hold the new Pool component
        GameObject newPoolGO = new GameObject("Pool " + prefab.name);
        //add Pool component to the new gameobject in the scene
        CPool newPool = newPoolGO.AddComponent <CPool>();

        //assign default parameters
        newPool.prefab   = prefab;
        newPool.preLoad  = preLoad;
        newPool.limit    = limit;
        newPool.maxCount = maxCount;
        //let it initialize itself after assigning variables
        newPool.Awake();
    }
Пример #6
0
    // ------------------------------

    void Awake()
    {
        // Too hardcoded for my taste, but it's what comes to mind:
        if (this.tag == "enemy")
        {
            bp = GameObject.FindGameObjectWithTag("enemyPool").GetComponent <CPool>();
        }
        else if (this.tag == "user")
        {
            bp = GameObject.FindGameObjectWithTag("userPool").GetComponent <CPool>();
        }

        if (goesUp)
        {
            dir = this.transform.up;
        }
        else
        {
            dir = this.transform.up * -1;
        }
        dir.z = 0.0f;
        dir.Normalize();
    }