├── .gitignore ├── AlphaFill.shader ├── AlphaFill.shader.meta ├── AnimCurveTo1DTexture.cs ├── AnimCurveTo1DTexture.cs.meta ├── AssetWriter.cs ├── AssetWriter.cs.meta ├── AudioClipTrimmer.cs ├── AudioClipTrimmer.cs.meta ├── BlitCubemapToEquirect.shader ├── BlitCubemapToEquirect.shader.meta ├── BlitDepth.shader ├── BlitDepth.shader.meta ├── BlitTriangle.shader ├── BlitTriangle.shader.meta ├── BytePool.cs ├── BytePool.cs.meta ├── CameraExport360.cs ├── CameraExport360.cs.meta ├── CameraPreviewWindow.cs ├── CameraPreviewWindow.cs.meta ├── ColourToLum.shader ├── ColourToLum.shader.meta ├── CommandBuffy.cs ├── CommandBuffy.cs.meta ├── Distort.shader ├── Distort.shader.meta ├── Editor.meta ├── Editor ├── PopData_Test.cs ├── PopData_Test.cs.meta ├── PopJson_Test.cs ├── PopJson_Test.cs.meta ├── PopMaterial_Test.cs └── PopMaterial_Test.cs.meta ├── EditorScopedProgressBar.cs ├── EditorScopedProgressBar.cs.meta ├── EventTrigger.cs ├── EventTrigger.cs.meta ├── FilePathAttribute.cs ├── FilePathAttribute.cs.meta ├── FishEyeDistortion.shader ├── FishEyeDistortion.shader.meta ├── FixedArray.cs ├── FixedArray.cs.meta ├── FlipMirror.shader ├── FlipMirror.shader.meta ├── GotoNextScene.cs ├── GotoNextScene.cs.meta ├── GuiHelper.cs ├── GuiHelper.cs.meta ├── InspectorButton.cs ├── InspectorButton.cs.meta ├── JobThread.cs ├── JobThread.cs.meta ├── JsonSanitiser.cs ├── JsonSanitiser.cs.meta ├── LICENSE.md ├── LICENSE.md.meta ├── MeshBoundsGizmo.cs ├── MeshBoundsGizmo.cs.meta ├── MicrophoneNameAttribute.cs ├── MicrophoneNameAttribute.cs.meta ├── NiceGraph.shader ├── NiceGraph.shader.meta ├── OnCameraPreRenderCallback.cs ├── OnCameraPreRenderCallback.cs.meta ├── OnChangedAttribute.cs ├── OnChangedAttribute.cs.meta ├── OnEnableEvent.cs ├── OnEnableEvent.cs.meta ├── OnEnableTime.cs ├── OnEnableTime.cs.meta ├── OpenLockedInspector.cs ├── OpenLockedInspector.cs.meta ├── OpenvrJoystickInterface.cs ├── OpenvrJoystickInterface.cs.meta ├── PopAssetDatabase.cs ├── PopAssetDatabase.cs.meta ├── PopBinaryChop.cs ├── PopBinaryChop.cs.meta ├── PopCheckCurrentCamera.cs ├── PopCheckCurrentCamera.cs.meta ├── PopCli.cs ├── PopCli.cs.meta ├── PopCommandLineBuild.cs ├── PopCommandLineBuild.cs.meta ├── PopCommon.cginc ├── PopCommon.cginc.meta ├── PopData.cs ├── PopData.cs.meta ├── PopEditor.cs ├── PopEditor.cs.meta ├── PopExceptions.cs ├── PopExceptions.cs.meta ├── PopFbxAscii.cs ├── PopFbxAscii.cs.meta ├── PopFitCollider.cs ├── PopFitCollider.cs.meta ├── PopGameObject.cs ├── PopGameObject.cs.meta ├── PopGeometry.cs ├── PopGeometry.cs.meta ├── PopGizmos.cs ├── PopGizmos.cs.meta ├── PopIO.cs ├── PopIO.cs.meta ├── PopJson.cs ├── PopJson.cs.meta ├── PopKalman.cs ├── PopKalman.cs.meta ├── PopMaterial.cs ├── PopMaterial.cs.meta ├── PopMath.cs ├── PopMath.cs.meta ├── PopMouseLook.cs ├── PopMouseLook.cs.meta ├── PopNet.cs ├── PopNet.cs.meta ├── PopNukeChan.cs ├── PopNukeChan.cs.meta ├── PopOgg.cs ├── PopOgg.cs.meta ├── PopPlayerPrefs.cs ├── PopPlayerPrefs.cs.meta ├── PopSvg.cs ├── PopSvg.cs.meta ├── PopTask.cs ├── PopTask.cs.meta ├── PopTaskProgressBar.cs ├── PopTaskProgressBar.cs.meta ├── PopTexture.cs ├── PopTexture.cs.meta ├── PopTextureBlur.cs ├── PopTextureBlur.cs.meta ├── PopTextureBlur.shader ├── PopTextureBlur.shader.meta ├── PopTime.cs ├── PopTime.cs.meta ├── PopUrl.cs ├── PopUrl.cs.meta ├── PopVectorX.cs ├── PopVectorX.cs.meta ├── PopWavefrontObj.cs ├── PopWavefrontObj.cs.meta ├── RandomMaterialInitialisation.cs ├── RandomMaterialInitialisation.cs.meta ├── RangeMinMaxAttribute.cs ├── RangeMinMaxAttribute.cs.meta ├── RectTransformUV.cs ├── RectTransformUV.cs.meta ├── RelayFloatValue.cs ├── RelayFloatValue.cs.meta ├── RgbToHsl.shader ├── RgbToHsl.shader.meta ├── SceneNameAttribute.cs ├── SceneNameAttribute.cs.meta ├── SceneOrderController.cs ├── SceneOrderController.cs.meta ├── SetAndroidManifest.cs ├── SetAndroidManifest.cs.meta ├── SetAnimationTime.cs ├── SetAnimationTime.cs.meta ├── SetMaterialValue.cs ├── SetMaterialValue.cs.meta ├── SetMaterialValueToCollider.cs ├── SetMaterialValueToCollider.cs.meta ├── SetMeshBoundsToCollider.cs ├── SetMeshBoundsToCollider.cs.meta ├── SetTimelineTime.cs ├── SetTimelineTime.cs.meta ├── ShaderBlit.cs ├── ShaderBlit.cs.meta ├── ShowFunctionResultAttribute.cs ├── ShowFunctionResultAttribute.cs.meta ├── ShowIfAttribute.cs ├── ShowIfAttribute.cs.meta ├── SmoothEvent.cs ├── SmoothEvent.cs.meta ├── Spline.cginc ├── Spline.cginc.meta ├── SplineQuad.cs ├── SplineQuad.cs.meta ├── SplineQuad.mat ├── SplineQuad.mat.meta ├── SplineQuad.shader ├── SplineQuad.shader.meta ├── StackedDictionary.cs ├── StackedDictionary.cs.meta ├── SteamvrSettings.cs ├── SteamvrSettings.cs.meta ├── Stereo360.shader ├── Stereo360.shader.meta ├── TextureBlitChain.cs ├── TextureBlitChain.cs.meta ├── TexturePreviewAttribute.cs ├── TexturePreviewAttribute.cs.meta ├── UnityEventsSpecialised.cs ├── UnityEventsSpecialised.cs.meta ├── VideoPlayerUtils.cs ├── VideoPlayerUtils.cs.meta ├── WebCameraNameAttribute.cs ├── WebCameraNameAttribute.cs.meta ├── WorldSpaceLaserGrid.shader ├── WorldSpaceLaserGrid.shader.meta ├── WwwCache.cs ├── WwwCache.cs.meta ├── package.json ├── package.json.meta ├── readme.md └── readme.md.meta /.gitignore: -------------------------------------------------------------------------------- 1 | # just in case unity meta files sneak in 2 | # gr: we want consistent meta files now I'm using this as a submodule more 3 | #*.meta 4 | -------------------------------------------------------------------------------- /AlphaFill.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "NewChromantics/AlphaFill" { 4 | Properties { 5 | _MainTex ("_MainTex", 2D) = "white" {} 6 | SampleRadius("SampleRadius", Range(0,9) ) = 4 7 | Debug_HighlightFill("HighlightFill", Int ) = 0 8 | } 9 | SubShader { 10 | 11 | pass 12 | { 13 | CGPROGRAM 14 | 15 | 16 | #pragma vertex vert 17 | #pragma fragment frag 18 | #pragma only_renderers d3d11 opengl 19 | 20 | struct VertexInput { 21 | float4 Position : POSITION; 22 | float2 uv_MainTex : TEXCOORD0; 23 | }; 24 | 25 | struct FragInput { 26 | float4 Position : SV_POSITION; 27 | float2 uv_MainTex : TEXCOORD0; 28 | }; 29 | 30 | sampler2D _MainTex; // new lum 31 | float4 _MainTex_TexelSize; 32 | float DiffTolerance; 33 | float DepthComponentInf; 34 | bool Debug_HighlightFill; 35 | 36 | const bool IncludeSelf = true; 37 | 38 | #if defined(UNITY_IOS) 39 | const int SampleRadius = 1; 40 | const int HitCountMin = 4; 41 | #else 42 | int SampleRadius; 43 | int HitCountMin; 44 | #endif 45 | 46 | // returns good depth (if inf, false) 47 | bool RgbaToDepth(out float Depth,float4 Rgba) 48 | { 49 | Depth = Rgba.x; 50 | return Rgba.w > 0.5f; 51 | } 52 | 53 | bool GetDepth(out float Depth,FragInput In,int2 PixelOffset) 54 | { 55 | // work out uv 56 | float2 uv = In.uv_MainTex + PixelOffset * _MainTex_TexelSize.xy; 57 | float4 rgba = tex2D( _MainTex, uv ); 58 | return RgbaToDepth( Depth, rgba ); 59 | } 60 | 61 | FragInput vert(VertexInput In) { 62 | FragInput Out; 63 | Out.Position = UnityObjectToClipPos (In.Position ); 64 | Out.uv_MainTex = In.uv_MainTex; 65 | return Out; 66 | } 67 | 68 | 69 | 70 | float4 frag(FragInput In) : SV_Target 71 | { 72 | float BaseDepth = 0.0f; 73 | bool BaseGoodDepth = GetDepth( BaseDepth, In, int2(0,0) ); 74 | if ( BaseGoodDepth ) 75 | return float4( BaseDepth, 0, 0, 1 ); 76 | 77 | float MinNeighbourDepth = 9999; 78 | // match depth around me, if I'm wildly out, discard. 79 | // if I'm not good, just pick a good one 80 | #ifdef SHADER_API_D3D11 81 | [unroll(12)] 82 | #endif 83 | for ( int y=-SampleRadius; y<=SampleRadius; y++ ) 84 | { 85 | #ifdef SHADER_API_D3D11 86 | [unroll(12)] 87 | #endif 88 | for ( int x=-SampleRadius; x<=SampleRadius; x++ ) 89 | { 90 | float MatchDepth = 0.0f; 91 | bool MatchGoodDepth = GetDepth( MatchDepth, In, int2(x,y) ); 92 | 93 | // ignore not-good neighbours 94 | MinNeighbourDepth = min(MinNeighbourDepth, MatchGoodDepth ? MatchDepth : MinNeighbourDepth); 95 | } 96 | } 97 | 98 | // no data 99 | if ( MinNeighbourDepth > 1 ) 100 | return float4(0,0,0,0); 101 | 102 | return float4(MinNeighbourDepth,0,Debug_HighlightFill?MinNeighbourDepth:0,1); 103 | } 104 | ENDCG 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /AlphaFill.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e9f788e56a024bfbb4886a61690e7b9 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /AnimCurveTo1DTexture.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | [System.Serializable] 7 | public class UnityEvent_Texture : UnityEvent {} 8 | 9 | public class AnimCurveTo1DTexture : MonoBehaviour { 10 | 11 | [InspectorButton("RegenerateAll")] 12 | public bool _RegenerateAll; 13 | 14 | public Texture2D Target; 15 | [Range(1,4096)] 16 | [ShowIfAttribute("TargetIsNull")] 17 | public int TargetWidth = 256; 18 | [ShowIfAttribute("TargetIsNull")] 19 | public TextureFormat TargetFormat = TextureFormat.RGBAFloat; 20 | 21 | [OnChanged(null,"Generate1DTexture")] 22 | public AnimationCurve Curve; 23 | 24 | [InspectorButton("Generate1DTexture")] 25 | public bool _Generate1DTexture; 26 | 27 | public UnityEvent_Texture OnGenerated; 28 | 29 | 30 | void RegenerateAll() 31 | { 32 | var acs = GameObject.FindObjectsOfType (); 33 | foreach (var ac in acs) { 34 | try { 35 | ac.Generate1DTexture (); 36 | } catch { 37 | } 38 | } 39 | } 40 | 41 | 42 | 43 | void OnEnable () 44 | { 45 | // invoke event, but only generate texture if required 46 | OnGenerated.Invoke( GetTexture() ); 47 | } 48 | 49 | bool TargetIsNull() 50 | { 51 | return Target == null; 52 | } 53 | 54 | public void Generate1DTexture() 55 | { 56 | if (!this.enabled) 57 | return; 58 | 59 | if (Target == null) { 60 | Debug.Log (this.name + " allocating new AnimCurve 1D texture", this); 61 | Target = new Texture2D (TargetWidth, 16, TargetFormat, false); 62 | Target.filterMode = FilterMode.Point; 63 | Target.wrapMode = TextureWrapMode.Clamp; 64 | } 65 | 66 | Debug.Log (this.name + " generating new AnimCurve 1D texture", this); 67 | var w = Target.width; 68 | 69 | var Colour = new Color (0, 0, 0); 70 | float Range = Mathf.Max (1, w - 1); 71 | var CurveTimeMin = Curve.keys [0].time; 72 | var CurveTimeMax = Curve.keys [Curve.length - 1].time; 73 | 74 | var Pixels = Target.GetPixels (); 75 | 76 | for (int x = 0; x < w; x++) { 77 | var xf = x / Range; 78 | var Time = Mathf.Lerp (CurveTimeMin, CurveTimeMax, xf); 79 | var Value = Curve.Evaluate (Time); 80 | 81 | // todo; scale value to min/max of curve? maybe neccessary for non-float textures 82 | 83 | Colour.r = Value; 84 | Colour.g = Value; 85 | Colour.b = Value; 86 | 87 | for (int y = 0; y < Target.height; y++) { 88 | Pixels [x + y * w] = Colour; 89 | } 90 | } 91 | 92 | Target.SetPixels (Pixels); 93 | Target.Apply (); 94 | OnGenerated.Invoke (Target); 95 | } 96 | 97 | // only alloc texture if dirty/not generated 98 | public Texture GetTexture() 99 | { 100 | if (Target == null) 101 | Generate1DTexture (); 102 | return Target; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /AnimCurveTo1DTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2da211d7632747e0b5dc794b099483b 3 | timeCreated: 1494340623 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /AssetWriter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class AssetWriter : MonoBehaviour { 6 | 7 | 8 | #if UNITY_EDITOR 9 | public static void DeleteAsset(string Name) 10 | { 11 | var Path = "Assets/" + Name + ".asset"; 12 | UnityEditor.AssetDatabase.DeleteAsset (Path); 13 | } 14 | #endif 15 | 16 | 17 | #if UNITY_EDITOR 18 | public static T WriteAsset(string Name,T Asset) where T : Object 19 | { 20 | if (Asset == null) 21 | return null; 22 | 23 | var Path = "Assets/" + Name + ".asset"; 24 | 25 | var ExistingAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(Path); 26 | 27 | if ( ExistingAsset == null ) 28 | { 29 | UnityEditor.AssetDatabase.CreateAsset( Asset, Path ); 30 | } 31 | else 32 | { 33 | UnityEditor.EditorUtility.CopySerialized(Asset, ExistingAsset); 34 | } 35 | 36 | return UnityEditor.AssetDatabase.LoadAssetAtPath(Path); 37 | } 38 | #endif 39 | 40 | 41 | 42 | #if UNITY_EDITOR 43 | public static T SaveAsset(T Asset) where T : Object 44 | { 45 | if (Asset == null) 46 | return null; 47 | 48 | var Path = UnityEditor.AssetDatabase.GetAssetPath (Asset); 49 | if (string.IsNullOrEmpty (Path)) { 50 | Path = UnityEditor.EditorUtility.SaveFilePanelInProject ("Save new asset...", Asset.name, "asset", "Save asset"); 51 | if (string.IsNullOrEmpty (Path)) 52 | throw new System.Exception ("Save aborted"); 53 | 54 | // gr: returns null 55 | //Path = UnityEditor.FileUtil.GetProjectRelativePath (Path); 56 | } 57 | 58 | var ExistingAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(Path); 59 | 60 | if ( ExistingAsset == null ) 61 | { 62 | UnityEditor.AssetDatabase.CreateAsset( Asset, Path ); 63 | UnityEditor.AssetDatabase.SaveAssets(); 64 | } 65 | else 66 | { 67 | UnityEditor.EditorUtility.CopySerialized(Asset, ExistingAsset); 68 | } 69 | 70 | return UnityEditor.AssetDatabase.LoadAssetAtPath(Path); 71 | } 72 | #endif 73 | 74 | 75 | 76 | #if UNITY_EDITOR 77 | public static T SaveAsNewAsset(T ExistingAsset) where T : Object, new() 78 | { 79 | if (ExistingAsset == null) 80 | return null; 81 | 82 | // duplicate this way; https://github.com/pharan/Unity-MeshSaver/blob/master/MeshSaver/Editor/MeshSaverEditor.cs 83 | // copyserialised was creating a garbage mesh (same number of points, but messed up) 84 | var NewAsset = Object.Instantiate(ExistingAsset) as Mesh; 85 | NewAsset.name = ExistingAsset.name + "_copy"; 86 | 87 | var Path = UnityEditor.EditorUtility.SaveFilePanelInProject("Save new asset...", NewAsset.name, "asset", "Save asset"); 88 | if (string.IsNullOrEmpty(Path)) 89 | throw new System.Exception("Save aborted"); 90 | 91 | UnityEditor.AssetDatabase.CreateAsset(NewAsset, Path); 92 | UnityEditor.AssetDatabase.SaveAssets(); 93 | 94 | return UnityEditor.AssetDatabase.LoadAssetAtPath(Path); 95 | } 96 | #endif 97 | } 98 | -------------------------------------------------------------------------------- /AssetWriter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 555b59852b543435bab908f7a1bce796 3 | timeCreated: 1483541943 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /AudioClipTrimmer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | using System.Reflection; 8 | using System; 9 | #endif 10 | 11 | #if UNITY_EDITOR 12 | public class AudioClipTrimmer : EditorWindow { 13 | 14 | float Left = 0; 15 | float Right = 1; 16 | 17 | [MenuItem ("Window/Audio Clip Trimmer")] 18 | public static void ShowWindow () { 19 | EditorWindow.GetWindow(typeof(AudioClipTrimmer)); 20 | } 21 | AudioClip GetAudioClip() 22 | { 23 | var Clips = UnityEditor.Selection.GetFiltered( SelectionMode.Assets ); 24 | return Clips[0]; 25 | } 26 | 27 | // from http://answers.unity3d.com/questions/993241/how-to-play-specific-part-of-the-audio.html 28 | public static AudioClip MakeSubclip(AudioClip clip, float start, float stop) 29 | { 30 | /* Create a new audio clip */ 31 | int frequency = clip.frequency; 32 | float timeLength = stop - start; 33 | int samplesLength = (int)(frequency * timeLength); 34 | var NewName = clip.name + " " + start.ToString("0.00") + "..." + stop.ToString("0.00"); 35 | 36 | AudioClip newClip = AudioClip.Create(NewName, samplesLength, clip.channels, frequency, false); 37 | 38 | // Create a temporary buffer for the samples 39 | float[] data = new float[samplesLength]; 40 | 41 | // Get the data from the original clip 42 | if ( !clip.GetData(data, (int)(frequency* start)) ) 43 | throw new System.Exception("Error getting clip data"); 44 | 45 | // Transfer the data to the new clip 46 | if ( !newClip.SetData(data, 0) ) 47 | throw new System.Exception("Error setting clip data"); 48 | 49 | return newClip; 50 | } 51 | 52 | public static void PlayClip(AudioClip clip, float startTime, bool loop) 53 | { 54 | //int startSample = (int)(startTime * clip.frequency); 55 | 56 | Assembly assembly = typeof(AudioImporter).Assembly; 57 | Type audioUtilType = assembly.GetType("UnityEditor.AudioUtil"); 58 | 59 | //Type[] typeParams = { typeof(AudioClip), typeof(int), typeof(bool) }; 60 | //object[] objParams = { clip, startSample, loop }; 61 | //MethodInfo method = audioUtilType.GetMethod("PlayClip", typeParams); 62 | 63 | Type[] typeParams = { typeof(AudioClip) }; 64 | object[] objParams = { clip }; 65 | MethodInfo method = audioUtilType.GetMethod("PlayClip", typeParams); 66 | /*var Result = */method.Invoke(null, BindingFlags.Static | BindingFlags.Public, null, objParams, null); 67 | } 68 | 69 | void ShowInspector(AudioClip Clip) 70 | { 71 | var Preview = AssetPreview.GetAssetPreview(Clip); 72 | 73 | Left = GUILayout.HorizontalSlider( Left, 0, 1, GUILayout.ExpandWidth(true) ); 74 | Left = Mathf.Min( Left, Right ); 75 | 76 | Right = GUILayout.HorizontalSlider( Right, 0, 1, GUILayout.ExpandWidth(true) ); 77 | Right = Mathf.Max( Left, Right ); 78 | 79 | if ( GUILayout.Button("Preview", GUILayout.ExpandWidth(false) ) ) 80 | { 81 | var SubClip = MakeSubclip( Clip, Left*Clip.length, Right * Clip.length ); 82 | PlayClip( SubClip, 0, false ); 83 | } 84 | 85 | if ( GUILayout.Button("Save As...", GUILayout.ExpandWidth(false) ) ) 86 | { 87 | var SubClip = MakeSubclip( Clip, Left*Clip.length, Right * Clip.length ); 88 | AssetWriter.SaveAsset( SubClip ); 89 | } 90 | 91 | 92 | { 93 | GUIStyle style = new GUIStyle(); 94 | style.fixedHeight = 100.0f; 95 | var Options = new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true) }; 96 | var GroupRect = GUILayoutUtility.GetRect(new GUIContent(),style, Options ); 97 | GUI.BeginGroup( GroupRect ); 98 | GroupRect.x = 0; 99 | GroupRect.y = 0; 100 | EditorGUILayout.BeginVertical (); 101 | GUI.DrawTextureWithTexCoords( GroupRect, Preview, new Rect( Left, 0, Right-Left, 1 ) ); 102 | EditorGUILayout.EndVertical (); 103 | GUI.EndGroup(); 104 | } 105 | } 106 | 107 | void ShowHelpInspector(string Message) 108 | { 109 | EditorGUILayout.HelpBox("Select an audio clip",MessageType.Info); 110 | } 111 | 112 | public void OnGUI() 113 | { 114 | try 115 | { 116 | var Clip = GetAudioClip(); 117 | ShowInspector(Clip); 118 | } 119 | catch (System.Exception e) 120 | { 121 | ShowHelpInspector(e.Message); 122 | } 123 | 124 | } 125 | } 126 | #endif 127 | 128 | -------------------------------------------------------------------------------- /AudioClipTrimmer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c985be8e67f414e4690c6b26ea855600 3 | timeCreated: 1503938372 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /BlitCubemapToEquirect.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da930620b7e2f4069be45b93019815c1 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /BlitDepth.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "NewChromantics/DepthBlit" 4 | { 5 | Properties 6 | { 7 | // far-near distance 8 | DepthMax ("DepthMax", Range(0,1000)) = 1000 9 | 10 | // camera.projectionMatrix.inverse of the ACTUAL CAMERA, as this blit is using an ortho camera to do texture->texture blit 11 | ScreenToViewMtx_Row0("ScreenToViewMtx_Row0", VECTOR) = (1,0,0,0) 12 | ScreenToViewMtx_Row1("ScreenToViewMtx_Row1", VECTOR) = (0,1,0,0) 13 | ScreenToViewMtx_Row2("ScreenToViewMtx_Row2", VECTOR) = (0,0,1,0) 14 | ScreenToViewMtx_Row3("ScreenToViewMtx_Row3", VECTOR) = (0,0,0,1) 15 | 16 | // show some debug 17 | Debug_DepthBandRange("Debug_DepthBandRange", Range(0,40) ) = 0 18 | } 19 | 20 | SubShader 21 | { 22 | Tags { "RenderType"="Opaque" } 23 | 24 | Pass 25 | { 26 | CGPROGRAM 27 | #pragma vertex vert 28 | #pragma fragment frag 29 | #include "UnityCG.cginc" 30 | 31 | 32 | float DepthMax; 33 | sampler2D _CameraDepthTexture; 34 | float4 ScreenToViewMtx_Row0; 35 | float4 ScreenToViewMtx_Row1; 36 | float4 ScreenToViewMtx_Row2; 37 | float4 ScreenToViewMtx_Row3; 38 | float Debug_DepthBandRange; 39 | 40 | struct v2f 41 | { 42 | float4 pos : SV_POSITION; 43 | float4 scrPos:TEXCOORD1; 44 | }; 45 | 46 | 47 | //Vertex Shader 48 | v2f vert (appdata_base v) 49 | { 50 | v2f o; 51 | o.pos = UnityObjectToClipPos (v.vertex); 52 | 53 | //UNITY_TRANSFER_DEPTH(o.depth); 54 | 55 | o.scrPos=ComputeScreenPos(o.pos); 56 | o.scrPos.x = 1 - o.scrPos.x; 57 | 58 | //#if UNITY_UV_STARTS_AT_TOP 59 | // o.scrPos.y = 1 - o.scrPos.y; 60 | //#endif 61 | return o; 62 | } 63 | 64 | float GetWorldDepth(v2f i) 65 | { 66 | // gr: this is planar to the cubemap. Fine for cubemaps, but not real indication of DEPTH FROM EYE, so no good for equirect 67 | if ( false ) 68 | { 69 | float Depth = DECODE_EYEDEPTH( SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.scrPos) ); 70 | return Depth ; 71 | } 72 | else if ( false ) 73 | { 74 | // gr: this gives identical results to above 75 | float Depth = Linear01Depth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r); 76 | return Depth * DepthMax; 77 | } 78 | else if( true ) 79 | { 80 | float Depth = DECODE_EYEDEPTH( SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.scrPos) ); 81 | // move to projection space 82 | float2 ScreenPos = (i.scrPos - 0.5f) * 2.0f; 83 | float4 CameraRay = float4( ScreenPos.x, ScreenPos.y, 0, 1 ); 84 | float4x4 ScreenToViewMtx = float4x4( ScreenToViewMtx_Row0, ScreenToViewMtx_Row1, ScreenToViewMtx_Row2, ScreenToViewMtx_Row3 ); 85 | float4 ViewRay4 = mul( ScreenToViewMtx, CameraRay ); 86 | float3 ViewRay = ViewRay4.xyz; 87 | //float3 ViewRay = normalize(ViewRay4.xyz); 88 | 89 | //Depth *= 0.20f; 90 | float3 ViewPos = ViewRay * Depth; 91 | return length( ViewPos ); 92 | } 93 | } 94 | 95 | //Fragment Shader 96 | float4 frag (v2f i) : COLOR 97 | { 98 | float Depth = GetWorldDepth(i); 99 | 100 | // gr: don't need to normalise, it's already normalised on the camera linear near->far 101 | float DepthNorm = Depth / DepthMax; 102 | 103 | bool ShowDebugBands = (Debug_DepthBandRange > 0.0f); 104 | 105 | if ( ShowDebugBands ) 106 | { 107 | // show bands 108 | int DepthInt = Depth * Debug_DepthBandRange; 109 | if ( ( DepthInt % 4) == 0 ) 110 | { 111 | DepthNorm = 1; 112 | } 113 | } 114 | 115 | DepthNorm = clamp( 0, 1, DepthNorm ); 116 | DepthNorm = 1 - DepthNorm; 117 | 118 | return float4( DepthNorm, DepthNorm, DepthNorm, 1 ); 119 | } 120 | ENDCG 121 | } 122 | } 123 | FallBack "Diffuse" 124 | } -------------------------------------------------------------------------------- /BlitDepth.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f611e95bbc495460ea24993c07d216b1 3 | timeCreated: 1491475402 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /BlitTriangle.shader: -------------------------------------------------------------------------------- 1 | Shader "NewChromantics/Blit Triangle" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Tags { "RenderType"="Opaque" } 10 | LOD 100 11 | 12 | Pass 13 | { 14 | CGPROGRAM 15 | #pragma vertex vert 16 | #pragma fragment frag 17 | 18 | #include "UnityCG.cginc" 19 | #include "PopCommon.cginc" 20 | 21 | struct appdata 22 | { 23 | float4 vertex : POSITION; 24 | float2 uv : TEXCOORD0; 25 | }; 26 | 27 | struct v2f 28 | { 29 | float2 uv : TEXCOORD0; 30 | float4 vertex : SV_POSITION; 31 | }; 32 | 33 | sampler2D _MainTex; 34 | float4 _MainTex_ST; 35 | 36 | #define TriangleCount 1 37 | #define MAX_TRIANGLE_COUNT TriangleCount 38 | float2 TriangleUvs[MAX_TRIANGLE_COUNT*3]; 39 | float4 TriangleColours[MAX_TRIANGLE_COUNT*3]; 40 | 41 | 42 | v2f vert (appdata v) 43 | { 44 | v2f o; 45 | o.vertex = UnityObjectToClipPos(v.vertex); 46 | o.uv = v.uv; 47 | return o; 48 | } 49 | 50 | 51 | fixed4 frag (v2f i) : SV_Target 52 | { 53 | // start with original colour 54 | float4 Colour = tex2D(_MainTex, i.uv); 55 | 56 | int TriangleIndex = 0; 57 | for ( int t=0; t= MaxPoolSize; } } 26 | 27 | static public int CountBytes(List Arrays) 28 | { 29 | var Total = 0; 30 | foreach ( var Array in Arrays ) 31 | Total += Array.Length; 32 | return Total; 33 | } 34 | 35 | 36 | List FreeArrays = new List(); 37 | List UsedArrays = new List(); 38 | 39 | void TrimArrays() 40 | { 41 | FreeArrays.Clear(); 42 | } 43 | 44 | public byte[] Alloc(byte[] CopyThisArray,bool AllowBiggerSize=false) 45 | { 46 | var NewArray = Alloc( CopyThisArray.Length, AllowBiggerSize ); 47 | CopyThisArray.CopyTo( NewArray, 0 ); 48 | return NewArray; 49 | } 50 | 51 | public byte[] Alloc(int Size,bool AllowBiggerSize=false) 52 | { 53 | lock(FreeArrays) 54 | { 55 | // find free array that fits 56 | for ( int i=0; i Size ) 64 | continue; 65 | 66 | // this fits! 67 | FreeArrays.RemoveAt(i); 68 | UsedArrays.Add(Array); 69 | return Array; 70 | } 71 | 72 | // not allowed to allocate more 73 | if ( TotalAllocatedArrays >= MaxPoolSize ) 74 | TrimArrays(); 75 | if ( TotalAllocatedArrays >= MaxPoolSize ) 76 | throw new System.Exception("Byte pool full " + TotalAllocatedArrays + "/" + MaxPoolSize ); 77 | 78 | // allocate a new array 79 | var NewArray = new byte[Size]; 80 | UsedArrays.Add( NewArray ); 81 | return NewArray; 82 | } 83 | } 84 | 85 | public void Release(byte[] ReleasedBuffer) 86 | { 87 | lock(FreeArrays) 88 | { 89 | if (!UsedArrays.Remove (ReleasedBuffer)) { 90 | Debug.LogError ("Tried to remove ByteBuffer (" + ReleasedBuffer.Length + ") from pool that does not belong"); 91 | return; 92 | } 93 | 94 | // move out of used arrays 95 | // gr: more error checking plz! 96 | FreeArrays.Add(ReleasedBuffer); 97 | } 98 | } 99 | }; 100 | 101 | -------------------------------------------------------------------------------- /BytePool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f3b386b114ed6f43a397414b777359d 3 | timeCreated: 1496509210 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /CameraExport360.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | 8 | 9 | 10 | public class CameraExport360 { 11 | 12 | [Range(0, 100)] 13 | const int JpegQuality = 100; 14 | const string BlitCubemapToEquirect_ShaderName = "BlitCubemapToEquirect"; 15 | 16 | #if UNITY_EDITOR 17 | [MenuItem("CONTEXT/Camera/Capture 360 to png...")] 18 | public static void Capture360ToPng(MenuCommand menuCommand) 19 | { 20 | Capture360ToFile(menuCommand, PopX.IO.ImageFileType.png); 21 | } 22 | #endif 23 | 24 | #if UNITY_EDITOR 25 | [MenuItem("CONTEXT/Camera/Capture 360 to jpeg...")] 26 | public static void Capture360ToJpeg(MenuCommand menuCommand) 27 | { 28 | Capture360ToFile(menuCommand, PopX.IO.ImageFileType.jpg); 29 | } 30 | #endif 31 | 32 | #if UNITY_EDITOR 33 | [MenuItem("CONTEXT/Camera/Capture 360 to exr...")] 34 | public static void Capture360ToExr(MenuCommand menuCommand) 35 | { 36 | Capture360ToFile(menuCommand, PopX.IO.ImageFileType.exr); 37 | } 38 | #endif 39 | 40 | #if UNITY_EDITOR 41 | public static void Capture360ToFile(MenuCommand menuCommand,PopX.IO.ImageFileType FileType) 42 | { 43 | var cam = menuCommand.context as Camera; 44 | var Texture = Capture360ToTexture(cam); 45 | 46 | var DefaultName = cam.name + "_360"; 47 | System.Action SaveTextureToFile = (Extension,Filename) => 48 | { 49 | byte[] Bytes = null; 50 | 51 | switch (Extension) 52 | { 53 | case PopX.IO.ImageFileType.jpg: 54 | Bytes = Texture.EncodeToJPG(JpegQuality); 55 | break; 56 | 57 | case PopX.IO.ImageFileType.png: 58 | Bytes = Texture.EncodeToPNG(); 59 | break; 60 | 61 | case PopX.IO.ImageFileType.exr: 62 | Bytes = Texture.EncodeToEXR(); 63 | break; 64 | 65 | default: 66 | throw new System.Exception("Don't know how to export texture to " + Extension); 67 | } 68 | 69 | System.IO.File.WriteAllBytes(Filename, Bytes); 70 | }; 71 | 72 | PopX.IO.SaveFile(DefaultName,FileType,SaveTextureToFile); 73 | } 74 | #endif 75 | 76 | public static Shader GetCubemapToEquirectShader() 77 | { 78 | #if UNITY_EDITOR 79 | var AssetGuids = AssetDatabase.FindAssets(BlitCubemapToEquirect_ShaderName); 80 | foreach (var AssetGuid in AssetGuids) 81 | { 82 | try 83 | { 84 | var AssetPath = AssetDatabase.GUIDToAssetPath(AssetGuid); 85 | var AssetShader = AssetDatabase.LoadAssetAtPath(AssetPath); 86 | return AssetShader; 87 | } 88 | catch (System.Exception e) 89 | { 90 | Debug.LogError("Failed to grab shader asset " + AssetGuid + ": " + e.Message ); 91 | } 92 | } 93 | throw new System.Exception("Failed to find shader " + BlitCubemapToEquirect_ShaderName); 94 | #else 95 | throw new System.Exception("This is currently editor only. Change caller to allow shader param to allow capture in-player"); 96 | #endif 97 | } 98 | 99 | public static Texture2D Capture360ToTexture(Camera cam) 100 | { 101 | var rt = RenderTexture.GetTemporary(4096, 4096, 0, RenderTextureFormat.ARGB32); 102 | try 103 | { 104 | Capture360ToRenderTexture(cam, rt); 105 | var Output = PopX.Textures.GetTexture2D(rt, false); 106 | RenderTexture.ReleaseTemporary(rt); 107 | return Output; 108 | } 109 | catch 110 | { 111 | RenderTexture.ReleaseTemporary(rt); 112 | throw; 113 | } 114 | } 115 | 116 | public static void Capture360ToRenderTexture(Camera cam,RenderTexture Target) 117 | { 118 | Target.dimension = UnityEngine.Rendering.TextureDimension.Cube; 119 | if ( !cam.RenderToCubemap(Target) ) 120 | throw new System.Exception("cam(" + cam.name + ").RenderToCubemap failed"); 121 | 122 | // take a temp texture, turn it into an equirect and return 123 | var EquirectShader = GetCubemapToEquirectShader(); 124 | 125 | var EquirectTarget = RenderTexture.GetTemporary(Target.width, Target.height, 0, Target.format); 126 | try 127 | { 128 | var EquirectShader_CubemapUniform = "Cubemap"; 129 | var EquirectShader_UseCubemapKeyword = "USE_CUBEMAP"; 130 | 131 | var EquirectMaterial = new Material(EquirectShader); 132 | EquirectMaterial.SetTexture(EquirectShader_CubemapUniform, Target); 133 | EquirectMaterial.EnableKeyword(EquirectShader_UseCubemapKeyword); 134 | 135 | Graphics.Blit(Target, EquirectTarget, EquirectMaterial); 136 | Graphics.Blit( EquirectTarget, Target ); 137 | RenderTexture.ReleaseTemporary(EquirectTarget); 138 | } 139 | catch 140 | { 141 | RenderTexture.ReleaseTemporary(EquirectTarget); 142 | throw; 143 | } 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /CameraExport360.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a89dd36e586b43298b96f5a37ac8c16 3 | timeCreated: 1519393261 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /CameraPreviewWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | 9 | 10 | #if UNITY_EDITOR 11 | public class CameraPreviewWindow : UnityEditor.EditorWindow 12 | { 13 | public Camera mCamera; 14 | public RenderTexture mRenderTexture; 15 | 16 | // Add menu named "My Window" to the Window menu 17 | [MenuItem ("NewChromantics/Camera Preview Window/Create Camera Preview Window")] 18 | static void Init () 19 | { 20 | // create a new window 21 | var NewWindow = EditorWindow.CreateInstance(); 22 | NewWindow.ShowUtility(); 23 | } 24 | 25 | void UpdateRenderTexture(Rect WindowSize) 26 | { 27 | // render camera 28 | if (mCamera == null) { 29 | mRenderTexture = null; 30 | } else { 31 | if (mRenderTexture != null && (mRenderTexture.width != WindowSize.width || mRenderTexture.height != WindowSize.height)) { 32 | mRenderTexture = null; 33 | } 34 | 35 | if (mRenderTexture == null) { 36 | int CameraRenderTextureDepth = (mCamera.targetTexture != null) ? mCamera.targetTexture.depth : 24; 37 | mRenderTexture = new RenderTexture ( (int)WindowSize.width, (int)WindowSize.height, CameraRenderTextureDepth); 38 | } 39 | 40 | var OldTarget = mCamera.targetTexture; 41 | mCamera.targetTexture = mRenderTexture; 42 | mCamera.Render (); 43 | mCamera.targetTexture = OldTarget; 44 | 45 | } 46 | } 47 | 48 | void SnapWindowToDisplay() 49 | { 50 | if ( mCamera == null ) 51 | return; 52 | 53 | // get disp 54 | } 55 | 56 | void OnGUI() 57 | { 58 | var Rect = this.position; 59 | Rect.x = 0; 60 | Rect.y = 0; 61 | 62 | // draw camera selection 63 | { 64 | int SelectedCamera = 0; 65 | List CameraNames = new List (); 66 | CameraNames.Add ("null"); 67 | 68 | // add the other cameras in the scene 69 | foreach (Camera Cam in Camera.allCameras) { 70 | CameraNames.Add (Cam.name); 71 | if (mCamera == Cam) 72 | SelectedCamera = CameraNames.Count - 1; 73 | } 74 | 75 | int NewSelectedCamera = EditorGUILayout.Popup ( SelectedCamera, CameraNames.ToArray(), GUILayout.ExpandWidth (true)); 76 | 77 | // changed camera 78 | if (NewSelectedCamera != SelectedCamera) { 79 | if (NewSelectedCamera == 0) { 80 | mCamera = null; 81 | } else { 82 | mCamera = Camera.allCameras [NewSelectedCamera -1]; 83 | } 84 | } 85 | } 86 | 87 | { 88 | if (GUILayout.Button ("Snap to display")) { 89 | SnapWindowToDisplay (); 90 | } 91 | } 92 | 93 | 94 | // draw the content! 95 | { 96 | // move the rect to go past all the previous controls 97 | var LastBottom = GUILayoutUtility.GetLastRect ().yMax; 98 | Rect.y += LastBottom; 99 | Rect.height -= LastBottom; 100 | 101 | UpdateRenderTexture (Rect); 102 | if (mRenderTexture == null) { 103 | GUI.Box (Rect, "No camera"); 104 | } else { 105 | GUI.DrawTexture (Rect, mRenderTexture); 106 | } 107 | } 108 | } 109 | } 110 | #endif 111 | -------------------------------------------------------------------------------- /CameraPreviewWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b61495750b184eb6bcb54f56b79b467 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ColourToLum.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "PopUnityCommon/ColourToLum" { 4 | Properties { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader { 8 | Pass 9 | { 10 | CGPROGRAM 11 | #pragma vertex vert 12 | #pragma fragment frag 13 | 14 | sampler2D _MainTex; 15 | 16 | struct VertexInput { 17 | float4 Position : POSITION; 18 | float2 uv_MainTex : TEXCOORD0; 19 | }; 20 | 21 | struct FragInput { 22 | float4 Position : SV_POSITION; 23 | float2 uv_MainTex : TEXCOORD0; 24 | }; 25 | 26 | 27 | float RgbaToLum(fixed4 Rgba) 28 | { 29 | // gr: get proper lum weights 30 | float Lumr = Rgba.x * 0.3333f; 31 | float Lumg = Rgba.y * 0.3333f; 32 | float Lumb = Rgba.z * 0.3333f; 33 | return Lumr + Lumg + Lumb; 34 | } 35 | 36 | float GetLuminance(float2 BlockUv,int XOffset,int YOffset) 37 | { 38 | fixed4 Rgba = tex2D ( _MainTex, BlockUv ); 39 | return RgbaToLum( Rgba ); 40 | } 41 | 42 | FragInput vert(VertexInput In) { 43 | FragInput Out; 44 | Out.Position = UnityObjectToClipPos (In.Position ); 45 | Out.uv_MainTex = In.uv_MainTex; 46 | return Out; 47 | } 48 | 49 | fixed4 frag(FragInput In) : SV_Target { 50 | 51 | float Lum = GetLuminance( In.uv_MainTex, 0, 0 ); 52 | 53 | return float4( Lum, Lum, Lum, 1 ); 54 | return fixed4(1,1,0,1); 55 | } 56 | 57 | ENDCG 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ColourToLum.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0e3369b3659240a199800c921189518 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /CommandBuffy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using UnityEngine.Events; 6 | 7 | [System.Serializable] 8 | public class UnityEvent_OnCaptureTextureCreated : UnityEvent {} 9 | 10 | 11 | public class CommandBuffy : MonoBehaviour { 12 | 13 | public RenderTexture Target; 14 | [ShowIfAttribute("TargetIsNull")] 15 | public RenderTextureFormat TargetFormat = RenderTextureFormat.ARGBFloat; 16 | 17 | [Range(1,4096)] 18 | [ShowIfAttribute("TargetIsNull")] 19 | public int TargetWidth = 2048; 20 | 21 | [Range(1,4096)] 22 | [ShowIfAttribute("TargetIsNull")] 23 | public int TargetHeight = 2048; 24 | 25 | [Header("Called if we create a target so you can assign to a material etc, or just called in start")] 26 | public UnityEvent_OnCaptureTextureCreated OnCaptureTextureCreated; 27 | 28 | [Header("When to capture from the screen")] 29 | public CameraEvent CaptureAfterEvent = CameraEvent.AfterSkybox; 30 | 31 | [ShowIfAttribute("CaptureEventRequiresDepthMode")] 32 | public bool SetCameraDepthMode = false; 33 | 34 | public BuiltinRenderTextureType CaptureSource = BuiltinRenderTextureType.CurrentActive; 35 | 36 | public bool AssignToAllCameras = true; 37 | 38 | [ShowIfAttribute("IsAssignToSpecificCameras")] 39 | public List AssignToCameraList; 40 | 41 | 42 | Dictionary CameraCommands; 43 | 44 | 45 | bool CaptureEventRequiresDepthMode() 46 | { 47 | switch ( CaptureAfterEvent ) 48 | { 49 | case CameraEvent.AfterDepthNormalsTexture: 50 | case CameraEvent.AfterDepthTexture: 51 | case CameraEvent.BeforeDepthNormalsTexture: 52 | case CameraEvent.BeforeDepthTexture: 53 | return true; 54 | default: 55 | return false; 56 | } 57 | } 58 | 59 | 60 | bool TargetIsNull() 61 | { 62 | return Target == null; 63 | } 64 | 65 | bool IsAssignToSpecificCameras() 66 | { 67 | return !AssignToAllCameras; 68 | } 69 | 70 | void Start () 71 | { 72 | if (Target == null) { 73 | Target = new RenderTexture (TargetWidth, TargetHeight, 0, TargetFormat); 74 | } 75 | OnCaptureTextureCreated.Invoke (Target); 76 | } 77 | 78 | void OnEnable() 79 | { 80 | var CameraList = AssignToAllCameras ? Camera.allCameras : AssignToCameraList.ToArray (); 81 | if (CameraList != null) { 82 | foreach (var Cam in CameraList) { 83 | CreateCommand (Cam); 84 | } 85 | } 86 | } 87 | 88 | void OnDisable() 89 | { 90 | if (CameraCommands != null) { 91 | foreach (var Cam in CameraCommands.Keys) { 92 | ReleaseCommand (Cam); 93 | } 94 | } 95 | } 96 | 97 | void CreateCommand(Camera Cam) 98 | { 99 | // if command already exists, replace it 100 | ReleaseCommand(Cam); 101 | 102 | // make new command 103 | var Command = new CommandBuffer(); 104 | Command.name = this.name; 105 | 106 | var DepthNormalsEvent = (CaptureAfterEvent == CameraEvent.AfterDepthNormalsTexture) || (CaptureAfterEvent == CameraEvent.BeforeDepthNormalsTexture); 107 | var DepthEvent = (CaptureAfterEvent == CameraEvent.AfterDepthTexture) || (CaptureAfterEvent == CameraEvent.BeforeDepthTexture); 108 | 109 | if (DepthEvent && Cam.depthTextureMode == DepthTextureMode.None) { 110 | if (SetCameraDepthMode) 111 | Cam.depthTextureMode = DepthTextureMode.Depth; 112 | else 113 | Debug.LogWarning ("Trying to capture " + CaptureSource + " but camera depth mode is " + Cam.depthTextureMode); 114 | } 115 | 116 | if (DepthNormalsEvent && Cam.depthTextureMode != DepthTextureMode.DepthNormals) { 117 | if (SetCameraDepthMode) 118 | Cam.depthTextureMode = DepthTextureMode.DepthNormals; 119 | else 120 | Debug.LogWarning ("Trying to capture " + CaptureSource + " but camera depth mode is " + Cam.depthTextureMode); 121 | } 122 | 123 | Debug.Log ("Camera " + Cam.name + " depth mode is " + Cam.depthTextureMode); 124 | 125 | // get target id 126 | var TargetId = new RenderTargetIdentifier(Target); 127 | var SourceId = new RenderTargetIdentifier (CaptureSource); 128 | 129 | Command.Blit (SourceId, TargetId); 130 | 131 | Cam.AddCommandBuffer (CaptureAfterEvent,Command); 132 | 133 | if ( CameraCommands == null ) 134 | CameraCommands = new Dictionary (); 135 | 136 | CameraCommands.Add (Cam, Command); 137 | } 138 | 139 | void ReleaseCommand(Camera Cam) 140 | { 141 | if (CameraCommands == null) 142 | return; 143 | 144 | if (!CameraCommands.ContainsKey (Cam)) 145 | return; 146 | 147 | Cam.RemoveCommandBuffer (CaptureAfterEvent,CameraCommands [Cam]); 148 | CameraCommands [Cam].Release (); 149 | CameraCommands.Remove (Cam); 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /CommandBuffy.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 165626605fc414285933e743192526d0 3 | timeCreated: 1494495509 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Distort.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "NewChromantics/Distort" { 4 | Properties { 5 | _MainTex ("_MainTex", 2D) = "green" {} 6 | Invert("Invert",Int) = 0 7 | ZoomUv("ZoomUv", Range(-1,2) ) = 0 8 | Debug("Debug",Int) = 0 9 | LensOffsetX("LensOffsetX", Range(-1,1)) = 0 10 | LensOffsetY("LensOffsetY", Range(-1,1)) = 0 11 | RadialDistortionX("RadialDistortionX", Range(-1.57,1.57)) = 0 12 | RadialDistortionY("RadialDistortionY", Range(-1.57,1.57)) = 0 13 | TangentialDistortionX("TangentialDistortionX", Range(-1.57,1.57)) = 0 14 | TangentialDistortionY("TangentialDistortionY", Range(-1.57,1.57)) = 0 15 | K5Distortion("K5Distortion", Range(-1.57,1.57)) = 0 16 | } 17 | SubShader 18 | { 19 | Pass 20 | { 21 | CGPROGRAM 22 | #pragma vertex vert 23 | #pragma fragment frag 24 | #include "UnityCG.cginc" 25 | sampler2D _MainTex; 26 | int Debug; 27 | float RadialDistortionX; 28 | float RadialDistortionY; 29 | float TangentialDistortionX; 30 | float TangentialDistortionY; 31 | float K5Distortion; 32 | float LensOffsetX; 33 | float LensOffsetY; 34 | int Invert; 35 | float ZoomUv; 36 | 37 | 38 | struct VertexInput { 39 | float4 Position : POSITION; 40 | float2 uv_MainTex : TEXCOORD0; 41 | }; 42 | 43 | struct FragInput { 44 | float4 Position : SV_POSITION; 45 | float2 uv_MainTex : TEXCOORD0; 46 | }; 47 | 48 | 49 | FragInput vert(VertexInput In) { 50 | FragInput Out; 51 | 52 | Out.Position = UnityObjectToClipPos (In.Position ); 53 | Out.uv_MainTex = In.uv_MainTex; 54 | 55 | return Out; 56 | } 57 | 58 | // http://stackoverflow.com/questions/21615298/opencv-distort-back 59 | float2 DistortPixel(float2 Point) 60 | { 61 | float Inverse = Invert?-1:1; 62 | float cx = LensOffsetX; 63 | float cy = LensOffsetY; 64 | float k1 = RadialDistortionX * Inverse; 65 | float k2 = RadialDistortionY * Inverse; 66 | float p1 = TangentialDistortionX * Inverse; 67 | float p2 = TangentialDistortionY * Inverse; 68 | float k3 = K5Distortion * Inverse; 69 | 70 | 71 | float x = Point.x - cx; 72 | float y = Point.y - cy; 73 | float r2 = x*x + y*y; 74 | 75 | // Radial distorsion 76 | float xDistort = x * (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2); 77 | float yDistort = y * (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2); 78 | 79 | // Tangential distorsion 80 | xDistort = xDistort + (2 * p1 * x * y + p2 * (r2 + 2 * x * x)); 81 | yDistort = yDistort + (p1 * (r2 + 2 * y * y) + 2 * p2 * x * y); 82 | 83 | // Back to absolute coordinates. 84 | xDistort = xDistort + cx; 85 | yDistort = yDistort + cy; 86 | 87 | return float2( xDistort, yDistort); 88 | } 89 | 90 | // 0..1 to -1..1 91 | float2 CenterUv(float2 uv) 92 | { 93 | uv = uv*float2(2,2) - float2(1,1); 94 | return uv; 95 | } 96 | 97 | float2 UncenterUv(float2 uv) 98 | { 99 | uv = (uv+float2(1,1)) / float2(2,2); 100 | return uv; 101 | } 102 | 103 | fixed4 frag(FragInput In) : SV_Target { 104 | 105 | float2 uv = In.uv_MainTex; 106 | uv = CenterUv(uv); 107 | uv *= 1.0f / ZoomUv; 108 | uv = DistortPixel( uv ); 109 | uv = UncenterUv(uv); 110 | 111 | if ( uv.x > 1 ) 112 | return float4(1,0,0,1); 113 | if ( uv.y > 1 ) 114 | return float4(0,1,0,1); 115 | if ( uv.x < 0 ) 116 | return float4(0,0,1,1); 117 | if ( uv.y < 0 ) 118 | return float4(1,1,0,1); 119 | 120 | uv = CenterUv(uv); 121 | uv *= 1.0f / ZoomUv; 122 | uv = UncenterUv(uv); 123 | 124 | float4 Sample = tex2D( _MainTex, uv ); 125 | 126 | if ( Debug ) 127 | return float4( uv.x, uv.y, Sample.x, 1 ); 128 | 129 | return Sample; 130 | 131 | } 132 | 133 | ENDCG 134 | } 135 | } 136 | } -------------------------------------------------------------------------------- /Distort.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7c874425d52b74ffcb96b471ac1ec5b1 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd82de838d2074cf78e490904575eb4a 3 | folderAsset: yes 4 | timeCreated: 1515427144 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Editor/PopData_Test.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | using NUnit.Framework; 6 | 7 | 8 | namespace PopX 9 | { 10 | public class Data_UnitTest 11 | { 12 | [Test] 13 | public void FindPattern_Match() 14 | { 15 | var Needle = "cat"; 16 | var Haystack = "Are we out of cat food again?"; 17 | var HaystackBytes = System.Text.Encoding.ASCII.GetBytes (Haystack); 18 | var ExceptedNeedlePos = Haystack.IndexOf (Needle); 19 | 20 | // test match 21 | var MatchPos = Data.FindPattern ( HaystackBytes, Needle.ToCharArray ()); 22 | Assert.AreEqual (ExceptedNeedlePos, MatchPos); 23 | } 24 | 25 | [Test] 26 | public void FindPattern_NotFound() 27 | { 28 | var Haystack = "Are we out of cat food again?"; 29 | var HaystackBytes = System.Text.Encoding.ASCII.GetBytes (Haystack); 30 | 31 | // test not found, should throw 32 | try 33 | { 34 | Data.FindPattern(HaystackBytes, "dog".ToCharArray() ); 35 | throw new System.Exception("Failed to NOT-FIND pattern"); 36 | } 37 | catch(PopX.Data.NotFound) 38 | { 39 | // expected behaviour 40 | } 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Editor/PopData_Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a64110e13d894dfc9530c8f291a7de0 3 | timeCreated: 1515500933 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/PopJson_Test.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | using NUnit.Framework; 6 | 7 | 8 | namespace PopX 9 | { 10 | public class Json_UnitTest 11 | { 12 | [System.Serializable] 13 | public class StructHello 14 | { 15 | public string Hello; 16 | 17 | public StructHello(string _HelloValue) 18 | { 19 | Hello = _HelloValue; 20 | } 21 | }; 22 | 23 | [System.Serializable] 24 | public class StructHelloCat : StructHello 25 | { 26 | public string Cat; 27 | 28 | public StructHelloCat(string _HelloValue,string _CatValue) : base(_HelloValue) 29 | { 30 | Cat = _CatValue; 31 | } 32 | }; 33 | 34 | [Test] 35 | public void Replace_Test() 36 | { 37 | // use a struct to avoid whitespace hassle. We just need to know if it de/serialises 38 | var Struct = new StructHello ("World"); 39 | var NewValue = "Universe"; 40 | var Json = JsonUtility.ToJson (Struct); 41 | PopX.Json.Replace (ref Json, "Hello", NewValue); 42 | JsonUtility.FromJsonOverwrite (Json, Struct); 43 | 44 | Assert.AreEqual ( NewValue,Struct.Hello); 45 | } 46 | 47 | [Test] 48 | public void Append_ToEmptyJson() 49 | { 50 | var Json = "{}"; 51 | var Value = "World"; 52 | PopX.Json.Append (ref Json, "Hello",Value); 53 | 54 | // read new json (will throw json syntax errors for us) 55 | var Struct = JsonUtility.FromJson(Json); 56 | 57 | Assert.AreEqual (Value,Struct.Hello); 58 | } 59 | 60 | [Test] 61 | public void Append_ToShallowJson() 62 | { 63 | var Json = JsonUtility.ToJson (new StructHello ("World")); 64 | var CatValue = "Dog"; 65 | PopX.Json.Append (ref Json, "Cat", CatValue ); 66 | 67 | // read new json (will throw json syntax errors for us) 68 | var Struct = JsonUtility.FromJson(Json); 69 | 70 | Assert.AreEqual (CatValue,Struct.Cat); 71 | } 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /Editor/PopJson_Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7cd057161d89f421da7aac2011126e8d 3 | timeCreated: 1515427154 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Editor/PopMaterial_Test.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | using NUnit.Framework; 6 | 7 | 8 | namespace PopX 9 | { 10 | public class Material_UnitTest 11 | { 12 | [Test] 13 | public void FindProperties() 14 | { 15 | var Shader = @"Shader ShaderName 16 | { 17 | Properties 18 | { 19 | Colour(""Colour"", COLOR) = (1, 1, 1, 1) 20 | TextureVar( ""SomeTexture"" , 2D ) = ""white"" 21 | } 22 | SubShader 23 | { 24 | } 25 | }"; 26 | 27 | var Props = PopX.Materials.GetProperties(Shader); 28 | Assert.AreEqual(Props["Colour"], typeof(Color)); 29 | Assert.AreEqual(Props["TextureVar"], typeof(Texture)); 30 | 31 | } 32 | 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Editor/PopMaterial_Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a76871310a8446cab9af5cbeaab7add 3 | timeCreated: 1520548902 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /EditorScopedProgressBar.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | 9 | /* 10 | To make this go out of scope without having to call YourProgress.Dispose() or GC.Collect, use the Using keyword 11 | 12 | using (var Progress = new ScopedProgressBar()) 13 | { 14 | ... 15 | } 16 | */ 17 | public class ScopedProgressBar : System.IDisposable 18 | { 19 | #if UNITY_EDITOR 20 | string mTitle; 21 | bool ShowProgressBar = true; 22 | int NotifyCounter = 0; 23 | #endif 24 | 25 | // gr: added a simple bool to disable rendering of the progress bar so caller can quickly turn on&off and still use using() 26 | public ScopedProgressBar(string Title,bool ShowProgressBar=true) 27 | { 28 | #if UNITY_EDITOR 29 | this.ShowProgressBar = ShowProgressBar; 30 | this.mTitle = Title; 31 | if ( ShowProgressBar ) 32 | EditorUtility.DisplayProgressBar (mTitle, "...", 0.0f); 33 | #endif 34 | } 35 | 36 | ~ScopedProgressBar() 37 | { 38 | // can't use destructor, not on the unity main thread. have to use disposable interface. 39 | //Dispose (); 40 | } 41 | 42 | public void Dispose() 43 | { 44 | #if UNITY_EDITOR 45 | if (!ShowProgressBar) 46 | return; 47 | EditorUtility.ClearProgressBar(); 48 | #endif 49 | } 50 | 51 | // use NotifyEveryNth (eg.=100) if you're doing large sets as the GUI update will slow down your thread, and you probably don't need to see progress for every one in 300,000 steps 52 | public void SetProgress(string StepName,int Step,int StepCount,int NotifyEveryNth=1) 53 | { 54 | #if UNITY_EDITOR 55 | // gr: we now have a notify counter for steps which aren't linear 56 | // eg. parsing chunks of a file that skip lines 57 | NotifyCounter++; 58 | bool Notify = (NotifyCounter % Mathf.Max(1,NotifyEveryNth)) == 0; 59 | Notify |= (Step % Mathf.Max(1,NotifyEveryNth)) == 0; 60 | 61 | if (!Notify) 62 | return; 63 | StepName += " " + Step + "/" + StepCount; 64 | SetProgress (StepName, Step / (float)StepCount); 65 | #endif 66 | } 67 | 68 | public void SetProgress(string StepName,float Progress) 69 | { 70 | #if UNITY_EDITOR 71 | if (!ShowProgressBar) 72 | return; 73 | if (EditorUtility.DisplayCancelableProgressBar (mTitle, StepName, Progress)) 74 | throw new System.Exception (mTitle + " cancelled"); 75 | #endif 76 | } 77 | }; 78 | 79 | -------------------------------------------------------------------------------- /EditorScopedProgressBar.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3a314cdd01b04828a6b0621bde38fe4 3 | timeCreated: 1491839780 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /EventTrigger.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine.Events; 3 | using UnityEngine; 4 | 5 | public class EventTrigger : MonoBehaviour 6 | { 7 | 8 | [Header("Normal triggers")] 9 | public UnityEvent OnTriggered1; 10 | public UnityEvent OnTriggered2; 11 | public UnityEvent OnTriggered3; 12 | public UnityEvent OnTriggered4; 13 | public UnityEvent OnTriggered5; 14 | 15 | public void Trigger1() 16 | { 17 | OnTriggered1.Invoke(); 18 | } 19 | public void Trigger2() 20 | { 21 | OnTriggered2.Invoke(); 22 | } 23 | public void Trigger3() 24 | { 25 | OnTriggered3.Invoke(); 26 | } 27 | public void Trigger4() 28 | { 29 | OnTriggered4.Invoke(); 30 | } 31 | public void Trigger5() 32 | { 33 | OnTriggered5.Invoke(); 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /EventTrigger.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 56dea6d330640ec46911e3c99e43bb50 3 | timeCreated: 1493125438 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FilePathAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b4e4bdbf37c44677a37be9e2e6e8733 3 | timeCreated: 1494934628 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /FishEyeDistortion.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "NewChromantics/FishEyeDistortion" 4 | { 5 | Properties 6 | { 7 | _MainTex ("Texture", 2D) = "white" {} 8 | 9 | ZoomUv("ZoomUv",float) = 1.0 10 | BarrelPower("BarrelPower", Range(-1,1) ) = 0.5 11 | AntiFisheyeMult("AntiFisheyeMult", Range(0,20) ) = 10.0 12 | } 13 | SubShader 14 | { 15 | Tags { "RenderType"="Opaque" } 16 | LOD 100 17 | 18 | Pass 19 | { 20 | CGPROGRAM 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | #pragma exclude_renderers gles3 24 | #include "UnityCG.cginc" 25 | 26 | struct appdata 27 | { 28 | float4 vertex : POSITION; 29 | float2 uv : TEXCOORD0; 30 | }; 31 | 32 | struct v2f 33 | { 34 | float2 uv : TEXCOORD0; 35 | float4 vertex : SV_POSITION; 36 | }; 37 | 38 | sampler2D _MainTex; 39 | float4 _MainTex_ST; 40 | float ZoomUv; 41 | float BarrelPower; 42 | float AntiFisheyeMult; 43 | 44 | 45 | v2f vert (appdata v) 46 | { 47 | v2f o; 48 | o.vertex = UnityObjectToClipPos(v.vertex); 49 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 50 | return o; 51 | } 52 | 53 | float2 DistortPixel(float2 Point) 54 | { 55 | float2 fragCoord; 56 | fragCoord.x = (Point.x+1.0f)/2.0f; 57 | fragCoord.y = (Point.y+1.0f)/2.0f; 58 | float2 p = fragCoord.xy;//normalized coords with some cheat 59 | //(assume 1:1 prop) 60 | float2 m = float2(0.5, 0.5);//center coords 61 | float2 d = p - m;//vector from center to current fragment 62 | float r = sqrt(dot(d, d)); // distance of pixel from center 63 | 64 | float power = ( 2.0 * 3.141592 / (2.0 * sqrt(dot(m, m))) ) * (BarrelPower - 0.5);//amount of effect 65 | float bind;//radius of 1:1 effect 66 | bind = (power > 0.0) ? sqrt(dot(m, m)) : m.y;//stick to corners 67 | 68 | 69 | //Weird formulas 70 | float2 uv; 71 | if (power > 0.0)//fisheye 72 | uv = m + normalize(d) * tan(r * power*AntiFisheyeMult) * bind / tan( bind * power*AntiFisheyeMult); 73 | else if (power < 0.0)//antifisheye 74 | uv = m + normalize(d) * atan(r * -power * AntiFisheyeMult) * bind / atan(-power * bind * AntiFisheyeMult); 75 | else 76 | uv = p;//no effect for power = 1.0 77 | 78 | uv.x = (uv.x * 2.0f) - 1.0f; 79 | uv.y = (uv.y * 2.0f) - 1.0f; 80 | return float2(uv.x, uv.y ); 81 | } 82 | 83 | // 0..1 to -1..1 84 | float2 CenterUv(float2 uv) 85 | { 86 | // gr: distort maths is for 0=bottom... so flip here for now 87 | uv.y = 1 - uv.y; 88 | 89 | uv = uv*float2(2,2) - float2(1,1); 90 | return uv; 91 | } 92 | 93 | float2 UncenterUv(float2 uv) 94 | { 95 | uv = (uv+float2(1,1)) / float2(2,2); 96 | 97 | // gr: distort maths is for 0=bottom... so flip here for now 98 | uv.y = 1 - uv.y; 99 | return uv; 100 | } 101 | 102 | 103 | 104 | fixed4 frag (v2f i) : SV_Target 105 | { 106 | float2 uv = i.uv; 107 | 108 | uv = CenterUv(uv); 109 | uv *= 1.0f / ZoomUv; 110 | uv = DistortPixel( uv ); 111 | uv = UncenterUv(uv); 112 | 113 | 114 | if ( uv.x > 1 ) 115 | { 116 | return float4(1,0,0,1); 117 | } 118 | if ( uv.y > 1 ) 119 | { 120 | return float4(0,1,0,1); 121 | } 122 | if ( uv.x < 0 ) 123 | { 124 | return float4(0,0,1,1); 125 | } 126 | if ( uv.y < 0 ) 127 | { 128 | return float4(1,1,0,1); 129 | } 130 | 131 | uv = CenterUv(uv); 132 | uv *= 1.0f / ZoomUv; 133 | uv = UncenterUv(uv); 134 | 135 | 136 | float4 Sample = tex2D( _MainTex, uv ); 137 | return Sample; 138 | } 139 | 140 | ENDCG 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /FishEyeDistortion.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29f338e48936e4595b7fb879abf17c7e 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /FixedArray.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | /* 8 | public class Vector2x4 : FixedArray 9 | { 10 | }; 11 | */ 12 | 13 | 14 | public interface SizePolicy 15 | { 16 | int Size{ get;} 17 | } 18 | 19 | public class of4 : SizePolicy 20 | { 21 | public int Size{ get { return 4;}} 22 | } 23 | 24 | // gr: cannot serialise a template! 25 | [System.Serializable] 26 | public class FixedArray where SizePolicyType : SizePolicy, new() 27 | { 28 | public Type this [int Index] { 29 | get { 30 | return Elements [Index]; 31 | } 32 | set { 33 | Elements [Index] = value; 34 | } 35 | } 36 | 37 | public int Length { get { return Size.Size; } } 38 | public int Count { get { return Size.Size; } } 39 | 40 | SizePolicyType Size = new SizePolicyType(); 41 | 42 | //[System.Serializable] 43 | Type[] _Elements; 44 | Type[] Elements { 45 | get { 46 | 47 | if (_Elements == null) 48 | _Elements = new Type[Length]; 49 | return _Elements; 50 | } 51 | } 52 | 53 | }; 54 | -------------------------------------------------------------------------------- /FixedArray.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df6f95adbac5543d6a68621b58b337ee 3 | timeCreated: 1516629781 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /FlipMirror.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "PopUnityCommon/FlipMirror" { 4 | Properties { 5 | _MainTex ("_MainTex", 2D) = "white" {} 6 | Flip("Flip", Int ) = 0 7 | Mirror("Mirror", Int ) = 0 8 | } 9 | SubShader { 10 | 11 | pass 12 | { 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | 17 | struct VertexInput { 18 | float4 Position : POSITION; 19 | float2 uv_MainTex : TEXCOORD0; 20 | }; 21 | 22 | struct FragInput { 23 | float4 Position : SV_POSITION; 24 | float2 uv_MainTex : TEXCOORD0; 25 | }; 26 | 27 | sampler2D _MainTex; // new lum 28 | int Flip; 29 | int Mirror; 30 | 31 | FragInput vert(VertexInput In) { 32 | FragInput Out; 33 | Out.Position = UnityObjectToClipPos (In.Position ); 34 | Out.uv_MainTex.y = Flip ? 1.0f - In.uv_MainTex.y : In.uv_MainTex.y; 35 | Out.uv_MainTex.x = Mirror ? 1.0f - In.uv_MainTex.x : In.uv_MainTex.x; 36 | return Out; 37 | } 38 | 39 | float4 frag(FragInput In) : SV_Target 40 | { 41 | return tex2D( _MainTex, In.uv_MainTex ); 42 | } 43 | ENDCG 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /FlipMirror.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 981bd70c3558a49078cdd38e44f496a5 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /GotoNextScene.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | using UnityEngine.SceneManagement; 6 | 7 | [System.Serializable] 8 | public class UnityEvent_float : UnityEvent {} 9 | 10 | 11 | 12 | public class GotoNextScene : MonoBehaviour { 13 | 14 | public enum SceneLoadMode 15 | { 16 | LoadNextScene, 17 | ReloadCurrentScene, 18 | LoadSpecificScene 19 | }; 20 | 21 | public SceneLoadMode LoadMode = SceneLoadMode.LoadNextScene; 22 | 23 | [ShowIf("ModeIs_LoadSpecificScene")] 24 | [SceneName] 25 | public string levelName; 26 | 27 | [InspectorButton("GotoNextScene")] 28 | public bool _GotoNextScene; 29 | 30 | [Header("If not zero, go to next scene after X secs from OnEnable")] 31 | [Range(0,180)] 32 | public float TriggerAfterSecs = 0; 33 | public bool DoTimedTrigger 34 | { 35 | get 36 | { 37 | return TriggerAfterSecs > 0; 38 | } 39 | } 40 | private float TriggerFromTime = 0; 41 | 42 | [Header("sends 0-1 of countdown")] 43 | public UnityEvent_float OnCountdown; 44 | 45 | public bool SkipOnMouseClick = false; 46 | 47 | 48 | bool ModeIs_LoadNextScene() 49 | { 50 | return LoadMode == SceneLoadMode.LoadNextScene; 51 | } 52 | 53 | bool ModeIs_ReloadCurrentScene() 54 | { 55 | return LoadMode == SceneLoadMode.ReloadCurrentScene; 56 | } 57 | 58 | bool ModeIs_LoadSpecificScene() 59 | { 60 | return LoadMode == SceneLoadMode.LoadSpecificScene; 61 | } 62 | 63 | public static void LoadNextScene() 64 | { 65 | var CurrentScene = SceneManager.GetActiveScene(); 66 | var CurrentSceneIndex = CurrentScene.buildIndex; 67 | var NextSceneIndex = (CurrentSceneIndex + 1) % SceneManager.sceneCountInBuildSettings; 68 | SceneManager.LoadScene(NextSceneIndex, LoadSceneMode.Single); 69 | } 70 | 71 | 72 | public void NextScene() 73 | { 74 | var CurrentScene = SceneManager.GetActiveScene(); 75 | 76 | switch( LoadMode ) 77 | { 78 | case SceneLoadMode.LoadNextScene: 79 | var CurrentSceneIndex = CurrentScene.buildIndex; 80 | var NextSceneIndex = (CurrentSceneIndex + 1) % SceneManager.sceneCountInBuildSettings; 81 | 82 | SceneManager.LoadScene(NextSceneIndex, LoadSceneMode.Single); 83 | break; 84 | 85 | case SceneLoadMode.ReloadCurrentScene: 86 | SceneManager.LoadScene(CurrentScene.name); 87 | break; 88 | 89 | case SceneLoadMode.LoadSpecificScene: 90 | SceneManager.LoadScene (levelName); 91 | break; 92 | } 93 | } 94 | 95 | void OnEnable() 96 | { 97 | TriggerFromTime = Time.time; 98 | } 99 | 100 | void Update () { 101 | 102 | if (SkipOnMouseClick) { 103 | if (Input.GetMouseButtonDown (0)) { 104 | NextScene (); 105 | } 106 | } 107 | 108 | if (DoTimedTrigger) { 109 | var TimeSinceStart = Time.time - TriggerFromTime; 110 | var CountdownFactor = Mathf.Clamp01 (TimeSinceStart / TriggerAfterSecs); 111 | //Debug.Log (CountdownFactor); 112 | OnCountdown.Invoke (CountdownFactor); 113 | if ( TimeSinceStart> TriggerAfterSecs) { 114 | NextScene (); 115 | } 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /GotoNextScene.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d7f0f8f182294040835f7ef9b91e296 3 | timeCreated: 1492094354 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /GuiHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6630965c8159d4932b4d3a915e75b098 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /InspectorButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | #if UNITY_EDITOR 3 | using UnityEditor; 4 | #endif 5 | using System.Reflection; 6 | 7 | 8 | // from https://www.reddit.com/r/Unity3D/comments/1s6czv/inspectorbutton_add_a_custom_button_to_your/ 9 | 10 | /// 11 | /// This attribute can only be applied to fields because its 12 | /// associated PropertyDrawer only operates on fields (either 13 | /// public or tagged with the [SerializeField] attribute) in 14 | /// the target MonoBehaviour. 15 | /// 16 | [System.AttributeUsage(System.AttributeTargets.Field)] 17 | public class InspectorButtonAttribute : PropertyAttribute 18 | { 19 | public static float kDefaultButtonWidth = 80; 20 | 21 | public readonly string MethodName; 22 | 23 | private float _buttonWidth = kDefaultButtonWidth; 24 | public float ButtonWidth 25 | { 26 | get { return _buttonWidth; } 27 | set { _buttonWidth = value; } 28 | } 29 | 30 | public InspectorButtonAttribute(string MethodName) 31 | { 32 | this.MethodName = MethodName; 33 | } 34 | } 35 | 36 | #if UNITY_EDITOR 37 | [CustomPropertyDrawer(typeof(InspectorButtonAttribute))] 38 | public class InspectorButtonPropertyDrawer : PropertyDrawer 39 | { 40 | private MethodInfo _eventMethodInfo = null; 41 | 42 | public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label) 43 | { 44 | InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute; 45 | //Rect buttonRect = new Rect(position.x + (position.width - inspectorButtonAttribute.ButtonWidth) * 0.5f, position.y, inspectorButtonAttribute.ButtonWidth, position.height); 46 | Rect buttonRect = position; 47 | if (GUI.Button(buttonRect, label.text)) 48 | { 49 | System.Type eventOwnerType = prop.serializedObject.targetObject.GetType(); 50 | string eventName = inspectorButtonAttribute.MethodName; 51 | 52 | if (_eventMethodInfo == null) 53 | _eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); 54 | 55 | if (_eventMethodInfo != null) 56 | _eventMethodInfo.Invoke(prop.serializedObject.targetObject, null); 57 | else 58 | Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType)); 59 | } 60 | } 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /InspectorButton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c71a412cb6dacf54cac3dbfe41728ff8 3 | timeCreated: 1480193188 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /JobThread.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c7f4e5e3429b44007bfe5927704f834a 3 | timeCreated: 1486483675 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /JsonSanitiser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff5c31b23c04f4959b97fd0b932a2994 3 | timeCreated: 1512485657 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 New Chromantics LTD 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be7884ace92eb4a149ddc756f8352e9f 3 | timeCreated: 1508970326 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /MeshBoundsGizmo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | /* 6 | * Display the mesh bounds as a gizmo. Because there's no built in way to do so 7 | */ 8 | [RequireComponent(typeof(MeshFilter))] 9 | public class MeshBoundsGizmo : MonoBehaviour { 10 | 11 | public Color Colour = Color.red; 12 | 13 | [ShowFunctionResult("GetBoundsMin")] 14 | public bool _Min; 15 | [ShowFunctionResult("GetBoundsMax")] 16 | public bool _Max; 17 | 18 | Vector3 GetBoundsMin() 19 | { 20 | var mf = GetComponent(); 21 | var m = mf.sharedMesh; 22 | var b = m.bounds; 23 | return b.min; 24 | } 25 | Vector3 GetBoundsMax() 26 | { 27 | var mf = GetComponent(); 28 | var m = mf.sharedMesh; 29 | var b = m.bounds; 30 | return b.max; 31 | } 32 | 33 | // to enable the enable checkbox 34 | void Update() 35 | { 36 | 37 | } 38 | 39 | void OnDrawGizmos() 40 | { 41 | if (!this.enabled) 42 | return; 43 | var mf = GetComponent(); 44 | var m = mf.sharedMesh; 45 | var b = m.bounds; 46 | 47 | Gizmos.matrix = this.transform.localToWorldMatrix; 48 | Gizmos.color = Colour; 49 | Gizmos.DrawWireCube(b.center, b.size); 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /MeshBoundsGizmo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02a4ee903c15c4f62b83b94794652334 3 | timeCreated: 1523880800 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /MicrophoneNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | using System.Reflection; 8 | #endif 9 | 10 | 11 | 12 | [System.AttributeUsage(System.AttributeTargets.Field)] 13 | public class MicrophoneNameAttribute : PropertyAttribute 14 | { 15 | } 16 | 17 | 18 | 19 | #if UNITY_EDITOR 20 | [CustomPropertyDrawer(typeof(MicrophoneNameAttribute))] 21 | public class MicrophoneNameAttributePropertyDrawer : PropertyDrawer 22 | { 23 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 24 | { 25 | var Attrib = (MicrophoneNameAttribute)attribute; 26 | var TargetObject = property.serializedObject.targetObject; 27 | 28 | var MicrophoneName = property.stringValue; 29 | 30 | EditorGUI.BeginChangeCheck(); 31 | 32 | var Options = new List(); 33 | var OtherIndex = Options.Count; 34 | var OtherLabel = "Custom..."; 35 | Options.Add(OtherLabel); 36 | int SelectedIndex = OtherIndex; 37 | var Devices = Microphone.devices; 38 | foreach (var Device in Devices) 39 | { 40 | if (MicrophoneName.Equals(Device)) 41 | SelectedIndex = Options.Count; 42 | Options.Add(Device); 43 | } 44 | 45 | 46 | position.height = base.GetPropertyHeight(property, label); 47 | 48 | var WasMatch = (SelectedIndex != OtherIndex); 49 | SelectedIndex = EditorGUI.Popup(position, property.displayName, SelectedIndex, Options.ToArray()); 50 | 51 | if (SelectedIndex == OtherIndex) 52 | { 53 | // need to reset the label if it changed, otherwise it'll revert back to a selection again 54 | if ( WasMatch ) 55 | MicrophoneName = ""; 56 | position.y += position.height; 57 | MicrophoneName = EditorGUI.TextField(position, OtherLabel, MicrophoneName); 58 | } 59 | else 60 | { 61 | MicrophoneName = Options[SelectedIndex]; 62 | } 63 | 64 | if (EditorGUI.EndChangeCheck()) 65 | { 66 | property.stringValue = MicrophoneName; 67 | } 68 | 69 | 70 | property.serializedObject.ApplyModifiedProperties(); 71 | } 72 | 73 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) 74 | { 75 | var OrigHeight = base.GetPropertyHeight(property, label); 76 | return OrigHeight * 2; 77 | } 78 | } 79 | #endif 80 | 81 | 82 | -------------------------------------------------------------------------------- /MicrophoneNameAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7699c2ce097a7841912cab2c361ac33 3 | timeCreated: 1536073753 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /NiceGraph.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2d7f6a0431c54592a401fca32aed9c3 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /OnCameraPreRenderCallback.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | // gr: I had a script in PopUnityCommon somewhere for this... 8 | [System.Serializable] 9 | public class UnityEvent_int : UnityEngine.Events.UnityEvent {} 10 | 11 | 12 | 13 | [RequireComponent(typeof(Camera))] 14 | public class OnCameraPreRenderCallback : MonoBehaviour { 15 | 16 | public UnityEvent_int OnPreRenderEye; 17 | public int LeftValue = 1; 18 | public int RightValue = 0; 19 | Camera ThisCamera; 20 | 21 | void Start() 22 | { 23 | ThisCamera = GetComponent (); 24 | } 25 | 26 | 27 | void OnPreRender () 28 | { 29 | var Left = (ThisCamera.stereoTargetEye == StereoTargetEyeMask.Left); 30 | OnPreRenderEye.Invoke (Left ? LeftValue : RightValue); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /OnCameraPreRenderCallback.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 495e06ab47cc34fe899a96a0a44d682d 3 | timeCreated: 1492110028 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /OnChangedAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | #if UNITY_EDITOR 8 | using UnityEditor; 9 | using System.Reflection; 10 | #endif 11 | 12 | [System.AttributeUsage(System.AttributeTargets.Field)] 13 | public class OnChangedAttribute : PropertyAttribute 14 | { 15 | public readonly string BeforeChangeFunctionName; 16 | public readonly string AfterChangeFunctionName; 17 | 18 | public OnChangedAttribute(string BeforeChangeFunctionName,string AfterChangeFunctionName) 19 | { 20 | this.BeforeChangeFunctionName = BeforeChangeFunctionName; 21 | this.AfterChangeFunctionName = AfterChangeFunctionName; 22 | } 23 | 24 | } 25 | 26 | 27 | #if UNITY_EDITOR 28 | [CustomPropertyDrawer(typeof(OnChangedAttribute))] 29 | public class OnChangedAttributePropertyDrawer : PropertyDrawer 30 | { 31 | private MethodInfo CachedEventMethodInfo = null; 32 | 33 | 34 | void CallOnChanged(Object TargetObject,OnChangedAttribute Attrib,string FunctionName) 35 | { 36 | if (string.IsNullOrEmpty (FunctionName)) 37 | return; 38 | 39 | var TargetObjectType = TargetObject.GetType(); 40 | 41 | if (CachedEventMethodInfo == null) 42 | CachedEventMethodInfo = TargetObjectType.GetMethod(FunctionName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); 43 | 44 | if (CachedEventMethodInfo == null) { 45 | Debug.LogWarning("OnChangedAttribute: Unable to find method "+ FunctionName + " in " + TargetObjectType); 46 | return; 47 | } 48 | 49 | CachedEventMethodInfo.Invoke (TargetObject, null); 50 | } 51 | 52 | 53 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 54 | { 55 | var Attrib = (OnChangedAttribute)attribute; 56 | var TargetObject = property.serializedObject.targetObject; 57 | 58 | 59 | EditorGUI.BeginChangeCheck (); 60 | 61 | //base.OnGUI (position, prop, label); 62 | EditorGUI.PropertyField (position, property, label, true); 63 | 64 | if (EditorGUI.EndChangeCheck ()) { 65 | 66 | // gr: property is changed, but not modified back to the serialised object at this point. 67 | // So we can do a pre-emptive call. But I don't know if calling ApplyModifiedProperties() is really bad here. 68 | CallOnChanged(TargetObject, Attrib, Attrib.BeforeChangeFunctionName); 69 | property.serializedObject.ApplyModifiedProperties(); 70 | CallOnChanged(TargetObject, Attrib, Attrib.AfterChangeFunctionName); 71 | } 72 | } 73 | /* 74 | public override float GetPropertyHeight (SerializedProperty property, GUIContent label) 75 | { 76 | var Attrib = (ShowIfAttribute)attribute; 77 | var TargetObject = property.serializedObject.targetObject; 78 | 79 | if ( IsVisible(TargetObject,Attrib)) { 80 | //base.OnGUI (position, prop, label); 81 | return base.GetPropertyHeight ( property, label); 82 | } 83 | return 0; 84 | } 85 | */ 86 | } 87 | #endif 88 | 89 | 90 | -------------------------------------------------------------------------------- /OnChangedAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a8d3b96157b2d4a0ba9560fa6451a79d 3 | timeCreated: 1494934628 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /OnEnableEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class OnEnableEvent : MonoBehaviour { 6 | 7 | public UnityEngine.Events.UnityEvent OnEnabled; 8 | public UnityEngine.Events.UnityEvent OnDisabled; 9 | 10 | void OnEnable() 11 | { 12 | OnEnabled.Invoke (); 13 | } 14 | 15 | void OnDisable() 16 | { 17 | OnDisabled.Invoke (); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /OnEnableEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a56ef721c67d47d4915f97707706246 3 | timeCreated: 1495809254 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /OnEnableTime.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class OnEnableTime : MonoBehaviour { 6 | 7 | public UnityEvent_float OnEnabledTime; 8 | public UnityEvent_float OnDisabledTime; 9 | 10 | [Header("Use timeSinceLevelLoad to match shader _Time")] 11 | // https://answers.unity.com/questions/302335/built-in-shaderlab-timey-and-timetime-are-not-equa.html 12 | public bool UseTimeSinceLevelLoad = true; 13 | 14 | void OnEnable() 15 | { 16 | OnEnabledTime.Invoke ( UseTimeSinceLevelLoad ? Time.timeSinceLevelLoad : Time.time ); 17 | } 18 | 19 | void OnDisable() 20 | { 21 | OnDisabledTime.Invoke ( UseTimeSinceLevelLoad ? Time.timeSinceLevelLoad : Time.time ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /OnEnableTime.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cd6ef2091de864e9c9a5db63eb59dffd 3 | timeCreated: 1509982658 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /OpenLockedInspector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | 9 | public static class OpenLockedInspector 10 | { 11 | #if UNITY_EDITOR 12 | [MenuItem("GameObject/Open Locked Inspector", false, 49)] 13 | public static void DoOpenLockedInspector() 14 | { 15 | var InspectorType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow"); 16 | //var Inspector = EditorWindow.GetWindow(InspectorType) as EditorWindow; 17 | var NewInspector = EditorWindow.CreateInstance (InspectorType) as EditorWindow; 18 | NewInspector.Show (); 19 | 20 | // todo: explicitly set object 21 | 22 | // try and lock it 23 | // https://github.com/MattRix/UnityDecompiled/blob/master/UnityEditor/UnityEditor/InspectorWindow.cs 24 | try 25 | { 26 | var IsLockedProp = InspectorType.GetProperty("isLocked", typeof(bool) ); 27 | if ( !IsLockedProp.CanWrite ) 28 | throw new System.Exception("UnityEditor.InspectorWindow.isLocked cannot be written"); 29 | IsLockedProp.SetValue( NewInspector, true, null ); 30 | } 31 | catch(System.Exception e) { 32 | Debug.LogError ("Failed to lock new inspector: " + e.Message); 33 | } 34 | 35 | } 36 | #endif 37 | } 38 | -------------------------------------------------------------------------------- /OpenLockedInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3bceaecb5e9f0407787a8bda09ba9ca5 3 | timeCreated: 1507812258 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /OpenvrJoystickInterface.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84ac2dc1f12b48c48a323da16bd2d655 3 | timeCreated: 1493645192 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopAssetDatabase.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | 9 | public static class PopAssetDatabase 10 | { 11 | public static string GetTypeAssetTypeName(System.Type Type) 12 | { 13 | #if UNITY_EDITOR 14 | // some special cases 15 | if (Type == typeof(SceneAsset)) 16 | return "scene"; 17 | #endif 18 | return Type.Name; 19 | } 20 | 21 | // gr: maybe should allow this in production, but find assets from somewhere else? resources? 22 | #if UNITY_EDITOR 23 | public static List GetAssets(string Filter=null) where T : UnityEngine.Object 24 | { 25 | var Assets = new List(); 26 | 27 | // get all guids 28 | var Typename = GetTypeAssetTypeName(typeof(T)); 29 | var Guids = AssetDatabase.FindAssets("t:" + Typename + " " + Filter ); 30 | foreach ( var Guid in Guids ) 31 | { 32 | var Path = AssetDatabase.GUIDToAssetPath(Guid); 33 | var Asset = AssetDatabase.LoadAssetAtPath(Path); 34 | Assets.Add(Asset); 35 | } 36 | 37 | return Assets; 38 | } 39 | #endif 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /PopAssetDatabase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d92e7a38be41d43fc95bc56ea9b5b363 3 | timeCreated: 1521713962 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopBinaryChop.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | namespace PopX 7 | { 8 | public static class BinaryChop 9 | { 10 | public enum CompareDirection 11 | { 12 | Before, 13 | Inside, 14 | After 15 | }; 16 | 17 | public static void Search(int FirstIndex, int LastIndex, System.Func GetElementAt, System.Func Compare, out int? NearestPrevIndex, out int? MatchIndex) 18 | { 19 | // dealing with 1million sized arrays, so this number needs to be big 20 | int Tries = 1000; 21 | while (Tries-- > 0) 22 | { 23 | if (FirstIndex > LastIndex) 24 | throw new System.Exception("Binary chop error, FirstIndex(" + FirstIndex + ") > LastIndex(" + LastIndex + ")"); 25 | 26 | var FirstElement = GetElementAt(FirstIndex); 27 | var FirstDirection = Compare(FirstElement); 28 | if (FirstDirection == CompareDirection.Inside) 29 | { 30 | MatchIndex = FirstIndex; 31 | NearestPrevIndex = FirstIndex; 32 | return; 33 | } 34 | // im before first 35 | if (FirstDirection == CompareDirection.Before) 36 | { 37 | MatchIndex = null; 38 | // gr: is this -1 right? 39 | NearestPrevIndex = FirstIndex - 1; 40 | return; 41 | } 42 | 43 | // in case we've exhausted the list 44 | // im after first 45 | if (FirstIndex == LastIndex) 46 | { 47 | MatchIndex = null; 48 | NearestPrevIndex = FirstIndex; 49 | return; 50 | } 51 | 52 | var LastElement = GetElementAt(LastIndex); 53 | var LastDirection = Compare(LastElement); 54 | if (LastDirection == CompareDirection.Inside) 55 | { 56 | MatchIndex = LastIndex; 57 | NearestPrevIndex = LastIndex; 58 | return; 59 | } 60 | // im after last 61 | if (LastDirection == CompareDirection.After) 62 | { 63 | MatchIndex = null; 64 | NearestPrevIndex = LastIndex; 65 | return; 66 | } 67 | 68 | // when no range left, we can get stuck with the midpoint, but we can bail out here 69 | if (FirstIndex+1 == LastIndex) 70 | { 71 | MatchIndex = null; 72 | NearestPrevIndex = FirstIndex; 73 | return; 74 | } 75 | 76 | if ( Tries < 10 ) 77 | { 78 | Debug.Log("Binary chop last chance..."); 79 | } 80 | 81 | // gr: can we get stuck here by not moving in either direction? 82 | // gr: yes (dealt with above) 83 | var RangeRemaining = LastIndex - FirstIndex; 84 | var MidIndex = FirstIndex + (RangeRemaining / 2); 85 | var MidElement = GetElementAt(MidIndex); 86 | var MidDirection = Compare(MidElement); 87 | if (MidDirection == CompareDirection.Inside) 88 | { 89 | MatchIndex = MidIndex; 90 | NearestPrevIndex = MidIndex; 91 | return; 92 | } 93 | 94 | // in first half or second half 95 | if (MidDirection == CompareDirection.Before) 96 | { 97 | LastIndex = MidIndex; 98 | //todo: FirstIndex++; 99 | } 100 | else 101 | { 102 | FirstIndex = MidIndex; 103 | //todo: LastIndex--; 104 | } 105 | 106 | if (FirstIndex > LastIndex) 107 | throw new System.Exception("Binary chop mid-jump error, FirstIndex(" + FirstIndex + ") > LastIndex(" + LastIndex + ")"); 108 | } 109 | 110 | throw new System.Exception("Binary chop bailed from loop"); 111 | } 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /PopBinaryChop.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9284675a02ad0403c94ed4803de62f7d 3 | timeCreated: 1521812435 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopCheckCurrentCamera.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | /* 6 | There's a bug in unity 5.0.1f1 where using Graphics.Blit() crashes in Update()(where I NEED to do blits) if there is no current camera set. 7 | Possibly due to specific texture types... 8 | Call this beforehand. 9 | */ 10 | public class PopCheckCurrentCamera : MonoBehaviour { 11 | 12 | static public bool CheckCurrentCamera() 13 | { 14 | if (!Camera.current) 15 | Camera.SetupCurrent (Camera.main); 16 | return Camera.current != null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PopCheckCurrentCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09655a41a376a46c9a2278609c81e7a0 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopCli.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.IO; 5 | using System; 6 | 7 | namespace PopX 8 | { 9 | public static class Cli 10 | { 11 | // returns the process exit code 12 | public static int Run(string ExeFilename, string Arguments, System.Action OnStdOut, System.Action OnStdErr = null, System.Func Continue = null) 13 | { 14 | // fill in the auto-continue func if none provided 15 | if (Continue == null) 16 | Continue = () => { return true; }; 17 | 18 | var info = new System.Diagnostics.ProcessStartInfo(ExeFilename, Arguments); 19 | info.UseShellExecute = false; 20 | info.CreateNoWindow = false; 21 | 22 | info.RedirectStandardInput = false; 23 | info.RedirectStandardOutput = OnStdOut != null; 24 | info.RedirectStandardError = OnStdErr != null; 25 | 26 | var SubProcess = System.Diagnostics.Process.Start(info); 27 | 28 | System.Action> ReadAllOfStream = (BinaryStream, OnRead) => 29 | { 30 | if (BinaryStream == null) 31 | return; 32 | if (OnRead == null) 33 | return; 34 | 35 | var Buffer = new byte[1024 * 10]; 36 | 37 | // allow external abort 38 | while (Continue()) 39 | { 40 | var BytesRead = BinaryStream.Read(Buffer, 0, Buffer.Length); 41 | if (BytesRead == 0) 42 | break; 43 | 44 | if (BytesRead < Buffer.Length) 45 | { 46 | var SmallBuffer = new byte[BytesRead]; 47 | Array.Copy(Buffer, SmallBuffer, SmallBuffer.Length); 48 | } 49 | else 50 | { 51 | OnRead(Buffer); 52 | } 53 | } 54 | }; 55 | 56 | 57 | var StdoutReader = OnStdOut != null ? new BinaryReader(SubProcess.StandardOutput.BaseStream) : null; 58 | var StderrReader = OnStdErr != null ? new BinaryReader(SubProcess.StandardError.BaseStream) : null; 59 | 60 | 61 | // run until done 62 | try 63 | { 64 | while (!SubProcess.HasExited) 65 | { 66 | if (!Continue()) 67 | throw new System.Exception("Aborted"); 68 | 69 | ReadAllOfStream(StdoutReader, OnStdOut); 70 | ReadAllOfStream(StderrReader, OnStdErr); 71 | 72 | System.Threading.Thread.Sleep(1); 73 | } 74 | } 75 | catch (System.Exception e) 76 | { 77 | UnityEngine.Debug.LogException(e); 78 | SubProcess.Kill(); 79 | throw; 80 | } 81 | 82 | var ExitCode = SubProcess.ExitCode; 83 | SubProcess.Close(); 84 | SubProcess.Dispose(); 85 | return ExitCode; 86 | } 87 | 88 | 89 | public static bool HasArgument(string Argument) 90 | { 91 | var Args = System.Environment.GetCommandLineArgs(); 92 | if (System.Array.IndexOf(Args, Argument) == -1) 93 | return false; 94 | return true; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /PopCli.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88c5bc892db7ab54a8c0d8fab1e1a270 3 | timeCreated: 1528796217 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopCommandLineBuild.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEngine; 3 | using UnityEditor; 4 | using System.Collections; 5 | using System.Linq; 6 | using System; 7 | 8 | 9 | /* 10 | * gr: this is being deprecated, for "PopBuild" a more complete build solution, but keeping this here temporarily until all funcitonality is replaced. 11 | * so PopBuild has been renamed to PopCommandLineBuild 12 | */ 13 | public class PopCommandLineBuild : MonoBehaviour { 14 | 15 | private static string BuildPathArg = "-BuildPath="; 16 | //private static string PathSuffixIos = "/"; 17 | private static string PathSuffixIos = null; 18 | private static string PathSuffixAndroid = ".apk"; 19 | 20 | private static string[] GetLevels() 21 | { 22 | return (from scene in EditorBuildSettings.scenes where scene.enabled select scene.path).ToArray(); 23 | } 24 | 25 | public static string GetCommandLineBuildPath(string RequiredSuffix) 26 | { 27 | string[] Args = Environment.GetCommandLineArgs (); 28 | try 29 | { 30 | string BuildPath = Args.Where( Element => Element.StartsWith(BuildPathArg)).Single(); 31 | // strip predicate 32 | BuildPath = BuildPath.Replace(BuildPathArg, ""); 33 | BuildPath = BuildPath.Replace("\"", "" ); 34 | BuildPath = BuildPath.Trim(); 35 | Debug.Log("Build path found as: " + BuildPath ); 36 | 37 | if ( RequiredSuffix != null ) 38 | if ( !BuildPath.EndsWith(RequiredSuffix) ) 39 | return null; 40 | 41 | return BuildPath; 42 | } 43 | catch(System.Exception e) 44 | { 45 | Debug.Log("failed to get BuildPath arg: " + e.Message ); 46 | return null; 47 | } 48 | } 49 | 50 | 51 | public static void Build(BuildTarget Target,string RequiredBuildPathSuffix) 52 | { 53 | string Path = GetCommandLineBuildPath (RequiredBuildPathSuffix); 54 | if ( Path==null ) 55 | { 56 | string Error = "No path (ending in "+RequiredBuildPathSuffix+") supplied on commandline. use " + BuildPathArg + "\"yourpath/filename" + RequiredBuildPathSuffix + "\""; 57 | throw new UnityException(Error); 58 | } 59 | BuildPipeline.BuildPlayer (GetLevels(), Path, Target, BuildOptions.None); 60 | } 61 | 62 | public static void BuildAndroid() 63 | { 64 | Build (BuildTarget.Android, PathSuffixAndroid); 65 | } 66 | 67 | public static void BuildIos() 68 | { 69 | Build (BuildTarget.iOS, PathSuffixIos); 70 | } 71 | 72 | } 73 | #endif//UNITY_EDITOR -------------------------------------------------------------------------------- /PopCommandLineBuild.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: adb4e8a1b1add4fc7afa7dcbc856c0dd 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopCommon.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0b65428b865e4353a43b5bcd3c9d9e2 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /PopData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace PopX 6 | { 7 | public static class Data 8 | { 9 | static public byte[] SubArray(this System.Array ParentArray, long Start, long Count) 10 | { 11 | var ChildArray = new byte[Count]; 12 | System.Array.Copy(ParentArray, Start, ChildArray, 0, Count); 13 | return ChildArray; 14 | } 15 | 16 | public class NotFound : System.Exception 17 | { 18 | public NotFound() 19 | { 20 | } 21 | } 22 | 23 | // minimal interface for reading through arrays of data (avoiding conversions) 24 | public interface IIndexer 25 | { 26 | T this [int index] { 27 | get; 28 | } 29 | int Count { 30 | get; 31 | } 32 | }; 33 | 34 | // char->byte conversion without copying all the chars and converting to a byte array 35 | public class CharsAsBytes : IIndexer 36 | { 37 | IList Data; 38 | 39 | public byte this [int index] { 40 | get { return (byte)Data [index]; } 41 | } 42 | 43 | public int Count { 44 | get { return Data.Count; } 45 | } 46 | 47 | public CharsAsBytes(IList Data) 48 | { 49 | this.Data = Data; 50 | } 51 | }; 52 | 53 | // list to indexer 54 | public class ListIndexer : IIndexer 55 | { 56 | IList Data; 57 | 58 | public T this [int index] { 59 | get { return Data [index]; } 60 | } 61 | 62 | public int Count { 63 | get { return Data.Count; } 64 | } 65 | 66 | public ListIndexer(IList Data) 67 | { 68 | this.Data = Data; 69 | } 70 | } 71 | 72 | static public int FindPattern(IList Data,IList Match,int Start=0) 73 | { 74 | return FindPattern ( Data, new ListIndexer(Match), Start); 75 | } 76 | 77 | static public int FindPattern(IList Data,IList Match,int Start=0) 78 | { 79 | return FindPattern ( Data, new CharsAsBytes (Match), Start); 80 | } 81 | 82 | // throws Data.NotFound if not present 83 | static public int FindPattern(IList Data,IIndexer Match,int Start=0) 84 | { 85 | var PrefixLen = Match.Count; 86 | int Position = Start; 87 | while (Position + PrefixLen < Data.Count) { 88 | 89 | var IsMatch = true; 90 | for (int i = 0; i < Match.Count; i++) { 91 | var d = Data [Position + i]; 92 | var m = Match [i]; 93 | IsMatch = IsMatch && (d == m); 94 | } 95 | 96 | if (IsMatch) 97 | return Position; 98 | 99 | Position++; 100 | } 101 | 102 | throw new Data.NotFound(); 103 | } 104 | 105 | 106 | }; 107 | } 108 | -------------------------------------------------------------------------------- /PopData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6d6da7dbc70244d2e88328afe22811e4 3 | timeCreated: 1515499732 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1882549bcc2865f4cb849dd31fe09afb 3 | timeCreated: 1502399256 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopExceptions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | namespace PopX 8 | { 9 | public static class Exception 10 | { 11 | public static void ThrowIf(bool Condition, string Error) 12 | { 13 | if (Condition) 14 | throw new System.Exception(Error); 15 | } 16 | 17 | public static void Assert(bool Condition, string Error) 18 | { 19 | ThrowIf(!Condition, Error); 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /PopExceptions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 96730754e5fe74b75906d0e7db18abe8 3 | timeCreated: 1517407435 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopFbxAscii.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 185f13338b4c94685bbb18703b7fef32 3 | timeCreated: 1523017322 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopFitCollider.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | 9 | public class PopFitCollider : MonoBehaviour { 10 | 11 | #if UNITY_EDITOR 12 | [MenuItem("NewChromantics/Collider/Fit collider to Children")] 13 | static void FitColliderToChildren() { 14 | foreach (GameObject rootGameObject in Selection.gameObjects) { 15 | if (!(rootGameObject.GetComponent() )) 16 | continue; 17 | 18 | 19 | Renderer[] ChildRenderers = rootGameObject.GetComponentsInChildren(); 20 | Renderer[] ThisRenderers = rootGameObject.GetComponents(); 21 | var Renderers = new Renderer[ChildRenderers.Length + ThisRenderers.Length]; 22 | ChildRenderers.CopyTo(Renderers, 0); 23 | ThisRenderers.CopyTo(Renderers, Renderers.Length); 24 | 25 | bool hasBounds = false; 26 | Bounds bounds = new Bounds(Vector3.zero, Vector3.zero); 27 | 28 | foreach( Renderer r in Renderers ) 29 | { 30 | if (hasBounds) { 31 | bounds.Encapsulate(r.bounds); 32 | } 33 | else { 34 | bounds = r.bounds; 35 | hasBounds = true; 36 | } 37 | } 38 | 39 | // set all collider components 40 | if ( rootGameObject.GetComponent() is BoxCollider ) 41 | { 42 | BoxCollider collider = (BoxCollider)rootGameObject.GetComponent(); 43 | collider.center = bounds.center - rootGameObject.transform.position; 44 | collider.size = bounds.size; 45 | } 46 | 47 | if ( rootGameObject.GetComponent() is CapsuleCollider ) 48 | { 49 | CapsuleCollider collider = (CapsuleCollider)rootGameObject.GetComponent(); 50 | collider.center = bounds.center - rootGameObject.transform.position; 51 | Debug.Log(bounds); 52 | collider.height = (bounds.max.y - bounds.min.y) * 1.0f; 53 | collider.radius = (bounds.max.x - bounds.min.x) * 0.5f; 54 | 55 | } 56 | 57 | } 58 | } 59 | #endif 60 | 61 | } -------------------------------------------------------------------------------- /PopFitCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6326227e32a740d094c465aa5ee094f 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopGameObject.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | public static class PopGameObject 8 | { 9 | public static T[] FindObjectsOfTypeIncludingDisabled(this GameObject go) 10 | { 11 | return go.GetComponentsInChildren (true); 12 | } 13 | 14 | public static T[] FindObjectsOfTypeIncludingDisabled() 15 | { 16 | var ActiveScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene (); 17 | var RootObjects = ActiveScene.GetRootGameObjects (); 18 | var MatchObjects = new List (); 19 | 20 | foreach (var ro in RootObjects) { 21 | var Matches = ro.FindObjectsOfTypeIncludingDisabled (); 22 | MatchObjects.AddRange (Matches); 23 | } 24 | 25 | return MatchObjects.ToArray (); 26 | } 27 | 28 | public static T FindObjectOfTypeIncludingDisabled(this GameObject go) 29 | { 30 | return go.GetComponentInChildren (true); 31 | } 32 | 33 | public static T FindObjectOfTypeIncludingDisabled() 34 | { 35 | var ActiveScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene (); 36 | var RootObjects = ActiveScene.GetRootGameObjects (); 37 | 38 | foreach (var ro in RootObjects) { 39 | var Match = ro.FindObjectOfTypeIncludingDisabled (); 40 | if (Match != null) 41 | return Match; 42 | } 43 | 44 | return default(T); 45 | } 46 | 47 | public static T FindObjectOfTypeInParents(this GameObject go) 48 | { 49 | var parent = go.transform.parent; 50 | if (parent == null) 51 | return default (T); 52 | 53 | var Match = parent.GetComponent (); 54 | if (Match != null) 55 | return Match; 56 | 57 | return parent.gameObject.FindObjectOfTypeInParents (); 58 | } 59 | 60 | public static T[] FindObjectsOfTypeWithName(string MatchName) where T : Component 61 | { 62 | System.Func Match = (x) => 63 | { 64 | return x.name == MatchName; 65 | }; 66 | return FindObjectsOfTypeMatching (Match); 67 | } 68 | 69 | public static T[] FindObjectsOfTypeMatching(System.Func Match) where T : Object 70 | { 71 | var MatchObjects = new List (); 72 | MatchObjects.AddRange (GameObject.FindObjectsOfType ()); 73 | 74 | for (int i = MatchObjects.Count - 1; i >= 0; i--) { 75 | var mo = MatchObjects [i]; 76 | if (Match (mo)) 77 | continue; 78 | 79 | MatchObjects.RemoveAt (i); 80 | } 81 | 82 | return MatchObjects.ToArray (); 83 | } 84 | 85 | 86 | 87 | public static void ForEachChild(this GameObject go,System.Action Lambda) 88 | { 89 | var t = go.transform; 90 | for (var c = 0; c < t.childCount; c++ ) 91 | { 92 | var Child = t.GetChild(c); 93 | Lambda.Invoke(Child.gameObject); 94 | } 95 | } 96 | 97 | // if you return false from this lambda, the search will abort early 98 | public static void ForEachChild(this GameObject go, System.Func Lambda) 99 | { 100 | var t = go.transform; 101 | for (var c = 0; c < t.childCount; c++) 102 | { 103 | var Child = t.GetChild(c); 104 | if (!Lambda.Invoke(Child.gameObject)) 105 | break; 106 | } 107 | } 108 | 109 | public static T GetChildMatching(this GameObject go,System.Func Match) where T : Object 110 | { 111 | var t = go.transform; 112 | for (var c = 0; c < t.childCount; c++) 113 | { 114 | var Child = t.GetChild(c); 115 | var ChildComp = (typeof(T) == typeof(GameObject)) ? (Child.gameObject as T) : Child.GetComponent(); 116 | if ( !ChildComp ) 117 | continue; 118 | if ( Match( ChildComp) ) 119 | return ChildComp; 120 | } 121 | return null; 122 | } 123 | 124 | public static GameObject GetChildWithName(this GameObject go,string Name) 125 | { 126 | System.Func Match = (Child) => 127 | { 128 | if (Child.name != Name) 129 | return false; 130 | return true; 131 | }; 132 | 133 | return go.GetChildMatching( Match ); 134 | 135 | } 136 | 137 | 138 | public static int GetChildIndex(this Transform Parent, Transform ChildMatch) 139 | { 140 | var Count = Parent.childCount; 141 | for (var c = 0; c < Count; c++) 142 | { 143 | var Child = Parent.GetChild(c); 144 | if (Child == ChildMatch) 145 | return c; 146 | } 147 | throw new System.Exception("Child " + ChildMatch.name + " not a child of " + Parent.name); 148 | } 149 | 150 | public static int GetChildIndex(this GameObject Parent, GameObject ChildMatch) 151 | { 152 | return Parent.transform.GetChildIndex(ChildMatch.transform); 153 | } 154 | 155 | } 156 | 157 | -------------------------------------------------------------------------------- /PopGameObject.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7602e09cf207c427480a1692005bee89 3 | timeCreated: 1508417252 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopGeometry.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5016d7358315a463bbc11067423b14e6 3 | timeCreated: 1491835634 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopGizmos.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | 6 | 7 | namespace PopX 8 | { 9 | public static class Gizmos 10 | { 11 | static public void DrawCross(Vector3 Position,Vector3 Size) 12 | { 13 | var Up = Vector3.up * Size.y * 0.5f; 14 | var Left = Vector3.left * Size.x * 0.5f; 15 | var Forward = Vector3.forward * Size.z * 0.5f; 16 | 17 | UnityEngine.Gizmos.DrawLine(Position + Up, Position - Up); 18 | UnityEngine.Gizmos.DrawLine(Position + Left, Position - Left); 19 | UnityEngine.Gizmos.DrawLine(Position + Forward, Position - Forward); 20 | } 21 | 22 | static public void DrawWireArrow(Vector3 Start,Vector3 End,float ArrowHeadSize) 23 | { 24 | // draw a line 25 | UnityEngine.Gizmos.DrawLine(Start, End); 26 | 27 | // todo: draw a cone instead of a sphere :) 28 | UnityEngine.Gizmos.DrawWireSphere(End, ArrowHeadSize); 29 | } 30 | 31 | // todo: better plane selection 32 | static public void DrawCircleXZ(Vector3 Center,float Radius,int Segments=30) 33 | { 34 | Segments = Mathf.Max(3, Segments); 35 | System.Func GetCirclePosition = (Time) => 36 | { 37 | var Pos = Center; 38 | Pos.x += Mathf.Sin(Mathf.Deg2Rad * 360.0f * Time) * Radius; 39 | Pos.z += Mathf.Cos(Mathf.Deg2Rad * 360.0f * Time) * Radius; 40 | return Pos; 41 | }; 42 | 43 | for (int i = 0; i < Segments; i++) 44 | { 45 | float t0 = (i + 0) / ((float)Segments - 1); 46 | float t1 = (i + 1) / ((float)Segments - 1); 47 | var Pos0 = GetCirclePosition(t0); 48 | var Pos1 = GetCirclePosition(t1); 49 | UnityEngine.Gizmos.DrawLine(Pos0, Pos1); 50 | } 51 | 52 | } 53 | 54 | static public void DrawWireRingSphere(Vector3 Center,float Radius,int Segments=30) 55 | { 56 | // gr: the vertical lines are nice too, this also verifies use of radius 57 | UnityEngine.Gizmos.DrawWireSphere (Center, Radius); 58 | 59 | for (var Ring = 0; Ring < Segments; Ring++ ) 60 | { 61 | var t = Ring / (float)Segments; 62 | var RadiusTheta = Mathf.Lerp(0 * Mathf.Deg2Rad, 180 * Mathf.Deg2Rad,t); 63 | var RingRadius = Mathf.Sin(RadiusTheta); 64 | var RingPos = Center; 65 | 66 | var YTheta = Mathf.Lerp(0 * Mathf.Deg2Rad, 180 * Mathf.Deg2Rad,t); 67 | var YOffset = Mathf.Cos(YTheta); 68 | 69 | RingPos.y = Center.y + (YOffset*Radius); 70 | 71 | DrawCircleXZ(RingPos, RingRadius * Radius, Segments); 72 | } 73 | 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /PopGizmos.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69f7be2b5903c4332922ada251ead087 3 | timeCreated: 1519733664 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopIO.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a8d6f1f0c3dc44328005906e5c2d67e 3 | timeCreated: 1509031814 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopJson.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82d827f1a4d8d4abab91c6c81df7171a 3 | timeCreated: 1515084108 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopKalman.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | // gr: from my old opencl kalman filter 8 | // https://gitlab.com/NewChromantics/PopLib/blob/master/data/TKalman.cl 9 | // which was originally from http://www.dzone.com/snippets/simple-kalman-filter-c 10 | // todo: document noise filter values. Generally use 0.001 to 1 11 | // todo: generic this, Everywhere with Vector3 can be swapped for another type 12 | public class PopKalman_Vector3 13 | { 14 | Vector3 x_est_last; 15 | Vector3 lastcorrected; 16 | float P_last; 17 | float QNoise; 18 | float RNoise; 19 | float TotalError; 20 | 21 | 22 | public PopKalman_Vector3(Vector3 InitialPos, float QNoise, float RNoise) 23 | { 24 | //initialize with a measurement 25 | //x_est_last = InitialPos; 26 | lastcorrected = InitialPos; 27 | P_last = 0; 28 | TotalError = 0; 29 | this.QNoise = QNoise; 30 | this.RNoise = RNoise; 31 | } 32 | 33 | // returns error amount (deviation) 34 | public float Push(Vector3 Position) 35 | { 36 | //do a prediction 37 | var x_temp_est = x_est_last; 38 | var P_temp = P_last + QNoise; 39 | 40 | //calculate the Kalman gain 41 | // gr: timestep here? 42 | var KGain = P_temp * (1.0f / (P_temp + RNoise)); 43 | 44 | // measured input 45 | var Accell = Position - lastcorrected; 46 | var z_measured = Accell; 47 | 48 | // do correction to the estimate 49 | var x_est = x_temp_est + KGain * (z_measured - x_temp_est); 50 | float P = (1 - KGain) * P_temp; 51 | 52 | // error is difference from the corrected estimate 53 | var Error = Vector3.Distance(z_measured, x_est); 54 | TotalError += Error; 55 | 56 | // update our last's 57 | P_last = P; 58 | x_est_last = x_est; 59 | 60 | lastcorrected = lastcorrected + x_est_last; 61 | 62 | return Error; 63 | } 64 | 65 | public Vector3 GetAcceleration() 66 | { 67 | return x_est_last; 68 | } 69 | 70 | 71 | public Vector3 GetFilteredPosition() 72 | { 73 | return GetEstimatedPosition(0); 74 | } 75 | 76 | public Vector3 GetEstimatedPosition(float TimeDelta) 77 | { 78 | var Accell = x_est_last; 79 | var NewPos = lastcorrected + (Accell * TimeDelta); 80 | return NewPos; 81 | } 82 | } 83 | 84 | 85 | public class PopKalman_Vector2 86 | { 87 | Vector2 x_est_last; 88 | Vector2 lastcorrected; 89 | float P_last; 90 | float QNoise; 91 | float RNoise; 92 | float TotalError; 93 | 94 | 95 | public PopKalman_Vector2(Vector2 InitialPos, float QNoise, float RNoise) 96 | { 97 | //initialize with a measurement 98 | //x_est_last = InitialPos; 99 | lastcorrected = InitialPos; 100 | P_last = 0; 101 | TotalError = 0; 102 | this.QNoise = QNoise; 103 | this.RNoise = RNoise; 104 | } 105 | 106 | // returns error amount (deviation) 107 | public float Push(Vector2 Position) 108 | { 109 | //do a prediction 110 | var x_temp_est = x_est_last; 111 | var P_temp = P_last + QNoise; 112 | 113 | //calculate the Kalman gain 114 | // gr: timestep here? 115 | var KGain = P_temp * (1.0f / (P_temp + RNoise)); 116 | 117 | // measured input 118 | var Accell = Position - lastcorrected; 119 | var z_measured = Accell; 120 | 121 | // do correction to the estimate 122 | var x_est = x_temp_est + KGain * (z_measured - x_temp_est); 123 | float P = (1 - KGain) * P_temp; 124 | 125 | // error is difference from the corrected estimate 126 | var Error = Vector2.Distance(z_measured, x_est); 127 | TotalError += Error; 128 | 129 | // update our last's 130 | P_last = P; 131 | x_est_last = x_est; 132 | 133 | lastcorrected = lastcorrected + x_est_last; 134 | 135 | return Error; 136 | } 137 | 138 | public Vector2 GetAcceleration() 139 | { 140 | return x_est_last; 141 | } 142 | 143 | 144 | public Vector2 GetFilteredPosition() 145 | { 146 | return GetEstimatedPosition(0); 147 | } 148 | 149 | public Vector2 GetEstimatedPosition(float TimeDelta) 150 | { 151 | var Accell = x_est_last; 152 | var NewPos = lastcorrected + (Accell * TimeDelta); 153 | return NewPos; 154 | } 155 | } 156 | 157 | -------------------------------------------------------------------------------- /PopKalman.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68d5989dd997f46f59ca263d50b0d4cb 3 | timeCreated: 1523451283 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.Text.RegularExpressions; 5 | 6 | 7 | namespace PopX 8 | { 9 | public static class Materials 10 | { 11 | const string InstanceSuffix = "Instance"; 12 | 13 | static public bool IsInstanceName(string Name) 14 | { 15 | if (Name.ToLower().Contains(InstanceSuffix.ToLower())) 16 | return true; 17 | 18 | return false; 19 | } 20 | 21 | public static Material GetInstancedMaterial(Material mat,string ExtraNameSuffix=null) 22 | { 23 | // don't make instances in edit mode 24 | if (Application.isEditor && !Application.isPlaying) 25 | { 26 | return mat; 27 | } 28 | 29 | // check if current is an instance 30 | if (IsInstanceName(mat.name)) 31 | return mat; 32 | 33 | if (ExtraNameSuffix == null) 34 | ExtraNameSuffix = ""; 35 | 36 | // make instance 37 | mat = new Material(mat); 38 | mat.name += " " + ExtraNameSuffix + " " + InstanceSuffix; 39 | if (!IsInstanceName(mat.name)) 40 | throw new System.Exception("New name " + mat.name + " isn't an instance"); 41 | return mat; 42 | } 43 | 44 | 45 | public static Material GetInstancedMaterial(ref Material mat,string ExtraNameSuffix=null) 46 | { 47 | mat = GetInstancedMaterial(mat,ExtraNameSuffix); 48 | return mat; 49 | } 50 | 51 | 52 | #if UNITY_EDITOR 53 | public static Dictionary GetProperties(Shader shader) 54 | { 55 | // get file contents of asset 56 | var Filename = UnityEditor.AssetDatabase.GetAssetPath(shader); 57 | var Contents = System.IO.File.ReadAllText(Filename); 58 | 59 | return GetProperties(Contents); 60 | } 61 | #endif 62 | 63 | public static System.Type GetType(string TypeName) 64 | { 65 | if (TypeName == "2D") return typeof(Texture); 66 | if (TypeName == "VECTOR") return typeof(Vector4); 67 | if (TypeName == "COLOR") return typeof(Color); 68 | throw new System.Exception("Unhandled shader typename " + TypeName); 69 | } 70 | 71 | public static Dictionary GetProperties(string Shader) 72 | { 73 | // get file contents of asset 74 | var Contents = Shader; 75 | 76 | // find properties section 77 | //var Pattern = new Regex(@"([_A-Za-z0-9]+)\s*\(\s*""[_A-Za-z0-9]+""\s*,"); 78 | 79 | var Pattern_Name = @"([_A-Za-z0-9]+)\s*"; // xyz 80 | var Pattern_OpenParenth = @"\(\s*"; // ( 81 | var Pattern_Label = @"""([_A-Za-z0-9]+)""\s*,\s*"; // "xyz", 82 | var Pattern_Type = "(2D|COLOR|VECTOR)"; // 83 | var Pattern_CloseParenth = @"\s*\)\s*"; // ) 84 | var Pattern = new Regex(Pattern_Name + Pattern_OpenParenth + Pattern_Label + Pattern_Type + Pattern_CloseParenth); 85 | var Matches = Pattern.Matches(Contents); 86 | 87 | // gr: change this to empty return if it's valid to have no properties. (Guess it is) 88 | if (Matches == null) 89 | throw new System.Exception("Could not find any matches in shader"); 90 | 91 | //Debug.Log("Match count " + Matches.Count); 92 | var Properties = new Dictionary(); 93 | 94 | foreach (var MatchObj in Matches) 95 | { 96 | var Match = (Match)MatchObj; 97 | 98 | try 99 | { 100 | /* 101 | Debug.Log("Group count = " + Match.Groups.Count ); 102 | var Found = ""; 103 | foreach ( var GroupObj in Match.Groups ) 104 | { 105 | var Group = (Group)GroupObj; 106 | var Capture = Group.Captures[0]; 107 | Found += Capture.Value + " ---> "; 108 | } 109 | Debug.Log(Found); 110 | */ 111 | var Name = Match.Groups[1].Captures[0].Value; 112 | var Label = Match.Groups[2].Captures[0].Value; 113 | var TypeString = Match.Groups[3].Captures[0].Value; 114 | var Type = GetType(TypeString); 115 | Properties.Add( Name, Type); 116 | } 117 | catch(System.Exception e) 118 | { 119 | Debug.LogError("Faled to parse property match; " + e.Message); 120 | } 121 | } 122 | 123 | return Properties; 124 | } 125 | } 126 | 127 | } 128 | 129 | -------------------------------------------------------------------------------- /PopMaterial.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 420e74e4358b54bb09596f5ee0582ffe 3 | timeCreated: 1517489388 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopMath.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a722286c1e309431787bdd00c46a47e3 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopMouseLook.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [AddComponentMenu("NewChromantics/PopMouseLook")] 5 | public class PopMouseLook : MonoBehaviour { 6 | 7 | public enum MouseButton { None=-1, Left=0, Middle=2, Right=1 }; 8 | [Header("None here means no buttons needs to be held")] 9 | public MouseButton RotateOnlyOnMouseButton = MouseButton.None; 10 | 11 | public bool UseGyroOnMobile = true; 12 | private Quaternion? mInitialGyro = null; 13 | public bool UseLateUpdate = false; 14 | 15 | public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 } 16 | public RotationAxes axes = RotationAxes.MouseXAndY; 17 | public float sensitivityX = 15F; 18 | public float sensitivityY = 15F; 19 | 20 | public float minimumX = -360F; 21 | public float maximumX = 360F; 22 | 23 | public float minimumY = -60F; 24 | public float maximumY = 60F; 25 | 26 | float rotationX = 0F; 27 | float rotationY = 0F; 28 | 29 | Quaternion originalRotation; 30 | 31 | 32 | public void ResetOrientation() 33 | { 34 | mInitialGyro = null; 35 | } 36 | 37 | static public bool UsingVr() 38 | { 39 | #if UNITY_2017_2_OR_NEWER 40 | var LoadedDevice = UnityEngine.XR.XRSettings.loadedDeviceName; 41 | if ( string.IsNullOrEmpty( LoadedDevice )) 42 | #elif UNITY_2017_1_OR_NEWER 43 | if (UnityEngine.VR.VRSettings.supportedDevices.Length == 0) 44 | #else 45 | if (UnityEngine.VR.VRSettings.loadedDevice == UnityEngine.VR.VRDeviceType.None) 46 | #endif 47 | { 48 | return false; 49 | } 50 | 51 | #if UNITY_2017_2_OR_NEWER 52 | if (!UnityEngine.XR.XRDevice.isPresent) 53 | #else 54 | if (!UnityEngine.VR.VRDevice.isPresent) 55 | #endif 56 | return false; 57 | 58 | return true; 59 | } 60 | 61 | void Update() 62 | { 63 | if (!UseLateUpdate) 64 | UpdateLook (); 65 | } 66 | 67 | void LateUpdate() 68 | { 69 | if (UseLateUpdate) 70 | UpdateLook (); 71 | } 72 | 73 | void UpdateLook () 74 | { 75 | // in VR mode, no mouse/gyro at all! 76 | if (UsingVr() ) 77 | return; 78 | 79 | if ( Input.mousePresent ) 80 | { 81 | if ( RotateOnlyOnMouseButton != MouseButton.None ) 82 | { 83 | if (!Input.GetMouseButton ((int)RotateOnlyOnMouseButton)) 84 | return; 85 | } 86 | } 87 | 88 | bool UseGyro = UseGyroOnMobile; 89 | { 90 | if (UseGyro) 91 | Input.gyro.enabled = true; 92 | UseGyro &= Input.gyro.enabled; 93 | } 94 | 95 | 96 | if (UseGyro) 97 | { 98 | bool GyroValid = Input.gyro.enabled; 99 | { 100 | // first usage of the attituide is all zeros, ignore this 101 | Vector4 Gyro4 = new Vector4( Input.gyro.attitude.x, Input.gyro.attitude.y, Input.gyro.attitude.z, Input.gyro.attitude.w ); 102 | GyroValid &= Gyro4.SqrMagnitude() > 0; 103 | } 104 | 105 | if ( GyroValid ) 106 | { 107 | // correction stolen from google cardboad SDK 108 | var att = Input.gyro.attitude; 109 | att = new Quaternion(att.x, att.y, -att.z, -att.w); 110 | att = Quaternion.Euler(0, 0, 0) * att; 111 | 112 | if ( mInitialGyro == null ) 113 | { 114 | mInitialGyro = att; 115 | } 116 | 117 | transform.localRotation = Quaternion.Inverse(mInitialGyro.Value) * att; 118 | } 119 | } 120 | else if (axes == RotationAxes.MouseXAndY) 121 | { 122 | // Read the mouse input axis 123 | rotationX += Input.GetAxis("Mouse X") * sensitivityX; 124 | rotationY += Input.GetAxis("Mouse Y") * sensitivityY; 125 | 126 | rotationX = ClampAngle (rotationX, minimumX, maximumX); 127 | rotationY = ClampAngle (rotationY, minimumY, maximumY); 128 | 129 | Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); 130 | Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right); 131 | 132 | transform.localRotation = originalRotation * xQuaternion * yQuaternion; 133 | } 134 | else if (axes == RotationAxes.MouseX) 135 | { 136 | rotationX += Input.GetAxis("Mouse X") * sensitivityX; 137 | rotationX = ClampAngle (rotationX, minimumX, maximumX); 138 | 139 | Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); 140 | transform.localRotation = originalRotation * xQuaternion; 141 | } 142 | else 143 | { 144 | rotationY += Input.GetAxis("Mouse Y") * sensitivityY; 145 | rotationY = ClampAngle (rotationY, minimumY, maximumY); 146 | 147 | Quaternion yQuaternion = Quaternion.AngleAxis (-rotationY, Vector3.right); 148 | transform.localRotation = originalRotation * yQuaternion; 149 | } 150 | } 151 | 152 | void Start () 153 | { 154 | originalRotation = transform.localRotation; 155 | } 156 | 157 | public static float ClampAngle (float angle, float min, float max) 158 | { 159 | if (angle <= -360F) 160 | angle += 360F; 161 | if (angle >= 360F) 162 | angle -= 360F; 163 | return Mathf.Clamp (angle, min, max); 164 | } 165 | } -------------------------------------------------------------------------------- /PopMouseLook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82e4de7c545584a7ebc180e6ab95a7ef 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopNet.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | // gr: PopX being renamed to Pop later 7 | namespace PopX 8 | { 9 | public static class Net 10 | { 11 | // when we open sockets with Address.Any, our address is still usually 0.0.0.0 12 | // no good for outsiders. 13 | // https://stackoverflow.com/a/27376368/355753 14 | public static IPAddress GetLocalAddress() 15 | { 16 | using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0)) 17 | { 18 | socket.Connect("8.8.8.8", 65530); 19 | var endPoint = socket.LocalEndPoint as IPEndPoint; 20 | var LocalAddress = endPoint.Address; 21 | return LocalAddress; 22 | } 23 | } 24 | 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /PopNet.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7692432ec34b84ddf8a9f438b86d07ae 3 | timeCreated: 1522268220 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopNukeChan.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | /* 7 | Nuke "chan" file format exporter, which is for paths. (and typically I believe... camera paths) 8 | 9 | an importer would be easy, but who knows what the ideal format would be. 10 | Animation asset I guess :) 11 | */ 12 | 13 | // rename namespace to Pop in later refactor 14 | namespace PopX 15 | { 16 | public static class NukeChan 17 | { 18 | public const string FileExtension = "chan"; 19 | 20 | // perhaps a matrix would be better than a custom struct 21 | public struct Frame 22 | { 23 | public Vector3 Position; 24 | public Quaternion Rotation; 25 | public float? CameraFov; 26 | }; 27 | 28 | public static void Export(System.Action WriteLine, System.Func GetFrameAtTime, float StartTime,float EndTime,float FrameRate) 29 | { 30 | if (EndTime < StartTime) 31 | throw new System.Exception("Trying to export start time (" + StartTime + ") that is after end time (" + EndTime + ")"); 32 | 33 | var FrameDuration = 1.0f / FrameRate; 34 | var FrameCountf = (EndTime - StartTime) * FrameRate; 35 | var FrameCount = (uint)FrameCountf; 36 | 37 | // get time for frame 38 | System.Func GetFrameTime = (FrameNumber) => 39 | { 40 | var Delta = FrameNumber * FrameDuration; 41 | return Delta + StartTime; 42 | }; 43 | 44 | System.Func GetFrame = (FrameNumber) => 45 | { 46 | var FrameTime = GetFrameTime(FrameNumber); 47 | return GetFrameAtTime(FrameTime); 48 | }; 49 | 50 | Export(WriteLine, GetFrame, FrameCount); 51 | } 52 | 53 | public static void Export(System.Action WriteLine,System.Func GetFrame,uint FrameCount) 54 | { 55 | for (uint i = 0; i < FrameCount; i++ ) 56 | { 57 | var Frame = GetFrame(i); 58 | var FormatNull = "{0} {1} {2} {3} {4} {5} {6}"; 59 | var FormatCamera = "{0} {1} {2} {3} {4} {5} {6} {7}"; 60 | var Format = Frame.CameraFov.HasValue ? FormatCamera : FormatNull; 61 | 62 | // gr: can't find documentation on whether the format is expecting radians or degrees :/ 63 | var RotationAngles = Frame.Rotation.eulerAngles; 64 | 65 | var fn = i + 1; 66 | var x = Frame.Position.x; 67 | var y = Frame.Position.y; 68 | var z = Frame.Position.z; 69 | 70 | var pitch = RotationAngles.x; 71 | var yaw = RotationAngles.y; 72 | var roll = RotationAngles.z; 73 | 74 | var Fov = Frame.CameraFov.HasValue ? Frame.CameraFov.Value : 0; 75 | 76 | var Line = string.Format(Format, fn, x, y, z, pitch, yaw, roll, Fov); 77 | WriteLine(Line); 78 | } 79 | } 80 | 81 | } 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /PopNukeChan.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d849de7a0f11d4a3e97bf77017aa59ff 3 | timeCreated: 1523017322 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopOgg.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aea58667452724e15aae4eef5c4e94f6 3 | timeCreated: 1515443725 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopPlayerPrefs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public static class PopPlayerPrefs 6 | { 7 | const string NullValue = ""; // if we serialise null, we write this. If we deseralise it instead of json, return null 8 | 9 | public static void SetObject(string Key, T Value) 10 | { 11 | var Json = (Value == null) ? NullValue : JsonUtility.ToJson(Value); 12 | PlayerPrefs.SetString(Key, Json); 13 | } 14 | 15 | public static T GetObject(string Key) 16 | { 17 | var Json = PlayerPrefs.GetString(Key); 18 | if (Json.Equals(NullValue)) 19 | return default(T); 20 | 21 | var Obj = JsonUtility.FromJson(Json); 22 | return Obj; 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /PopPlayerPrefs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 78e53c9579f4b42b1a6a8e3fbb61b657 3 | timeCreated: 1521036122 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopSvg.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8715f141675184b10b075c8cbe94b777 3 | timeCreated: 1538428012 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopTask.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | public class TTask 8 | { 9 | public System.Action Function; 10 | public string Description; 11 | 12 | public TTask(string _Description,System.Action _Function) 13 | { 14 | this.Function = _Function; 15 | this.Description = _Description; 16 | } 17 | }; 18 | 19 | 20 | 21 | 22 | [ExecuteInEditMode] 23 | public abstract class PopTaskManager : MonoBehaviour { 24 | 25 | public PopTaskProgressBar Progress; 26 | protected List Tasks; 27 | 28 | abstract protected void PopulateTasks(); 29 | virtual protected void OnTaskException(System.Exception e) 30 | { 31 | } 32 | 33 | IEnumerator RunTasks() 34 | { 35 | Tasks = new List(); 36 | PopulateTasks(); 37 | 38 | if ( Progress ) 39 | Progress.InitProgress( this.name, (uint)Tasks.Count ); 40 | 41 | for (int t = 0; t < Tasks.Count; t++) 42 | { 43 | var Task = Tasks[t]; 44 | 45 | try 46 | { 47 | if ( Progress ) 48 | Progress.UpdateProgress(Task.Description); 49 | Task.Function.Invoke(); 50 | } 51 | catch (System.Exception e) 52 | { 53 | OnTaskException(e); 54 | Debug.LogException(e); 55 | if ( Progress ) 56 | Progress.FinishProgress(false); 57 | yield break; 58 | } 59 | 60 | yield return null; 61 | } 62 | 63 | if ( Progress ) 64 | Progress.FinishProgress(true); 65 | } 66 | 67 | public void Execute() 68 | { 69 | StartCoroutine( RunTasks() ); 70 | } 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /PopTask.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a21f5080d71c38e41948f7117e840495 3 | timeCreated: 1480258159 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopTaskProgressBar.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | using UnityEngine.UI; 9 | 10 | 11 | [System.Serializable] 12 | public class UnityEvent_OnProgress : UnityEvent {} 13 | 14 | 15 | 16 | public class PopTaskProgressBar : MonoBehaviour { 17 | 18 | public UnityEvent_OnProgress OnProgress; 19 | public UnityEvent OnComplete; 20 | 21 | [Header("UI progress bar")] 22 | public Slider ProgressSlider; 23 | public Button CancelButton; 24 | public Text DescriptionText; 25 | 26 | string ProgressName; 27 | int CurrentStep; 28 | bool Cancelled; 29 | uint StepCount; 30 | 31 | 32 | public void InitProgress(string ProgressName,uint StepCount) 33 | { 34 | this.ProgressName = ProgressName; 35 | CurrentStep = -1; 36 | Cancelled = false; 37 | this.StepCount = StepCount; 38 | 39 | 40 | if (ProgressSlider != null) 41 | { 42 | ProgressSlider.maxValue = StepCount; 43 | ProgressSlider.minValue = 0; 44 | ProgressSlider.value = 0; 45 | ProgressSlider.wholeNumbers = true; 46 | } 47 | 48 | if ( DescriptionText != null ) 49 | { 50 | DescriptionText.text = ProgressName; 51 | } 52 | 53 | if ( CancelButton != null ) 54 | { 55 | UnityAction Cancel = () => 56 | { 57 | Cancelled = true; 58 | }; 59 | CancelButton.onClick.AddListener( Cancel ); 60 | } 61 | 62 | } 63 | 64 | 65 | 66 | public void UpdateProgress(string Description) 67 | { 68 | CurrentStep++; 69 | 70 | float Progress = CurrentStep / (float)StepCount; 71 | 72 | try 73 | { 74 | OnProgress.Invoke(Progress); 75 | } 76 | catch (System.Exception e) 77 | { 78 | Debug.LogException( e ); 79 | } 80 | 81 | // update editorui 82 | #if UNITY_EDITOR 83 | if ( EditorUtility.DisplayCancelableProgressBar( ProgressName, Description, Progress ) ) 84 | { 85 | Cancelled = true; 86 | } 87 | #endif 88 | // update ui 89 | if ( ProgressSlider != null ) 90 | { 91 | ProgressSlider.value = CurrentStep; 92 | } 93 | if ( DescriptionText != null ) 94 | { 95 | DescriptionText.text = Description; 96 | } 97 | 98 | if (Cancelled) 99 | { 100 | FinishProgress(false); 101 | throw new System.Exception( ProgressName + " cancelled"); 102 | } 103 | } 104 | 105 | 106 | public void FinishProgress(bool Success=true) 107 | { 108 | #if UNITY_EDITOR 109 | EditorUtility.ClearProgressBar(); 110 | #endif 111 | if ( DescriptionText != null ) 112 | { 113 | if ( Success ) 114 | DescriptionText.text = ProgressName + " complete"; 115 | else 116 | DescriptionText.text = ProgressName + " failed"; 117 | } 118 | if ( ProgressSlider != null ) 119 | { 120 | if ( Success ) 121 | ProgressSlider.value = ProgressSlider.maxValue; 122 | } 123 | 124 | try 125 | { 126 | if ( Success ) 127 | OnComplete.Invoke(); 128 | } 129 | catch (System.Exception e) 130 | { 131 | Debug.LogException( e ); 132 | } 133 | 134 | } 135 | 136 | 137 | 138 | } 139 | -------------------------------------------------------------------------------- /PopTaskProgressBar.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7658d1c0d3b0a834d8d53d8bf447ba44 3 | timeCreated: 1480196918 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.IO; 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | 8 | namespace PopX 9 | { 10 | public static class Textures 11 | { 12 | #if UNITY_EDITOR 13 | [MenuItem("Assets/Texture/Save Texture to Png No Alpha")] 14 | static void _SaveTextureToPng() 15 | { 16 | _SaveTextureToPng(false); 17 | } 18 | #endif 19 | 20 | #if UNITY_EDITOR 21 | [MenuItem("Assets/Texture/Save Texture to Png With Alpha")] 22 | static void _SaveTextureToPngWithAlpha() 23 | { 24 | _SaveTextureToPng(true); 25 | } 26 | #endif 27 | 28 | #if UNITY_EDITOR 29 | static void _SaveTextureToPng(bool Alpha) 30 | { 31 | // get selected textures 32 | string[] AssetGuids = Selection.assetGUIDs; 33 | for (int i=0; i> downsample; 67 | int rtH = Source.height >> downsample; 68 | 69 | // downsample 70 | RenderTexture rt = RenderTexture.GetTemporary (rtW, rtH, 0, Source.format); 71 | 72 | rt.filterMode = FilterMode.Bilinear; 73 | Graphics.Blit (Source, rt, blurMaterial, 0); 74 | 75 | var passOffs= blurType == BlurType.StandardGauss ? 0 : 2; 76 | 77 | for(int i = 0; i < blurIterations; i++) { 78 | float iterationOffs = (i*1.0f); 79 | blurMaterial.SetVector ("_Parameter", new Vector4 (blurSize * widthMod + iterationOffs, -blurSize * widthMod - iterationOffs, 0.0f, 0.0f)); 80 | 81 | // vertical blur 82 | RenderTexture rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, Source.format); 83 | rt2.filterMode = FilterMode.Bilinear; 84 | Graphics.Blit (rt, rt2, blurMaterial, 1 + passOffs); 85 | RenderTexture.ReleaseTemporary (rt); 86 | rt = rt2; 87 | 88 | // horizontal blur 89 | rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, Source.format); 90 | rt2.filterMode = FilterMode.Bilinear; 91 | Graphics.Blit (rt, rt2, blurMaterial, 2 + passOffs); 92 | RenderTexture.ReleaseTemporary (rt); 93 | rt = rt2; 94 | } 95 | 96 | Target.DiscardContents (); 97 | Graphics.Blit (rt, Target); 98 | 99 | RenderTexture.ReleaseTemporary (rt); 100 | 101 | 102 | return true; 103 | } 104 | 105 | void OnGUI() 106 | { 107 | if ( mOutput && mDebugViewport.width+mDebugViewport.height>0 ) 108 | { 109 | GUI.DrawTexture( new Rect(mDebugViewport.x*Screen.width, mDebugViewport.y*Screen.height, mDebugViewport.width*Screen.width, mDebugViewport.height*Screen.height ), mOutput ); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /PopTextureBlur.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f8cc0d9964a447458e38b27d53b0e07 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopTextureBlur.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 50887dd2ffad449ad825a2f8ca741ca1 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /PopTime.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace PopX 6 | { 7 | public static class Time 8 | { 9 | // this is okay as an int as 10 | // max in a day will be 86400000 11 | // max int32 2147483647 12 | // but YOU should probably not be storing timecodes in an int. 13 | // being utc, maybe this can be negative? 14 | public static int GetTodayUtcTimeMs() 15 | { 16 | var TimeMs = 0; 17 | var MsMs = 1; 18 | var SecondMs = 1000; 19 | var MinuteMs = SecondMs * 60; 20 | var HourMs = MinuteMs * 60; 21 | var Now = System.DateTime.UtcNow; 22 | TimeMs += Now.Hour * HourMs; 23 | TimeMs += Now.Minute * MinuteMs; 24 | TimeMs += Now.Second * SecondMs; 25 | TimeMs += Now.Millisecond * MsMs; 26 | return TimeMs; 27 | } 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /PopTime.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fb4c02c0a54c24a61bcd382d5ca7bda4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /PopUrl.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7f2193da979b42fa846ba674e125962 3 | timeCreated: 1472594903 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PopVectorX.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a11915961443247198d91d8a76af8100 3 | timeCreated: 1519733664 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /PopWavefrontObj.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8f0deaf2bffbd496e935b4d4bc8d155f 3 | timeCreated: 1523017322 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /RandomMaterialInitialisation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | public class RandomMaterialInitialisation : MonoBehaviour { 7 | 8 | [InspectorButton("Randomise")] 9 | public bool _Randomise; 10 | 11 | [Header("If this is false, a new instance of the material will be created")] 12 | public bool RandomiseSharedMaterial = true; 13 | 14 | [Header("Randomly set these values based on their range")] 15 | public List Uniforms; 16 | 17 | void Start () { 18 | } 19 | 20 | #if UNITY_EDITOR 21 | public void Randomise() 22 | { 23 | var mr = GetComponent (); 24 | var Mat = RandomiseSharedMaterial ? mr.sharedMaterial : mr.material; 25 | 26 | foreach (var Uniform in Uniforms) { 27 | RandomiseUniform (Mat, Uniform); 28 | } 29 | } 30 | #endif 31 | 32 | #if UNITY_EDITOR 33 | public void RandomiseUniform(Material Mat,string Uniform) 34 | { 35 | var Shader = Mat.shader; 36 | var PropertyIndex = Shader.PropertyToID (Uniform); 37 | if (PropertyIndex < 0) 38 | { 39 | Debug.LogError ("No uniform named " + Uniform + " in " + Shader.name); 40 | return; 41 | } 42 | Debug.Log ("uniform " + Uniform + " in " + Shader.name + " = " + PropertyIndex); 43 | 44 | //float Default = UnityEditor.ShaderUtil.GetRangeLimits (Shader, PropertyIndex, 0); 45 | float Min = UnityEditor.ShaderUtil.GetRangeLimits (Shader, PropertyIndex, 1); 46 | float Max = UnityEditor.ShaderUtil.GetRangeLimits (Shader, PropertyIndex, 2); 47 | 48 | RandomiseUniform (Mat, Uniform, Min, Max); 49 | } 50 | #endif 51 | 52 | // gr: serialise these attributes to allow randomisation at startup 53 | #if UNITY_EDITOR 54 | public void RandomiseUniform(Material Mat,string Uniform,float Min,float Max) 55 | { 56 | var Value = Random.Range (Min, Max); 57 | Mat.SetFloat (Uniform, Value); 58 | } 59 | #endif 60 | 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /RandomMaterialInitialisation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 168a5ee5a99d746eb87867e3149145c6 3 | timeCreated: 1484827252 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /RangeMinMaxAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | #if UNITY_EDITOR 8 | using UnityEditor; 9 | using System.Reflection; 10 | #endif 11 | 12 | 13 | 14 | [System.AttributeUsage(System.AttributeTargets.Field)] 15 | public class RangeMinMaxAttribute : PropertyAttribute 16 | { 17 | public float Min; 18 | public float Max; 19 | public bool ShowNumbers; 20 | 21 | public RangeMinMaxAttribute(float Min,float Max,bool ShowNumbers=true) 22 | { 23 | this.Min = Min; 24 | this.Max = Max; 25 | this.ShowNumbers = ShowNumbers; 26 | } 27 | } 28 | 29 | 30 | 31 | #if UNITY_EDITOR 32 | [CustomPropertyDrawer(typeof(RangeMinMaxAttribute))] 33 | public class RangeMinMaxAttributeDrawer : PropertyDrawer 34 | { 35 | public static bool DrawAttribute(Rect position,ref Vector2 Value,Vector2 MinMax,string Label,bool ShowNumbers) 36 | { 37 | var xy = Value; 38 | 39 | // gr: label width is way too big for materials... 40 | var LabelWidth = EditorGUIUtility.labelWidth * 0.20f; 41 | //EditorGUIUtility.labelWidth = LabelWidth; 42 | 43 | // work out rects for each bit 44 | var LeftWidth = position.height * 3; 45 | var LeftStart = position.xMin + LabelWidth; 46 | var LeftEnd = LeftStart + LeftWidth; 47 | var RightEnd = position.xMax; 48 | var RightStart = RightEnd - LeftWidth; 49 | if (!ShowNumbers) 50 | { 51 | LeftEnd = LeftStart; 52 | RightStart = RightEnd; 53 | } 54 | var MiddleStart = LeftEnd; 55 | var MiddleEnd = RightStart; 56 | 57 | var LabelRect = new Rect(position.x, position.y, LabelWidth, position.height); 58 | var LeftRect = new Rect(LeftStart, position.y, LeftEnd - LeftStart, position.height); 59 | var RightRect = new Rect(RightStart, position.y, RightEnd - RightStart, position.height); 60 | var MiddleRect = new Rect(MiddleStart, position.y, MiddleEnd - MiddleStart, position.height); 61 | 62 | EditorGUI.LabelField(LabelRect, Label); 63 | EditorGUI.BeginChangeCheck(); 64 | 65 | if ( ShowNumbers ) 66 | xy.x = EditorGUI.FloatField(LeftRect, xy.x); 67 | EditorGUI.MinMaxSlider(MiddleRect, ref xy.x, ref xy.y, MinMax.x, MinMax.y); 68 | if (ShowNumbers) 69 | xy.y = EditorGUI.FloatField(RightRect, xy.y); 70 | 71 | if (!EditorGUI.EndChangeCheck()) 72 | return false; 73 | 74 | Value = xy; 75 | return true; 76 | } 77 | 78 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 79 | { 80 | var Attrib = (RangeMinMaxAttribute)attribute; 81 | var MinMax = new Vector2(Attrib.Min, Attrib.Max); 82 | 83 | var Value2 = property.vector2Value; 84 | if (DrawAttribute(position, ref Value2, MinMax, label.text, Attrib.ShowNumbers)) 85 | { 86 | property.vector2Value = Value2; 87 | } 88 | } 89 | } 90 | #endif 91 | 92 | 93 | // add to material property like 94 | // [RangeMinMax(0,1)]MyRange("MyRange", VECTOR) = (0,0,0,0) 95 | #if UNITY_EDITOR 96 | public class RangeMinMaxDrawer : MaterialPropertyDrawer 97 | { 98 | float ValueMin = 0; 99 | float ValueMax = 0; 100 | 101 | public RangeMinMaxDrawer(float Min, float Max) 102 | { 103 | this.ValueMin = Min; 104 | this.ValueMax = Max; 105 | } 106 | 107 | // Draw the property inside the given rect 108 | public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) 109 | { 110 | var MinMax = new Vector2(ValueMin, ValueMax); 111 | var ShowNumbers = true; 112 | var Value2 = prop.vectorValue.xy(); 113 | 114 | if (RangeMinMaxAttributeDrawer.DrawAttribute(position, ref Value2, MinMax, label, ShowNumbers)) 115 | { 116 | var Value4 = Value2.xyzw(prop.vectorValue.z, prop.vectorValue.w); 117 | prop.vectorValue = Value4; 118 | } 119 | 120 | } 121 | } 122 | #endif 123 | -------------------------------------------------------------------------------- /RangeMinMaxAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8809616eaca6d4ced85de62e7dbf4f91 3 | timeCreated: 1494934628 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /RectTransformUV.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | 9 | [RequireComponent(typeof(RectTransform))] 10 | public class RectTransformUV : MonoBehaviour { 11 | 12 | [InspectorButton("SetPosition00")] 13 | public bool _SetPosition00; 14 | 15 | [InspectorButton("SetPosition11")] 16 | public bool _SetPosition11; 17 | 18 | 19 | void SetPosition00() 20 | { 21 | SetPositionUv (new Vector2 (0, 0)); 22 | } 23 | 24 | void SetPosition11() 25 | { 26 | SetPositionUv (new Vector2 (1, 1)); 27 | } 28 | 29 | public void SetPositionUv(Vector2 PositionUv) 30 | { 31 | var rt = GetComponent (); 32 | var rtparent = rt.parent; 33 | var rtparentrt = rtparent.GetComponent (); 34 | 35 | var rect = rtparentrt.rect; 36 | 37 | var Pos3 = new Vector3 (0, 0, rt.localPosition.z); 38 | Pos3.x = Mathf.Lerp (rect.xMin, rect.xMax, PositionUv.x); 39 | Pos3.y = 1 - Mathf.Lerp (rect.yMin, rect.yMax, PositionUv.y); 40 | 41 | rt.localPosition = Pos3; 42 | } 43 | } 44 | 45 | /* 46 | #if UNITY_EDITOR 47 | [CustomEditor(typeof(RectTransformUV))] 48 | public class RectTransformUVEditor : Editor 49 | { 50 | public override void OnInspectorGUI() 51 | { 52 | var RT = (RectTransformUV)target; 53 | 54 | EditorGUI.DrawRect( 55 | 56 | myTarget.experience = EditorGUILayout.IntField("Experience", myTarget.experience); 57 | EditorGUILayout.LabelField("Level", myTarget.Level.ToString()); 58 | } 59 | } 60 | #endif 61 | */ 62 | -------------------------------------------------------------------------------- /RectTransformUV.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 826ad77c6233c4e808bbb553245cc108 3 | timeCreated: 1498927117 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /RelayFloatValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | 7 | public class RelayFloatValue : MonoBehaviour 8 | { 9 | 10 | public bool SetDefaultOnStart = true; 11 | public bool SetDefaultOnDestroy = true; 12 | public float DefaultValue; 13 | public float Value; 14 | public UnityEvent_float OnUpdate; 15 | 16 | void Start() 17 | { 18 | if ( SetDefaultOnStart ) 19 | OnUpdate.Invoke(DefaultValue); 20 | } 21 | 22 | void Update() 23 | { 24 | OnUpdate.Invoke(Value); 25 | } 26 | 27 | void OnDestroy() 28 | { 29 | if ( SetDefaultOnDestroy ) 30 | OnUpdate.Invoke(DefaultValue); 31 | } 32 | 33 | public void SetValue(float f) 34 | { 35 | Value = f; 36 | OnUpdate.Invoke (Value); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /RelayFloatValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c600b5a2213e1fc408579891030704dc 3 | timeCreated: 1497448981 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /RgbToHsl.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "NewChromantics/RgbToHsl" 4 | { 5 | Properties 6 | { 7 | _MainTex ("Texture", 2D) = "white" {} 8 | } 9 | SubShader 10 | { 11 | Tags { "RenderType"="Opaque" } 12 | 13 | Pass 14 | { 15 | CGPROGRAM 16 | #pragma vertex vert 17 | #pragma fragment frag 18 | 19 | #include "UnityCG.cginc" 20 | #include "PopCommon.cginc" 21 | 22 | struct appdata 23 | { 24 | float4 vertex : POSITION; 25 | float2 uv : TEXCOORD0; 26 | }; 27 | 28 | struct v2f 29 | { 30 | float2 uv : TEXCOORD0; 31 | float4 vertex : SV_POSITION; 32 | }; 33 | 34 | sampler2D _MainTex; 35 | float4 _MainTex_ST; 36 | 37 | v2f vert (appdata v) 38 | { 39 | v2f o; 40 | o.vertex = UnityObjectToClipPos(v.vertex); 41 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 42 | return o; 43 | } 44 | 45 | float4 frag (v2f i) : SV_Target 46 | { 47 | float4 rgba = tex2D(_MainTex, i.uv); 48 | 49 | float3 hsl = RgbToHsl( rgba.xyz ); 50 | 51 | return float4( hsl, rgba.w ); 52 | } 53 | ENDCG 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /RgbToHsl.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7121a89afe79be847bd58ee5f9f88410 3 | timeCreated: 1479498263 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SceneNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | #if UNITY_EDITOR 8 | using UnityEditor; 9 | using System.Reflection; 10 | #endif 11 | 12 | 13 | 14 | [System.AttributeUsage(System.AttributeTargets.Field)] 15 | public class SceneNameAttribute : PropertyAttribute 16 | { 17 | } 18 | 19 | 20 | 21 | #if UNITY_EDITOR 22 | [CustomPropertyDrawer(typeof(SceneNameAttribute))] 23 | public class SceneNameAttributePropertyDrawer : PropertyDrawer 24 | { 25 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 26 | { 27 | var Attrib = (SceneNameAttribute)attribute; 28 | var TargetObject = property.serializedObject.targetObject; 29 | 30 | var SceneName = property.stringValue; 31 | 32 | 33 | SceneAsset Scene = null; 34 | try 35 | { 36 | if ( !string.IsNullOrEmpty(SceneName) ) 37 | { 38 | var SceneGuids = AssetDatabase.FindAssets ("t:scene " + SceneName); 39 | var SceneGuid = SceneGuids[0]; 40 | var ScenePath = AssetDatabase.GUIDToAssetPath( SceneGuid ); 41 | Scene = AssetDatabase.LoadAssetAtPath( ScenePath ); 42 | } 43 | } 44 | catch { 45 | } 46 | 47 | //serializedObject.Update(); 48 | 49 | EditorGUI.BeginChangeCheck(); 50 | 51 | //Scene = EditorGUI.ObjectField( position, property.displayName, Scene, typeof(SceneAsset), false) as SceneAsset; 52 | Scene = EditorGUI.ObjectField( position, property.displayName, Scene, typeof(SceneAsset), false ) as SceneAsset; 53 | 54 | if (EditorGUI.EndChangeCheck()) 55 | { 56 | property.stringValue = Scene ? Scene.name : null; 57 | } 58 | 59 | property.serializedObject.ApplyModifiedProperties(); 60 | 61 | } 62 | 63 | } 64 | #endif 65 | 66 | 67 | -------------------------------------------------------------------------------- /SceneNameAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf5e87e0d99c041b18a3f71229406c0e 3 | timeCreated: 1509054593 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /SceneOrderController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class SceneOrderController : MonoBehaviour { 6 | 7 | public List ScenesNames; 8 | 9 | [InspectorButton("NextScene")] 10 | public bool _NextScene; 11 | 12 | void Awake() { 13 | DontDestroyOnLoad(this); 14 | } 15 | 16 | public void NextScene() 17 | { 18 | // pop first one and goto it 19 | string NextScene = null; 20 | while (ScenesNames.Count > 0) { 21 | NextScene = ScenesNames [0]; 22 | ScenesNames.RemoveAt (0); 23 | if (NextScene != null) 24 | break; 25 | Debug.Log ("Entry in scene list is null"); 26 | } 27 | 28 | if (NextScene == null) { 29 | Debug.LogError ("No scene to move onto."); 30 | return; 31 | } 32 | 33 | Debug.Log ("Loading " + NextScene); 34 | UnityEngine.SceneManagement.SceneManager.LoadScene (NextScene, UnityEngine.SceneManagement.LoadSceneMode.Single); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SceneOrderController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 47745d597506642a386feca3c400d81e 3 | timeCreated: 1492685504 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SetAndroidManifest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.Text.RegularExpressions; 5 | 6 | #if UNITY_EDITOR 7 | using UnityEditor; 8 | #endif 9 | 10 | public class SetAndroidManifest : MonoBehaviour { 11 | 12 | const string AndroidManifestAssetName = "AndroidManifest"; 13 | const string AndroidManifestFilename = "AndroidManifest.xml"; 14 | 15 | #if UNITY_EDITOR 16 | [MenuItem("NewChromantics/Android/Set Manifest category.LAUNCHER (Debug)")] 17 | public static void SetAndroidManifest_Launcher() 18 | { 19 | SetAndroidManifestTo ("LAUNCHER"); 20 | } 21 | #endif 22 | 23 | #if UNITY_EDITOR 24 | [MenuItem("NewChromantics/Android/Set Manifest category.INFO (Store)")] 25 | public static void SetAndroidManifest_Info() 26 | { 27 | SetAndroidManifestTo ("INFO"); 28 | } 29 | #endif 30 | 31 | #if UNITY_EDITOR 32 | public static void SetAndroidManifestTo(string NewCategory) 33 | { 34 | // find manifest assets 35 | var XmlGuids = AssetDatabase.FindAssets (AndroidManifestAssetName, null); 36 | 37 | // filter matching filenames 38 | var XmlFileGuids = new List (XmlGuids).FindAll ((Guid) => { 39 | var Path = AssetDatabase.GUIDToAssetPath (Guid); 40 | return Path.EndsWith (AndroidManifestFilename); 41 | }); 42 | 43 | // setup regular expression 44 | string MatchPattern = ""; 45 | // gr: I thought it would just repalce the match, but in c# the whole match is replaced :) 46 | //string Replacement = NewCategory; 47 | string Replacement = ""; 48 | Regex RegExpression = new Regex(MatchPattern); 49 | 50 | string NoChangeFilenames = null; 51 | 52 | foreach (var XmlGuid in XmlFileGuids) { 53 | var Path = AssetDatabase.GUIDToAssetPath (XmlGuid); 54 | try 55 | { 56 | var Contents = System.IO.File.ReadAllText( Path ); 57 | var NewContents = RegExpression.Replace( Contents, Replacement ); 58 | if ( Contents != NewContents ) 59 | { 60 | System.IO.File.WriteAllText( Path, NewContents ); 61 | Debug.Log("Updated " + Path ); 62 | } 63 | else 64 | { 65 | NoChangeFilenames += Path + " "; 66 | //Debug.Log("skipped " + Path ); 67 | } 68 | } 69 | catch(System.Exception e) { 70 | Debug.LogError ("Error replacing manifest in " + Path); 71 | Debug.LogException (e); 72 | } 73 | } 74 | 75 | if (!string.IsNullOrEmpty (NoChangeFilenames)) 76 | Debug.Log ("Didn't change " + NoChangeFilenames); 77 | 78 | // search/replace in file 79 | // 80 | } 81 | #endif 82 | 83 | } 84 | -------------------------------------------------------------------------------- /SetAndroidManifest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3268a85d14627477c9f28c5e26c8b124 3 | timeCreated: 1493303337 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SetAnimationTime.cs: -------------------------------------------------------------------------------- 1 | // gr: actually the simpler solution. 2 | #define PAUSE_VIA_ENABLE 3 | 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using UnityEngine; 7 | 8 | 9 | public class SetAnimationTime : MonoBehaviour { 10 | 11 | public bool ShowDebug = false; 12 | #if !PAUSE_VIA_ENABLE 13 | float? PausedNormTime = null; 14 | int? PausedState = null; 15 | #endif 16 | 17 | Animator Anim 18 | { 19 | get 20 | { 21 | var Comp = GetComponent(); 22 | if (Comp != null) 23 | return Comp; 24 | 25 | return GetComponentInChildren(); 26 | } 27 | } 28 | 29 | 30 | public void SetNormalisedTime(float TimeNorm) 31 | { 32 | // gr: we get errors with Play() below if this isn't enabled 33 | // Animator is not playing an AnimatorController 34 | // and while it might be nicer to just make it work, unity is throwing out this error we can't suppress 35 | if (!this.isActiveAndEnabled) 36 | return; 37 | 38 | try 39 | { 40 | // gr: if we were "paused", the state is probably garbage. 41 | Resume(); 42 | } 43 | catch(System.Exception) 44 | { 45 | } 46 | 47 | var State = Anim.GetCurrentAnimatorStateInfo(0); 48 | var StateHash = State.shortNameHash; 49 | 50 | var TimeSecs = TimeNorm * State.length; 51 | 52 | if ( ShowDebug ) 53 | Debug.Log("Setting animator time " + TimeSecs + "/" + State.length + " -> Play(" + TimeNorm + ")"); 54 | 55 | Anim.speed = 1; 56 | Anim.Play(StateHash, 0, TimeNorm); 57 | 58 | #if !PAUSE_VIA_ENABLE 59 | { 60 | // "unpause" 61 | PausedNormTime = null; 62 | PausedState = null; 63 | } 64 | #endif 65 | } 66 | 67 | 68 | public void SetTime(float TimeSecs) 69 | { 70 | try 71 | { 72 | // gr: if we were "paused", the state is probably garbage. 73 | Resume(); 74 | } 75 | catch (System.Exception){ 76 | } 77 | 78 | var Anim = this.Anim; 79 | var State = Anim.GetCurrentAnimatorStateInfo (0); 80 | var TimeNorm = TimeSecs / State.length; 81 | 82 | SetNormalisedTime(TimeNorm); 83 | } 84 | 85 | public void Resume() 86 | { 87 | var Anim = this.Anim; 88 | 89 | #if PAUSE_VIA_ENABLE 90 | { 91 | Anim.enabled = true; 92 | } 93 | #else 94 | { 95 | if (!PausedNormTime.HasValue || !PausedState.HasValue) 96 | throw new System.Exception ("Trying to resume Animator which wasn't paused"); 97 | 98 | //var Anim = this.Anim; 99 | 100 | var TimeNorm = PausedNormTime.Value; 101 | var StateHash = PausedState.Value; 102 | 103 | PausedNormTime = null; 104 | PausedState = null; 105 | 106 | Debug.Log ("Resuming animator at normalised time " + TimeNorm + ")"); 107 | 108 | 109 | Anim.speed = 1; 110 | Anim.Play ( StateHash, 0, TimeNorm); 111 | } 112 | #endif 113 | } 114 | 115 | public void Pause() 116 | { 117 | var Anim = this.Anim; 118 | 119 | #if PAUSE_VIA_ENABLE 120 | { 121 | Anim.enabled = false; 122 | } 123 | #else 124 | { 125 | var State = Anim.GetCurrentAnimatorStateInfo (0); 126 | var TimeSecs = State.normalizedTime * State.length; 127 | 128 | PausedNormTime = State.normalizedTime; 129 | PausedState = State.shortNameHash; 130 | 131 | Debug.Log ("Pausing animator at " + TimeSecs); 132 | Anim.speed = 0; 133 | } 134 | #endif 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /SetAnimationTime.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: de7d3dc831d1a4966ac6fe96ef425db7 3 | timeCreated: 1509477415 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SetMaterialValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1de785c1d6f724c579a28ce4226ef101 3 | timeCreated: 1483532256 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SetMaterialValueToCollider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | [System.Serializable] 7 | public class UnityEvent_Vector4 : UnityEngine.Events.UnityEvent {} 8 | 9 | 10 | 11 | [ExecuteInEditMode] 12 | public class SetMaterialValueToCollider : MonoBehaviour { 13 | 14 | public UnityEvent_Vector4 OnColliderChanged; 15 | 16 | void Start () { 17 | 18 | var Sphere = GetComponent (); 19 | if (Sphere) { 20 | var Sphere4 = new Vector4 (Sphere.center.x, Sphere.center.y, Sphere.center.z, Sphere.radius); 21 | OnColliderChanged.Invoke (Sphere4); 22 | } 23 | } 24 | 25 | #if UNITY_EDITOR 26 | void Update() 27 | { 28 | Start(); 29 | } 30 | #endif 31 | 32 | } 33 | -------------------------------------------------------------------------------- /SetMaterialValueToCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 968380231b9a84f5cb096b1db3b38021 3 | timeCreated: 1484850356 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SetMeshBoundsToCollider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class SetMeshBoundsToCollider : MonoBehaviour { 6 | 7 | 8 | [InspectorButton("SetMeshFilterMeshBoundsToCollider")] 9 | public bool _SetMeshFilterMeshBoundsToCollider; 10 | 11 | 12 | void Start () { 13 | 14 | SetMeshFilterMeshBoundsToCollider (); 15 | } 16 | 17 | 18 | public void SetMeshFilterMeshBoundsToCollider() 19 | { 20 | var mf = GetComponent (); 21 | if (mf) { 22 | var Mesh = mf.mesh; 23 | SetMeshBoundsToMeshFilterMesh (Mesh); 24 | } 25 | 26 | } 27 | 28 | public void SetMeshBoundsToMeshFilterMesh(Mesh mesh) 29 | { 30 | var Collider = GetComponent (); 31 | if (Collider && mesh) { 32 | mesh.bounds = Collider.bounds; 33 | } 34 | 35 | } 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /SetMeshBoundsToCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e7bbf08a48844bc391e037f0d499880 3 | timeCreated: 1484855216 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SetTimelineTime.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_2017_1_OR_NEWER 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEngine.Playables; 6 | 7 | 8 | public class SetTimelineTime : MonoBehaviour { 9 | 10 | PlayableDirector TimelineDirector { get { return GetComponent (); } } 11 | 12 | public void SetTime(float Seconds) 13 | { 14 | var Timeline = TimelineDirector; 15 | Timeline.time = Seconds; 16 | } 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /SetTimelineTime.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abaf90481e26d467c891af4432ca15b1 3 | timeCreated: 1509537383 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ShaderBlit.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | 6 | [ExecuteInEditMode] 7 | public class ShaderBlit : MonoBehaviour { 8 | 9 | [InspectorButton("Execute")] 10 | public bool Dirty = true; 11 | public bool AlwaysDirtyInEditor = true; 12 | public Texture Input; 13 | public Shader BlitShader; 14 | public Material BlitMaterial; 15 | public RenderTexture Output; 16 | public UnityEngine.Events.UnityEvent OnClean; 17 | 18 | public void SetDirty() 19 | { 20 | Dirty = true; 21 | } 22 | 23 | public void Execute() 24 | { 25 | if (BlitShader != null) 26 | { 27 | if ( BlitMaterial == null ) 28 | BlitMaterial = new Material( BlitShader ); 29 | } 30 | 31 | //if ( BlitMaterial == null ) 32 | // return; 33 | 34 | if ( BlitMaterial == null ) 35 | Graphics.Blit( Input, Output ); 36 | else 37 | Graphics.Blit( Input, Output, BlitMaterial ); 38 | 39 | } 40 | 41 | 42 | void Update () 43 | { 44 | if ( Application.isEditor && !Application.isPlaying && AlwaysDirtyInEditor ) 45 | Dirty = true; 46 | 47 | if ( !Dirty ) 48 | return; 49 | 50 | if ( Input == null ) 51 | return; 52 | 53 | Execute(); 54 | 55 | Dirty = false; 56 | 57 | if ( OnClean != null ) 58 | OnClean.Invoke(); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ShaderBlit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ed8d634c334801438938b7b65a73043 3 | timeCreated: 1479497941 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ShowFunctionResultAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | using System.Reflection; 8 | #endif 9 | 10 | 11 | [System.AttributeUsage(System.AttributeTargets.Field)] 12 | public class ShowFunctionResultAttribute : PropertyAttribute 13 | { 14 | public readonly string MethodName; 15 | public readonly float AdditionalHeight; 16 | 17 | public ShowFunctionResultAttribute(string MethodName,float AdditionalHeight=0) 18 | { 19 | this.MethodName = MethodName; 20 | this.AdditionalHeight = AdditionalHeight; 21 | } 22 | } 23 | 24 | #if UNITY_EDITOR 25 | [CustomPropertyDrawer(typeof(ShowFunctionResultAttribute))] 26 | public class ShowFunctionResultAttributeDrawer : PropertyDrawer 27 | { 28 | 29 | public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label) 30 | { 31 | var Attrib = (ShowFunctionResultAttribute)attribute; 32 | 33 | try 34 | { 35 | System.Type eventOwnerType = prop.serializedObject.targetObject.GetType(); 36 | var FunctionName = Attrib.MethodName; 37 | var _eventMethodInfo = eventOwnerType.GetMethod( FunctionName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); 38 | 39 | var Result = _eventMethodInfo.Invoke(prop.serializedObject.targetObject, null); 40 | 41 | if ( Result is Color ) 42 | { 43 | var ResultColour = (Color)Result; 44 | EditorGUI.DrawRect(position, ResultColour); 45 | } 46 | else 47 | { 48 | var Text = "" + Result; 49 | EditorGUI.HelpBox(position, Text, MessageType.Info); 50 | } 51 | } 52 | catch(System.Exception e) 53 | { 54 | EditorGUI.HelpBox (position, e.Message, MessageType.Error); 55 | } 56 | } 57 | 58 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) 59 | { 60 | var Attrib = (ShowFunctionResultAttribute)attribute; 61 | 62 | var OriginalHeight = base.GetPropertyHeight(property, label); 63 | OriginalHeight += Attrib.AdditionalHeight; 64 | return OriginalHeight; 65 | } 66 | 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /ShowFunctionResultAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 60318ee66b7c44999828a4c0bac8c3f4 3 | timeCreated: 1510078216 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ShowIfAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | using System.Reflection; 8 | #endif 9 | 10 | [System.AttributeUsage(System.AttributeTargets.Field)] 11 | public class ShowIfAttribute : PropertyAttribute 12 | { 13 | public readonly string FunctionName; 14 | 15 | public ShowIfAttribute(string _FunctionName) 16 | { 17 | this.FunctionName = _FunctionName; 18 | } 19 | 20 | 21 | } 22 | 23 | 24 | #if UNITY_EDITOR 25 | [CustomPropertyDrawer(typeof(ShowIfAttribute))] 26 | public class PopPlatformAttributePropertyDrawer : PropertyDrawer 27 | { 28 | private MethodInfo CachedEventMethodInfo = null; 29 | 30 | 31 | bool IsVisible(Object TargetObject,ShowIfAttribute Attrib) 32 | { 33 | var TargetObjectType = TargetObject.GetType(); 34 | 35 | if (CachedEventMethodInfo == null) 36 | CachedEventMethodInfo = TargetObjectType.GetMethod(Attrib.FunctionName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); 37 | 38 | if (CachedEventMethodInfo != null) { 39 | var Result = CachedEventMethodInfo.Invoke (TargetObject, null); 40 | var ResultType = (Result == null) ? "null" : Result.GetType ().Name; 41 | try 42 | { 43 | var ResultBool = (bool)Result; 44 | return ResultBool; 45 | } 46 | catch(System.Exception e) { 47 | Debug.LogWarning ("Failed to get event " + Attrib.FunctionName + " in " + TargetObjectType + " result as bool (is " + ResultType + "); " + e.Message ); 48 | } 49 | } 50 | 51 | Debug.LogWarning("ShowIfAttribute: Unable to find method "+ Attrib.FunctionName + " in " + TargetObjectType); 52 | return false; 53 | } 54 | 55 | 56 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 57 | { 58 | var Attrib = (ShowIfAttribute)attribute; 59 | var TargetObject = property.serializedObject.targetObject; 60 | 61 | if ( IsVisible(TargetObject,Attrib)) { 62 | //base.OnGUI (position, prop, label); 63 | EditorGUI.PropertyField (position, property, label, true); 64 | } 65 | } 66 | 67 | public override float GetPropertyHeight (SerializedProperty property, GUIContent label) 68 | { 69 | var Attrib = (ShowIfAttribute)attribute; 70 | var TargetObject = property.serializedObject.targetObject; 71 | 72 | if ( IsVisible(TargetObject,Attrib)) { 73 | //base.OnGUI (position, prop, label); 74 | return base.GetPropertyHeight ( property, label); 75 | } 76 | return 0; 77 | } 78 | 79 | } 80 | #endif 81 | -------------------------------------------------------------------------------- /ShowIfAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d154d0e44abef48079bb286e091fab25 3 | timeCreated: 1493904669 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SmoothEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | public class SmoothEvent : MonoBehaviour { 7 | 8 | [Header("Called every frame")] 9 | public UnityEvent_float OnUpdate; 10 | public UnityEvent_float OnUpdateInverse; 11 | 12 | public UnityEvent OnFinished; 13 | public bool DisableOnFinished = true; 14 | 15 | [Header("Curve will be stretched to this duration")] 16 | [Range(0.01f,20.0f)] 17 | public float Duration = 5; 18 | public AnimationCurve Curve; 19 | 20 | public bool OnDisableJumpToEnd = false; 21 | 22 | public bool ClampOutput01 = false; 23 | 24 | float StartTime = 0; 25 | 26 | 27 | void OnEnable() 28 | { 29 | StartTime = Time.time; 30 | Update (); 31 | } 32 | 33 | void OnDisable() 34 | { 35 | if ( OnDisableJumpToEnd ) 36 | { 37 | StartTime = Time.time - Duration; 38 | Update(); 39 | } 40 | } 41 | 42 | 43 | void Update () { 44 | 45 | float TimePassed = Time.time - StartTime; 46 | 47 | 48 | if (TimePassed > Duration) { 49 | OnFinished.Invoke (); 50 | TimePassed = Duration; 51 | 52 | if (DisableOnFinished) 53 | this.enabled = false; 54 | } 55 | 56 | float Value = 0; 57 | if (Curve.keys.Length > 1) { 58 | var t = TimePassed / Duration; 59 | var CurveDuration = Curve.keys [Curve.length - 1].time; 60 | t = t * CurveDuration; 61 | Value = Curve.Evaluate (t); 62 | } else { 63 | Value = TimePassed / Duration; 64 | } 65 | 66 | if (ClampOutput01) 67 | Value = Mathf.Clamp01 (Value); 68 | 69 | OnUpdate.Invoke (Value); 70 | OnUpdateInverse.Invoke (1 - Value); 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /SmoothEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45de3c81884ba41df85676fdbb20e23b 3 | timeCreated: 1499632104 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Spline.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73b0969ecd1d1431587e26de92840ae6 3 | timeCreated: 1499526654 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SplineQuad.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | 7 | 8 | [System.Serializable] 9 | public class UnityEvent_ListOfVector3 : UnityEngine.Events.UnityEvent > {} 10 | 11 | [System.Serializable] 12 | public class UnityEvent_ArrayOfVector3 : UnityEngine.Events.UnityEvent {} 13 | 14 | 15 | [ExecuteInEditMode] 16 | public class SplineQuad : MonoBehaviour { 17 | 18 | 19 | [Range(0.0001f,1.0f)] 20 | public float MinDistanceToPushPosition = 0.1f; 21 | 22 | const int MAX_SPLINE_POINTS = 20; // see shader 23 | public string WorldPositionsUniform = "WorldPositions"; 24 | public string WorldPositionsCountUniform = "WorldPositionsCount"; 25 | 26 | [Header("If null, THIS is used")] 27 | public Transform _TheTrackObject; 28 | public Transform TrackObject { get{ return _TheTrackObject!=null ? _TheTrackObject : this.transform; }} 29 | public Material _SplineMaterial; 30 | public Material SplineMaterial { get{ return _SplineMaterial ? _SplineMaterial : GetSplineMaterial (); }} 31 | public bool _UseSharedMaterial = true; 32 | public bool UseSharedMaterial { get{ return (Application.isEditor && !Application.isPlaying) ? true : _UseSharedMaterial; }} 33 | public bool AutoTrack = true; 34 | 35 | List Positions; 36 | Vector4 TrackedPosition { get { return TrackObject.position; }} 37 | 38 | [Range(0.0f,10.0f)] 39 | public float Debug_Radius = 0.5f; 40 | 41 | public UnityEvent_ArrayOfVector3 OnPositionsChanged; 42 | 43 | [InspectorButton("RecordPosition")] 44 | public bool _RecordPosition; 45 | 46 | public void RecordPosition() 47 | { 48 | PushPosition( TrackedPosition ); 49 | } 50 | 51 | public void UpdateRootValue() 52 | { 53 | var WorldPosition = TrackedPosition; 54 | 55 | Pop.AllocIfNull (ref Positions); 56 | if (Positions.Count == 0) 57 | Positions.Add (WorldPosition); 58 | 59 | Positions [0] = WorldPosition; 60 | } 61 | 62 | public void PushPosition(Vector4 WorldPosition) 63 | { 64 | Pop.AllocIfNull (ref Positions); 65 | 66 | // only add if significant 67 | if (Positions.Count > 1) { 68 | var DistanceToLastPos = Vector3.Distance (WorldPosition, Positions [1] ); 69 | if (DistanceToLastPos < MinDistanceToPushPosition) { 70 | return; 71 | } 72 | } 73 | 74 | Positions.Insert(0,WorldPosition); 75 | if (Positions.Count > MAX_SPLINE_POINTS) 76 | Positions.RemoveRange (MAX_SPLINE_POINTS, Positions.Count - MAX_SPLINE_POINTS); 77 | 78 | var Positions4 = new Vector3[Positions.Count]; 79 | for (int i = 0; i < Positions.Count; i++) 80 | Positions4 [i] = Positions [i]; 81 | 82 | OnPositionsChanged.Invoke (Positions4); 83 | } 84 | 85 | Material GetSplineMaterial() 86 | { 87 | try 88 | { 89 | var mr = GetComponent(); 90 | var mat = UseSharedMaterial ? mr.sharedMaterial : mr.material; 91 | if ( mat != null ) 92 | return mat; 93 | } 94 | catch{ 95 | } 96 | 97 | try 98 | { 99 | var mr = GetComponent(); 100 | var mat = UseSharedMaterial ? mr.sharedMaterial : mr.material; 101 | if ( mat != null ) 102 | return mat; 103 | } 104 | catch{ 105 | } 106 | 107 | return null; 108 | } 109 | 110 | void OnEnable() 111 | { 112 | Positions = null; 113 | } 114 | 115 | void UpdateMaterial() 116 | { 117 | var Points = new Vector4[MAX_SPLINE_POINTS]; 118 | Positions.CopyTo( Points ); 119 | 120 | var mat = SplineMaterial; 121 | if (mat != null) { 122 | mat.SetVectorArray (WorldPositionsUniform, Points); 123 | mat.SetInt (WorldPositionsCountUniform, Positions.Count); 124 | } 125 | } 126 | 127 | void Update () 128 | { 129 | UpdateRootValue (); 130 | 131 | if (AutoTrack) 132 | RecordPosition (); 133 | 134 | UpdateMaterial (); 135 | } 136 | 137 | void OnDrawGizmos() 138 | { 139 | if ( Positions != null && Positions.Count > 0 ) 140 | { 141 | Gizmos.color = Color.yellow; 142 | 143 | var Points = new List (); 144 | var Radius = SplineMaterial.HasProperty("Radius") ? SplineMaterial.GetFloat("Radius") : Debug_Radius; 145 | 146 | foreach (var Pos in Positions) { 147 | var WorldPos = Pos; 148 | Points.Add (WorldPos); 149 | } 150 | 151 | Gizmos.DrawWireSphere (Points[0], Radius); 152 | for ( int i=1; i where KEY : class 15 | { 16 | List _Values = new List(); 17 | List _Keys = new List(); 18 | 19 | public int Count { get { return _Keys.Count; } } 20 | public List Keys { get { return _Keys; } } 21 | 22 | 23 | public int GetKeyIndex(KEY Key) 24 | { 25 | for (int i = 0; i < Keys.Count; i++) 26 | if (Keys [i] == Key) 27 | return i; 28 | return -1; 29 | } 30 | 31 | public VALUE this[int KeyIndex] 32 | { 33 | get { return _Values[KeyIndex]; } 34 | set { _Values[KeyIndex] = value; } 35 | } 36 | 37 | public VALUE this[KEY Key] 38 | { 39 | get { return _Values[GetKeyIndex(Key)]; } 40 | set { _Values[GetKeyIndex(Key)] = value; } 41 | } 42 | 43 | public bool ContainsKey(KEY Key) 44 | { 45 | return GetKeyIndex (Key) != -1; 46 | } 47 | 48 | public void Add(KEY Key,VALUE Value) 49 | { 50 | _Values.Add (Value); 51 | _Keys.Add (Key); 52 | } 53 | }; 54 | 55 | 56 | -------------------------------------------------------------------------------- /StackedDictionary.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 27d220f57c66c4a068005cfc0ea5f828 3 | timeCreated: 1483960549 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SteamvrSettings.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e968f77814dcf54b9a7da5f094407c8 3 | timeCreated: 1493303337 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Stereo360.shader: -------------------------------------------------------------------------------- 1 | Shader "New Chromantics/Stereo360" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | [Toggle(ENABLE_STEREO)] _Stereo("Enable Stereo", Float) = 0 7 | 8 | [KeywordEnum(IsCamera,IsLocalOrigin)]EyePosition("EyePosition",float) = 0 9 | LocalYOffset("LocalYOffset", Range(-10,10) ) = 0 10 | } 11 | SubShader 12 | { 13 | Tags { "RenderType"="Opaque" } 14 | LOD 100 15 | Cull Off 16 | 17 | Pass 18 | { 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | 23 | #include "UnityCG.cginc" 24 | #include "PopCommon.cginc" 25 | 26 | // gr: I got these by looking at the debug view of the material inspector. Note caps. 27 | #pragma multi_compile EYEPOSITION_ISCAMERA EYEPOSITION_ISLOCALORIGIN 28 | 29 | float LocalYOffset; 30 | 31 | 32 | float3 GetEyePosition() 33 | { 34 | #if defined(EYEPOSITION_ISCAMERA) 35 | { 36 | return _WorldSpaceCameraPos; 37 | } 38 | #elif defined(EYEPOSITION_ISLOCALORIGIN) 39 | { 40 | float3 LocalPos = float3(0,LocalYOffset,0); 41 | float4 WorldOrigin = mul( unity_ObjectToWorld, float4(LocalPos,1) ); 42 | return (WorldOrigin.xyz / WorldOrigin.w); 43 | } 44 | #else 45 | #error Eye origin not specified 46 | #endif 47 | } 48 | 49 | // global toggle 50 | int LeftEye = 0; 51 | 52 | 53 | 54 | 55 | struct appdata 56 | { 57 | float4 LocalPos : POSITION; 58 | }; 59 | 60 | struct v2f 61 | { 62 | float4 ScreenPos : SV_POSITION; 63 | float3 WorldPos : TEXCOORD1; 64 | }; 65 | 66 | sampler2D _MainTex; 67 | half4 _Stereo; 68 | float4 _MainTex_ST; 69 | 70 | bool IsStereoLeftEye() 71 | { 72 | return (LeftEye!=0) ? true : false; 73 | } 74 | 75 | float2 MonoUvToStereoUv(float2 uv) 76 | { 77 | #ifdef ENABLE_STERE0 78 | bool Left = IsStereoLeftEye(); 79 | float minu = Left ? 0 : 0.5f; 80 | float maxu = Left ? 0.5f : 1.0f; 81 | float minv = Left ? 0 : 0; 82 | float maxv = Left ? 1 : 1; 83 | 84 | return float2( lerp(minu,maxu,uv.x), lerp(minv,maxv,uv.y) ); 85 | #else 86 | return uv; 87 | #endif 88 | } 89 | 90 | 91 | v2f vert (appdata v) 92 | { 93 | v2f o; 94 | o.WorldPos = mul( unity_ObjectToWorld, v.LocalPos ); 95 | o.ScreenPos = UnityObjectToClipPos(v.LocalPos); 96 | return o; 97 | } 98 | 99 | 100 | fixed4 frag (v2f i) : SV_Target 101 | { 102 | 103 | float3 ViewDir = GetEyePosition() - i.WorldPos; 104 | float2 EquirectUv = ViewToEquirect( ViewDir ); 105 | 106 | // gr: why upside down? 107 | EquirectUv.y = 1 - EquirectUv.y; 108 | 109 | EquirectUv = MonoUvToStereoUv( EquirectUv ); 110 | float4 Colour = tex2D( _MainTex, EquirectUv ); 111 | 112 | return Colour; 113 | } 114 | ENDCG 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Stereo360.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 016cb2a819e2a496cbad208596114fc2 3 | timeCreated: 1492108292 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /TextureBlitChain.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | public class TextureBlitChain : MonoBehaviour { 6 | 7 | public List mShaders; 8 | 9 | public void Execute (RenderTexture mInput,RenderTexture mOutput) 10 | { 11 | if (!mInput || !mOutput) 12 | return; 13 | 14 | RenderTexture BufferIn = RenderTexture.GetTemporary (mInput.width, mInput.height, mInput.depth, mInput.format); 15 | RenderTexture BufferOut = RenderTexture.GetTemporary (mInput.width, mInput.height, mInput.depth, mInput.format); 16 | Graphics.Blit (mInput, BufferOut); 17 | 18 | for (int i=0; i {} 9 | 10 | 11 | -------------------------------------------------------------------------------- /UnityEventsSpecialised.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 064a03a8b4c2240739a8f321e0109ec5 3 | timeCreated: 1478457990 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /VideoPlayerUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f9f3a80f9cd54005b1b95bb4ba39ba7 3 | timeCreated: 1493813980 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /WebCameraNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | using System.Reflection; 8 | #endif 9 | 10 | 11 | 12 | [System.AttributeUsage(System.AttributeTargets.Field)] 13 | public class WebCamNameAttribute : PropertyAttribute 14 | { 15 | } 16 | 17 | 18 | 19 | #if UNITY_EDITOR 20 | [CustomPropertyDrawer(typeof(WebCamNameAttribute))] 21 | public class WebCamNameAttributePropertyDrawer : PropertyDrawer 22 | { 23 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 24 | { 25 | var Attrib = (WebCamNameAttribute)attribute; 26 | var TargetObject = property.serializedObject.targetObject; 27 | 28 | var WebCamName = property.stringValue; 29 | 30 | EditorGUI.BeginChangeCheck(); 31 | 32 | var Options = new List(); 33 | var OtherIndex = Options.Count; 34 | var OtherLabel = "Custom..."; 35 | Options.Add(OtherLabel); 36 | int SelectedIndex = OtherIndex; 37 | var Devices = WebCamTexture.devices; 38 | foreach (var Device in Devices) 39 | { 40 | if (WebCamName.Equals(Device.name)) 41 | SelectedIndex = Options.Count; 42 | Options.Add(Device.name); 43 | } 44 | 45 | 46 | position.height = base.GetPropertyHeight(property, label); 47 | 48 | var WasMatch = (SelectedIndex != OtherIndex); 49 | SelectedIndex = EditorGUI.Popup(position, property.displayName, SelectedIndex, Options.ToArray()); 50 | 51 | if (SelectedIndex == OtherIndex) 52 | { 53 | // need to reset the label if it changed, otherwise it'll revert back to a selection again 54 | if ( WasMatch ) 55 | WebCamName = ""; 56 | position.y += position.height; 57 | WebCamName = EditorGUI.TextField(position, OtherLabel, WebCamName); 58 | } 59 | else 60 | { 61 | WebCamName = Options[SelectedIndex]; 62 | } 63 | 64 | if (EditorGUI.EndChangeCheck()) 65 | { 66 | property.stringValue = WebCamName; 67 | } 68 | 69 | 70 | property.serializedObject.ApplyModifiedProperties(); 71 | } 72 | 73 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) 74 | { 75 | var OrigHeight = base.GetPropertyHeight(property, label); 76 | return OrigHeight * 2; 77 | } 78 | } 79 | #endif 80 | 81 | 82 | -------------------------------------------------------------------------------- /WebCameraNameAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfaa7cd29d2004aa988a1ab2ac314fcc 3 | timeCreated: 1521048591 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /WorldSpaceLaserGrid.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 4 | 5 | Shader "NewChromantics/WorldSpaceLaserGrid" 6 | { 7 | Properties 8 | { 9 | _MainTex ("Texture", 2D) = "white" {} 10 | GridSize("GridSize", Range(0,10) ) = 0.5 11 | LineWidth("LineWidth", Range(0,1) ) = 0.1 12 | LineColour("LineColour", COLOR ) = (0,1,0) 13 | } 14 | SubShader 15 | { 16 | Tags { "RenderType"="Opaque" } 17 | LOD 100 18 | Cull off 19 | 20 | Pass 21 | { 22 | CGPROGRAM 23 | #pragma vertex vert 24 | #pragma fragment frag 25 | 26 | #include "UnityCG.cginc" 27 | 28 | struct appdata 29 | { 30 | float4 vertex : POSITION; 31 | }; 32 | 33 | struct v2f 34 | { 35 | float4 vertex : SV_POSITION; 36 | float4 WorldSpace : TEXCOORD1; 37 | }; 38 | 39 | sampler2D _MainTex; 40 | float4 _MainTex_ST; 41 | 42 | float GridSize; 43 | float LineWidth; 44 | float4 LineColour; 45 | 46 | v2f vert (appdata v) 47 | { 48 | v2f o; 49 | o.vertex = UnityObjectToClipPos(v.vertex); 50 | o.WorldSpace = mul(unity_ObjectToWorld,v.vertex); 51 | return o; 52 | } 53 | 54 | fixed4 frag (v2f i) : SV_Target 55 | { 56 | float3 World = i.WorldSpace.xyz; 57 | float3 Grid; 58 | float temp; 59 | 60 | Grid.x = fmod( World.x, GridSize ); 61 | Grid.y = fmod( World.y, GridSize ); 62 | Grid.z = fmod( World.z, GridSize ); 63 | Grid = abs(Grid); 64 | 65 | if ( Grid.x < LineWidth || Grid.y < LineWidth || Grid.z < LineWidth ) 66 | return LineColour; 67 | discard; 68 | return 1; 69 | } 70 | ENDCG 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /WorldSpaceLaserGrid.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9b511cfa951944c949fbb21d14095920 3 | timeCreated: 1478457991 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /WwwCache.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System; 4 | using System.IO; 5 | 6 | public class WwwCache 7 | { 8 | static string GetCachePath() 9 | { 10 | // gr: \ actually doesn't work on windows for file: urls ... so can't use the proper seperator 11 | var Seperator = '/'; 12 | //var Seperator = System.IO.Path.DirectorySeparatorChar; 13 | return Application.persistentDataPath + Seperator; 14 | } 15 | 16 | static string strToBase64(string str) { 17 | byte[] byt = System.Text.Encoding.UTF8.GetBytes(str); 18 | return Convert.ToBase64String(byt); 19 | } 20 | 21 | static string base64ToStr(string base64) { 22 | byte[] b = Convert.FromBase64String(base64); 23 | #if UNITY_WSA 24 | return System.Text.Encoding.UTF8.GetString(b,0,b.Length); 25 | #else 26 | return System.Text.Encoding.UTF8.GetString(b); 27 | #endif 28 | } 29 | 30 | static string urlToCachePath(string url) { 31 | return GetCachePath() + strToBase64(url); 32 | } 33 | 34 | public static bool HasCache(string url) { 35 | return File.Exists(urlToCachePath(url)); 36 | } 37 | 38 | public static void WriteCache(WWW www) 39 | { 40 | // skip if url in cached path 41 | var CachePrefix = PopUrl.MakeFileUrl( GetCachePath() ); 42 | if (www.url.StartsWith ( CachePrefix ) ) 43 | return; 44 | 45 | try 46 | { 47 | var CachePath = urlToCachePath (www.url); 48 | File.WriteAllBytes( CachePath, www.bytes); 49 | Debug.Log ("Wrote " + www.url + " cache to " + CachePath); 50 | } 51 | catch(System.Exception e) 52 | { 53 | Debug.LogError ("Failed to write cache (" + www.url + "); " + e.Message); 54 | } 55 | } 56 | 57 | // returns cached url if the file is there 58 | public static string GetCachedUrl(string url) 59 | { 60 | // if url is local, no cache 61 | if (PopUrl.IsLocalUrl (url)) 62 | return url; 63 | 64 | string path = urlToCachePath(url); 65 | if ( !File.Exists(path) ) 66 | { 67 | //Debug.LogWarning("dont have cache url:"+url); 68 | return url; 69 | } 70 | 71 | return PopUrl.MakeFileUrl (path); 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /WwwCache.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1cc00dfb2d1744d9b0cbce212f472f6 3 | timeCreated: 1475091555 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.newchromantics.popunitycommon", 3 | "version": "0.0.1", 4 | "displayName": "PopUnityCommon", 5 | "description": "Graham's Old Unity Utils.", 6 | "author": 7 | { 8 | "name" : "New Chromantics", 9 | "url" : "http://newchromantics.com/" 10 | }, 11 | "unity": "2019.4" 12 | } 13 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a0cf6665f2b9043e78af215372dbbcc4 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Well this repository got out of hand. 2 | 3 | Collection of scripts, exporters, extensions, attributes, editor tools. 4 | 5 | Will split this up soon. 6 | 7 | Currently going through a refactor and putting things in `Pop.` namespace (Currently `PopX.` as there's a static class called pop at the moment) 8 | -------------------------------------------------------------------------------- /readme.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 737e9d4ec0a944fa99675b8052473e7b 3 | timeCreated: 1523893337 4 | licenseType: Free 5 | TextScriptImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | --------------------------------------------------------------------------------