forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacker.cs
More file actions
197 lines (178 loc) · 5.96 KB
/
Packer.cs
File metadata and controls
197 lines (178 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Internal;
using UnityEngine.Scripting;
namespace UnityEditor.Sprites
{
public sealed class Packer
{
public enum Execution
{
Normal,
ForceRegroup
}
public static string kDefaultPolicy = typeof(DefaultPackerPolicy).Name;
private static string[] m_policies = null;
private static string m_selectedPolicy = null;
private static Dictionary<string, Type> m_policyTypeCache = null;
public static extern string[] atlasNames
{
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
public static string[] Policies
{
get
{
Packer.RegenerateList();
return Packer.m_policies;
}
}
public static string SelectedPolicy
{
get
{
Packer.RegenerateList();
return Packer.m_selectedPolicy;
}
set
{
Packer.RegenerateList();
if (value == null)
{
throw new ArgumentNullException();
}
if (!Packer.m_policies.Contains(value))
{
throw new ArgumentException("Specified policy {0} is not in the policy list.", value);
}
Packer.SetSelectedPolicy(value);
}
}
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Texture2D[] GetTexturesForAtlas(string atlasName);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Texture2D[] GetAlphaTexturesForAtlas(string atlasName);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void RebuildAtlasCacheIfNeeded(BuildTarget target, [DefaultValue("false")] bool displayProgressBar, [DefaultValue("Execution.Normal")] Packer.Execution execution);
[ExcludeFromDocs]
public static void RebuildAtlasCacheIfNeeded(BuildTarget target, bool displayProgressBar)
{
Packer.Execution execution = Packer.Execution.Normal;
Packer.RebuildAtlasCacheIfNeeded(target, displayProgressBar, execution);
}
[ExcludeFromDocs]
public static void RebuildAtlasCacheIfNeeded(BuildTarget target)
{
Packer.Execution execution = Packer.Execution.Normal;
bool displayProgressBar = false;
Packer.RebuildAtlasCacheIfNeeded(target, displayProgressBar, execution);
}
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void GetAtlasDataForSprite(Sprite sprite, out string atlasName, out Texture2D atlasTexture);
private static void SetSelectedPolicy(string value)
{
Packer.m_selectedPolicy = value;
PlayerSettings.spritePackerPolicy = Packer.m_selectedPolicy;
}
private static void RegenerateList()
{
if (Packer.m_policies == null)
{
List<Type> list = new List<Type>();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Assembly[] array = assemblies;
for (int i = 0; i < array.Length; i++)
{
Assembly assembly = array[i];
try
{
Type[] types = assembly.GetTypes();
Type[] array2 = types;
for (int j = 0; j < array2.Length; j++)
{
Type type = array2[j];
if (typeof(IPackerPolicy).IsAssignableFrom(type) && type != typeof(IPackerPolicy))
{
list.Add(type);
}
}
}
catch (Exception ex)
{
Debug.Log(string.Format("SpritePacker failed to get types from {0}. Error: {1}", assembly.FullName, ex.Message));
}
}
Packer.m_policies = (from t in list
select t.Name).ToArray<string>();
Packer.m_policyTypeCache = new Dictionary<string, Type>();
foreach (Type current in list)
{
if (Packer.m_policyTypeCache.ContainsKey(current.Name))
{
Type type2 = Packer.m_policyTypeCache[current.Name];
Debug.LogError(string.Format("Duplicate Sprite Packer policies found: {0} and {1}. Please rename one.", current.FullName, type2.FullName));
}
else
{
Packer.m_policyTypeCache[current.Name] = current;
}
}
Packer.m_selectedPolicy = ((!string.IsNullOrEmpty(PlayerSettings.spritePackerPolicy)) ? PlayerSettings.spritePackerPolicy : Packer.kDefaultPolicy);
if (!Packer.m_policies.Contains(Packer.m_selectedPolicy))
{
Packer.SetSelectedPolicy(Packer.kDefaultPolicy);
}
}
}
internal static string GetSelectedPolicyId()
{
Packer.RegenerateList();
Type type = Packer.m_policyTypeCache[Packer.m_selectedPolicy];
IPackerPolicy packerPolicy = Activator.CreateInstance(type) as IPackerPolicy;
return string.Format("{0}::{1}", type.AssemblyQualifiedName, packerPolicy.GetVersion());
}
internal static void ExecuteSelectedPolicy(BuildTarget target, int[] textureImporterInstanceIDs)
{
Packer.RegenerateList();
Type type = Packer.m_policyTypeCache[Packer.m_selectedPolicy];
IPackerPolicy packerPolicy = Activator.CreateInstance(type) as IPackerPolicy;
packerPolicy.OnGroupAtlases(target, new PackerJob(), textureImporterInstanceIDs);
}
internal static void SaveUnappliedTextureImporterSettings()
{
InspectorWindow[] allInspectorWindows = InspectorWindow.GetAllInspectorWindows();
for (int i = 0; i < allInspectorWindows.Length; i++)
{
InspectorWindow inspectorWindow = allInspectorWindows[i];
ActiveEditorTracker tracker = inspectorWindow.tracker;
Editor[] activeEditors = tracker.activeEditors;
for (int j = 0; j < activeEditors.Length; j++)
{
Editor editor = activeEditors[j];
TextureImporterInspector textureImporterInspector = editor as TextureImporterInspector;
if (!(textureImporterInspector == null))
{
if (textureImporterInspector.HasModified())
{
TextureImporter textureImporter = textureImporterInspector.target as TextureImporter;
if (EditorUtility.DisplayDialog("Unapplied import settings", "Unapplied import settings for '" + textureImporter.assetPath + "'", "Apply", "Revert"))
{
textureImporterInspector.ApplyAndImport();
}
}
}
}
}
}
}
}