Skip to content

Commit

Permalink
Scriptable Object で設定項目を管理 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarukosu authored Nov 12, 2020
1 parent 4e60972 commit 5327578
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1318,18 +1318,29 @@ PrefabInstance:
- target: {fileID: 1653683205836488025, guid: d4331a52f91fbd64ebb9a5e50b6b9fa1,
type: 3}
propertyPath: signalingKey
value:
value: snf2QsAkNlib1tohto42kEilqlMExptlDvUpQv7XsKFClKZY
objectReference: {fileID: 0}
- target: {fileID: 1653683205836488025, guid: d4331a52f91fbd64ebb9a5e50b6b9fa1,
type: 3}
propertyPath: roomId
value:
value: tarukosu@a
objectReference: {fileID: 0}
- target: {fileID: 1653683205836488025, guid: d4331a52f91fbd64ebb9a5e50b6b9fa1,
type: 3}
propertyPath: printDebugLog
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1653683205836488025, guid: d4331a52f91fbd64ebb9a5e50b6b9fa1,
type: 3}
propertyPath: serverUrl
value: wss://ayame-labo.shiguredo.jp/signaling
objectReference: {fileID: 0}
- target: {fileID: 1653683205836488025, guid: d4331a52f91fbd64ebb9a5e50b6b9fa1,
type: 3}
propertyPath: connectionSettings
value:
objectReference: {fileID: 11400000, guid: 3e04ff4efab5c0f4abdc799bd6753ff8,
type: 2}
- target: {fileID: 1653683205836488026, guid: d4331a52f91fbd64ebb9a5e50b6b9fa1,
type: 3}
propertyPath: m_Name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using UnityEngine;

namespace Microsoft.MixedReality.WebRTC.Unity.ThirdParty.Ayame
{
public class AyameConnectionSettings : ScriptableObject, ISerializationCallbackReceiver
{
[SerializeField]
private string serverUrl;

[NonSerialized]
public string ServerUrl;

[SerializeField]
private string signalingKey;

[NonSerialized]
public string SignalingKey;

[SerializeField]
private string roomId;

[NonSerialized]
public string RoomId;

[SerializeField]
private bool autoConnection = false;

[NonSerialized]
public bool AutoConnection;


public void OnAfterDeserialize()
{
ServerUrl = serverUrl;
SignalingKey = signalingKey;
RoomId = roomId;
AutoConnection = autoConnection;
}

public void OnBeforeSerialize() { }
}
}

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 @@ -16,49 +16,30 @@ namespace Microsoft.MixedReality.WebRTC.Unity.ThirdParty.Ayame
public class AyameSignaler : Signaler
{
[SerializeField]
string serverUrl = "wss://ayame-lite.shiguredo.jp/signaling";
private AyameConnectionSettings connectionSettings = null;

[SerializeField]
string signalingKey = "";

[SerializeField]
string roomId = "";
public AyameConnectionSettings ConnectionSettings => connectionSettings;

[SerializeField]
bool autoConnection = true;

[SerializeField]
bool printDebugLog = false;

WebSocket ws;
bool tryToConnect = false;
private bool printDebugLog = false;

readonly object messageQueueLock = new object();
ConcurrentQueue<ReceivedMessage> receivedMessageQueue = new ConcurrentQueue<ReceivedMessage>();
private WebSocket ws;
private bool tryToConnect = false;

public string RoomId
{
set
{
roomId = value;
}
get
{
return roomId;
}
}
private readonly object messageQueueLock = new object();
private readonly ConcurrentQueue<ReceivedMessage> receivedMessageQueue = new ConcurrentQueue<ReceivedMessage>();

async void Start()
{
ws = new WebSocket(serverUrl);
ws = new WebSocket(connectionSettings.ServerUrl);

ws.Opened += Websocket_Opened;
ws.MessageReceived += Websocket_MessageReceived;
ws.Closed += Websocket_Closed;

ws.EnableAutoSendPing = false;

if (autoConnection)
if (connectionSettings.AutoConnection)
{
await Task.Delay(3000);
tryToConnect = true;
Expand Down Expand Up @@ -121,9 +102,10 @@ private async void Websocket_Closed(object sender, EventArgs e)
if (printDebugLog)
{
Debug.Log("Websocket closed");
Debug.Log(e);
}

if (autoConnection)
if (connectionSettings.AutoConnection)
{
await Task.Delay(1000);

Expand Down Expand Up @@ -192,8 +174,8 @@ private void SendRegisterMessage()
var message = new RegisterMessage()
{
Type = "register",
SignalingKey = signalingKey,
RoomId = roomId,
SignalingKey = connectionSettings.SignalingKey,
RoomId = connectionSettings.RoomId,
ClientId = clientId,
};

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
@@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f16a468e8963e7345952bec168cb9bc7, type: 3}
m_Name: AyameConnectionSettings
m_EditorClassIdentifier:
serverUrl: wss://ayame-labo.shiguredo.jp/signaling
signalingKey:
roomId:
autoConnection: 0

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

0 comments on commit 5327578

Please sign in to comment.