text:
fileFormatVersion: 2
guid: 66469b0b04212454284a1a73d31edc24
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:

repo_name: keijiro/Khoreo

repo_language: C#

mime_type: text/x-c++


text:
fileFormatVersion: 2
guid: 2e95996f313e4524fb366bc4670c36bb
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 610c20d3b39c7fc41a92c0c24189882a
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 03ab38bf488316f41a83086900c16cd2
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 1077b26a90745044ead3a9bb041aa16f
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: a4c0542e75065254d90fd6ab85f431ea
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 357c7fcd36a3e3841a4054b474b87d21
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 7b6479b1e8c2d81419144be19ae9a1f3
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 57526457cbb53bc4fbcb5b6707cd779e
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEditor;

namespace Khoreo
{
    [CustomEditor(typeof(FloatValueAnimation)), CanEditMultipleObjects]
    sealed class FloatValueAnimationEditor : Editor
    {
        SerializedProperty _curve;
        SerializedProperty _speed;
        SerializedProperty _trigger;
        SerializedProperty _event;

        void OnEnable()
        {
            _curve   = serializedObject.FindProperty("_curve");
            _speed   = serializedObject.FindProperty("_speed");
            _trigger = serializedObject.FindProperty("_trigger");
            _event   = serializedObject.FindProperty("_event");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(_curve);
            EditorGUILayout.PropertyField(_speed);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_trigger);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_event);
            serializedObject.ApplyModifiedProperties();
        }
    }
}


text:
fileFormatVersion: 2
guid: c70b831c659378e40abcd4c16c0360ec
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEditor;

namespace Khoreo
{
    [CustomEditor(typeof(VolumeWeightRandomizer)), CanEditMultipleObjects]
    sealed class VolumeWeightRandomizerEditor : Editor
    {
        SerializedProperty _volume;
        SerializedProperty _trigger;
        SerializedProperty _reset;

        void OnEnable()
        {
            _volume  = serializedObject.FindProperty("_volume");
            _trigger = serializedObject.FindProperty("_trigger");
            _reset   = serializedObject.FindProperty("_reset");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(_volume);

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(_trigger);

            if (EditorApplication.isPlaying && GUILayout.Button("Trigger"))
                ((VolumeWeightRandomizer)target).Randomize();

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(_reset);

            if (EditorApplication.isPlaying && GUILayout.Button("Reset"))
                ((VolumeWeightRandomizer)target).SetWeight(0);

            serializedObject.ApplyModifiedProperties();
        }
    }
}


text:
fileFormatVersion: 2
guid: 48c3c574d6bc4a14d8b667fd2de74126
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 96a11807d4dd0f04bbbca2172efe1f01
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEditor;

namespace Khoreo
{
    [CustomEditor(typeof(AudioThreshold)), CanEditMultipleObjects]
    sealed class AudioThresholdEditor : Editor
    {
        SerializedProperty _tracker;
        SerializedProperty _threshold;
        SerializedProperty _delay;
        SerializedProperty _onEvent;
        SerializedProperty _offEvent;

        void OnEnable()
        {
            _tracker   = serializedObject.FindProperty("_tracker");
            _threshold = serializedObject.FindProperty("_threshold");
            _delay     = serializedObject.FindProperty("_delay");
            _onEvent   = serializedObject.FindProperty("_onEvent");
            _offEvent  = serializedObject.FindProperty("_offEvent");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(_tracker);
            EditorGUILayout.PropertyField(_threshold);
            EditorGUILayout.PropertyField(_delay);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_onEvent);
            EditorGUILayout.PropertyField(_offEvent);
            serializedObject.ApplyModifiedProperties();
        }
    }
}


text:
fileFormatVersion: 2
guid: 8b43172003b9a5943a2f6a48e20b9f96
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 7dd05479879062f4cb2ad2f332cefabc
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEditor;

namespace Khoreo
{
    [CustomEditor(typeof(Toggle)), CanEditMultipleObjects]
    sealed class ToggleEditor : Editor
    {
        SerializedProperty _state;
        SerializedProperty _action;
        SerializedProperty _offEvent;
        SerializedProperty _onEvent;

        void OnEnable()
        {
            _state    = serializedObject.FindProperty("_state");
            _action   = serializedObject.FindProperty("_action");
            _offEvent = serializedObject.FindProperty("_offEvent");
            _onEvent  = serializedObject.FindProperty("_onEvent");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(_state);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_action);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_offEvent);
            EditorGUILayout.PropertyField(_onEvent);
            serializedObject.ApplyModifiedProperties();
        }
    }
}


