/// <summary> /// Initializes a new instance of <see cref="GameplayMPHost"/> with specified size of map and /// <see cref="TcpClient"/> to use for communication with client. /// </summary> /// <param name="mapSize">Size of the map to play with.</param> /// <param name="client"><see cref="TcpClient"/> to use for communication with client.</param> public GameplayMPHost(Size mapSize, TcpClient client) : base(mapSize, Mark.Cross) { NetPlayer remote = new NetPlayer(); connection = new Connection(client); controller = new HostController(mapSize, connection, 10) { SyncConext = SynchronizationContext.Current }; controller.AddPlayers(new User(), remote); HostTimer timing = controller.Timing as HostTimer; connection.DataProcessor.RegisterProcessingUnit(NetPlayer.MarkCode, remote); connection.DataProcessor.RegisterProcessingUnit(NetPlayer.QuitCode, remote); connection.DataProcessor.RegisterProcessingUnit(ClientTimer.TimeCode, timing); connection.DataProcessor.RegisterProcessingUnit(ClientTimer.TimePassedCode, timing); controller.Timing.Tick += (sender, e) => { TimeSpan time = TimeSpan.FromSeconds(controller.Timing.TimeLeft); connection.SendInformation(ClientTimer.TimeCode, time.ToString()); }; controller.Timing.TimePassed += (sender, e) => { connection.SendInformation(ClientTimer.TimePassedCode, null); }; controller.State.CurrentChanged += (sender, e) => { MainWindow.BeginInvoke(new MethodInvoker(() => { controller.Timing.Restart(); })); }; }
// Use this for initialization public void Start() { if (!isLocalPlayer) { //自分以外のプレイヤーの当たり判定をoff GetComponent <BoxCollider>().enabled = false; smog.Stop(); //Skyテクスチャオフ foreach (Transform child in this.transform) { if (child.name == "Sky") { child.gameObject.SetActive(false); } } //名前の変更 this.name = ("vsPlayer"); return; } //スタートとゴールのUI取得 startUi = GameObject.Find("Main Camera/startUI"); startRenderer = startUi.GetComponent <Renderer>(); goalUi = GameObject.Find("Main Camera/goalUi"); goalUi.GetComponent <Renderer>().enabled = false; resultTimer = 0; Distance = 0.0f; Player2 = null; rank = 1; //ネットワーク上では、プレイヤーが生成されてからステージを作ったりするため。色々設定~。 //名前の変更 this.name = ("player"); //ネットワークマネージャーに自分を教える GameObject.Find("NetworkManager").GetComponent <NetworkManagerScript>().SetPlayer(this.gameObject); //ネットワーク上で管理するタイマーを取得 Timer = GameObject.Find("HostTimer"); hostTimerScript = Timer.GetComponent <HostTimer>(); hostTimerScript.Start(); velocity = Vector3.zero; time = 0; state = PLAYER_STATE.STOP; bJump = false; bDoubleJump = false; bHitWall = false; //スピードUI speedText = GameObject.Find("Canvas/Speed").GetComponent <Text>(); speedText.text = "Speed: 0"; //ランクUI rankText = GameObject.Find("Canvas/Rank").GetComponent <Text>(); //カメラの更新 camera = GameObject.Find("Main Camera"); camera.GetComponent <cameraController>().SetCamera(); //ぷにコンの長さを取得するため、コントローラーマネージャ取得 Scr_ControllerManager = GameObject.Find("PuniconCamera/ControllerManager"); //ステージ生成。 MapLorder mapLorderScript = GameObject.Find("StageEditor").GetComponent <MapLorder>(); mapLorderScript.SetNetworkPlayer(this.gameObject); //スタート位置に戻す処理などを考えてここで再度配置しておく。 transform.position = GetComponent <playerSetting>().GetStartPos(); //スコアの取得 Score = GameObject.Find("ScoreManager"); //ボタンに自分自身のジャンプを割り当てる。 GameObject jumpButton = GameObject.Find("Canvas/JumpButton"); //ボタンに直接割り当てる場合。(イベントトリガーに設定したらいらなくなった。) /*Button button = jumpButton.gameObject.GetComponent<Button>(); * button.onClick.RemoveAllListeners(); * button.onClick.AddListener( () => playerJump(true) );*/ //エフェクト smog.Stop(); anim = GetComponent <Animator>(); anim.speed = 1.0f; //SE seSource = GameObject.Find("SEManager").GetComponent <AudioSource>(); se = GameObject.Find("SEManager").GetComponent <SEManager>(); if (!bAddBotton) { //ボタン登録 //ボタンのイベントトリガーに割当 EventTrigger currentTrigger = jumpButton.AddComponent <EventTrigger>(); currentTrigger.triggers = new List <EventTrigger.Entry>(); //↑ここでAddComponentしているので一応、初期化しています。 EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerDown; //PointerClickの部分は追加したいEventによって変更してね entry.callback.AddListener((x) => playerJump(true)); //ラムダ式の右側は追加するメソッドです。 currentTrigger.triggers.Add(entry); bAddBotton = true; } }