Skip to content

Custom and Built-In PlayFab functions wrapped in a single script, with easy and accessible methods

License

Notifications You must be signed in to change notification settings

superpanos/PlayFabWrapper

Repository files navigation

PlayFab Wrapper

Custom and Built-In PlayFab functions wrapped in a single script, with easy and accessible methods

Downloads Download Discord

Features βš™οΈ

Player πŸ’:

  • Login Using Oculus (Custom made, uses CloudScript)
  • Login From Unity
  • Player Ban Info
  • Player Inventory Management
  • Player Currency Management (Multiple currencies support)
  • Player PlayFab Username Management
  • Title Player Data Management
  • Remove Currency From Player (CloudScript)

Title πŸ“„:

  • Title Data Management

Economy πŸ’Έ:

  • Multiple currencies support
  • Economy Catalogs Management
  • Economy Items Management
  • Items Purchasing (Using PlayFab)
  • Player Item Granting (CloudScript)
  • Add Currency To Player (CloudScript)
  • Remove Currency From Player (CloudScript)

Multiplayer (Photon PUN) πŸ‘₯:

  • PlayFab Authentication
  • Oculus and PlayFab Authentication

Oculus πŸ₯½:

  • IAP Purchase Consumption

Other πŸ”¨

  • A small PlayFabManager sample
  • Debug/Test Mode (With buttons, etc.)

How To Install and ConfigureπŸ“²

⚠️Supported Unity Editor Versions: 2021.3 and higher

Installation ⬇️:

  1. Download and import PlayFab Unity SDK and PlayFab Editor Extensions
  2. When imported, open PlayFab Editor Extensions window by going in Window -> PlayFab -> Editor Extensions, login, and choose your studio and title
  3. After thats done, download PlayFab Wrapper Unity Package from Releases, and import its content into your Project
  4. Create an Empty Game Object in the root of your Hierarchy, name it PlayFabManager, and put a PlayFabWrapper script on it

Additionally: If you are a VR Developer, its recommended to also use my OculusSDKWrapper

Additionally: if you want to try out a small sample, put a PlayFabManagerSample script onto where your PlayFabWrapper script is. In our case, its on PlayFabManager object

PlayFab Title Configuration πŸ”§:

To get PlayFabWrapper working we need to configure our PlayFab Title first

  1. (Ignore if you already have an existing title you want to use) Go to PlayFab Website, login, and create a new title by press 3 dots on next to your Studio and press New Title
  2. After you have a Title, press gear icon next to your Title name, and click Title Settings

screenshot

  1. Go to API Features tab, scroll down and click (check) "Allow client to view ban reason and duration"

screenshot

  1. After that, go to Secret Keys tab, select all existing secret keys, and press Delete
  2. Next, look on the right side of your the dashboard, and click on Automation, then Revisions (Legacy)

screenshot

  1. Select all code inside (Win: CTRL + A | Mac: CMD + A), and delete it

  2. Now, scroll back up, find and open CloudScripts file, select and copy EVERYTHING (all code) inside of it

  3. Go back to the Revisions (Legacy) page, and paste all copied code inside of it

  4. Go to Meta Quest Developer Dashboard, open your App, and find API tab, open it, and copy your App ID, and App Secret (Do not tell anybody your App Secret!)

  5. In VerifyOculusPlayer and ConsumeIAP cloudscripts, find words "appidhere" and "appsecrethere" IN the links, and put your App ID and App Secret instead of them

  6. After the code is pasted, press Upload new revision, click Deploy this revision after save, and the press Save and deploy. After that, CloudScripts are set up

screenshot

Done!

Additionally: To use Economy features, you can create Catalogs, Items, and Currency for your PlayFab Title, by following these official guides:

Documentation πŸ“‘

(All the methods have summaries in the script too)

⚠️All variables are accessible through the instance. For example: PlayFabWrapper.instance.PlayFabID is the PlayFab ID

Player πŸ’:

Login using Oculus User ID and Oculus User Nonce

Saves:

  • Saves PlayFab ID in the instance (PlayFabID type of string)
  • Saves PlayFab Display Name in the instance (PlayerAccountName type of string) Example Usage:
    PlayFabWrapper.LoginWithOculus(r => {
        //success
    }, e => {
        //error
    });

