Skip to content

Instantly share code, notes, and snippets.

View mandarinx's full-sized avatar

Thomas Viktil mandarinx

View GitHub Profile
@mandarinx
mandarinx / GamePauser.cs
Last active October 21, 2022 23:53
Feedback1
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
@mandarinx
mandarinx / Player.cs
Last active October 21, 2022 23:52
Rudimentary spawnpoint
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
void OnTriggerEnter() {
transform = SpawnPoint.Coordinate;
}
}
@mandarinx
mandarinx / bestpractice.md
Last active November 1, 2021 17:28
Unity best practice when working in teams
  • 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
@mandarinx
mandarinx / ScriptableObjectInspector.cs
Created February 24, 2015 21:50
Unity inspector for ScriptableObjects
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();
@mandarinx
mandarinx / ten_commandments.md
Last active August 29, 2015 14:19
The ten commandments of egoless programming

Taken from Jerry Weinberg's book The Psychology of Computer Programming

  1. 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.
  2. 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.
  3. 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.
  4. 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
@mandarinx
mandarinx / NineSliceScaling.cs
Last active July 22, 2022 02:43
9 slice scaling with a mesh in Unity3D
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/
@mandarinx
mandarinx / Comments.md
Last active August 29, 2015 14:26
Marquee selection in Unity3D

This script requires the Nine Slice Scaling script from https://gist.github.com/mandarinx/06192ee17d68c528edb9

How this works

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.

Note

@mandarinx
mandarinx / performance.md
Created August 18, 2015 08:35
Unity3D performance notes
@mandarinx
mandarinx / GearRotator.cs
Last active August 29, 2015 14:28 — forked from LordNed/GearRotator.cs
A quick example of creating a gear or object that can spin with mouse cursor. Expects object to rotate along its Forward vector.
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;
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
namespace Cluster {
public class CollisionCall : MonoBehaviour {
public LayerMask layerMask = -1;