コード例 #1
0
    public void GetMyRoom(CallFuncInfo f)
    {
        Debug.Log("[GetMyRoom execute]: " + f);
        var roomInfo = f.Param[0].Unpack <RoomInfo> ();

        Debug.Log(roomInfo);
    }
コード例 #2
0
    public void Health(CallFuncInfo f)
    {
        Debug.Log("[Health execute]" + f);
        var entity = IdMapEntityManager[f.TargetId];

        entity.HealthQ.Enqueue(f.Value);
    }
コード例 #3
0
    public void EnterRoom(CallFuncInfo f)
    {
        Debug.Log("[EnterRoom execute]: " + f);
        var roomInfo = f.Param [0].Unpack <RoomInfo> ();

        selectRoomCanvas.Enter(roomInfo);
    }
コード例 #4
0
    /// <summary>
    /// Adds the out func queue.
    /// </summary>
    /// <returns>The out func queue.</returns>
    /// <param name="f">F.</param>
    public Task AddOutFuncQueue(CallFuncInfo f)
    {
        var T = Task.Run(async() => {
            OutFuncQueue.Enqueue(f);
        });

        return(T);
    }
コード例 #5
0
    public void AddRoomInfo(CallFuncInfo f)
    {
        Debug.Log("[AddRoomInfo execute]: " + f);
        var roomInfo = f.Param [0].Unpack <RoomInfo> ();

        Debug.Log(roomInfo);
        selectRoomCanvas.addRoomQueue.Enqueue(roomInfo);
    }
コード例 #6
0
    public void CallMathod(CallFuncInfo fInfo)
    {
        System.Type type = this.GetType();
        MethodInfo  f    = type.GetMethod(fInfo.Func);

        object[] param = new object[] { fInfo };
        f.Invoke(this, param);
    }
コード例 #7
0
    public void DestroyEntity(CallFuncInfo f)
    {
        EntityManager entity;

        if (IdMapEntityManager.TryGetValue(f.TargetId, out entity))
        {
            Debug.Log("[DestroyEntity execute]:" + f);
            entity.Destroy();
        }
    }
コード例 #8
0
 public void GetAllRoomInfo(CallFuncInfo f)
 {
     Debug.Log("[GetMyRoom execute]: " + f);
     foreach (var param in f.Param)
     {
         var roomInfo = param.Unpack <RoomInfo> ();
         Debug.Log("[Get Room]" + roomInfo);
         selectRoomCanvas.addRoomQueue.Enqueue(roomInfo);
     }
 }
コード例 #9
0
    public void Calibrate(CallFuncInfo f)
    {
        var ToServerTime = f.FromId - f.TargetId;
        var ToClientTime = util.GetTimeStamp() - f.TimeStamp;
        var timeOffset   = (ToClientTime - ToServerTime) / 2;

        util.TimeOffset = (Int64)(timeOffset);
        var delay = (ToClientTime + ToServerTime);

        Debug.Log("Calibrate offset: " + util.TimeOffset + " ms, Delay: " + delay + " ms");
    }
コード例 #10
0
    void createEntityManager()
    {
        var f = new CallFuncInfo();

        if (CreateEntityManagerQueue.TryDequeue(out f))
        {
            var t_entityInfo = f.Param [0].Unpack <Character> ();
            var t            = util.PraseTransform(f.FromPos);
            switch (t_entityInfo.CharacterType)
            {
            case "Shell":
                var shell_Instance = Instantiate(m_entityPrefab["Shell"], t.Item1, t.Item2) as GameObject;
                var shell          = new EntityManager(t_entityInfo, shell_Instance, shell_Instance.GetComponent <ShellMovement>());
                IdMapEntityManager.Add(t_entityInfo.Uuid, shell);
                break;

            case "Player":
                var player_Instance = Instantiate(m_entityPrefab["Tank"], t.Item1, t.Item2) as GameObject;

                var player = new EntityManager(t_entityInfo, player_Instance, player_Instance.GetComponent <TankMovement>());
                player.SetPlayer(player_Instance.GetComponent <TankMovement>());
                foreach (KeyValuePair <long, Character> item in m_UserInfo.OwnCharacter)
                {
                    if (item.Key == t_entityInfo.Uuid)
                    {
                        player.SetMainPlayer();
                        mainPlayer      = player;
                        IsPlayerCreated = true;
                        Client.SyncPos(m_UserInfo.Uuid);
                        m_CameraControl.centerTarget = player.m_Instance.transform;
                        break;
                    }
                }
                m_Players.Add(player);
                IdMapEntityManager.Add(t_entityInfo.Uuid, player);
                break;

            case "Enemy":
                var enemy_Instance = Instantiate(m_entityPrefab["Tank"], t.Item1, t.Item2) as GameObject;
                var enemy          = new EntityManager(t_entityInfo, enemy_Instance, enemy_Instance.GetComponent <TankMovement>());
                enemy.SetPlayer(enemy_Instance.GetComponent <TankMovement>());
                m_Players.Add(enemy);
                IdMapEntityManager.Add(t_entityInfo.Uuid, enemy);
                break;

            default:
                Debug.Log("No such entity type " + t_entityInfo.CharacterType);
                break;
            }
        }
    }
コード例 #11
0
ファイル: RoomManager.cs プロジェクト: mengtest/Tank-Online
    void createRoom()
    {
        var          name = RoomName.text;
        CallFuncInfo f    = new CallFuncInfo();

        f.FromId = Gm.m_UserInfo.Uuid;
        f.Func   = "CreateNewRoom";

        var roomInfo = new RoomInfo();

        roomInfo.Name     = name;
        roomInfo.GameType = "room";
        f.Param.Add(Any.Pack(roomInfo));
        Gm.OutFuncQueue.Enqueue(f);
    }
