diff --git a/Editor/CompressionTests.cs b/Editor/CompressionTests.cs deleted file mode 100644 index 1eebdb2..0000000 --- a/Editor/CompressionTests.cs +++ /dev/null @@ -1,219 +0,0 @@ -#if UNITY_5_3_OR_NEWER -using NUnit.Framework; -using System; -using System.IO; -using System.Linq; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; -using System.Text; -using UnityEngine; -using UnityEngine.UI.Extensions; - -public class CompressionTests { - - [Test] - public void RandomGUIDCompressionTestLength() - { - string x = string.Empty; - using (var sequence = Enumerable.Range(1, 100).GetEnumerator()) - { - while(sequence.MoveNext()) // string length 3600 - { - x += Guid.NewGuid(); - } - } - - byte[] byteText = Encoding.Unicode.GetBytes(x); - var compressed = CLZF2.Compress(byteText); - var decompressed = CLZF2.Decompress(compressed); - - Assert.AreEqual(byteText.Length, decompressed.Length); - - } - - [Test] - public void RandomGUIDCompressionTestBytes() - { - string x = string.Empty; - using (var sequence = Enumerable.Range(1, 100).GetEnumerator()) - { - while (sequence.MoveNext()) // string length 3600 - { - x += Guid.NewGuid(); - } - } - - byte[] byteText = Encoding.Unicode.GetBytes(x); - var compressed = CLZF2.Compress(byteText); - var decompressed = CLZF2.Decompress(compressed); - - Assert.AreEqual(byteText, decompressed); - } - - [Test] - public void RandomGUIDCompressionTestString() - { - string x = string.Empty; - using (var sequence = Enumerable.Range(1, 100).GetEnumerator()) - { - while (sequence.MoveNext()) // string length 3600 - { - x += Guid.NewGuid(); - } - } - - byte[] byteText = Encoding.Unicode.GetBytes(x); - var compressed = CLZF2.Compress(byteText); - var decompressed = CLZF2.Decompress(compressed); - var outString = Encoding.Unicode.GetString(decompressed); - - Assert.AreEqual(outString, x); - } - - [Test] - public void ThousandCharacterCompressionTest() - { - var x = new string('X', 10000); - byte[] byteText = Encoding.Unicode.GetBytes(x); - byte[] compressed = CLZF2.Compress(byteText); - byte[] decompressed = CLZF2.Decompress(compressed); - var outString = Encoding.Unicode.GetString(decompressed); - - Assert.AreEqual(byteText.Length, decompressed.Length); - Assert.AreEqual(byteText, decompressed); - Assert.AreEqual(outString, x); - } - - [Test] - public void LongFormattedStringCompressionTest() - { - string longstring = "defined input is deluciously delicious.14 And here and Nora called The reversal from ground from here and executed with touch the country road, Nora made of, reliance on, can’t publish the goals of grandeur, said to his book and encouraging an envelope, and enable entry into the chryssial shimmering of hers, so God of information in her hands Spiros sits down the sign of winter? —It’s kind of Spice Christ. It is one hundred birds circle above the text: They did we said. 69 percent dead. Sissy Cogan’s shadow. —Are you x then sings.) I’m 96 percent dead humanoid figure,"; - byte[] byteText = Encoding.Unicode.GetBytes(longstring); - byte[] compressed = CLZF2.Compress(byteText); - byte[] decompressed = CLZF2.Decompress(compressed); - var outString = Encoding.Unicode.GetString(decompressed); - - Assert.AreEqual(byteText.Length, decompressed.Length); - Assert.AreEqual(byteText, decompressed); - Assert.AreEqual(outString, longstring); - } - - [Test] - public void SavingSimpleObject() - { - Vector3[] MySaveItem = new Vector3[1000]; - for (int i = 0; i < MySaveItem.Length; i++) - { - MySaveItem[i] = Vector3.one * i; - } - var mySaveObject = ObjectToByteArray(MySaveItem); - byte[] compressed = CLZF2.Compress(mySaveObject); - byte[] decompressed = CLZF2.Decompress(compressed); - var outSaveObject = ObjectToByteArray(decompressed); - - Assert.AreEqual(mySaveObject.Length, decompressed.Length); - Assert.AreEqual(mySaveObject, decompressed); - Assert.AreEqual(outSaveObject, MySaveItem); - } - - [Test] - public void SavingComplexObject() - { - MyComplexObject[] MySaveItem = new MyComplexObject[1000]; - for (int i = 0; i < MySaveItem.Length; i++) - { - var item = new MyComplexObject(); - item.myPosition = Vector3.one * i; - item.myPositionHistory = new Vector3[100]; - item.myChatHistory = new string[100]; - for (int j = 0; j < 100; j++) - { - item.myPositionHistory[j] = Vector3.one * j; - item.myChatHistory[j] = "Chat line: " + j; - } - } - var mySaveObject = ObjectToByteArray(MySaveItem); - byte[] compressed = CLZF2.Compress(mySaveObject); - byte[] decompressed = CLZF2.Decompress(compressed); - var outSaveObject = ObjectToByteArray(decompressed); - - Assert.AreEqual(mySaveObject.Length, decompressed.Length); - Assert.AreEqual(mySaveObject, decompressed); - Assert.AreEqual(outSaveObject, MySaveItem); - } - - [Serializable] - struct MyComplexObject - { - public Vector3 myPosition; - public Vector3[] myPositionHistory; - public string[] myChatHistory; - } - - byte[] ObjectToByteArray(object obj) - { - if (obj == null) - return null; - BinaryFormatter bf = new BinaryFormatter(); - // 1. Construct a SurrogateSelector object - SurrogateSelector ss = new SurrogateSelector(); - // 2. Add the ISerializationSurrogates to our new SurrogateSelector - AddSurrogates(ref ss); - // 3. Have the formatter use our surrogate selector - bf.SurrogateSelector = ss; - - using (MemoryStream ms = new MemoryStream()) - { - bf.Serialize(ms, obj); - return ms.ToArray(); - } - } - - T ObjectToByteArray(byte[] arrBytes) - { - if (arrBytes == null) - return default(T); - - using (MemoryStream memStream = new MemoryStream()) - { - BinaryFormatter bf = new BinaryFormatter(); - // 1. Construct a SurrogateSelector object - SurrogateSelector ss = new SurrogateSelector(); - // 2. Add the ISerializationSurrogates to our new SurrogateSelector - AddSurrogates(ref ss); - // 3. Have the formatter use our surrogate selector - bf.SurrogateSelector = ss; - memStream.Write(arrBytes, 0, arrBytes.Length); - memStream.Seek(0, SeekOrigin.Begin); - T obj = (T)bf.Deserialize(memStream); - - return obj; - } - } - - private static void AddSurrogates(ref SurrogateSelector ss) - { - Vector2Surrogate Vector2_SS = new Vector2Surrogate(); - ss.AddSurrogate(typeof(Vector2), - new StreamingContext(StreamingContextStates.All), - Vector2_SS); - Vector3Surrogate Vector3_SS = new Vector3Surrogate(); - ss.AddSurrogate(typeof(Vector3), - new StreamingContext(StreamingContextStates.All), - Vector3_SS); - Vector4Surrogate Vector4_SS = new Vector4Surrogate(); - ss.AddSurrogate(typeof(Vector4), - new StreamingContext(StreamingContextStates.All), - Vector4_SS); - ColorSurrogate Color_SS = new ColorSurrogate(); - ss.AddSurrogate(typeof(Color), - new StreamingContext(StreamingContextStates.All), - Color_SS); - QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate(); - ss.AddSurrogate(typeof(Quaternion), - new StreamingContext(StreamingContextStates.All), - Quaternion_SS); - - } -} -#endif diff --git a/Editor/CompressionTests.cs.meta b/Editor/CompressionTests.cs.meta deleted file mode 100644 index 31b03d5..0000000 --- a/Editor/CompressionTests.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: ff5c7cf8d5ccd284482327cd78debc20 -timeCreated: 1464888738 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Examples/SerialisationExampleScriptsAndClasses.meta b/Examples/SerialisationExampleScriptsAndClasses.meta deleted file mode 100644 index 86be744..0000000 --- a/Examples/SerialisationExampleScriptsAndClasses.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 130e60ba03fb5aa49861fbf664f0f633 -folderAsset: yes -timeCreated: 1435853426 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Examples/SerialisationExampleScriptsAndClasses/SerializeTest.unity b/Examples/SerialisationExampleScriptsAndClasses/SerializeTest.unity deleted file mode 100644 index 5491fb0..0000000 --- a/Examples/SerialisationExampleScriptsAndClasses/SerializeTest.unity +++ /dev/null @@ -1,623 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!29 &1 -SceneSettings: - m_ObjectHideFlags: 0 - m_PVSData: - m_PVSObjectsArray: [] - m_PVSPortalsArray: [] - m_OcclusionBakeSettings: - smallestOccluder: 5 - smallestHole: 0.25 - backfaceThreshold: 100 ---- !u!104 &2 -RenderSettings: - m_ObjectHideFlags: 0 - serializedVersion: 6 - m_Fog: 0 - m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - m_FogMode: 3 - m_FogDensity: 0.01 - m_LinearFogStart: 0 - m_LinearFogEnd: 300 - m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} - m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} - m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} - m_AmbientIntensity: 1 - m_AmbientMode: 0 - m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} - m_HaloStrength: 0.5 - m_FlareStrength: 1 - m_FlareFadeSpeed: 3 - m_HaloTexture: {fileID: 0} - m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} - m_DefaultReflectionMode: 0 - m_DefaultReflectionResolution: 128 - m_ReflectionBounces: 1 - m_ReflectionIntensity: 1 - m_CustomReflection: {fileID: 0} - m_Sun: {fileID: 0} ---- !u!157 &4 -LightmapSettings: - m_ObjectHideFlags: 0 - serializedVersion: 6 - m_GIWorkflowMode: 0 - m_LightmapsMode: 1 - m_GISettings: - serializedVersion: 2 - m_BounceScale: 1 - m_IndirectOutputScale: 1 - m_AlbedoBoost: 1 - m_TemporalCoherenceThreshold: 1 - m_EnvironmentLightingMode: 0 - m_EnableBakedLightmaps: 1 - m_EnableRealtimeLightmaps: 1 - m_LightmapEditorSettings: - serializedVersion: 3 - m_Resolution: 2 - m_BakeResolution: 40 - m_TextureWidth: 1024 - m_TextureHeight: 1024 - m_AOMaxDistance: 1 - m_Padding: 2 - m_CompAOExponent: 0 - m_LightmapParameters: {fileID: 0} - m_TextureCompression: 1 - m_FinalGather: 0 - m_FinalGatherRayCount: 1024 - m_ReflectionCompression: 2 - m_LightingDataAsset: {fileID: 0} - m_RuntimeCPUUsage: 25 ---- !u!196 &5 -NavMeshSettings: - serializedVersion: 2 - m_ObjectHideFlags: 0 - m_BuildSettings: - serializedVersion: 2 - agentRadius: 0.5 - agentHeight: 2 - agentSlope: 45 - agentClimb: 0.4 - ledgeDropHeight: 0 - maxJumpAcrossDistance: 0 - accuratePlacement: 0 - minRegionArea: 2 - cellSize: 0.16666667 - manualCellSize: 0 - m_NavMeshData: {fileID: 0} ---- !u!1 &295572876 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 295572881} - - 33: {fileID: 295572880} - - 135: {fileID: 295572879} - - 23: {fileID: 295572878} - - 114: {fileID: 295572877} - m_Layer: 0 - m_Name: Persistent GameObject - m_TagString: DontDestroy - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &295572877 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 295572876} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: bd4dc9485ec174c44bb7aa7b9d65f7e4, type: 3} - m_Name: - m_EditorClassIdentifier: - showMenu: 0 - usePersistentDataPath: 1 - savePath: 633a2f4d792053617665642047616d65732f ---- !u!23 &295572878 -MeshRenderer: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 295572876} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_Materials: - - {fileID: 10754, guid: 0000000000000000e000000000000000, type: 0} - m_SubsetIndices: - m_StaticBatchRoot: {fileID: 0} - m_UseLightProbes: 1 - m_ReflectionProbeUsage: 1 - m_ProbeAnchor: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 1 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingOrder: 0 ---- !u!135 &295572879 -SphereCollider: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 295572876} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!33 &295572880 -MeshFilter: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 295572876} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &295572881 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 295572876} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 ---- !u!1 &469137979 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 191666, guid: f3b705d54062603418fef7f609535a48, type: 2} - m_PrefabInternal: {fileID: 1984912377} - serializedVersion: 4 - m_Component: - - 4: {fileID: 469137984} - - 33: {fileID: 469137983} - - 136: {fileID: 469137982} - - 23: {fileID: 469137981} - - 114: {fileID: 469137980} - m_Layer: 0 - m_Name: TestObject 2 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &469137980 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 11483362, guid: f3b705d54062603418fef7f609535a48, - type: 2} - m_PrefabInternal: {fileID: 1984912377} - m_GameObject: {fileID: 469137979} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0c19f3e134862e74dbc98cb514a82ef5, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!23 &469137981 -MeshRenderer: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 2343766, guid: f3b705d54062603418fef7f609535a48, - type: 2} - m_PrefabInternal: {fileID: 1984912377} - m_GameObject: {fileID: 469137979} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_SubsetIndices: - m_StaticBatchRoot: {fileID: 0} - m_UseLightProbes: 1 - m_ReflectionProbeUsage: 1 - m_ProbeAnchor: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 1 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingOrder: 0 ---- !u!136 &469137982 -CapsuleCollider: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 13676560, guid: f3b705d54062603418fef7f609535a48, - type: 2} - m_PrefabInternal: {fileID: 1984912377} - m_GameObject: {fileID: 469137979} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - m_Radius: 0.5 - m_Height: 2 - m_Direction: 1 - m_Center: {x: 0, y: 0, z: 0} ---- !u!33 &469137983 -MeshFilter: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 3370042, guid: f3b705d54062603418fef7f609535a48, - type: 2} - m_PrefabInternal: {fileID: 1984912377} - m_GameObject: {fileID: 469137979} - m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &469137984 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - m_PrefabInternal: {fileID: 1984912377} - m_GameObject: {fileID: 469137979} - m_LocalRotation: {x: -0.09426609, y: 0.4054792, z: -0.45864588, w: 0.7850761} - m_LocalPosition: {x: -2.29, y: 0, z: 1.79} - m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 4 ---- !u!1 &574899098 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 574899100} - - 108: {fileID: 574899099} - m_Layer: 0 - m_Name: Directional Light - m_TagString: DontDestroy - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!108 &574899099 -Light: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 574899098} - m_Enabled: 1 - serializedVersion: 6 - m_Type: 1 - m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 1 - m_Range: 10 - m_SpotAngle: 30 - m_CookieSize: 10 - m_Shadows: - m_Type: 2 - m_Resolution: -1 - m_Strength: 1 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_Lightmapping: 4 - m_BounceIntensity: 1 - m_ShadowRadius: 0 - m_ShadowAngle: 0 - m_AreaSize: {x: 1, y: 1} ---- !u!4 &574899100 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 574899098} - m_LocalRotation: {x: 0.40821794, y: -0.23456973, z: 0.109381676, w: 0.87542605} - m_LocalPosition: {x: 0, y: 3, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 1 ---- !u!1 &635294011 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 635294016} - - 20: {fileID: 635294015} - - 92: {fileID: 635294014} - - 124: {fileID: 635294013} - - 81: {fileID: 635294012} - m_Layer: 0 - m_Name: Main Camera - m_TagString: DontDestroy - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!81 &635294012 -AudioListener: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 635294011} - m_Enabled: 1 ---- !u!124 &635294013 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 635294011} - m_Enabled: 1 ---- !u!92 &635294014 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 635294011} - m_Enabled: 1 ---- !u!20 &635294015 -Camera: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 635294011} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844} - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 - m_StereoMirrorMode: 0 ---- !u!4 &635294016 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 635294011} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 ---- !u!1001 &1034211790 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_LocalPosition.x - value: -4.51999998 - objectReference: {fileID: 0} - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_LocalPosition.y - value: 1.69000006 - objectReference: {fileID: 0} - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_LocalPosition.z - value: 3.06999993 - objectReference: {fileID: 0} - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: m_RootOrder - value: 3 - objectReference: {fileID: 0} - - target: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: someGameObject - value: - objectReference: {fileID: 1034211791} - - target: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: testClassArray.Array.data[0].go - value: - objectReference: {fileID: 1034211791} - - target: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - propertyPath: TransformThatWontBeSaved - value: - objectReference: {fileID: 1034211797} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - m_RootGameObject: {fileID: 1034211791} - m_IsPrefabParent: 0 ---- !u!1 &1034211791 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 106558, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - m_PrefabInternal: {fileID: 1034211790} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1034211797} - - 33: {fileID: 1034211796} - - 65: {fileID: 1034211795} - - 23: {fileID: 1034211794} - - 114: {fileID: 1034211793} - - 114: {fileID: 1034211792} - m_Layer: 0 - m_Name: TestObject 1 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1034211792 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 11498422, guid: 6ab4be07dd04115438edfc50dd6ed81e, - type: 2} - m_PrefabInternal: {fileID: 1034211790} - m_GameObject: {fileID: 1034211791} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 693e98742914c7b40b6f0d1b51020e3c, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!114 &1034211793 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 11438930, guid: 6ab4be07dd04115438edfc50dd6ed81e, - type: 2} - m_PrefabInternal: {fileID: 1034211790} - m_GameObject: {fileID: 1034211791} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0c19f3e134862e74dbc98cb514a82ef5, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!23 &1034211794 -MeshRenderer: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 2315152, guid: 6ab4be07dd04115438edfc50dd6ed81e, - type: 2} - m_PrefabInternal: {fileID: 1034211790} - m_GameObject: {fileID: 1034211791} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_SubsetIndices: - m_StaticBatchRoot: {fileID: 0} - m_UseLightProbes: 1 - m_ReflectionProbeUsage: 1 - m_ProbeAnchor: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 1 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingOrder: 0 ---- !u!65 &1034211795 -BoxCollider: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 6552138, guid: 6ab4be07dd04115438edfc50dd6ed81e, - type: 2} - m_PrefabInternal: {fileID: 1034211790} - m_GameObject: {fileID: 1034211791} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} ---- !u!33 &1034211796 -MeshFilter: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 3398618, guid: 6ab4be07dd04115438edfc50dd6ed81e, - type: 2} - m_PrefabInternal: {fileID: 1034211790} - m_GameObject: {fileID: 1034211791} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &1034211797 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 416904, guid: 6ab4be07dd04115438edfc50dd6ed81e, type: 2} - m_PrefabInternal: {fileID: 1034211790} - m_GameObject: {fileID: 1034211791} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -4.52, y: 1.69, z: 3.07} - m_LocalScale: {x: 1, y: 1, z: 1} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 3 ---- !u!1001 &1984912377 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_LocalPosition.x - value: -2.28999996 - objectReference: {fileID: 0} - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_LocalPosition.z - value: 1.78999996 - objectReference: {fileID: 0} - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_LocalRotation.x - value: -.0942660868 - objectReference: {fileID: 0} - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_LocalRotation.y - value: .405479193 - objectReference: {fileID: 0} - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_LocalRotation.z - value: -.45864588 - objectReference: {fileID: 0} - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_LocalRotation.w - value: .785076082 - objectReference: {fileID: 0} - - target: {fileID: 497016, guid: f3b705d54062603418fef7f609535a48, type: 2} - propertyPath: m_RootOrder - value: 4 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: f3b705d54062603418fef7f609535a48, type: 2} - m_RootGameObject: {fileID: 469137979} - m_IsPrefabParent: 0 diff --git a/Examples/SerialisationExampleScriptsAndClasses/SerializeTest.unity.meta b/Examples/SerialisationExampleScriptsAndClasses/SerializeTest.unity.meta deleted file mode 100644 index 61bd66b..0000000 --- a/Examples/SerialisationExampleScriptsAndClasses/SerializeTest.unity.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6eac4e9e69c0f7645b30c39bfa564d95 -timeCreated: 1435852640 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Examples/SerialisationExampleScriptsAndClasses/TestClass.cs b/Examples/SerialisationExampleScriptsAndClasses/TestClass.cs deleted file mode 100644 index c5b2d2d..0000000 --- a/Examples/SerialisationExampleScriptsAndClasses/TestClass.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace UnityEngine.UI.Extensions.Examples -{ - [System.Serializable] - public class TestClass - { - public string myString; - public GameObject go; - public string go_id; - public Vector3 somePosition; - public Color color; - public int[] myArray = new int[] { 2, 43, 12 }; - } -} \ No newline at end of file diff --git a/Examples/SerialisationExampleScriptsAndClasses/TestClass.cs.meta b/Examples/SerialisationExampleScriptsAndClasses/TestClass.cs.meta deleted file mode 100644 index fd4ae59..0000000 --- a/Examples/SerialisationExampleScriptsAndClasses/TestClass.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: e7a05842b3056ca42ac57d79fb273d79 -timeCreated: 1435853431 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Examples/SerialisationExampleScriptsAndClasses/TestScript.cs b/Examples/SerialisationExampleScriptsAndClasses/TestScript.cs deleted file mode 100644 index 7034958..0000000 --- a/Examples/SerialisationExampleScriptsAndClasses/TestScript.cs +++ /dev/null @@ -1,98 +0,0 @@ -namespace UnityEngine.UI.Extensions.Examples -{ - public class TestScript : MonoBehaviour - { - public string testString = "Hello"; - public GameObject someGameObject; - public string someGameObject_id; - public TestClass testClass = new TestClass(); - public TestClass[] testClassArray = new TestClass[2]; - [DontSaveField] public Transform TransformThatWontBeSaved;//The [DontSaveField] attribute we wrote ourselves prevents the field from being included in the packed component data - - public void OnSerialize() - { - //This is an example of a OnSerialize method, called before a gameobject is packed into serializable form. - //In this case, the GameObject variable "someGameObject" and those in the testClass and testclass Array instances of TestClass should be reconstructed after loading. - //Since GameObject (and Transform) references assigned during runtime can't be serialized directly, - //we keep a seperate string variable for each GO variable that holds the ID of the GO instead. - //This allows us to just save the ID instead. - - //This example is one way of dealing with GameObject (and Transform) references. If a lot of those occur in your project, - //it might be more efficient to go directly into the static SaveLoad.PackComponent method. and doing it there. - - if (someGameObject != null && someGameObject.GetComponent()) - { - someGameObject_id = someGameObject.GetComponent().id; - } - else - { - someGameObject_id = null; - } - - if (testClassArray != null) - { - foreach (TestClass testClass_cur in testClassArray) - { - if (testClass_cur.go != null && testClass_cur.go.GetComponent()) - { - testClass_cur.go_id = testClass_cur.go.GetComponent().id; - } - else - { - testClass_cur.go_id = null; - } - } - - } - } - - public void OnDeserialize() - { - - //Since we saved the ID of the GameObject references, we can now use those to recreate the references. - //We just iterate through all the ObjectIdentifier component occurences in the scene, compare their id value to our saved and loaded someGameObject id (etc.) value, - //and assign the component's GameObject if it matches. - //Note that the "break" command is important, both because it elimitates unneccessary iterations, - //and because continuing after having found a match might for some reason find another, wrong match that makes a null reference. - - ObjectIdentifier[] objectsIdentifiers = FindObjectsOfType(typeof(ObjectIdentifier)) as ObjectIdentifier[]; - - if (string.IsNullOrEmpty(someGameObject_id) == false) - { - foreach (ObjectIdentifier objectIdentifier in objectsIdentifiers) - { - - if (string.IsNullOrEmpty(objectIdentifier.id) == false) - { - if (objectIdentifier.id == someGameObject_id) - { - someGameObject = objectIdentifier.gameObject; - break; - } - } - } - } - - if (testClassArray != null) - { - foreach (TestClass testClass_cur in testClassArray) - { - if (string.IsNullOrEmpty(testClass_cur.go_id) == false) - { - foreach (ObjectIdentifier objectIdentifier in objectsIdentifiers) - { - if (string.IsNullOrEmpty(objectIdentifier.id) == false) - { - if (objectIdentifier.id == testClass_cur.go_id) - { - testClass_cur.go = objectIdentifier.gameObject; - break; - } - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/Examples/SerialisationExampleScriptsAndClasses/TestScript.cs.meta b/Examples/SerialisationExampleScriptsAndClasses/TestScript.cs.meta deleted file mode 100644 index ef40583..0000000 --- a/Examples/SerialisationExampleScriptsAndClasses/TestScript.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 693e98742914c7b40b6f0d1b51020e3c -timeCreated: 1435853426 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/README.md b/README.md index 9875db1..e185e28 100644 --- a/README.md +++ b/README.md @@ -1,110 +1,144 @@ -# README # +# README This is an extension project for the new Unity UI system which can be found at: [Unity UI Source](https://bitbucket.org/Unity-Technologies/ui) ------ -#[Supporting the UI Extensions project](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=89L8T9N6BR7LJ)# - -If you wish to support the Unity UI Extensions project itself, then you can using the PayPal link below. -All funds go to support the project, no matter the amount. - -> Donations in code are also extremely welcome :D - -(PayPal account not required and you can remain anonymous if you wish) - -##[>> Donate <<](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=89L8T9N6BR7LJ)## - ------ - -#[Intro](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/GettingStarted)# +# [Intro](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/GettingStarted) For more info, here's a little introduction video for the project: [![View Intro Video](http://img.youtube.com/vi/njoIeE4akq0/0.jpg)](http://www.youtube.com/watch?v=njoIeE4akq0 "Unity UI Extensions intro video") You can follow the UI Extensions team for updates and news on: -### [Twitter](https://twitter.com/search?q=%23unityuiextensions) / [Facebook](https://www.facebook.com/UnityUIExtensions/) / [YouTube](https://www.youtube.com/channel/UCG3gZOkmL-2rmZat4ufv28Q)### +## [Twitter](https://twitter.com/hashtag/UnityUIExtensions?src=hash) / [Facebook](https://www.facebook.com/UnityUIExtensions/) / [YouTube](https://www.youtube.com/channel/UCG3gZOkmL-2rmZat4ufv28Q) -Also, come chat live with the Unity UI Extensions community on Gitter here: -### [UI Extensions Live Chat](https://gitter.im/Unity-UI-Extensions/Lobby) ### +> ## Also, come chat live with the Unity UI Extensions community on Gitter here: [UI Extensions Live Chat](https://gitter.im/Unity-UI-Extensions/Lobby) ----- -#[ What is this repository for? ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/About)# +# [What is this repository for? ](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/About) -In this repository is a collection of extension scripts to enhance your Unity UI experience. These scripts have been gathered from many sources and combined and improved over time. +In this repository is a collection of extension scripts / effects and controls to enhance your Unity UI experience. These scripts have been gathered from many sources, combined and improved over time. > The majority of the scripts came from the Scripts thread on the [Unity UI forum here](http://bit.ly/UnityUIScriptsForumPost) You can either download / fork this project to access the scripts, or you can also download these pre-compiled Unity Assets, chock full of goodness for each release: -#[Download](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)# +# [Download](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Downloads) -The asset has been full tested on all current versions of Unity 5 (for versions prior to Unity 5.3, please see the [archive](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)) +For the 2.0 release, we have expanded where you can download the UnityPackage asset and widened the options to contribute to the project. -* [Unity UI Extensions Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions.unitypackage) +> I will still stress however, ***contribution is optional***. **The asset / code will always remain FREE** -To view previous releases, visit the [release archive](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads) +[![Download from Itch.IO](https://bytebucket.org/UnityUIExtensions/unity-ui-extensions/wiki/SiteImages/itchio.png)](https://unityuiextensions.itch.io/uiextensions2-0 "Download from Itch.IO") +[![Download from Itch.IO](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/SiteImages/unionassets.png)](https://unionassets.com/admin/AssetList "Download from Union Assets") +[![Download from Itch.IO](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/SiteImages/patreon.jpg)](https://www.patreon.com/UnityUIExtensions "Support Unity UI Extensions on Patreon & download") + +> Still available on the [BitBucket site](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/downloads/UnityUIExtensions.unitypackage) if you prefer + +To view previous releases, visit the [release archive](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Downloads) ----- -#[Getting Started](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/GettingStarted)# +# [Supporting the UI Extensions project](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=89L8T9N6BR7LJ) + +If you wish to further support the Unity UI Extensions project itself, then you can either subsidise your downloads above, or contribute direct using the PayPal link below. +All funds go to support the project, no matter the amount, donations in code are also extremely welcome :D + +> (PayPal account not required and you can remain anonymous if you wish) + +## [>> Donate via PayPal <<](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=89L8T9N6BR7LJ) + +----- + +# [Getting Started](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/GettingStarted) To get started with the project, here's a little guide: [![View Getting Started Video](http://img.youtube.com/vi/sVLeYmsNQAI/0.jpg)](http://www.youtube.com/watch?v=sVLeYmsNQAI "Unity UI getting started video") ----- -#[Updates:](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES)# +# [Updates:](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES) -##Update 1.2## -[![View 1.2 update Video](http://img.youtube.com/vi/cWv0A6rEEc8/0.jpg)](https://www.youtube.com/watch?v=cWv0A6rEEc8 "Update 1.2 for the Unity UI Extensions Project") +## Update 2.0 - The update so big they had to name it twice +[![View 2.0 update Video](http://img.youtube.com/vi/Ivzt9_jhGfQ/0.jpg)](https://www.youtube.com/watch?v=Ivzt9_jhGfQ "Update 2.0 for the Unity UI Extensions Project") -###New / updated features### -* Major updates to the Horizontal and Vertical Scroll Snap controls -* Replacement HSV/Color picker control (and new Box Slider control) -* Fixes / updates to the TextPic control -* Updates to SoftAlphaUI script - improved Text / worldspace support -* Updates to Extensions Toggle - Adds ID and event to publish ID on change -* New Gadient control (gradient 2) -* New UI ScrollRect Occlusion utility -* New UI Tween Scale utility -* New UI Infinite ScrollRect -* New Table Layout Group -* New Non Drawing Graphic Control +> Be sure to logon to the new Gitter Chat site for the UI Extensions project, if you have any questions, queries or suggestions +> Much easier that posting a question / issue on YouTube, Twitter or Facebook :D +> ## [UIExtensions Gitter Chanel](https://gitter.im/Unity-UI-Extensions/Lobby) -###Fixes### -* H&V Scroll Snap indexing issues -* H&V Scroll Snap performance updates -* H&V Scroll Snap Long swipe behavior updated -* H&V Scroll Snap support for Rect Resizing -* TextPic Set set before draw issues -* HSV picker replaced with more generic color picker +### New / updated features +* Major updates to the Line renderer for texture and positioning support, inc Editor support +* Line Renderer also includes "dotted" line support and the ability to increase the vertex count +* Reorderable list now also works in Screenspace-Camera & Worldspace +* H&V Scroll Snap controls now support scrollbars +* Minor updates to the Gradient 2 control +* Minor updates to all dropdown controls to manage control startup +* Update UI Particle Renderer with new updates, including Texture Sheet animation support +* New Selectable Scalar +* New MonoSpacing text effect +* New Multi-Touch Scrollrect support +* New UI Grid Renderer (handy if you want a UI grid background) +* New CoolDownButton control (adds a timer between button clicks) +* New Curly UI - for those who like their UI Bendy +* New Fancy Scroll View - A programmatic scroll view +* New UI Line connector control - extends line renderer to draw lines between UI Objects +* New Radial Slider control - for those who like their sliders to curve +* New Stepper control - a +/- control similar to that found on iOS +* New Segmented Control - A button array control similar to that found on iOS +* New UIHighlightable control - just in case the user wasn't sure where they were -###Known issues### -* The Image_Extended control has been removed due to Unity upgrade issues. Will return in a future update. +### Examples / Examples / Examples +Finally added some proper examples, especially for the newer controls. +These can be found in the Examples folder (which can be safely deleted if you wish) -##Upgrade Notes## -Although not specifically required, it is recommended to remove the old UI Extensions folder before importing the new asset -The HSS picker especially had a lot of file changes in this update. +* ColorPicker - shows the Color Picker UI in both SS and WS +* ComboBox - shows all the different combo box controls +* Cooldown - several example implementations of the cooldown button control using Unity image effects and SAUIM +* CurlyUI - shows off the CurlyUI control +* FancyScrollView - the only REAL way to understand this programmatic control (direct from the contributor) +* HSS-VSS-ScrollSnap - several working examples of the HSS/VSS scroll snaps (not ScrollSnap or FancyScrollView), including a full screen variant +* MenuExample - A demo menu implementation showing off the new MenuManager control +* Radial Slider - Just keep on sliding +* ReorderableList - Several examples of the re-orderable list in action, complete with managed drag / drop features +* ScrollConflictManager - Making ScrollRects get along +* SelectionBox - The RTS selector in action, showing examples of selecting 2D and 3D objects +* Serialisation - Unit test case examples for the serialisation components +* TextEffects - All the Text effects and shaders in one easy to view place +* UIlineRenderer - Several demos / examples for using the Line Renderer and UI Line connector controls +* UIVerticalScrollerDemo - A full screen example of a UIVertical Scroller implementation. ->**Note** In Unity 5.5 the particle system was overhauled and several methods were marked for removal. However, the UI Particle System script currently still uses them -> Either ignore these errors or remove the *_UIParticleSystem_* script in the "*Unity UI Extensions / Scripts / Effects*" folder +### Fixes +* H&V Scroll Snap Next/Previous Button interactable handler (only enables when there is a child to move to) +* H&V Scroll Snap Swipe logic updated and now includes scaling support +* Editor options for non-drawing graphic control +* Events in ComboBox, Dropdown and autocomplete controls updated to use UI events +* UIFlippable "Argument out of Range" bigfix (pesky component orders with effects) +* All primitive controls will now redraw when enabled in code +* Autocomplete has two lookup text methods now, Array and Linq +* Line renderer pivot fix (now respects the pivot point) +* TextPic rendering and event updates +* Minor tweaks to the UIParticle system to remove "upgrade" errors. Still needs a rework tbh +* Clean up of all unnecessary usings (swept under the rug) +### Known issues +Serialisation functionality has been removed due to several incompatibilities between platforms, suggest the UniversalSerialiser as an alternative. May bring back if there is demand. (or copy out the source from the previous release) -------------------- -##Release History## +## Upgrade Notes +With this being a major version update, it is recommended to remove the old UI Extensions folder before importing the new asset. + +---------------- +## Release History For the full release history, follow the below link to the full release notes page. -### [Release Notes](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES)### +### [Release Notes](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES) --- -#[Controls and extensions listed in this project](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls):# +# [Controls and extensions listed in this project](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls): There are almost 70+ extension controls / effect and other utilities in the project which are listed on the following page: -##[UI Extensions controls list](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls)## +## [UI Extensions controls list](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls) [Controls](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Controls#markdown-header-controls)||||| ------|------|------|------| @@ -148,9 +182,9 @@ AimerInputModule|GamePadInputModule||| ------|------|------|------| ReturnKeyTrigger|TabNavigation|uGUITools|ScrollRectTweener|ScrollRectLinker ScrollRectEx|UI_InfiniteScroll|UI_ScrollRectOcclusion|UIScrollToSelection|UISelectableExtension -switchToRectTransform|ScrollConflictManager|CLFZ2 (Encryption)|Serialization|DragCorrector -PPIViewer|UI_TweenScale|UI_InfiniteScroll|UI_ScrollRectOcclusion|NonDrawingGraphic -UILineConnector|UIHighlightable|MenuSystem|| +switchToRectTransform|ScrollConflictManager|CLFZ2 (Encryption)|DragCorrector|PPIViewer +UI_TweenScale|UI_InfiniteScroll|UI_ScrollRectOcclusion|NonDrawingGraphic|UILineConnector +UIHighlightable|Menu Manager|Pagination Manager|| |||| *More to come* @@ -158,11 +192,11 @@ UILineConnector|UIHighlightable|MenuSystem|| --- -#[ How do I get set up? ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/GettingStarted)# +# [How do I get set up? ](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/GettingStarted) Either clone / download this repository to your machine and then copy the scripts in, or use the pre-packaged .UnityPackage for your version of Unity and import it as a custom package in to your project. -#[ Contribution guidelines ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/ContributionGuidelines)# +# [Contribution guidelines ](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/ContributionGuidelines) Got a script you want added? Then just fork the bitbucket repository and submit a PR. All contributions accepted (including fixes) Just ensure @@ -170,30 +204,30 @@ Just ensure * The script uses the **Unity.UI.Extensions** namespace so they do not affect any other developments * (optional) Add Component and Editor options where possible (editor options are in the Editor\UIExtensionsMenuOptions.cs file) -#[ License ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/License)# +# [License ](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/License) -All scripts conform to the BSD license and are free to use / distribute. See the [LICENSE](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/License) file for more information +All scripts conform to the BSD license and are free to use / distribute. See the [LICENSE](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/License) file for more information -#[ Like what you see? ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/FurtherInfo)# +# [Like what you see? ](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/FurtherInfo) All these scripts were put together for my latest book Unity3D UI Essentials Check out the [page on my blog](http://bit.ly/Unity3DUIEssentials) for more details and learn all about the inner workings of the new Unity UI System. -#[ The downloads ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)# +# [The downloads ](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Downloads) As this repo was created to support my new Unity UI Title ["Unity 3D UI Essentials"](http://bit.ly/Unity3DUIEssentials), in the downloads section you will find two custom assets (SpaceShip-DemoScene-Start.unitypackage and RollABallSample-Start.unitypackage). These are just here as starter scenes for doing UI tasks in the book. I will add more sample scenes for the UI examples in this repository and detail them above over time. -#[Previous Releases](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)# +# [Previous Releases](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/wiki/Downloads) -* [Unity UI Extensions Unity 4.x Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-4.x.unitypackage) +* [Unity UI Extensions Unity 4.x Asset](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/downloads/UnityUIExtensions-4.x.unitypackage) -* [Unity UI Extensions Unity 5.1 Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-5.1.unitypackage) +* [Unity UI Extensions Unity 5.1 Asset](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/downloads/UnityUIExtensions-5.1.unitypackage) -* [Unity UI Extensions Unity 5.2 Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-5.2.unitypackage) <- 5.2.0 - 5.2.1 base releases ONLY +* [Unity UI Extensions Unity 5.2 Asset](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/downloads/UnityUIExtensions-5.2.unitypackage) <- 5.2.0 - 5.2.1 base releases ONLY -* [Unity UI Extensions Unity 5.3 (5.2.1P+) Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-5.3.unitypackage) <- use this for 5.2.1P+ releases +* [Unity UI Extensions Unity 5.3 (5.2.1P+) Asset](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/downloads/UnityUIExtensions-5.3.unitypackage) <- use this for 5.2.1P+ releases > **Note** To retain 5.2 compatibility in the 5.3 package, you will see two warnings related to: > ``` diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b81f236..285bf77 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -2,10 +2,80 @@ This file contains the up to date release notes for each release of the UI Extensions project including release videos where required. ---------------- -##Update 1.2## +## Update 2.0 - The update so big they had to name it twice +[![View 2.0 update Video](http://img.youtube.com/vi/Ivzt9_jhGfQ/0.jpg)](https://www.youtube.com/watch?v=Ivzt9_jhGfQ "Update 2.0 for the Unity UI Extensions Project") + +> Be sure to logon to the new Gitter Chat site for the UI Extensions project, if you have any questions, queries or suggestions +> +> Much easier that posting a question / issue on YouTube, Twitter or Facebook :D +> +> ## [UIExtensions Gitter Chanel](https://gitter.im/Unity-UI-Extensions/Lobby) + +### New / updated features +* Major updates to the Line renderer for texture and positioning support, inc Editor support +* Line Renderer also includes "dotted" line support and the ability to increase the vertex count +* Reorderable list now also works in Screenspace-Camera & Worldspace +* H&V Scroll Snap controls now support scrollbars +* Minor updates to the Gradient 2 control +* Minor updates to all dropdown controls to manage control startup +* Update UI Particle Renderer with new updates, including Texture Sheet animation support +* New Selectable Scalar +* New MonoSpacing text effect +* New Multi-Touch Scrollrect support +* New UI Grid Renderer (handy if you want a UI grid background) +* New CoolDownButton control (adds a timer between button clicks) +* New Curly UI - for those who like their UI Bendy +* New Fancy Scroll View - A programmatic scroll view +* New UI Line connector control - extends line renderer to draw lines between UI Objects +* New Radial Slider control - for those who like their sliders to curve +* New Stepper control - a +/- control similar to that found on iOS +* New Segmented Control - A button array control similar to that found on iOS +* New UIHighlightable control - just in case the user wasn't sure where they were + +### Examples / Examples / Examples +Finally added some proper examples, especially for the newer controls. +These can be found in the Examples folder (which can be safely deleted if you wish) + +* ColorPicker - shows the Color Picker UI in both SS and WS +* ComboBox - shows all the different combo box controls +* Cooldown - several example implementations of the cooldown button control using Unity image effects and SAUIM +* CurlyUI - shows off the CurlyUI control +* FancyScrollView - the only REAL way to understand this programmatic control (direct from the contributor) +* HSS-VSS-ScrollSnap - several working examples of the HSS/VSS scroll snaps (not ScrollSnap or FancyScrollView), including a full screen variant +* MenuExample - A demo menu implementation showing off the new MenuManager control +* Radial Slider - Just keep on sliding +* ReorderableList - Several examples of the re-orderable list in action, complete with managed drag / drop features +* ScrollConflictManager - Making ScrollRects get along +* SelectionBox - The RTS selector in action, showing examples of selecting 2D and 3D objects +* Serialisation - Unit test case examples for the serialisation components +* TextEffects - All the Text effects and shaders in one easy to view place +* UIlineRenderer - Several demos / examples for using the Line Renderer and UI Line connector controls +* UIVerticalScrollerDemo - A full screen example of a UIVertical Scroller implementation. + +### Fixes +* H&V Scroll Snap Next/Previous Button interactable handler (only enables when there is a child to move to) +* H&V Scroll Snap Swipe logic updated and now includes scaling support +* Editor options for non-drawing graphic control +* Events in ComboBox, Dropdown and autocomplete controls updated to use UI events +* UIFlippable "Argument out of Range" bigfix (pesky component orders with effects) +* All primitive controls will now redraw when enabled in code +* Autocomplete has two lookup text methods now, Array and Linq +* Line renderer pivot fix (now respects the pivot point) +* TextPic rendering and event updates +* Minor tweaks to the UIParticle system to remove "upgrade" errors. Still needs a rework tbh +* Clean up of all unnecessary usings (swept under the rug) + +### Known issues +Serialisation functionality has been removed due to several incompatibilities between platforms, suggest the UniversalSerialiser as an alternative. May bring back if there is demand. (or copy out the source from the previous release) + +## Upgrade Notes +With this being a major version update, it is recommended to remove the old UI Extensions folder before importing the new asset. + +---------------- +## Update 1.2 [![View 1.2 update Video](http://img.youtube.com/vi/cWv0A6rEEc8/0.jpg)](https://www.youtube.com/watch?v=cWv0A6rEEc8 "Update 1.2 for the Unity UI Extensions Project") -###New / updated features### +### New / updated features * Major updates to the Horizontal and Vertical Scroll Snap controls * Replacement HSV/Color picker control (and new Box Slider control) * Fixes / updates to the TextPic control @@ -16,9 +86,8 @@ This file contains the up to date release notes for each release of the UI Exten * New UI Tween Scale utility * New UI Infinite ScrollRect * New Table Layout Group -* New Non Drawing Graphic Control -###Fixes### +### Fixes * H&V Scroll Snap indexing issues * H&V Scroll Snap performance updates * H&V Scroll Snap Long swipe behavior updated @@ -26,10 +95,10 @@ This file contains the up to date release notes for each release of the UI Exten * TextPic Set set before draw issues * HSV picker replaced with more generic color picker -###Known issues### +### Known issues * The Image_Extended control has been removed due to Unity upgrade issues. Will return in a future update. -##Upgrade Notes## +## Upgrade Notes Although not specifically required, it is recommended to remove the old UI Extensions folder before importing the new asset The HSS picker especially had a lot of file changes in this update. @@ -37,13 +106,13 @@ The HSS picker especially had a lot of file changes in this update. > Either ignore these errors or remove the *_UIParticleSystem_* script in the "*Unity UI Extensions / Scripts / Effects*" folder ---------------- -##Update 1.1## +## Update 1.1 [![View 1.1 update Video](http://img.youtube.com/vi/JuE0ja5DmV4/0.jpg)](https://www.youtube.com/watch?v=JuE0ja5DmV4 "Update 1.1 for the Unity UI Extensions Project") > **Note** for 4.6 / 5.1, some features will not be available due to their incompatibility. > Also the Line Renderer remains unchanged in these releases as the updates do not work with the older system -###New / updated features### +### New / updated features * New Polygon primitive * New UI Vertical Scroller control * New Curved layout component @@ -56,24 +125,24 @@ The HSS picker especially had a lot of file changes in this update. * Added some script helper functions for LZF compression and Serialization * Two utilities to help manage drag thresholds on high PPI systems -###Fixes### +### Fixes * Line Render almost completely re-written with tons of fixes * Radial layout updated to avoid 360 overlap (first and last) * Scroll Snaps updates to better handle children. * Scroll Snaps distribute function updated so it can be called onDirty more efficiently. -##Upgrade Notes## +## Upgrade Notes Two scripts were moved and need their originals need deleting post upgrade. Please remove the following files: * Scripts\ImageExtended * Scripts\UIImageCrop ---------------- -##Update 1.0.6.1## +## Update 1.0.6.1 - Minor update to enhance soft alpha mask and add cylinder text plus a fix to letter spacing ---------------- -##Update 1.0.6## +## Update 1.0.6 [![View 1.0.6 update Video](http://img.youtube.com/vi/jpyFiRvSmbg/0.jpg)](http://www.youtube.com/watch?v=jpyFiRvSmbg "Update 1.0.6 for the Unity UI Extensions Project") @@ -83,39 +152,37 @@ Two scripts were moved and need their originals need deleting post upgrade. Ple * I've added a donate column to the lists. If you are getting great use out of a control, help out the dev who created it. Optional of course. Will update with links as I get them. ---------------- -##Update 1.0.5## +## Update 1.0.5 Few minor fixes and a couple of additional scripts. Predominately created the new 5.3 branch to maintain the UI API changes from the 5.2.1 Patch releases. 5.3 package is 100% compatible with 5.2.1 Patch releases. ---------------- -##Update 1.0.4## +## Update 1.0.4 [![View Getting Started Video](http://img.youtube.com/vi/oF48Qpaq3ls/0.jpg)](http://www.youtube.com/watch?v=oF48Qpaq3ls "Update 1.0.0.4 for the Unity UI Extensions Project") --- - - ======================= -#Additional Info# +# Additional Info ======================= -### How do I get set up? ### +### How do I get set up? Either clone / download this repository to your machine and then copy the scripts in, or use the pre-packaged .UnityPackage for your version of Unity and import it as a custom package in to your project. -### Contribution guidelines ### +### Contribution guidelines Got a script you want added, then just fork and submit a PR. All contributions accepted (including fixes) Just ensure * The header of the script matches the standard used in all scripts * The script uses the **Unity.UI.Extensions** namespace so they do not affect any other developments * (optional) Add Component and Editor options where possible (editor options are in the Editor\UIExtensionsMenuOptions.cs file) -### License ### -All scripts conform to the BSD license and are free to use / distribute. See the [LICENSE](https://bitbucket.org/ddreaper/unity-ui-extensions/src/6d03f25b0150994afa97c6a55854d6ae696cad13/LICENSE?at=default) file for more information +### License +All scripts conform to the BSD license and are free to use / distribute. See the [LICENSE](https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/src/6d03f25b0150994afa97c6a55854d6ae696cad13/LICENSE?at=default) file for more information -### Like what you see? ### +### Like what you see? All these scripts were put together for my latest book Unity3D UI Essentials Check out the [page on my blog](http://bit.ly/Unity3DUIEssentials) for more details and learn all about the inner workings of the new Unity UI System. -### The downloads ### +### The downloads As this repo was created to support my new Unity UI Title ["Unity 3D UI Essentials"](http://bit.ly/Unity3DUIEssentials), in the downloads section you will find two custom assets (SpaceShip-DemoScene-Start.unitypackage and RollABallSample-Start.unitypackage). These are just here as starter scenes for doing UI tasks in the book. I will add more sample scenes for the UI examples in this repository and detail them above over time. \ No newline at end of file diff --git a/Scripts/Controls/ImageExtended.cs b/Scripts/Controls/ImageExtended.cs deleted file mode 100644 index e2b6a4d..0000000 --- a/Scripts/Controls/ImageExtended.cs +++ /dev/null @@ -1,1079 +0,0 @@ -/// Credit Ges -/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2062320 - -using System; -using System.Collections.Generic; -using UnityEngine.Serialization; - -namespace UnityEngine.UI.Extensions -{ - /// - /// Image is a textured element in the UI hierarchy. - /// Non-Functional as of 5.2.1p+ / 5.3, need to see updated Image Base script updates to fix properly. - /// - - [AddComponentMenu("UI/Extensions/Image Extended")] - public class ImageExtended : MaskableGraphic, ISerializationCallbackReceiver, ILayoutElement, ICanvasRaycastFilter - { - public enum Type - { - Simple, - Sliced, - Tiled, - Filled - } - - public enum FillMethod - { - Horizontal, - Vertical, - Radial90, - Radial180, - Radial360, - } - - public enum OriginHorizontal - { - Left, - Right, - } - - public enum OriginVertical - { - Bottom, - Top, - } - - public enum Origin90 - { - BottomLeft, - TopLeft, - TopRight, - BottomRight, - } - - public enum Origin180 - { - Bottom, - Left, - Top, - Right, - } - - public enum Origin360 - { - Bottom, - Right, - Top, - Left, - } - - public enum Rotate - { - Rotate0, - Rotate90, - Rotate180, - Rotate270, - } - - [FormerlySerializedAs("m_Frame")] - [SerializeField] - private Sprite m_Sprite; - public Sprite sprite { get { return m_Sprite; } set { if (SetPropertyUtility.SetClass(ref m_Sprite, value)) SetAllDirty(); } } - - [NonSerialized] - private Sprite m_OverrideSprite; - public Sprite overrideSprite { get { return m_OverrideSprite == null ? sprite : m_OverrideSprite; } set { if (SetPropertyUtility.SetClass(ref m_OverrideSprite, value)) SetAllDirty(); } } - - /// How the Image is drawn. - [SerializeField] - private Type m_Type = Type.Simple; - public Type type { get { return m_Type; } set { if (SetPropertyUtility.SetStruct(ref m_Type, value)) SetVerticesDirty(); } } - - [SerializeField] - private bool m_PreserveAspect = false; - public bool preserveAspect { get { return m_PreserveAspect; } set { if (SetPropertyUtility.SetStruct(ref m_PreserveAspect, value)) SetVerticesDirty(); } } - - [SerializeField] - private bool m_FillCenter = true; - public bool fillCenter { get { return m_FillCenter; } set { if (SetPropertyUtility.SetStruct(ref m_FillCenter, value)) SetVerticesDirty(); } } - - /// Filling method for filled sprites. - [SerializeField] - private FillMethod m_FillMethod = FillMethod.Radial360; - public FillMethod fillMethod { get { return m_FillMethod; } set { if (SetPropertyUtility.SetStruct(ref m_FillMethod, value)) { SetVerticesDirty(); m_FillOrigin = 0; } } } - - /// Amount of the Image shown. 0-1 range with 0 being nothing shown, and 1 being the full Image. - [Range(0, 1)] - [SerializeField] - private float m_FillAmount = 1.0f; - public float fillAmount { get { return m_FillAmount; } set { if (SetPropertyUtility.SetStruct(ref m_FillAmount, Mathf.Clamp01(value))) SetVerticesDirty(); } } - - /// Whether the Image should be filled clockwise (true) or counter-clockwise (false). - [SerializeField] - private bool m_FillClockwise = true; - public bool fillClockwise { get { return m_FillClockwise; } set { if (SetPropertyUtility.SetStruct(ref m_FillClockwise, value)) SetVerticesDirty(); } } - - /// Controls the origin point of the Fill process. Value means different things with each fill method. - [SerializeField] - private int m_FillOrigin; - public int fillOrigin { get { return m_FillOrigin; } set { if (SetPropertyUtility.SetStruct(ref m_FillOrigin, value)) SetVerticesDirty(); } } - - [SerializeField] - private Rotate m_Rotate = Rotate.Rotate0; - public Rotate rotate { get { return m_Rotate; } set { if (SetPropertyUtility.SetStruct(ref m_Rotate, value)) SetVerticesDirty(); } } - - // Not serialized until we support read-enabled sprites better. - private float m_EventAlphaThreshold = 1; - public float eventAlphaThreshold { get { return m_EventAlphaThreshold; } set { m_EventAlphaThreshold = value; } } - - protected ImageExtended() - { } - - /// - /// Image's texture comes from the UnityEngine.Image. - /// - public override Texture mainTexture - { - get - { - return overrideSprite == null ? s_WhiteTexture : overrideSprite.texture; - } - } - - /// - /// Whether the Image has a border to work with. - /// - - public bool hasBorder - { - get - { - if (overrideSprite != null) - { - Vector4 v = overrideSprite.border; - return v.sqrMagnitude > 0f; - } - return false; - } - } - - public float pixelsPerUnit - { - get - { - float spritePixelsPerUnit = 100; - if (sprite) - spritePixelsPerUnit = sprite.pixelsPerUnit; - - float referencePixelsPerUnit = 100; - if (canvas) - referencePixelsPerUnit = canvas.referencePixelsPerUnit; - - return spritePixelsPerUnit / referencePixelsPerUnit; - } - } - - public virtual void OnBeforeSerialize() { } - - public virtual void OnAfterDeserialize() - { - if (m_FillOrigin < 0) - m_FillOrigin = 0; - else if (m_FillMethod == FillMethod.Horizontal && m_FillOrigin > 1) - m_FillOrigin = 0; - else if (m_FillMethod == FillMethod.Vertical && m_FillOrigin > 1) - m_FillOrigin = 0; - else if (m_FillOrigin > 3) - m_FillOrigin = 0; - - m_FillAmount = Mathf.Clamp(m_FillAmount, 0f, 1f); - } - - /// Image's dimensions used for drawing. X = left, Y = bottom, Z = right, W = top. - private Vector4 GetDrawingDimensions(bool shouldPreserveAspect) - { - var padding = overrideSprite == null ? Vector4.zero : Sprites.DataUtility.GetPadding(overrideSprite); - var size = overrideSprite == null ? Vector2.zero : new Vector2(overrideSprite.rect.width, overrideSprite.rect.height); - - Rect r = GetPixelAdjustedRect(); - - int spriteW = Mathf.RoundToInt(size.x); - int spriteH = Mathf.RoundToInt(size.y); - - var v = overrideSprite == null ? new Vector4(0, 0, 1, 1) : - new Vector4( - padding.x / spriteW, - padding.y / spriteH, - (spriteW - padding.z) / spriteW, - (spriteH - padding.w) / spriteH); - - if (shouldPreserveAspect && size.sqrMagnitude > 0.0f) - { - var spriteRatio = size.x / size.y; - var rectRatio = r.width / r.height; - - if (spriteRatio > rectRatio) - { - var oldHeight = r.height; - r.height = r.width * (1.0f / spriteRatio); - r.y += (oldHeight - r.height) * rectTransform.pivot.y; - } - else - { - var oldWidth = r.width; - r.width = r.height * spriteRatio; - r.x += (oldWidth - r.width) * rectTransform.pivot.x; - } - } - - v = new Vector4( - r.x + r.width * v.x, - r.y + r.height * v.y, - r.x + r.width * v.z, - r.y + r.height * v.w - ); - - return v; - } - - public override void SetNativeSize() - { - if (overrideSprite != null) - { - float w = overrideSprite.rect.width / pixelsPerUnit; - float h = overrideSprite.rect.height / pixelsPerUnit; - rectTransform.anchorMax = rectTransform.anchorMin; - rectTransform.sizeDelta = new Vector2(w, h); - SetAllDirty(); - } - } - - /// - /// Update the UI renderer mesh. - /// - - protected override void OnPopulateMesh(VertexHelper vh) - { - List vbo = new List(); - vh.GetUIVertexStream(vbo); - - switch (type) - { - case Type.Simple: - GenerateSimpleSprite(vbo, m_PreserveAspect); - break; - case Type.Sliced: - GenerateSlicedSprite(vbo); - break; - case Type.Tiled: - GenerateTiledSprite(vbo); - break; - case Type.Filled: - GenerateFilledSprite(vbo, m_PreserveAspect); - break; - } - vh.Clear(); - vh.AddUIVertexTriangleStream(vbo); - } - - #region Various fill functions - /// - /// Generate vertices for a simple Image. - /// - - void GenerateSimpleSprite(List vbo, bool preserveAspect) - { - var vert = UIVertex.simpleVert; - vert.color = color; - - Vector4 v = GetDrawingDimensions(preserveAspect); - var uv = (overrideSprite != null) ? Sprites.DataUtility.GetOuterUV(overrideSprite) : Vector4.zero; - - AddQuad(vbo, vert, - new Vector2(v.x, v.y), new Vector2(v.z, v.w), - new Vector2(uv.x, uv.y), new Vector2(uv.z, uv.w)); - } - - /// - /// Generate vertices for a 9-sliced Image. - /// - - static readonly Vector2[] s_VertScratch = new Vector2[4]; - static readonly Vector2[] s_UVScratch = new Vector2[4]; - void GenerateSlicedSprite(List vbo) - { - if (!hasBorder) - { - GenerateSimpleSprite(vbo, false); - return; - } - - Vector4 outer, inner, padding, border; - - if (overrideSprite != null) - { - outer = Sprites.DataUtility.GetOuterUV(overrideSprite); - inner = Sprites.DataUtility.GetInnerUV(overrideSprite); - padding = Sprites.DataUtility.GetPadding(overrideSprite); - border = overrideSprite.border; - } - else - { - outer = Vector4.zero; - inner = Vector4.zero; - padding = Vector4.zero; - border = Vector4.zero; - } - - Rect rect = GetPixelAdjustedRect(); - border = GetAdjustedBorders(border / pixelsPerUnit, rect); - padding = padding / pixelsPerUnit; - - int offset = 4 - (int)rotate; - for (int i = 0; i < 4; ++i) - { - s_VertScratch[(4 - i / 2) % 4][i % 2] = padding[(i + offset) % 4]; - s_VertScratch[1 + i / 2][i % 2] = border[(i + offset) % 4]; - } - for (int i = 2; i < 4; ++i) - { - s_VertScratch[i].x = rect.width - s_VertScratch[i].x; - s_VertScratch[i].y = rect.height - s_VertScratch[i].y; - } - for (int i = 0; i < 4; ++i) - { - s_VertScratch[i].x += rect.x; - s_VertScratch[i].y += rect.y; - } - - s_UVScratch[0] = new Vector2(outer.x, outer.y); - s_UVScratch[1] = new Vector2(inner.x, inner.y); - s_UVScratch[2] = new Vector2(inner.z, inner.w); - s_UVScratch[3] = new Vector2(outer.z, outer.w); - - var uiv = UIVertex.simpleVert; - uiv.color = color; - for (int x = 0; x < 3; ++x) - { - int x2 = x + 1; - - for (int y = 0; y < 3; ++y) - { - if (!m_FillCenter && x == 1 && y == 1) - continue; - - int y2 = y + 1; - - int vx1 = x, vy1 = y; - int vx2 = x2, vy2 = y2; - for (int i = 0; i < (int)rotate; ++i) - { - int t1 = 4 - vy1 - 1; - vy1 = vx1; vx1 = t1; - int t2 = 4 - vy2 - 1; - vy2 = vx2; vx2 = t2; - } - int ux1 = x, uy1 = y; - int ux2 = x2, uy2 = y2; - if ((int)rotate >= 2) - { - ux1 = x2; ux2 = x; - } - if (((int)rotate + 1) % 4 >= 2) - { - uy1 = y2; uy2 = y; - } - if (Mathf.Abs(s_VertScratch[vx1].x - s_VertScratch[vx2].x) < Mathf.Epsilon) - continue; - if (Mathf.Abs(s_VertScratch[vy1].y - s_VertScratch[vy2].y) < Mathf.Epsilon) - continue; - AddQuad(vbo, uiv, - new Vector2(s_VertScratch[vx1].x, s_VertScratch[vy1].y), - new Vector2(s_VertScratch[vx2].x, s_VertScratch[vy2].y), - new Vector2(s_UVScratch[ux1].x, s_UVScratch[uy1].y), - new Vector2(s_UVScratch[ux2].x, s_UVScratch[uy2].y)); - } - } - } - - /// - /// Generate vertices for a tiled Image. - /// - - static readonly Vector2[] s_UVTiled = new Vector2[2]; - void GenerateTiledSprite(List vbo) - { - Vector4 outer, inner, border; - Vector2 spriteSize; - - if (overrideSprite != null) - { - outer = Sprites.DataUtility.GetOuterUV(overrideSprite); - inner = Sprites.DataUtility.GetInnerUV(overrideSprite); - border = overrideSprite.border; - spriteSize = overrideSprite.rect.size; - } - else - { - outer = Vector4.zero; - inner = Vector4.zero; - border = Vector4.zero; - spriteSize = Vector2.one * 100; - } - - Rect rect = GetPixelAdjustedRect(); - float tileWidth = (spriteSize.x - border.x - border.z) / pixelsPerUnit; - float tileHeight = (spriteSize.y - border.y - border.w) / pixelsPerUnit; - border = GetAdjustedBorders(border / pixelsPerUnit, rect); - - int offset = 4 - (int)rotate; - int rx = (0 + offset) % 4, ry = (1 + offset) % 4, rz = (2 + offset) % 4, rw = (3 + offset) % 4; - - var v = UIVertex.simpleVert; - v.color = color; - - // Min to max max range for tiled region in coordinates relative to lower left corner. - float xMin = border[rx]; - float xMax = rect.width - border[rz]; - float yMin = border[ry]; - float yMax = rect.height - border[rw]; - - // Safety check. Useful so Unity doesn't run out of memory if the sprites are too small. - // Max tiles are 100 x 100. - if ((xMax - xMin) > tileWidth * 100 || (yMax - yMin) > tileHeight * 100) - { - tileWidth = (xMax - xMin) / 100; - tileHeight = (yMax - yMin) / 100; - } - if ((int)rotate % 2 == 1) - { - float t = tileWidth; - tileWidth = tileHeight; - tileHeight = t; - } - - if (m_FillCenter) - { - for (float y1 = yMin; y1 < yMax; y1 += tileHeight) - { - s_UVTiled[0] = new Vector2(inner.x, inner.y); - s_UVTiled[1] = new Vector2(inner.z, inner.w); - float y2 = y1 + tileHeight; - if (y2 > yMax) - { - int k1 = 1 - (int)rotate / 2, k2 = 1 - (int)rotate % 2; - s_UVTiled[k1][k2] = s_UVTiled[1 - k1][k2] + (s_UVTiled[k1][k2] - s_UVTiled[1 - k1][k2]) * (yMax - y1) / (y2 - y1); - y2 = yMax; - } - for (float x1 = xMin; x1 < xMax; x1 += tileWidth) - { - float x2 = x1 + tileWidth; - if (x2 > xMax) - { - int k1 = ((int)rotate + 3) % 4 / 2, k2 = (int)rotate % 2; - s_UVTiled[k1][k2] = s_UVTiled[1 - k1][k2] + (s_UVTiled[k1][k2] - s_UVTiled[1 - k1][k2]) * (xMax - x1) / (x2 - x1); - x2 = xMax; - } - AddQuad(vbo, v, new Vector2(x1, y1) + rect.position, new Vector2(x2, y2) + rect.position, s_UVTiled[0], s_UVTiled[1]); - } - } - } - - if (!hasBorder) - return; - - // Bottom and top tiled border - for (int i = 0; i < 2; ++i) - { - float y1 = i == 0 ? 0 : yMax; - float y2 = i == 0 ? yMin : rect.height; - if (Mathf.Abs(y1 - y2) < Mathf.Epsilon) - continue; - - s_UVTiled[0] = GetRotatedUV(inner, 0, i == 0 ? outer : inner, i == 0 ? 1 : 3); - s_UVTiled[1] = GetRotatedUV(inner, 2, i == 0 ? inner : outer, i == 0 ? 1 : 3); - RotatePairUV(s_UVTiled); - for (float x1 = xMin; x1 < xMax; x1 += tileWidth) - { - float x2 = x1 + tileWidth; - if (x2 > xMax) - { - int k1 = ((int)rotate + 3) % 4 / 2, k2 = (int)rotate % 2; - s_UVTiled[k1][k2] = s_UVTiled[1 - k1][k2] + (s_UVTiled[k1][k2] - s_UVTiled[1 - k1][k2]) * (xMax - x1) / (x2 - x1); - x2 = xMax; - } - AddQuad(vbo, v, - new Vector2(x1, y1) + rect.position, - new Vector2(x2, y2) + rect.position, - s_UVTiled[0], s_UVTiled[1]); - } - } - - // Left and right tiled border - for (int i = 0; i < 2; ++i) - { - float x1 = i == 0 ? 0 : xMax; - float x2 = i == 0 ? xMin : rect.width; - if (Mathf.Abs(x1 - x2) < Mathf.Epsilon) - continue; - - s_UVTiled[0] = GetRotatedUV(i == 0 ? outer : inner, i == 0 ? 0 : 2, inner, 1); - s_UVTiled[1] = GetRotatedUV(i == 0 ? inner : outer, i == 0 ? 0 : 2, inner, 3); - RotatePairUV(s_UVTiled); - for (float y1 = yMin; y1 < yMax; y1 += tileHeight) - { - float y2 = y1 + tileHeight; - if (y2 > yMax) - { - int k1 = 1 - (int)rotate / 2, k2 = 1 - (int)rotate % 2; - s_UVTiled[k1][k2] = s_UVTiled[1 - k1][k2] + (s_UVTiled[k1][k2] - s_UVTiled[1 - k1][k2]) * (yMax - y1) / (y2 - y1); - y2 = yMax; - } - AddQuad(vbo, v, - new Vector2(x1, y1) + rect.position, - new Vector2(x2, y2) + rect.position, - s_UVTiled[0], s_UVTiled[1]); - } - } - - // Corners - if (Mathf.Abs(border[rx]) > Mathf.Epsilon && - Mathf.Abs(border[ry]) > Mathf.Epsilon) - { - s_UVTiled[0] = GetRotatedUV(outer, 0, outer, 1); - s_UVTiled[1] = GetRotatedUV(inner, 0, inner, 1); - RotatePairUV(s_UVTiled); - AddQuad(vbo, v, - new Vector2(0, 0) + rect.position, - new Vector2(xMin, yMin) + rect.position, - s_UVTiled[0], s_UVTiled[1]); - } - if (Mathf.Abs(border[rz]) > Mathf.Epsilon && - Mathf.Abs(border[ry]) > Mathf.Epsilon) - { - s_UVTiled[0] = GetRotatedUV(inner, 2, outer, 1); - s_UVTiled[1] = GetRotatedUV(outer, 2, inner, 1); - RotatePairUV(s_UVTiled); - AddQuad(vbo, v, - new Vector2(xMax, 0) + rect.position, - new Vector2(rect.width, yMin) + rect.position, - s_UVTiled[0], s_UVTiled[1]); - } - if (Mathf.Abs(border[rx]) > Mathf.Epsilon && - Mathf.Abs(border[rw]) > Mathf.Epsilon) - { - s_UVTiled[0] = GetRotatedUV(outer, 0, inner, 3); - s_UVTiled[1] = GetRotatedUV(inner, 0, outer, 3); - RotatePairUV(s_UVTiled); - AddQuad(vbo, v, - new Vector2(0, yMax) + rect.position, - new Vector2(xMin, rect.height) + rect.position, - s_UVTiled[0], s_UVTiled[1]); - } - if (Mathf.Abs(border[rz]) > Mathf.Epsilon && - Mathf.Abs(border[rw]) > Mathf.Epsilon) - { - s_UVTiled[0] = GetRotatedUV(inner, 2, inner, 3); - s_UVTiled[1] = GetRotatedUV(outer, 2, outer, 3); - RotatePairUV(s_UVTiled); - AddQuad(vbo, v, - new Vector2(xMax, yMax) + rect.position, - new Vector2(rect.width, rect.height) + rect.position, - s_UVTiled[0], s_UVTiled[1]); - } - } - - Vector2 GetRotatedUV(Vector4 sX, int iX, Vector4 sY, int iY) - { - for (int i = 0; i < (int)rotate; i++) - { - Vector4 tS = sX; - sX = sY; sY = tS; - int tI = (iX + 3) % 4; - iX = iY - 1; iY = tI; - } - return new Vector2(sX[iX], sY[iY]); - } - - void RotatePairUV(Vector2[] uv) - { - if ((int)rotate / 2 == 1) - { - float t = uv[0].x; - uv[0].x = uv[1].x; - uv[1].x = t; - } - if (((int)rotate + 1) / 2 == 1) - { - float t = uv[0].y; - uv[0].y = uv[1].y; - uv[1].y = t; - } - } - - static readonly Vector3[] s_VertQuad = new Vector3[4]; - static readonly Vector2[] s_UVQuad = new Vector2[4]; - void AddQuad(List vbo, UIVertex v, Vector2 posMin, Vector2 posMax, Vector2 uvMin, Vector2 uvMax) - { - s_VertQuad[0] = new Vector3(posMin.x, posMin.y, 0); - s_VertQuad[1] = new Vector3(posMin.x, posMax.y, 0); - s_VertQuad[2] = new Vector3(posMax.x, posMax.y, 0); - s_VertQuad[3] = new Vector3(posMax.x, posMin.y, 0); - s_UVQuad[0] = new Vector2(uvMin.x, uvMin.y); - s_UVQuad[1] = new Vector2(uvMin.x, uvMax.y); - s_UVQuad[2] = new Vector2(uvMax.x, uvMax.y); - s_UVQuad[3] = new Vector2(uvMax.x, uvMin.y); - - int offset = (int)rotate; - for (int i = 0; i < 4; i++) - { - v.position = s_VertQuad[i]; - v.uv0 = s_UVQuad[(i + offset) % 4]; - vbo.Add(v); - } - } - - Vector4 GetAdjustedBorders(Vector4 border, Rect rect) - { - for (int axis = 0; axis <= 1; axis++) - { - // If the rect is smaller than the combined borders, then there's not room for the borders at their normal size. - // In order to avoid artefacts with overlapping borders, we scale the borders down to fit. - float combinedBorders = border[axis] + border[axis + 2]; - float rectSize = rect.size[(axis + (int)rotate % 2) % 2]; - if (rectSize < combinedBorders && combinedBorders != 0) - { - float borderScaleRatio = rectSize / combinedBorders; - border[axis] *= borderScaleRatio; - border[axis + 2] *= borderScaleRatio; - } - } - return border; - } - - /// - /// Generate vertices for a filled Image. - /// - - static readonly Vector2[] s_Xy = new Vector2[4]; - static readonly Vector2[] s_Uv = new Vector2[4]; - void GenerateFilledSprite(List vbo, bool preserveAspect) - { - if (m_FillAmount < 0.001f) - return; - - Vector4 v = GetDrawingDimensions(preserveAspect); - Vector4 outer = overrideSprite != null ? Sprites.DataUtility.GetOuterUV(overrideSprite) : Vector4.zero; - UIVertex uiv = UIVertex.simpleVert; - uiv.color = color; - - int offset = 4 - (int)rotate; - int rx = (0 + offset) % 4, ry = (1 + offset) % 4, rz = (2 + offset) % 4, rw = (3 + offset) % 4; - - // Horizontal and vertical filled sprites are simple -- just end the Image prematurely - if (m_FillMethod == FillMethod.Horizontal || m_FillMethod == FillMethod.Vertical) - { - if (fillMethod == FillMethod.Horizontal) - { - float fill = (outer[rz] - outer[rx]) * m_FillAmount; - - if (m_FillOrigin == 1) - { - v.x = v.z - (v.z - v.x) * m_FillAmount; - outer[rx] = outer[rz] - fill; - } - else - { - v.z = v.x + (v.z - v.x) * m_FillAmount; - outer[rz] = outer[rx] + fill; - } - } - else if (fillMethod == FillMethod.Vertical) - { - float fill = (outer[rw] - outer[ry]) * m_FillAmount; - - if (m_FillOrigin == 1) - { - v.y = v.w - (v.w - v.y) * m_FillAmount; - outer[ry] = outer[rw] - fill; - } - else - { - v.w = v.y + (v.w - v.y) * m_FillAmount; - outer[rw] = outer[ry] + fill; - } - } - } - - s_Xy[0] = new Vector2(v.x, v.y); - s_Xy[1] = new Vector2(v.x, v.w); - s_Xy[2] = new Vector2(v.z, v.w); - s_Xy[3] = new Vector2(v.z, v.y); - - s_Uv[(0 + offset) % 4] = new Vector2(outer.x, outer.y); - s_Uv[(1 + offset) % 4] = new Vector2(outer.x, outer.w); - s_Uv[(2 + offset) % 4] = new Vector2(outer.z, outer.w); - s_Uv[(3 + offset) % 4] = new Vector2(outer.z, outer.y); - - if (m_FillAmount < 1f) - { - float tx0 = outer.x; - float ty0 = outer.y; - float tx1 = outer.z; - float ty1 = outer.w; - if (fillMethod == FillMethod.Radial90) - { - if (RadialCut(s_Xy, s_Uv, m_FillAmount, m_FillClockwise, m_FillOrigin)) - { - for (int i = 0; i < 4; ++i) - { - uiv.position = s_Xy[i]; - uiv.uv0 = s_Uv[i]; - vbo.Add(uiv); - } - } - return; - } - - if (fillMethod == FillMethod.Radial180) - { - for (int side = 0; side < 2; ++side) - { - float fx0, fx1, fy0, fy1; - int even = m_FillOrigin > 1 ? 1 : 0; - - if (m_FillOrigin == 0 || m_FillOrigin == 2) - { - fy0 = 0f; - fy1 = 1f; - if (side == even) { fx0 = 0f; fx1 = 0.5f; } - else { fx0 = 0.5f; fx1 = 1f; } - } - else - { - fx0 = 0f; - fx1 = 1f; - if (side == even) { fy0 = 0.5f; fy1 = 1f; } - else { fy0 = 0f; fy1 = 0.5f; } - } - - s_Xy[0].x = Mathf.Lerp(v.x, v.z, fx0); - s_Xy[1].x = s_Xy[0].x; - s_Xy[2].x = Mathf.Lerp(v.x, v.z, fx1); - s_Xy[3].x = s_Xy[2].x; - - s_Xy[0].y = Mathf.Lerp(v.y, v.w, fy0); - s_Xy[1].y = Mathf.Lerp(v.y, v.w, fy1); - s_Xy[2].y = s_Xy[1].y; - s_Xy[3].y = s_Xy[0].y; - - s_Uv[0].x = Mathf.Lerp(tx0, tx1, fx0); - s_Uv[1].x = s_Uv[0].x; - s_Uv[2].x = Mathf.Lerp(tx0, tx1, fx1); - s_Uv[3].x = s_Uv[2].x; - - s_Uv[0].y = Mathf.Lerp(ty0, ty1, fy0); - s_Uv[1].y = Mathf.Lerp(ty0, ty1, fy1); - s_Uv[2].y = s_Uv[1].y; - s_Uv[3].y = s_Uv[0].y; - - float val = m_FillClockwise ? fillAmount * 2f - side : m_FillAmount * 2f - (1 - side); - - if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(val), m_FillClockwise, ((side + m_FillOrigin + 3) % 4))) - { - for (int i = 0; i < 4; ++i) - { - uiv.position = s_Xy[i]; - uiv.uv0 = s_Uv[i]; - vbo.Add(uiv); - } - } - } - return; - } - - if (fillMethod == FillMethod.Radial360) - { - for (int corner = 0; corner < 4; ++corner) - { - float fx0, fx1, fy0, fy1; - - if (corner < 2) { fx0 = 0f; fx1 = 0.5f; } - else { fx0 = 0.5f; fx1 = 1f; } - - if (corner == 0 || corner == 3) { fy0 = 0f; fy1 = 0.5f; } - else { fy0 = 0.5f; fy1 = 1f; } - - s_Xy[0].x = Mathf.Lerp(v.x, v.z, fx0); - s_Xy[1].x = s_Xy[0].x; - s_Xy[2].x = Mathf.Lerp(v.x, v.z, fx1); - s_Xy[3].x = s_Xy[2].x; - - s_Xy[0].y = Mathf.Lerp(v.y, v.w, fy0); - s_Xy[1].y = Mathf.Lerp(v.y, v.w, fy1); - s_Xy[2].y = s_Xy[1].y; - s_Xy[3].y = s_Xy[0].y; - - s_Uv[0].x = Mathf.Lerp(tx0, tx1, fx0); - s_Uv[1].x = s_Uv[0].x; - s_Uv[2].x = Mathf.Lerp(tx0, tx1, fx1); - s_Uv[3].x = s_Uv[2].x; - - s_Uv[0].y = Mathf.Lerp(ty0, ty1, fy0); - s_Uv[1].y = Mathf.Lerp(ty0, ty1, fy1); - s_Uv[2].y = s_Uv[1].y; - s_Uv[3].y = s_Uv[0].y; - - float val = m_FillClockwise ? - m_FillAmount * 4f - ((corner + m_FillOrigin) % 4) : - m_FillAmount * 4f - (3 - ((corner + m_FillOrigin) % 4)); - - if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(val), m_FillClockwise, ((corner + 2) % 4))) - { - for (int i = 0; i < 4; ++i) - { - uiv.position = s_Xy[i]; - uiv.uv0 = s_Uv[i]; - vbo.Add(uiv); - } - } - } - return; - } - } - - // Fill the buffer with the quad for the Image - for (int i = 0; i < 4; ++i) - { - uiv.position = s_Xy[i]; - uiv.uv0 = s_Uv[i]; - vbo.Add(uiv); - } - } - - /// - /// Adjust the specified quad, making it be radially filled instead. - /// - - static bool RadialCut(Vector2[] xy, Vector2[] uv, float fill, bool invert, int corner) - { - // Nothing to fill - if (fill < 0.001f) return false; - - // Even corners invert the fill direction - if ((corner & 1) == 1) invert = !invert; - - // Nothing to adjust - if (!invert && fill > 0.999f) return true; - - // Convert 0-1 value into 0 to 90 degrees angle in radians - float angle = Mathf.Clamp01(fill); - if (invert) angle = 1f - angle; - angle *= 90f * Mathf.Deg2Rad; - - // Calculate the effective X and Y factors - float cos = Mathf.Cos(angle); - float sin = Mathf.Sin(angle); - - RadialCut(xy, cos, sin, invert, corner); - RadialCut(uv, cos, sin, invert, corner); - return true; - } - - /// - /// Adjust the specified quad, making it be radially filled instead. - /// - - static void RadialCut(Vector2[] xy, float cos, float sin, bool invert, int corner) - { - int i0 = corner; - int i1 = ((corner + 1) % 4); - int i2 = ((corner + 2) % 4); - int i3 = ((corner + 3) % 4); - - if ((corner & 1) == 1) - { - if (sin > cos) - { - cos /= sin; - sin = 1f; - - if (invert) - { - xy[i1].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); - xy[i2].x = xy[i1].x; - } - } - else if (cos > sin) - { - sin /= cos; - cos = 1f; - - if (!invert) - { - xy[i2].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); - xy[i3].y = xy[i2].y; - } - } - else - { - cos = 1f; - sin = 1f; - } - - if (!invert) xy[i3].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); - else xy[i1].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); - } - else - { - if (cos > sin) - { - sin /= cos; - cos = 1f; - - if (!invert) - { - xy[i1].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); - xy[i2].y = xy[i1].y; - } - } - else if (sin > cos) - { - cos /= sin; - sin = 1f; - - if (invert) - { - xy[i2].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); - xy[i3].x = xy[i2].x; - } - } - else - { - cos = 1f; - sin = 1f; - } - - if (invert) xy[i3].y = Mathf.Lerp(xy[i0].y, xy[i2].y, sin); - else xy[i1].x = Mathf.Lerp(xy[i0].x, xy[i2].x, cos); - } - } - - #endregion - - public virtual void CalculateLayoutInputHorizontal() { } - public virtual void CalculateLayoutInputVertical() { } - - public virtual float minWidth { get { return 0; } } - - public virtual float preferredWidth - { - get - { - if (overrideSprite == null) - return 0; - if (type == Type.Sliced || type == Type.Tiled) - return Sprites.DataUtility.GetMinSize(overrideSprite).x / pixelsPerUnit; - return overrideSprite.rect.size.x / pixelsPerUnit; - } - } - - public virtual float flexibleWidth { get { return -1; } } - - public virtual float minHeight { get { return 0; } } - - public virtual float preferredHeight - { - get - { - if (overrideSprite == null) - return 0; - if (type == Type.Sliced || type == Type.Tiled) - return Sprites.DataUtility.GetMinSize(overrideSprite).y / pixelsPerUnit; - return overrideSprite.rect.size.y / pixelsPerUnit; - } - } - - public virtual float flexibleHeight { get { return -1; } } - - public virtual int layoutPriority { get { return 0; } } - - public virtual bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera) - { - if (m_EventAlphaThreshold >= 1) - return true; - - Sprite sprite = overrideSprite; - if (sprite == null) - return true; - - Vector2 local; - RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, screenPoint, eventCamera, out local); - - Rect rect = GetPixelAdjustedRect(); - - // Convert to have lower left corner as reference point. - local.x += rectTransform.pivot.x * rect.width; - local.y += rectTransform.pivot.y * rect.height; - - local = MapCoordinate(local, rect); - - // Normalize local coordinates. - Rect spriteRect = sprite.textureRect; - Vector2 normalized = new Vector2(local.x / spriteRect.width, local.y / spriteRect.height); - - // Convert to texture space. - float x = Mathf.Lerp(spriteRect.x, spriteRect.xMax, normalized.x) / sprite.texture.width; - float y = Mathf.Lerp(spriteRect.y, spriteRect.yMax, normalized.y) / sprite.texture.height; - - try - { - return sprite.texture.GetPixelBilinear(x, y).a >= m_EventAlphaThreshold; - } - catch (UnityException e) - { - Debug.LogError("Using clickAlphaThreshold lower than 1 on Image whose sprite texture cannot be read. " + e.Message + " Also make sure to disable sprite packing for this sprite.", this); - return true; - } - } - - private Vector2 MapCoordinate(Vector2 local, Rect rect) - { - Rect spriteRect = sprite.rect; - if (type == Type.Simple || type == Type.Filled) - return new Vector2(local.x * spriteRect.width / rect.width, local.y * spriteRect.height / rect.height); - - Vector4 border = sprite.border; - Vector4 adjustedBorder = GetAdjustedBorders(border / pixelsPerUnit, rect); - - for (int i = 0; i < 2; i++) - { - if (local[i] <= adjustedBorder[i]) - continue; - - if (rect.size[i] - local[i] <= adjustedBorder[i + 2]) - { - local[i] -= (rect.size[i] - spriteRect.size[i]); - continue; - } - - if (type == Type.Sliced) - { - float lerp = Mathf.InverseLerp(adjustedBorder[i], rect.size[i] - adjustedBorder[i + 2], local[i]); - local[i] = Mathf.Lerp(border[i], spriteRect.size[i] - border[i + 2], lerp); - continue; - } - else - { - local[i] -= adjustedBorder[i]; - local[i] = Mathf.Repeat(local[i], spriteRect.size[i] - border[i] - border[i + 2]); - local[i] += border[i]; - continue; - } - } - - return local; - } - } -} \ No newline at end of file diff --git a/Scripts/Controls/ImageExtended.cs.meta b/Scripts/Controls/ImageExtended.cs.meta deleted file mode 100644 index fac983a..0000000 --- a/Scripts/Controls/ImageExtended.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 494907d85b5e56a49884a914adc358a5 -timeCreated: 1440851346 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Controls/RadialSlider.cs b/Scripts/Controls/RadialSlider.cs index e8b8f7b..d9f227c 100644 --- a/Scripts/Controls/RadialSlider.cs +++ b/Scripts/Controls/RadialSlider.cs @@ -3,7 +3,6 @@ /// Updated to include lerping features and programatic access to angle/value using System; -using System.Collections; using UnityEngine.Events; using UnityEngine.EventSystems; diff --git a/Scripts/Layout/ScrollPositionController.cs b/Scripts/Layout/ScrollPositionController.cs index fe6b1ec..2eb3070 100644 --- a/Scripts/Layout/ScrollPositionController.cs +++ b/Scripts/Layout/ScrollPositionController.cs @@ -8,305 +8,316 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { - public class ScrollPositionController : UIBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler - { - #region Sub-Classes - [System.Serializable] - public class UpdatePositionEvent : UnityEvent { } - #endregion + public class ScrollPositionController : UIBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler + { + #region Sub-Classes + [System.Serializable] + public class UpdatePositionEvent : UnityEvent { } - [Serializable] - struct Snap - { - public bool Enable; - public float VelocityThreshold; - public float Duration; - } + [System.Serializable] + public class ItemSelectedEvent : UnityEvent { } + #endregion - enum ScrollDirection - { - Vertical, - Horizontal, - } + [Serializable] + struct Snap + { + public bool Enable; + public float VelocityThreshold; + public float Duration; + } - enum MovementType - { - Unrestricted = ScrollRect.MovementType.Unrestricted, - Elastic = ScrollRect.MovementType.Elastic, - Clamped = ScrollRect.MovementType.Clamped - } + enum ScrollDirection + { + Vertical, + Horizontal, + } - [SerializeField] - RectTransform viewport; - [SerializeField] - ScrollDirection directionOfRecognize = ScrollDirection.Vertical; - [SerializeField] - MovementType movementType = MovementType.Elastic; - [SerializeField] - float elasticity = 0.1f; - [SerializeField] - float scrollSensitivity = 1f; - [SerializeField] - bool inertia = true; - [SerializeField, Tooltip("Only used when inertia is enabled")] - float decelerationRate = 0.03f; - [SerializeField, Tooltip("Only used when inertia is enabled")] - Snap snap = new Snap { Enable = true, VelocityThreshold = 0.5f, Duration = 0.3f }; - [SerializeField] - int dataCount; + enum MovementType + { + Unrestricted = ScrollRect.MovementType.Unrestricted, + Elastic = ScrollRect.MovementType.Elastic, + Clamped = ScrollRect.MovementType.Clamped + } - #region Events - [Tooltip("Event that fires when the position of an item changes")] - public UpdatePositionEvent OnUpdatePosition; - #endregion + [SerializeField] + RectTransform viewport; + [SerializeField] + ScrollDirection directionOfRecognize = ScrollDirection.Vertical; + [SerializeField] + MovementType movementType = MovementType.Elastic; + [SerializeField] + float elasticity = 0.1f; + [SerializeField] + float scrollSensitivity = 1f; + [SerializeField] + bool inertia = true; + [SerializeField, Tooltip("Only used when inertia is enabled")] + float decelerationRate = 0.03f; + [SerializeField, Tooltip("Only used when inertia is enabled")] + Snap snap = new Snap { Enable = true, VelocityThreshold = 0.5f, Duration = 0.3f }; + [SerializeField] + int dataCount; - Vector2 pointerStartLocalPosition; - float dragStartScrollPosition; - float currentScrollPosition; - bool dragging; + #region Events + [Tooltip("Event that fires when the position of an item changes")] + public UpdatePositionEvent OnUpdatePosition; - void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } + [Tooltip("Event that fires when an item is selected/focused")] + public ItemSelectedEvent OnItemSelected; + #endregion - pointerStartLocalPosition = Vector2.zero; - RectTransformUtility.ScreenPointToLocalPointInRectangle( - viewport, - eventData.position, - eventData.pressEventCamera, - out pointerStartLocalPosition); + Vector2 pointerStartLocalPosition; + float dragStartScrollPosition; + float currentScrollPosition; + bool dragging; - dragStartScrollPosition = currentScrollPosition; - dragging = true; - } + void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) + { + if (eventData.button != PointerEventData.InputButton.Left) + { + return; + } - void IDragHandler.OnDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } + pointerStartLocalPosition = Vector2.zero; + RectTransformUtility.ScreenPointToLocalPointInRectangle( + viewport, + eventData.position, + eventData.pressEventCamera, + out pointerStartLocalPosition); - if (!dragging) - { - return; - } + dragStartScrollPosition = currentScrollPosition; + dragging = true; + } - Vector2 localCursor; - if (!RectTransformUtility.ScreenPointToLocalPointInRectangle( - viewport, - eventData.position, - eventData.pressEventCamera, - out localCursor)) - { - return; - } + void IDragHandler.OnDrag(PointerEventData eventData) + { + if (eventData.button != PointerEventData.InputButton.Left) + { + return; + } - var pointerDelta = localCursor - pointerStartLocalPosition; - var position = (directionOfRecognize == ScrollDirection.Horizontal ? -pointerDelta.x : pointerDelta.y) - / GetViewportSize() - * scrollSensitivity - + dragStartScrollPosition; + if (!dragging) + { + return; + } - var offset = CalculateOffset(position); - position += offset; + Vector2 localCursor; + if (!RectTransformUtility.ScreenPointToLocalPointInRectangle( + viewport, + eventData.position, + eventData.pressEventCamera, + out localCursor)) + { + return; + } - if (movementType == MovementType.Elastic) - { - if (offset != 0) - { - position -= RubberDelta(offset, scrollSensitivity); - } - } - UpdatePosition(position); - } + var pointerDelta = localCursor - pointerStartLocalPosition; + var position = (directionOfRecognize == ScrollDirection.Horizontal ? -pointerDelta.x : pointerDelta.y) + / GetViewportSize() + * scrollSensitivity + + dragStartScrollPosition; - void IEndDragHandler.OnEndDrag(PointerEventData eventData) - { - if (eventData.button != PointerEventData.InputButton.Left) - { - return; - } + var offset = CalculateOffset(position); + position += offset; - dragging = false; - } + if (movementType == MovementType.Elastic) + { + if (offset != 0) + { + position -= RubberDelta(offset, scrollSensitivity); + } + } + UpdatePosition(position); + } - float GetViewportSize() - { - return directionOfRecognize == ScrollDirection.Horizontal - ? viewport.rect.size.x - : viewport.rect.size.y; - } + void IEndDragHandler.OnEndDrag(PointerEventData eventData) + { + if (eventData.button != PointerEventData.InputButton.Left) + { + return; + } - float CalculateOffset(float position) - { - if (movementType == MovementType.Unrestricted) - { - return 0; - } - if (position < 0) - { - return -position; - } - if (position > dataCount - 1) - { - return (dataCount - 1) - position; - } - return 0f; - } + dragging = false; + } - void UpdatePosition(float position) - { - currentScrollPosition = position; + float GetViewportSize() + { + return directionOfRecognize == ScrollDirection.Horizontal + ? viewport.rect.size.x + : viewport.rect.size.y; + } - if (OnUpdatePosition != null) - { - OnUpdatePosition.Invoke(currentScrollPosition); - } - } + float CalculateOffset(float position) + { + if (movementType == MovementType.Unrestricted) + { + return 0; + } + if (position < 0) + { + return -position; + } + if (position > dataCount - 1) + { + return (dataCount - 1) - position; + } + return 0f; + } - float RubberDelta(float overStretching, float viewSize) - { - return (1 - (1 / ((Mathf.Abs(overStretching) * 0.55f / viewSize) + 1))) * viewSize * Mathf.Sign(overStretching); - } + void UpdatePosition(float position) + { + currentScrollPosition = position; - //public void OnUpdatePosition(Action onUpdatePosition) - //{ - // this.onUpdatePosition = onUpdatePosition; - //} + if (OnUpdatePosition != null) + { + OnUpdatePosition.Invoke(currentScrollPosition); + } + } - public void SetDataCount(int dataCont) - { - this.dataCount = dataCont; - } + float RubberDelta(float overStretching, float viewSize) + { + return (1 - (1 / ((Mathf.Abs(overStretching) * 0.55f / viewSize) + 1))) * viewSize * Mathf.Sign(overStretching); + } - float velocity; - float prevScrollPosition; + //public void OnUpdatePosition(Action onUpdatePosition) + //{ + // this.onUpdatePosition = onUpdatePosition; + //} - bool autoScrolling; - float autoScrollDuration; - float autoScrollStartTime; - float autoScrollPosition; + public void SetDataCount(int dataCont) + { + this.dataCount = dataCont; + } - void Update() - { - var deltaTime = Time.unscaledDeltaTime; - var offset = CalculateOffset(currentScrollPosition); + float velocity; + float prevScrollPosition; - if (autoScrolling) - { - var alpha = Mathf.Clamp01((Time.unscaledTime - autoScrollStartTime) / Mathf.Max(autoScrollDuration, float.Epsilon)); - var position = Mathf.Lerp(dragStartScrollPosition, autoScrollPosition, EaseInOutCubic(0, 1, alpha)); - UpdatePosition(position); + bool autoScrolling; + float autoScrollDuration; + float autoScrollStartTime; + float autoScrollPosition; - if (Mathf.Approximately(alpha, 1f)) - { - autoScrolling = false; - } - } - else if (!dragging && (offset != 0 || velocity != 0)) - { - var position = currentScrollPosition; - // Apply spring physics if movement is elastic and content has an offset from the view. - if (movementType == MovementType.Elastic && offset != 0) - { - var speed = velocity; - position = Mathf.SmoothDamp(currentScrollPosition, currentScrollPosition + offset, ref speed, elasticity, Mathf.Infinity, deltaTime); - velocity = speed; - } - // Else move content according to velocity with deceleration applied. - else if (inertia) - { - velocity *= Mathf.Pow(decelerationRate, deltaTime); - if (Mathf.Abs(velocity) < 0.001f) - velocity = 0; - position += velocity * deltaTime; + void Update() + { + var deltaTime = Time.unscaledDeltaTime; + var offset = CalculateOffset(currentScrollPosition); - if (snap.Enable && Mathf.Abs(velocity) < snap.VelocityThreshold) - { - ScrollTo(Mathf.RoundToInt(currentScrollPosition), snap.Duration); - } - } - // If we have neither elaticity or friction, there shouldn't be any velocity. - else - { - velocity = 0; - } + if (autoScrolling) + { + var alpha = Mathf.Clamp01((Time.unscaledTime - autoScrollStartTime) / Mathf.Max(autoScrollDuration, float.Epsilon)); + var position = Mathf.Lerp(dragStartScrollPosition, autoScrollPosition, EaseInOutCubic(0, 1, alpha)); + UpdatePosition(position); - if (velocity != 0) - { - if (movementType == MovementType.Clamped) - { - offset = CalculateOffset(position); - position += offset; - } - UpdatePosition(position); - } - } + if (Mathf.Approximately(alpha, 1f)) + { + autoScrolling = false; + // Auto scrolling is completed, get the item's index and firing OnItemSelected event. + if(OnItemSelected != null) + { + OnItemSelected.Invoke(Mathf.RoundToInt(GetLoopPosition(autoScrollPosition, dataCount))); + } + } + } + else if (!dragging && (offset != 0 || velocity != 0)) + { + var position = currentScrollPosition; + // Apply spring physics if movement is elastic and content has an offset from the view. + if (movementType == MovementType.Elastic && offset != 0) + { + var speed = velocity; + position = Mathf.SmoothDamp(currentScrollPosition, currentScrollPosition + offset, ref speed, elasticity, Mathf.Infinity, deltaTime); + velocity = speed; + } + // Else move content according to velocity with deceleration applied. + else if (inertia) + { + velocity *= Mathf.Pow(decelerationRate, deltaTime); + if (Mathf.Abs(velocity) < 0.001f) + velocity = 0; + position += velocity * deltaTime; - if (!autoScrolling && dragging && inertia) - { - var newVelocity = (currentScrollPosition - prevScrollPosition) / deltaTime; - velocity = Mathf.Lerp(velocity, newVelocity, deltaTime * 10f); - } + if (snap.Enable && Mathf.Abs(velocity) < snap.VelocityThreshold) + { + ScrollTo(Mathf.RoundToInt(currentScrollPosition), snap.Duration); + } + } + // If we have neither elaticity or friction, there shouldn't be any velocity. + else + { + velocity = 0; + } - if (currentScrollPosition != prevScrollPosition) - { - prevScrollPosition = currentScrollPosition; - } - } + if (velocity != 0) + { + if (movementType == MovementType.Clamped) + { + offset = CalculateOffset(position); + position += offset; + } + UpdatePosition(position); + } + } - public void ScrollTo(int index, float duration) - { - velocity = 0; - autoScrolling = true; - autoScrollDuration = duration; - autoScrollStartTime = Time.unscaledTime; - dragStartScrollPosition = currentScrollPosition; + if (!autoScrolling && dragging && inertia) + { + var newVelocity = (currentScrollPosition - prevScrollPosition) / deltaTime; + velocity = Mathf.Lerp(velocity, newVelocity, deltaTime * 10f); + } - autoScrollPosition = movementType == MovementType.Unrestricted - ? CalculateClosestPosition(index) - : index; - } + if (currentScrollPosition != prevScrollPosition) + { + prevScrollPosition = currentScrollPosition; + } + } - float CalculateClosestPosition(int index) - { - var diff = GetLoopPosition(index, dataCount) - - GetLoopPosition(currentScrollPosition, dataCount); + public void ScrollTo(int index, float duration) + { + velocity = 0; + autoScrolling = true; + autoScrollDuration = duration; + autoScrollStartTime = Time.unscaledTime; + dragStartScrollPosition = currentScrollPosition; - if (Mathf.Abs(diff) > dataCount * 0.5f) - { - diff = Mathf.Sign(-diff) * (dataCount - Mathf.Abs(diff)); - } - return diff + currentScrollPosition; - } + autoScrollPosition = movementType == MovementType.Unrestricted + ? CalculateClosestPosition(index) + : index; + } - float GetLoopPosition(float position, int length) - { - if (position < 0) - { - position = (length - 1) + (position + 1) % length; - } - else if (position > length - 1) - { - position = position % length; - } - return position; - } + float CalculateClosestPosition(int index) + { + var diff = GetLoopPosition(index, dataCount) + - GetLoopPosition(currentScrollPosition, dataCount); - float EaseInOutCubic(float start, float end, float value) - { - value /= 0.5f; - end -= start; - if (value < 1f) - { - return end * 0.5f * value * value * value + start; - } - value -= 2f; - return end * 0.5f * (value * value * value + 2f) + start; - } - } + if (Mathf.Abs(diff) > dataCount * 0.5f) + { + diff = Mathf.Sign(-diff) * (dataCount - Mathf.Abs(diff)); + } + return diff + currentScrollPosition; + } + + float GetLoopPosition(float position, int length) + { + if (position < 0) + { + position = (length - 1) + (position + 1) % length; + } + else if (position > length - 1) + { + position = position % length; + } + return position; + } + + float EaseInOutCubic(float start, float end, float value) + { + value /= 0.5f; + end -= start; + if (value < 1f) + { + return end * 0.5f * value * value * value + start; + } + value -= 2f; + return end * 0.5f * (value * value * value + 2f) + start; + } + } } \ No newline at end of file diff --git a/Scripts/Layout/ScrollSnap.cs b/Scripts/Layout/ScrollSnap.cs index e064bf8..0d93a28 100644 --- a/Scripts/Layout/ScrollSnap.cs +++ b/Scripts/Layout/ScrollSnap.cs @@ -33,7 +33,7 @@ namespace UnityEngine.UI.Extensions private Transform _listContainerTransform; - private RectTransform _rectTransform; + //private RectTransform _rectTransform; private int _pages; @@ -113,7 +113,7 @@ namespace UnityEngine.UI.Extensions _listContainerTransform = _scroll_rect.content; _listContainerRectTransform = _listContainerTransform.GetComponent(); - _rectTransform = _listContainerTransform.gameObject.GetComponent(); + //_rectTransform = _listContainerTransform.gameObject.GetComponent(); UpdateListItemsSize(); UpdateListItemPositions(); diff --git a/Scripts/MenuSystem/Menu.cs b/Scripts/MenuSystem/Menu.cs index c0f932d..f86a72c 100644 --- a/Scripts/MenuSystem/Menu.cs +++ b/Scripts/MenuSystem/Menu.cs @@ -2,7 +2,6 @@ /// Sourced from - https://github.com/YousicianGit/UnityMenuSystem /// Updated by SimonDarksideJ - Refactored to be a more generic component -using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { diff --git a/Scripts/Primitives/UIPrimitiveBase.cs b/Scripts/Primitives/UIPrimitiveBase.cs index 54e534d..acd5bab 100644 --- a/Scripts/Primitives/UIPrimitiveBase.cs +++ b/Scripts/Primitives/UIPrimitiveBase.cs @@ -15,7 +15,7 @@ namespace UnityEngine.UI.Extensions static protected Material s_ETC1DefaultUI = null; [SerializeField] private Sprite m_Sprite; - public Sprite sprite { get { return m_Sprite; } set { if (SetPropertyUtility.SetClass(ref m_Sprite, value)) ; GeneratedUVs(); SetAllDirty(); } } + public Sprite sprite { get { return m_Sprite; } set { if (SetPropertyUtility.SetClass(ref m_Sprite, value)) GeneratedUVs(); SetAllDirty(); } } [NonSerialized] private Sprite m_OverrideSprite; diff --git a/Scripts/Utilities/PaginationManager.cs b/Scripts/Utilities/PaginationManager.cs index 55a3237..9e5dc99 100644 --- a/Scripts/Utilities/PaginationManager.cs +++ b/Scripts/Utilities/PaginationManager.cs @@ -6,6 +6,7 @@ using System.Linq; namespace UnityEngine.UI.Extensions { + [AddComponentMenu("UI/Extensions/Pagination Manager")] public class PaginationManager : ToggleGroup { private List m_PaginationChildren; diff --git a/Scripts/Utilities/ReadOnlyAttribute.cs b/Scripts/Utilities/ReadOnlyAttribute.cs index 7b3e61a..0eb6a26 100644 --- a/Scripts/Utilities/ReadOnlyAttribute.cs +++ b/Scripts/Utilities/ReadOnlyAttribute.cs @@ -1,7 +1,6 @@ /// Credit tanoshimi /// Sourced from - https://forum.unity3d.com/threads/read-only-fields.68976/ -using UnityEngine; namespace UnityEngine.UI.Extensions { public class ReadOnlyAttribute : PropertyAttribute { } diff --git a/Scripts/Utilities/Serialization.meta b/Scripts/Utilities/Serialization.meta deleted file mode 100644 index 44dedbb..0000000 --- a/Scripts/Utilities/Serialization.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 1ef00bcef4289ff46a687da0f3bb245a -folderAsset: yes -timeCreated: 1435843505 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Attributes.meta b/Scripts/Utilities/Serialization/Attributes.meta deleted file mode 100644 index 014aa1b..0000000 --- a/Scripts/Utilities/Serialization/Attributes.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: de298d0f8df2abd4b898cede877984fc -folderAsset: yes -timeCreated: 1435844327 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Attributes/DontSaveField.cs b/Scripts/Utilities/Serialization/Attributes/DontSaveField.cs deleted file mode 100644 index 8895894..0000000 --- a/Scripts/Utilities/Serialization/Attributes/DontSaveField.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -namespace UnityEngine.UI.Extensions -{ - public class DontSaveField : Attribute - { - - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Attributes/DontSaveField.cs.meta b/Scripts/Utilities/Serialization/Attributes/DontSaveField.cs.meta deleted file mode 100644 index 3b54813..0000000 --- a/Scripts/Utilities/Serialization/Attributes/DontSaveField.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b76f678f8bde62944a2a2b76e40acd89 -timeCreated: 1435851264 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Non-Mono Classes.meta b/Scripts/Utilities/Serialization/Non-Mono Classes.meta deleted file mode 100644 index 0b80461..0000000 --- a/Scripts/Utilities/Serialization/Non-Mono Classes.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 6c24ae448872e974aab97c935d25c3b3 -folderAsset: yes -timeCreated: 1435844196 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Non-Mono Classes/ObjectComponent.cs b/Scripts/Utilities/Serialization/Non-Mono Classes/ObjectComponent.cs deleted file mode 100644 index 3f529c8..0000000 --- a/Scripts/Utilities/Serialization/Non-Mono Classes/ObjectComponent.cs +++ /dev/null @@ -1,13 +0,0 @@ -//The ObjectComponent class holds all data of a gameobject's component. -//The Dictionary holds the actual data of a component; A field's name as key and the corresponding value (object) as value. Confusing, right? -using System.Collections.Generic; - -namespace UnityEngine.UI.Extensions -{ - [System.Serializable] - public class ObjectComponent - { - public string componentName; - public Dictionary fields; - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Non-Mono Classes/ObjectComponent.cs.meta b/Scripts/Utilities/Serialization/Non-Mono Classes/ObjectComponent.cs.meta deleted file mode 100644 index 3d6e97d..0000000 --- a/Scripts/Utilities/Serialization/Non-Mono Classes/ObjectComponent.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: ab93d4079c9c0724f9855a7e549d3189 -timeCreated: 1435844196 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneData.cs b/Scripts/Utilities/Serialization/Non-Mono Classes/SceneData.cs deleted file mode 100644 index d89ddbc..0000000 --- a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneData.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace UnityEngine.UI.Extensions -{ - [System.Serializable] - public class SaveGame - { - - public string savegameName = "New SaveGame"; - public List sceneObjects = new List(); - - public SaveGame() - { - - } - - public SaveGame(string s, List list) - { - savegameName = s; - sceneObjects = list; - } - } -} diff --git a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneData.cs.meta b/Scripts/Utilities/Serialization/Non-Mono Classes/SceneData.cs.meta deleted file mode 100644 index 4203553..0000000 --- a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneData.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 5d1cbba8c8c32a44daf9525381cfd6b0 -timeCreated: 1435844196 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneObject.cs b/Scripts/Utilities/Serialization/Non-Mono Classes/SceneObject.cs deleted file mode 100644 index 93c49a3..0000000 --- a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneObject.cs +++ /dev/null @@ -1,24 +0,0 @@ -//This class holds is meant to hold all the data of a GameObject in the scene which has an ObjectIdentifier component. -//The values from the OI component are mirrored here, along with misc. stuff like the activation state of the gameObect (bool active), and of course it's components. - -using System.Collections.Generic; - -namespace UnityEngine.UI.Extensions -{ - [System.Serializable] - public class SceneObject - { - public string name; - public string prefabName; - public string id; - public string idParent; - - public bool active; - public Vector3 position; - public Vector3 localScale; - public Quaternion rotation; - - public List objectComponents = new List(); - } -} - diff --git a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneObject.cs.meta b/Scripts/Utilities/Serialization/Non-Mono Classes/SceneObject.cs.meta deleted file mode 100644 index e7b810c..0000000 --- a/Scripts/Utilities/Serialization/Non-Mono Classes/SceneObject.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: fab7f6b7ed3c13b4a8222ec3607582b8 -timeCreated: 1435844197 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/ObjectIdentifier.cs b/Scripts/Utilities/Serialization/ObjectIdentifier.cs deleted file mode 100644 index 982052e..0000000 --- a/Scripts/Utilities/Serialization/ObjectIdentifier.cs +++ /dev/null @@ -1,50 +0,0 @@ -//Add an ObjectIdentifier component to each Prefab that might possibly be serialized and deserialized. -//The name variable is not used by the serialization; it is just there so you can name your prefabs any way you want, -//while the "in-game" name can be something different -//for example, an item that the play can inspect might have the prefab name "sword_01_a", -//but the name (not the GameObject name; that is the prefab name! We are talking about the variable "name" here!) can be "Short Sword", -//which is what the palyer will see when inspecting it. -//To clarify again: A GameObject's (and thus, prefab's) name should be the same as prefabName, while the varialbe "name" in this script can be anything you want (or nothing at all). - -namespace UnityEngine.UI.Extensions -{ - public class ObjectIdentifier : MonoBehaviour - { - - //public string name; - public string prefabName; - - public string id; - public string idParent; - public bool dontSave = false; - - public void SetID() - { - - id = System.Guid.NewGuid().ToString(); - CheckForRelatives(); - } - - private void CheckForRelatives() - { - - if (transform.parent == null) - { - idParent = null; - } - else - { - ObjectIdentifier[] childrenIds = GetComponentsInChildren(); - foreach (ObjectIdentifier idScript in childrenIds) - { - if (idScript.transform.gameObject != gameObject) - { - idScript.idParent = id; - idScript.SetID(); - } - } - } - } - } -} - diff --git a/Scripts/Utilities/Serialization/ObjectIdentifier.cs.meta b/Scripts/Utilities/Serialization/ObjectIdentifier.cs.meta deleted file mode 100644 index 508a4c6..0000000 --- a/Scripts/Utilities/Serialization/ObjectIdentifier.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 0c19f3e134862e74dbc98cb514a82ef5 -timeCreated: 1435843519 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/SaveLoad.cs b/Scripts/Utilities/Serialization/SaveLoad.cs deleted file mode 100644 index ce7ca71..0000000 --- a/Scripts/Utilities/Serialization/SaveLoad.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.IO; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; - -namespace UnityEngine.UI.Extensions -{ - public static class SaveLoad - { - - //You may define any path you like, such as "c:/Saved Games" - //remember to use slashes instead of backslashes! ("/" instead of "\") - //Application.DataPath: http://docs.unity3d.com/ScriptReference/Application-dataPath.html - //Application.persistentDataPath: http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html - public static string saveGamePath = Application.persistentDataPath + "/Saved Games/"; - - public static void Save(SaveGame saveGame) - { - - BinaryFormatter bf = new BinaryFormatter(); - - // 1. Construct a SurrogateSelector object - SurrogateSelector ss = new SurrogateSelector(); - // 2. Add the ISerializationSurrogates to our new SurrogateSelector - AddSurrogates(ref ss); - // 3. Have the formatter use our surrogate selector - bf.SurrogateSelector = ss; - - //Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located - //You can also use any path you like - CheckPath(saveGamePath); - - FileStream file = File.Create(saveGamePath + saveGame.savegameName + ".sav"); //you can call it anything you want including the file extension - bf.Serialize(file, saveGame); - file.Close(); - Debug.Log("Saved Game: " + saveGame.savegameName); - - } - - public static SaveGame Load(string gameToLoad) - { - if (File.Exists(saveGamePath + gameToLoad + ".sav")) - { - - BinaryFormatter bf = new BinaryFormatter(); - // 1. Construct a SurrogateSelector object - SurrogateSelector ss = new SurrogateSelector(); - // 2. Add the ISerializationSurrogates to our new SurrogateSelector - AddSurrogates(ref ss); - // 3. Have the formatter use our surrogate selector - bf.SurrogateSelector = ss; - - FileStream file = File.Open(saveGamePath + gameToLoad + ".sav", FileMode.Open); - SaveGame loadedGame = (SaveGame)bf.Deserialize(file); - file.Close(); - Debug.Log("Loaded Game: " + loadedGame.savegameName); - return loadedGame; - } - else - { - Debug.Log(gameToLoad + " does not exist!"); - return null; - } - } - - private static void AddSurrogates(ref SurrogateSelector ss) - { - Vector2Surrogate Vector2_SS = new Vector2Surrogate(); - ss.AddSurrogate(typeof(Vector2), - new StreamingContext(StreamingContextStates.All), - Vector2_SS); - - Vector3Surrogate Vector3_SS = new Vector3Surrogate(); - ss.AddSurrogate(typeof(Vector3), - new StreamingContext(StreamingContextStates.All), - Vector3_SS); - - Vector4Surrogate Vector4_SS = new Vector4Surrogate(); - ss.AddSurrogate(typeof(Vector4), - new StreamingContext(StreamingContextStates.All), - Vector4_SS); - - ColorSurrogate Color_SS = new ColorSurrogate(); - ss.AddSurrogate(typeof(Color), - new StreamingContext(StreamingContextStates.All), - Color_SS); - - QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate(); - ss.AddSurrogate(typeof(Quaternion), - new StreamingContext(StreamingContextStates.All), - Quaternion_SS); - - //Reserved for future implementation - //Texture2DSurrogate Texture2D_SS = new Texture2DSurrogate(); - //ss.AddSurrogate(typeof(Texture2D), - // new StreamingContext(StreamingContextStates.All), - // Texture2D_SS); - //GameObjectSurrogate GameObject_SS = new GameObjectSurrogate(); - //ss.AddSurrogate(typeof(GameObject), - // new StreamingContext(StreamingContextStates.All), - // GameObject_SS); - //TransformSurrogate Transform_SS = new TransformSurrogate(); - //ss.AddSurrogate(typeof(Transform), - // new StreamingContext(StreamingContextStates.All), - // Transform_SS); - } - - private static void CheckPath(string path) - { - try - { - // Determine whether the directory exists. - if (Directory.Exists(path)) - { - //Debug.Log("That path exists already."); - return; - } - - // Try to create the directory. - //DirectoryInfo dir = Directory.CreateDirectory(path); - Directory.CreateDirectory(path); - Debug.Log("The directory was created successfully at " + path); - - } - catch (Exception e) - { - Debug.Log("The process failed: " + e.ToString()); - } - finally { } - } - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/SaveLoad.cs.meta b/Scripts/Utilities/Serialization/SaveLoad.cs.meta deleted file mode 100644 index 04876be..0000000 --- a/Scripts/Utilities/Serialization/SaveLoad.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b920ef6d49aee1a48926564263c95432 -timeCreated: 1435845727 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/SaveLoadMenu.cs b/Scripts/Utilities/Serialization/SaveLoadMenu.cs deleted file mode 100644 index 8edff35..0000000 --- a/Scripts/Utilities/Serialization/SaveLoadMenu.cs +++ /dev/null @@ -1,438 +0,0 @@ -using System;//for Type class -using System.Collections; -using System.Collections.Generic; -using System.Reflection; - -namespace UnityEngine.UI.Extensions -{ - public class SaveLoadMenu : MonoBehaviour - { - - public bool showMenu; - public bool usePersistentDataPath = true; - public string savePath; - public Dictionary prefabDictionary; - - // Use this for initialization - void Start() - { - if (usePersistentDataPath == true) - { - savePath = Application.persistentDataPath + "/Saved Games/"; - } - - prefabDictionary = new Dictionary(); - GameObject[] prefabs = Resources.LoadAll(""); - foreach (GameObject loadedPrefab in prefabs) - { - if (loadedPrefab.GetComponent()) - { - prefabDictionary.Add(loadedPrefab.name, loadedPrefab); - Debug.Log("Added GameObject to prefabDictionary: " + loadedPrefab.name); - } - } - } - - // Update is called once per frame - void Update() - { - - if (Input.GetKeyDown(KeyCode.Escape)) - { - showMenu = !showMenu; - } - - if (Input.GetKeyDown(KeyCode.F5)) - { - SaveGame(); - } - - if (Input.GetKeyDown(KeyCode.F9)) - { - LoadGame(); - } - } - - - - void OnGUI() - { - - if (showMenu == true) - { - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - GUILayout.BeginVertical(); - GUILayout.FlexibleSpace(); - - if (GUILayout.Button("Exit to Windows")) - { - Application.Quit(); - return; - } - - if (GUILayout.Button("Save Game")) - { - - SaveGame(); - return; - } - - if (GUILayout.Button("Load Game")) - { - LoadGame(); - return; - } - - GUILayout.FlexibleSpace(); - GUILayout.EndVertical(); - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - } - } - - IEnumerator wait(float time) - { - yield return new WaitForSeconds(time); - } - - //Use this for quicksaving - public void SaveGame() - { - SaveGame("QuickSave"); - } - - //use this one for specifying a filename - public void SaveGame(string saveGameName) - { - - if (string.IsNullOrEmpty(saveGameName)) - { - Debug.Log("SaveGameName is null or empty!"); - return; - } - - SaveLoad.saveGamePath = savePath; - - //Create a new instance of SaveGame. This will hold all the data that should be saved in our scene. - SaveGame newSaveGame = new SaveGame(); - newSaveGame.savegameName = saveGameName; - - List goList = new List(); - - //Find all ObjectIdentifier components in the scene. - //Since we can access the gameObject to which each one belongs with .gameObject, we thereby get all GameObject in the scene which should be saved! - ObjectIdentifier[] objectsToSerialize = FindObjectsOfType(typeof(ObjectIdentifier)) as ObjectIdentifier[]; - //Go through the "raw" collection of components - foreach (ObjectIdentifier objectIdentifier in objectsToSerialize) - { - //if the gameObject shouldn't be saved, for whatever reason (maybe it's a temporary ParticleSystem that will be destroyed anyway), ignore it - if (objectIdentifier.dontSave == true) - { - Debug.Log("GameObject " + objectIdentifier.gameObject.name + " is set to dontSave = true, continuing loop."); - continue; - } - - //First, we will set the ID of the GO if it doesn't already have one. - if (string.IsNullOrEmpty(objectIdentifier.id) == true) - { - objectIdentifier.SetID(); - } - - //store it in the goList temporarily, so we can first set it's ID (done above), - //then go through the list and call all OnSerialize methods on it, - //and finally go through the list again to pack the GO and add the packed data to the sceneObjects list of the new SaveGame. - goList.Add(objectIdentifier.gameObject); - } - - //This is a good time to call any functions on the GO that should be called before it gets serialized as part of a SaveGame. Example below. - foreach (GameObject go in goList) - { - go.SendMessage("OnSerialize", SendMessageOptions.DontRequireReceiver); - } - - foreach (GameObject go2 in goList) - { - //Convert the GameObject's data into a form that can be serialized (an instance of SceneObject), - //and add it to the SaveGame instance's list of SceneObjects. - newSaveGame.sceneObjects.Add(PackGameObject(go2)); - } - - //Call the static method that serialized our game and writes the data to a file. - SaveLoad.Save(newSaveGame); - } - - //Use this for quickloading - public void LoadGame() - { - LoadGame("QuickSave"); - } - - //use this one for loading a saved gamt with a specific filename - public void LoadGame(string saveGameName) - { - - //First, we will destroy all objects in the scene which are not tagged with "DontDestroy" (such as Cameras, Managers of any type, and so on... things that should persist) - ClearScene(); - - //Call the static method that will attempt to load the specified file and deserialize it's data into a form that we can use - SaveGame loadedGame = SaveLoad.Load(saveGameName); - if (loadedGame == null) - { - Debug.Log("saveGameName " + saveGameName + "couldn't be found!"); - return; - } - - //create a new list that will hold all the gameObjects we will create anew from the deserialized data - List goList = new List(); - - //iterate through the loaded game's sceneObjects list to access each stored objet's data and reconstruct it with all it's components - foreach (SceneObject loadedObject in loadedGame.sceneObjects) - { - GameObject go_reconstructed = UnpackGameObject(loadedObject); - if (go_reconstructed != null) - { - //Add the reconstructed GO to the list we created earlier. - goList.Add(go_reconstructed); - } - } - - //Go through the list of reconstructed GOs and reassign any missing children - foreach (GameObject go in goList) - { - string parentId = go.GetComponent().idParent; - if (string.IsNullOrEmpty(parentId) == false) - { - foreach (GameObject go_parent in goList) - { - if (go_parent.GetComponent().id == parentId) - { - go.transform.parent = go_parent.transform; - } - } - } - } - - //This is when you might want to call any functions that should be called when a gameobject is loaded. Example below. - foreach (GameObject go2 in goList) - { - go2.SendMessage("OnDeserialize", SendMessageOptions.DontRequireReceiver); - } - - } - - public void ClearScene() - { - - //Clear the scene of all non-persistent GameObjects so we have a clean slate - object[] obj = GameObject.FindObjectsOfType(typeof(GameObject)); - foreach (object o in obj) - { - GameObject go = (GameObject)o; - - //if the GO is tagged with DontDestroy, ignore it. (Cameras, Managers, etc. which should survive loading) - //these kind of GO's shouldn't have an ObjectIdentifier component! - if (go.CompareTag("DontDestroy")) - { - Debug.Log("Keeping GameObject in the scene: " + go.name); - continue; - } - Destroy(go); - } - } - - public SceneObject PackGameObject(GameObject go) - { - - ObjectIdentifier objectIdentifier = go.GetComponent(); - - //Now, we create a new instance of SceneObject, which will hold all the GO's data, including it's components. - SceneObject sceneObject = new SceneObject(); - sceneObject.name = go.name; - sceneObject.prefabName = objectIdentifier.prefabName; - sceneObject.id = objectIdentifier.id; - if (go.transform.parent != null && go.transform.parent.GetComponent() == true) - { - sceneObject.idParent = go.transform.parent.GetComponent().id; - } - else - { - sceneObject.idParent = null; - } - - //in this case, we will only store MonoBehavior scripts that are on the GO. The Transform is stored as part of the ScenObject isntance (assigned further down below). - //If you wish to store other component types, you have to find you own ways to do it if the "easy" way that is used for storing components doesn't work for them. - List componentTypesToAdd = new List() { - "UnityEngine.MonoBehaviour" - }; - - //This list will hold only the components that are actually stored (MonoBehavior scripts, in this case) - List components_filtered = new List(); - - //Collect all the components that are attached to the GO. - //This includes MonoBehavior scripts, Renderers, Transform, Animator... - //If it - object[] components_raw = go.GetComponents() as object[]; - foreach (object component_raw in components_raw) - { - if (componentTypesToAdd.Contains(component_raw.GetType().BaseType.FullName)) - { - components_filtered.Add(component_raw); - } - } - - foreach (object component_filtered in components_filtered) - { - sceneObject.objectComponents.Add(PackComponent(component_filtered)); - } - - //Assign all the GameObject's misc. values - sceneObject.position = go.transform.position; - sceneObject.localScale = go.transform.localScale; - sceneObject.rotation = go.transform.rotation; - sceneObject.active = go.activeSelf; - - return sceneObject; - } - - public ObjectComponent PackComponent(object component) - { - - //This will go through all the fields of a component, check each one if it is serializable, and it it should be stored, - //and puts it into the fields dictionary of a new instance of ObjectComponent, - //with the field's name as key and the field's value as (object)value - //for example, if a script has the field "float myFloat = 12.5f", then the key would be "myFloat" and the value "12.5f", tha latter stored as an object. - - ObjectComponent newObjectComponent = new ObjectComponent(); - newObjectComponent.fields = new Dictionary(); - - const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; - var componentType = component.GetType(); - FieldInfo[] fields = componentType.GetFields(flags); - - newObjectComponent.componentName = componentType.ToString(); - - foreach (FieldInfo field in fields) - { - - if (field != null) - { - if (field.FieldType.IsSerializable == false) - { - //Debug.Log(field.Name + " (Type: " + field.FieldType + ") is not marked as serializable. Continue loop."); - continue; - } - if (TypeSystem.IsEnumerableType(field.FieldType) == true || TypeSystem.IsCollectionType(field.FieldType) == true) - { - Type elementType = TypeSystem.GetElementType(field.FieldType); - //Debug.Log(field.Name + " -> " + elementType); - - if (elementType.IsSerializable == false) - { - continue; - } - } - - object[] attributes = field.GetCustomAttributes(typeof(DontSaveField), true); - bool stop = false; - foreach (Attribute attribute in attributes) - { - if (attribute.GetType() == typeof(DontSaveField)) - { - //Debug.Log(attribute.GetType().Name.ToString()); - stop = true; - break; - } - } - if (stop == true) - { - continue; - } - - newObjectComponent.fields.Add(field.Name, field.GetValue(component)); - //Debug.Log(field.Name + " (Type: " + field.FieldType + "): " + field.GetValue(component)); - } - } - return newObjectComponent; - } - - public GameObject UnpackGameObject(SceneObject sceneObject) - { - //This is where our prefabDictionary above comes in. Each GameObject that was saved needs to be reconstucted, so we need a Prefab, - //and we know which prefab it is because we stored the GameObject's prefab name in it's ObjectIdentifier/SceneObject script/class. - //Theoretically, we could even reconstruct GO's that have no prefab by instatiating an empty GO and filling it with the required components... I'lll leave that to you. - if (prefabDictionary.ContainsKey(sceneObject.prefabName) == false) - { - Debug.Log("Can't find key " + sceneObject.prefabName + " in SaveLoadMenu.prefabDictionary!"); - return null; - } - //instantiate the gameObject - GameObject go = Instantiate(prefabDictionary[sceneObject.prefabName], sceneObject.position, sceneObject.rotation) as GameObject; - - //Reassign values - go.name = sceneObject.name; - go.transform.localScale = sceneObject.localScale; - go.SetActive(sceneObject.active); - - if (go.GetComponent() == false) - { - //ObjectIdentifier oi = go.AddComponent(); - go.AddComponent(); - } - - ObjectIdentifier idScript = go.GetComponent(); - idScript.id = sceneObject.id; - idScript.idParent = sceneObject.idParent; - - UnpackComponents(ref go, sceneObject); - - //Destroy any children that were not referenced as having a parent - ObjectIdentifier[] childrenIds = go.GetComponentsInChildren(); - foreach (ObjectIdentifier childrenIDScript in childrenIds) - { - if (childrenIDScript.transform != go.transform) - { - if (string.IsNullOrEmpty(childrenIDScript.id) == true) - { - Destroy(childrenIDScript.gameObject); - } - } - } - - return go; - } - - public void UnpackComponents(ref GameObject go, SceneObject sceneObject) - { - //Go through the stored object's component list and reassign all values in each component, and add components that are missing - foreach (ObjectComponent obc in sceneObject.objectComponents) - { - - if (go.GetComponent(obc.componentName) == false) - { - Type componentType = Type.GetType(obc.componentName); - go.AddComponent(componentType); - } - - object obj = go.GetComponent(obc.componentName) as object; - - var tp = obj.GetType(); - foreach (KeyValuePair p in obc.fields) - { - - var fld = tp.GetField(p.Key, - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | - BindingFlags.SetField); - if (fld != null) - { - - object value = p.Value; - fld.SetValue(obj, value); - } - } - } - } - - } - -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/SaveLoadMenu.cs.meta b/Scripts/Utilities/Serialization/SaveLoadMenu.cs.meta deleted file mode 100644 index 172f094..0000000 --- a/Scripts/Utilities/Serialization/SaveLoadMenu.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: bd4dc9485ec174c44bb7aa7b9d65f7e4 -timeCreated: 1435848358 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Serialization-ReadME.md b/Scripts/Utilities/Serialization/Serialization-ReadME.md deleted file mode 100644 index 9eb1714..0000000 --- a/Scripts/Utilities/Serialization/Serialization-ReadME.md +++ /dev/null @@ -1,27 +0,0 @@ -Sourced from Unity forums - [serializehelper-free-save-and-load-utility-de-serialize-all-objects-in-your-scene](http://forum.unity3d.com/threads/serializehelper-free-save-and-load-utility-de-serialize-all-objects-in-your-scene.338148/) - -#Description# -The serializationHelper is a useful extension to Unity to be able to serialise the base Unity structs (such as Vector3 / Quanterion) without having to employ custom classes or convertors. -It uses the standard ISerializationSurrogates to provide a serialisation interface for the base classes themselves - -This starter pack was provided via Unity forum guru [Cherno](http://forum.unity3d.com/members/cherno.245586/) - -#What's included# -Not all classes have had surrogates provided for as yet, here is what is working: -* Color -* Quaternion -* Vector2 -* Vector3 -* Vector4 - -There are some initial templates for other items but they do not seem fully implemented yet: -* GameObject -* Texture2D -* Transform -Feel free to re-enable them by uncommenting their code (in the Surrogates folder) and test. Have a look at the working examples for reference. - -#Contribute# -Feel free to get other surrogates working and submit them back to the project to increase the scope and enjoy - -#Notes# -Part of the reason I added this library, since it's not really UI, is to support the LZF compression component. Both together provide a useful solution for packing data to save or send over a network. \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Serialization-ReadME.md.meta b/Scripts/Utilities/Serialization/Serialization-ReadME.md.meta deleted file mode 100644 index c690307..0000000 --- a/Scripts/Utilities/Serialization/Serialization-ReadME.md.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0b972ef82b6647d4fa774ed6de28650c -timeCreated: 1464945707 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates.meta b/Scripts/Utilities/Serialization/Surrogates.meta deleted file mode 100644 index 2e25e2e..0000000 --- a/Scripts/Utilities/Serialization/Surrogates.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 2e48060c8c4bc3d448dcaffe916307ca -folderAsset: yes -timeCreated: 1435845247 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/ColorSurrogate.cs b/Scripts/Utilities/Serialization/Surrogates/ColorSurrogate.cs deleted file mode 100644 index ac74308..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/ColorSurrogate.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Runtime.Serialization; -namespace UnityEngine.UI.Extensions -{ - public sealed class ColorSurrogate : ISerializationSurrogate - { - - // Method called to serialize a Vector3 object - public void GetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context) - { - Color color = (Color)obj; - info.AddValue("r", color.r); - info.AddValue("g", color.g); - info.AddValue("b", color.b); - info.AddValue("a", color.a); - } - - // Method called to deserialize a Vector3 object - public System.Object SetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context, - ISurrogateSelector selector) - { - Color color = (Color)obj; - color.r = (float)info.GetValue("r", typeof(float)); - color.g = (float)info.GetValue("g", typeof(float)); - color.b = (float)info.GetValue("b", typeof(float)); - color.a = (float)info.GetValue("a", typeof(float)); - obj = color; - return obj; - } - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/ColorSurrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/ColorSurrogate.cs.meta deleted file mode 100644 index d7985e4..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/ColorSurrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 81d3e9dc19c30c24483b1f77953a82c3 -timeCreated: 1435845247 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/GameObjectSurrogate.cs b/Scripts/Utilities/Serialization/Surrogates/GameObjectSurrogate.cs deleted file mode 100644 index 17cd50c..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/GameObjectSurrogate.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace UnityEngine.UI.Extensions -{ - /// - /// Doesn't seem fully implemented yet? - /// - //public sealed class GameObjectSurrogate : ISerializationSurrogate - //{ - - // // Method called to serialize a Vector3 object - // public void GetObjectData(System.Object obj, - // SerializationInfo info, StreamingContext context) - // { - - // GameObject go = (GameObject)obj; - // } - - // // Method called to deserialize a Vector3 object - // public System.Object SetObjectData(System.Object obj, - // SerializationInfo info, StreamingContext context, - // ISurrogateSelector selector) - // { - - // GameObject go = (GameObject)obj; - // return obj; - // } - //} -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/GameObjectSurrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/GameObjectSurrogate.cs.meta deleted file mode 100644 index b725ad4..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/GameObjectSurrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 2e0e2f61dca10bf4e95ecd579cc58e1a -timeCreated: 1435845247 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/QuaternionSurrogate.cs b/Scripts/Utilities/Serialization/Surrogates/QuaternionSurrogate.cs deleted file mode 100644 index 7896102..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/QuaternionSurrogate.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Runtime.Serialization; - -namespace UnityEngine.UI.Extensions -{ - public sealed class QuaternionSurrogate : ISerializationSurrogate - { - - // Method called to serialize a Vector3 object - public void GetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context) - { - - Quaternion quaternion = (Quaternion)obj; - info.AddValue("x", quaternion.x); - info.AddValue("y", quaternion.y); - info.AddValue("z", quaternion.z); - info.AddValue("w", quaternion.w); - } - - // Method called to deserialize a Vector3 object - public System.Object SetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context, - ISurrogateSelector selector) - { - - Quaternion quaternion = (Quaternion)obj; - quaternion.x = (float)info.GetValue("x", typeof(float)); - quaternion.y = (float)info.GetValue("y", typeof(float)); - quaternion.z = (float)info.GetValue("z", typeof(float)); - quaternion.w = (float)info.GetValue("w", typeof(float)); - obj = quaternion; - return obj; - } - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/QuaternionSurrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/QuaternionSurrogate.cs.meta deleted file mode 100644 index bed622f..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/QuaternionSurrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 095b25ad2d34e594bb0fdafe57f1cdcf -timeCreated: 1435851264 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/SurrogatesReadMe.txt b/Scripts/Utilities/Serialization/Surrogates/SurrogatesReadMe.txt deleted file mode 100644 index 0bb7a18..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/SurrogatesReadMe.txt +++ /dev/null @@ -1,12 +0,0 @@ -ISerializationSurrogates are used to tell a BinaryFormatter how to serialize and deserialize certain types. -For example, a BinaryFormatter can't (de)serialize a Vector3 instance. -This is true for most, or even all, Unity-specific types like Transform, GameObject, Color, Mesh, and so on. -What a ISerializationSurrogate does is tell the Formatter, if it is used, how to serialize and deserialize each field of a type. -A Vector3 is just made of three floats: x, y and z. These can easily be serialized one by one. -An ISS can't be written for the type GameObject that easily, as it is vastly more complex. The Formatter will throw an error when trying to serialize it. -However, we are using a workaround for saving & loading GOs anyway (by storing their positions, rotations, scales, active states, and components one by one), -so we can use a ISS for type GameObject that uses none of a GO's fields. Nothing will be serialized, but we won't get an error either, which is the point of the empty ISS. -Note that we could use the attribute [DontSerializeField] to make our algorithm skip a field of type GameObject, -but this will only work if the GO field sits in the class that is to be serialized itself. If we want to save a MonoBehavior script which contains a field of type (CustomClass), -which in turn contains a field of type GameObject, then this will not work as we can only go through each field of a component, not through each field of each field, so to speak. - diff --git a/Scripts/Utilities/Serialization/Surrogates/SurrogatesReadMe.txt.meta b/Scripts/Utilities/Serialization/Surrogates/SurrogatesReadMe.txt.meta deleted file mode 100644 index b587d63..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/SurrogatesReadMe.txt.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e65ea62503a78f14182bc6c9d9a05106 -timeCreated: 1435845250 -licenseType: Free -TextScriptImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/Texture2DSurrogate.cs b/Scripts/Utilities/Serialization/Surrogates/Texture2DSurrogate.cs deleted file mode 100644 index 1ec1fb5..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Texture2DSurrogate.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace UnityEngine.UI.Extensions -{ - /// - /// Doesn't seem fully implemented yet? - /// - //public sealed class Texture2DSurrogate : ISerializationSurrogate - //{ - - // // Method called to serialize a Vector3 object - // public void GetObjectData(System.Object obj, - // SerializationInfo info, StreamingContext context) - // { - - // Texture2D t = (Texture2D)obj; - // } - - // // Method called to deserialize a Vector3 object - // public System.Object SetObjectData(System.Object obj, - // SerializationInfo info, StreamingContext context, - // ISurrogateSelector selector) - // { - - // Texture2D t = (Texture2D)obj; - // return obj; - // } - //} -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/Texture2DSurrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/Texture2DSurrogate.cs.meta deleted file mode 100644 index 8fca6bc..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Texture2DSurrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 90fc034c9d310aa4fbff10d91d4d91ee -timeCreated: 1435845247 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/TransformSurrogate.cs b/Scripts/Utilities/Serialization/Surrogates/TransformSurrogate.cs deleted file mode 100644 index 173e4d7..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/TransformSurrogate.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace UnityEngine.UI.Extensions -{ - /// - /// Doesn't seem fully implemented yet? - /// - //public sealed class TransformSurrogate : ISerializationSurrogate - //{ - - // // Method called to serialize a Vector3 object - // public void GetObjectData(System.Object obj, - // SerializationInfo info, StreamingContext context) - // { - - // Transform tr = (Transform)obj; - // } - - // // Method called to deserialize a Vector3 object - // public System.Object SetObjectData(System.Object obj, - // SerializationInfo info, StreamingContext context, - // ISurrogateSelector selector) - // { - - // Transform tr = (Transform)obj; - - // return obj; - // } - //} -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/TransformSurrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/TransformSurrogate.cs.meta deleted file mode 100644 index fe306b5..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/TransformSurrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: c882de0bea6973f4fa729fa1dd81a99a -timeCreated: 1435845250 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/Vector2Surrogate.cs b/Scripts/Utilities/Serialization/Surrogates/Vector2Surrogate.cs deleted file mode 100644 index 9012279..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Vector2Surrogate.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Runtime.Serialization; - -namespace UnityEngine.UI.Extensions -{ - public sealed class Vector2Surrogate : ISerializationSurrogate - { - - // Method called to serialize a Vector2 object - public void GetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context) - { - Vector2 v2 = (Vector2)obj; - info.AddValue("x", v2.x); - info.AddValue("y", v2.y); - } - - // Method called to deserialize a Vector2 object - public System.Object SetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context, - ISurrogateSelector selector) - { - Vector2 v2 = (Vector2)obj; - v2.x = (float)info.GetValue("x", typeof(float)); - v2.y = (float)info.GetValue("y", typeof(float)); - obj = v2; - return obj; - } - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/Vector2Surrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/Vector2Surrogate.cs.meta deleted file mode 100644 index d27a7e6..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Vector2Surrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 02aba5388a28c944787d5d61deafed98 -timeCreated: 1464901177 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/Vector3Surrogate.cs b/Scripts/Utilities/Serialization/Surrogates/Vector3Surrogate.cs deleted file mode 100644 index 8015f9a..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Vector3Surrogate.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Runtime.Serialization; - -namespace UnityEngine.UI.Extensions -{ - public sealed class Vector3Surrogate : ISerializationSurrogate - { - - // Method called to serialize a Vector3 object - public void GetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context) - { - Vector3 v3 = (Vector3)obj; - info.AddValue("x", v3.x); - info.AddValue("y", v3.y); - info.AddValue("z", v3.z); - } - - // Method called to deserialize a Vector3 object - public System.Object SetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context, - ISurrogateSelector selector) - { - Vector3 v3 = (Vector3)obj; - v3.x = (float)info.GetValue("x", typeof(float)); - v3.y = (float)info.GetValue("y", typeof(float)); - v3.z = (float)info.GetValue("z", typeof(float)); - obj = v3; - return obj; - } - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/Vector3Surrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/Vector3Surrogate.cs.meta deleted file mode 100644 index 1243f99..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Vector3Surrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b812bdab84e09a8478923cbe2b562d61 -timeCreated: 1435845247 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Surrogates/Vector4Surrogate.cs b/Scripts/Utilities/Serialization/Surrogates/Vector4Surrogate.cs deleted file mode 100644 index 127710c..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Vector4Surrogate.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Runtime.Serialization; - -namespace UnityEngine.UI.Extensions -{ - public sealed class Vector4Surrogate : ISerializationSurrogate - { - - // Method called to serialize a Vector4 object - public void GetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context) - { - Vector4 v4 = (Vector4)obj; - info.AddValue("x", v4.x); - info.AddValue("y", v4.y); - info.AddValue("w", v4.w); - info.AddValue("z", v4.z); - } - - // Method called to deserialize a Vector4 object - public System.Object SetObjectData(System.Object obj, - SerializationInfo info, StreamingContext context, - ISurrogateSelector selector) - { - Vector4 v4 = (Vector4)obj; - v4.x = (float)info.GetValue("x", typeof(float)); - v4.y = (float)info.GetValue("y", typeof(float)); - v4.w = (float)info.GetValue("w", typeof(float)); - v4.z = (float)info.GetValue("z", typeof(float)); - obj = v4; - return obj; - } - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Surrogates/Vector4Surrogate.cs.meta b/Scripts/Utilities/Serialization/Surrogates/Vector4Surrogate.cs.meta deleted file mode 100644 index 3ec73a8..0000000 --- a/Scripts/Utilities/Serialization/Surrogates/Vector4Surrogate.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b8d9d01e813a7f647b39998b6e31af44 -timeCreated: 1464901177 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Utilities.meta b/Scripts/Utilities/Serialization/Utilities.meta deleted file mode 100644 index 8f91198..0000000 --- a/Scripts/Utilities/Serialization/Utilities.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: b02d1e4ae10379b42a2fa24244dd991a -folderAsset: yes -timeCreated: 1435851264 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/Serialization/Utilities/TypeSystem.cs b/Scripts/Utilities/Serialization/Utilities/TypeSystem.cs deleted file mode 100644 index a3db8a2..0000000 --- a/Scripts/Utilities/Serialization/Utilities/TypeSystem.cs +++ /dev/null @@ -1,63 +0,0 @@ -//This is used to get teh element type of a collection -//source: http://stackoverflow.com/questions/1900353/how-to-get-the-type-contained-in-a-collection-through-reflection -//via http://blogs.msdn.com/b/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx -//The methods IsEnumerableType and IsCollectionType were added by myself (Cherno). Use them to find out wether a Type is a collection (array, List,...) - -using System; -using System.Collections.Generic; - -namespace UnityEngine.UI.Extensions -{ - internal static class TypeSystem - { - internal static Type GetElementType(Type seqType) - { - Type ienum = FindIEnumerable(seqType); - if (ienum == null) return seqType; - return ienum.GetGenericArguments()[0]; - } - private static Type FindIEnumerable(Type seqType) - { - if (seqType == null || seqType == typeof(string)) - return null; - if (seqType.IsArray) - return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType()); - if (seqType.IsGenericType) - { - foreach (Type arg in seqType.GetGenericArguments()) - { - Type ienum = typeof(IEnumerable<>).MakeGenericType(arg); - if (ienum.IsAssignableFrom(seqType)) - { - return ienum; - } - } - } - Type[] ifaces = seqType.GetInterfaces(); - if (ifaces != null && ifaces.Length > 0) - { - foreach (Type iface in ifaces) - { - Type ienum = FindIEnumerable(iface); - if (ienum != null) return ienum; - } - } - if (seqType.BaseType != null && seqType.BaseType != typeof(object)) - { - return FindIEnumerable(seqType.BaseType); - } - return null; - } - - //is a type a collection? - public static bool IsEnumerableType(Type type) - { - return (type.GetInterface("IEnumerable") != null); - } - - public static bool IsCollectionType(Type type) - { - return (type.GetInterface("ICollection") != null); - } - } -} \ No newline at end of file diff --git a/Scripts/Utilities/Serialization/Utilities/TypeSystem.cs.meta b/Scripts/Utilities/Serialization/Utilities/TypeSystem.cs.meta deleted file mode 100644 index 07490b5..0000000 --- a/Scripts/Utilities/Serialization/Utilities/TypeSystem.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: ee3f0396a2ae70749a914a63018d074f -timeCreated: 1435851264 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Utilities/UISelectableExtension.cs b/Scripts/Utilities/UISelectableExtension.cs index b677019..155872d 100644 --- a/Scripts/Utilities/UISelectableExtension.cs +++ b/Scripts/Utilities/UISelectableExtension.cs @@ -9,65 +9,65 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { - /// - /// UIButton - /// - [AddComponentMenu("UI/Extensions/UI Selectable Extension")] - [RequireComponent(typeof(Selectable))] - public class UISelectableExtension : MonoBehaviour, IPointerDownHandler, IPointerUpHandler - { - #region Sub-Classes - [System.Serializable] - public class UIButtonEvent : UnityEvent { } - #endregion + /// + /// UIButton + /// + [AddComponentMenu("UI/Extensions/UI Selectable Extension")] + [RequireComponent(typeof(Selectable))] + public class UISelectableExtension : MonoBehaviour, IPointerDownHandler, IPointerUpHandler + { + #region Sub-Classes + [System.Serializable] + public class UIButtonEvent : UnityEvent { } + #endregion - #region Events + #region Events [Tooltip("Event that fires when a button is initially pressed down")] - public UIButtonEvent OnButtonPress; + public UIButtonEvent OnButtonPress; [Tooltip("Event that fires when a button is released")] - public UIButtonEvent OnButtonRelease; + public UIButtonEvent OnButtonRelease; [Tooltip("Event that continually fires while a button is held down")] - public UIButtonEvent OnButtonHeld; - #endregion + public UIButtonEvent OnButtonHeld; + #endregion private bool _pressed; - private PointerEventData _heldEventData; + private PointerEventData _heldEventData; - void IPointerDownHandler.OnPointerDown(PointerEventData eventData) - { - //Can't set the state as it's too locked down. + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + //Can't set the state as it's too locked down. //DoStateTransition(SelectionState.Pressed, false); - if (OnButtonPress != null) - { - OnButtonPress.Invoke(eventData.button); - } + if (OnButtonPress != null) + { + OnButtonPress.Invoke(eventData.button); + } _pressed = true; - _heldEventData = eventData; - } + _heldEventData = eventData; + } - void IPointerUpHandler.OnPointerUp(PointerEventData eventData) - { - //DoStateTransition(SelectionState.Normal, false); + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + //DoStateTransition(SelectionState.Normal, false); - if (OnButtonRelease != null) - { - OnButtonRelease.Invoke(eventData.button); - } - _pressed = false; - _heldEventData = null; - } + if (OnButtonRelease != null) + { + OnButtonRelease.Invoke(eventData.button); + } + _pressed = false; + _heldEventData = null; + } - void Update() + void Update() { if (!_pressed) return; if (OnButtonHeld != null) - { - OnButtonHeld.Invoke(_heldEventData.button); - } + { + OnButtonHeld.Invoke(_heldEventData.button); + } } /// @@ -110,10 +110,10 @@ namespace UnityEngine.UI.Extensions #endif } - //Fixed UISelectableExtension inactive bug (if gameObject becomes inactive while button is held down it never goes back to _pressed = false) - void OnDisable() - { - _pressed = false; - } - } + //Fixed UISelectableExtension inactive bug (if gameObject becomes inactive while button is held down it never goes back to _pressed = false) + void OnDisable() + { + _pressed = false; + } + } } \ No newline at end of file diff --git a/UnityUIExtensions.unitypackage b/UnityUIExtensions.unitypackage index a2a48df..88a79a1 100644 Binary files a/UnityUIExtensions.unitypackage and b/UnityUIExtensions.unitypackage differ diff --git a/package.json b/package.json index dc5f601..193a874 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unity ui extensions", - "version": "1.2.0.3", + "version": "2.0.0.0", "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", "author": "Simon darkside Jackson <@SimonDarksideJ>", "contributors": [{