Skip to content

Instantly share code, notes, and snippets.

@mh-studios
mh-studios / SpatialHashGrid.cs
Created February 9, 2024 11:02 — forked from knowlife4/SpatialHashGrid.cs
Spatial Hash Grid for the Unity Game Engine.
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
public class SpatialHashGrid<T> where T : MonoBehaviour
{
public SpatialHashGrid(int xSize, int ySize, int zSize) => CellSize = new int3(xSize, ySize, zSize);
public SpatialHashGrid(int3 cellSize) => CellSize = cellSize;
@mh-studios
mh-studios / ScrollViewFocusFunctions.cs
Created March 3, 2023 11:44 — forked from yasirkula/ScrollViewFocusFunctions.cs
Focus/center Scroll View to the specified point/item in Unity
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public static class ScrollViewFocusFunctions
{
public static Vector2 CalculateFocusedScrollPosition( this ScrollRect scrollView, Vector2 focusPoint )
{
Vector2 contentSize = scrollView.content.rect.size;
Vector2 viewportSize = ( (RectTransform) scrollView.content.parent ).rect.size;