Skip to content

Unity client sdk #1105

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

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open

Conversation

Fellmonkey
Copy link
Contributor

What does this PR do?

This PR adds comprehensive Unity SDK support to the SDK generator by:

  1. Unity Language Implementation: Introduces a new Unity language class (src/SDK/Language/Unity.php) that extends the base Language class, providing Unity-specific type mappings, keywords, and code generation logic for C# in Unity environment.

  2. Unity Template System: Adds a complete set of Unity-specific templates under templates/unity/Assets/ including:

    • Runtime components (Client, Services, Models, Enums, etc.)
    • Editor tools (Setup Assistant, Setup Window)
    • Unity project files (assembly definitions, project settings)
    • Required .NET libraries for Unity compatibility
  3. Automated Testing Integration: Introduces Unity2021 test support with:

    • Unity2021Test.php test class that integrates with the existing test framework
    • Unity test source files (Tests.cs, Tests.asmdef) for comprehensive SDK testing
    • Docker-based Unity CI testing using unityci/editor:ubuntu-2021.3.45f1-base-3.1.0
  4. CI/CD Integration: Updates the GitHub Actions workflow to:

    • Include Unity2021 in the test matrix alongside other SDK platforms
    • Set up the UNITY_LICENSE environment variable for Unity Editor automation
    • Enable automated testing of the Unity SDK in the CI pipeline
  5. Unity Project Structure: Implements proper Unity package structure with:

    • Assets organized under Assets/Runtime/ and Assets/Editor/
    • Required Unity project settings and manifest files

Test Plan

The testing strategy includes:

  1. Unit Testing: The Unity2021Test.php runs comprehensive tests covering:

    • HTTP operations (GET, POST, PUT, PATCH, DELETE)
    • File upload functionality with different file types
    • Error handling and exception management
    • OAuth2 authentication flow
    • Query helper methods
    • Permission and role management
    • ID generation utilities
  2. Docker-based CI Testing: Tests run in a controlled Unity environment using:

    • Unity Editor 2021.3.45f1 in headless mode
    • Automated license activation using secrets
    • PlayMode test execution with filtered output
    • Integration with the existing mock API server

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

Yes

Moved Unity SDK template files from 'templates/unity/Runtime' and 'templates/unity/Editor' to 'templates/unity/Assets/Runtime' and 'templates/unity/Assets/Editor' for better alignment with Unity project conventions. Updated getFiles() in Unity.php to reflect new paths and added support for copying plugin DLLs and project settings. Improved file upload logic in Client.cs.twig to handle streams and byte arrays more robustly, and removed Unity-specific logging from Exception.cs.twig. Minor fixes in Realtime.cs.twig and Role.cs.twig for namespace and async handling.
Introduces Unity2021 test support by adding a Unity2021Test.php, Unity test source files, and updating the GitHub Actions workflow to include Unity2021 in the test matrix and set the UNITY_LICENSE environment variable. This enables automated testing for the Unity SDK within the CI pipeline.
@Fellmonkey
Copy link
Contributor Author

I am also attaching instructions on how to obtain a Unity license painlessly.
manual

@Fellmonkey
Copy link
Contributor Author

The basic functionality tested in the test is guaranteed to work, but I'm not sure about the rest. I will continue to refine it.

Also, a question: What to implement next for the client SDK?

@Fellmonkey
Copy link
Contributor Author

Fellmonkey commented Jul 11, 2025

The test failed because the secret is not configured in appwrite/sdk-generator.
{90B0C66F-3E43-439F-8158-11FB0AE9AA1C}

The successful test is here:
https://github.com/Comanda-A/sdk-generator-b/actions/runs/16206122996/job/45756699934
{B8C80D49-D1B7-481B-8359-B8378156B653}

@Fellmonkey
Copy link
Contributor Author

// Cookie support
client.SetCookie() / client.GetCookie()

// Real-time subscriptions  
realtime.Subscribe(channels, callback)

// Connection testing
await client.Ping()

The successful test is here:
https://github.com/Comanda-A/sdk-generator-b/actions/runs/16240261125/job/45855715029

@Fellmonkey
Copy link
Contributor Author

I'm done with cosmetics, now I'm going to implement the SDK into projects and fix anything that's wrong.

I'll also create a temporary repository to allow the community to use the generated Unity SDK.

The successful test is here:
https://github.com/Fellmonkey/sdk-generator/actions/runs/16354634859

Wrapped UniTask-related code in #if UNI_TASK preprocessor directives and updated asmdef to define UNI_TASK when com.cysharp.unitask is present.
Add conditional UniTask support for Unity templates
Introduces a [Flags] enum for selecting which services to initialize in the Unity inspector, adds related fields to the configuration ScriptableObject, and provides tooltips and warnings about API key security.
Introduces a mechanism to initialize selected services dynamically based on configuration using reflection. Adds a dictionary to store service instances, updates initialization logic, and provides methods to retrieve or try to retrieve initialized services. Also refactors the initialization and reinitialization methods to support optional realtime setup and improves error handling and logging.
add deprecation handling & sync with appwrite:master
@Fellmonkey
Copy link
Contributor Author

The generated SDK is here: https://github.com/Fellmonkey/sdk-appwrite-unity

@ChiragAgg5k
Copy link
Member

@Fellmonkey awesome work 🔥
I am kind of at a loss for words 😅

i am have tagged the team to take a look at the pr. in the meanwhile can we have the conflict resolved, and the test passing?

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces comprehensive Unity SDK support to the SDK generator, enabling Unity developers to integrate Appwrite services into their games and applications. The implementation provides a complete Unity package structure with client-side authentication, real-time subscriptions, server-side API access, and Unity-specific async/await support through UniTask.

Key changes include:

  • Unity language implementation with C# code generation for Unity environment
  • Complete Unity template system with runtime components, editor tools, and Unity project files
  • Automated testing integration with Unity2021 test support and Docker-based CI testing

Reviewed Changes

Copilot reviewed 70 out of 77 changed files in this pull request and generated 3 comments.

File Description
tests/Unity2021Test.php PHP test class integrating Unity testing with existing test framework
tests/languages/unity/Tests.cs Comprehensive Unity C# test file covering HTTP operations, file uploads, and helper methods
tests/languages/unity/Tests.asmdef Unity assembly definition for test dependencies and configuration
templates/unity/ Complete Unity package structure with runtime components, project settings, and documentation

@Fellmonkey
Copy link
Contributor Author

Fellmonkey commented Jul 24, 2025

@Fellmonkey awesome work 🔥 I am kind of at a loss for words 😅

i am have tagged the team to take a look at the pr. in the meanwhile can we have the conflict resolved, and the test passing?

@ChiragAgg5k As for the tests, I described above that a unity license secret is required (it is recommended not to ignore the tutorial #1105 (comment)).
Why : #1105 (comment)

Until the responsible person does this, the tests are bound to fail.
You can view the successful tests in detail in pr. For example, the latest one is Fellmonkey#4

Fellmonkey and others added 2 commits July 24, 2025 12:14
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants