Skip to content

Commit

Permalink
Network things runnint prfectly, Build success
Browse files Browse the repository at this point in the history
  • Loading branch information
snlpatel001213 committed Nov 24, 2021
1 parent 9a332ff commit 2297da9
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 72 deletions.
18 changes: 18 additions & 0 deletions Assets/AirplanePhysics/Code/Editor/AC_Airplane_Menus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AC_Airplane_Menus : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
11 changes: 11 additions & 0 deletions Assets/AirplanePhysics/Code/Editor/AC_Airplane_Menus.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/AirplanePhysics/Code/Scripts/Controller.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AirControl
{
public class AC_Airplane_Controller : AC_BaseRigidbody_Controller
{
#region variables
public AC_BaseAirplane_Input input;
#endregion

#region Custom Methods
protected override void HandlePhysics()
{

}
#endregion
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AirControl
{
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(AudioSource))]
public class AC_BaseRigidbody_Controller : MonoBehaviour
{
#region Variable
private Rigidbody rb;
private AudioSource aSource;
#endregion

#region Builtin Methods
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
aSource = GetComponent<AudioSource>();
// Dont allow audio to play on start
if(aSource){
aSource.playOnAwake = false;
}
}

// Update is called once per frame
void FixedUpdate()
{
if(rb){
HandlePhysics();
}
}
#endregion

#region Custom Methods
protected virtual void HandlePhysics(){

}
#endregion
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
host, port = "127.0.0.1" , 8052
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host,port))
# for i in range(0,10):
# data = "0.22,{},{}".format(i*2,i*5)
# try:
for i in range(0,10):
data = '{"pitch":1.245,"roll":0.0,"yaw":5555,"throttle":0.0,"brake":0.0,"flaps":0}'
try:

# sock.sendall(data.encode("utf-8"))
# data = sock.recv(1024).decode("utf-8")
# print(data)
sock.sendall(data.encode("utf-8"))
data = sock.recv(1024).decode("utf-8")
print(data)

# except Exception as e:
# print(">>>>>>>>>>>>",e)
# time.sleep(5)
# sock.close()
except Exception as e:
print(">>>>>>>>>>>>",e)
time.sleep(5)
sock.close()

while(True):
data = sock.recv(1024).decode("utf-8")
print(data)
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ namespace AirControl
public class InputOutputHandel
{
#region Variables
public AC_BaseAirplane_Input currentReadings;
// public TCPTestServer networkUtils;

// Output Struct // struct to send msg out of unity
struct outputStructure
public struct outputStructure
{
public float pitch;
public float roll;
Expand All @@ -24,10 +23,16 @@ struct outputStructure
outputStructure outStruct;

// Input Struct // struct to receive msg to unity
struct inputStructure
public struct inputStructure
{

}
public float pitch;
public float roll;
public float yaw;
public float throttle;
public float brake;
public int flaps;
};
inputStructure inStruct;

#endregion

Expand All @@ -41,17 +46,21 @@ struct inputStructure

#region Custom Methods
// receive msg to unity
void InputHandel()
public void ParseInput(string receivedString)
{

//parse input
inputStructure inStructDeserialized = JsonConvert.DeserializeObject<inputStructure>(receivedString);
Debug.Log("received string : " + receivedString);
// call a fucntion to set this input to the rigid body
//pending
}

// send msg out of unity
public string Outputhandel()
public string ParseOutput(AC_BaseAirplane_Input currentReadings)
{
// Debug.Log("listening to controls : "+currentReadings.Pitch);
// Put data to structure

Debug.Log("listening to controls : "+currentReadings.Pitch);
outStruct.pitch = currentReadings.Pitch;
outStruct.roll = currentReadings.Roll;
outStruct.yaw = currentReadings.Yaw;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class TCPTestServer : MonoBehaviour
/// Create handle to connected tcp client.
/// </summary>
private TcpClient connectedTcpClient;
// provide base input to access variables
public AC_BaseAirplane_Input currentReadings;

private InputOutputHandel InOutManager = new InputOutputHandel();
#endregion
Expand All @@ -38,16 +40,6 @@ void Start () {
tcpListenerThread.IsBackground = true;
tcpListenerThread.Start();
}
#region Depricated
// Update is called once per frame
void Update () {
// if (Input.GetKeyDown(KeyCode.Space)) {

string outputmsg = InOutManager.Outputhandel();
SendMessage(outputmsg);
// }
}
#endregion
#endregion

#region Custom Methods
Expand All @@ -72,10 +64,11 @@ public void ListenForIncommingRequests () {
var incommingData = new byte[length];
Array.Copy(bytes, 0, incommingData, 0, length);
// Convert byte array to string message.
string clientMessage = Encoding.ASCII.GetString(incommingData);
Debug.Log("client message received as: " + clientMessage);
// send message in return
// SendMessage(String);
string clientMessage = Encoding.ASCII.GetString(incommingData);
InOutManager.ParseInput(clientMessage);
// once received the message, send message in return
string outputmsg = InOutManager.ParseOutput(currentReadings);
SendMessage(outputmsg);
}
}
}
Expand All @@ -93,7 +86,6 @@ public void ListenForIncommingRequests () {
if (connectedTcpClient == null) {
return;
}

try {
// Get a stream object for writing.
NetworkStream stream = connectedTcpClient.GetStream();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions Assets/AirplanePhysics/Prefabs/Airplanes/IndiePixel_Plane.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 544299066754510615}
- component: {fileID: 6357270310726759898}
m_Layer: 0
m_Name: IndiePixel_Plane
m_TagString: Untagged
Expand All @@ -2397,22 +2396,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!54 &6357270310726759898
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6357270310726759901}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1001 &4428820741641706452
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
Loading

0 comments on commit 2297da9

Please sign in to comment.