Snippets

Sam Gates Great Extension Methods

Created by Sam Gates last modified
using UnityEngine;

public static class Ext
{
    public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
    {
        if (source == null || action == null)
        {
            ConsoleLogger.WriteLine($"IEnumerable source isNull: {source == null}", source == null);
            ConsoleLogger.WriteLine($"Action action isNull: {action == null}", action == null);
            return;
        }
        foreach (var element in source)
        {
            action(element);
        }
    }
    
    public static Vector3 XY(this Vector3 _v, float z = 0f)
    {
        return new Vector3(_v.x, _v.y, z);
    }

    public static Vector3 XZ(this Vector3 _v, float y = 0f)
    {
        return new Vector3(_v.x, y, _v.z);
    }

    public static Vector3 YZ(this Vector3 _v, float x = 0f)
    {
        return new Vector3(x, _v.y, _v.z);
    }

    public static Vector3 X(this Vector3 _v)
    {
        return new Vector3(_v.x, 0, 0);
    }

    public static Vector3 Y(this Vector3 _v)
    {
        return new Vector3(0, _v.y, 0);
    }

    public static Vector3 Z(this Vector3 _v)
    {
        return new Vector3(0, 0, _v.z);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.