diff --git a/Assets/Resources/Unity-Theme Database.asset b/Assets/Resources/Unity-Theme Database.asset deleted file mode 100644 index 2c54cb6..0000000 --- a/Assets/Resources/Unity-Theme Database.asset +++ /dev/null @@ -1,164 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 06ff1dc9c64b296469122d9b7a7d6df0, type: 3} - m_Name: Unity-Theme Database - m_EditorClassIdentifier: - debugLevel: 0 - currentThemeIndex: 1 - colors: - - guid: c1a53828-f2d5-4129-ac25-a315c3584b93 - name: Primary - - guid: 9e099043-a40e-460e-8c7d-a8f382d08869 - name: On Primary - - guid: d56cc8cb-8732-4810-b374-034acd1b667d - name: Primary Container - - guid: 595cc7f8-00e2-436d-b252-cdacf09534ea - name: On Primary Container - - guid: a0c561f4-e79c-4d8f-9fef-1b6ee7b42b8c - name: Secondary - - guid: 504c48e6-eec6-48e3-9800-318b0432bf89 - name: On Secondary - - guid: 5d255797-0487-457d-9309-dea410a1f02b - name: Secondary Container - - guid: 79554701-52d6-45fa-bb83-0234e9561513 - name: On Secondary Container - - guid: c17be719-c931-47e7-8478-115cd5ccfd24 - name: Tertiary - - guid: bf3106a2-589e-48da-86ac-e71c39583d83 - name: On Tertiary - - guid: 1c31e8b9-953e-4278-8afe-8308ab87227a - name: Tertiary Container - - guid: e0a80c4c-e254-4129-adf7-1573036bb1ab - name: On Tertiary Container - - guid: 9c7c42d7-4d10-468b-9462-eed1222bb2ab - name: Error - - guid: e5b85ceb-41f7-4e94-8ad5-53eba5509e42 - name: On Error - - guid: fa46b747-6bc6-4e27-aa52-501174599797 - name: Error Container - - guid: 672d7657-2bde-4509-9317-79b9ac48aad7 - name: On Error Container - - guid: 6b072958-1f3d-42d4-9ca9-705f108286b7 - name: Background - - guid: 0774ae24-94db-4d65-b751-3f0c755ce1bc - name: On Background - - guid: 2d9a5145-3e26-4550-be57-3527a57a2172 - name: Surface - - guid: 8cf63047-10b4-496a-8a85-52d3771a28f0 - name: On Surface - - guid: 1429e101-aae5-4ae8-9490-6435a57f9a37 - name: Outline - - guid: 6f6bb671-9e5f-48db-9131-5b41f1d4e6c4 - name: Surface-Variant - - guid: c6100240-c4e5-4485-994e-a1cafc3c4749 - name: On Surface-Variant - themes: - - guid: a1aa6e11-8df7-47e4-a920-e9eb1e48312c - expanded: 1 - themeName: Light - colors: - - guid: c1a53828-f2d5-4129-ac25-a315c3584b93 - color: {r: 0.40392157, g: 0.3137255, b: 0.6431373, a: 1} - - guid: 9e099043-a40e-460e-8c7d-a8f382d08869 - color: {r: 1, g: 1, b: 1, a: 1} - - guid: d56cc8cb-8732-4810-b374-034acd1b667d - color: {r: 0.91764706, g: 0.8666667, b: 1, a: 1} - - guid: 595cc7f8-00e2-436d-b252-cdacf09534ea - color: {r: 0.12941177, g: 0, b: 0.3647059, a: 1} - - guid: a0c561f4-e79c-4d8f-9fef-1b6ee7b42b8c - color: {r: 0.38431373, g: 0.35686275, b: 0.44313726, a: 1} - - guid: 504c48e6-eec6-48e3-9800-318b0432bf89 - color: {r: 1, g: 1, b: 1, a: 1} - - guid: 5d255797-0487-457d-9309-dea410a1f02b - color: {r: 0.9098039, g: 0.87058824, b: 0.972549, a: 1} - - guid: 79554701-52d6-45fa-bb83-0234e9561513 - color: {r: 0.11372549, g: 0.09803922, b: 0.16862746, a: 1} - - guid: c17be719-c931-47e7-8478-115cd5ccfd24 - color: {r: 0.49019608, g: 0.32156864, b: 0.3764706, a: 1} - - guid: bf3106a2-589e-48da-86ac-e71c39583d83 - color: {r: 1, g: 1, b: 1, a: 1} - - guid: 1c31e8b9-953e-4278-8afe-8308ab87227a - color: {r: 1, g: 0.84705883, b: 0.89411765, a: 1} - - guid: e0a80c4c-e254-4129-adf7-1573036bb1ab - color: {r: 0.19215687, g: 0.06666667, b: 0.11372549, a: 1} - - guid: 9c7c42d7-4d10-468b-9462-eed1222bb2ab - color: {r: 0.7019608, g: 0.14901961, b: 0.11764706, a: 1} - - guid: e5b85ceb-41f7-4e94-8ad5-53eba5509e42 - color: {r: 1, g: 1, b: 1, a: 1} - - guid: fa46b747-6bc6-4e27-aa52-501174599797 - color: {r: 0.9764706, g: 0.87058824, b: 0.8627451, a: 1} - - guid: 672d7657-2bde-4509-9317-79b9ac48aad7 - color: {r: 0.25490198, g: 0.05490196, b: 0.043137256, a: 1} - - guid: 6b072958-1f3d-42d4-9ca9-705f108286b7 - color: {r: 1, g: 0.9843137, b: 0.99607843, a: 1} - - guid: 0774ae24-94db-4d65-b751-3f0c755ce1bc - color: {r: 0.10980392, g: 0.105882354, b: 0.12156863, a: 1} - - guid: 2d9a5145-3e26-4550-be57-3527a57a2172 - color: {r: 1, g: 0.9843137, b: 0.99607843, a: 1} - - guid: 8cf63047-10b4-496a-8a85-52d3771a28f0 - color: {r: 0.10980392, g: 0.105882354, b: 0.12156863, a: 1} - - guid: 1429e101-aae5-4ae8-9490-6435a57f9a37 - color: {r: 0.4745098, g: 0.45490196, b: 0.49411765, a: 1} - - guid: 6f6bb671-9e5f-48db-9131-5b41f1d4e6c4 - color: {r: 0.90588236, g: 0.8784314, b: 0.9254902, a: 1} - - guid: c6100240-c4e5-4485-994e-a1cafc3c4749 - color: {r: 0.28627452, g: 0.27058825, b: 0.30980393, a: 1} - - guid: 828eccfe-604f-4621-96c9-ae358f6e7017 - expanded: 1 - themeName: Dark - colors: - - guid: c1a53828-f2d5-4129-ac25-a315c3584b93 - color: {r: 0.8156863, g: 0.7372549, b: 1, a: 1} - - guid: 9e099043-a40e-460e-8c7d-a8f382d08869 - color: {r: 0.21960784, g: 0.11764706, b: 0.44705883, a: 1} - - guid: d56cc8cb-8732-4810-b374-034acd1b667d - color: {r: 0.30980393, g: 0.21568628, b: 0.54509807, a: 1} - - guid: 595cc7f8-00e2-436d-b252-cdacf09534ea - color: {r: 0.91764706, g: 0.8666667, b: 1, a: 1} - - guid: a0c561f4-e79c-4d8f-9fef-1b6ee7b42b8c - color: {r: 0.8, g: 0.7607843, b: 0.8627451, a: 1} - - guid: 504c48e6-eec6-48e3-9800-318b0432bf89 - color: {r: 0.2, g: 0.1764706, b: 0.25490198, a: 1} - - guid: 5d255797-0487-457d-9309-dea410a1f02b - color: {r: 0.2901961, g: 0.26666668, b: 0.34509805, a: 1} - - guid: 79554701-52d6-45fa-bb83-0234e9561513 - color: {r: 0.9098039, g: 0.87058824, b: 0.972549, a: 1} - - guid: c17be719-c931-47e7-8478-115cd5ccfd24 - color: {r: 0.9372549, g: 0.72156864, b: 0.78431374, a: 1} - - guid: bf3106a2-589e-48da-86ac-e71c39583d83 - color: {r: 0.28627452, g: 0.14509805, b: 0.19607843, a: 1} - - guid: 1c31e8b9-953e-4278-8afe-8308ab87227a - color: {r: 0.3882353, g: 0.23137255, b: 0.28235295, a: 1} - - guid: e0a80c4c-e254-4129-adf7-1573036bb1ab - color: {r: 1, g: 0.84705883, b: 0.89411765, a: 1} - - guid: 9c7c42d7-4d10-468b-9462-eed1222bb2ab - color: {r: 0.9490196, g: 0.72156864, b: 0.70980394, a: 1} - - guid: e5b85ceb-41f7-4e94-8ad5-53eba5509e42 - color: {r: 0.3764706, g: 0.078431375, b: 0.0627451, a: 1} - - guid: fa46b747-6bc6-4e27-aa52-501174599797 - color: {r: 0.54901963, g: 0.11372549, b: 0.09411765, a: 1} - - guid: 672d7657-2bde-4509-9317-79b9ac48aad7 - color: {r: 0.9764706, g: 0.87058824, b: 0.8627451, a: 1} - - guid: 6b072958-1f3d-42d4-9ca9-705f108286b7 - color: {r: 0.10980392, g: 0.105882354, b: 0.12156863, a: 1} - - guid: 0774ae24-94db-4d65-b751-3f0c755ce1bc - color: {r: 0.9019608, g: 0.88235295, b: 0.8980392, a: 1} - - guid: 2d9a5145-3e26-4550-be57-3527a57a2172 - color: {r: 0.10980392, g: 0.105882354, b: 0.12156863, a: 1} - - guid: 8cf63047-10b4-496a-8a85-52d3771a28f0 - color: {r: 0.9019608, g: 0.88235295, b: 0.8980392, a: 1} - - guid: 1429e101-aae5-4ae8-9490-6435a57f9a37 - color: {r: 0.5764706, g: 0.56078434, b: 0.6, a: 1} - - guid: 6f6bb671-9e5f-48db-9131-5b41f1d4e6c4 - color: {r: 0.28627452, g: 0.27058825, b: 0.30980393, a: 1} - - guid: c6100240-c4e5-4485-994e-a1cafc3c4749 - color: {r: 0.7921569, g: 0.76862746, b: 0.8156863, a: 1} diff --git a/Assets/Resources/Unity-Theme-Database.json b/Assets/Resources/Unity-Theme-Database.json new file mode 100644 index 0000000..681fcfb --- /dev/null +++ b/Assets/Resources/Unity-Theme-Database.json @@ -0,0 +1,298 @@ +{ + "debugLevel": 2, + "currentThemeIndex": 0, + "colors": [ + { + "guid": "c1a53828-f2d5-4129-ac25-a315c3584b93", + "name": "Primary" + }, + { + "guid": "9e099043-a40e-460e-8c7d-a8f382d08869", + "name": "Primary Text" + }, + { + "guid": "d56cc8cb-8732-4810-b374-034acd1b667d", + "name": "Primary Container" + }, + { + "guid": "595cc7f8-00e2-436d-b252-cdacf09534ea", + "name": "Primary Container Text" + }, + { + "guid": "a0c561f4-e79c-4d8f-9fef-1b6ee7b42b8c", + "name": "Secondary" + }, + { + "guid": "504c48e6-eec6-48e3-9800-318b0432bf89", + "name": "Secondary Text" + }, + { + "guid": "5d255797-0487-457d-9309-dea410a1f02b", + "name": "Secondary Container" + }, + { + "guid": "79554701-52d6-45fa-bb83-0234e9561513", + "name": "Secondary Container Text" + }, + { + "guid": "c17be719-c931-47e7-8478-115cd5ccfd24", + "name": "Tertiary" + }, + { + "guid": "bf3106a2-589e-48da-86ac-e71c39583d83", + "name": "Tertiary Text" + }, + { + "guid": "1c31e8b9-953e-4278-8afe-8308ab87227a", + "name": "Tertiary Container" + }, + { + "guid": "e0a80c4c-e254-4129-adf7-1573036bb1ab", + "name": "Tertiary Container Text" + }, + { + "guid": "9c7c42d7-4d10-468b-9462-eed1222bb2ab", + "name": "Error" + }, + { + "guid": "e5b85ceb-41f7-4e94-8ad5-53eba5509e42", + "name": "Error Text" + }, + { + "guid": "fa46b747-6bc6-4e27-aa52-501174599797", + "name": "Error Container" + }, + { + "guid": "672d7657-2bde-4509-9317-79b9ac48aad7", + "name": "Error Container Text" + }, + { + "guid": "6b072958-1f3d-42d4-9ca9-705f108286b7", + "name": "Background" + }, + { + "guid": "0774ae24-94db-4d65-b751-3f0c755ce1bc", + "name": "Background Text" + }, + { + "guid": "2d9a5145-3e26-4550-be57-3527a57a2172", + "name": "Surface" + }, + { + "guid": "8cf63047-10b4-496a-8a85-52d3771a28f0", + "name": "Surface Text" + }, + { + "guid": "1429e101-aae5-4ae8-9490-6435a57f9a37", + "name": "Outline" + }, + { + "guid": "6f6bb671-9e5f-48db-9131-5b41f1d4e6c4", + "name": "Surface-Variant" + }, + { + "guid": "c6100240-c4e5-4485-994e-a1cafc3c4749", + "name": "Surface-Variant Text" + } + ], + "themes": [ + { + "guid": "a1aa6e11-8df7-47e4-a920-e9eb1e48312c", + "expanded": true, + "themeName": "Light", + "colors": [ + { + "guid": "c1a53828-f2d5-4129-ac25-a315c3584b93", + "colorHex": "#6750A4FF" + }, + { + "guid": "9e099043-a40e-460e-8c7d-a8f382d08869", + "colorHex": "#FFFFFFFF" + }, + { + "guid": "d56cc8cb-8732-4810-b374-034acd1b667d", + "colorHex": "#EADBFFFF" + }, + { + "guid": "595cc7f8-00e2-436d-b252-cdacf09534ea", + "colorHex": "#21005DFF" + }, + { + "guid": "a0c561f4-e79c-4d8f-9fef-1b6ee7b42b8c", + "colorHex": "#625A71FF" + }, + { + "guid": "504c48e6-eec6-48e3-9800-318b0432bf89", + "colorHex": "#FFFFFFFF" + }, + { + "guid": "5d255797-0487-457d-9309-dea410a1f02b", + "colorHex": "#E8DEF8FF" + }, + { + "guid": "79554701-52d6-45fa-bb83-0234e9561513", + "colorHex": "#1D192BFF" + }, + { + "guid": "c17be719-c931-47e7-8478-115cd5ccfd24", + "colorHex": "#7D5260FF" + }, + { + "guid": "bf3106a2-589e-48da-86ac-e71c39583d83", + "colorHex": "#FFFFFFFF" + }, + { + "guid": "1c31e8b9-953e-4278-8afe-8308ab87227a", + "colorHex": "#FFD8E4FF" + }, + { + "guid": "e0a80c4c-e254-4129-adf7-1573036bb1ab", + "colorHex": "#31061DFF" + }, + { + "guid": "9c7c42d7-4d10-468b-9462-eed1222bb2ab", + "colorHex": "#B5251DFF" + }, + { + "guid": "e5b85ceb-41f7-4e94-8ad5-53eba5509e42", + "colorHex": "#FFFFFFFF" + }, + { + "guid": "fa46b747-6bc6-4e27-aa52-501174599797", + "colorHex": "#F9DDDCC7" + }, + { + "guid": "672d7657-2bde-4509-9317-79b9ac48aad7", + "colorHex": "#410E0BFF" + }, + { + "guid": "6b072958-1f3d-42d4-9ca9-705f108286b7", + "colorHex": "#FFF9FCFF" + }, + { + "guid": "0774ae24-94db-4d65-b751-3f0c755ce1bc", + "colorHex": "#1C1B1FFF" + }, + { + "guid": "2d9a5145-3e26-4550-be57-3527a57a2172", + "colorHex": "#FFF9FCFF" + }, + { + "guid": "8cf63047-10b4-496a-8a85-52d3771a28f0", + "colorHex": "#1C1B1FFF" + }, + { + "guid": "1429e101-aae5-4ae8-9490-6435a57f9a37", + "colorHex": "#79747EFF" + }, + { + "guid": "6f6bb671-9e5f-48db-9131-5b41f1d4e6c4", + "colorHex": "#E7E1ECFF" + }, + { + "guid": "c6100240-c4e5-4485-994e-a1cafc3c4749", + "colorHex": "#49454FFF" + } + ] + }, + { + "guid": "828eccfe-604f-4621-96c9-ae358f6e7017", + "expanded": false, + "themeName": "Dark", + "colors": [ + { + "guid": "c1a53828-f2d5-4129-ac25-a315c3584b93", + "colorHex": "#D0BCFFFF" + }, + { + "guid": "9e099043-a40e-460e-8c7d-a8f382d08869", + "colorHex": "#381E72FF" + }, + { + "guid": "d56cc8cb-8732-4810-b374-034acd1b667d", + "colorHex": "#4F378BFF" + }, + { + "guid": "595cc7f8-00e2-436d-b252-cdacf09534ea", + "colorHex": "#EADBFFFF" + }, + { + "guid": "a0c561f4-e79c-4d8f-9fef-1b6ee7b42b8c", + "colorHex": "#CCBCE8FF" + }, + { + "guid": "504c48e6-eec6-48e3-9800-318b0432bf89", + "colorHex": "#332D41FF" + }, + { + "guid": "5d255797-0487-457d-9309-dea410a1f02b", + "colorHex": "#4A4458FF" + }, + { + "guid": "79554701-52d6-45fa-bb83-0234e9561513", + "colorHex": "#E8DEF8FF" + }, + { + "guid": "c17be719-c931-47e7-8478-115cd5ccfd24", + "colorHex": "#EFBCD1FF" + }, + { + "guid": "bf3106a2-589e-48da-86ac-e71c39583d83", + "colorHex": "#492539FF" + }, + { + "guid": "1c31e8b9-953e-4278-8afe-8308ab87227a", + "colorHex": "#633740FF" + }, + { + "guid": "e0a80c4c-e254-4129-adf7-1573036bb1ab", + "colorHex": "#FFD8E4FF" + }, + { + "guid": "9c7c42d7-4d10-468b-9462-eed1222bb2ab", + "colorHex": "#F2B8B5FF" + }, + { + "guid": "e5b85ceb-41f7-4e94-8ad5-53eba5509e42", + "colorHex": "#602319FF" + }, + { + "guid": "fa46b747-6bc6-4e27-aa52-501174599797", + "colorHex": "#8C1D18FF" + }, + { + "guid": "672d7657-2bde-4509-9317-79b9ac48aad7", + "colorHex": "#F9DDDCCC" + }, + { + "guid": "6b072958-1f3d-42d4-9ca9-705f108286b7", + "colorHex": "#1C1B1FFF" + }, + { + "guid": "0774ae24-94db-4d65-b751-3f0c755ce1bc", + "colorHex": "#E6E1E5FF" + }, + { + "guid": "2d9a5145-3e26-4550-be57-3527a57a2172", + "colorHex": "#1C1B1FFF" + }, + { + "guid": "8cf63047-10b4-496a-8a85-52d3771a28f0", + "colorHex": "#E6E1E5FF" + }, + { + "guid": "1429e101-aae5-4ae8-9490-6435a57f9a37", + "colorHex": "#938F99FF" + }, + { + "guid": "6f6bb671-9e5f-48db-9131-5b41f1d4e6c4", + "colorHex": "#49454FFF" + }, + { + "guid": "c6100240-c4e5-4485-994e-a1cafc3c4749", + "colorHex": "#CAC4D0FF" + } + ] + } + ] +} \ No newline at end of file diff --git a/Assets/Resources/Unity-Theme Database.asset.meta b/Assets/Resources/Unity-Theme-Database.json.meta similarity index 52% rename from Assets/Resources/Unity-Theme Database.asset.meta rename to Assets/Resources/Unity-Theme-Database.json.meta index 57476a2..c7f3f90 100644 --- a/Assets/Resources/Unity-Theme Database.asset.meta +++ b/Assets/Resources/Unity-Theme-Database.json.meta @@ -1,8 +1,7 @@ fileFormatVersion: 2 -guid: 0a6e10ae3b2e55f46aa3533663db6956 -NativeFormatImporter: +guid: 828f8c07324cee044ac05194b60ce6ba +TextScriptImporter: externalObjects: {} - mainObjectFileID: 11400000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Samples/Prefabs/Container.prefab b/Assets/Samples/Prefabs/Container.prefab index 6d83d16..3425a71 100644 --- a/Assets/Samples/Prefabs/Container.prefab +++ b/Assets/Samples/Prefabs/Container.prefab @@ -133,6 +133,22 @@ PrefabInstance: propertyPath: m_Name value: Image (1) objectReference: {fileID: 0} + - target: {fileID: 8157052197910363766, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} + propertyPath: m_Color.b + value: 0.90588236 + objectReference: {fileID: 0} + - target: {fileID: 8157052197910363766, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} + propertyPath: m_Color.g + value: 0.5529412 + objectReference: {fileID: 0} + - target: {fileID: 8157052197910363766, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} + propertyPath: m_Color.r + value: 0.87058824 + objectReference: {fileID: 0} + - target: {fileID: 8157052197910363767, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} + propertyPath: data.colorGuid + value: c17be719-c931-47e7-8478-115cd5ccfd24 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] @@ -241,15 +257,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8157052197910363766, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} propertyPath: m_Color.b - value: 1 + value: 0.627451 objectReference: {fileID: 0} - target: {fileID: 8157052197910363766, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} propertyPath: m_Color.g - value: 0.7372549 + value: 0.8784314 objectReference: {fileID: 0} - target: {fileID: 8157052197910363766, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} propertyPath: m_Color.r - value: 0.8156863 + value: 0.9137255 objectReference: {fileID: 0} - target: {fileID: 8157052197910363767, guid: e5929e4fa94cdd24a97e25d7b2568c14, type: 3} propertyPath: colorGuid diff --git a/Assets/Samples/Prefabs/Image.prefab b/Assets/Samples/Prefabs/Image.prefab index be54e13..a62acfc 100644 --- a/Assets/Samples/Prefabs/Image.prefab +++ b/Assets/Samples/Prefabs/Image.prefab @@ -29,9 +29,9 @@ RectTransform: 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_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -59,7 +59,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.6901961, g: 0.74509805, b: 0.77254903, a: 1} + m_Color: {r: 0.9137255, g: 0.8784314, b: 0.627451, a: 1} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 @@ -88,7 +88,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 44e5162ee87061045ba821e0dfb969d0, type: 3} m_Name: m_EditorClassIdentifier: - colorGuid: ef17db61-7d25-4613-842e-2c8247d13fc5 - overrideAlpha: 0 - alpha: 1 + data: + colorGuid: a0c561f4-e79c-4d8f-9fef-1b6ee7b42b8c + overrideAlpha: 0 + alpha: 1 image: {fileID: 8157052197910363766} diff --git a/Assets/Samples/Scenes/Test.unity b/Assets/Samples/Scenes/Test.unity index f151e20..fcb707e 100644 --- a/Assets/Samples/Scenes/Test.unity +++ b/Assets/Samples/Scenes/Test.unity @@ -221,15 +221,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.b - value: 0.972549 + value: 0.09411765 objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.g - value: 0.87058824 + value: 0.25490198 objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.r - value: 0.9098039 + value: 0.24705882 objectReference: {fileID: 0} - target: {fileID: 5601321488045288321, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: alpha @@ -249,15 +249,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.b - value: 0.78431374 + value: 0.90588236 objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.g - value: 0.72156864 + value: 0.5529412 objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.r - value: 0.9372549 + value: 0.87058824 objectReference: {fileID: 0} - target: {fileID: 5886343440413528679, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: alpha @@ -485,15 +485,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.b - value: 0.44705883 + value: 0.36862746 objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.g - value: 0.11764706 + value: 0.36862746 objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.r - value: 0.21960784 + value: 0.78431374 objectReference: {fileID: 0} - target: {fileID: 5601321488045288321, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: alpha @@ -525,15 +525,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.b - value: 0.0627451 + value: 1 objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.g - value: 0.078431375 + value: 1 objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.r - value: 0.3764706 + value: 1 objectReference: {fileID: 0} - target: {fileID: 5886343440413528679, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: alpha @@ -935,15 +935,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.b - value: 0.19607843 + value: 0.5921569 objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.g - value: 0.14509805 + value: 0.23921569 objectReference: {fileID: 0} - target: {fileID: 5601321488045288320, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.r - value: 0.28627452 + value: 0.6901961 objectReference: {fileID: 0} - target: {fileID: 5601321488045288321, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: data.alpha @@ -963,23 +963,23 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.a - value: 0.85 + value: 0.926 objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.b - value: 0.78431374 + value: 0.90588236 objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.g - value: 0.72156864 + value: 0.5529412 objectReference: {fileID: 0} - target: {fileID: 5886343440413528678, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: m_Color.r - value: 0.9372549 + value: 0.87058824 objectReference: {fileID: 0} - target: {fileID: 5886343440413528679, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: data.alpha - value: 0.85 + value: 0.926 objectReference: {fileID: 0} - target: {fileID: 5886343440413528679, guid: a7497797f1922894899c4729fd5b884b, type: 3} propertyPath: data.colorGuid diff --git a/Assets/_PackageRoot/Documentation~/README.md b/Assets/_PackageRoot/Documentation~/README.md index a77f763..03b7074 100644 --- a/Assets/_PackageRoot/Documentation~/README.md +++ b/Assets/_PackageRoot/Documentation~/README.md @@ -117,3 +117,91 @@ namespace Unity.Theme.Binders ## Other - **[Color palette builder](https://m3.material.io/theme-builder#/custom)** by Google's Material Design V3 + +--- + +## Migration from 2.x.x version + +> ❗❗❗**WARNING** +> Before you start the migration, please close Unity project to avoid any data loss. +> When you finished, you need to delete the `Assets/Resources/Unity-Theme Database.asset` file. + +The version 3.x.x has a different database structure, so you need to migrate your data manually if you want to keep existed binders to still be connected to a right color. The binders are using GUIDs to connect to colors. + +### To do + +**You need to copy GUIDs** from `Assets/Resources/Unity-Theme Database.asset` to `Assets/Resources/Unity-Theme-Database.json`. To do that, please take a look at the samples below. You may see what is data format of old and new databases, and how to copy GUIDs. + +#### Sample of `Assets/Resources/Unity-Theme Database.asset` - old file (source) + +Take a look at the `guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c`, the file contains it 3 times, depends on your setup. You would need to copy the guid to the `Unity-Theme-Database.json` file. + +``` + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + name: Primary + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + name: Primary Text + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + name: Primary Container + themes: + - guid: 6d1fce4e-1938-4d6d-93b0-b4b9f6497293 + expanded: 1 + themeName: Light + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + color: {r: 0.40392157, g: 0.3137255, b: 0.6431373, a: 1} + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + color: {r: 1, g: 1, b: 1, a: 1} + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + color: {r: 0.91764706, g: 0.8666667, b: 1, a: 1} + - guid: 54c71f36-6023-4d84-bce7-c8192cf7ba40 + expanded: 1 + themeName: Dark + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + color: {r: 0, g: 0.4784314, b: 1, a: 1} + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + color: {r: 1, g: 1, b: 1, a: 1} + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + color: {r: 0.15294118, g: 0.15294118, b: 0.15686275, a: 1} +``` + +### Sample of `Assets/Resources/Unity-Theme-Database.json` - new file (destination) + +That is the file that you need to make in the end of the migration process. +When you done, you may need to close & open Unity project to let Unity-Theme to reload the data. + +```json +{ + "debugLevel": 2, + "currentThemeIndex": 1, + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "name": "Primary" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "name": "Primary Text" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "name": "Primary Container" } + ], + "themes": [ + { + "guid": "4cfe4185-bc3e-4247-969f-1da1d3f2bdec", + "expanded": false, + "themeName": "Light", + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#6750A4FF" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#EADDFFFF" } + ] + }, + { + "guid": "dca52c83-4f79-4fee-854e-0defe9ccbe07", + "expanded": true, + "themeName": "Dark", + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#007AFFFF" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#272728FF" } + ] + } + ] +} +``` diff --git a/Assets/_PackageRoot/Editor/Scripts/ColorBinderDataDrawer.cs b/Assets/_PackageRoot/Editor/Scripts/ColorBinderDataDrawer.cs index c71c9dc..8d3007b 100644 --- a/Assets/_PackageRoot/Editor/Scripts/ColorBinderDataDrawer.cs +++ b/Assets/_PackageRoot/Editor/Scripts/ColorBinderDataDrawer.cs @@ -6,7 +6,7 @@ namespace Unity.Theme.Editor { - [CustomPropertyDrawer(typeof(Unity.Theme.Binders.ColorBinderData), true)] + [CustomPropertyDrawer(typeof(Binders.ColorBinderData), true)] public class ColorBinderDataDrawer : PropertyDrawer { const string templateGuid = "7bc7f57ecc1dcb54ebd343051d02f17b"; @@ -65,7 +65,7 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property) } void UpdateColorFill(VisualElement colorFill, string colorGuid, float alpha) { - var color = Theme.Instance?.GetColorByGuid(colorGuid)?.color ?? Theme.DefaultColor; + var color = Theme.Instance?.GetColorByGuid(colorGuid)?.Color ?? Theme.DefaultColor; color.a = alpha; colorFill.style.unityBackgroundImageTintColor = new StyleColor(color); } diff --git a/Assets/_PackageRoot/Editor/Scripts/ThemeWindowEditor.cs b/Assets/_PackageRoot/Editor/Scripts/ThemeWindowEditor.cs index e5d49c4..a236482 100644 --- a/Assets/_PackageRoot/Editor/Scripts/ThemeWindowEditor.cs +++ b/Assets/_PackageRoot/Editor/Scripts/ThemeWindowEditor.cs @@ -28,6 +28,10 @@ public static ThemeWindowEditor ShowWindow() } public void Invalidate() => CreateGUI(); + void OnValidate() + { + Theme.Instance.OnValidate(); + } private void SaveChanges(string message) { @@ -35,8 +39,8 @@ private void SaveChanges(string message) Debug.Log(message); saveChangesMessage = message; base.SaveChanges(); - EditorUtility.SetDirty(Theme.Instance); - Undo.RecordObject(Theme.Instance, message); + Theme.Instance.Save(); + Undo.RecordObject(Theme.Instance.AssetFile, message); } private void UpdateDropdownCurrentTheme(Theme config) @@ -52,7 +56,7 @@ public void CreateGUI() { rootVisualElement.Clear(); - var config = Theme.Instance; + var config = Theme.Instance; var panel = templateControlPanel.Instantiate(); var root = new ScrollView(); rootVisualElement.Add(root); @@ -190,7 +194,7 @@ void UIAddThemeColor(Theme config, UITheme uiTheme, ColorData themeColor) uiTheme.colors[themeColor.Guid] = uiThemeColor; uiThemeColor.txtName.value = config.GetColorName(themeColor.Guid); - uiThemeColor.colorField.value = themeColor.color; + uiThemeColor.colorField.value = themeColor.Color; uiThemeColor.txtName.RegisterValueChangedCallback(evt => { @@ -208,7 +212,7 @@ void UIAddThemeColor(Theme config, UITheme uiTheme, ColorData themeColor) uiThemeColor.colorField.RegisterValueChangedCallback(evt => { - themeColor.color = evt.newValue; + themeColor.Color = evt.newValue; config.UpdateColor(uiTheme.theme, themeColor); UIGenerateColorPreviews(uiTheme); SaveChanges($"Theme color[{config.GetColorName(themeColor.Guid)}] changed: {evt.newValue}"); @@ -239,7 +243,7 @@ void UIGenerateColorPreviews(UITheme uiTheme) foreach (var themeColor in uiTheme.theme.colors) { var colorFill = colorFillTemplate.Instantiate(); - colorFill.Query("colorFill").Last().style.unityBackgroundImageTintColor = new StyleColor(themeColor.color); + colorFill.Query("colorFill").Last().style.unityBackgroundImageTintColor = new StyleColor(themeColor.Color); uiTheme.contPreview.Add(colorFill); } } diff --git a/Assets/_PackageRoot/README.md b/Assets/_PackageRoot/README.md index a77f763..03b7074 100644 --- a/Assets/_PackageRoot/README.md +++ b/Assets/_PackageRoot/README.md @@ -117,3 +117,91 @@ namespace Unity.Theme.Binders ## Other - **[Color palette builder](https://m3.material.io/theme-builder#/custom)** by Google's Material Design V3 + +--- + +## Migration from 2.x.x version + +> ❗❗❗**WARNING** +> Before you start the migration, please close Unity project to avoid any data loss. +> When you finished, you need to delete the `Assets/Resources/Unity-Theme Database.asset` file. + +The version 3.x.x has a different database structure, so you need to migrate your data manually if you want to keep existed binders to still be connected to a right color. The binders are using GUIDs to connect to colors. + +### To do + +**You need to copy GUIDs** from `Assets/Resources/Unity-Theme Database.asset` to `Assets/Resources/Unity-Theme-Database.json`. To do that, please take a look at the samples below. You may see what is data format of old and new databases, and how to copy GUIDs. + +#### Sample of `Assets/Resources/Unity-Theme Database.asset` - old file (source) + +Take a look at the `guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c`, the file contains it 3 times, depends on your setup. You would need to copy the guid to the `Unity-Theme-Database.json` file. + +``` + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + name: Primary + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + name: Primary Text + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + name: Primary Container + themes: + - guid: 6d1fce4e-1938-4d6d-93b0-b4b9f6497293 + expanded: 1 + themeName: Light + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + color: {r: 0.40392157, g: 0.3137255, b: 0.6431373, a: 1} + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + color: {r: 1, g: 1, b: 1, a: 1} + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + color: {r: 0.91764706, g: 0.8666667, b: 1, a: 1} + - guid: 54c71f36-6023-4d84-bce7-c8192cf7ba40 + expanded: 1 + themeName: Dark + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + color: {r: 0, g: 0.4784314, b: 1, a: 1} + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + color: {r: 1, g: 1, b: 1, a: 1} + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + color: {r: 0.15294118, g: 0.15294118, b: 0.15686275, a: 1} +``` + +### Sample of `Assets/Resources/Unity-Theme-Database.json` - new file (destination) + +That is the file that you need to make in the end of the migration process. +When you done, you may need to close & open Unity project to let Unity-Theme to reload the data. + +```json +{ + "debugLevel": 2, + "currentThemeIndex": 1, + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "name": "Primary" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "name": "Primary Text" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "name": "Primary Container" } + ], + "themes": [ + { + "guid": "4cfe4185-bc3e-4247-969f-1da1d3f2bdec", + "expanded": false, + "themeName": "Light", + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#6750A4FF" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#EADDFFFF" } + ] + }, + { + "guid": "dca52c83-4f79-4fee-854e-0defe9ccbe07", + "expanded": true, + "themeName": "Dark", + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#007AFFFF" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#272728FF" } + ] + } + ] +} +``` diff --git a/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs b/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs index 99a777d..5df1dd9 100644 --- a/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs +++ b/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs @@ -1,10 +1,15 @@ +using System.Text; using UnityEngine; namespace Unity.Theme.Binders { public abstract partial class BaseColorBinder : MonoBehaviour { - protected virtual void OnValidate() +#if UNITY_EDITOR + protected virtual void OnValidate() => UnityEditor.EditorApplication.delayCall += Validate; +#endif + + protected virtual void Validate() { if (string.IsNullOrEmpty(data.colorGuid)) { @@ -22,23 +27,45 @@ protected virtual void OnValidate() TrySetColor(Theme.Instance.CurrentTheme); #endif } - + // UTILS ---------------------------------------------------------------------------// - protected string GameObjectPath() => GameObjectPath(transform); // - protected static string GameObjectPath(Transform trans, string path = "") // + protected string GameObjectPath() // + { // +#pragma warning disable CS0168 // + try { return GameObjectPath(transform).ToString(); } // + catch (MissingReferenceException e) { /* ignore */ } // +#pragma warning restore CS0168 // + return null; // + } // + protected StringBuilder GameObjectPath(Transform trans, StringBuilder path = null) // { // - if (string.IsNullOrEmpty(path)) // - path = trans.name; // + if (path == null) // + path = new StringBuilder(); // + // + if (path.Length == 0) // + { // + path.Append(trans.name); // + } // else // - path = $"{trans.name}/{path}"; // + { // + // $"{trans.name}/{path}" // + path.Insert(0, "/"); // + path.Insert(0, trans.name); // + } // // if (trans.parent == null) // { // var isPrefab = string.IsNullOrEmpty(trans.gameObject.scene.name); // if (isPrefab) // - path = $"Prefabs/{path}"; // + { // + path.Insert(0, "Prefabs/"); // + } // else // - path = $"{trans.gameObject.scene.name}/{path}"; // + { // + path.Insert(0, "/"); // + path.Insert(0, trans.gameObject.scene.name); // + path.Insert(0, ""); // + } // return path; // } // else // diff --git a/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs.meta b/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs.meta index 38bb17a..c838d7c 100644 --- a/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs.meta +++ b/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: f3fc5d645f4cab648922bc272e9da716, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.cs b/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.cs index 3dc3012..eb6283e 100644 --- a/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.cs +++ b/Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.cs @@ -28,8 +28,24 @@ protected virtual void Start() TrySetColor(Theme.Instance.CurrentTheme); #endif } + protected virtual void OnEnable() { +#if UNITY_EDITOR + if (Application.isPlaying) + { + Enable(); + } + else + { + UnityEditor.EditorApplication.delayCall += Enable; + } +#else + Enable(); +#endif + } + protected virtual void Enable() + { TrySetColor(Theme.Instance.CurrentTheme); Theme.Instance.onThemeChanged += TrySetColor; Theme.Instance.onThemeColorChanged += OnThemeColorChanged; @@ -79,7 +95,7 @@ protected virtual void TrySetColor(ThemeData theme) protected virtual Color GetTargetColor(ColorData colorData) { - var result = colorData.color; + var result = colorData.Color; if (data.overrideAlpha) result.a = data.alpha; diff --git a/Assets/_PackageRoot/Scripts/Config/Data/ColorData.cs b/Assets/_PackageRoot/Scripts/Config/Data/ColorData.cs index f7a1440..1072cb2 100644 --- a/Assets/_PackageRoot/Scripts/Config/Data/ColorData.cs +++ b/Assets/_PackageRoot/Scripts/Config/Data/ColorData.cs @@ -9,18 +9,31 @@ public class ColorData [SerializeField, HideInInspector] private string guid; - public Color color = Color.white; + [SerializeField, HideInInspector] + private string colorHex = "#FFFFFFFF"; + + // [NonSerialized] + // public Color color = Color.white; + + public Color Color + { + get => ColorUtility.TryParseHtmlString(colorHex, out var color) + ? color + : Color.white; + set => colorHex = value.ToHexRGBA(); + } public string Guid => guid; public ColorData() { } - public ColorData(ColorData colorData) : this(colorData.guid, colorData.color) { } + public ColorData(ColorData colorData) : this(colorData.guid, colorData.colorHex) { } public ColorData(ColorDataRef colorRef) : this(colorRef, Color.white) { } public ColorData(ColorDataRef colorRef, Color color) : this(colorRef.Guid, color) { } - public ColorData(string guid, Color color) : this() + public ColorData(string guid, Color color) : this(guid, color.ToHexRGBA()) { } + public ColorData(string guid, string colorHex) : this() { this.guid = guid; - this.color = color; + this.colorHex = colorHex; } } } \ No newline at end of file diff --git a/Assets/_PackageRoot/Scripts/Config/Theme.Colors.cs b/Assets/_PackageRoot/Scripts/Config/Theme.Colors.cs index 02dbd33..bd8360e 100644 --- a/Assets/_PackageRoot/Scripts/Config/Theme.Colors.cs +++ b/Assets/_PackageRoot/Scripts/Config/Theme.Colors.cs @@ -6,7 +6,7 @@ namespace Unity.Theme { #pragma warning disable CA2235 // Mark all non-serializable fields - public partial class Theme : ScriptableObject + public partial class Theme { public IEnumerable ColorNames => colors?.Select(x => x.name); public IEnumerable ColorGuids => colors?.Select(x => x.Guid); @@ -28,9 +28,9 @@ public partial class Theme : ScriptableObject public ColorDataRef AddColor(string colorName) => AddColor(colorName, DefaultColor); public ColorDataRef AddColor(string colorName, string colorHex) { - var color = DefaultColor; - if (!ColorUtility.TryParseHtmlString(colorHex, out color)) + if (!ColorUtility.TryParseHtmlString(colorHex, out var color)) { + color = DefaultColor; if (debugLevel <= DebugLevel.Error) Debug.LogError($"Color HEX can't be parsed from '{colorHex}'"); } @@ -59,9 +59,9 @@ public ColorDataRef AddColor(string colorName, Color color) } public ColorData SetColor(string colorName, string colorHex) { - var color = DefaultColor; - if (!ColorUtility.TryParseHtmlString(colorHex, out color)) + if (!ColorUtility.TryParseHtmlString(colorHex, out var color)) { + color = DefaultColor; if (debugLevel <= DebugLevel.Error) Debug.LogError($"Color HEX can't be parsed from '{colorHex}'"); } @@ -76,14 +76,14 @@ public ColorData SetColor(string colorName, Color color) Debug.LogError($"SetColor error. Color with name '{colorName}' not found"); return null; } - colorData.color = color; + colorData.Color = color; return colorData; } public ColorData SetOrAddColor(string colorName, string colorHex) { - var color = DefaultColor; - if (!ColorUtility.TryParseHtmlString(colorHex, out color)) + if (!ColorUtility.TryParseHtmlString(colorHex, out var color)) { + color = DefaultColor; if (debugLevel <= DebugLevel.Error) Debug.LogError($"Color HEX can't be parsed from '{colorHex}'"); } @@ -97,7 +97,7 @@ public ColorData SetOrAddColor(string colorName, Color color) AddColor(colorName, color); colorData = GetColorByName(colorName); } - colorData.color = color; + colorData.Color = color; NotifyColorChanged(colorData); return colorData; } @@ -165,12 +165,11 @@ public void RemoveAllColors() public void SortColorsByName() { foreach (var theme in themes) - theme.colors.Sort((l, r) => - { - var refL = colors.FirstOrDefault(x => x.Guid == l.Guid); - var refR = colors.FirstOrDefault(x => x.Guid == r.Guid); - return ColorDataRef.Compare(refL, refR); - }); + { + theme.colors.Sort((l, r) => ColorDataRef.Compare( + colors.FirstOrDefault(x => x.Guid == l.Guid), + colors.FirstOrDefault(x => x.Guid == r.Guid))); + } } protected virtual void NotifyColorChanged(ColorData colorData, ThemeData theme = null) diff --git a/Assets/_PackageRoot/Scripts/Config/Theme.Editor.cs b/Assets/_PackageRoot/Scripts/Config/Theme.Editor.cs index 75b0a0c..103ed83 100644 --- a/Assets/_PackageRoot/Scripts/Config/Theme.Editor.cs +++ b/Assets/_PackageRoot/Scripts/Config/Theme.Editor.cs @@ -1,49 +1,54 @@ +using System; +using System.IO; using UnityEngine; namespace Unity.Theme { #pragma warning disable CA2235 // Mark all non-serializable fields - public partial class Theme : ScriptableObject + public partial class Theme { - public const string ASSETS_PATH = "Assets/Resources/Unity-Theme Database.asset"; - public const string RESOURCES_PATH = "Unity-Theme Database"; - + public static string ResourcesFileName => "Unity-Theme-Database"; + public static string AssetsFilePath => $"Assets/Resources/{ResourcesFileName}.json"; #if UNITY_EDITOR + public TextAsset AssetFile => UnityEditor.AssetDatabase.LoadAssetAtPath(AssetsFilePath); +#endif + public static Theme GetOrCreateInstance() { - var config = Application.isPlaying - ? Resources.Load(RESOURCES_PATH) - : UnityEditor.AssetDatabase.LoadAssetAtPath(ASSETS_PATH); - - if (config == null) + try { - Debug.Log($"Creating Unity-Theme database file at {ASSETS_PATH}"); - config = ScriptableObject.CreateInstance(); - - config.SetDefaultPalettes(); - - var directory = System.IO.Path.GetDirectoryName(ASSETS_PATH); - if (!System.IO.Directory.Exists(directory)) +#if UNITY_EDITOR + var json = Application.isPlaying + ? Resources.Load(ResourcesFileName).text + : File.Exists(AssetsFilePath) + ? File.ReadAllText(AssetsFilePath) + : null; +#else + var json = Resources.Load(ResourcesFileName).text; +#endif + Theme config = null; + try { config = JsonUtility.FromJson(json); } + catch (Exception e) { - System.IO.Directory.CreateDirectory(directory); + Debug.LogError($"{ResourcesFileName} file is corrupted at {AssetsFilePath}"); + Debug.LogException(e); } - - UnityEditor.AssetDatabase.CreateAsset(config, ASSETS_PATH); - UnityEditor.AssetDatabase.SaveAssets(); + if (config == null) + { + Debug.Log($"Creating {ResourcesFileName} file at {AssetsFilePath}"); + config = new Theme(); + config.SetDefaultPalettes(); + } + return config; } - return config; - } -#else - public static Theme GetOrCreateInstance() - { - var config = Resources.Load(RESOURCES_PATH); - if (config == null) + catch (Exception e) { - Debug.LogError($"Can't find Unity-Theme database file at {ASSETS_PATH}"); + Debug.LogError($"{ResourcesFileName} file can't be loaded from {AssetsFilePath}"); + Debug.LogException(e); } - return config; + return null; } -#endif + public void SetDefaultPalettes() { SetOrAddTheme("Light", true); @@ -110,8 +115,30 @@ public void SetDefaultPalettes() SetOrAddColor("Surface-Variant", "#49454F"); SetOrAddColor("On Surface-Variant", "#CAC4D0"); + Save(); + } + + public void Save() + { #if UNITY_EDITOR - UnityEditor.EditorUtility.SetDirty(this); + OnValidate(); + try + { + var directory = Path.GetDirectoryName(AssetsFilePath); + if (!Directory.Exists(directory)) + Directory.CreateDirectory(directory); + + var json = JsonUtility.ToJson(this, true); + File.WriteAllText(AssetsFilePath, json); + UnityEditor.EditorUtility.SetDirty(AssetFile); + } + catch (Exception e) + { + Debug.LogError($"{ResourcesFileName} file can't be saved at {AssetsFilePath}"); + Debug.LogException(e); + } +#else + return; #endif } } diff --git a/Assets/_PackageRoot/Scripts/Config/Theme.Settings.cs b/Assets/_PackageRoot/Scripts/Config/Theme.Settings.cs index a316e04..0e73bad 100644 --- a/Assets/_PackageRoot/Scripts/Config/Theme.Settings.cs +++ b/Assets/_PackageRoot/Scripts/Config/Theme.Settings.cs @@ -4,7 +4,7 @@ namespace Unity.Theme { #pragma warning disable CA2235 // Mark all non-serializable fields - public partial class Theme : ScriptableObject + public partial class Theme { [SerializeField] public DebugLevel debugLevel = DebugLevel.Error; diff --git a/Assets/_PackageRoot/Scripts/Config/Theme.Singleton.cs b/Assets/_PackageRoot/Scripts/Config/Theme.Singleton.cs index 3c247c2..985b6f9 100644 --- a/Assets/_PackageRoot/Scripts/Config/Theme.Singleton.cs +++ b/Assets/_PackageRoot/Scripts/Config/Theme.Singleton.cs @@ -3,7 +3,7 @@ namespace Unity.Theme { #pragma warning disable CA2235 // Mark all non-serializable fields - public partial class Theme : ScriptableObject + public partial class Theme { private static Theme instance; public static Theme Instance diff --git a/Assets/_PackageRoot/Scripts/Config/Theme.Theme.cs b/Assets/_PackageRoot/Scripts/Config/Theme.Theme.cs index 4c51556..e3e87d0 100644 --- a/Assets/_PackageRoot/Scripts/Config/Theme.Theme.cs +++ b/Assets/_PackageRoot/Scripts/Config/Theme.Theme.cs @@ -6,7 +6,7 @@ namespace Unity.Theme { #pragma warning disable CA2235 // Mark all non-serializable fields - public partial class Theme : ScriptableObject + public partial class Theme { public List Themes => themes; public IEnumerable ThemeNames => themes.Select(x => x.themeName); diff --git a/Assets/_PackageRoot/Scripts/Config/Theme.Tools.cs b/Assets/_PackageRoot/Scripts/Config/Theme.Tools.cs index 795ce38..33705e1 100644 --- a/Assets/_PackageRoot/Scripts/Config/Theme.Tools.cs +++ b/Assets/_PackageRoot/Scripts/Config/Theme.Tools.cs @@ -1,10 +1,9 @@ using System.Linq; -using UnityEngine; namespace Unity.Theme { #pragma warning disable CA2235 // Mark all non-serializable fields - public partial class Theme : ScriptableObject + public partial class Theme { private bool SortColors(ThemeData theme) { diff --git a/Assets/_PackageRoot/Scripts/Config/Theme.cs b/Assets/_PackageRoot/Scripts/Config/Theme.cs index acadd64..5fafbda 100644 --- a/Assets/_PackageRoot/Scripts/Config/Theme.cs +++ b/Assets/_PackageRoot/Scripts/Config/Theme.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -5,7 +6,8 @@ namespace Unity.Theme { #pragma warning disable CA2235 // Mark all non-serializable fields - public partial class Theme : ScriptableObject + [Serializable] + public partial class Theme { public static Color DefaultColor => Color.white; @@ -15,7 +17,7 @@ public partial class Theme : ScriptableObject public OnTheme onThemeChanged; public OnColor onThemeColorChanged; - private void OnValidate() + public void OnValidate() { colors ??= new List(); themes ??= new List(); diff --git a/Assets/_PackageRoot/package.json b/Assets/_PackageRoot/package.json index f3919fe..5260b11 100644 --- a/Assets/_PackageRoot/package.json +++ b/Assets/_PackageRoot/package.json @@ -5,7 +5,7 @@ "name": "Ivan Murzak", "url": "https://github.com/IvanMurzak" }, - "version": "2.1.6", + "version": "3.0.0", "unity": "2019.2", "description": "Create palettes of colors and components for change specific color on a specific visual element. Very useful to UI.", "keywords": [ diff --git a/README.md b/README.md index a77f763..03b7074 100644 --- a/README.md +++ b/README.md @@ -117,3 +117,91 @@ namespace Unity.Theme.Binders ## Other - **[Color palette builder](https://m3.material.io/theme-builder#/custom)** by Google's Material Design V3 + +--- + +## Migration from 2.x.x version + +> ❗❗❗**WARNING** +> Before you start the migration, please close Unity project to avoid any data loss. +> When you finished, you need to delete the `Assets/Resources/Unity-Theme Database.asset` file. + +The version 3.x.x has a different database structure, so you need to migrate your data manually if you want to keep existed binders to still be connected to a right color. The binders are using GUIDs to connect to colors. + +### To do + +**You need to copy GUIDs** from `Assets/Resources/Unity-Theme Database.asset` to `Assets/Resources/Unity-Theme-Database.json`. To do that, please take a look at the samples below. You may see what is data format of old and new databases, and how to copy GUIDs. + +#### Sample of `Assets/Resources/Unity-Theme Database.asset` - old file (source) + +Take a look at the `guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c`, the file contains it 3 times, depends on your setup. You would need to copy the guid to the `Unity-Theme-Database.json` file. + +``` + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + name: Primary + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + name: Primary Text + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + name: Primary Container + themes: + - guid: 6d1fce4e-1938-4d6d-93b0-b4b9f6497293 + expanded: 1 + themeName: Light + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + color: {r: 0.40392157, g: 0.3137255, b: 0.6431373, a: 1} + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + color: {r: 1, g: 1, b: 1, a: 1} + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + color: {r: 0.91764706, g: 0.8666667, b: 1, a: 1} + - guid: 54c71f36-6023-4d84-bce7-c8192cf7ba40 + expanded: 1 + themeName: Dark + colors: + - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c + color: {r: 0, g: 0.4784314, b: 1, a: 1} + - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8 + color: {r: 1, g: 1, b: 1, a: 1} + - guid: 465741bc-25d8-4722-a981-7e4a18074d83 + color: {r: 0.15294118, g: 0.15294118, b: 0.15686275, a: 1} +``` + +### Sample of `Assets/Resources/Unity-Theme-Database.json` - new file (destination) + +That is the file that you need to make in the end of the migration process. +When you done, you may need to close & open Unity project to let Unity-Theme to reload the data. + +```json +{ + "debugLevel": 2, + "currentThemeIndex": 1, + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "name": "Primary" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "name": "Primary Text" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "name": "Primary Container" } + ], + "themes": [ + { + "guid": "4cfe4185-bc3e-4247-969f-1da1d3f2bdec", + "expanded": false, + "themeName": "Light", + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#6750A4FF" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#EADDFFFF" } + ] + }, + { + "guid": "dca52c83-4f79-4fee-854e-0defe9ccbe07", + "expanded": true, + "themeName": "Dark", + "colors": [ + { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#007AFFFF" }, + { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" }, + { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#272728FF" } + ] + } + ] +} +```