Verified Commit c57031ea authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

Building WebGLPlayer using Makefile

parent edb696b9
......@@ -130,8 +130,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 849675542}
- component: {fileID: 849675544}
- component: {fileID: 849675543}
- component: {fileID: 849675545}
m_Layer: 2
m_Name: CommunicationChannels
......@@ -154,35 +152,6 @@ Transform:
m_Father: {fileID: 1309245142}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &849675543
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 849675541}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4d23bc1d1dff4f6da09683d485b730c, type: 3}
m_Name:
m_EditorClassIdentifier:
sceneController: {fileID: 0}
address: ws://127.0.0.1:8392
restartOnError: 0
--- !u!114 &849675544
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 849675541}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 789360ba9f7a148faa3e44af5b17bb41, type: 3}
m_Name:
m_EditorClassIdentifier:
sceneController: {fileID: 0}
address: tcp://127.0.0.1:5559
--- !u!114 &849675545
MonoBehaviour:
m_ObjectHideFlags: 0
......
using UnityEngine;
using System.Collections;
using SimpleJSON;
using System.Text;
using HybridWebSocket;
namespace dlu
{
public class WebsocketCommunication : Communication
{
private WebSocket ws;
public string address = "ws://127.0.0.1:5000";
public bool restartOnError = true;
private bool workingOnRequest = false;
protected override void StartServer()
{
if (ws == null)
{
Debug.Log($"[WebSocket] Connecting to {address}");
ws = WebSocketFactory.CreateInstance(address);
ws.OnOpen += () =>
{
Debug.Log($"[WebSocket] Connected to {address}");
};
ws.OnMessage += ReceiveMessage;
ws.OnError += (string errMsg) =>
{
Debug.LogError("[WebSocket] error: " + errMsg);
};
ws.OnClose += (WebSocketCloseCode code) =>
{
Debug.Log($"[WebSocket] Disconnected from {address} (Reason: {code})");
ws = null;
};
ws.Connect();
}
}
void Update()
{
if (!workingOnRequest)
{
if (ws == null && restartOnError)
{
Debug.LogWarning("[WebSocket] Restarting WebSocket...");
StartServer();
}
}
}
void ReceiveMessage(byte[] msg)
{
workingOnRequest = true;
string request = Encoding.UTF8.GetString(msg);
Debug.Log($"[WebSocket] Received message:\n{request}");
JSONObject requestObject = JSON.Parse(request) as JSONObject;
HandleRequest(requestObject);
}
void OnDestroy()
{
if (ws != null)
{
try
{
ws.Close();
} catch (WebSocketInvalidStateException)
{
// Do nothing
}
ws = null;
}
}
public void Send(string message)
{
Debug.Log($"[WebSocket] Sending message:\n{message}");
ws.Send(Encoding.UTF8.GetBytes(message));
}
public override IEnumerator ReplyToRequest(JSONObject response, JSONObject originalRequest)
{
string responseString = base.ComposeReply(response, originalRequest);
Send(responseString);
yield return null;
workingOnRequest = false;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: f4d23bc1d1dff4f6da09683d485b730c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
using SimpleJSON;
using System;
using NetMQ;
using NetMQ.Sockets;
namespace dlu
{
public class ZMQServerCommunication : Communication
{
private ResponseSocket server;
public string address = "tcp://127.0.0.1:5559";
private bool workingOnRequest = false;
protected override void StartServer()
{
if (!address.StartsWith("@"))
{
address = "@" + address;
}
Debug.Log($"[ZMQServer] Listening to {address}");
server = new ResponseSocket(address);
server.ReceiveReady += ReceiveMessage;
}
void Update()
{
if (!workingOnRequest)
{
if (server == null)
{
Debug.LogWarning("[ZMQServer] Restarting server...");
StartServer();
}
server.Poll(TimeSpan.FromMilliseconds(100));
}
}
void ReceiveMessage(object sender, NetMQSocketEventArgs args)
{
workingOnRequest = true;
string request = server.ReceiveFrameString();
Debug.Log($"[ZMQServer] Received message:\n{request}");
JSONObject requestObject = JSON.Parse(request) as JSONObject;
HandleRequest(requestObject);
}
void OnDestroy()
{
if (server != null)
{
server.Close();
server = null;
}
}
public override IEnumerator ReplyToRequest(JSONObject response, JSONObject originalRequest)
{
string responseString = base.ComposeReply(response, originalRequest);
Debug.Log($"[ZMQServer] Sending message:\n{response}");
server.SendFrame(responseString);
yield return null;
workingOnRequest = false;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 789360ba9f7a148faa3e44af5b17bb41
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEditor;
using System;
[CustomEditor(typeof(WebGLBuilder))]
public class WebGLBuilderEditor : Editor {} // Fixes "Editor layout could not be fully loaded"
......@@ -8,12 +10,14 @@ public class WebGLBuilder {
// Place all your scenes here
string[] scenes = {
"Assets/Scenes/Controller.unity",
"Assets/Scenes/Kitchen.unity",
"Assets/Scenes/UI.unity",
"Assets/DLU/Scenes/Controller.unity",
"Assets/DLU/Scenes/Kitchen.unity",
"Assets/DLU/Scenes/UI.unity",
};
string outdir = "Build/PhysicsSimulator/";
string[] args = System.Environment.GetCommandLineArgs();
string outdir = $"{args[args.Length - 1]}/";
BuildPipeline.BuildPlayer(scenes, outdir, BuildTarget.WebGL, BuildOptions.None);
}
}
\ No newline at end of file
......@@ -2,28 +2,14 @@ NetMQ_VERSION=4.0.0.207
AsyncIO_VERSION=0.1.69
NUGET_DIRECTORY=NuGetPackages
UNITY=/Applications/Unity/Hub/Editor/2019.3.3f1/Unity.app/Contents/MacOS/Unity
UNITY_BATCH:=${UNITY} -batchmode -quit -noUpm -logFile - -projectPath $(CURDIR)
UNITY=/Applications/Unity/Hub/Editor/2019.4.13f1/Unity.app/Contents/MacOS/Unity
UNITY_BATCH:=${UNITY} -batchmode -quit -logFile - -projectPath $(CURDIR)
.PHONY: build
build: Build/physicssimulator.app
build: Build/PhysicsSimulator
Build/physicssimulator.app: | Build
-${UNITY_BATCH} -buildOSXUniversalPlayer $@
.PHONY: setup
setup: $(foreach P,AsyncIO NetMQ,Assets/Plugins/${P}.dll)
Assets/Plugins/NetMQ.dll: ${NUGET_DIRECTORY}/NetMQ.${NetMQ_VERSION}/lib/net40/NetMQ.dll
@mkdir -p ${@D}
cp $^ $@
Assets/Plugins/AsyncIO.dll: ${NUGET_DIRECTORY}/AsyncIO.${AsyncIO_VERSION}/lib/net40/AsyncIO.dll
@mkdir -p ${@D}
cp $^ $@
${NUGET_DIRECTORY}/NetMQ.${NetMQ_VERSION}/lib/net40/NetMQ.dll ${NUGET_DIRECTORY}/AsyncIO.${AsyncIO_VERSION}/lib/net40/AsyncIO.dll:
nuget install NetMQ -Version ${NetMQ_VERSION} -OutputDirectory ${NUGET_DIRECTORY}
Build/PhysicsSimulator: | Build
-${UNITY_BATCH} -executeMethod WebGLBuilder.BuildWebGL $@
Build:
@mkdir -p $@
\ No newline at end of file
@mkdir -p $@
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment