Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements a unity sample app which can be controlled using webbrowser client #552

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions unity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/

# Never ignore Asset meta data
![Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# [Aa]ssets/AssetStoreTools*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties
70 changes: 70 additions & 0 deletions unity/Example1/Assets/Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;

using WebSocketSharp;
using WebSocketSharp.Server;

public static class GlobalVariables
{
public static float azimuth = 0;
public static float elevation = 0;
public static float zoom = 1;
}

public class Example1 : WebSocketBehavior
{
// this is the data that we send using websockets (as JSON)
[Serializable]
public class WSData
{
public float az;
public float el;
public float z;
}

protected override void OnMessage(MessageEventArgs e)
{
WSData data = JsonUtility.FromJson<WSData>(e.Data);
GlobalVariables.azimuth = data.az / (float)Math.PI * 180;
GlobalVariables.elevation = data.el / (float)Math.PI * 180;
GlobalVariables.zoom = data.z;
}

protected override void OnOpen()
{
Debug.Log("connection opened");
}
}

public class Controller : MonoBehaviour
{
public string m_IP = "127.0.0.1";
public int m_port = 55555;
private WebSocketServer m_WSServer = null;

void Start()
{
string addr = "ws://" + m_IP + ":" + m_port.ToString();
Debug.Log("Run WS Server at: " + addr);
m_WSServer = new WebSocketServer(addr);
m_WSServer.AddWebSocketService<Example1>("/Example1");
m_WSServer.Start();
}

void OnDestroy()
{
Debug.Log("OnDestroy");
m_WSServer.Stop();
m_WSServer = null;
}

// Update is called once per frame
void Update()
{
gameObject.transform.eulerAngles = new Vector3(GlobalVariables.elevation, GlobalVariables.azimuth, gameObject.transform.eulerAngles.z);
gameObject.transform.localScale = new Vector3(GlobalVariables.zoom, GlobalVariables.zoom, GlobalVariables.zoom);
}
}
11 changes: 11 additions & 0 deletions unity/Example1/Assets/Controller.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 unity/Example1/Assets/Plugins.meta

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

Binary file not shown.
33 changes: 33 additions & 0 deletions unity/Example1/Assets/Plugins/websocket-sharp.dll.meta

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

8 changes: 8 additions & 0 deletions unity/Example1/Assets/Scenes.meta

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

Loading