text:
using UnityEditor;

namespace Khoreo
{
    [CustomEditor(typeof(Trigger)), CanEditMultipleObjects]
    sealed class TriggerEditor : Editor
    {
        SerializedProperty _action;
        SerializedProperty _event;

        void OnEnable()
        {
            _action = serializedObject.FindProperty("_action");
            _event  = serializedObject.FindProperty("_event");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(_action);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_event);
            serializedObject.ApplyModifiedProperties();
        }
    }
}


text:
fileFormatVersion: 2
guid: da35bc61b7c3df24cb43c90cbeb84d4c
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 7d6c6ec79d55ccd4fab4701c37b248f8
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEditor;

namespace Khoreo
{
    [CustomEditor(typeof(FloatValueRelay)), CanEditMultipleObjects]
    sealed class FloatValueRelayEditor : Editor
    {
        SerializedProperty _speed;
        SerializedProperty _targetValue;
        SerializedProperty _event;

        void OnEnable()
        {
            _speed       = serializedObject.FindProperty("_speed");
            _targetValue = serializedObject.FindProperty("_targetValue");
            _event       = serializedObject.FindProperty("_event");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(_speed);
            EditorGUILayout.PropertyField(_targetValue);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_event);
            serializedObject.ApplyModifiedProperties();
        }
    }
}


text:
using UnityEditor;

namespace Khoreo
{
    [CustomEditor(typeof(VolumeWeightAnimation)), CanEditMultipleObjects]
    sealed class VolumeWeightAnimationEditor : Editor
    {
        SerializedProperty _curve;
        SerializedProperty _speed;
        SerializedProperty _trigger;
        SerializedProperty _volume;

        void OnEnable()
        {
            _curve   = serializedObject.FindProperty("_curve");
            _speed   = serializedObject.FindProperty("_speed");
            _trigger = serializedObject.FindProperty("_trigger");
            _volume  = serializedObject.FindProperty("_volume");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(_curve);
            EditorGUILayout.PropertyField(_speed);
            EditorGUILayout.PropertyField(_volume);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_trigger);
            serializedObject.ApplyModifiedProperties();
        }
    }
}


text:
fileFormatVersion: 2
guid: eb3b59bdb54641d42b5d3d49f1f328bd
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.VFX;
using UnityEngine.VFX.Utility;

namespace Khoreo
{
    [AddComponentMenu("VFX/Property Binders/Khoreo/Float Value Relay Binder")]
    [VFXBinder("Khoreo/Float Value Relay")]
    sealed class VFXFloatValueRelayBinder : VFXBinderBase
    {
        public string Property
          { get => (string)_property; set => _property = value; }

        [VFXPropertyBinding("System.Single"), SerializeField]
        ExposedProperty _property = "FloatValue";

        public FloatValueRelay Target = null;

        public override bool IsValid(VisualEffect component)
          => Target != null && component.HasFloat(_property);

        public override void UpdateBinding(VisualEffect component)
          => component.SetFloat(_property, Target.currentValue);

        public override string ToString()
          => $"Float Value : '{_property}' -> {Target?.name ?? "(null)"}";
    }
}


text:
using UnityEngine;

namespace Khoreo
{
    public sealed class SnapToGround : MonoBehaviour
    {
        [SerializeField] Transform _target = null;
        [SerializeField] float _offset = 0;

        void LateUpdate()
        {
            var p = _target.position;
            p.y = _offset;
            transform.position = p;
        }
    }
}


text:
fileFormatVersion: 2
guid: c17c1a4cc7177fd4faa3e8593b5b102f
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;

namespace Khoreo
{
    public sealed class VolumeWeightRandomizer : MonoBehaviour
    {
        #region Editable attributes

        [SerializeField] Volume _volume = null;
        [SerializeField] InputAction _trigger = null;
        [SerializeField] InputAction _reset = null;

        #endregion

        #region Public members

        public void Randomize()
        {
            if (!IsActive) return;
            _volume.weight = Random.value;
        }

        public void SetWeight(float weight)
        {
            if (!IsActive) return;
            _volume.weight = weight;
        }

        #endregion

        #region Private members

        bool IsActive
          => enabled && gameObject.activeInHierarchy;

        void OnTriggerPerformed(InputAction.CallbackContext ctx)
          => Randomize();

        void OnResetPerformed(InputAction.CallbackContext ctx)
          => SetWeight(0);

        #endregion

        #region MonoBehaviour

        void OnEnable()
        {
            _trigger.performed += OnTriggerPerformed;
            _trigger.Enable();

            _reset.performed += OnResetPerformed;
            _reset.Enable();
        }

        void OnDisable()
        {
            _trigger.Disable();
            _trigger.performed -= OnTriggerPerformed;

            _reset.Disable();
            _reset.performed -= OnResetPerformed;
        }

        #endregion
    }
}


text:
using UnityEngine;
using UnityEngine.Events;
using Lasp;

namespace Khoreo
{
    public sealed class AudioThreshold : MonoBehaviour
    {
        [SerializeField] AudioLevelTracker _tracker = null;
        [SerializeField] float _threshold = 0;
        [SerializeField] float _delay = 0.2f;
        [SerializeField] UnityEvent _onEvent = null;
        [SerializeField] UnityEvent _offEvent = null;

        bool _flag;
        float _timer;

        void OnDisable()
        {
            // Force off on disable
            if (_flag)
            {
                _flag = false;
                _offEvent.Invoke();
            }
        }

        void Start()
          => _offEvent.Invoke(); // Starts from the off state.

        void Update()
        {
            if (!_flag)
            {
                // Currently off: Turn on when the input hits the threshold.
                if (_tracker.normalizedLevel > _threshold)
                {
                    _onEvent.Invoke();
                    _timer = _delay;
                    _flag = true;
                }
            }
            else
            {
                // Currently on: Turn off when the timer ends.
                if (_tracker.normalizedLevel > _threshold)
                {
                    _timer = _delay;
                }
                else
                {
                    _timer -= Time.deltaTime;
                    if (_timer <= 0)
                    {
                        _offEvent.Invoke();
                        _flag = false;
                    }
                }
            }
        }
    }
}


text:
using UnityEngine;

namespace Khoreo
{
    sealed class AppController : MonoBehaviour
    {
        void Start()
        {
#if !UNITY_EDITOR
            Cursor.visible = false;
#endif
        }
    }
}


text:
using UnityEngine;
using UnityEngine.VFX;
using UnityEngine.VFX.Utility;

namespace Khoreo
{
    [AddComponentMenu("VFX/Property Binders/Khoreo/Toggle Binder")]
    [VFXBinder("Khoreo/Toggle")]
    sealed class VFXToggleBinder : VFXBinderBase
    {
        public string Property
          { get => (string)_property; set => _property = value; }

        [VFXPropertyBinding("System.Boolean"), SerializeField]
        ExposedProperty _property = "BoolValue";

        public Toggle Target = null;

        public override bool IsValid(VisualEffect component)
          => Target != null && component.HasBool(_property);

        public override void UpdateBinding(VisualEffect component)
          => component.SetBool(_property, Target.IsOn);

        public override string ToString()
          => $"Toggle : '{_property}' -> {Target?.name ?? "(null)"}";
    }
}


text:
fileFormatVersion: 2
guid: 01e59f00db7cba042ae2942ab7a92b14
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 49eb6eced1164c6498f39eecf476a481
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.Events;
using Klak.Math;

namespace Khoreo
{
    public sealed class FloatValueRelay : MonoBehaviour
    {
        #region Local class

        [System.Serializable] class FloatEvent : UnityEvent<float> {}

        #endregion

        #region Editable attributes

        [SerializeField] float _speed = 10;
        [SerializeField] float _targetValue = 0;
        [SerializeField] FloatEvent _event = null;

        #endregion

        #region Public members

        public float Speed
          { get => _speed; set => _speed = value; }

        public float targetValue
          { get => _targetValue; set => _targetValue = value; }

        public float currentValue
          { get => _currentValue; set => _currentValue = value; }

        #endregion

        #region MonoBehaviour

        float _currentValue;
        float _velocity;

        void Start()
        {
            _currentValue = _targetValue;

            _event.Invoke(_currentValue);
        }

        void Update()
        {
            _currentValue = CdsTween.Step
              (_currentValue, _targetValue, ref _velocity, _speed);

            _event.Invoke(_currentValue);
        }

        #endregion
    }
}


text:
fileFormatVersion: 2
guid: 85fb56910d67a1b45b4bfd60e26405a9
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: ed19c2ac44829f043955e8e1e5b4f9fa
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;

