Initial Client/Server Communication

#1
Followed the MagicOnion quickstart guide, borrowing code from the chat sample app to get something working
This commit is contained in:
hyperion51 2020-02-26 17:48:40 +00:00
commit a0c8dbee72
493 changed files with 57790 additions and 3 deletions

View file

@ -0,0 +1,19 @@
using Grpc.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MagicOnion
{
public static class ChannelExtensions
{
/// <summary>
/// Safety way for subscribe streaming events.
/// </summary>
public static void RegisterStreamingSubscription(this Channel channel, IDisposable subscription)
{
channel.ShutdownToken.Register(() => subscription.Dispose());
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 88d6659672dcc9e408775f1fcaa6dea3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,15 @@
{
"name": "MagicOnion.Unity",
"references": [
"MagicOnion.Abstractions",
"MagicOnion"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 350d0af80fb7b7947a59de66ab477547
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,157 @@
using Grpc.Core.Logging;
using System;
namespace MagicOnion
{
public class UnityDebugLogger : ILogger
{
readonly Type forType;
readonly string forTypeString;
readonly bool errorToWarn = true; // default is true(gRPC internal log show to warn)
public UnityDebugLogger()
: this(null)
{
}
public UnityDebugLogger(bool errorToWarn)
: this(null)
{
this.errorToWarn = errorToWarn;
}
protected UnityDebugLogger(Type forType)
{
this.forType = forType;
if (forType != null)
{
var namespaceStr = forType.Namespace ?? "";
if (namespaceStr.Length > 0)
{
namespaceStr += ".";
}
this.forTypeString = namespaceStr + forType.Name + " ";
}
else
{
this.forTypeString = "";
}
}
/// <summary>
/// Returns a logger associated with the specified type.
/// </summary>
public virtual ILogger ForType<T>()
{
if (typeof(T) == forType)
{
return this;
}
return new UnityDebugLogger(typeof(T));
}
/// <summary>Logs a message with severity Debug.</summary>
public void Debug(string message)
{
UnityEngine.Debug.Log(BuildMessage(message));
}
/// <summary>Logs a formatted message with severity Debug.</summary>
public void Debug(string format, params object[] formatArgs)
{
UnityEngine.Debug.Log(BuildMessage(format, formatArgs));
}
/// <summary>Logs a message with severity Info.</summary>
public void Info(string message)
{
UnityEngine.Debug.Log(BuildMessage(message));
}
/// <summary>Logs a formatted message with severity Info.</summary>
public void Info(string format, params object[] formatArgs)
{
UnityEngine.Debug.Log(BuildMessage(format, formatArgs));
}
/// <summary>Logs a message with severity Warning.</summary>
public void Warning(string message)
{
UnityEngine.Debug.LogWarning(BuildMessage(message));
}
/// <summary>Logs a formatted message with severity Warning.</summary>
public void Warning(string format, params object[] formatArgs)
{
UnityEngine.Debug.LogWarning(BuildMessage(format, formatArgs));
}
/// <summary>Logs a message and an associated exception with severity Warning.</summary>
public void Warning(Exception exception, string message)
{
Warning(message + " " + exception);
}
/// <summary>Logs a message with severity Error.</summary>
public void Error(string message)
{
if (errorToWarn)
{
UnityEngine.Debug.LogWarning(BuildMessage(message));
}
else
{
UnityEngine.Debug.LogError(BuildMessage(message));
}
}
/// <summary>Logs a formatted message with severity Error.</summary>
public void Error(string format, params object[] formatArgs)
{
if (errorToWarn)
{
UnityEngine.Debug.LogWarning(BuildMessage(format, formatArgs));
}
else
{
UnityEngine.Debug.LogError(BuildMessage(format, formatArgs));
}
}
/// <summary>Logs a message and an associated exception with severity Error.</summary>
public void Error(Exception exception, string message)
{
Error(message + " " + exception);
}
/// <summary>Gets the type associated with this logger.</summary>
protected Type AssociatedType
{
get { return forType; }
}
string BuildMessage(string message)
{
if (forType != null)
{
return forTypeString + message;
}
else
{
return message;
}
}
string BuildMessage(string format, object[] args)
{
if (forType != null)
{
return forTypeString + string.Format(format, args);
}
else
{
return string.Format(format, args);
}
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5a9b20988ba163244a107c806f58c14f
timeCreated: 1482380673
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: