Skip to content

Instantly share code, notes, and snippets.

View agrawalsuneet's full-sized avatar
🎲
Busy building games

Suneet Agrawal agrawalsuneet

🎲
Busy building games
View GitHub Profile
#!/usr/bin/env bash
# NB: local trial script has to be self-contained
# See https://sipb.mit.edu/doc/safe-shell/
set -euf -o pipefail
if [[ "$OSTYPE" == "linux-gnu" ]]; then
export MAYBE_SUDO="sudo"
else
export MAYBE_SUDO=""
@agrawalsuneet
agrawalsuneet / UserDefaults+Codable.swift
Last active April 10, 2022 03:22
Easy way to store codables into UserDefaults
//MARK: - UserDefaults + Codable
extension UserDefaults {
func storeCodable<T: Codable>(_ object: T, key: String) {
do {
let data = try JSONEncoder().encode(object)
UserDefaults.standard.set(data, forKey: key)
} catch let error {
print("Error encoding: \(error)")
}
}
@agrawalsuneet
agrawalsuneet / UISwitch+SwitchChangeListener.swift
Last active March 30, 2022 13:11
Extension to UISwitch to add switch value change event in a clean way
//MARK: - UISwitch Extension
@available(iOS 14.0, *)
extension UISwitch {
func setOnValueChangeListener(onValueChanged :@escaping () -> Void){
self.addAction(UIAction(){ action in
onValueChanged()
}, for: .valueChanged)
}
@agrawalsuneet
agrawalsuneet / UITextField+TextChangeListener.swift
Last active March 9, 2022 15:18
Extension to UITextField to add editing event in a clean way
//MARK: - UITextField Extension
@available(iOS 14.0, *)
extension UITextField {
func setOnTextChangeListener(onTextChanged :@escaping () -> Void){
self.addAction(UIAction(){ action in
onTextChanged()
}, for: .editingChanged)
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.agrawalsuneet.unitysharingclient" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="@style/UnityThemeSelector" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:isGame="true" android:banner="@drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
<intent-filter>
<action andro
using UnityEngine;
using UnityEngine.UI;
public class AcceptIncomingTextInUnity : MonoBehaviour
{
public Button acceptIncomingTextBtn;
void Start()
{
acceptIncomingTextBtn.onClick.AddListener(onAcceptImageClicked);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.agrawalsuneet.unitysharingclient" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="@style/UnityThemeSelector" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:isGame="true" android:banner="@drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
<intent-filter>
<action andro
using UnityEngine;
public class CastToJavaObject : MonoBehaviour
{
//C# Code
public AndroidJavaObject castToJavaObject(AndroidJavaObject source, string className)
{
var clazz = new AndroidJavaClass("java.lang.Class");
var destClass = clazz.CallStatic<AndroidJavaObject>("forName", className);
return destClass.Call<AndroidJavaObject>("cast", source);
//
// UIView+ClickListener.swift
//
// Created by Suneet Agrawal on 12/12/20.
//
import UIKit
// MARK: ClickListener
class ClickListener: UITapGestureRecognizer {
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class NativeAndroidWhatsappContactDirectShare : MonoBehaviour {
public Button shareButton;
private string packageName = "com.whatsapp";