namespace Khoreo
{
    public sealed class VolumeWeightAnimation : MonoBehaviour
    {
        #region Editable attributes

        [SerializeField] AnimationCurve _curve = DefaultCurve;
        [SerializeField] float _speed = 1;
        [SerializeField] Volume _volume = null;
        [SerializeField] InputAction _trigger = null;

        #endregion

        #region Public members

        public float Speed
          { get => _speed; set => _speed = value; }

        public void Play()
        {
            if (!IsActive) return;
            _time = 0;
            ApplyCurve();
        }

        public void Stop()
        {
            _time = 1e+5f;
            ApplyCurve();
        }

        #endregion

        #region Private members

        static AnimationCurve DefaultCurve
          { get => AnimationCurve.Linear(0, 1, 1, 0); }

        float _time = 1e+5f;

        bool IsActive
          => enabled && gameObject.activeInHierarchy;

        void ApplyCurve()
          => _volume.weight = _curve.Evaluate(_time);

        void OnPerformed(InputAction.CallbackContext ctx)
          => Play();

        #endregion

        #region MonoBehaviour

        void OnEnable()
        {
            _trigger.performed += OnPerformed;
            _trigger.Enable();
        }

        void OnDisable()
        {
            Stop();
            _trigger.Disable();
            _trigger.performed -= OnPerformed;
        }

        void Start()
          => Stop();

        void Update()
        {
            ApplyCurve();
            _time += Time.deltaTime * _speed;
        }

        #endregion
    }
}


text:
fileFormatVersion: 2
guid: 8098baa449299884dae1363cdd42b3f6
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;

namespace Khoreo
{
    public sealed class Toggle : MonoBehaviour
    {
        [SerializeField] bool _state = false;
        [SerializeField] InputAction _action = null;
        [SerializeField] UnityEvent _offEvent = null;
        [SerializeField] UnityEvent _onEvent = null;

        public bool IsOn => _state;

        public void Flip()
        {
            _state = !_state;
            (_state ? _onEvent : _offEvent).Invoke();
        }

        void OnEnable()
        {
            _action.performed += OnPerformed;
            _action.Enable();
        }

        void OnDisable()
        {
            _action.Disable();
            _action.performed -= OnPerformed;
        }

        void OnPerformed(InputAction.CallbackContext ctx)
          => Flip();

        void Start()
          => (_state ? _onEvent : _offEvent).Invoke();
    }
}


text:
fileFormatVersion: 2
guid: 7fe553cbdc0b8394ab8b63292954b247
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;

namespace Khoreo
{
    public sealed class FloatValueAnimation : MonoBehaviour
    {
        #region Local class

        [System.Serializable] class FloatEvent : UnityEvent<float> {}

        #endregion

        #region Editable attributes

        [SerializeField] AnimationCurve _curve = DefaultCurve;
        [SerializeField] float _speed = 1;
        [SerializeField] InputAction _trigger = null;
        [SerializeField] FloatEvent _event = null;

        #endregion

        #region Public members

        public float Speed
          { get => _speed; set => _speed = value; }

        public void Play()
        {
            if (!IsActive) return;
            _time = 0;
            ApplyCurve();
        }

        public void Stop()
        {
            _time = 1e+5f;
            ApplyCurve();
        }

        #endregion

        #region Private members

        static AnimationCurve DefaultCurve
          { get => AnimationCurve.Linear(0, 1, 1, 0); }

        float _time = 1e+5f;

        bool IsActive
          => enabled && gameObject.activeInHierarchy;

        void ApplyCurve()
          => _event.Invoke(_curve.Evaluate(_time));

        void OnPerformed(InputAction.CallbackContext ctx)
          => Play();

        #endregion

        #region MonoBehaviour

        void OnEnable()
        {
            _trigger.performed += OnPerformed;
            _trigger.Enable();
        }

        void OnDisable()
        {
            Stop();
            _trigger.Disable();
            _trigger.performed -= OnPerformed;
        }

        void Start()
          => Stop();

        void Update()
        {
            ApplyCurve();
            _time += Time.deltaTime * _speed;
        }

        #endregion
    }
}


text:
fileFormatVersion: 2
guid: 589014d47d7ab7d438683e0a8b7318ae
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: ed2cfc890f166804a83d8fbfac293915
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;

namespace Khoreo
{
    public sealed class Trigger : MonoBehaviour
    {
        [SerializeField] InputAction _action = null;
        [SerializeField] UnityEvent _event = null;

        void OnEnable()
        {
            _action.performed += OnPerformed;
            _action.Enable();
        }

        void OnDisable()
        {
            _action.Disable();
            _action.performed -= OnPerformed;
        }

        void OnPerformed(InputAction.CallbackContext ctx)
          => _event.Invoke();
    }
}


text:
fileFormatVersion: 2
guid: 2aaa4c4873e43a74fbd95bb9bced39c8
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 1cc7bc1f9b34e444a9a9d3ebe4ac5025
VisualEffectImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 07669e25b9eb498488b9a34ae186df27
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 9cc6a7b8b7d145949924441c5a9a29b0
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:


text:
using UnityEngine;
using UnityEngine.VFX;

namespace Khoreo
{
    public sealed class WebcamController : MonoBehaviour
    {
        [SerializeField] Shader _filterShader = null;
        [SerializeField, Range(0, 1)] float _threshold = 0.1f;
        [SerializeField, Range(0, 1)] float _contrast = 0.5f;

        WebCamTexture _webcam;
        Material _material;
        RenderTexture _filtered;

        void Start()
        {
            _webcam = new WebCamTexture();
            _material = new Material(_filterShader);
            _filtered = new RenderTexture(1024, 1024, 0);
            _filtered.useMipMap = true;

            _webcam.Play();

            GetComponent<VisualEffect>()
              .SetTexture("WebcamTexture", _filtered);
        }

        void OnDestroy()
        {
            _webcam.Stop();

            Destroy(_webcam);
            Destroy(_material);
            Destroy(_filtered);
        }

        void Update()
        {
            _material.SetVector
              ("_FilterParams", new Vector2(_threshold, _contrast));

            Graphics.Blit(_webcam, _filtered, _material, 0);
        }
    }
}


text:
Shader "Hidden/Khoreo/Webcam/Screen"
{
    Properties
    {
        _MainTex("", 2D) = "black" {}
    }

    HLSLINCLUDE

    #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"

    float min_xy(float2 v) { return min(v.x, v.y); }
    float max_xy(float2 v) { return max(v.x, v.y); }

    sampler2D _MainTex;
    float2 _FilterParams;
    float4 _Time;

    void Vertex(
        float4 position : POSITION,
        float2 texcoord : TEXCOORD0,
        out float4 outPosition : SV_Position,
        out float2 outTexcoord : TEXCOORD0
    )
    {
        outPosition.x =  position.x * 2 - 1;
        outPosition.y = -position.y * 2 + 1;
        outPosition.zw = float2(1, 1);
        outTexcoord = texcoord;
    }

    void Fragment(
        float4 position : SV_Position,
        float2 texcoord : TEXCOORD0,
        out float4 outColor : SV_Target
    )
    {
        float contours, grid_lines, edge_lines, edge_mask;

        float2 fw = fwidth(texcoord);

        // Contour lines (edge detection effect)
        {
            float2 uv = texcoord;

            float2 uv0 = uv;
            float2 uv1 = uv + fw;
            float2 uv2 = uv + float2(fw.x, 0);
            float2 uv3 = uv + float2(0, fw.y);

            float3 c0 = tex2D(_MainTex, uv0).rgb;
            float3 c1 = tex2D(_MainTex, uv1).rgb;
            float3 c2 = tex2D(_MainTex, uv2).rgb;
            float3 c3 = tex2D(_MainTex, uv3).rgb;

            // Roberts cross operator
            float3 g1 = c1 - c0.rgb;
            float3 g2 = c3 - c2;
            float g = sqrt(dot(g1, g1) + dot(g2, g2));

            // Threshold parameters
            float th1 = _FilterParams.x;
            float th2 = th1 + 1 - _FilterParams.y;
            contours = smoothstep(th1, th2, g);
        }

        // Grid lines
        {
            float2 repeat = float2(8, 4);
            float2 uv = frac(texcoord * repeat + 0.5);

            float2 p = min(uv, 1 - uv);
            float2 p_div_fw = p / (fw * repeat);

            float cut = all(p < 0.2);

            grid_lines = max_xy(saturate(1 - p_div_fw)) * cut;
        }

        // Outer edge
        {
            float2 p = min(texcoord, 1 - texcoord);
            float2 p_div_fw = p / fw;

            float cut = all(abs(p - 0.5) > 0.3);

            edge_mask  = min_xy(saturate(    p_div_fw));
            edge_lines = max_xy(saturate(2 - p_div_fw)) * cut;
        }

        // Noise
        {
            uint seed = _Time.y * 60;

            float r1 = GenerateHashedRandomFloat(seed);
            float r2 = GenerateHashedRandomFloat(seed + 0xcafebabe);
            float r3 = GenerateHashedRandomFloat(seed + 0xdeadbeef);

            contours *= lerp(0.5, 1, r1);
            grid_lines *= r2;
            edge_lines *= r3;
        }

        // Composition
        outColor.rgb = (contours + grid_lines + edge_lines) * edge_mask;
        outColor.a = 1;
    }

    ENDHLSL

    SubShader
    {
        Cull Off ZWrite Off ZTest Always
        Pass
        {
            HLSLPROGRAM
            #pragma vertex Vertex
            #pragma fragment Fragment
            ENDHLSL
        }
    }
}


