Giter Site home page Giter Site logo

unity-toolsandhelpers's Introduction

馃敡 Unity Tools and Helpers

Useful tools and handy functions to use for Unity projects.

馃敤 Get Started

  • git clone https://github.com/BrandonBartram98/Unity-ToolsAndHelpers - Clone project
  • Import scripts into Unity project

Helpers/Extensions

General Helpers

Useful functions for optimization and some that are just reguarly used.

Example

// Non-Allocating WaitForSeconds
// Reduce garbage collection by reusing WaitForSeconds if same wait time exists
private static readonly Dictionary<float, WaitForSeconds> WaitDictionary = new Dictionary<float, WaitForSeconds>();

public static WaitForSeconds GetWait(float time)
{
    if (WaitDictionary.TryGetValue(time, out var wait)) return wait;

    WaitDictionary[time] = new WaitForSeconds(time);
    return WaitDictionary[time];
}

LatLongs

Scripts for converting latitude + longitudes into Unity meters and getting bearings between them.

Get Bearing

public float GetBearing(float lat1, float lon1, float lat2, float lon2)
{
    double 蠁1 = lat1 * Math.PI / 180; // 蠁, 位 in radians
    double 蠁2 = lat2 * Math.PI / 180;
    double 位1 = lon1 * Math.PI / 180;
    double 位2 = lon2 * Math.PI / 180;

    // where 蠁1,位1 is the start point, 蠁2,位2 the end point (螖位 is the difference in longitude)
    double y = Math.Sin(位2 - 位1) * Math.Cos(蠁2);
    double x = Math.Cos(蠁1) * Math.Sin(蠁2) -
               Math.Sin(蠁1) * Math.Cos(蠁2) * Math.Cos(位2 - 位1);
    double  = Math.Atan2(y, x);
    double brng = ( * 180 / Math.PI + 360) % 360; // in degrees

    return (float)brng;
}

Get Distance

public float GetDistance(float lat1, float lon1, float lat2, float lon2)
{
    // 蠁 is latitude, 位 is longitude, R is earth鈥檚 radius (mean radius = 6,371km)
    double R = 6371e3; // metres
    double 蠁1 = lat1 * Math.PI / 180; // 蠁, 位 in radians
    double 蠁2 = lat2 * Math.PI / 180;
    double 螖蠁 = (lat2 - lat1) * Math.PI / 180;
    double 螖位 = (lon2 - lon1) * Math.PI / 180;

    double a = Math.Sin(螖蠁 / 2) * Math.Sin(螖蠁 / 2) +
               Math.Cos(蠁1) * Math.Cos(蠁2) *
               Math.Sin(螖位 / 2) * Math.Sin(螖位 / 2);
    double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

    double d = R * c; // in metres

    return (float)d;
}

VR

Useful Virtual Reality scripts.

Force Player Rig Rotation

[Header("XR Rig")]
[SerializeField] private Transform _xrRig;
[SerializeField] private Transform _rigOffset;
[SerializeField] private Transform _rigCamera;

[Header("Transforms")]
[SerializeField] private Transform _desiredTransform;

// Set the player position and rotation, useful to force rotation after loading scene
public void SetPlayerPositionAndRotation()
{
    Vector3 newPos = new Vector3(_desiredTransform.position.x, _xrRig.position.y, _desiredTransform.position.z);

    _xrRig.SetPositionAndRotation(newPos, _desiredTransform.rotation);

    _rigOffset.localRotation = Quaternion.identity;
    _rigOffset.localRotation = Quaternion.Inverse(Quaternion.Euler(0, _rigCamera.eulerAngles.y, 0)) * _xrRig.rotation;
}

Prefabs/Plugins

Custom Keyboard

A prefab + scripts for a Onscreen or VR/AR keyboard.

馃懟 Contribute

git clone https://github.com/BrandonBartram98/Unity-ToolsAndHelpers

unity-toolsandhelpers's People

Contributors

brandonbartram98 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.