Skip to content

Instantly share code, notes, and snippets.

View STARasGAMES's full-sized avatar

Taras STARasGAMES

View GitHub Profile
@STARasGAMES
STARasGAMES / TerrainTreesToSceneObjectsConverter.cs
Created October 24, 2022 16:13
Add this script to your unity terrain object, and at startup it will convert terrain trees into actual scene objects. While in editor it may floode hierarchy, so by default all instantiated trees are hidden and non-selectable. You can change this behavior in the inspector.
using UnityEngine;
namespace Impostors.Utilities
{
public class TerrainTreesToSceneObjectsConverter : MonoBehaviour
{
[SerializeField]
private Terrain _terrain = default;
[SerializeField]
@STARasGAMES
STARasGAMES / EventTriggerExtensions.cs
Created March 1, 2021 19:55
Handy EventTrigger extensions for adding and removing listeners(callbacks) from C# script.
using System;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public static class EventTriggerExtensions
{
public static void AddListener(this EventTrigger eventTrigger, EventTriggerType triggerType,
UnityAction<BaseEventData> call)
{
if (eventTrigger == null)
@STARasGAMES
STARasGAMES / ScriptableObjectVariables.cs
Last active April 18, 2021 06:26
Main classes to implement ScriptableObjects variables workflow. They are not functionaly working, but will give you an overview what should be implemented. Note: there are only generic classes, and you eventually will need to create variants for each variable such as float, int, bool, Transform, Color etc.
public abstract class ReadonlyVariable<TValue> : ScriptableObject
{
public abstract TValue Value { get; }
}
public abstract class Variable<TValue> : ReadonlyVariable<TValue>
{
protected TValue _runtimeValue;
public override TValue Value
{
@STARasGAMES
STARasGAMES / isodata_clustering_for_vectors.py
Last active February 22, 2024 08:48
Very messy and not 100% correct ISODATA clustering algorithm implementation on Python that works with vectors. Source: https://github.com/PyRadar/pyradar/blob/master/pyradar/classifiers/isodata.py
# Very messy and not 100% correct ISODATA clustering algorithm implementation that works with vectors.
# Source: https://github.com/PyRadar/pyradar/blob/master/pyradar/classifiers/isodata.py
# it works only for one-dimensional vectors :-(
# P.S.
# I've made it for university lab that's why you can find test values at the end of the file. (and that's why code so flipping bad XD)
# And I was shocked that there is no complete implementation of this algorithm on the internet o_O.
# Hope this helped:3
@STARasGAMES
STARasGAMES / TerrainGrassWindSettingsSetter.cs
Last active May 23, 2021 18:25
Script responsoble for setting terrain's grass wind settings. It restores default terrain's asset 'TerrainData' after disable so you will not lose your default settings.
using UnityEngine;
namespace Core.Utilities
{
// Creates a new instance of terrain data that can be safely changed.
// Applies wind wettings specified in inspector.
public class TerrainGrassWindSettingsSetter : MonoBehaviour
{
[SerializeField]
private Terrain _terrain;
@STARasGAMES
STARasGAMES / NativeStack.cs
Last active May 17, 2023 09:25
Unity Native Stack implementation
///////////////////////////////////////////////////////////////////////////////////////
// Native queue collection with fixed length. FILO.
// NativeStack<T> supports writing in IJobParallelFor, just use ParallelWriter and AsParallelWriter().
// Not tested to much, works for me with integers and unity 2019.3
//
// Assembled with help of:
// - NativeCounter example (https://docs.unity3d.com/Packages/com.unity.jobs@0.1/manual/custom_job_types.html)
// - How to Make Custom Native Collections (https://jacksondunstan.com/articles/4734)
// - source code of NativeQueue and NativeList