|
1 | | -using UnityEditor; |
2 | | -using UnityEngine; |
| 1 | +using UnityEngine; |
3 | 2 |
|
4 | 3 | namespace LDtkUnity.Editor |
5 | 4 | { |
@@ -67,8 +66,7 @@ private void BuildEntityInstance() |
67 | 66 |
|
68 | 67 | private void PopulateEntityComponent() |
69 | 68 | { |
70 | | - Vector2 size = ((Vector2)_entity.UnityPxSize / Project.PixelsPerUnit); |
71 | | - |
| 69 | + Vector2 size = (Vector2)_entity.UnityPxSize / Project.PixelsPerUnit; |
72 | 70 | _entityComponent.OnImport(Importer.DefinitionObjects, _entity, LayerComponent, _fieldsComponent, _iidComponent, size); |
73 | 71 | } |
74 | 72 |
|
@@ -96,10 +94,6 @@ private void AddFieldData() |
96 | 94 | _fieldsComponent = fieldsFactory.FieldsComponent; |
97 | 95 | LDtkProfiler.EndSample(); |
98 | 96 |
|
99 | | - LDtkProfiler.BeginSample("AddHandleDrawers"); |
100 | | - AddHandleDrawers(_entityObj, _entity, Layer.GridSize); |
101 | | - LDtkProfiler.EndSample(); |
102 | | - |
103 | 97 | LDtkProfiler.BeginSample("InterfaceEvents"); |
104 | 98 | InterfaceEvents(); |
105 | 99 | LDtkProfiler.EndSample(); |
@@ -144,115 +138,6 @@ private void PositionEntity() |
144 | 138 |
|
145 | 139 | _entityObj.transform.localPosition = localPos; |
146 | 140 | } |
147 | | - |
148 | | - /// <summary> |
149 | | - /// Only doing this for importer performance. an early return to not build the rest |
150 | | - /// </summary> |
151 | | - private static bool DrawerEligibility(FieldInstance field) |
152 | | - { |
153 | | - EditorDisplayMode? mode = field.Definition.EditorDisplayMode; |
154 | | - |
155 | | - switch (mode) |
156 | | - { |
157 | | - case EditorDisplayMode.Hidden: //do not show |
158 | | - return false; |
159 | | - |
160 | | - case EditorDisplayMode.ValueOnly: //all but point/point array |
161 | | - return !field.IsPoint; |
162 | | - |
163 | | - case EditorDisplayMode.NameAndValue: //all |
164 | | - return true; |
165 | | - |
166 | | - case EditorDisplayMode.EntityTile: //enum/enum array, tile/tile array |
167 | | - return field.IsEnum || field.IsTile; |
168 | | - |
169 | | - case EditorDisplayMode.RadiusGrid: //int, float |
170 | | - case EditorDisplayMode.RadiusPx: //int, float |
171 | | - return field.IsInt || field.IsFloat; |
172 | | - |
173 | | - case EditorDisplayMode.PointStar: //point, point array |
174 | | - case EditorDisplayMode.Points: //point, point array |
175 | | - return field.IsPoint; |
176 | | - |
177 | | - case EditorDisplayMode.PointPath: //point array only |
178 | | - case EditorDisplayMode.PointPathLoop: //point array only |
179 | | - return field.IsPoint && field.Definition.IsArray; |
180 | | - |
181 | | - case EditorDisplayMode.ArrayCountNoLabel: //any arrays |
182 | | - case EditorDisplayMode.ArrayCountWithLabel: //any arrays |
183 | | - return field.Definition.IsArray; |
184 | | - |
185 | | - case EditorDisplayMode.RefLinkBetweenCenters: //entity ref, entity ref array |
186 | | - case EditorDisplayMode.RefLinkBetweenPivots: //entity ref, entity ref array |
187 | | - return field.IsEntityRef; |
188 | | - |
189 | | - default: |
190 | | - LDtkDebug.LogError("No Drawer eligibility found!"); |
191 | | - return false; |
192 | | - } |
193 | | - } |
194 | | - |
195 | | - private void AddHandleDrawers(GameObject gameObject, EntityInstance entityInstance, int gridSize) |
196 | | - { |
197 | | - LDtkEntityDrawerComponent drawerComponent = gameObject.gameObject.AddComponent<LDtkEntityDrawerComponent>(); |
198 | | - EntityDefinition entityDef = entityInstance.Definition; |
199 | | - |
200 | | - string entityPath = GetEntityImageAndRect(entityInstance, Project.assetPath, out Rect entityIconRect); |
201 | | - Vector2 size = (Vector2)entityInstance.UnityPxSize / Project.PixelsPerUnit; |
202 | | - |
203 | | - Color smartColor = entityInstance.UnitySmartColor; |
204 | | - |
205 | | - //entity handle data |
206 | | - LDtkEntityDrawerData entityDrawerData = new LDtkEntityDrawerData(drawerComponent.transform, entityDef, entityPath, entityIconRect, size, smartColor); |
207 | | - drawerComponent.AddEntityDrawer(entityDrawerData); |
208 | | - |
209 | | - foreach (FieldInstance fieldInstance in entityInstance.FieldInstances) |
210 | | - { |
211 | | - if (!DrawerEligibility(fieldInstance)) |
212 | | - { |
213 | | - continue; |
214 | | - } |
215 | | - |
216 | | - EditorDisplayMode displayMode = fieldInstance.Definition.EditorDisplayMode; |
217 | | - Vector2 pivotOffset = LDtkCoordConverter.EntityPivotOffset(entityDef.UnityPivot, size); |
218 | | - Vector3 middleCenter = gameObject.transform.position + (Vector3)pivotOffset; |
219 | | - |
220 | | - LDtkFieldDrawerData data = new LDtkFieldDrawerData(_fieldsComponent, smartColor, displayMode, fieldInstance.Identifier, gridSize, Project.PixelsPerUnit, middleCenter); |
221 | | - drawerComponent.AddReference(data); |
222 | | - } |
223 | | - } |
224 | | - |
225 | | - //this would be used instead in the entity drawer for getting the texture that way |
226 | | - private string GetEntityImageAndRect(EntityInstance entityInstance, string assetPath, out Rect rect) |
227 | | - { |
228 | | - rect = new Rect(); |
229 | | - |
230 | | - TilesetRectangle tile = entityInstance.Tile; |
231 | | - if (tile == null) |
232 | | - { |
233 | | - return null; |
234 | | - } |
235 | | - |
236 | | - //todo while awaiting this fix, safely null check it https://github.com/deepnight/ldtk/issues/1107 |
237 | | - TilesetDefinition tileset = tile.Tileset; |
238 | | - if (tileset == null) |
239 | | - { |
240 | | - return null; |
241 | | - } |
242 | | - |
243 | | - LDtkRelativeGetterTilesetTexture textureGetter = new LDtkRelativeGetterTilesetTexture(); |
244 | | - Texture2D tex = textureGetter.GetRelativeAsset(tileset, assetPath); |
245 | | - if (tex == null) |
246 | | - { |
247 | | - return null; |
248 | | - } |
249 | | - |
250 | | - Rect src = tile.UnityRect; |
251 | | - rect = LDtkCoordConverter.ImageSlice(src, tex.height); |
252 | | - |
253 | | - string texPath = AssetDatabase.GetAssetPath(tex); |
254 | | - return texPath; |
255 | | - } |
256 | 141 |
|
257 | 142 | public PointParseData GetParsedPointData() |
258 | 143 | { |
|
0 commit comments