Login from Unity (For Debug/Test)

Saves:

  • Saves PlayFab ID in the instance (PlayFabID type of string)
  • Saves PlayFab Display Name in the instance (PlayerAccountName type of string) Example Usage:
    PlayFabWrapper.LoginFromUnity(r => {
        //success
    }, e => {
        //error
    });

Get User Inventory and Currencies

Saves:

  • Saves owned currencies and their amounts in the instance (OwnedCurrencyAmount type of Dictionary<string, int>)
  • Saves Items Owned by the Player in the instance (PlayerOwnedItems type of List<string>) Example Usage:
    PlayFabWrapper.GetUserInventoryAndCurrency(r => {
        //success
    }, e => {
        //error
    });

Set PlayFab Display Name

Saves:

  • Saves PlayFab Display Name in the instance (PlayerAccountName type of string) Example Usage:
    PlayFabWrapper.SetPlayerDisplayName("exampleName", r => {
        //success
    }, e => {
        //error
    });

Set PlayFab Title Player Data

Example Usage:

    Dictionary<string, string> data_ = new(){
        { "example", "test" }
    }
    PlayFabWrapper.SetPlayerData(data_, r => {
        //success
    }, e => {
        //error
    });

Get PlayFab Title Player Data

Saves:

  • Saves received Title Player Data in the instance (TitlePlayerData type of Dictionary<string, string>)

Example Usage:

    PlayFabWrapper.GetPlayerData("PlayFabId", r => {
        //success
    }, e => {
        //error
    });

Title πŸ“„

Get Title Data

Saves:

  • Saves received Title Data in the instance (TitleData type of Dictionary<string, string>)

Example Usage:

    PlayFabWrapper.GetTitleData(r => {
        //success
    }, e => {
        //error
    });

Economy πŸ’Έ

Get Catalog and Item Prices

Saves:

  • Saves received Catalog and its Items infos in the instance (ItemsAndPrices type of List<CatalogInfo>)

Example Usage:

    PlayFabWrapper.GetCatalogAndPrices("TestCatalog", r => {
        //success
    }, e => {
        //error
    });

Purchase Item from Catalog

⚠️Get Catalog and Item Prices first (only once). Documentation on it is right above

(Price is set automatically, from the catalog that you got)

Example Usage:

    PlayFabWrapper.PurchaseItem("TestCatalog", "MyItem", "AB", r => {
        //success
    }, e => {
        //error
    });

Grant Item to Player

Example Usage:

    PlayFabWrapper.GrantItemToPlayer("PlayFabId", "TestCatalog", "MyItem", r => {
        //success
    }, e => {
        //error
    });

Add Currency to Player

Example Usage:

    PlayFabWrapper.AddCurrencyToPlayer("PlayFabId", "AB", 100, r => {
        //success
    }, e => {
        //error
    });

Remove Currency from Player

Example Usage:

    PlayFabWrapper.RemoveCurrencyFromPlayer("PlayFabId", "AB", 100, r => {
        //success
    }, e => {
        //error
    });

Multiplayer (Photon PUN) πŸ‘₯

Authenticate Photon With PlayFab

Automatically connects to Photon Pun after authenticated

Example Usage:

    PlayFabWrapper.AuthenticatePhotonWithPlayFab("PlayFabId", r => {
        //success
    }, e => {
        //error
    });

Authenticate Photon With Oculus and PlayFab

Automatically connects to Photon Pun after authenticated

Example Usage:

    PlayFabWrapper.AuthenticatePhotonWithPlayFabAndOculus("PlayFabId", r => {
        //success
    }, e => {
        //error
    });

Oculus πŸ₯½

Consume Oculus IAP (with CloudScript)

Example Usage:

    PlayFabWrapper.ConsumeOculusConsumablePurchase("exampleSku", r => {
        if(r){
            //Consume success
        } else {
            //Consume error
        }
    });

Contribution 🀝

You can contribute by suggesting changes, fixes, and new functiononality by suggesting it in #general channel in my discord

Credits πŸ™Œ

About

Custom and Built-In PlayFab functions wrapped in a single script, with easy and accessible methods

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages