| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | namespace GDX.DataTables.CellValues |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// A <see cref="DataTableBase" /> <see cref="Quaternion" /> cell reference. |
| | 12 | | /// </summary> |
| | 13 | | [Serializable] |
| | 14 | | public struct QuaternionCellValue |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// The cached struct of the referenced <see cref="DataTable" /> cell. |
| | 18 | | /// </summary> |
| | 19 | | Quaternion m_CachedValue; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// The cached <see cref="DataTable" /> version found when last updating <see cref="m_CachedValue" />. |
| | 23 | | /// </summary> |
| | 24 | | ulong m_TableVersion; |
| | 25 | | #pragma warning disable IDE1006 |
| | 26 | | // ReSharper disable InconsistentNaming |
| | 27 | | /// <summary> |
| | 28 | | /// The <see cref="DataTableBase" /> polled for cell data. |
| | 29 | | /// </summary> |
| | 30 | | public DataTableBase DataTable; |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// The unique column identifier used when accessing the <see cref="DataTable" />. |
| | 34 | | /// </summary> |
| | 35 | | public int ColumnIdentifier; |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// The unique row identifier used when accessing the <see cref="DataTable" />. |
| | 39 | | /// </summary> |
| | 40 | | public int RowIdentifier; |
| | 41 | | // ReSharper enable InconsistentNaming |
| | 42 | | #pragma warning restore IDE1006 |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Creates a <see cref="QuaternionCellValue" />. |
| | 46 | | /// </summary> |
| | 47 | | /// <param name="dataTable">The referenced <see cref="DataTableBase" />.</param> |
| | 48 | | /// <param name="rowIdentifier">The unique row identifier to use when polling the <paramref name="dataTable" />. |
| | 49 | | /// <param name="columnIdentifier">The unique column identifier to use when polling the <paramref name="dataTabl |
| | 50 | | public QuaternionCellValue(DataTableBase dataTable, int rowIdentifier, int columnIdentifier) |
| 0 | 51 | | { |
| 0 | 52 | | DataTable = dataTable; |
| 0 | 53 | | RowIdentifier = rowIdentifier; |
| 0 | 54 | | ColumnIdentifier = columnIdentifier; |
| 0 | 55 | | m_TableVersion = 0; |
| 0 | 56 | | m_CachedValue = default; |
| 0 | 57 | | Get(); |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Get the <see cref="Quaternion" /> value referenced from the <see cref="DataTableBase" />. |
| | 62 | | /// </summary> |
| | 63 | | /// <remarks> |
| | 64 | | /// This will evaluate if the version of the table matches the internally cached version, and will update |
| | 65 | | /// the cached reference if necessary. |
| | 66 | | /// </remarks> |
| | 67 | | /// <returns>A <see cref="Quaternion" /> struct.</returns> |
| | 68 | | public Quaternion Get() |
| 0 | 69 | | { |
| 0 | 70 | | if (m_TableVersion == DataTable.GetDataVersion()) |
| 0 | 71 | | { |
| 0 | 72 | | return m_CachedValue; |
| | 73 | | } |
| | 74 | |
|
| 0 | 75 | | m_CachedValue = DataTable.GetQuaternion(RowIdentifier, ColumnIdentifier); |
| 0 | 76 | | m_TableVersion = DataTable.GetDataVersion(); |
| 0 | 77 | | return m_CachedValue; |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | /// <summary> |
| | 81 | | /// Get the internally cached version of the <see cref="DataTableBase" />'s data version. |
| | 82 | | /// </summary> |
| | 83 | | /// <returns>A version number.</returns> |
| | 84 | | public ulong GetDataVersion() |
| 0 | 85 | | { |
| 0 | 86 | | return m_TableVersion; |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// Get the cached value without a version check. |
| | 91 | | /// </summary> |
| | 92 | | /// <remarks> |
| | 93 | | /// This can respond with a default value if a <see cref="Get" /> call has not been made yet to populate the |
| | 94 | | /// internally cached value. |
| | 95 | | /// </remarks> |
| | 96 | | /// <returns>A <see cref="Quaternion" /> struct.</returns> |
| | 97 | | public Quaternion GetUnsafe() |
| 0 | 98 | | { |
| 0 | 99 | | return m_CachedValue; |
| 0 | 100 | | } |
| | 101 | |
|
| | 102 | | /// <summary> |
| | 103 | | /// Sets the cached value of the struct and by default, updates the associated <see cref="DataTableBase" />. |
| | 104 | | /// </summary> |
| | 105 | | /// <remarks>Updating the <see cref="DataTableBase" /> will update the cached table version.</remarks> |
| | 106 | | /// <param name="eulerAngles">A <see cref="Vector3" /> struct.</param> |
| | 107 | | /// <param name="updateTable">Should the value be pushed back to the referenced <see cref="DataTableBase" /> cel |
| | 108 | | public void Set(Vector3 eulerAngles, bool updateTable = true) |
| 0 | 109 | | { |
| 0 | 110 | | Set(Quaternion.Euler(eulerAngles), updateTable); |
| 0 | 111 | | } |
| | 112 | |
|
| | 113 | | /// <summary> |
| | 114 | | /// Sets the cached value of the struct and by default, updates the associated <see cref="DataTableBase" />. |
| | 115 | | /// </summary> |
| | 116 | | /// <remarks>Updating the <see cref="DataTableBase" /> will update the cached table version.</remarks> |
| | 117 | | /// <param name="newValue">A <see cref="Vector4" /> struct.</param> |
| | 118 | | /// <param name="updateTable">Should the value be pushed back to the referenced <see cref="DataTableBase" /> cel |
| | 119 | | public void Set(Vector4 newValue, bool updateTable = true) |
| 0 | 120 | | { |
| 0 | 121 | | Set(new Quaternion(newValue.x, newValue.y, newValue.z, newValue.w), updateTable); |
| 0 | 122 | | } |
| | 123 | |
|
| | 124 | | /// <summary> |
| | 125 | | /// Sets the cached value of the struct and by default, updates the associated <see cref="DataTableBase" />. |
| | 126 | | /// </summary> |
| | 127 | | /// <remarks>Updating the <see cref="DataTableBase" /> will update the cached table version.</remarks> |
| | 128 | | /// <param name="newValue">A <see cref="Quaternion" /> struct.</param> |
| | 129 | | /// <param name="updateTable">Should the value be pushed back to the referenced <see cref="DataTableBase" /> cel |
| | 130 | | public void Set(Quaternion newValue, bool updateTable = true) |
| 0 | 131 | | { |
| 0 | 132 | | m_CachedValue = newValue; |
| 0 | 133 | | if (updateTable) |
| 0 | 134 | | { |
| 0 | 135 | | m_TableVersion = DataTable.SetQuaternion(RowIdentifier, ColumnIdentifier, newValue); |
| 0 | 136 | | } |
| 0 | 137 | | } |
| | 138 | |
|
| | 139 | | /// <summary> |
| | 140 | | /// Get the <see cref="Serializable.SerializableTypes" /> which this struct supports. |
| | 141 | | /// </summary> |
| | 142 | | /// <returns>A <see cref="Serializable.SerializableTypes" />.</returns> |
| | 143 | | public static Serializable.SerializableTypes GetSupportedType() |
| 0 | 144 | | { |
| 0 | 145 | | return Serializable.SerializableTypes.Quaternion; |
| 0 | 146 | | } |
| | 147 | | } |
| | 148 | | } |