Пример #1
0
    // Use this for initialization
    void Start()
    {
        // if don't exist an instance of this class
        if (instance == null)
        {
            //it doesn't destroy the object, if other scene be loaded
            DontDestroyOnLoad(this.gameObject);

            instance = this;            // define the class as a static variable

            udpClient = gameObject.GetComponent <UDPClientComponent>();

            int randomPort = UnityEngine.Random.Range(3001, 3310);



            //find any  server in others hosts
            ConnectToUDPServer(serverPort, randomPort);

            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());

            string address = string.Empty;

            string subAddress = string.Empty;

            _localAddresses = new List <string>();
        }
        else
        {
            //it destroys the class if already other class exists
            Destroy(this.gameObject);
        }
    }
Пример #2
0
 private void Start()
 {
     if (instance == null)
     {
         DontDestroyOnLoad(gameObject);
         instance  = this;
         udpClient = gameObject.GetComponent <UDPClientComponent>();
     }
     else
     {
         Destroy(gameObject);
     }
 }
    private void Start()
    {
        if (instance == null)
        {
            DontDestroyOnLoad(this.gameObject);
            instance  = this;
            udpClient = gameObject.GetComponent <UDPClientComponent>();

            ConnectToUDPServer();
        }
        else
        {
            //一个客户端只需要一个交互类
            Destroy(this.gameObject);
        }
    }
Пример #4
0
        // Use this for initialization
        void Start()
        {
            // if don't exist an instance of this class
            if (instance == null)
            {
                //it doesn't destroy the object, if other scene be loaded
                DontDestroyOnLoad(this.gameObject);

                instance = this;                // define the class as a static variable

                udpClient = gameObject.GetComponent <UDPClientComponent>();
            }
            else
            {
                //it destroys the class if already other class exists
                Destroy(this.gameObject);
            }
        }
    // Use this for initialization
    void Start()
    {
        Debug.Log("TicTacNetworkManager_start() 网络传输控制类,负责与服务器交互");
        //创建单例类
        // if don't exist an instance of this class
        if (instance == null)
        {
            //it doesn't destroy the object, if other scene be loaded
            DontDestroyOnLoad(this.gameObject);

            instance = this;// define the class as a static variable

            udpClient = gameObject.GetComponent <UDPClientComponent>();

            //find any  server in others hosts
            //寻找服务器执行相对ui方法
            ConnectToUDPServer();
        }
        else
        {
            //it destroys the class if already other class exists
            Destroy(this.gameObject);
        }
    }