Skip to content

Instantly share code, notes, and snippets.

View abeldantas's full-sized avatar
🔮
Yes!

Abel Dantas abeldantas

🔮
Yes!
View GitHub Profile
@abeldantas
abeldantas / FeatureTests.cs
Last active October 9, 2023 08:15
Quickstart Unity C# test template. Not perfect, but gets you testing now.
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
// Namespace should mirror the implementation namespace with a '.Tests' suffix.
// If the implementation is under 'MyCompany.FeatureScope', then tests should be 'MyCompany.Tests.FeatureScope'.
namespace MyCompany.Tests.FeatureScope
{
@abeldantas
abeldantas / Singleton.cs
Last active October 27, 2023 08:21
Basic singleton for C# Unity
using System;
using UnityEngine;
public abstract class Singleton<T> : MonoBehaviour, IDisposable where T : Singleton<T>
{
public static T Instance { get; protected set; }
void Awake()
{
if ( Instance != null && Instance != this )
@abeldantas
abeldantas / txn.json
Created January 22, 2022 18:21
Bitcoin transaction. vout are the transaction outputs. vin are the inputs. The scriptPubKey on the vouts will be unlocked with scriptSig of vin of a future transaction.
{
"version": 1,
"locktime": 0,
"vin": [
{
"txid": "7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18",
"vout": 0,
"scriptSig" : "3045022100884d142d86652a3f47ba4746ec719bbfbd040a570b1deccbb6498c75c4ae24cb02204b9f039ff08df09cbe9f6addac960298cad530a863ea8f53982c09db8f6e3813[ALL] 0484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adf",
"sequence": 4294967295
}
using UnityEngine;
public class Animal<T> : MonoBehaviour
{
public new T Injector;
}
public class Horse : Animal<ISteroidsInjector>
{
}
@abeldantas
abeldantas / CreateGameAsync.cs
Created February 27, 2019 21:52
CreateGameAsync.cs
IEnumerator CreateGameAsync()
{
StartCoroutine( GetUsernameFromIdAsync( OpponentName.text, (id, isUsernameValid) =>
{
if ( !isUsernameValid )
{
FadeScreen.FadeBack();
GameCreationError.SetActive( true );
StartCoroutine( CoroutineHelper.WaitAndDo( 3.5f, () => { ShowMenu.OnClick(); } ) );
}
Transaction CreateUtxoSpendTxn( string rawUtxo, byte[][] msg )
{
var utxo = JsonConvert.DeserializeObject<UTXO>( rawUtxo );
Debug.Log( rawUtxo );
var coin = new Coin( new uint256( utxo.TxId), (uint)utxo.OutputIndex, utxo.Satoshis, bitcoinSecret.ScriptPubKey );
var txnBuilder = NBitcoin.Altcoins.BCash.Instance.Mainnet.CreateTransactionBuilder();
return txnBuilder
.AddCoins( coin )
.AddKeys( bitcoinSecret )
#!/bin/sh
FILE=$(find . -name '*.asm.framework.unityweb' -exec basename {} +)
echo 'fixed '$FILE
mv $FILE $FILE.gz
gunzip $FILE.gz
gsed -i.bak 's#function _JS_Sound_Init(){try{window.AudioContext=window.AudioContext||window.webkitAudioContext;WEBAudio.audioContext=new AudioContext;WEBAudio.audioWebEnabled=1}catch(e){alert("Web Audio API is not supported in this browser")}}#function _JS_Sound_Init(){try{window.AudioContext=window.AudioContext||window.webkitAudioContext;WEBAudio.audioContext=new AudioContext();var tryToResumeAudioContext=function(){if(WEBAudio.audioContext.state==="suspended")WEBAudio.audioContext.resume();else{clearInterval(resumeInterval)}};var resumeInterval=setInterval(tryToResumeAudioContext,400);WEBAudio.audioWebEnabled=1}catch(e){alert("Web Audio API is not supported in this browser")}}#g' $FILE
rm $FILE.bak
gzip --best $FILE
mv $FILE.gz $FILE
using System.Collections.Generic;
using System.Linq;
using FullInspector;
using MathUtils;
using UnityEngine.UI;
public class FadeGraphics : BaseBehavior
{
public Dictionary<float, List<Graphic>> GraphicFinalAlphaMap;
@abeldantas
abeldantas / FindMonobehaviourInScene.cs
Created April 24, 2018 15:38
Find Monobehaviour In Scene
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class FindMonobehaviourInScene
{
[MenuItem( "Editor Utils/Select Script in Scene #&s" )] public static void SelectScriptInScene()
@abeldantas
abeldantas / AdManager.cs
Created March 2, 2017 11:57
Hit'n'run - Showing ads with supersonic
using System;
using UnityEngine;
public class AdManager : GameObjectSingleton<AdManager>
{
public string appKey = "3fbb9d89";
bool hasRewardBeenGiven;
Action onSuccess;
Action onCanceled;