Skip to content

Instantly share code, notes, and snippets.

View iamgabrielma's full-sized avatar

Gabriel Maldonado iamgabrielma

View GitHub Profile
@iamgabrielma
iamgabrielma / CalculateEntityClosestFOV.cs
Created June 23, 2019 08:30
Calculates the closest FOV of an entity list
void CalculateEntityClosestFOV(List<Entity> _listOfEntities) {
// We iterate through each item of the Entity list that was passed as an argument
foreach (var enemy in _listOfEntities)
{
// If entity != null, proceed
if (enemy != null)
{
// Get its position and set some constants that will create the quadrant around the entity:
Vector3 _entityLocation = new Vector3(enemy.entityLocation.x, enemy.entityLocation.y, 0);
@iamgabrielma
iamgabrielma / h_msMethodAnalysis.cs
Created June 19, 2019 06:19
Helper function to calculate how many milliseconds takes a method from start to finish
using System.Diagnostics; // enables System.Diagnostics.StopWatch
using System; // enables System.TimeSPan
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Your function here
stopwatch.Stop();
TimeSpan ts = stopwatch.Elapsed;
@iamgabrielma
iamgabrielma / functions.php
Created June 17, 2019 07:10
Disables WPCOM masterbar
function disable_wpcomtoolbar ( $modules ) {
if ( isset( $modules['masterbar'] ) ) {
unset( $modules['masterbar'] );
}
return $modules;
}
add_filter( 'jetpack_get_available_modules', 'disable_wpcomtoolbar' );
@iamgabrielma
iamgabrielma / RoguelikeCameraController.cs
Created June 16, 2019 14:01
Attaches the main camera to the player so it moves with the player.
/* The main problem we try to solve here is that the Main Camera is a game object that is already in place before the Player Entity is generated, so it cannot be assigned as the Player instance is null */
using UnityEngine;
public class CameraController : MonoBehaviour
{
public Transform target; // The Player Transform
private bool isPlayerFound;
void Start()
{
@iamgabrielma
iamgabrielma / _debug_helper_functions.cs
Created June 12, 2019 12:24
Debug function example: When enabled, 100% chance to create a certain item each time x is triggered
private bool _debug_create_specific_item = true;
// DEBUG: When enabled, 100% chance to create a certain item each time x is triggered
if (_debug_create_specific_item)
{
Debug.Log("###############------+ DEBUG MODE +-----###############");
pickupItemObject = new GameObject("itemName");
itemTag = "itemTag";
SetupPickupItem(pickupItemObject, itemTag, itemSprite);
## in PlayerCollisions.cs , attached to the player game object:
public bool isPlayerTakingDamage;
public void Start(){
isPlayerTakingDamage = false;
}
@iamgabrielma
iamgabrielma / FloatingTextController.cs
Created May 30, 2019 11:59
Creates floating text on events
/* FloatingTextController.cs*/
public class FloatingTextController : MonoBehaviour
{
private static FloatingText popupText;
private static GameObject canvas;
public static void Initialize()
@iamgabrielma
iamgabrielma / MapColorPulse.cs
Created May 29, 2019 01:17
Modifies the alpha value of a GameObject following a pulse rhythm, creating the effect of appear/disappear gradually.
IEnumerator MapColorPulse()
{
bool isLimitReached = false;
map = GameObject.Find("Map");
SpriteRenderer mapRendererComponent = map.GetComponent<SpriteRenderer>();
initialMapAlphaValue = mapRendererComponent.color.a; // 1
//Debug.Log("Initial alpha: " + initialMapAlphaValue); // 1
// Test: Using Find() + new Color for setting up the alpha value:
@iamgabrielma
iamgabrielma / AdManager.cs
Created May 26, 2019 05:21
Ad Manager that deals with Unity Ads between gameplays
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
namespace Ngu
{
public class AdManager : MonoBehaviour
{
/* Atomic V1 & V2 */
if( ( defined( 'PRESSABLE_PROXY' ) && PRESSABLE_PROXY ) || ( defined( 'ATOMIC_PROXY' ) && ATOMIC_PROXY ) ) {
// Your code here
}