protected void OnEnable() { #if UNITY_4_6 || UNITY_4_7 this.title = "SP Reference Replacer"; #else this.titleContent = new GUIContent("SP Reference Replacer"); #endif if (EditorPrefs.HasKey(SPTools.Settings_SavedInstanceIDKey)) { string instancePath = AssetDatabase.GetAssetPath(EditorPrefs.GetInt(SPTools.Settings_SavedInstanceIDKey, 0)); if (!string.IsNullOrEmpty(instancePath)) { this.m_Instance = AssetDatabase.LoadAssetAtPath(instancePath, typeof(SPInstance)) as SPInstance; } } // Default prefs if (!EditorPrefs.HasKey(SPReferenceReplacerWindow.PrefsKey_TargetMode)) { EditorPrefs.SetInt(SPReferenceReplacerWindow.PrefsKey_TargetMode, (int)this.m_TargetMode); } // Load target mode setting this.m_TargetMode = (TargetMode)EditorPrefs.GetInt(SPReferenceReplacerWindow.PrefsKey_TargetMode); }
public static void CreateInstance() { string assetPath = GetSavePath(); if (string.IsNullOrEmpty(assetPath)) { return; } // Create the sprite packer instance SPInstance asset = ScriptableObject.CreateInstance("SPInstance") as SPInstance; AssetDatabase.CreateAsset(asset, AssetDatabase.GenerateUniqueAssetPath(assetPath)); AssetDatabase.Refresh(); // Save the instance id in the editor prefs EditorPrefs.SetInt(SPTools.Settings_SavedInstanceIDKey, asset.GetInstanceID()); // Repaint the SPDropWindow EditorWindow.GetWindow(typeof(SPDropWindow)).Repaint(); // Get a name for the texture string texturePath = assetPath.Replace(".asset", ".png"); // Create blank texture if (SPTools.CreateBlankTexture(texturePath, true)) { // Set the texture reff in the sprite packer instance asset.texture = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D; } // Focus on the new sprite packer EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
protected override void OnCreate() { this.instance = this.GetOwner().GetAsset() as SPInstance; for (int i = 0; i < this.imagelist.Count; i++) { SetImage(this.imagelist[i]); } this.imagelist.Clear(); }
protected void OnEnable() { this.m_SPInstance = this.target as SPInstance; this.m_AtlasBuilder = new SPAtlasBuilder(this.m_SPInstance); SPTools.PrepareDefaultEditorPrefs(); this.boxStyle = new GUIStyle(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).box); this.paddingStyle = new GUIStyle(); this.paddingStyle.padding = new RectOffset(3, 3, 3, 3); }
public Sprite GetSprite(string sname, string spname) { spname = spname.ToLower(); SPInstance SPInstance = GetSPInstance(sname); if (SPInstance != null) { return(SPInstance.GetSprite(spname)); } return(null); }
protected void OnEnable() { this.titleContent = new GUIContent("SP Drop"); if (EditorPrefs.HasKey(SPTools.Settings_SavedInstanceIDKey)) { string instancePath = AssetDatabase.GetAssetPath(EditorPrefs.GetInt(SPTools.Settings_SavedInstanceIDKey, 0)); if (!string.IsNullOrEmpty(instancePath)) { this.m_Instance = AssetDatabase.LoadAssetAtPath(instancePath, typeof(SPInstance)) as SPInstance; } } }
protected void OnGUI() { EditorGUIUtility.labelWidth = 100f; GUILayout.BeginVertical(); GUILayout.Space(8f); GUI.changed = false; this.m_Instance = EditorGUILayout.ObjectField("Sprite Packer", this.m_Instance, typeof(SPInstance), false) as SPInstance; if (GUI.changed) { // Save the instance id EditorPrefs.SetInt(SPTools.Settings_SavedInstanceIDKey, (this.m_Instance == null) ? 0 : this.m_Instance.GetInstanceID()); } GUILayout.Space(4f); if (this.m_Instance == null) { EditorGUILayout.HelpBox("Please set the sprite packer instance reference in order to use this feature.", MessageType.Info); } else { Event evt = Event.current; Rect drop_area = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUIStyle boxStyle = new GUIStyle(GUI.skin.box); boxStyle.alignment = TextAnchor.MiddleCenter; GUI.color = SPDropWindow.green; GUI.Box(drop_area, "Add Sprite (Drop Here)", boxStyle); GUI.color = Color.white; switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: { if (!drop_area.Contains(evt.mousePosition)) { return; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); Object[] filtered = SPTools.FilterResourcesForAtlasImport(DragAndDrop.objectReferences); // Additional filtering specific to the instance for (int i = 0; i < filtered.Length; i++) { if (this.m_Instance.sprites.Find(s => s.name == filtered[i].name) != null) { Debug.LogWarning("A sprite with source \"" + SimpleSpritePackerEditor.SPTools.GetAssetPath(filtered[i]) + "\" already exists in the atlas, consider changing the Sprite Packer settings to allow multiple sprites from the same source."); System.Array.Clear(filtered, i, 1); } } // Types are handled internally this.m_Instance.QueueAction_AddSprites(filtered); Selection.activeObject = this.m_Instance; //EditorPrefs.SetBool(SPTools.Settings_ShowSpritesKeys, false); } break; } } } GUILayout.EndVertical(); }
// Constructor public SPAtlasBuilder(SPInstance instance) { this.m_Instance = instance; }
protected void OnGUI() { EditorGUIUtility.labelWidth = 100f; GUILayout.BeginVertical(); GUILayout.Space((float)SPReferenceReplacerWindow.padding.top); GUILayout.BeginHorizontal(); GUILayout.Space((float)SPReferenceReplacerWindow.padding.left); GUILayout.BeginVertical(); GUI.changed = false; this.m_Instance = EditorGUILayout.ObjectField("Sprite Packer", this.m_Instance, typeof(SPInstance), false) as SPInstance; if (GUI.changed) { // Save the instance id EditorPrefs.SetInt(SPTools.Settings_SavedInstanceIDKey, (this.m_Instance == null) ? 0 : this.m_Instance.GetInstanceID()); } GUILayout.Space(6f); GUILayout.BeginVertical(GUI.skin.box); GUILayout.Space(6f); GUILayout.BeginHorizontal(); GUILayout.Space(6f); EditorGUILayout.LabelField("Replace mode", GUILayout.Width(130f)); this.m_ReplaceMode = (ReplaceMode)EditorGUILayout.EnumPopup(this.m_ReplaceMode); GUILayout.Space(6f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(6f); EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField("Replace references in", GUILayout.Width(130f)); this.m_TargetMode = (TargetMode)EditorGUILayout.EnumPopup(this.m_TargetMode); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetInt(SPReferenceReplacerWindow.PrefsKey_TargetMode, (int)this.m_TargetMode); } GUILayout.Space(6f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUI.changed = false; bool spriteRenderersOnly = GUILayout.Toggle(EditorPrefs.GetBool(SPReferenceReplacerWindow.PrefsKey_SpriteRenderersOnly), " Replace references in Sprite Renderers only ?"); if (GUI.changed) { EditorPrefs.SetBool(SPReferenceReplacerWindow.PrefsKey_SpriteRenderersOnly, spriteRenderersOnly); } GUILayout.Space(6f); GUILayout.EndHorizontal(); GUILayout.Space(6f); GUILayout.EndVertical(); GUILayout.Space(6f); if (this.m_Instance == null) { EditorGUILayout.HelpBox("Please set the sprite packer instance reference in order to use this feature.", MessageType.Info); } else { if (GUILayout.Button("Replace")) { int replacedCount = 0; switch (this.m_TargetMode) { case TargetMode.CurrentScene: { replacedCount += SPTools.ReplaceReferencesInScene(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly); break; } case TargetMode.ProjectOnly: { replacedCount += SPTools.ReplaceReferencesInProject(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly); break; } case TargetMode.CurrentSceneAndProject: { replacedCount += SPTools.ReplaceReferencesInProject(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly); replacedCount += SPTools.ReplaceReferencesInScene(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly); break; } case TargetMode.AllScenes: { replacedCount += SPTools.ReplaceReferencesInAllScenes(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly, false); break; } case TargetMode.AllScenesAndProject: { replacedCount += SPTools.ReplaceReferencesInProject(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly); replacedCount += SPTools.ReplaceReferencesInScene(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly); EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); replacedCount += SPTools.ReplaceReferencesInAllScenes(this.m_Instance.copyOfSprites, this.m_ReplaceMode, spriteRenderersOnly, true); break; } } EditorUtility.DisplayDialog("Reference Replacer", "Replaced references count: " + replacedCount.ToString(), "Okay"); } } GUILayout.EndVertical(); GUILayout.Space((float)SPReferenceReplacerWindow.padding.right); GUILayout.EndHorizontal(); GUILayout.Space((float)SPReferenceReplacerWindow.padding.bottom); GUILayout.EndVertical(); }
protected void OnDisable() { this.m_AtlasBuilder = null; this.m_SPInstance = null; }
protected override void OnDestroy() { this.instance = null; this.imagelist.Clear(); this.imagelist = null; }