Skip to content

Instantly share code, notes, and snippets.

View Guendeli's full-sized avatar

Guendeli Omar Guendeli

  • Ubisoft
  • Abu Dhabi - UAE
View GitHub Profile
@Guendeli
Guendeli / Pool.cs
Created April 24, 2019 19:39
Object pooler
/// Usage:
///
/// There's no need to do any special setup of any kind.
///
/// Instead of calling Instantiate(), use this:
/// SimplePool.Spawn(somePrefab, somePosition, someRotation);
///
/// Instead of destroying an object, use this:
/// SimplePool.Despawn(myGameObject);
///
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
public class AnimatedUnitCompressor : EditorWindow {
Vector2 scrollPos = Vector2.zero;
public List<GameObject> UnitPrefabs;
public static string BonePrefix;
private SerializedObject _serializedObject;
@Guendeli
Guendeli / MemoryTips.cs
Last active April 15, 2021 12:35
Memory Conservation tips for Unity
// Let's talk about memory conservation
// If a Unity API returns an array, it allocates a new copy.
// Every time it is accessed, Even if the values do not change.
// Bad Sample 1: this code allocate too many Arrays
for ( int i = 0;i < Input.touches.Length; i++ ) // Get() accessor call + creating copy
{
Touch touch = Input.touches[i]; // Creating copy
// …
}
@Guendeli
Guendeli / Utils_Perf.cs
Last active April 15, 2021 12:55
Performance Utility variables with no accessor functions and bybe by byte string comparison
/// <summary>
/// Performance utility code
/// </summary>
public class Utils_Perf
{
/// <summary>
/// Static values with no accessor functions to slow them down.
/// Actually calling Vector3.zero is like calling New Vector3(0,0,0)
/// About 4x faster than Vector3.zero
using UnityEngine;
using System;
namespace GokUtil.UpdateManager
{
public class UpdateManager : MonoBehaviour
{
const int InitialSize = 16;
private int tail = 0;
@Guendeli
Guendeli / AwesomeUtils.cs
Last active April 14, 2024 21:38
Cool Utility class extending various Unity3D functions in: Screenshots, Mathf, Animator, PlayerPrefs, Color etc..
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
/*
* AWESOME UTILS TO SAVE YOUR DAY
* These codes were aggregated from personnal codebase as well
* as some Stack / Unity threads
@Guendeli
Guendeli / NonSenseGenerator.cs
Created January 5, 2017 01:29
Generates funny texts to show for your loading screens.
public class NonSenseGenerator : MonoBehaviour {
string[] n = new string[71];
string[] v = new string[71];
// Use this for initialization
void Start () {
SetNoun();
SetVerb();
}
@Guendeli
Guendeli / TextureCache.cs
Last active April 15, 2021 12:37
Unity offer no method to Load from file or Download besides AssetBundles, here is a class to Cache stuff into the persistent file path, then check if it exists before calling a WWW to download.
using UnityEngine;
using System;
using System.Collections;
using System.IO;
/// <summary>
///
/// </summary>
public class TextureCache
{
@Guendeli
Guendeli / ToastMessage.cs
Created September 28, 2016 10:08
a script to show Toast Messages on Android Unity3D Apps
using UnityEngine;
public class ToastMessage : MonoBehaviour
{
string toastString;
string input;
AndroidJavaObject currentActivity;
AndroidJavaClass UnityPlayer;
AndroidJavaObject context;
@Guendeli
Guendeli / Global Event System.cs
Last active April 15, 2021 12:35
a non-generic abstract base class which serves only the purpose of storing all the generic subclasses inside a common list
using System;
using System.Collections.Generic;
//----------------------------
// Some interesting shit is going on here
// We have a non-generic abstract base class which serves only the purpose of storing all the generic
// subclasses inside a common list (you'll see one in the GlobalEventSystemMaitenance class).
// Different events inside the EventSystem.Events namespace (and folder) are just statically typed
// entities used to differentiate the events one from another
//----------------------------