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 / EventsExtension.cs
Created February 2, 2018 08:38
Unity3d EventsExtension
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using System.Linq;
using UnityEngine.UI;
public static class EventsExtension
@glebov21
glebov21 / MainThread.cs
Created February 2, 2018 08:42
unity3d MainThread
/* Attach this to any object in your scene, to make it work */
using System;
using System.Collections;
using UnityEngine;
using System.Threading;
public class MainThread : MonoBehaviour
{
private static InvokePump mPump;
@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:88d0a19088741e4723c6d5e9de540dde
Last active March 5, 2020 10:36
unity3d application quit
public static void ExitApp() {
if(Application.isEditor)
UnityEditor.EditorApplication.isPlaying = false;
else if(Application.isMobilePlatform)
System.Diagnostics.Process.GetCurrentProcess().Kill();
else
Application.Quit();
}
@glebov21
glebov21 / gist:0b130ad6e2a7deeb69788797797cfdac
Last active September 12, 2018 07:07
3d linerenderer line
LineRenderer Create3DLineRendererLine(IList<Vector3> points, Transform parentForLine, float width)
{
GameObject line = new GameObject("lineRenderer");
line.transform.parent = parentForLine;
line.layer = parentForLine.gameObject.layer;
line.transform.localPosition = Vector3.zero;
line.transform.localScale = Vector3.one;
LineRenderer lr = line.AddComponent<LineRenderer>();
lr.positionCount = points.Count;
lr.startWidth = width;
@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)