diff --git a/Materials.meta b/Materials.meta new file mode 100644 index 0000000..d0db19e --- /dev/null +++ b/Materials.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 9c13e9266c2d4ed4d9dfe8d643b19d09 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Materials/UIImageCropMaterial.mat b/Materials/UIImageCropMaterial.mat new file mode 100644 index 0000000..c1fa6e7 Binary files /dev/null and b/Materials/UIImageCropMaterial.mat differ diff --git a/Materials/UIImageCropMaterial.mat.meta b/Materials/UIImageCropMaterial.mat.meta new file mode 100644 index 0000000..649017b --- /dev/null +++ b/Materials/UIImageCropMaterial.mat.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: 7919197bf9b9d854fa3b0b0c116c2152 +NativeFormatImporter: + userData: diff --git a/Scripts/Primitives.meta b/Scripts/Primitives.meta new file mode 100644 index 0000000..a2295eb --- /dev/null +++ b/Scripts/Primitives.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: f657b7093c5ea7b42897453c086b7cef +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/UIImageCrop.cs b/Scripts/UIImageCrop.cs new file mode 100644 index 0000000..22538ae --- /dev/null +++ b/Scripts/UIImageCrop.cs @@ -0,0 +1,63 @@ +/// Credit 00christian00 +/// Sourced from - http://forum.unity3d.com/threads/any-way-to-show-part-of-an-image-without-using-mask.360085/#post-2332030 + + +namespace UnityEngine.UI.Extensions +{ + [AddComponentMenu("UI/Extensions/UIImageCrop")] + [ExecuteInEditMode] + [RequireComponent(typeof(RectTransform))] + public class UIImageCrop : MonoBehaviour + { + MaskableGraphic mGraphic; + Material mat; + int XCropProperty, YCropProperty; + public float XCrop = 0f; + public float YCrop = 0f; + + + // Use this for initialization + void Start() + { + + SetMaterial(); + } + public void SetMaterial() + { + mGraphic = this.GetComponent(); + XCropProperty = Shader.PropertyToID("_XCrop"); + YCropProperty = Shader.PropertyToID("_YCrop"); + if (mGraphic != null) + { + mat = mGraphic.material; + + } + else Debug.LogError("Please attach a UI component"); + } + public void OnValidate() + { + SetMaterial(); + SetXCrop(XCrop); + SetYCrop(YCrop); + } + /// + /// Set the x crop factor, with x being a normalized value 0-1f. + /// + /// + public void SetXCrop(float xcrop) + { + XCrop = Mathf.Clamp01(xcrop); + mat.SetFloat(XCropProperty, XCrop); + } + + /// + /// Set the y crop factor, with y being a normalized value 0-1f. + /// + /// + public void SetYCrop(float ycrop) + { + YCrop = Mathf.Clamp01(ycrop); + mat.SetFloat(YCropProperty, YCrop); + } + } +} \ No newline at end of file diff --git a/Scripts/UIImageCrop.cs.meta b/Scripts/UIImageCrop.cs.meta new file mode 100644 index 0000000..ac959b0 --- /dev/null +++ b/Scripts/UIImageCrop.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 022c3983095dce44c9504739a8ed7324 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Shaders.meta b/Shaders.meta new file mode 100644 index 0000000..d4a4df4 --- /dev/null +++ b/Shaders.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: 0873351fdb3a65f43901b3ec088375b0 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Shaders/UIImageCrop.shader b/Shaders/UIImageCrop.shader new file mode 100644 index 0000000..c225403 --- /dev/null +++ b/Shaders/UIImageCrop.shader @@ -0,0 +1,67 @@ +/// Credit 00christian00 +/// Sourced from - http://forum.unity3d.com/threads/any-way-to-show-part-of-an-image-without-using-mask.360085/#post-2332030 + +Shader "UI Extensions/UI Image Crop" { + Properties + { + _MainTex ("Base (RGB)", 2D) = "white" {} + + _XCrop ("X Crop", Range(0.0,1.0)) = 1 + _YCrop ("Y Crop", Range(0.0,1.0)) = 1 + } + + SubShader { + + ZWrite Off + Tags + { + "Queue" = "Transparent" + "RenderType" = "Transparent" + "IgnoreProjector" = "True" + } + Blend SrcAlpha OneMinusSrcAlpha + + Pass { + + CGPROGRAM + + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + + struct v2f { + float4 pos : POSITION; + fixed4 color : COLOR; + float2 uv : TEXCOORD0; //UV1 coord + }; + + uniform sampler2D _MainTex; + float4 _MainTex_ST; + uniform float _XCrop; + uniform float _YCrop; + + v2f vert (v2f v) + { + + v2f o; + o.color=v.color; + o.color.a=0.1; + o.pos = mul (UNITY_MATRIX_MVP, v.pos); + + o.uv=TRANSFORM_TEX(v.uv, _MainTex); + + return o; + } + fixed4 frag (v2f i) : COLOR + { + + //return fixed4(0.25,0,0,1); + i.color.a=step(i.uv.x,_XCrop); + //I don't like the bottom up ordering,so I reverse it + i.color.a=i.color.a*step(1-i.uv.y,_YCrop); + return i.color * tex2D (_MainTex, i.uv); + } + ENDCG + } + } +} diff --git a/Shaders/UIImageCrop.shader.meta b/Shaders/UIImageCrop.shader.meta new file mode 100644 index 0000000..583a0f6 --- /dev/null +++ b/Shaders/UIImageCrop.shader.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: ccf5a0c8f87d3c547aff3daecb3164a4 +ShaderImporter: + defaultTextures: [] + userData: