Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. #if USE_TEXTURE_PLATFORM_FIX
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using PhotoshopFile;
  6. using UnityEditor.AssetImporters;
  7. using UnityEditor.IMGUI.Controls;
  8. using UnityEditor.U2D.Animation;
  9. using UnityEditor.U2D.Common;
  10. using UnityEditor.U2D.Sprites;
  11. using UnityEngine;
  12. using UnityEngine.Profiling;
  13. using UnityEngine.Scripting.APIUpdating;
  14. using UnityEngine.U2D.Animation;
  15. using UnityEngine.U2D.Common;
  16. namespace UnityEditor.U2D.PSD
  17. {
  18. /// <summary>
  19. /// Inspector for PSDImporter
  20. /// </summary>
  21. [CustomEditor(typeof(PSDImporter))]
  22. [MovedFrom("UnityEditor.Experimental.AssetImporters")]
  23. public class PSDImporterEditor : ScriptedImporterEditor, ITexturePlatformSettingsDataProvider
  24. {
  25. struct InspectorGUI
  26. {
  27. public Action callback;
  28. public bool needsRepaint;
  29. }
  30. SerializedProperty m_TextureType;
  31. SerializedProperty m_TextureShape;
  32. SerializedProperty m_SpriteMode;
  33. SerializedProperty m_SpritePixelsToUnits;
  34. SerializedProperty m_SpriteMeshType;
  35. SerializedProperty m_SpriteExtrude;
  36. SerializedProperty m_Alignment;
  37. SerializedProperty m_SpritePivot;
  38. SerializedProperty m_NPOTScale;
  39. SerializedProperty m_IsReadable;
  40. SerializedProperty m_sRGBTexture;
  41. SerializedProperty m_AlphaSource;
  42. SerializedProperty m_MipMapMode;
  43. SerializedProperty m_EnableMipMap;
  44. SerializedProperty m_FadeOut;
  45. SerializedProperty m_BorderMipMap;
  46. SerializedProperty m_MipMapsPreserveCoverage;
  47. SerializedProperty m_AlphaTestReferenceValue;
  48. SerializedProperty m_MipMapFadeDistanceStart;
  49. SerializedProperty m_MipMapFadeDistanceEnd;
  50. SerializedProperty m_AlphaIsTransparency;
  51. SerializedProperty m_FilterMode;
  52. SerializedProperty m_Aniso;
  53. SerializedProperty m_WrapU;
  54. SerializedProperty m_WrapV;
  55. SerializedProperty m_WrapW;
  56. SerializedProperty m_ConvertToNormalMap;
  57. SerializedProperty m_MosaicLayers;
  58. SerializedProperty m_ImportHiddenLayers;
  59. SerializedProperty m_ResliceFromLayer;
  60. SerializedProperty m_CharacterMode;
  61. SerializedProperty m_DocumentPivot;
  62. SerializedProperty m_DocumentAlignment;
  63. SerializedProperty m_GenerateGOHierarchy;
  64. SerializedProperty m_PaperDollMode;
  65. SerializedProperty m_KeepDupilcateSpriteName;
  66. SerializedProperty m_SkeletonAssetReferenceID;
  67. SerializedProperty m_GeneratePhysicsShape;
  68. SerializedProperty m_LayerMappingOption;
  69. SerializedProperty m_PlatformSettingsArrProp;
  70. private SkeletonAsset m_SkeletonAsset;
  71. readonly int[] m_FilterModeOptions = (int[])(Enum.GetValues(typeof(FilterMode)));
  72. bool m_IsPOT = false;
  73. Dictionary<TextureImporterType, Action[]> m_AdvanceInspectorGUI = new Dictionary<TextureImporterType, Action[]>();
  74. int m_PlatformSettingsIndex;
  75. bool m_ShowPerAxisWrapModes = false;
  76. int m_ActiveEditorIndex = 0;
  77. TexturePlatformSettingsHelper m_TexturePlatformSettingsHelper;
  78. TexturePlatformSettingsView m_TexturePlatformSettingsView = new TexturePlatformSettingsView();
  79. TexturePlatformSettingsController m_TexturePlatformSettingsController = new TexturePlatformSettingsController();
  80. PSDImporterEditorFoldOutState m_EditorFoldOutState = new PSDImporterEditorFoldOutState();
  81. InspectorGUI[] m_InspectorUI;
  82. PSDImporterEditorLayerTreeView m_LayerTreeView;
  83. TreeViewState m_TreeViewState;
  84. PSDImporter m_CurrentTarget;
  85. PSDGameObjectPreviewData m_PreviewRenderUtility;
  86. /// <summary>
  87. /// Implementation of AssetImporterEditor.OnEnable
  88. /// </summary>
  89. public override void OnEnable()
  90. {
  91. base.OnEnable();
  92. m_MosaicLayers = serializedObject.FindProperty("m_MosaicLayers");
  93. m_ImportHiddenLayers = serializedObject.FindProperty("m_ImportHiddenLayers");
  94. m_ResliceFromLayer = serializedObject.FindProperty("m_ResliceFromLayer");
  95. m_CharacterMode = serializedObject.FindProperty("m_CharacterMode");
  96. m_DocumentPivot = serializedObject.FindProperty("m_DocumentPivot");
  97. m_DocumentAlignment = serializedObject.FindProperty("m_DocumentAlignment");
  98. m_GenerateGOHierarchy = serializedObject.FindProperty("m_GenerateGOHierarchy");
  99. m_PaperDollMode = serializedObject.FindProperty("m_PaperDollMode");
  100. m_KeepDupilcateSpriteName = serializedObject.FindProperty("m_KeepDupilcateSpriteName");
  101. m_SkeletonAssetReferenceID = serializedObject.FindProperty("m_SkeletonAssetReferenceID");
  102. m_GeneratePhysicsShape = serializedObject.FindProperty("m_GeneratePhysicsShape");
  103. m_LayerMappingOption = serializedObject.FindProperty("m_LayerMappingOption");
  104. var textureImporterSettingsSP = serializedObject.FindProperty("m_TextureImporterSettings");
  105. m_TextureType = textureImporterSettingsSP.FindPropertyRelative("m_TextureType");
  106. m_TextureShape = textureImporterSettingsSP.FindPropertyRelative("m_TextureShape");
  107. m_ConvertToNormalMap = textureImporterSettingsSP.FindPropertyRelative("m_ConvertToNormalMap");
  108. m_SpriteMode = textureImporterSettingsSP.FindPropertyRelative("m_SpriteMode");
  109. m_SpritePixelsToUnits = textureImporterSettingsSP.FindPropertyRelative("m_SpritePixelsToUnits");
  110. m_SpriteMeshType = textureImporterSettingsSP.FindPropertyRelative("m_SpriteMeshType");
  111. m_SpriteExtrude = textureImporterSettingsSP.FindPropertyRelative("m_SpriteExtrude");
  112. m_Alignment = textureImporterSettingsSP.FindPropertyRelative("m_Alignment");
  113. m_SpritePivot = textureImporterSettingsSP.FindPropertyRelative("m_SpritePivot");
  114. m_NPOTScale = textureImporterSettingsSP.FindPropertyRelative("m_NPOTScale");
  115. m_IsReadable = textureImporterSettingsSP.FindPropertyRelative("m_IsReadable");
  116. m_sRGBTexture = textureImporterSettingsSP.FindPropertyRelative("m_sRGBTexture");
  117. m_AlphaSource = textureImporterSettingsSP.FindPropertyRelative("m_AlphaSource");
  118. m_MipMapMode = textureImporterSettingsSP.FindPropertyRelative("m_MipMapMode");
  119. m_EnableMipMap = textureImporterSettingsSP.FindPropertyRelative("m_EnableMipMap");
  120. m_FadeOut = textureImporterSettingsSP.FindPropertyRelative("m_FadeOut");
  121. m_BorderMipMap = textureImporterSettingsSP.FindPropertyRelative("m_BorderMipMap");
  122. m_MipMapsPreserveCoverage = textureImporterSettingsSP.FindPropertyRelative("m_MipMapsPreserveCoverage");
  123. m_AlphaTestReferenceValue = textureImporterSettingsSP.FindPropertyRelative("m_AlphaTestReferenceValue");
  124. m_MipMapFadeDistanceStart = textureImporterSettingsSP.FindPropertyRelative("m_MipMapFadeDistanceStart");
  125. m_MipMapFadeDistanceEnd = textureImporterSettingsSP.FindPropertyRelative("m_MipMapFadeDistanceEnd");
  126. m_AlphaIsTransparency = textureImporterSettingsSP.FindPropertyRelative("m_AlphaIsTransparency");
  127. m_FilterMode = textureImporterSettingsSP.FindPropertyRelative("m_FilterMode");
  128. m_Aniso = textureImporterSettingsSP.FindPropertyRelative("m_Aniso");
  129. m_WrapU = textureImporterSettingsSP.FindPropertyRelative("m_WrapU");
  130. m_WrapV = textureImporterSettingsSP.FindPropertyRelative("m_WrapV");
  131. m_WrapW = textureImporterSettingsSP.FindPropertyRelative("m_WrapW");
  132. m_PlatformSettingsArrProp = extraDataSerializedObject.FindProperty("platformSettings");
  133. foreach (var t in targets)
  134. {
  135. m_IsPOT &= ((PSDImporter)t).isNPOT;
  136. }
  137. var assetPath = AssetDatabase.GUIDToAssetPath(m_SkeletonAssetReferenceID.stringValue);
  138. m_SkeletonAsset = AssetDatabase.LoadAssetAtPath<SkeletonAsset>(assetPath);
  139. var advanceGUIAction = new Action[]
  140. {
  141. ColorSpaceGUI,
  142. AlphaHandlingGUI,
  143. POTScaleGUI,
  144. ReadableGUI,
  145. MipMapGUI
  146. };
  147. m_AdvanceInspectorGUI.Add(TextureImporterType.Sprite, advanceGUIAction);
  148. advanceGUIAction = new Action[]
  149. {
  150. POTScaleGUI,
  151. ReadableGUI,
  152. MipMapGUI
  153. };
  154. m_AdvanceInspectorGUI.Add(TextureImporterType.Default, advanceGUIAction);
  155. m_TexturePlatformSettingsHelper = new TexturePlatformSettingsHelper(this);
  156. m_ActiveEditorIndex = EditorPrefs.GetInt(this.GetType().Name + "ActiveEditorIndex", 0);
  157. m_InspectorUI = new []
  158. {
  159. new InspectorGUI()
  160. {
  161. callback = DoSettingsUI,
  162. needsRepaint = false
  163. },
  164. new InspectorGUI()
  165. {
  166. callback = DoLayerManagementUI,
  167. needsRepaint = true
  168. }
  169. };
  170. m_TreeViewState = new TreeViewState();
  171. UpdateLayerTreeView();
  172. InitPreview();
  173. }
  174. /// <summary>
  175. /// Override for AssetImporter.extraDataType
  176. /// </summary>
  177. protected override Type extraDataType => typeof(PSDImporterEditorExternalData);
  178. /// <summary>
  179. /// Override for AssetImporter.InitializeExtraDataInstance
  180. /// </summary>
  181. /// <param name="extraTarget">Target object</param>
  182. /// <param name="targetIndex">Target index</param>
  183. protected override void InitializeExtraDataInstance(UnityEngine.Object extraTarget, int targetIndex)
  184. {
  185. var importer = targets[targetIndex] as PSDImporter;
  186. var extraData = extraTarget as PSDImporterEditorExternalData;
  187. var platformSettingsNeeded = TexturePlatformSettingsHelper.PlatformSettingsNeeded(this);
  188. if (importer != null)
  189. {
  190. extraData.Init(importer, platformSettingsNeeded);
  191. }
  192. }
  193. void InitPreview()
  194. {
  195. var t = (PSDImporter)target;
  196. var gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(t.assetPath);
  197. if (m_PreviewRenderUtility != null)
  198. {
  199. m_PreviewRenderUtility.Dispose();
  200. m_PreviewRenderUtility = null;
  201. }
  202. if (gameObject != null)
  203. {
  204. var documentSize = new Rect(0, 0, t.importData.documentSize.x / t.pixelsPerUnit, t.importData.documentSize.y / t.pixelsPerUnit);
  205. m_PreviewRenderUtility = new PSDGameObjectPreviewData(gameObject, documentSize);
  206. }
  207. }
  208. /// <summary>
  209. /// Implmentation of AssetImporterEditor.OnDisable
  210. /// </summary>
  211. public override void OnDisable()
  212. {
  213. base.OnDisable();
  214. if (m_PreviewRenderUtility != null)
  215. {
  216. m_PreviewRenderUtility.Dispose();
  217. m_PreviewRenderUtility = null;
  218. }
  219. }
  220. void UpdateLayerTreeView()
  221. {
  222. if (!ReferenceEquals(m_CurrentTarget,target) || m_LayerTreeView == null)
  223. {
  224. m_CurrentTarget = (PSDImporter)target;
  225. m_LayerTreeView = new PSDImporterEditorLayerTreeView(assetTarget.name, m_TreeViewState, m_CurrentTarget.importData.psdLayerData, m_ImportHiddenLayers.boolValue, serializedObject.FindProperty("m_PSDLayerImportSetting"), m_CurrentTarget.GetLayerMappingStrategy());
  226. }
  227. }
  228. /// <summary>
  229. /// Override from AssetImporterEditor.RequiresConstantRepaint
  230. /// </summary>
  231. /// <returns>Returns true when in Layer Management tab for UI feedback update, false otherwise.</returns>
  232. public override bool RequiresConstantRepaint()
  233. {
  234. return m_InspectorUI[m_ActiveEditorIndex].needsRepaint;
  235. }
  236. /// <summary>
  237. /// Implementation of AssetImporterEditor.OnInspectorGUI
  238. /// </summary>
  239. public override void OnInspectorGUI()
  240. {
  241. Profiler.BeginSample("PSDImporter.OnInspectorGUI");
  242. serializedObject.Update();
  243. extraDataSerializedObject.Update();
  244. if (s_Styles == null)
  245. s_Styles = new Styles();
  246. UpdateLayerTreeView();
  247. GUILayout.Space(5);
  248. using (new GUILayout.HorizontalScope())
  249. {
  250. GUILayout.FlexibleSpace();
  251. using (var check = new EditorGUI.ChangeCheckScope())
  252. {
  253. m_ActiveEditorIndex = GUILayout.Toolbar(m_ActiveEditorIndex, s_Styles.editorTabNames, "LargeButton", GUI.ToolbarButtonSize.FitToContents);
  254. if (check.changed)
  255. {
  256. EditorPrefs.SetInt(GetType().Name + "ActiveEditorIndex", m_ActiveEditorIndex);
  257. }
  258. }
  259. GUILayout.FlexibleSpace();
  260. }
  261. GUILayout.Space(5);
  262. m_InspectorUI[m_ActiveEditorIndex].callback();
  263. serializedObject.ApplyModifiedProperties();
  264. extraDataSerializedObject.ApplyModifiedProperties();
  265. ApplyRevertGUI();
  266. Profiler.EndSample();
  267. }
  268. void DoLayerManagementUI()
  269. {
  270. var rect = InternalEngineBridge.GetGUIClipVisibleRect();
  271. //Magic number. 54 is for header. The rest no idea.
  272. rect = GUILayoutUtility.GetRect(0,rect.height - (54 + 120), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
  273. m_LayerTreeView.OnGUI(rect);
  274. }
  275. void DoSettingsUI()
  276. {
  277. if (m_EditorFoldOutState.DoGeneralUI(s_Styles.generalHeaderText))
  278. {
  279. EditorGUI.showMixedValue = m_TextureType.hasMultipleDifferentValues;
  280. m_TextureType.intValue = EditorGUILayout.IntPopup(s_Styles.textureTypeTitle, m_TextureType.intValue, s_Styles.textureTypeOptions, s_Styles.textureTypeValues);
  281. EditorGUI.showMixedValue = false;
  282. switch ((TextureImporterType)m_TextureType.intValue)
  283. {
  284. case TextureImporterType.Sprite:
  285. DoSpriteTextureTypeInspector();
  286. break;
  287. case TextureImporterType.Default:
  288. DoTextureDefaultTextureTypeInspector();
  289. break;
  290. default:
  291. Debug.LogWarning("We only support Default or Sprite texture type for now. Texture type is set to default.");
  292. m_TextureType.intValue = (int)TextureImporterType.Default;
  293. break;
  294. }
  295. GUILayout.Space(5);
  296. }
  297. if ((TextureImporterType)m_TextureType.intValue == TextureImporterType.Sprite)
  298. DoSpriteInspector();
  299. CommonTextureSettingsGUI();
  300. DoPlatformSettings();
  301. DoAdvanceInspector();
  302. }
  303. void MainRigPropertyField()
  304. {
  305. EditorGUI.BeginChangeCheck();
  306. m_SkeletonAsset = EditorGUILayout.ObjectField(s_Styles.mainSkeletonName, m_SkeletonAsset, typeof(SkeletonAsset), false) as SkeletonAsset;
  307. if (EditorGUI.EndChangeCheck())
  308. {
  309. var referencePath = AssetDatabase.GetAssetPath(m_SkeletonAsset);
  310. if (referencePath == ((AssetImporter) target).assetPath)
  311. m_SkeletonAssetReferenceID.stringValue = "";
  312. else
  313. m_SkeletonAssetReferenceID.stringValue = AssetDatabase.GUIDFromAssetPath(referencePath).ToString();
  314. }
  315. }
  316. /// <summary>
  317. /// Implementation of AssetImporterEditor.Apply
  318. /// </summary>
  319. protected override void Apply()
  320. {
  321. InternalEditorBridge.ApplySpriteEditorWindow();
  322. FileStream fileStream = new FileStream(((AssetImporter)target).assetPath, FileMode.Open, FileAccess.Read);
  323. var doc = PaintDotNet.Data.PhotoshopFileType.PsdLoad.Load(fileStream, ELoadFlag.Header | ELoadFlag.ColorMode);
  324. PSDApplyEvent evt = new PSDApplyEvent()
  325. {
  326. instance_id = target.GetInstanceID(),
  327. texture_type = m_TextureType.intValue,
  328. sprite_mode = m_SpriteMode.intValue,
  329. mosaic_layer = m_MosaicLayers.boolValue,
  330. import_hidden_layer = m_ImportHiddenLayers.boolValue,
  331. character_mode = m_CharacterMode.boolValue,
  332. generate_go_hierarchy = m_GenerateGOHierarchy.boolValue,
  333. reslice_from_layer = m_ResliceFromLayer.boolValue,
  334. is_character_rigged = IsCharacterRigged(),
  335. is_psd = IsPSD(doc),
  336. color_mode = FileColorMode(doc)
  337. };
  338. doc.Cleanup();
  339. AnalyticFactory.analytics.SendApplyEvent(evt);
  340. m_TexturePlatformSettingsHelper.Apply();
  341. ApplyTexturePlatformSettings();
  342. base.Apply();
  343. PSDImportPostProcessor.currentApplyAssetPath = ((PSDImporter) target).assetPath;
  344. if (m_PreviewRenderUtility != null)
  345. {
  346. m_PreviewRenderUtility.Dispose();
  347. m_PreviewRenderUtility = null;
  348. }
  349. }
  350. void ApplyTexturePlatformSettings()
  351. {
  352. for(int i = 0; i< targets.Length && i < extraDataTargets.Length; ++i)
  353. {
  354. var psdImporter = (PSDImporter)targets[i];
  355. var externalData = (PSDImporterEditorExternalData)extraDataTargets[i];
  356. foreach (var ps in externalData.platformSettings)
  357. {
  358. psdImporter.SetPlatformTextureSettings(ps);
  359. psdImporter.Apply();
  360. }
  361. }
  362. }
  363. static bool IsPSD(PsdFile doc)
  364. {
  365. return !doc.IsLargeDocument;
  366. }
  367. static PsdColorMode FileColorMode(PsdFile doc)
  368. {
  369. return doc.ColorMode;
  370. }
  371. bool IsCharacterRigged()
  372. {
  373. var importer = target as PSDImporter;
  374. if (importer != null)
  375. {
  376. var characterProvider = importer.GetDataProvider<ICharacterDataProvider>();
  377. var meshDataProvider = importer.GetDataProvider<ISpriteMeshDataProvider>();
  378. if (characterProvider != null && meshDataProvider != null)
  379. {
  380. var character = characterProvider.GetCharacterData();
  381. foreach (var parts in character.parts)
  382. {
  383. var vert = meshDataProvider.GetVertices(new GUID(parts.spriteId));
  384. var indices = meshDataProvider.GetIndices(new GUID(parts.spriteId));
  385. if (parts.bones != null && parts.bones.Length > 0 &&
  386. vert != null && vert.Length > 0 &&
  387. indices != null && indices.Length > 0)
  388. return true;
  389. }
  390. }
  391. }
  392. return false;
  393. }
  394. void DoPlatformSettings()
  395. {
  396. if (m_EditorFoldOutState.DoPlatformSettingsUI(s_Styles.platformSettingsHeaderText))
  397. {
  398. GUILayout.Space(5);
  399. m_TexturePlatformSettingsHelper.ShowPlatformSpecificSettings();
  400. GUILayout.Space(5);
  401. }
  402. }
  403. void DoAdvanceInspector()
  404. {
  405. if (!m_TextureType.hasMultipleDifferentValues)
  406. {
  407. if (m_AdvanceInspectorGUI.ContainsKey((TextureImporterType)m_TextureType.intValue))
  408. {
  409. if (m_EditorFoldOutState.DoAdvancedUI(s_Styles.advancedHeaderText))
  410. {
  411. foreach (var action in m_AdvanceInspectorGUI[(TextureImporterType)m_TextureType.intValue])
  412. {
  413. action();
  414. }
  415. }
  416. }
  417. }
  418. }
  419. void CommonTextureSettingsGUI()
  420. {
  421. if (m_EditorFoldOutState.DoTextureUI(s_Styles.textureHeaderText))
  422. {
  423. EditorGUI.BeginChangeCheck();
  424. // Wrap mode
  425. bool isVolume = false;
  426. WrapModePopup(m_WrapU, m_WrapV, m_WrapW, isVolume, ref m_ShowPerAxisWrapModes);
  427. // Display warning about repeat wrap mode on restricted npot emulation
  428. if (m_NPOTScale.intValue == (int)TextureImporterNPOTScale.None &&
  429. (m_WrapU.intValue == (int)TextureWrapMode.Repeat || m_WrapV.intValue == (int)TextureWrapMode.Repeat) &&
  430. !InternalEditorBridge.DoesHardwareSupportsFullNPOT())
  431. {
  432. bool displayWarning = false;
  433. foreach (var target in targets)
  434. {
  435. var imp = (PSDImporter)target;
  436. int w = imp.textureActualWidth;
  437. int h = imp.textureActualHeight;
  438. if (!Mathf.IsPowerOfTwo(w) || !Mathf.IsPowerOfTwo(h))
  439. {
  440. displayWarning = true;
  441. break;
  442. }
  443. }
  444. if (displayWarning)
  445. {
  446. EditorGUILayout.HelpBox(s_Styles.warpNotSupportWarning.text, MessageType.Warning, true);
  447. }
  448. }
  449. // Filter mode
  450. EditorGUI.showMixedValue = m_FilterMode.hasMultipleDifferentValues;
  451. FilterMode filter = (FilterMode)m_FilterMode.intValue;
  452. if ((int)filter == -1)
  453. {
  454. if (m_FadeOut.intValue > 0 || m_ConvertToNormalMap.intValue > 0)
  455. filter = FilterMode.Trilinear;
  456. else
  457. filter = FilterMode.Bilinear;
  458. }
  459. filter = (FilterMode)EditorGUILayout.IntPopup(s_Styles.filterMode, (int)filter, s_Styles.filterModeOptions, m_FilterModeOptions);
  460. EditorGUI.showMixedValue = false;
  461. if (EditorGUI.EndChangeCheck())
  462. m_FilterMode.intValue = (int)filter;
  463. // Aniso
  464. bool showAniso = (FilterMode)m_FilterMode.intValue != FilterMode.Point
  465. && m_EnableMipMap.intValue > 0
  466. && (TextureImporterShape)m_TextureShape.intValue != TextureImporterShape.TextureCube;
  467. using (new EditorGUI.DisabledScope(!showAniso))
  468. {
  469. EditorGUI.BeginChangeCheck();
  470. EditorGUI.showMixedValue = m_Aniso.hasMultipleDifferentValues;
  471. int aniso = m_Aniso.intValue;
  472. if (aniso == -1)
  473. aniso = 1;
  474. aniso = EditorGUILayout.IntSlider(s_Styles.anisoLevelLabel, aniso, 0, 16);
  475. EditorGUI.showMixedValue = false;
  476. if (EditorGUI.EndChangeCheck())
  477. m_Aniso.intValue = aniso;
  478. if (aniso > 1)
  479. {
  480. if (QualitySettings.anisotropicFiltering == AnisotropicFiltering.Disable)
  481. EditorGUILayout.HelpBox(s_Styles.anisotropicDisableInfo.text, MessageType.Info);
  482. else if (QualitySettings.anisotropicFiltering == AnisotropicFiltering.ForceEnable)
  483. EditorGUILayout.HelpBox(s_Styles.anisotropicForceEnableInfo.text, MessageType.Info);
  484. }
  485. }
  486. GUILayout.Space(5);
  487. }
  488. }
  489. private static bool IsAnyTextureObjectUsingPerAxisWrapMode(UnityEngine.Object[] objects, bool isVolumeTexture)
  490. {
  491. foreach (var o in objects)
  492. {
  493. int u = 0, v = 0, w = 0;
  494. // the objects can be Textures themselves, or texture-related importers
  495. if (o is Texture)
  496. {
  497. var ti = (Texture)o;
  498. u = (int)ti.wrapModeU;
  499. v = (int)ti.wrapModeV;
  500. w = (int)ti.wrapModeW;
  501. }
  502. if (o is TextureImporter)
  503. {
  504. var ti = (TextureImporter)o;
  505. u = (int)ti.wrapModeU;
  506. v = (int)ti.wrapModeV;
  507. w = (int)ti.wrapModeW;
  508. }
  509. if (o is IHVImageFormatImporter)
  510. {
  511. var ti = (IHVImageFormatImporter)o;
  512. u = (int)ti.wrapModeU;
  513. v = (int)ti.wrapModeV;
  514. w = (int)ti.wrapModeW;
  515. }
  516. u = Mathf.Max(0, u);
  517. v = Mathf.Max(0, v);
  518. w = Mathf.Max(0, w);
  519. if (u != v)
  520. {
  521. return true;
  522. }
  523. if (isVolumeTexture)
  524. {
  525. if (u != w || v != w)
  526. {
  527. return true;
  528. }
  529. }
  530. }
  531. return false;
  532. }
  533. // showPerAxisWrapModes is state of whether "Per-Axis" mode should be active in the main dropdown.
  534. // It is set automatically if wrap modes in UVW are different, or if user explicitly picks "Per-Axis" option -- when that one is picked,
  535. // then it should stay true even if UVW wrap modes will initially be the same.
  536. //
  537. // Note: W wrapping mode is only shown when isVolumeTexture is true.
  538. internal static void WrapModePopup(SerializedProperty wrapU, SerializedProperty wrapV, SerializedProperty wrapW, bool isVolumeTexture, ref bool showPerAxisWrapModes)
  539. {
  540. if (s_Styles == null)
  541. s_Styles = new Styles();
  542. // In texture importer settings, serialized properties for things like wrap modes can contain -1;
  543. // that seems to indicate "use defaults, user has not changed them to anything" but not totally sure.
  544. // Show them as Repeat wrap modes in the popups.
  545. var wu = (TextureWrapMode)Mathf.Max(wrapU.intValue, 0);
  546. var wv = (TextureWrapMode)Mathf.Max(wrapV.intValue, 0);
  547. var ww = (TextureWrapMode)Mathf.Max(wrapW.intValue, 0);
  548. // automatically go into per-axis mode if values are already different
  549. if (wu != wv)
  550. showPerAxisWrapModes = true;
  551. if (isVolumeTexture)
  552. {
  553. if (wu != ww || wv != ww)
  554. showPerAxisWrapModes = true;
  555. }
  556. // It's not possible to determine whether any single texture in the whole selection is using per-axis wrap modes
  557. // just from SerializedProperty values. They can only tell if "some values in whole selection are different" (e.g.
  558. // wrap value on U axis is not the same among all textures), and can return value of "some" object in the selection
  559. // (typically based on object loading order). So in order for more intuitive behavior with multi-selection,
  560. // we go over the actual objects when there's >1 object selected and some wrap modes are different.
  561. if (!showPerAxisWrapModes)
  562. {
  563. if (wrapU.hasMultipleDifferentValues || wrapV.hasMultipleDifferentValues || (isVolumeTexture && wrapW.hasMultipleDifferentValues))
  564. {
  565. if (IsAnyTextureObjectUsingPerAxisWrapMode(wrapU.serializedObject.targetObjects, isVolumeTexture))
  566. {
  567. showPerAxisWrapModes = true;
  568. }
  569. }
  570. }
  571. int value = showPerAxisWrapModes ? -1 : (int)wu;
  572. // main wrap mode popup
  573. EditorGUI.BeginChangeCheck();
  574. EditorGUI.showMixedValue = !showPerAxisWrapModes && (wrapU.hasMultipleDifferentValues || wrapV.hasMultipleDifferentValues || (isVolumeTexture && wrapW.hasMultipleDifferentValues));
  575. value = EditorGUILayout.IntPopup(s_Styles.wrapModeLabel, value, s_Styles.wrapModeContents, s_Styles.wrapModeValues);
  576. if (EditorGUI.EndChangeCheck() && value != -1)
  577. {
  578. // assign the same wrap mode to all axes, and hide per-axis popups
  579. wrapU.intValue = value;
  580. wrapV.intValue = value;
  581. wrapW.intValue = value;
  582. showPerAxisWrapModes = false;
  583. }
  584. // show per-axis popups if needed
  585. if (value == -1)
  586. {
  587. showPerAxisWrapModes = true;
  588. EditorGUI.indentLevel++;
  589. WrapModeAxisPopup(s_Styles.wrapU, wrapU);
  590. WrapModeAxisPopup(s_Styles.wrapV, wrapV);
  591. if (isVolumeTexture)
  592. {
  593. WrapModeAxisPopup(s_Styles.wrapW, wrapW);
  594. }
  595. EditorGUI.indentLevel--;
  596. }
  597. EditorGUI.showMixedValue = false;
  598. }
  599. static void WrapModeAxisPopup(GUIContent label, SerializedProperty wrapProperty)
  600. {
  601. // In texture importer settings, serialized properties for wrap modes can contain -1, which means "use default".
  602. var wrap = (TextureWrapMode)Mathf.Max(wrapProperty.intValue, 0);
  603. Rect rect = EditorGUILayout.GetControlRect();
  604. EditorGUI.BeginChangeCheck();
  605. EditorGUI.BeginProperty(rect, label, wrapProperty);
  606. wrap = (TextureWrapMode)EditorGUI.EnumPopup(rect, label, wrap);
  607. EditorGUI.EndProperty();
  608. if (EditorGUI.EndChangeCheck())
  609. {
  610. wrapProperty.intValue = (int)wrap;
  611. }
  612. }
  613. void DoWrapModePopup()
  614. {
  615. WrapModePopup(m_WrapU, m_WrapV, m_WrapW, IsVolume(), ref m_ShowPerAxisWrapModes);
  616. }
  617. bool IsVolume()
  618. {
  619. var t = target as Texture;
  620. return t != null && t.dimension == UnityEngine.Rendering.TextureDimension.Tex3D;
  621. }
  622. void DoSpriteTextureTypeInspector()
  623. {
  624. EditorGUI.BeginChangeCheck();
  625. EditorGUILayout.IntPopup(m_SpriteMode, s_Styles.spriteModeOptions, new[] { 1, 2, 3 }, s_Styles.spriteMode);
  626. // Ensure that PropertyField focus will be cleared when we change spriteMode.
  627. if (EditorGUI.EndChangeCheck())
  628. {
  629. GUIUtility.keyboardControl = 0;
  630. }
  631. // Show generic attributes
  632. using (new EditorGUI.DisabledScope(m_SpriteMode.intValue == 0))
  633. {
  634. EditorGUILayout.PropertyField(m_SpritePixelsToUnits, s_Styles.spritePixelsPerUnit);
  635. if (m_SpriteMode.intValue != (int)SpriteImportMode.Polygon && !m_SpriteMode.hasMultipleDifferentValues)
  636. {
  637. EditorGUILayout.IntPopup(m_SpriteMeshType, s_Styles.spriteMeshTypeOptions, new[] { 0, 1 }, s_Styles.spriteMeshType);
  638. }
  639. EditorGUILayout.IntSlider(m_SpriteExtrude, 0, 32, s_Styles.spriteExtrude);
  640. if (m_SpriteMode.intValue == 1)
  641. {
  642. EditorGUILayout.IntPopup(m_Alignment, s_Styles.spriteAlignmentOptions, new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s_Styles.spriteAlignment);
  643. if (m_Alignment.intValue == (int)SpriteAlignment.Custom)
  644. {
  645. GUILayout.BeginHorizontal();
  646. EditorGUILayout.PropertyField(m_SpritePivot, new GUIContent());
  647. GUILayout.EndHorizontal();
  648. }
  649. }
  650. }
  651. EditorGUILayout.PropertyField(m_GeneratePhysicsShape, s_Styles.generatePhysicsShape);
  652. using (new EditorGUI.DisabledScope(!m_MosaicLayers.boolValue))
  653. {
  654. EditorGUILayout.PropertyField(m_ResliceFromLayer, s_Styles.resliceFromLayer);
  655. if (m_ResliceFromLayer.boolValue)
  656. {
  657. EditorGUILayout.HelpBox(s_Styles.resliceFromLayerWarning.text, MessageType.Info, true);
  658. }
  659. }
  660. DoOpenSpriteEditorButton();
  661. }
  662. void DoSpriteInspector()
  663. {
  664. if (m_EditorFoldOutState.DoLayerImportUI(s_Styles.layerImportHeaderText))
  665. {
  666. using (new EditorGUI.DisabledScope(m_SpriteMode.intValue != (int)SpriteImportMode.Multiple || m_SpriteMode.hasMultipleDifferentValues))
  667. {
  668. EditorGUILayout.PropertyField(m_ImportHiddenLayers, s_Styles.importHiddenLayer);
  669. using (new EditorGUI.DisabledScope(m_SpriteMode.intValue != (int)SpriteImportMode.Multiple || m_SpriteMode.hasMultipleDifferentValues))
  670. {
  671. using (new EditorGUI.DisabledScope(m_MosaicLayers.boolValue == false))
  672. {
  673. EditorGUILayout.PropertyField(m_KeepDupilcateSpriteName, s_Styles.keepDuplicateSpriteName);
  674. using (new EditorGUI.DisabledScope(!m_MosaicLayers.boolValue || !m_CharacterMode.boolValue))
  675. {
  676. EditorGUILayout.PropertyField(m_GenerateGOHierarchy, s_Styles.layerGroupLabel);
  677. }
  678. EditorGUILayout.IntPopup(m_LayerMappingOption, s_Styles.layerMappingOption, s_Styles.layerMappingOptionValues, s_Styles.layerMapping);
  679. }
  680. var boolToInt = !m_MosaicLayers.boolValue ? 1 : 0;
  681. EditorGUI.BeginChangeCheck();
  682. boolToInt = EditorGUILayout.IntPopup(s_Styles.mosaicLayers, boolToInt, s_Styles.importModeOptions, s_Styles.falseTrueOptionValue);
  683. if (EditorGUI.EndChangeCheck())
  684. m_MosaicLayers.boolValue = boolToInt != 1;
  685. }
  686. GUILayout.Space(5);
  687. }
  688. GUILayout.Space(5);
  689. }
  690. if (m_EditorFoldOutState.DoCharacterRigUI(s_Styles.characterRigHeaderText))
  691. {
  692. using (new EditorGUI.DisabledScope(m_SpriteMode.intValue != (int)SpriteImportMode.Multiple || m_SpriteMode.hasMultipleDifferentValues || m_MosaicLayers.boolValue == false))
  693. {
  694. EditorGUILayout.PropertyField(m_CharacterMode, s_Styles.characterMode);
  695. using (new EditorGUI.DisabledScope(!m_CharacterMode.boolValue))
  696. {
  697. MainRigPropertyField();
  698. EditorGUILayout.IntPopup(m_DocumentAlignment, s_Styles.spriteAlignmentOptions, new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s_Styles.characterAlignment);
  699. if (m_DocumentAlignment.intValue == (int)SpriteAlignment.Custom)
  700. {
  701. GUILayout.BeginHorizontal();
  702. GUILayout.Space(EditorGUIUtility.labelWidth);
  703. EditorGUILayout.PropertyField(m_DocumentPivot, new GUIContent());
  704. GUILayout.EndHorizontal();
  705. }
  706. }
  707. }
  708. GUILayout.Space(5);
  709. //EditorGUILayout.PropertyField(m_PaperDollMode, s_Styles.paperDollMode);
  710. }
  711. }
  712. void DoOpenSpriteEditorButton()
  713. {
  714. using (new EditorGUI.DisabledScope(targets.Length != 1))
  715. {
  716. GUILayout.BeginHorizontal();
  717. GUILayout.FlexibleSpace();
  718. if (GUILayout.Button(s_Styles.spriteEditorButtonLabel))
  719. {
  720. if (HasModified())
  721. {
  722. // To ensure Sprite Editor Window to have the latest texture import setting,
  723. // We must applied those modified values first.
  724. string dialogText = string.Format(s_Styles.unappliedSettingsDialogContent.text, ((AssetImporter)target).assetPath);
  725. if (EditorUtility.DisplayDialog(s_Styles.unappliedSettingsDialogTitle.text,
  726. dialogText, s_Styles.applyButtonLabel.text, s_Styles.cancelButtonLabel.text))
  727. {
  728. ApplyAndImport();
  729. InternalEditorBridge.ShowSpriteEditorWindow(this.assetTarget);
  730. // We reimported the asset which destroyed the editor, so we can't keep running the UI here.
  731. GUIUtility.ExitGUI();
  732. }
  733. }
  734. else
  735. {
  736. InternalEditorBridge.ShowSpriteEditorWindow(this.assetTarget);
  737. }
  738. }
  739. GUILayout.EndHorizontal();
  740. }
  741. }
  742. void DoTextureDefaultTextureTypeInspector()
  743. {
  744. ColorSpaceGUI();
  745. AlphaHandlingGUI();
  746. }
  747. void ColorSpaceGUI()
  748. {
  749. ToggleFromInt(m_sRGBTexture, s_Styles.sRGBTexture);
  750. }
  751. void POTScaleGUI()
  752. {
  753. using (new EditorGUI.DisabledScope(m_IsPOT || m_TextureType.intValue == (int)TextureImporterType.Sprite))
  754. {
  755. EnumPopup(m_NPOTScale, typeof(TextureImporterNPOTScale), s_Styles.npot);
  756. }
  757. }
  758. void ReadableGUI()
  759. {
  760. ToggleFromInt(m_IsReadable, s_Styles.readWrite);
  761. }
  762. void AlphaHandlingGUI()
  763. {
  764. EditorGUI.showMixedValue = m_AlphaSource.hasMultipleDifferentValues;
  765. EditorGUI.BeginChangeCheck();
  766. int newAlphaUsage = EditorGUILayout.IntPopup(s_Styles.alphaSource, m_AlphaSource.intValue, s_Styles.alphaSourceOptions, s_Styles.alphaSourceValues);
  767. EditorGUI.showMixedValue = false;
  768. if (EditorGUI.EndChangeCheck())
  769. {
  770. m_AlphaSource.intValue = newAlphaUsage;
  771. }
  772. bool showAlphaIsTransparency = (TextureImporterAlphaSource)m_AlphaSource.intValue != TextureImporterAlphaSource.None;
  773. using (new EditorGUI.DisabledScope(!showAlphaIsTransparency))
  774. {
  775. ToggleFromInt(m_AlphaIsTransparency, s_Styles.alphaIsTransparency);
  776. }
  777. }
  778. void MipMapGUI()
  779. {
  780. ToggleFromInt(m_EnableMipMap, s_Styles.generateMipMaps);
  781. if (m_EnableMipMap.boolValue && !m_EnableMipMap.hasMultipleDifferentValues)
  782. {
  783. EditorGUI.indentLevel++;
  784. ToggleFromInt(m_BorderMipMap, s_Styles.borderMipMaps);
  785. m_MipMapMode.intValue = EditorGUILayout.Popup(s_Styles.mipMapFilter, m_MipMapMode.intValue, s_Styles.mipMapFilterOptions);
  786. ToggleFromInt(m_MipMapsPreserveCoverage, s_Styles.mipMapsPreserveCoverage);
  787. if (m_MipMapsPreserveCoverage.intValue != 0 && !m_MipMapsPreserveCoverage.hasMultipleDifferentValues)
  788. {
  789. EditorGUI.indentLevel++;
  790. EditorGUILayout.PropertyField(m_AlphaTestReferenceValue, s_Styles.alphaTestReferenceValue);
  791. EditorGUI.indentLevel--;
  792. }
  793. // Mipmap fadeout
  794. ToggleFromInt(m_FadeOut, s_Styles.mipmapFadeOutToggle);
  795. if (m_FadeOut.intValue > 0)
  796. {
  797. EditorGUI.indentLevel++;
  798. EditorGUI.BeginChangeCheck();
  799. float min = m_MipMapFadeDistanceStart.intValue;
  800. float max = m_MipMapFadeDistanceEnd.intValue;
  801. EditorGUILayout.MinMaxSlider(s_Styles.mipmapFadeOut, ref min, ref max, 0, 10);
  802. if (EditorGUI.EndChangeCheck())
  803. {
  804. m_MipMapFadeDistanceStart.intValue = Mathf.RoundToInt(min);
  805. m_MipMapFadeDistanceEnd.intValue = Mathf.RoundToInt(max);
  806. }
  807. EditorGUI.indentLevel--;
  808. }
  809. EditorGUI.indentLevel--;
  810. }
  811. }
  812. void ToggleFromInt(SerializedProperty property, GUIContent label)
  813. {
  814. EditorGUI.BeginChangeCheck();
  815. EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
  816. int value = EditorGUILayout.Toggle(label, property.intValue > 0) ? 1 : 0;
  817. EditorGUI.showMixedValue = false;
  818. if (EditorGUI.EndChangeCheck())
  819. property.intValue = value;
  820. }
  821. void EnumPopup(SerializedProperty property, System.Type type, GUIContent label)
  822. {
  823. EditorGUILayout.IntPopup(label.text, property.intValue,
  824. System.Enum.GetNames(type),
  825. System.Enum.GetValues(type) as int[]);
  826. }
  827. void ExportMosaicTexture()
  828. {
  829. var assetPath = ((AssetImporter)target).assetPath;
  830. var texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
  831. if (texture2D == null)
  832. return;
  833. if (!texture2D.isReadable)
  834. texture2D = InternalEditorBridge.CreateTemporaryDuplicate(texture2D, texture2D.width, texture2D.height);
  835. var pixelData = texture2D.GetPixels();
  836. texture2D = new Texture2D(texture2D.width, texture2D.height);
  837. texture2D.SetPixels(pixelData);
  838. texture2D.Apply();
  839. byte[] bytes = texture2D.EncodeToPNG();
  840. var fileName = Path.GetFileNameWithoutExtension(assetPath);
  841. var filePath = Path.GetDirectoryName(assetPath);
  842. var savePath = Path.Combine(filePath, fileName + ".png");
  843. File.WriteAllBytes(savePath, bytes);
  844. AssetDatabase.Refresh();
  845. }
  846. /// <summary>
  847. /// Implementation of AssetImporterEditor.ResetValues.
  848. /// </summary>
  849. protected override void ResetValues()
  850. {
  851. base.ResetValues();
  852. m_TexturePlatformSettingsHelper = new TexturePlatformSettingsHelper(this);
  853. }
  854. /// <summary>
  855. /// Implementation of ITexturePlatformSettingsDataProvider.GetTargetCount.
  856. /// </summary>
  857. /// <returns>Returns the number of selected targets.</returns>
  858. public int GetTargetCount()
  859. {
  860. return targets.Length;
  861. }
  862. /// <summary>
  863. /// ITexturePlatformSettingsDataProvider.GetPlatformTextureSettings.
  864. /// </summary>
  865. /// <param name="i">Selected target index.</param>
  866. /// <param name="name">Name of the platform.</param>
  867. /// <returns>TextureImporterPlatformSettings for the given platform name and selected target index.</returns>
  868. public TextureImporterPlatformSettings GetPlatformTextureSettings(int i, string name)
  869. {
  870. var externalData = extraDataSerializedObject.targetObjects[i] as PSDImporterEditorExternalData;
  871. if (externalData != null)
  872. {
  873. foreach (var ps in externalData.platformSettings)
  874. {
  875. if (ps.name == name)
  876. return ps;
  877. }
  878. }
  879. return new TextureImporterPlatformSettings()
  880. {
  881. name = name,
  882. overridden = false
  883. };
  884. }
  885. /// <summary>
  886. /// Implementation of ITexturePlatformSettingsDataProvider.ShowPresetSettings.
  887. /// </summary>
  888. /// <returns>True if valid asset is selected, false otherwiser.</returns>
  889. public bool ShowPresetSettings()
  890. {
  891. return assetTarget == null;
  892. }
  893. /// <summary>
  894. /// Implementation of ITexturePlatformSettingsDataProvider.DoesSourceTextureHaveAlpha.
  895. /// </summary>
  896. /// <param name="i">Index to selected target.</param>
  897. /// <returns>Always returns true since importer deals with source file that has alpha.</returns>
  898. public bool DoesSourceTextureHaveAlpha(int i)
  899. {
  900. return true;
  901. }
  902. /// <summary>
  903. /// Implementation of ITexturePlatformSettingsDataProvider.IsSourceTextureHDR.
  904. /// </summary>
  905. /// <param name="i">Index to selected target.</param>
  906. /// <returns>Always returns false since importer does not handle HDR textures.</returns>
  907. public bool IsSourceTextureHDR(int i)
  908. {
  909. return false;
  910. }
  911. /// <summary>
  912. /// Implementation of ITexturePlatformSettingsDataProvider.SetPlatformTextureSettings.
  913. /// </summary>
  914. /// <param name="i">Selected target index.</param>
  915. /// <param name="platformSettings">TextureImporterPlatformSettings to apply to target.</param>
  916. public void SetPlatformTextureSettings(int i, TextureImporterPlatformSettings platformSettings)
  917. {
  918. // var psdImporter = ((PSDImporter)targets[i]);
  919. // psdImporter.SetPlatformTextureSettings(platformSettings);
  920. // psdImporter.Apply();
  921. }
  922. /// <summary>
  923. /// Implementation of ITexturePlatformSettingsDataProvider.GetImporterSettings.
  924. /// </summary>
  925. /// <param name="i">Selected target index.</param>
  926. /// <param name="settings">TextureImporterPlatformSettings reference for data retrieval.</param>
  927. public void GetImporterSettings(int i, TextureImporterSettings settings)
  928. {
  929. ((PSDImporter)targets[i]).ReadTextureSettings(settings);
  930. // Get settings that have been changed in the inspector
  931. GetSerializedPropertySettings(settings);
  932. }
  933. /// <summary>
  934. /// Retrieves the build target name property of a TextureImporterPlatformSettings
  935. /// </summary>
  936. /// <param name="sp">The SerializedProperty of a TextureImporterPlatformSettings</param>
  937. /// <returns></returns>
  938. string ITexturePlatformSettingsDataProvider.GetBuildTargetName(SerializedProperty sp)
  939. {
  940. return sp.FindPropertyRelative("m_Name").stringValue;
  941. }
  942. /// <summary>
  943. /// Returns SerializedProperty for TextureImporterPlatformSettings array.
  944. /// </summary>
  945. SerializedProperty ITexturePlatformSettingsDataProvider.platformSettingsArray => m_PlatformSettingsArrProp;
  946. internal TextureImporterSettings GetSerializedPropertySettings(TextureImporterSettings settings)
  947. {
  948. if (!m_AlphaSource.hasMultipleDifferentValues)
  949. settings.alphaSource = (TextureImporterAlphaSource)m_AlphaSource.intValue;
  950. if (!m_ConvertToNormalMap.hasMultipleDifferentValues)
  951. settings.convertToNormalMap = m_ConvertToNormalMap.intValue > 0;
  952. if (!m_BorderMipMap.hasMultipleDifferentValues)
  953. settings.borderMipmap = m_BorderMipMap.intValue > 0;
  954. if (!m_MipMapsPreserveCoverage.hasMultipleDifferentValues)
  955. settings.mipMapsPreserveCoverage = m_MipMapsPreserveCoverage.intValue > 0;
  956. if (!m_AlphaTestReferenceValue.hasMultipleDifferentValues)
  957. settings.alphaTestReferenceValue = m_AlphaTestReferenceValue.floatValue;
  958. if (!m_NPOTScale.hasMultipleDifferentValues)
  959. settings.npotScale = (TextureImporterNPOTScale)m_NPOTScale.intValue;
  960. if (!m_IsReadable.hasMultipleDifferentValues)
  961. settings.readable = m_IsReadable.intValue > 0;
  962. if (!m_sRGBTexture.hasMultipleDifferentValues)
  963. settings.sRGBTexture = m_sRGBTexture.intValue > 0;
  964. if (!m_EnableMipMap.hasMultipleDifferentValues)
  965. settings.mipmapEnabled = m_EnableMipMap.intValue > 0;
  966. if (!m_MipMapMode.hasMultipleDifferentValues)
  967. settings.mipmapFilter = (TextureImporterMipFilter)m_MipMapMode.intValue;
  968. if (!m_FadeOut.hasMultipleDifferentValues)
  969. settings.fadeOut = m_FadeOut.intValue > 0;
  970. if (!m_MipMapFadeDistanceStart.hasMultipleDifferentValues)
  971. settings.mipmapFadeDistanceStart = m_MipMapFadeDistanceStart.intValue;
  972. if (!m_MipMapFadeDistanceEnd.hasMultipleDifferentValues)
  973. settings.mipmapFadeDistanceEnd = m_MipMapFadeDistanceEnd.intValue;
  974. if (!m_SpriteMode.hasMultipleDifferentValues)
  975. settings.spriteMode = m_SpriteMode.intValue;
  976. if (!m_SpritePixelsToUnits.hasMultipleDifferentValues)
  977. settings.spritePixelsPerUnit = m_SpritePixelsToUnits.floatValue;
  978. if (!m_SpriteExtrude.hasMultipleDifferentValues)
  979. settings.spriteExtrude = (uint)m_SpriteExtrude.intValue;
  980. if (!m_SpriteMeshType.hasMultipleDifferentValues)
  981. settings.spriteMeshType = (SpriteMeshType)m_SpriteMeshType.intValue;
  982. if (!m_Alignment.hasMultipleDifferentValues)
  983. settings.spriteAlignment = m_Alignment.intValue;
  984. if (!m_SpritePivot.hasMultipleDifferentValues)
  985. settings.spritePivot = m_SpritePivot.vector2Value;
  986. if (!m_WrapU.hasMultipleDifferentValues)
  987. settings.wrapModeU = (TextureWrapMode)m_WrapU.intValue;
  988. if (!m_WrapV.hasMultipleDifferentValues)
  989. settings.wrapModeU = (TextureWrapMode)m_WrapV.intValue;
  990. if (!m_WrapW.hasMultipleDifferentValues)
  991. settings.wrapModeU = (TextureWrapMode)m_WrapW.intValue;
  992. if (!m_FilterMode.hasMultipleDifferentValues)
  993. settings.filterMode = (FilterMode)m_FilterMode.intValue;
  994. if (!m_Aniso.hasMultipleDifferentValues)
  995. settings.aniso = m_Aniso.intValue;
  996. if (!m_AlphaIsTransparency.hasMultipleDifferentValues)
  997. settings.alphaIsTransparency = m_AlphaIsTransparency.intValue > 0;
  998. if (!m_TextureType.hasMultipleDifferentValues)
  999. settings.textureType = (TextureImporterType)m_TextureType.intValue;
  1000. if (!m_TextureShape.hasMultipleDifferentValues)
  1001. settings.textureShape = (TextureImporterShape)m_TextureShape.intValue;
  1002. return settings;
  1003. }
  1004. /// <summary>
  1005. /// Override of AssetImporterEditor.showImportedObject
  1006. /// The property always returns false so that imported objects does not show up in the Inspector.
  1007. /// </summary>
  1008. /// <returns>false</returns>
  1009. public override bool showImportedObject
  1010. {
  1011. get { return false; }
  1012. }
  1013. /// <summary>
  1014. /// Implementation of ITexturePlatformSettingsDataProvider.textureTypeHasMultipleDifferentValues.
  1015. /// </summary>
  1016. public bool textureTypeHasMultipleDifferentValues
  1017. {
  1018. get { return m_TextureType.hasMultipleDifferentValues; }
  1019. }
  1020. /// <summary>
  1021. /// Implementation of ITexturePlatformSettingsDataProvider.textureType.
  1022. /// </summary>
  1023. public TextureImporterType textureType
  1024. {
  1025. get { return (TextureImporterType)m_TextureType.intValue; }
  1026. }
  1027. /// <summary>
  1028. /// Implementation of ITexturePlatformSettingsDataProvider.spriteImportMode.
  1029. /// </summary>
  1030. public SpriteImportMode spriteImportMode
  1031. {
  1032. get { return (SpriteImportMode)m_SpriteMode.intValue; }
  1033. }
  1034. /// <summary>
  1035. /// Override of AssetImporterEditor.HasModified.
  1036. /// </summary>
  1037. /// <returns>Returns True if has modified data. False otherwise.</returns>
  1038. public override bool HasModified()
  1039. {
  1040. if (base.HasModified())
  1041. return true;
  1042. return m_TexturePlatformSettingsHelper.HasModified();
  1043. }
  1044. /// <summary>
  1045. /// Override from AssetImporterEditor to show custom preview.
  1046. /// </summary>
  1047. /// <param name="r">Preview Rect.</param>
  1048. public override void DrawPreview(Rect r)
  1049. {
  1050. if (m_PreviewRenderUtility == null)
  1051. InitPreview();
  1052. if (m_PreviewRenderUtility != null)
  1053. {
  1054. var t = (PSDImporter)target;
  1055. var prefabBounds = new Rect(0 , 0, t.importData.documentSize.x/ t.pixelsPerUnit, t.importData.documentSize.y/ t.pixelsPerUnit);
  1056. m_PreviewRenderUtility.DrawPreview(r, "PreBackgroundSolid", prefabBounds.center, false);
  1057. }
  1058. else
  1059. base.DrawPreview(r);
  1060. }
  1061. internal class Styles
  1062. {
  1063. public readonly GUIContent textureTypeTitle = new GUIContent("Texture Type", "What will this texture be used for?");
  1064. public readonly GUIContent[] textureTypeOptions =
  1065. {
  1066. new GUIContent("Default", "Texture is a normal image such as a diffuse texture or other."),
  1067. new GUIContent("Sprite (2D and UI)", "Texture is used for a sprite."),
  1068. };
  1069. public readonly int[] textureTypeValues =
  1070. {
  1071. (int)TextureImporterType.Default,
  1072. (int)TextureImporterType.Sprite,
  1073. };
  1074. private readonly GUIContent textureShape2D = new GUIContent("2D, Texture is 2D.");
  1075. private readonly GUIContent textureShapeCube = new GUIContent("Cube", "Texture is a Cubemap.");
  1076. public readonly Dictionary<TextureImporterShape, GUIContent[]> textureShapeOptionsDictionnary = new Dictionary<TextureImporterShape, GUIContent[]>();
  1077. public readonly Dictionary<TextureImporterShape, int[]> textureShapeValuesDictionnary = new Dictionary<TextureImporterShape, int[]>();
  1078. public readonly GUIContent filterMode = new GUIContent("Filter Mode");
  1079. public readonly GUIContent[] filterModeOptions =
  1080. {
  1081. new GUIContent("Point (no filter)"),
  1082. new GUIContent("Bilinear"),
  1083. new GUIContent("Trilinear")
  1084. };
  1085. public readonly GUIContent mipmapFadeOutToggle = new GUIContent("Fadeout Mip Maps");
  1086. public readonly GUIContent mipmapFadeOut = new GUIContent("Fade Range");
  1087. public readonly GUIContent readWrite = new GUIContent("Read/Write Enabled", "Enable to be able to access the raw pixel data from code.");
  1088. public readonly GUIContent alphaSource = new GUIContent("Alpha Source", "How is the alpha generated for the imported texture.");
  1089. public readonly GUIContent[] alphaSourceOptions =
  1090. {
  1091. new GUIContent("None", "No Alpha will be used."),
  1092. new GUIContent("Input Texture Alpha", "Use Alpha from the input texture if one is provided."),
  1093. new GUIContent("From Gray Scale", "Generate Alpha from image gray scale."),
  1094. };
  1095. public readonly int[] alphaSourceValues =
  1096. {
  1097. (int)TextureImporterAlphaSource.None,
  1098. (int)TextureImporterAlphaSource.FromInput,
  1099. (int)TextureImporterAlphaSource.FromGrayScale,
  1100. };
  1101. public readonly GUIContent generateMipMaps = new GUIContent("Generate Mip Maps");
  1102. public readonly GUIContent sRGBTexture = new GUIContent("sRGB (Color Texture)", "Texture content is stored in gamma space. Non-HDR color textures should enable this flag (except if used for IMGUI).");
  1103. public readonly GUIContent borderMipMaps = new GUIContent("Border Mip Maps");
  1104. public readonly GUIContent mipMapsPreserveCoverage = new GUIContent("Mip Maps Preserve Coverage", "The alpha channel of generated Mip Maps will preserve coverage during the alpha test.");
  1105. public readonly GUIContent alphaTestReferenceValue = new GUIContent("Alpha Cutoff Value", "The reference value used during the alpha test. Controls Mip Map coverage.");
  1106. public readonly GUIContent mipMapFilter = new GUIContent("Mip Map Filtering");
  1107. public readonly GUIContent[] mipMapFilterOptions =
  1108. {
  1109. new GUIContent("Box"),
  1110. new GUIContent("Kaiser"),
  1111. };
  1112. public readonly GUIContent npot = new GUIContent("Non Power of 2", "How non-power-of-two textures are scaled on import.");
  1113. public readonly GUIContent spriteMode = new GUIContent("Sprite Mode");
  1114. public readonly GUIContent[] spriteModeOptions =
  1115. {
  1116. new GUIContent("Single"),
  1117. new GUIContent("Multiple"),
  1118. new GUIContent("Polygon"),
  1119. };
  1120. public readonly GUIContent[] spriteMeshTypeOptions =
  1121. {
  1122. new GUIContent("Full Rect"),
  1123. new GUIContent("Tight"),
  1124. };
  1125. public readonly GUIContent spritePixelsPerUnit = new GUIContent("Pixels Per Unit", "How many pixels in the sprite correspond to one unit in the world.");
  1126. public readonly GUIContent spriteExtrude = new GUIContent("Extrude Edges", "How much empty area to leave around the sprite in the generated mesh.");
  1127. public readonly GUIContent spriteMeshType = new GUIContent("Mesh Type", "Type of sprite mesh to generate.");
  1128. public readonly GUIContent spriteAlignment = new GUIContent("Pivot", "Sprite pivot point in its local space. May be used for syncing animation frames of different sizes.");
  1129. public readonly GUIContent characterAlignment = new GUIContent("Pivot", "Character pivot point in its local space using normalized value i.e. 0 - 1");
  1130. public readonly GUIContent[] spriteAlignmentOptions =
  1131. {
  1132. new GUIContent("Center"),
  1133. new GUIContent("Top Left"),
  1134. new GUIContent("Top"),
  1135. new GUIContent("Top Right"),
  1136. new GUIContent("Left"),
  1137. new GUIContent("Right"),
  1138. new GUIContent("Bottom Left"),
  1139. new GUIContent("Bottom"),
  1140. new GUIContent("Bottom Right"),
  1141. new GUIContent("Custom"),
  1142. };
  1143. public readonly GUIContent warpNotSupportWarning = new GUIContent("Graphics device doesn't support Repeat wrap mode on NPOT textures. Falling back to Clamp.");
  1144. public readonly GUIContent anisoLevelLabel = new GUIContent("Aniso Level");
  1145. public readonly GUIContent anisotropicDisableInfo = new GUIContent("Anisotropic filtering is disabled for all textures in Quality Settings.");
  1146. public readonly GUIContent anisotropicForceEnableInfo = new GUIContent("Anisotropic filtering is enabled for all textures in Quality Settings.");
  1147. public readonly GUIContent unappliedSettingsDialogTitle = new GUIContent("Unapplied import settings");
  1148. public readonly GUIContent unappliedSettingsDialogContent = new GUIContent("Unapplied import settings for \'{0}\'.\nApply and continue to sprite editor or cancel.");
  1149. public readonly GUIContent applyButtonLabel = new GUIContent("Apply");
  1150. public readonly GUIContent cancelButtonLabel = new GUIContent("Cancel");
  1151. public readonly GUIContent spriteEditorButtonLabel = new GUIContent("Open Sprite Editor");
  1152. public readonly GUIContent resliceFromLayerWarning = new GUIContent("This will reinitialize and recreate all Sprites based on the file’s layer data. Existing Sprite metadata from previously generated Sprites are copied over.");
  1153. public readonly GUIContent alphaIsTransparency = new GUIContent("Alpha Is Transparency", "If the provided alpha channel is transparency, enable this to pre-filter the color to avoid texture filtering artifacts. This is not supported for HDR textures.");
  1154. public readonly GUIContent advancedHeaderText = new GUIContent("Advanced", "Show advanced settings.");
  1155. public readonly GUIContent platformSettingsHeaderText = new GUIContent("Platform Setttings");
  1156. public readonly GUIContent[] platformSettingsSelection;
  1157. public readonly GUIContent wrapModeLabel = new GUIContent("Wrap Mode");
  1158. public readonly GUIContent wrapU = new GUIContent("U axis");
  1159. public readonly GUIContent wrapV = new GUIContent("V axis");
  1160. public readonly GUIContent wrapW = new GUIContent("W axis");
  1161. public readonly GUIContent[] wrapModeContents =
  1162. {
  1163. new GUIContent("Repeat"),
  1164. new GUIContent("Clamp"),
  1165. new GUIContent("Mirror"),
  1166. new GUIContent("Mirror Once"),
  1167. new GUIContent("Per-axis")
  1168. };
  1169. public readonly int[] wrapModeValues =
  1170. {
  1171. (int)TextureWrapMode.Repeat,
  1172. (int)TextureWrapMode.Clamp,
  1173. (int)TextureWrapMode.Mirror,
  1174. (int)TextureWrapMode.MirrorOnce,
  1175. -1
  1176. };
  1177. public readonly GUIContent layerMapping = EditorGUIUtility.TrTextContent("Layer Mapping", "Options for indicating how layer to Sprite mapping.");
  1178. public readonly GUIContent generatePhysicsShape = EditorGUIUtility.TrTextContent("Generate Physics Shape", "Generates a default physics shape from the outline of the Sprite/s when a physics shape has not been set in the Sprite Editor.");
  1179. public readonly GUIContent importHiddenLayer = EditorGUIUtility.TrTextContent("Include Hidden Layers", "Settings to determine when hidden layers should be imported.");
  1180. public readonly GUIContent mosaicLayers = EditorGUIUtility.TrTextContent("Import Mode", "Layers will be imported as individual Sprites.");
  1181. public readonly GUIContent characterMode = EditorGUIUtility.TrTextContent("Use as Rig","Enable to support 2D Animation character rigging.");
  1182. public readonly GUIContent layerGroupLabel = EditorGUIUtility.TrTextContent("Use Layer Group", "GameObjects are grouped according to source file layer grouping.");
  1183. public readonly GUIContent resliceFromLayer = EditorGUIUtility.TrTextContent("Automatic Reslice", "Recreate Sprite rects from file.");
  1184. public readonly GUIContent paperDollMode = EditorGUIUtility.TrTextContent("Paper Doll Mode", "Special mode to generate a Prefab for Paper Doll use case.");
  1185. public readonly GUIContent keepDuplicateSpriteName = EditorGUIUtility.TrTextContent("Keep Duplicate Names", "Keep Sprite name same as Layer Name even if there are duplicated Layer Name.");
  1186. public readonly GUIContent mainSkeletonName = EditorGUIUtility.TrTextContent("Main Skeleton", "Main Skeleton to use for Rigging.");
  1187. public readonly GUIContent generalHeaderText = EditorGUIUtility.TrTextContent("General", "General settings.");
  1188. public readonly GUIContent layerImportHeaderText = EditorGUIUtility.TrTextContent("Layer Import","Layer Import settings.");
  1189. public readonly GUIContent characterRigHeaderText = EditorGUIUtility.TrTextContent("Character Rig","Character Rig settings.");
  1190. public readonly GUIContent textureHeaderText = EditorGUIUtility.TrTextContent("Texture","Texture settings.");
  1191. public readonly int[] falseTrueOptionValue =
  1192. {
  1193. 0,
  1194. 1
  1195. };
  1196. public readonly GUIContent[] importModeOptions=
  1197. {
  1198. EditorGUIUtility.TrTextContent("Individual Sprites (Mosaic)","Import individual Photoshop layers as Sprites."),
  1199. new GUIContent("Merged","Merge Photoshop layers and import as single Sprite.")
  1200. };
  1201. public readonly GUIContent[] layerMappingOption=
  1202. {
  1203. EditorGUIUtility.TrTextContent("Use Layer ID","Use layer's ID to identify layer and Sprite mapping."),
  1204. EditorGUIUtility.TrTextContent("Use Layer Name","Use layer's name to identify layer and Sprite mapping."),
  1205. EditorGUIUtility.TrTextContent("Use Layer Name (Case Sensitive)","Use layer's name to identify layer and Sprite mapping."),
  1206. };
  1207. public readonly int[] layerMappingOptionValues =
  1208. {
  1209. (int)PSDImporter.ELayerMappingOption.UseLayerId,
  1210. (int)PSDImporter.ELayerMappingOption.UseLayerName,
  1211. (int)PSDImporter.ELayerMappingOption.UseLayerNameCaseSensitive
  1212. };
  1213. public readonly GUIContent[] editorTabNames =
  1214. {
  1215. EditorGUIUtility.TrTextContent("Settings", "Importer Settings."),
  1216. EditorGUIUtility.TrTextContent("Layer Management", "Layer merge settings.")
  1217. };
  1218. public Styles()
  1219. {
  1220. // This is far from ideal, but it's better than having tons of logic in the GUI code itself.
  1221. // The combination should not grow too much anyway since only Texture3D will be added later.
  1222. GUIContent[] s2D_Options = { textureShape2D };
  1223. GUIContent[] sCube_Options = { textureShapeCube };
  1224. GUIContent[] s2D_Cube_Options = { textureShape2D, textureShapeCube };
  1225. textureShapeOptionsDictionnary.Add(TextureImporterShape.Texture2D, s2D_Options);
  1226. textureShapeOptionsDictionnary.Add(TextureImporterShape.TextureCube, sCube_Options);
  1227. textureShapeOptionsDictionnary.Add(TextureImporterShape.Texture2D | TextureImporterShape.TextureCube, s2D_Cube_Options);
  1228. int[] s2D_Values = { (int)TextureImporterShape.Texture2D };
  1229. int[] sCube_Values = { (int)TextureImporterShape.TextureCube };
  1230. int[] s2D_Cube_Values = { (int)TextureImporterShape.Texture2D, (int)TextureImporterShape.TextureCube };
  1231. textureShapeValuesDictionnary.Add(TextureImporterShape.Texture2D, s2D_Values);
  1232. textureShapeValuesDictionnary.Add(TextureImporterShape.TextureCube, sCube_Values);
  1233. textureShapeValuesDictionnary.Add(TextureImporterShape.Texture2D | TextureImporterShape.TextureCube, s2D_Cube_Values);
  1234. platformSettingsSelection = new GUIContent[TexturePlatformSettingsModal.kValidBuildPlatform.Length];
  1235. for (int i = 0; i < TexturePlatformSettingsModal.kValidBuildPlatform.Length; ++i)
  1236. {
  1237. platformSettingsSelection[i] = new GUIContent(TexturePlatformSettingsModal.kValidBuildPlatform[i].buildTargetName);
  1238. }
  1239. }
  1240. }
  1241. internal static Styles s_Styles;
  1242. }
  1243. class PSDImporterEditorFoldOutState
  1244. {
  1245. SavedBool m_GeneralFoldout;
  1246. SavedBool m_LayerImportFoldout;
  1247. SavedBool m_CharacterRigFoldout;
  1248. SavedBool m_AdvancedFoldout;
  1249. SavedBool m_TextureFoldout;
  1250. SavedBool m_PlatformSettingsFoldout;
  1251. public PSDImporterEditorFoldOutState()
  1252. {
  1253. m_GeneralFoldout = new SavedBool("PSDImporterEditor.m_GeneralFoldout", true);
  1254. m_LayerImportFoldout = new SavedBool("PSDImporterEditor.m_LayerImportFoldout", true);
  1255. m_CharacterRigFoldout = new SavedBool("PSDImporterEditor.m_CharacterRigFoldout", false);
  1256. m_AdvancedFoldout = new SavedBool("PSDImporterEditor.m_AdvancedFoldout", false);
  1257. m_TextureFoldout = new SavedBool("PSDImporterEditor.m_TextureFoldout", false);
  1258. m_PlatformSettingsFoldout = new SavedBool("PSDImporterEditor.m_PlatformSettingsFoldout", false);
  1259. }
  1260. bool DoFoldout(GUIContent title, bool state)
  1261. {
  1262. InspectorUtils.DrawSplitter();
  1263. return InspectorUtils.DrawHeaderFoldout(title, state);
  1264. }
  1265. public bool DoGeneralUI(GUIContent title)
  1266. {
  1267. m_GeneralFoldout.value = DoFoldout(title, m_GeneralFoldout.value);
  1268. return m_GeneralFoldout.value;
  1269. }
  1270. public bool DoLayerImportUI(GUIContent title)
  1271. {
  1272. m_LayerImportFoldout.value = DoFoldout(title, m_LayerImportFoldout.value);
  1273. return m_LayerImportFoldout.value;
  1274. }
  1275. public bool DoCharacterRigUI(GUIContent title)
  1276. {
  1277. m_CharacterRigFoldout.value = DoFoldout(title, m_CharacterRigFoldout.value);
  1278. return m_CharacterRigFoldout.value;
  1279. }
  1280. public bool DoAdvancedUI(GUIContent title)
  1281. {
  1282. m_AdvancedFoldout.value = DoFoldout(title, m_AdvancedFoldout.value);
  1283. return m_AdvancedFoldout.value;
  1284. }
  1285. public bool DoPlatformSettingsUI(GUIContent title)
  1286. {
  1287. m_PlatformSettingsFoldout.value = DoFoldout(title, m_PlatformSettingsFoldout.value);
  1288. return m_PlatformSettingsFoldout.value;
  1289. }
  1290. public bool DoTextureUI(GUIContent title)
  1291. {
  1292. m_TextureFoldout.value = DoFoldout(title, m_TextureFoldout.value);
  1293. return m_TextureFoldout.value;
  1294. }
  1295. class SavedBool
  1296. {
  1297. bool m_Value;
  1298. string m_Name;
  1299. bool m_Loaded;
  1300. public SavedBool(string name, bool value)
  1301. {
  1302. m_Name = name;
  1303. m_Loaded = false;
  1304. m_Value = value;
  1305. }
  1306. private void Load()
  1307. {
  1308. if (m_Loaded)
  1309. return;
  1310. m_Loaded = true;
  1311. m_Value = EditorPrefs.GetBool(m_Name, m_Value);
  1312. }
  1313. public bool value
  1314. {
  1315. get { Load(); return m_Value; }
  1316. set
  1317. {
  1318. Load();
  1319. if (m_Value == value)
  1320. return;
  1321. m_Value = value;
  1322. EditorPrefs.SetBool(m_Name, value);
  1323. }
  1324. }
  1325. public static implicit operator bool(SavedBool s)
  1326. {
  1327. return s.value;
  1328. }
  1329. }
  1330. }
  1331. }
  1332. #endif