question

Ethan K. G avatar image
Ethan K. G asked

Failed to compile Unicorn Battle demo

Try to compile Unicorn Battle client (https://github.com/PlayFab/UnicornBattle) and get the following errors:

Assets/Scripts/PF_StaticsAndHelpers/PF_PubSub.cs(5,15): error CS0234: The type or namespace name 'Sockets' does not exist in the namespace 'PlayFab' (are you missing an assembly reference?)

Assets/Scripts/PF_StaticsAndHelpers/PF_PubSub.cs(15,19): error CS0246: The type or namespace name 'EntityKey' could not be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/PF_StaticsAndHelpers/PF_PubSub.cs(115,50): error CS0246: The type or namespace name 'PlayFabNetworkMessage' could not be found (are you missing a using directive or an assembly reference?)

My environment is:

Unity2019.4.14f1

PlayFabSDK 2.98.201027

Any hint?

PF_PubSub.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.Sockets;
using System;
using PlayFab.Sockets.Models;


public class PF_PubSub
{
    public delegate void PubSubMessageHandler(MessageFromServer msg);
    public static event PubSubMessageHandler OnMessageToPlayer;
    public static event PubSubMessageHandler OnMessageToAllPlayers;


    public static EntityKey currentEntity;


    private static bool isInitialized = false;


    public static void InitializePubSub()
    {
        if (isInitialized)
            return;


        isInitialized = true;
        //PlayFabSocketsAPI.Debugging = true;
        PlayFabSocketsAPI.Initialize();


        PlayFabSocketsAPI.OnConnected.AddListener(OnSocketsConnected);
        PlayFabSocketsAPI.Connect();
        PlayFabSocketsAPI.OnConnectionError.AddListener(OnSocketsConnectionError);
        PlayFabSocketsAPI.OnDisconnected.AddListener(OnSocketsDisconnected);




    }


    private static void OnSocketsConnected()
    {
        // create topics for both title specific AND player specific messages
        var entity = new PlayFab.Sockets.Models.EntityKey()
        {
            Id = currentEntity.Id,
            Type = currentEntity.Type
        };


        //Create a list of Topics to subscribe to
        var topics = new List<Topic>();


        //Create a Topic object to listen to
        var sendMessageToPlayerTopic= new Topic()
        {
            Entity = entity,
            FullName = new PlayFab.Sockets.Models.EventFullName() {
                Name =  "MessageToPlayer",
                Namespace = "custom.UnicornBattle"
            }
        };
        //Add that topic to the array		
        topics.Add(sendMessageToPlayerTopic);


        PlayFabSocketsAPI.RegisterHandler(sendMessageToPlayerTopic, OnReceiveMessageToPlayer);


        var sendMessageToAllPlayersTopic= new Topic()
        {
            Entity = new PlayFab.Sockets.Models.EntityKey() {
                Type = "Title",
                Id = PlayFabSettings.TitleId
            },


            FullName = new PlayFab.Sockets.Models.EventFullName() {
                Name =  "MessageToAllPlayers",
                Namespace = "custom.UnicornBattle"
            }
        };
        //Add that topic to the array		
        topics.Add(sendMessageToAllPlayersTopic);


        PlayFabSocketsAPI.RegisterHandler(sendMessageToAllPlayersTopic, OnReceiveMessageToPlayer);




        //send topic subscriptions and output any success or failures
        PlayFabSocketsAPI.Subscribe(topics, (subscribedTopics) =>
        {
            if (PlayFabSocketsAPI.Debugging)
                Debug.Log("Subscribe Success");
                
   /*          subscribedTopics.ForEach((t) =>
            {
                if (PlayFabSocketsAPI.Debugging)
                    Debug.LogFormat("{0} Subscribed Successfully", t.EventName);
            }); */
        }, (subscribedErrors) =>
        {
            if (PlayFabSocketsAPI.Debugging)
                Debug.Log("Subscribe Failed");
            
           /*  subscribedErrors.ForEach((t) =>
            {
                if (PlayFabSocketsAPI.Debugging)
                    Debug.LogFormat("{0}", t.Message);
            });		 */	
        });


    }


    private static void OnSocketsDisconnected()
    {
        Debug.Log("PlayFab PubSub:You were disconnected from the server");
    }


    private static void OnSocketsConnectionError(PlayFabError error)
    {
        Debug.LogFormat("PlayFab PubSub Error: {0}", error.GenerateErrorReport());
    }


    private static void OnReceiveMessageToPlayer(PlayFabNetworkMessage netMsg) {
        Debug.Log(netMsg.@event);		
        var jsonSerializer = PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer);
        if (netMsg.@event.payload != null) 
        {
            var msg = jsonSerializer.DeserializeObject<MessageFromServer>(netMsg.@event.payload);
            
            


            if (OnMessageToPlayer != null)                        
                OnMessageToPlayer(msg);            
        }
    }


    private static void ProcessMsgResponse(bool response)
    {
        
    }
}


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

PlayFab PubSub was a feature in private preview. The PubSub development has been suspended. Currently, there is no future information about it. PlayFab doesn't release the Socket API and PubSub feature in the public SDK. We would suggest you remove the code related to Pubsub first, then compile this project.

For the clarification, in the past few years since UnicornBattle was released, PlayFab's features have been updated and iterated several times. However, UnicornBattle hasn’t been updated for a long time. Before successfully compiling it, you could need to modify the code according to the actual situation. You can post the specific questions in the forum for the help. If you want to request a new version of the demo, you can try to add a feature request for it.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.