Unity3d handle pre and post build ops

PostprocessBuildPlayer scripts do not fire on windows machines to date, and a pre process script for unity does not exist in the public domain, so here is an editor script which adds two custom buttons to your menu:- Custom Build, and Custom Build-Run. The purpose of this script is to allow you to handle any file copying or amendment to the build folder pre or post build automatically.

The script takes all the information required from the normal build window options into account, when executed manually it allows the user to choose a save path, it then fires a pre-process function before building and post process function after building and the build path is sent as a parameter, from within these functions you can call whatever you heart desires from c# file copying code to calling other applications and sending parameters alongside

(more…)

By |November 11th, 2011|Unity 3D|4 Comments

Cartesian coordinate conversion Unity3d

In 3D, we have a total of 48 different combinations of space coordinates to choose from:-

2 handed (or single axis flipped) systems x 3 axis x 4 (90 degree possible rotations around each (generally)) x 2 (possible 2 flipped axis variations on the same hand same rotation) = 48 possibilities.

There are 6 ways to notate xyz in a file but this would essentially replicate one of the 48 possibilities simply converting it from one possibility to another.

The functions below will only cover converting the 6 basic types (2 handed (or single axis flipped) systems x 3 axis) to Y-Up Left Hand system used by unity, so discounting the one that unity uses equals five conversions & one non conversion, also presuming all notation is written x,y,z irrespective of direction.
(more…)

By |July 6th, 2011|Unity 3D|Comments Off on Cartesian coordinate conversion Unity3d

Marquee / Rectangle GameObject Selection

I had queried this problem many times in the past but never needed to try and solve it until this week. The problem with selecting object/s via given screen rect coordinates within Unity is that if your camera’s view is not orthographic…which in most cases it isn’t, your rectangle, projected collision detection or raycast will need to take the form of a trapezoid shape i.e. matching the camera frustrum, fanning out from the screen rectangle.

You could create a mesh of this shape and try some sort of collision detection, but perhaps if you are using many mesh colliders this may not be an easy task and carry too much overhead.

Here are two pretty useful functions that will solve this task, both functions take two screen coordinates in the form of Vector3’s (as in Input.mousePosition), and an array of GameObjects to test against however they return different results:-

The first function returns an array of GameObjects where the center of the GO’s renderer bounds is within the camera projected rectangle/trapezoid – This method is probably only useful on small non-enclosed meshes however it does allow the user not to have to completely surround objects with the marquee.

The second function returns an array of GameObjects where the meshes local OBB points are within the camera projected rectangle – This method provides much more accuracy with selection however an objects bounds must be completely encompassed by the given screen rect.
(more…)

By |July 5th, 2011|Unity 3D|Comments Off on Marquee / Rectangle GameObject Selection

Move Vertices / Vector3 Without Transform

This post is just a quick reminder to myself and for anyone else who’s brain seems to freeze when it comes to moving vertices / vector3 positions around in code for whatever reason without using a transform component, in this post i’m not going to write about any of the complexities or inner workings behind the readily available Unity3d Matrix functions, but the code below has proved usefull when writing import functions for 3d mesh/models. I’m sure there are quicker methods and i’d love to hear about them.

The code below takes a Vector3 (position.x,position.y,position.z) and translates, rotates and scales it according to your own input using a matrix (exactly like the Unity3d Transform in the inspector) you could run the code in a loop multiplying a sequence of vector3[] vertices through it and offset your mesh from its original (pivot point)/origin if you so wished. The code is a short example written in c#:-

(more…)

By |February 21st, 2011|Unity 3D|1 Comment

Normal / Bump Mesh Tangent Generation

If you are generating meshes or importing meshes at runtime you may stumble upon the problem of generating tangents for your mesh. Normal / bumped shaders require that tangent plane basis vectors be calculated for each vertex in your mesh to correctly light or effect your mesh in a consistant manner.

I did some digging and found this code on the unity3d forum (unfortunately their was a slight/tiny error on the c# version) so I thought I would post the working version here for reference. I have also added some ammendments which also apparently calculate bi-normals or bit-tangents should you ever find a need. I believe the code may have originated come from here: Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”. Terathon Software 3D Graphics Library, 2001.

(more…)

By |February 16th, 2011|Unity 3D|3 Comments