- Developers should agree on a standard for code formatting. Goal: a developer should be able to look at a class and not be able to determine who wrote it. Makes it easier for developers to fix eachother's bugs.
- Not everything needs to be a MonoBehaviour
- Gain control of the startup sequence of the scene. Do not blindly rely on Awake and Start.
- If a class has a public property that needs it's reference set in the Inspector, provide valuable feedback when the property is null so that other developers, and your future you, knows how to fix the problem when you forget to set the value.
- Think about code reuse, but don't be fanatic about it. Split your code into multiple generic classes that can be reused in other parts of the game, and possibly future games.
- Think about performance, but don't try to fix a problem before it actually is a problem. Premature optimizations always eats up much more of your time than you think. Don't be sloppy about it. You don't want to paint yourself into a corner and have t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| // With very little effort, the previous code (behaviour.js) has | |
| // been refitted to become a standalone component that handles | |
| // pausing and unpausing of the current scene. It also adds the | |
| // extra option of starting the game in a paused or unpaused | |
| // state. | |
| // The Pause function was set to be public to make it accessible |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class Player : MonoBehaviour { | |
| void OnTriggerEnter() { | |
| transform = SpawnPoint.Coordinate; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEditor; | |
| using UnityEngine; | |
| using System; | |
| [CustomEditor(typeof(MonoScript))] | |
| public class ScriptInspector : Editor { | |
| public override void OnInspectorGUI() { | |
| MonoScript ms = target as MonoScript; | |
| Type type = ms.GetClass(); |
Taken from Jerry Weinberg's book The Psychology of Computer Programming
- Understand and accept that you will make mistakes. The point is to find them early, before they make it into production. Fortunately, except for the few of us developing rocket guidance software at JPL, mistakes are rarely fatal in our industry. We can, and should, learn, laugh, and move on.
- You are not your code. Remember that the entire point of a review is to find problems, and problems will be found. Don’t take it personally when one is uncovered.
- No matter how much “karate” you know, someone else will always know more. Such an individual can teach you some new moves if you ask. Seek and accept input from others, especially when you think it’s not needed.
- Don’t rewrite code without consultation. There’s a fine line between “fixing code” and “rewriting code.” Know the difference, and pursue stylistic changes within the framework of a code review, not as
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| // Nine slice scaling using a Mesh. | |
| // Original code by Asher Vollmer | |
| // https://twitter.com/AsherVo | |
| // http://ashervollmer.tumblr.com | |
| // Modifications by Thomas Viktil | |
| // https://twitter.com/mandarinx | |
| // http://ma.ndar.in/ |
This script requires the Nine Slice Scaling script from https://gist.github.com/mandarinx/06192ee17d68c528edb9
Each update a ray is cast on a plane, based on the mouse cursor position. The hit point is snapped to a grid defined by unitSize and gridSize. The distance between the grid index of mouse click and index of mouse release is used to calculate the area of selection.
From: http://unity3d.com/learn/resources/performance-optimization-tips-and-tricks-unity
- Transform.position iterates the transform hierarchy and does matrix multiplications to find the global position of the transform. Cache position for faster access.
- Culling algorithms can be more effective than trying to lower draw calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using System.Linq; | |
| public class GearRotator : MonoBehaviour | |
| { | |
| [SerializeField] private float m_radiusThreshold = 4f; | |
| private float m_startingAngle; | |
| private Quaternion m_startingRotation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| using UnityEngine.Events; | |
| namespace Cluster { | |
| public class CollisionCall : MonoBehaviour { | |
| public LayerMask layerMask = -1; |