Skip to content

Useful tools for Unity. (Unregistered team will see 404 error as it is currently private)

License

Notifications You must be signed in to change notification settings

fysoul17/QuasarUnityTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Useful tools for Unity by Quasar Inc & GIX Inc.

Copyright (c) 2015 Quasar Inc., GIX Inc., Terry Keetae Kwon All rights reserved.

This project is for Unity® to provide a useful tools that allows game developers to save time making thoes on every project. However, this project is not in any way endorsed or supervised by Unity Technologies.

Unity® is a trademark of Unity Technologies.

Working progress can be found at Trello

Overview

  • PlayFab authentication with various platform with just one line of code. (IMPORTANT: API/Plugins provided by each organization are required)

  • PlayFab Server time synchroniser. (IMPORTANT: Plugin is required)

    • JSON .NET for Unity - JSON Parser. ($27.50 on Asset store)
    • Cloud script must be uploaded to PlayFab Server
  • Many useful UI tools. (IMPORTANT: Some require plugins)

    • Loading Indicator needs iTween - Tested with version of 2.0.7  - Flexible tab window
  • RPG tools that can be commonly used for RPG Games such as Stat system or inventory system.

  • Utilities

    • Random selection from list of item with probabilities.
    • Big number formatter. (1,000 -> 1.00A, 1,000,000 -> 1.00B, ...)
  • Input system

    • Advanced joystick (Single / Dual). (IMPORTANT: 'Standard Assets' is required) Import: Assets > (Right click) > Import Package > CrossPlatformInput
    • Swipe detector in 4 directions.
  • Classes that apply GoF design patterns. (Singleton, Command, etc..)

PlayFab

using Quasar.PlayFab

Authentication

using Quasar.PlayFab.Authentication;

public class Authentication : MonoBehaviour
{
    public void Authenticate() 
    {
        // PlayFab Custom
        (new PlayFabAuthentication("PlayFabTestAccount", "Test1234")).Login(OnLoginSuccess, OnLoginFailed, infoRequestParams);
        
        // Mobile Platform using device unique identifier
        (new MobilePlayFabAuthentication()).Login(OnLoginSuccess, OnLoginFailed, infoRequestParams);
        
        // Facebook
        new FacebookAuthentication().Login(OnLoginSuccess, OnLoginFailed, infoRequestParams);
        
        // GameCenter
        new GameCenterAuthentication().Login(OnLoginSuccess, OnLoginFailed, infoRequestParams);
        
        // Google Play
        new GooglePlayAuthentication().Login(OnLoginSuccess, OnLoginFailed, infoRequestParams);
    }
}

Manager

Allow multiple server API calls simultaneously, and throw callback when it is all finished.

  1. Create and attach API calling script on appropriate GameObject.
[SerializeField] PlayFabManager manager;

void Awake()
{
    // Register. Some data that has to be loaded before 'ScheduleLoading'
    manager.SchedulePreloading(OnReadyToPreLoad);
    
    // Register default data loading.
    manager.ScheduleLoading(OnReadyToLoad);
}

void OnReadyToPreLoad() 
{
    // API Calls..
    
    // Must call this when API call has finished, so that we can check whether all data is loaded.
    manager.FinishedPreloading();
}
  1. Simply fire data fetch function on appropriate timing.
[SerializeField] PlayFabManager playFabManager;

void OnLoggedIntoPlayFab() 
{
    yield return StartCoroutine(playFabManager.FetchDataFromServer(() =>
    {
        // One of loading is done.
    },
    () =>
    {
        // All loadings are done. Proceed next process.
    }));
}

Server Time

Fetch server time and sync on client device, so that we can prevent time hacks on client side. Attach PlayFabManager, PlayFabTimer and ServerTimeSynchroniser scripts on GameObject then use as below:

ServerTimeSynchroniser.ServerTime

RPG

TBA

UI

using Quasar.UI

Loading Indicator

Grab prefab named 'LoadingIndicator' and put it on Canvas which has highest sorting order so that it can block inner UIs while showing indicator.

public class UITest : MonoBehaviour
{
    [SerializeField] LoadingIndicator loadingIndicator;

