Skip to content

Instantly share code, notes, and snippets.

@GeorgiyRyaposov
GeorgiyRyaposov / UnityToCubeHex.cs
Created November 18, 2020 06:57
Convert unity hex coords to cube hex coords
private Vector3Int UnityCellToCube(Vector3Int cell)
{
var yCell = cell.x;
var xCell = cell.y;
var x = yCell - (xCell - (xCell & 1)) / 2;
var z = xCell;
var y = -x - z;
return new Vector3Int(x, y, z);
}
private Vector3Int CubeToUnityCell(Vector3Int cube)
@GeorgiyRyaposov
GeorgiyRyaposov / KeyValueAttribute.cs
Created October 9, 2020 04:32
Change displayed name of serialisable item in list
using UnityEngine;
namespace Assets.Game.Utils
{
public class KeyValueAttribute : PropertyAttribute
{
public readonly string PropertyName;
public KeyValueAttribute(string propertyName)
{
private Bounds OrthographicBounds(float orthographicSize)
{
float screenAspect = (float)Screen.width / (float)Screen.height;
float cameraHeight = orthographicSize * 2;
Bounds bounds = new Bounds(
transform.position,
new Vector3(cameraHeight * screenAspect, cameraHeight, 0));
return bounds;
using System;
using System.Collections.Generic;
namespace Prototype.Scripts.Contexts.Common
{
public interface IObserver<T, Tenum> where Tenum : struct, IConvertible
{
void OnContextChanged(T context, Tenum property);
void OnAttached(T context);
void OnDetached();
namespace Assets.Scripts.Tools
{
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class ShuffleBag<T> : IList<T>
{
[SerializeField] private List<T> data = new();
using UnityEngine;
using UnityEngine.UI;
namespace Prototype.Scripts.Utils
{
public static class ScrollRectExtension
{
public static void SnapToChild(this ScrollRect scrollRect, RectTransform child)
{
scrollRect.content.localPosition = GetContentLocalPositionForChild(scrollRect, child);
using UnityEngine;
using System.Collections.Generic;
using System;
using System.Linq;
namespace Assets.Scripts.Domain.Localization
{
[CreateAssetMenu(fileName = "Localization", menuName = "Data/Localization")]
public class LocalizationItem : ScriptableObject
{
private float FindPercentage(float input, float min, float max)
{
return ((input - min)) / (max - min);
}
@GeorgiyRyaposov
GeorgiyRyaposov / ActionsQueue.cs
Last active September 8, 2018 03:25
Trigger actions\coroutines by order
namespace Assets.Scripts.Domain.Systems
{
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class ActionsQueue : MonoBehaviour
{
protected static ActionsQueue _instance;
@GeorgiyRyaposov
GeorgiyRyaposov / ImportHelper.cs
Last active September 4, 2018 07:03
Reimport png with settings
[MenuItem("Custom tools/import icons")]
public static void ImportIcons()
{
var rootPath = Path.Combine(Application.dataPath, "Resources/text_icons/");
var icons = Directory.GetFiles(rootPath, "*.png", SearchOption.AllDirectories);
if (icons.Length == 0)
{
UnityEngine.Debug.Log("Failed to find icons");
return;
}