コード例 #12
0
    public async Task <CallFuncInfo> GetOutCallFunc()
    {
        var  f    = new CallFuncInfo();
        bool getf = false;

        while (!getf)
        {
            if (OutFuncQueue.TryDequeue(out f))
            {
                getf = true;
            }
            await Task.Delay(1);
        }
        return(f);
    }
コード例 #13
0
    void ReviewRoomInfo(RoomInfo roomInfo)
    {
        RoomInfoText.text = "Room Name: " + roomInfo.Name +
                            "\nRoom ID: " + roomInfo.Uuid.ToString() +
                            "\nOwner ID: " + roomInfo.OwnerUuid.ToString() + "\n Users In Room :\n";
        foreach (KeyValuePair <long, UserInfo> u in roomInfo.UserInRoom)
        {
            RoomInfoText.text += "\t[" + u.Key.ToString() + "]" + u.Value.UserName;
        }
        CallFuncInfo f = new CallFuncInfo {
            Func = "RoomReady", FromId = Gm.m_UserInfo.Uuid, TargetId = roomInfo.Uuid
        };

        ReadyRoomButton.onClick.AddListener(() => {
            Gm.AddOutFuncQueue(f);
        });
    }
コード例 #14
0
	public async void CallClient(Int64 userId){
		
		using (var call = client.CallMethod ()) {
			// Recevice
			var CallRecvTask = Task.Run (async () => {
				while (!rpcStopSignal.Token.IsCancellationRequested && await call.ResponseStream.MoveNext ()) {
					CallFuncInfo f = call.ResponseStream.Current;
					unity.Debug.Log (f);
					Gm.CallMathod (f);
				}
			});
			//Send

			CallFuncInfo start = new CallFuncInfo{ FromId = userId};
			await call.RequestStream.WriteAsync (start);
            CallFuncInfo cali = new CallFuncInfo { FromId = userId, TimeStamp = util.GetTimeStamp(), Func = "Calibrate" };
            await call.RequestStream.WriteAsync(cali);
            while (!rpcStopSignal.Token.IsCancellationRequested) {
				CallFuncInfo f = new CallFuncInfo();
				if (Gm.OutFuncQueue.TryPeek(out f)){
					unity.Debug.Log (f);
                    try
                    {
                        call.RequestStream.WriteAsync(f);
                        Gm.OutFuncQueue.TryDequeue(out f);
                    }
					catch (InvalidOperationException e)
                    {
                        unity.Debug.Log("CallMathod,"+f+","+e);
                    }
				}
                await Task.Delay(1);
            }

            await call.RequestStream.CompleteAsync ();
			await CallRecvTask;
			unity.Debug.Log ("callMethod(); exit");
		}
	}
コード例 #15
0
ファイル: SelectRoom.cs プロジェクト: mengtest/Tank-Online
    void ReviewRoomInfo(RoomInfo roomInfo)
    {
        Debug.Log(roomInfo);
        state             = 1;
        RoomInfoText.text = "Room Name: " + roomInfo.Name +
                            "\nRoom ID: " + roomInfo.Uuid.ToString() +
                            "\nOwner ID: " + roomInfo.OwnerUuid.ToString() + "\nUsers In Room :\n";
        foreach (KeyValuePair <long, UserInfo> u in roomInfo.UserInRoom)
        {
            RoomInfoText.text += "\t[" + u.Key.ToString() + "]" + u.Value.UserName;
        }

        EnterRoomButton.onClick.RemoveListener(EnterRoomAction);
        LeaveRoomButton.onClick.RemoveListener(LeaveRoomAction);
        ReadyRoomButton.onClick.RemoveListener(ReadyRoomAction);
        EnterRoomButton.interactable = true;
        LeaveRoomAction = () => {
            CallFuncInfo f = new CallFuncInfo {
                Func = "LeaveRoom", TargetId = roomInfo.Uuid, FromId = Gm.m_UserInfo.Uuid
            };
            Gm.AddOutFuncQueue(f);
        };
        EnterRoomAction = () => {
            CallFuncInfo f = new CallFuncInfo {
                Func = "EnterRoom", TargetId = roomInfo.Uuid, FromId = Gm.m_UserInfo.Uuid
            };
            Gm.AddOutFuncQueue(f);
        };
        ReadyRoomAction = () => {
            CallFuncInfo f = new CallFuncInfo {
                Func = "ReadyRoom", TargetId = roomInfo.Uuid, FromId = Gm.m_UserInfo.Uuid
            };
            Gm.AddOutFuncQueue(f);
        };
        EnterRoomButton.onClick.AddListener(EnterRoomAction);
        LeaveRoomButton.onClick.AddListener(LeaveRoomAction);
        ReadyRoomButton.onClick.AddListener(ReadyRoomAction);
    }
コード例 #16
0
 public void CreateShell(CallFuncInfo f)
 {
     Debug.Log("[CreateShell execute]: " + f);
     CreateEntityManagerQueue.Enqueue(f);
 }
コード例 #17
0
 public void StartRoom(CallFuncInfo f)
 {
     Debug.Log("[StartRoom execute]: " + f);
     IsRoomStart = true;
 }
コード例 #18
0
 public void LeaveRoom(CallFuncInfo f)
 {
     Debug.Log("[LeaveRoom execute]: " + f);
     selectRoomCanvas.Leave(f.TargetId);
 }
コード例 #19
0
 public void AddInFuncQueue(CallFuncInfo f)
 {
 }
コード例 #20
0
    public CallFuncInfo GetInCallFunc()
    {
        var f = new CallFuncInfo();

        return(f);
    }