|
5 | 5 | using System.Linq; |
6 | 6 | using UnityEngine; |
7 | 7 | using UnityEngine.EventSystems; |
| 8 | +using UnityEngine.Rendering; |
8 | 9 | using UnityEngine.SceneManagement; |
9 | 10 | using UnityEngine.UI; |
10 | 11 |
|
@@ -41,30 +42,53 @@ public SizedReplacementInfo GetMatchingReplacement(Texture2D tex) |
41 | 42 | if (replacements.Count == 0) |
42 | 43 | return null; |
43 | 44 |
|
44 | | - SizedReplacementInfo replacement = null; |
| 45 | + var sized = GetSizedReplacement(tex); |
| 46 | + var unsized = GetUnsizedReplacement(tex); |
45 | 47 |
|
46 | | - // Try to find a texture replacement with matching dimensions. |
| 48 | + if (sized is not null) |
| 49 | + { |
| 50 | + // If priorities are equal then prefer the sized texture |
| 51 | + if (unsized.priority <= sized.priority) |
| 52 | + return sized; |
| 53 | + } |
| 54 | + |
| 55 | + return unsized; |
| 56 | + } |
| 57 | + |
| 58 | + SizedReplacementInfo GetSizedReplacement(Texture2D tex) |
| 59 | + { |
47 | 60 | foreach (var info in replacements) |
48 | 61 | { |
49 | 62 | if (info.width == tex.width && info.height == tex.height) |
| 63 | + return info; |
| 64 | + } |
| 65 | + |
| 66 | + return null; |
| 67 | + } |
| 68 | + |
| 69 | + SizedReplacementInfo GetUnsizedReplacement(Texture2D tex) |
| 70 | + { |
| 71 | + SizedReplacementInfo found = replacements[0]; |
| 72 | + |
| 73 | + foreach (var info in replacements) |
| 74 | + { |
| 75 | + if (info.priority < found.priority) |
| 76 | + break; |
| 77 | + |
| 78 | + // Prefer textures without a specific size if we have one |
| 79 | + // available. |
| 80 | + if (info.width == 0 && info.height == 0) |
50 | 81 | { |
51 | | - replacement = info; |
| 82 | + found = info; |
52 | 83 | break; |
53 | 84 | } |
54 | | - } |
55 | | - |
56 | | - var unsized = replacements[0]; |
57 | 85 |
|
58 | | - // If no matching sized replacements just return the highest |
59 | | - // priority replacement. |
60 | | - if (replacement is null) |
61 | | - return unsized; |
| 86 | + // Otherwise use the biggest texture we have |
| 87 | + if (info.width > found.width && info.height > found.height) |
| 88 | + found = info; |
| 89 | + } |
62 | 90 |
|
63 | | - // Prefer the wrong-sized texture if it is higher priority, but |
64 | | - // otherwise use the replacement. |
65 | | - if (unsized.priority > replacement.priority) |
66 | | - return unsized; |
67 | | - return replacement; |
| 91 | + return found; |
68 | 92 | } |
69 | 93 | } |
70 | 94 |
|
|
0 commit comments