Skip to content

Instantly share code, notes, and snippets.

@pelengami
pelengami / .cs
Created September 13, 2018 14:44
Unity Particles Orbital Movement
[ExecuteInEditMode]
[RequireComponent(typeof(ParticleSystem))]
public sealed class ParticlesOrbitalMovement : MonoBehaviour
{
public float MinSpeed;
public float MaxSpeed;
private ParticleSystem _particleSystem;
private ParticleSystem.Particle[] _particles;
private Dictionary<int, OrbitalParticleData> _orbitalParticleDatas;
@pelengami
pelengami / TextureAnimation.shader
Created June 29, 2017 15:10 — forked from mattatz/TextureAnimation.shader
Texture animation shader for Unity.
Shader "Mattatz/TextureAnimation"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
_Cols ("Cols Count", Int) = 5
_Rows ("Rows Count", Int) = 3
_Frame ("Per Frame Length", Float) = 0.5
@pelengami
pelengami / .rs
Created May 9, 2017 13:59
Get images path in directory
fn get_images_paths(directoryPath: &String) -> Vec<String> {
let mut res_paths = vec!();
let paths = fs::read_dir(directoryPath).unwrap();
for img_path in paths {
let path = img_path.unwrap().path();
let extension = {
let extension = path.extension();
pub fn clone_into_array<A, T>(slice: &[T]) -> A
where A: Sized + Default + AsMut<[T]>,
T: Clone
{
let mut arr = Default::default();
<A as AsMut<[T]>>::as_mut(&mut arr).clone_from_slice(slice);
arr
}
pub fn shuffle_create_new<T: Clone>(vec: &[T]) -> Vec<T> {
@pelengami
pelengami / .cs
Created March 22, 2017 11:51
Get available udp port
public bool TryGetAvailablePort(out int availableUdpPort)
{
var activeUdpListeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners();
var range = Enumerable.Range(5000, 6000);
availableUdpPort = range.First(p => activeUdpListeners.All(l => l.Port != p));
return availableUdpPort != -1;
}
@pelengami
pelengami / .cs
Created February 21, 2017 06:18
Repeater
public static class Repeater
{
public static async Task DoInfinityAsync(Action action, TimeSpan interval, CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
try
{
action();
await Task.Delay(interval, cancellationToken);
@pelengami
pelengami / .cs
Created February 19, 2017 18:01
Get Available Ip Addresses
public static IEnumerable<IPAddress> GetIpAddressesFromNetworkAdapters(AddressFamily addressFamily)
{
var networkInterfaces = from networkInterface in NetworkInterface.GetAllNetworkInterfaces()
where networkInterface.OperationalStatus == OperationalStatus.Up &&
networkInterface.SupportsMulticast &&
(networkInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||
networkInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
select new
{
name = networkInterface.Name,
@pelengami
pelengami / .cs
Created February 16, 2017 06:10
Get first available udp port
public bool TryGetFirstAvailableUdpPort(out int port)
{
var startingAtPort = 5678;
var maxNumberOfPortsToCheck = 500;
var range = Enumerable.Range(startingAtPort, maxNumberOfPortsToCheck).ToList();
var portsInUse =
from p in range
join used in System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners()
on p equals used.Port