text:
fileFormatVersion: 2
guid: 77b3fc137f469d04d813ff07c8e8721e
ShaderImporter:
  externalObjects: {}
  defaultTextures: []
  nonModifiableTextures: []
  userData:
  assetBundleName:
  assetBundleVariant:


text:
fileFormatVersion: 2
guid: 6c3df3e421862564e8e086d930071e6c
TextureImporter:
  internalIDToNameTable: []
  externalObjects: {}
  serializedVersion: 11
  mipmaps:
    mipMapMode: 0
    enableMipMap: 1
    sRGBTexture: 1
    linearTexture: 0
    fadeOut: 0
    borderMipMap: 0
    mipMapsPreserveCoverage: 0
    alphaTestReferenceValue: 0.5
    mipMapFadeDistanceStart: 1
    mipMapFadeDistanceEnd: 3
  bumpmap:
    convertToNormalMap: 0
    externalNormalMap: 0
    heightScale: 0.25
    normalMapFilter: 0
  isReadable: 0
  streamingMipmaps: 0
  streamingMipmapsPriority: 0
  grayScaleToAlpha: 0
  generateCubemap: 6
  cubemapConvolution: 0
  seamlessCubemap: 0
  textureFormat: 1
  maxTextureSize: 2048
  textureSettings:
    serializedVersion: 2
    filterMode: -1
    aniso: -1
    mipBias: -100
    wrapU: 1
    wrapV: 1
    wrapW: 1
  nPOTScale: 1
  lightmap: 0
  compressionQuality: 50
  spriteMode: 0
  spriteExtrude: 1
  spriteMeshType: 1
  alignment: 0
  spritePivot: {x: 0.5, y: 0.5}
  spritePixelsToUnits: 100
  spriteBorder: {x: 0, y: 0, z: 0, w: 0}
  spriteGenerateFallbackPhysicsShape: 1
  alphaUsage: 1
  alphaIsTransparency: 0
  spriteTessellationDetail: -1
  textureType: 0
  textureShape: 1
  singleChannelComponent: 0
  maxTextureSizeSet: 0
  compressionQualitySet: 0
  textureFormatSet: 0
  applyGammaDecoding: 0
  platformSettings:
  - serializedVersion: 3
    buildTarget: DefaultTexturePlatform
    maxTextureSize: 2048
    resizeAlgorithm: 0
    textureFormat: -1
    textureCompression: 1
    compressionQuality: 50
    crunchedCompression: 0
    allowsAlphaSplitting: 0
    overridden: 0
    androidETC2FallbackOverride: 0
    forceMaximumCompressionQuality_BC6H_BC7: 0
  - serializedVersion: 3
    buildTarget: Standalone
    maxTextureSize: 2048
    resizeAlgorithm: 0
    textureFormat: -1
    textureCompression: 1
    compressionQuality: 50
    crunchedCompression: 0
    allowsAlphaSplitting: 0
    overridden: 0
    androidETC2FallbackOverride: 0
    forceMaximumCompressionQuality_BC6H_BC7: 0
  spriteSheet:
    serializedVersion: 2
    sprites: []
    outline: []
    physicsShape: []
    bones: []
    spriteID:
    internalID: 0
    vertices: []
    indices:
    edges: []
    weights: []
    secondaryTextures: []
  spritePackingTag:
  pSDRemoveMatte: 0
  pSDShowRemoveMatteOption: 0
  userData:
  assetBundleName:
  assetBundleVariant: