Unity Editor Scripting : If you ever have to create an instance (in hierarchy) from an .fbx file and a prefab from an instance, you can use following commands. 1 .fbx to instance : PrefabUtility . InstantiatePrefab 2 instance to .prefab : PrefabUtility . CreatePrefab Creating AnimatorController file : AssetDatabase . CreateAsset
Conditional Operator / Ternary Operator : condition ? true_expression : false_expression; bool x = condition ? true : false; eg : string result = (percentage >= 36) ? "pass" : "fail" ; -------------------------------------------------------- NullCoalesce (??) int totalMarks = marks ?? 0 ; The ?? operator is called the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand. eg: int ? x = null ; int y = x ?? -1; int? is a shorthand for Nullable, which itself is shorthand of Nullable. eg Nullable a = null; A nullable type can represent the correct range of values for its underlying value type, plus a additional null value. --------------------------------------------------------
Install home-brew if not already installed ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" or ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" sudo brew update brew install ant brew install svn brew install git Install JDK 7 ( If apache doesn't work in Sierra here is a usefull article : https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions)
Great trick for optimization so that code doesn't have to count size of array/list again and again. for ( int i = 0 , count = objectList . Count ; i < count ; i ++) { ....... = objectList [ i ]; if ( .... ) { ........ } }
Recently, I have started working with C# on a project at Disney. This is my first experience using C# professionally and I will start collecting some notes on C# on my blog. 1. Delegates Code Example ( Unity ) : using UnityEngine ; using System . Collections ; public class DelegateExample : MonoBehaviour { // Define and Declare delegate void iAmDelegate (); iAmDelegate delegateOne ; void MethodForCallback ( iAmDelegate callbackFunction ) { callbackFunction (); } void callbackOne () { Debug . Log ( " callback one " ); } ...
To add another generic answer. If you want to map the linear range [A..B] to [C..D], you can apply the following steps: Shift the range so the lower bound is 0. (subract A from both bounds: [ A .. B ] -> [ 0. . B - A ] Scale the range so it is [0..1]. (divide by the upper bound): [ 0. . B - A ] -> [ 0. . 1 ] Scale the range so it has the length of the new range which is D-C. (multiply with D-C): [ 0. . 1 ] -> [ 0. . D - C ] Shift the range so the lower bound is C. (add C to the bounds): [ 0. . D - C ] -> [ C .. D ] Combining this to a single formula, we get: ( D - C )*( X - A ) X ' = ----------- + C ( B - A ) Eg : Normalizing a range of 0.5 ----> 1.0 to 0 ------> 1 A=0.5, B=1, C=0, D=1 you get: ( X - 0.5 ) X ' = ------- = 2X - 1 ( 0.5 ) Note, if you have to convert a lot of X to X', you can change the formula to: ( D - C ) C * B - A * D X ' = --...