Skip to content

Instantly share code, notes, and snippets.

@johans2
johans2 / FullStateMachineExample.cs
Created February 19, 2021 10:38
Hierarchical statemachine setup example.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HFSM;
public class MoveState : StateMachine {
protected override void OnUpdate() {
Debug.Log("Updating MoveState");
}
}
@johans2
johans2 / LoadStatesExample.cs
Created February 19, 2021 10:14
Load states example
moveState.LoadSubState(runState);
moveState.LoadSubState(jumpState);
public void LoadSubState(StateMachine subState) {
...
}
@johans2
johans2 / StateMachineStateExample.cs
Created February 19, 2021 09:31
StateMachine example state.
public class RunState : StateMachine {
protected override void OnEnter() {
Debug.Log("Enter RunState");
}
protected override void OnUpdate() {
Debug.Log("Updating RunState");
}
protected override void OnExit() {
@johans2
johans2 / StateMachineAddTransitionMethod.cs
Last active February 19, 2021 09:24
Add transition method signature of hierarchical statemachine.
public void AddTransition(StateMachine from, StateMachine to, int trigger) {
...
}
@johans2
johans2 / StateMachine.cs
Created February 16, 2021 22:59
Hierarchical State Machine
using System;
using System.Collections.Generic;
namespace HFSM {
public abstract class StateMachine {
private StateMachine currentSubState;
private StateMachine defaultSubState;
private StateMachine parent;
func (r *renderer) setData(verts []float32, material material)
#version 330
in vec2 fragTexCoord;
in vec3 fragNormal;
in vec3 fragWorldPos;
uniform vec3 color;
uniform float specPower;
uniform sampler2D cellRampDiffuse;
uniform sampler2D cellRampSpecular;
float GetSpaceDistortionLerpValue(float schwarzschildRadius, float distanceToSingularity, float spaceDistortion) {
return pow(schwarzschildRadius, spaceDistortion) / pow(distanceToSingularity, spaceDistortion);
}
// Created by Johan Svensson. https://medium.com/dotcrossdot
// Slightly modified version of http://flafla2.github.io/2016/10/01/raymarching.html
// Most shader properties are moved to the material instead for better control.
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Effects/Raymarch (Generic)")]