void OnEnable() { instance = this; atlasToRemove = new List <UGUIAtlas> (); atlases = new List <UGUIAtlas> (Resources.FindObjectsOfTypeAll <UGUIAtlas> ()); SortAtlases(); }
public static void Hide() { if (instance != null) { instance.Close(); instance = null; } }
public static void Show(UnityAction <UGUIAtlas> onClickAtlas = null, UnityAction <UGUIAtlas> onDoubleClickAtlas = null, UGUIAtlas selectedAtlas = null) { if (instance != null) { instance.Close(); instance = null; } instance = ScriptableWizard.DisplayWizard <AtlasSelector> ("Select an atlas"); instance.onClickAtlas = onClickAtlas; instance.onDoubleClickAtlas = onDoubleClickAtlas; instance.selectedAtlas = selectedAtlas; }
private void OnDoubleClickAtlas(UGUIAtlas atlas) { serializedObject.Update(); SerializedProperty atlasProperty = serializedObject.FindProperty("_uiAtlas"); if (atlasProperty != null && atlasProperty.objectReferenceValue != atlas) { Undo.RecordObject(serializedObject.targetObject, "Atlas Selection"); atlasProperty.objectReferenceValue = atlas; SerializedProperty spriteProperty = serializedObject.FindProperty("m_Sprite"); if (spriteProperty != null) { spriteProperty.objectReferenceValue = null; } serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(serializedObject.targetObject); } AtlasSelector.Hide(); }
void OnDisable() { instance = null; }
public override void OnInspectorGUI() { serializedObject.Update(); if (atlasProperty != null) { using (EditorGUILayout.HorizontalScope horizontalScope = new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("Atlas", "DropDown", GUILayout.Width(EditorGUIUtility.labelWidth - 10)) == true) { AtlasSelector.Show(null, OnDoubleClickAtlas, atlasProperty.objectReferenceValue as UGUIAtlas); } //绘制图集属性 UGUIAtlas selectedAtlas = EditorGUILayout.ObjectField(atlasProperty.objectReferenceValue, typeof(UGUIAtlas), true) as UGUIAtlas; if (selectedAtlas != atlasProperty.objectReferenceValue) { atlasProperty.objectReferenceValue = selectedAtlas; spriteProperty.objectReferenceValue = null; serializedObject.ApplyModifiedProperties(); } } using (EditorGUILayout.HorizontalScope horizontalScope = new EditorGUILayout.HorizontalScope()) { var atlas = atlasProperty.objectReferenceValue as UGUIAtlas; if (atlas != null) { if (GUILayout.Button("Sprite", "DropDown", GUILayout.Width(EditorGUIUtility.labelWidth - 10)) == true) { AtlasSpriteSelector.Show(atlas, OnClickSprite, OnDoubleClickSprite, spriteProperty.objectReferenceValue as Sprite); } } else { GUILayout.Label("Sprite", GUILayout.Width(EditorGUIUtility.labelWidth - 10)); } using (EditorGUI.DisabledScope disableGroup = new EditorGUI.DisabledScope(atlas != null)) { using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.PropertyField(spriteProperty, new GUIContent("")); if (changeCheckScope.changed == true) { var newSprite = spriteProperty.objectReferenceValue as Sprite; if (newSprite) { Image.Type oldType = (Image.Type)typeProperty.enumValueIndex; if (newSprite.border.SqrMagnitude() > 0) { typeProperty.enumValueIndex = (int)Image.Type.Sliced; } else if (oldType == Image.Type.Sliced) { typeProperty.enumValueIndex = (int)Image.Type.Simple; } } } serializedObject.ApplyModifiedProperties(); } } } AppearanceControlsGUI(); RaycastControlsGUI(); showType.target = spriteProperty.objectReferenceValue != null; if (EditorGUILayout.BeginFadeGroup(showType.faded)) { TypeGUI(); } EditorGUILayout.EndFadeGroup(); SetShowNativeSize(true, true); if (EditorGUILayout.BeginFadeGroup(m_ShowNativeSize.faded)) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(preserveAspectProperty); EditorGUI.indentLevel--; } EditorGUILayout.EndFadeGroup(); NativeSizeButtonGUI(); serializedObject.ApplyModifiedProperties(); } }