public LDTimeLine RequestTimeLine() { LDTimeLine timeline = new LDTimeLine(); try { // Create a TcpClient. TcpClient client = new TcpClient(ipAdress, port); // Send request message to server byte[] data = System.Text.Encoding.ASCII.GetBytes("Get me TimeLine"); NetworkStream stream = client.GetStream(); stream.Write(data, 0, data.Length); Debug.Log("Sent: request"); // Receive the TcpServer.response. // Read the first batch of the TcpServer response bytes. int bytes = stream.Read(buffer, 0, buffer.Length); mem.Seek(0, SeekOrigin.Begin); mem.Write(buffer, 0, bytes); mem.Seek(0, SeekOrigin.Begin); timeline = WritableSystem.Read <LDTimeLine>(mem); // Close everything. stream.Close(); client.Close(); } catch (ArgumentNullException e) { Debug.Log($"ArgumentNullException: {e}"); } catch (SocketException e) { Debug.Log($"SocketException: {e}"); } return(timeline); }
private void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(this); } else { Destroy(gameObject); return; } LDConversionTable LDConversionTable = LDConversionTable.Load(); m_DeathInputFrame = new LDInputFrame { action = LDConversionTable.GameplayTagToLDID(TypeTag.DeathAction), cell = 0 }; m_ServerTimeLine = new Server().RequestTimeLine(); if (m_ServerTimeLine.timeLine == null || m_ServerTimeLine.timeLine.Length <= 0) { m_ServerTimeLine.timeLine = new LDBlock[0]; m_BranchingIndex = 0; m_CurrentBlock.mods = new LDAttribute[0]; m_CurrentBlock.branches = new int[0]; m_CurrentBlock.characters = new LDCharacter[3]; m_CurrentBlock.characters[0].role = (byte)CharacterRole.Assassin; m_CurrentBlock.characters[0].timeLine = new LDInputFrame[1]; m_CurrentBlock.characters[0].timeLine[0] = m_DeathInputFrame; m_CurrentBlock.characters[0].name = "Ezio"; m_CurrentBlock.characters[0].attributes = new LDAttribute[0]; m_CurrentBlock.characters[1].role = (byte)CharacterRole.Barbarian; m_CurrentBlock.characters[1].timeLine = new LDInputFrame[1]; m_CurrentBlock.characters[1].timeLine[0] = m_DeathInputFrame; m_CurrentBlock.characters[1].name = "Barb"; m_CurrentBlock.characters[1].attributes = new LDAttribute[0]; m_CurrentBlock.characters[2].role = (byte)CharacterRole.Necromancer; m_CurrentBlock.characters[2].timeLine = new LDInputFrame[1]; m_CurrentBlock.characters[2].timeLine[0] = m_DeathInputFrame; m_CurrentBlock.characters[2].name = "Bob"; m_CurrentBlock.characters[2].attributes = new LDAttribute[0]; } else { m_CurrentBlock = m_ServerTimeLine.timeLine[0]; } }