Coder Social home page Coder Social logo

magiconion.logiclooper.webgl's Introduction

MagicOnion.LogicLooper.WebGL

Cysharp server framework boilerplate example.

MagicOnion with Unity Installation

Tested Unity version

  • 2022.3.17f1
  • 에디터 환경 작동 확인.
  • WebGL 빌드(Brotli compress) 작동 확인.

Prepare

먼저 하지 않으면 중간에 컴파일 에러 발생시 진행 안되는 것들

  1. Nuget for Unity 설치 https://github.com/GlitchEnzo/NuGetForUnity
  2. CsprojModifier 설치 https://github.com/Cysharp/CsprojModifier

Client(Unity)

nuget으로 설치 해야 하는 것들

  1. MicroSoft.CodeAnalysis MagicOnion, MemoryPack 여기서 SourceGenerator 사용하는데 여기서 필요
  2. MicroSoft.CodeAnalysis.CSharp MicroSoft.CodeAnalysis 설치하면 의존성때문에 같이 설치 되는데 에러나는 것들 지우다 보면 같이 지워져서 따로 받아야 함.
  3. Microsoft.Extensions.Logging.Abstractions.8.0.0
  4. ZLogger

unitypackage 파일로 설치 한 것들

  1. MagicOnion
  2. MemoryPack MagicOnion serializer로 MemoryPack 사용하기 위한 코드
    [UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void RegisterResolvers()
    {
        MagicOnionSerializerProvider.Default = MemoryPackMagicOnionSerializerProvider.Instance;
    }
  1. GrpcWebSocketBridge

유니티에서는 나지 않지만 IDE에서 에러나는 것들이 있어서 패키지 형태로 구성되어 있는 것들은 다 패키지 폴더로 이동시키기

기타 설치 패키지들(Not Necessary)

  • ZLogger.Unity
  1. Install ZLogger.Unity package via git url. Add https://github.com/Cysharp/ZLogger.git?path=src/ZLogger.Unity/Assets/ZLogger.Unity to Package Manager git이 설치 안된 곳에서는 소스코드 다운 받아서 해당 경로에 있는 파일 직접 유니티 Package 폴더로 복사

WebGL 추가 작업(for WebGL only)

  1. GrpcWebSocketBridge webgl custom release 페이지에 가서 Grpc.Net.Client-ModifiedForWebGL.x.x.x.zip 파일 받아서 안에 있는 DLL들 교체

  2. Disable SynchronizationContext (WebGL) https://github.com/Cysharp/GrpcWebSocketBridge?tab=readme-ov-file#disable-synchronizationcontext-webgl

    초기화 클래스 생성후 아래 코드 삽입

    #if UNITY_WEBGL && !UNITY_EDITOR
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void InitializeSynchronizationContext()
    {
        SynchronizationContext.SetSynchronizationContext(null);
    }
    #endif

ShareProject Configuration

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <!--
      prior to .NET 8
      <BaseIntermediateOutputPath>.artifacts\obj\</BaseIntermediateOutputPath>
		  <BaseOutputPath>.artifacts\bin\</BaseOutputPath>
    -->

    <!-- after .NET 8: https://learn.microsoft.com/en-us/dotnet/core/sdk/artifacts-output -->
    <!-- Unity ignores . prefix folder -->
    <ArtifactsPath>$(MSBuildThisFileDirectory).artifacts</ArtifactsPath>
  </PropertyGroup>
</Project>
  • 유니티 프로젝트에서 위에서 만든 패키지 디펜던시로 추가
{
  "dependencies": {
    "com.your.package.shared.unity": "file:../../YourPackageSharedUnity",
  }
}
  • 문서에는 MemoryPack이 아니고 MessagePack을 사용하는 방법으로 Code Generate 섹션이 있는데 MagicOnion, MemoryPack 을 사용해서 SourceGenerator 가 코드를 생성해주기 때문에 스킵

  • 프로젝트 파일 참고

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
      <TargetFrameworks>netstandard2.1;net8.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="**\package.json" />
    <None Remove="**\*.asmdef" />
    <None Remove="**\*.meta" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="MagicOnion.Abstractions" Version="6.0.0" />
    <PackageReference Include="MemoryPack.Generator" Version="1.10.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="MemoryPack.UnityShims" Version="1.10.0" />
  </ItemGroup>

</Project>

서버 프로젝트

  • ShareProject 이것만 ProjectRefrence로 추가하면 나머지는 그냥 시키는대로만 하면 잘 돼서 설명서 잘 따라하면 됨

이상 1주일간 삽질기 마무리....

magiconion.logiclooper.webgl's People

Contributors

colorsockss avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.