Kinetix Documentation
Website
  • 🖐️Welcome
  • 🕺About Kinetix
  • 🖌️User-Generated Emote
    • 🤖Video-to-animation AI
    • 🤸Kinetix Emote Standards
    • 🦴Retargeting
    • 🏂Kinanim (Emote streaming)
    • 🖊️Try the User-Generated Emote feature
  • INTEGRATION
    • 🤷SDK or API: what to choose
    • 🤩Kinetix SDK
      • ⚙️SDK - Core Package
      • 🧩SDK - Sample scene
      • 🧑‍💻Tested & approved Game Engines for the SDK
      • 💻SDK Integration in Unity
        • ⬇️Set-up Unity & Import the SDK
          • 🔑Get your Game authentification API Key
          • ⚙️Setup your Unity environment
          • 🔧Install the Kinetix SDK in Unity
          • ⌨️SDK Initialization - Unity
        • ⚡Quickstart - Unity SDK
        • 🦋SDK Core Modules activation - Unity
          • 🔐Account Management in Unity
          • 💃Animation System - Unity
            • 🎢Unity's Animator System
            • 🎨Custom Animation System
            • 🌳Root Motion
              • RootMotion + NavMeshAgent
            • 🎞️Frame Controller
            • 💪IK Controller
            • 🫥Avatar Mask
          • 📶Network - Unity SDK
            • Photon PUN
            • Photon Fusion
        • 🕺User-Generated Emote integration (Unity)
          • Embedding the PWA in your Unity application
          • Validation / Retake
        • 🚧How to update Kinetix SDK in Unity?
        • 📕SDK API Reference - Unity
          • KinetixCore
          • KinetixCore.Account
          • KinetixCore.Animation
          • KinetixCore.Metadata
          • KinetixCore.Network
          • KinetixCore.UGC
        • 📂Unity SDK Changelog
      • 🕹️SDK Integration in Unreal Engine
        • ⬇️Set-up Unreal Engine & Download the SDK
          • 🔑Get your Game authentification API Key
          • ⚙️Set up your Unreal Engine environment
          • 🔧Install the Kinetix SDK in Unreal
          • ⌨️UE SDK Core Package Initialization
        • ⚡Quick Start
        • 🦋SDK Core Modules activation - Unreal
          • 🔐Account Management - UE
          • 💃Animation System - UE
            • Local player system in Unreal Engine
            • Avatar system in Unreal Engine
            • Without uploading an avatar (deprecated)
              • Animation in a Third Person Template
              • Animation in an existing project
          • 📶Network - UE SDK
        • 🕺User-Generated Emote integration (UE)
        • 📕SDK API Reference - UE
          • KinetixCore
          • KinetixCore.Account
          • KinetixCore.Animation
          • KinetixCore.Metadata
          • KinetixCore.Network
        • ⬆️Updating from 0.3 to 0.4
        • 📂UE SDK Changelog
    • 😍Kinetix API
      • 🔑Get your Authentification API key
      • 🔌API routes
      • 🪝API Webhooks
      • 🏓Possible Return Codes
  • Management
    • 🚪Developer Portal
      • 👽Avatar Upload
      • 👮UGC Moderation
    • 🖌️UGE: Guides & Best Practices
      • 📐User-Generated Emote specifications
      • 👌Video recording best practices
      • 👻User-Generate Emote Use Cases
  • SUPPORT
    • 📬Bugs reports & features requests
    • ❓FAQ
      • FAQ: General questions
      • FAQ: Unity SDK
      • FAQ: Unreal Engine SDK
    • 🤕Troubleshooting
    • 📚Glossary of terms
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. INTEGRATION
  2. Kinetix SDK
  3. SDK Integration in Unity
  4. SDK Core Modules activation - Unity
  5. Network - Unity SDK

Photon PUN

Exemple of Photon PUN integration

This exemple is pseudo code giving an idea on how to implement our Network module. It may be different based on your Network Architecture and we recommend you to develop your own implementation.

PhotonConnectManager is a global script attached one time to get information if the local player joined a room and then instantiate its prefab.

Player is a script attached to the player prefab and will register and unregister if its local player or a remote player.

using Photon.Pun;
using Kinetix;
using Newtonsoft.Json;

public class PhotonConnectionManager : MonoBehaviourPunCallbacks
{
    // Called when local player joined room
    public override void OnJoinedRoom()
    {
       GameObject gameObject = PhotonNetwork.Instantiate(PLAYER_PREFAB, Vector3.zero, Quaternion.identity);
       Player player = gameObject.GetComponent<Player>();
       player.Init()
    }	
}
using Photon.Pun;
using Kinetix;

public class Player : MonoBehaviourPun, IPunObservable
{
    private KinetixCharacterComponent Kcc;
    private AnimationIds nextAnimation;

    private void Init()
    {
        Animator animator = GetComponent<Animator>();
    
        if (photonView.AmOwner)
        {
            // Player is local player
            KinetixCore.Animation.RegisterLocalPlayer(animator);
            KinetixCore.Animation.OnAnimationStartOnLocalPlayerAnimator += (_Ids) => nextAnimation = _Ids;
        }
        else
        {
            peerID = PhotonView.Get(this).ViewID;
            // Player is remote player
            KinetixCore.Network.RegisterRemotePeerAnimator(peerID, animator);
        }
    }

    public void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)	
    {
        if (Kcc == null) return;
        
        if (stream.IsWriting) 
        {
            // If the animation ids have been set
            if (nextAnimation != null) 
	    {
	        // Serialize and send on stream, then set it to null
		stream.SendNext(JsonConvert.SerializeObject (nextAnimation));
		nextAnimation = null;
	    }		
        } 
        else
        {
            // When receiving an emote to play from a distant player
            if (stream.Count > 0) 
	    {
	        string nextAnimationJson = (string) stream.ReceiveNext();
	
	        nextAnimation = JsonConvert.DeserializeObject<AnimationIds>(nextAnimationJson);
                
                ((KinetixCharacterComponentRemote) Kcc).PlayAnimation(nextAnimation);
	    }
        }
    }

    
    private void OnDestroy()
    {
        if (photonView.AmOwner)
        {
            KinetixCore.Animation.UnregisterLocalPlayer();
            KinetixCore.Network.UnregisterAllRemotePeers();
        }
        else
        {
            KinetixCore.Network.UnregisterRemotePeer(peerID);
        }
    }
}
PreviousNetwork - Unity SDKNextPhoton Fusion

Last updated 1 year ago

Was this helpful?

🤩
💻
🦋
📶