    public void LoadSomething() 
    {
        // With Text: loadingIndicator.Display("Loading data from server...");
        loadingIndicator.Display();
        
        // Loading start.
        // Loading...
        // Loading done.
        
        loadingIndicator.Hide();
    }
}

Tab Window

Grab prefab named 'Tab Window' and put it on Canvas. It has 3 tab buttons and 3 panels that interact to each button as a default.
In order to make from scratch, just add 'Tab Window Controller' script and 'Tab Window Button' prefabs, then link buttons and panels using the controller script.

Utilities

using Quasar.Util

QuasarRandom

// Select the index randomly from the array of probabilities.
// ex) float[] p = { 0.1f, 0.3f, 0.5f, 0.1f } => each item has 10%, 30%, 50%, 10% chances to be selected.
int randomSelectedIndex = QuasarRandom.SelectRandomIndexWithProbability(emergeProbabilities);

BigNumberFormatter

// Returns formatted string of double number.
// Can be renamed by modifying 'enum BigNumberFormat'.
double aBigNumber = 10000000000d;
string formattedString = aBigNumber.ToFormattedString("n2");
// 10,000,000,000 = 10.00 C (A, B, C ...)

int aIntValue = 10000000;
string formattedIntString = aIntValue.ToFormattedString("n2");
// 10,000,000 = 10.00 M (K, M, B, T)

Input

using Quasar.Input

AdvancedJoystick

Added few function based on Unity standard assets' 'Joystick' script as standard joystick only provides simple function whereas 'AdvancedJoystick' provides more such as 'Circle joystick', 'Single/dual joystick' and 'Dynamic joystick' function.

Check Dual joystick Prefab in Sample folder if needed.
IMPORTANT: As standard joystick does, it only works on Mobile Platform.

public enum JoystickType                // Availble joystick types.
{
    Circle,
    Rectagle
}
public bool dynamicJoystick             // Allows to move around touch area when user touches.

Swipe Detector

Detects swipe input in 4 directions. Can be modified to 8 directions easily. Simply attach the script to component that is raycast targets (eg. elements of canvas), and use it as below.

private void Awake()
{
    SwipeInputDetector.InputDerectionCallback += HandleSwipeInput;
}

private void HandleSwipeInput(InputDirection direction)
{
    ...
}

Patterns

using Quasar.Patterns

Singleton Pattern

By inheriting MonoSingleton class, you can easily implement singleton pattern.
Source code is from this site. This script doesn't need to add 'using' as it does not use custom namespace.

public class Singleton : MonoSingleton<Singleton>
{
    ...
}

Observer Pattern

Simply add observers and notify on other scripts. Below is sample codes for usage.

public class Player : MonoBehaviour
{
    void Start() 
    {
        EventHandler.Notify("OnPlayerAwaken", gameObject);
    }
}
public class GameMaster : MonoBehaviour
{
    void Awake() 
    {
        EventHandler.AddObserver("OnPlayerAwaken", JoinBattle);
    }
    
    // IMPORTANT: Must remove when destroyed as the event is static.
    void OnDestroy()
    {
        EventHandler.RemoveObserver("OnPlayerAwaken", JoinBattle);
    }
    
    void JoinBattle(params object[] args) 
    {
        Player player = (args[0] as GameObject).GetComponent<Player>();
        Debug.Log(player + " is joinning battle"); 
    }
}

Command Pattern

Applies command pattern of GoF. Just a simple abstract class.

public class SomeCommand : Command
{
    public override double TimeStamp
    {
        get;
        set;
    }
    
    public override void Execute()
    {
    }
    
    public override void Undo()
    {
    }
}

Attribute

using Quasar.Attribute

Read Only Attribute

Prevents modifying value on Editor.

[ReadOnlyProperty]
public int readOnlyValue = 10;

Unity Assets

In this folder, every assets are created by Unity Technologies and can be downloaded from thier webpage

EditorWithSubEditors

This class acts as a base class for Editors that have Editors nested within them.

Serialized Property Extensions

This script is created by Unity Technologies and added here to use at 'Interaction' module editor.

About

Useful tools for Unity. (Unregistered team will see 404 error as it is currently private)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published