Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (isAtStartup)
        {
            if (Input.GetKeyDown(KeyCode.S))
            {
                game      = new GameObject();
                game.name = "game";
                game.AddComponent <game>();
                channel s = game.AddComponent <channel>();
                game.AddComponent <server>();
                network n = game.GetComponent <network>();
                int     t = n.AddGameObjectToChannel(game, game.GetComponent <server>().GetFreeID());
                s.SetNetwork(n);
                s.SetChannel(t);
                game.GetComponent <game>().Init();
                game.GetComponent <game>().LoadShip("Prefabs/Ship1", "Ship");
                isAtStartup = false;
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                isClient  = true;
                game      = new GameObject();
                game.name = "game";
                game.AddComponent <game>();
                channel s = game.AddComponent <channel>();
                game.AddComponent <client>();
                network n = game.GetComponent <network>();
                int     t = n.AddGameObjectToChannel(game, 0);
                s.SetNetwork(n);
                s.SetChannel(t);
                game.GetComponent <game>().Init();
                game.GetComponent <client>().Connect(myserver);
                game.GetComponent <game>().LoadShip("Prefabs/Ship1", "Ship");
                isAtStartup      = false;
                Cursor.lockState = CursorLockMode.Locked;
            }
        }
    }
Beispiel #2
0
    public void LoadShip(string prefab_name, string object_name)
    {
        GameObject Ship = Instantiate(Resources.Load(prefab_name, typeof(GameObject)), this.gameObject.transform) as GameObject;
        channel    s    = Ship.GetComponent <channel>();

        Ship.GetComponent <puppet>().InitTransform(Ship.transform.localPosition, Ship.transform.localRotation);// rotation);
        network n      = GameObject.FindObjectOfType <network>();
        int     unikID = 1;

        if (!Channel.GetNetwork().IsClient())
        {
            unikID = GetComponent <server>().GetFreeID();
        }
        int t = n.AddGameObjectToChannel(Ship, unikID);

        s.SetNetwork(n);
        s.SetChannel(t);
        Channel.RegisterEntity(Ship, s.GetChannel());
        object_name += "_" + t;
        Ship.name    = object_name;
        Ship.GetComponent <ship>().Init(this.gameObject);
        ShipList[s.GetChannel()] = Ship;
    }
Beispiel #3
0
 void Awake()
 {
     string[] sys = System.Environment.GetCommandLineArgs();
     myserver = "localhost";
     foreach (string s in sys)
     {
         if (s == "-batchmode")
         {
             game      = new GameObject();
             game.name = "game";
             game.AddComponent <game>();
             channel ss = game.AddComponent <channel>();
             game.AddComponent <server>();
             network n = game.GetComponent <network>();
             int     t = n.AddGameObjectToChannel(game, game.GetComponent <server>().GetFreeID());
             ss.SetNetwork(n);
             ss.SetChannel(t);
             game.GetComponent <game>().Init();
             game.GetComponent <game>().LoadShip("Prefabs/Ship1", "Ship");
             isAtStartup = false;
             break;
         }
     }
 }