Unity example: show when connected

This commit is contained in:
Chris Marsh 2017-08-03 09:52:43 -07:00
parent f6853fac1b
commit 470259e8b0
2 changed files with 111 additions and 0 deletions

View file

@ -7,6 +7,8 @@ public class DiscordController : MonoBehaviour {
public string applicationId;
public int callbackCalls;
public int clickCounter;
public UnityEngine.Events.UnityEvent onConnect;
public UnityEngine.Events.UnityEvent onDisconnect;
DiscordRpc.EventHandlers handlers;
@ -24,12 +26,14 @@ public class DiscordController : MonoBehaviour {
{
++callbackCalls;
Debug.Log("Discord: ready");
onConnect.Invoke();
}
public void DisconnectedCallback(int errorCode, string message)
{
++callbackCalls;
Debug.Log(string.Format("Discord: disconnect {0}: {1}", errorCode, message));
onDisconnect.Invoke();
}
public void ErrorCallback(int errorCode, string message)

View file

@ -271,6 +271,80 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 359174702}
--- !u!1 &657463235
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 657463238}
- component: {fileID: 657463237}
- component: {fileID: 657463236}
m_Layer: 5
m_Name: IsConnectedLabel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &657463236
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 657463235}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.89518255, g: 0.9338235, b: 0.23345588, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 24
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Discord Disconnected
--- !u!222 &657463237
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 657463235}
--- !u!224 &657463238
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 657463235}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1766020814}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -766, y: 378.99997}
m_SizeDelta: {x: 239.2, y: 37.8}
m_Pivot: {x: 0, y: 1}
--- !u!1 &1032248338
GameObject:
m_ObjectHideFlags: 0
@ -541,6 +615,7 @@ RectTransform:
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1032248339}
- {fileID: 657463238}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -595,6 +670,38 @@ MonoBehaviour:
applicationId: 338030514596216832
callbackCalls: 0
clickCounter: 0
onConnect:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 657463236}
m_MethodName: set_text
m_Mode: 5
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument: Discord Connected
m_BoolArgument: 1
m_CallState: 2
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null
onDisconnect:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 657463236}
m_MethodName: set_text
m_Mode: 5
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument: Discord Disconnected
m_BoolArgument: 0
m_CallState: 2
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null
--- !u!4 &1929635630
Transform:
m_ObjectHideFlags: 0