Skip to content

Instantly share code, notes, and snippets.

@glebov21
glebov21 / Binding.cs
Last active January 11, 2017 13:17
Property bindints without strings
public struct Binding
{
//WeakReference for garbige collection
public System.Reflection.PropertyInfo To;
public System.Reflection.PropertyInfo From; //memberinfo, methodinfo
public WeakReference ToSource;
public WeakReference FromSource;
public Delegate Convertation;
}
@glebov21
glebov21 / EventsAggregator.cs
Created February 2, 2018 08:36
EventsAggregator
using Autogramma.CombApp;
using Autogramma.CombApp.Events;
using System;
using System.Collections.Generic;
public class EventsAggregator
{
public abstract class AbstractEventAggregator<TAction>
{
private List<WeakReference> _listeners = new List<WeakReference>();
@glebov21
glebov21 / gist:c882627408a3021ad937c676ddc00ca5
Created February 21, 2018 15:49
Number to Short string
public static string NumToShortStr(this double num)
{
string prefix = string.Empty;
if (num < 0)
prefix = "-";
num = Math.Abs(num);
if (num >= 1000000000000D)
return prefix + (num / 1000000000000D).ToString("0.#").Replace(',', '.') + "T";
if (num >= 1000000000D)
return prefix + (num / 1000000000D).ToString("0.#").Replace(',', '.') + "B";
@glebov21
glebov21 / gist:20dc24da21d497282512ab74df771ac2
Created February 21, 2018 15:51
Color conberter rgb hsv int hex
#region COLOR
static public Color ParseColor(string text, int offset) { return ParseColor24(text, offset); }
static public Color ParseColor24(string text, int offset)
{
int r = (HexToDecimal(text[offset]) << 4) | HexToDecimal(text[offset + 1]);
int g = (HexToDecimal(text[offset + 2]) << 4) | HexToDecimal(text[offset + 3]);
int b = (HexToDecimal(text[offset + 4]) << 4) | HexToDecimal(text[offset + 5]);
float f = 1f / 255f;
return new Color(f * r, f * g, f * b);
@glebov21
glebov21 / gist:04c7b7944ae9af69f01f4a9330abec15
Created February 21, 2018 15:53
Is cursor or touch under ui (unity3d)
public static bool IsCursorOrTouchUnderUI()
{
if (EventSystem.current == null)
return true;
if (EventSystem.current.enabled == false)
return true;
if (EventSystem.current.currentSelectedGameObject != null)
return true;
if (EventSystem.current.IsPointerOverGameObject()) //лишняя и грузит? Если проблем нет, то удалить
return true;
public static string GetTimeLeftString(this TimeSpan timeLeft)
{
var ts = timeLeft;
if (ts.TotalSeconds < 0)
return "...";
var result = string.Format("{0}:{1}", ts.Minutes.ToString("00"), ts.Seconds.ToString("00"));
if (timeLeft.TotalHours > 1d)
@glebov21
glebov21 / MuteButton.cs
Created February 21, 2018 15:55
Mute (unity3d)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
[RequireComponent(typeof(Button))]
public class MuteButton : MonoBehaviour {
float defaultVolume = 1f;
void Awake()
{
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public static class ChangeNotifier
{
private static Dictionary<Type, List<WeakReference>> listeners = new Dictionary<Type, List<WeakReference>>();
private static List<WeakReference> checkersToRemove = new List<WeakReference>();
using UnityEngine;
using System.Collections;
public class ChangeChecker
{
private bool isUpdated = false;
public bool IsUpdated
{
get
@glebov21
glebov21 / gist:5b0146d67f115fbd526842f295953729
Created February 21, 2018 15:58
WebGL set parameter (low memery) (unity3d)
using UnityEngine;
using System.Collections;
using UnityEditor;
public class WebGL : MonoBehaviour
{
[MenuItem("Tools/SetWebGLParameter")]
public static void SetWebGLParameter()
{
PlayerSettings.SetPropertyString("emscriptenArgs", "-s ALLOW_MEMORY_GROWTH=1 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=2", BuildTargetGroup.WebGL);