Giter Club home page Giter Club logo

unitytoolkit's Introduction

UnityToolkit

Collection of tech of Unity3d

1, Locate camera to position, after that, camera will lookat the target automatically

// get the camera transform
Transform cameraTransform = Global.Instance.FindMainCameraTransform();
Debug.Assert(cameraTransform != null);

// let's get a position for initialize
Vector3 position = targetGameObject.transform.position;
// then get the camera forward direction in world space (camera forward in local space is always Vector3.forward)
Vector3 direction = cameraTransform.TransformDirection(Vector3.forward);
direction.Normalize();
// now we get the right position for camera transform
position -= direction * 5f;
// set camera transform's position
cameraTransform.position = position;

# 2, GameObject Layer Mask
// get a mask can be used in Physics.Raycast
int LayerMask.GetMask(string[] layerNameArray);

// get a layer integer from given name, need to use 1 << layer for Physics.Raycast using
int LayerMask.NameToLayer(string name);

// get a layer name
string LayerMask.LayerToName(int layer)

# 3, UI adaption

You should have a design resolution first.
Then you make a UI canvas, on the "Canvas Scaler" component, "UI Scale Mode" choose "Scale With Screen Size". Then fill Reference Resolution with your design resolution.

Tip:
if there is ScrollView with dynamic content, you should add your content, for example, one row, by using transform.SetParent(t, false);

# 4, WebGL javascript

You can customize your template by add a template to Assets/WebGL Templates folder, copy one folder from Unity Engine (for example, on mac, it's path is "Unity/PlaybackEngines/WebGLSupport/WebGL Templates"). And add <script src="">[file.js]</script> below unity's script tag. 

In file.js, put your code there. For unityInstance, you can keep reference at callback of createUnityInstance, use window.unityInstance = unityInstance;
Then at your file.js, you can use unityInstance as window.unityInstance anywhere.

To call C# code, you use window.unityInstance.SendMessage()

# 5, Unity Remote Debug

To test 'touch' feature, Unity remote is a tool (application) to make thing easy. For iOS, download "Unity Remote 5" from appstore. Then
a, in unity editor, switch active settings to iOS
b, link iPhone/iPad with a wire to your PC. For sure, you can install iTunes to see whether you can see your device on the iTunes.
c, unity editor, edit/project settings/editor, unity remote/device, should see Any iOS device and your iOS device name. Choose your iOS device.
d, play, you can now see the screen sync to your device.

unitytoolkit's People

Watchers

 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.