Beispiel #1
0
 private void Clean()
 {
     DisconnectPlayer(GetPlayerWithId(playerId));
     simIniTime  = 0;
     ownPlayer   = null;
     isConnected = false;
 }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        // 使用下面这句可以将该脚本附着的物体放入一个全局场景中,该场景不会因为场景载入而销毁
        GameObject.DontDestroyOnLoad(gameObject);

        // 找到网络管理器的引用
        NetworkManager = GameObject.Find("NetworkManager");

        // 找到提示信息管理器的引用
        HintMessageManager = GameObject.Find("HintMessageManager");

        ClientPlayerManager = GameObject.Find("ClientPlayerManager");

        MainClientPlayerController = ClientPlayerManager.GetComponent <ClientPlayerController>();

        // 向网络管理器注册自己的数据包处理函数
        NetworkManager.GetComponent <NetworkController>().ManagerRegistion("GameRoomController", MessageReceive);

        Debug.Log("Enter GameRoom successful.");
    }
Beispiel #3
0
    private void ConnectPlayer(int _playerId)
    {
        PlayerNetworkView player = GetPlayerWithId(_playerId);

        if (player != null)
        {
            DisconnectPlayer(player);
        }

        GameObject playerGO = Instantiate(playerPrefab) as GameObject;

        playerGO.name = PLAYER + " " + _playerId;
        player        = playerGO.GetComponent <PlayerNetworkView>();
        player.id     = _playerId;

        if (_playerId.Equals(playerId))
        {
            isConnected           = true;
            ownPlayer             = playerGO.AddComponent <ClientPlayerController>();
            ownPlayer.playerInput = new PlayerInput();
        }
        players.Add(player);
    }
 public void setOwnership()
 {
     cpc = (ClientPlayerController)tank.GetComponent (typeof(ClientPlayerController));
         n = cpc.getOwner ();
 }
 void setOwnership()
 {
     GameObject tank = transform.parent.parent.parent.FindChild ("NewTank").gameObject;
     cpc = (ClientPlayerController)tank.GetComponent (typeof(ClientPlayerController));
     netPlayer = cpc.getOwner ();
 }
Beispiel #6
0
    // Use this for initialization
    void Start()
    {
        // 获取位于网络管理器上的网络控制器
        //MainNetworkController = GameObject.Find("NetworkManager").GetComponent<NetworkController>();

        // 向网络管理器注册自己的数据包处理函数
        //MainNetworkController.ManagerRegistion("GameManager", MessageReceive);

        // 用于单场景开发时加载测试使用
        if (GameObject.Find("ClientPlayerManager") == null)
        {
            PlayerID           = 0;
            GameMapID          = "FreedomDay";
            FirstRoundPlayerID = 0;
        }
        else
        {
            MainClientPlayerController = GameObject.Find("ClientPlayerManager").GetComponent <ClientPlayerController>();
            PlayerID           = MainClientPlayerController.GetPlayerID();
            GameMapID          = MainClientPlayerController.GetGameMapID();
            FirstRoundPlayerID = MainClientPlayerController.GetFirstRoundPlayerID();
        }

        // 1. 生成所有游戏必要组件
        //===================================================================================================================
        MainLibraryManager = new LibraryManager(this);

        MainCardManager = new CardManager(this);

        MainResourceManager  = new ResourceManager(this);
        MainDiplomacyManager = new DiplomacyManager(this);
        MainRoundManager     = new RoundManager(this);


        MainEnvironmentManager = new EnvironmentManager(this);
        MainWorldManager       = new WorldManager(this);

        MainGameLoader = new GameLoader(this);

        MainInitialHandCardManager = new InitialHandCardManager(this);

        GameObject CardDisplayManagerPrefab = (GameObject)Resources.Load("Prefabs/Manager/GamePlay/CardDisplayManager");

        CardDisplayManager        = GameObject.Instantiate(CardDisplayManagerPrefab);
        CardDisplayManager.name   = "CardDisplayManager";
        MainCardDisplayController = CardDisplayManager.GetComponent <CardDisplayController>();
        MainCardDisplayController.Initialize(this);

        GameObject InputManagerPrefab = (GameObject)Resources.Load("Prefabs/Manager/GamePlay/InputManager");

        InputManager        = GameObject.Instantiate(InputManagerPrefab);
        InputManager.name   = "InputManager";
        MainInputController = InputManager.GetComponent <InputController>();
        MainInputController.SetCurrentPlayerID(PlayerID);
        MainInputController.Initialize(this);

        GameObject MessageManagerPrefab = (GameObject)Resources.Load("Prefabs/Manager/GamePlay/MassageManager");

        MessageManager        = GameObject.Instantiate(MessageManagerPrefab);
        MessageManager.name   = "MessageManager";
        MainMessageController = MessageManager.GetComponent <MessageController>();
        MainMessageController.Initialize(this);


        GameObject UIManagerPrefab = (GameObject)Resources.Load("Prefabs/Manager/GamePlay/UIManager");

        UIManager        = GameObject.Instantiate(UIManagerPrefab);
        UIManager.name   = "UIManager";
        MainUIController = UIManager.GetComponent <UIController>();
        MainUIController.Initialize(this);

        //2. 将游戏组件中的refernece建立
        //===================================================================================================================

        MainLibraryManager.EstablishReference();
        MainCardManager.EstablishReference();
        MainResourceManager.EstablishReference();
        MainDiplomacyManager.EstablishReference();
        MainRoundManager.EstablishReference();
        MainEnvironmentManager.EstablishReference();
        MainWorldManager.EstablishReference();
        MainGameLoader.EstablishReference();
        MainInitialHandCardManager.EstablishReference();

        MainCardDisplayController.EstablishReference();
        MainInputController.EstablishReference();
        MainMessageController.EstablishReference();
        MainUIController.EstablishReference();

        // 参数设置
        //===================================================================================================================

        MainRoundManager.SetCurrentRoundPlayerID(FirstRoundPlayerID);
        MainGameLoader.SetGameMapID(GameMapID);

        //===================================================================================================================
        MainLibraryManager.LoadGameDataFromXML();

        MainGameLoader.LoadGame();



        // 生成发送信息
        string SendMessage = "";

        // 通知网络管理器发送信息
        //CurrentMessageToBeSent = MainNetworkController.AddMessageInSendList(SendMessage);



        MainInitialHandCardManager.GenerateInitialHandCard(3);
    }