Skip to content

Instantly share code, notes, and snippets.

View psuong's full-sized avatar

Porrith Suong psuong

View GitHub Profile
@psuong
psuong / ClippedOpaqueMatrix.shader
Created August 19, 2020 22:00
ClippedOpaqueMatrix.shader
Shader "Inwards/URP/ClippedOpaque_Matrix_URP_V2"
{
Properties
{
// Specular vs Metallic workflow
[HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
[MainColor] _BaseColor("Color", Color) = (0.5,0.5,0.5,1)
[MainTexture] _BaseMap("Albedo", 2D) = "white" {}
@psuong
psuong / ClippedOpaque.hlsl
Created August 19, 2020 21:59
ClippedOpaque.hlsl
#ifndef CLIPPED_OPAQUE
#define CLIPPED_OPAQUE
#include "VertexHelpers.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
StructuredBuffer<float4x4> matrixBuffer;
struct Attributes
@psuong
psuong / ForEachExtensions.cs
Last active September 19, 2019 01:54
ForEachExtension methods for more expressive code
// Loop Extensions, but will generate garbage because we'd have to use lambda expressions
public static class LoopExtensions {
// Ex: (2, 5).ForEach(i => { --do some-action-on-this-elem-- }
public static void ForEach(this (int, int) range, Action<int> action)
{
for (int i = range.Item1; i < range.Item2; i++)
{
action(i);
}
@psuong
psuong / PrefabUtils.cs
Last active September 7, 2019 20:56
PrefabUtils Extended
public enum Mode : int {
ConvertAndDestroy = 0,
ConvertAndInjectOriginal = 1
}
// Allows you to just create a copy of the asset and convert it.
public static void ConstructEntityFromPrefab(string name, string folder, Mode mode, out GameObject src) {
src = GetInstantiatedAsset<GameObject>(name, folder).transform.root.gameObject;
switch (mode) {
case Mode.ConvertAndDestroy:
@psuong
psuong / ChargeFXIndicatorSystem.cs
Created February 23, 2019 20:15
Charging a Charge Shot
public class ChargeFXIndicatorSystem : ComponentSystem {
private ComponentGroup particleGroup, playerGroup;
protected override void OnCreateManager() {
particleGroup = GetComponentGroup(ComponentType.ReadOnly<ParticleSystemPair>(), ComponentType.ReadOnly<ID>());
playerGroup = GetComponentGroup(ComponentType.ReadOnly<ChargeShotTimer>(), ComponentType.ReadOnly<ID>());
}
protected override void OnUpdate() {
@psuong
psuong / ArenaTestFixtures.cs
Created February 23, 2019 20:10
Test SetUp for ECS
public class ArenaTestFixtures {
protected World previousWorld;
protected World currentWorld;
protected EntityManager entityManager;
public RetrievalSystem RetrievalSystem {
get => World.Active.GetOrCreateManager<RetrievalSystem>();
}
@psuong
psuong / ChargeFXIndicatorTests.cs
Last active February 23, 2019 20:08
ChargeFXIndicatorTests
private ChargeFXIndicatorSystem indicatorSystem;
private Entity playerEntity;
private ComponentGroup particleGroup, playerGroup;
private GameObject particles, player;
[SetUp]
public override void SetUp() {
base.SetUp();
indicatorSystem = currentWorld.GetOrCreateManager<ChargeFXIndicatorSystem>();
particles = GetInstantiatedAsset<GameObject>("ChargeEffect", "Assets/Prefabs");
@psuong
psuong / PrefabUtility.cs
Last active September 7, 2019 20:41
Prefab Utility to Instantiate a Test Prefab
using UnityEditor;
using UnityEngine;
public static class PrefabUtils {
public static T GetInstantiatedAsset<T>(string searchParams, string folder) where T : Object {
var guids = AssetDatabase.FindAssets(searchParams, new [] { folder });
if (guids.Length != 1) {
throw new System.InvalidOperationException(
$"Found {guids.Length} assets, please narrow down the search result!");