Skip to content

Instantly share code, notes, and snippets.

View Demkeys's full-sized avatar
💭
Always learning and sharing knowledge

Abhinav a.k.a Demkeys Demkeys

💭
Always learning and sharing knowledge
View GitHub Profile
@Demkeys
Demkeys / GameobjectSelectorWindow.cs
Last active April 23, 2018 17:45
GameobjectSelector
/// <summary>
/// -----------------------------
/// Gameobject selector window
/// -----------------------------
/// Make sure to place this script in the Editor folder. To open the window click 'MyTools/GameobjectSelector'.
/// This window lets you assign a gameobject to the ObjectToSelect field. Once a gameobject is assigned, if the gameobject
/// has any child gameobjects, four buttons will show up, giving you the following options.
/// 1.Select Parent gameobject
/// 2.Select First child gameobject
/// 3.Select Last child gameobject
@Demkeys
Demkeys / TransformChanges.cs
Created October 26, 2017 08:18
Store Transform PlayMode Changes
/// <summary>
/// -----------------------------
/// Transform Changes tool
/// -----------------------------
/// This is a simple tool that allows you to store any changes made to the Position, Rotation and Scale of all Gameobjects in the scene
/// during PlayMode, and apply those changes to all the Gameobjects after exiting PlayMode.
/// Instructions:
/// -Place this script in the Editor folder in your project. Then the 'MyTools' menu should appear in your MenuBar with the
/// Store and Apply options.
/// -Enter PlayMode. Make changes to the Postion, Rotation and Scale of gameobjects in the scene. Click 'MyTools/Store Transform PlayMode Changes'.
@Demkeys
Demkeys / CircleGenScript01.cs
Created April 16, 2018 11:48
Simple script that procedurally generates a circle of spheres, and then updates the position of those spheres every frame to form patterns.
// Just something fun I came up with when learning Trigonometry.
// Attach this script to an empty gameobject and enter Play Mode. A circle of spheres will be created. All the spheres will be
// children of the gameobject that this script is attached to. When you hit the Spacebar key, the position of each sphere will
// start updating and from that point on, every frame the positions will be updated to form patterns.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CircleGenScript01 : MonoBehaviour {
@Demkeys
Demkeys / GridSnapper.cs
Last active October 24, 2018 11:33
Simple Grid Snapper script to show how the Grid component can be used to align GameObjects along the cells of a Grid.
/// <summary>
/// - Make sure you have a Grid GameObject (any GameObject with a Grid component attached to it) in the scene.
/// - Attach this script to the GameObject you wanna snap to the Grid. Then drag and drop the Grid
/// GameObject into the AttachedGrid field to create a reference to the Grid component attached to it.
/// - Enter Play Mode, and then every time you hit the Space key, this GameObject will move 1 unit
/// down along the Y axis, while remaining snapped to the Grid.
/// </summary>
using System.Collections;
using System.Collections.Generic;
@Demkeys
Demkeys / MuteTimelineTracksScript.cs
Created June 29, 2018 13:59
Example code showing how to mute Tracks in a Timeline asset.
/// <summary>
/// Instructions
/// - Create a Timeline asset. Add 3 tracks to it.
/// - Create empty GameObject in scene. Attach this script to the GameObject. Then attach a PlayableDirector component to it.
/// Drag and drop the Timeline asset you created into the Playable field of the PlayableDirector.
/// - Hit Play. The 1, 2 and 3 keys on your keyboard mute the first, second and third tracks respectively.
/// </summary>
using System.Collections;
using System.Collections.Generic;
@Demkeys
Demkeys / ScreencapScript.cs
Last active August 5, 2018 23:59
Simple example showing how to use the Screencapture class.
/// <summary>
/// Attach this script to any gameobject in the scene, enter Play Mode, then hit Space on your keyboard to capture a screenshot.
/// Exit Play Mode, refresh the Project panel, and the scenecap image should be in the Assets folder.
/// </summary>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScreencapScript : MonoBehaviour {
@Demkeys
Demkeys / KeyEventComparer.cs
Created August 30, 2018 07:51
KeyEventComparer for GOTO Logic
using System;
using UnityEngine;
namespace GOTO.Logic.Comparers
{
[Serializable]
[ComparerCategory("Comparer")]
public class KeyEventComparer : Comparer
{
public enum KeyEventType { KeyDown, KeyUp, KeyPress };
@Demkeys
Demkeys / JsonExample01.cs
Last active October 2, 2018 07:50
Examples showing how to serialize and deserialize data in Unity
// Attach this script to a gameobject in the scene. myChar01 is serialized into JSON and stored
// in a string. Then the JSON is deserialized and cast to Character type, and stored into myChar02.
// The data of myChar02 can be seen in the Inspector.
using UnityEngine;
public class JsonExample01 : MonoBehaviour {
public Character myChar01;
public Character myChar02;
@Demkeys
Demkeys / JsonExample02.cs
Created October 2, 2018 07:51
Example showing how to serialize and deserialize arrays of data in Unty
// Attach this script to a gameobject in the scene. objectDetails01 is serialized into JSON and stored
// in a string. Then the JSON string is deserialized and cast to ObjectDetails type, and stored into
// objectDetails02. The data of objectDetails02 can be seen in the Inspector.
using UnityEngine;
public class JsonExample02 : MonoBehaviour {
public ObjectDetails objectDetails01;
public ObjectDetails objectDetails02;
@Demkeys
Demkeys / BoolArrayToBitString.cs
Last active October 17, 2018 02:42
Example code for Unity, demonstrating how to pack a bool array into a string and unpack a string in a bool array.
/// <summary>
/// This script demonstrates how to convert a bool array to a string of bits and convert a string of bits to a bool array.
/// Usage:
/// - Attach this script to an empty gameobject. From the Inspector set the values of the items in the bool array.
/// - Enter Play Mode.
/// - Hit 'a' key, the values of the bool array will be converted to a bit string.
/// - Hit 's' key, bit string will be converted into a bool array.
/// </summary>
using UnityEngine;