public static void HandleDradAndDrop(SpAtlas atlas, Rect dropRect) { if (dropRect.Contains(Event.current.mousePosition) == true) { switch (Event.current.type) { case EventType.DragUpdated: { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } break; case EventType.DragPerform: { if (Event.current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); for (var i = 0; i < DragAndDrop.objectReferences.Length; i++) { var objectReference = DragAndDrop.objectReferences[i]; var objectPath = AssetDatabase.GetAssetPath(objectReference); if (string.IsNullOrEmpty(objectPath) == false) { atlas.TryAddSource(objectPath); } } } } break; } } }
private void DrawSettings(SpAtlas atlas) { EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel); atlas.AutoUpdate = EditorGUILayout.Toggle("Auto Update", atlas.AutoUpdate); atlas.ForceSquare = EditorGUILayout.Toggle("Force Square", atlas.ForceSquare); }
private void DrawFindButton(SpAtlas atlas, SpSource source, Rect rect, Texture2D sourceTexture) { EditorGUI.BeginDisabledGroup(sourceTexture == null && source.Flag == SpFlag.JustCreated); { if (GUI.Button(rect, "find", EditorStyles.miniButtonMid) == true) { var sourceName = source.Name; var sourceSprites = source.Sprites; var foundSprites = source.FindSprites(atlas.Sprites, sourceSprites); if (foundSprites.Count > 0) { Selection.objects = foundSprites.ToArray(); } else { var sprite = atlas.Sprites.Find(s => s.name == sourceName); if (sprite != null) { Selection.activeObject = sprite; } else { Debug.Log("Failed to find linked sprites"); } } } } EditorGUI.EndDisabledGroup(); }
private void DrawDestroyButton(SpAtlas atlas, SpSource source, Rect rect) { if (GUI.Button(rect, "x", EditorStyles.miniButtonRight) == true) { switch (source.Flag) { case SpFlag.None: { source.Flag = SpFlag.MarkedForDestruction; } break; case SpFlag.JustCreated: { atlas.Sources.Remove(source); } break; case SpFlag.MarkedForDestruction: { source.Flag = SpFlag.None; } break; } } }
private void DrawSources(SpAtlas atlas) { hasGreen = false; hasYellow = false; hasRed = false; EditorGUILayout.LabelField("Textures", EditorStyles.boldLabel); atlas.Sources.RemoveAll(s => s.Flag == SpFlag.JustCreated && s.Texture == null); for (var i = 0; i < atlas.Sources.Count; i++) { DrawSource(atlas, atlas.Sources[i]); } if (hasGreen == true) { EditorGUILayout.HelpBox("A green box means the texture has just been added to the atlas. Press 'Update' to add these textures to the atlas.", MessageType.Info); } if (hasYellow == true) { EditorGUILayout.HelpBox("A yellow box means the texture has been modified. Press 'Update' to update these textures in the atlas.", MessageType.Info); } if (hasRed == true) { EditorGUILayout.HelpBox("A red box mean the texture has been marked for deletion. Press 'Update' to remove these textures from the atlas.", MessageType.Info); } }
private void DrawAtlas(SpAtlas atlas) { EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel); var rect = SpHelper.Reserve(14.0f); var width = rect.width / 3.0f; var rect0 = rect; rect0.width = width; rect0.x = rect.x + width * 0; rect0.xMax -= 2; var rect1 = rect; rect1.width = width; rect1.x = rect.x + width * 1; rect1.xMin += 1; rect1.xMax -= 1; var rect2 = rect; rect2.width = width; rect2.x = rect.x + width * 2; rect2.xMin += 2; if (GUI.Button(rect0, "Update", EditorStyles.miniButton) == true) { atlas.Update(); } EditorGUI.BeginDisabledGroup(atlas.Texture == null); { if (GUI.Button(rect1, "Select", EditorStyles.miniButton) == true) { Selection.activeObject = atlas.Texture; } if (GUI.Button(rect2, "Link", EditorStyles.miniButton) == true) { SpLink_Wizard.Open(atlas); } } EditorGUI.EndDisabledGroup(); }
private void DrawDefaults(SpAtlas atlas) { EditorGUILayout.LabelField("Defaults", EditorStyles.boldLabel); atlas.DefaultTrim = EditorGUILayout.Toggle("Trim", atlas.DefaultTrim); atlas.DefaultPadSize = EditorGUILayout.IntField("Pad Size", atlas.DefaultPadSize); atlas.DefaultPadStyle = (SpPadStyle)EditorGUILayout.EnumPopup("Pad Style", atlas.DefaultPadStyle); }
private void DrawDragAndDrop(SpAtlas atlas) { var dropRect = SpHelper.Reserve(48.0f); // Open drag and drop window? if (GUI.Button(dropRect, "Add Textures\n(Drag And Drop)") == true) { var drop = SpDrop_Window.Open(); drop.CurrentAtlas = atlas; drop.Repaint(); } SpHelper.DrawDragAndDropZone(dropRect); SpHelper.HandleDradAndDrop(atlas, dropRect); }
public static SpLink_Wizard Open(SpAtlas atlas) { if (atlas != null) { var path = AssetDatabase.GUIDToAssetPath(atlas.Identifier); var texture = AssetDatabase.LoadMainAssetAtPath(path) as Texture2D; if (texture != null) { var allSourceSprites = new List <Sprite>(); var allPackedSprites = new List <Sprite>(); for (var i = 0; i < atlas.Sources.Count; i++) { var source = atlas.Sources[i]; var sourceSprites = source.Sprites; if (sourceSprites.Count > 0) { allSourceSprites.AddRange(sourceSprites); allPackedSprites.AddRange(source.FindSprites(atlas.Sprites, sourceSprites)); } } if (allSourceSprites.Count > 0) { var linker = ScriptableWizard.DisplayWizard <SpLink_Wizard>("Sprite Linker", "Link", "Cancel"); linker.atlas = atlas; linker.sourceSprites = allSourceSprites.ToArray(); linker.packedSprites = allPackedSprites.ToArray(); return(linker); } } } return(null); }
public static void Start() { if (Directory.Exists(RecoveryDirName) == false) { Directory.CreateDirectory(RecoveryDirName); } else { serv.DirectoryCopy(RecoveryDirName, ".", true);//*/ } SpectroWizard.Log.SetupPath("log.txt"); Conf = new Config(); CreateDb(); try { SpectrAtlas = new SpAtlas(); SpectrAtlas.Load(); } catch { } try { Env = Env.Restore(EnvPath); } catch { Env = new Env(); } try { LDb = new LineDb("lib\\data.bin"); } catch { LDb = new LineDb(); } try { LyData = new LyDb(); } catch (Exception ex) { //Log(ex); } IsRunning = true; Dev = KnownDevList.GetDev(Conf.RegId, Conf.GenId, Conf.FillLId, Conf.GasId); Dev.Reg.InitNullCalibrator(); DefaultResultTableFont = new Font[3]; DefaultResultTableFont[0] = new Font(FontFamily.GenericSerif, Common.Env.DefaultFontSize, FontStyle.Underline); DefaultResultTableFont[1] = new Font(FontFamily.GenericSerif, Common.Env.DefaultFontSize, FontStyle.Bold); int fsize = Common.Env.DefaultFontSize; fsize = (int)(fsize * 0.8); if (fsize < 8) { fsize = 8; } DefaultResultTableFont[2] = new Font(FontFamily.GenericSerif, fsize); GOSTDb = new GOSTDb(); GOSTDb.Init("lib\\gost\\"); CUSTOMDb = new GOSTDb(); CUSTOMDb.Init("lib\\custom\\"); }
private void DrawSource(SpAtlas atlas, SpSource source) { var background = default(GUIStyle); var sourceTexture = source.Texture; if (source.Flag == SpFlag.None && sourceTexture == null) { source.Flag = SpFlag.MarkedForDestruction; } if (source.Flag == SpFlag.JustCreated) { background = SpHelper.GreenBox; hasGreen = true; } else if (source.Flag == SpFlag.MarkedForDestruction) { background = SpHelper.RedBox; hasRed = true; } else { if (source.Dirty == true) { background = SpHelper.YellowBox; hasYellow = true; } } SpHelper.BeginError(background != null, background); { var rect = SpHelper.Reserve(); var rect0 = rect; rect0.xMax -= 100.0f; var rect1 = rect; rect1.xMin = rect1.xMax - 45.0f; rect1.x -= 55.0f; var rect2 = rect; rect2.xMin = rect2.xMax - 35.0f; rect2.x -= 20.0f; var rect3 = rect; rect3.xMin = rect3.xMax - 20.0f; if (EditorGUI.Foldout(rect0, currentSource == source, source.Name) == true) { EditorGUI.BeginChangeCheck(); { currentSource = source; EditorGUI.BeginDisabledGroup(source.Flag == SpFlag.MarkedForDestruction); { source.PadSize = EditorGUILayout.IntField("Pad Size", source.PadSize); source.PadStyle = (SpPadStyle)EditorGUILayout.EnumPopup("Pad Style", source.PadStyle); if (source.PadStyle == SpPadStyle.Transparent) { source.Trim = EditorGUILayout.Toggle("Trim", source.Trim); } DrawPivot(source); DrawBorder(source); } EditorGUI.EndDisabledGroup(); } if (EditorGUI.EndChangeCheck() == true) { source.Dirty = true; } } else if (currentSource == source) { currentSource = null; } // See if the PPU is inconsistent var importer = source.Importer; if (importer != null) { var ppu = importer.spritePixelsPerUnit; if (lastPpu < 0.0f) { lastPpu = ppu; } if (lastPpu != ppu) { EditorGUILayout.HelpBox("This sprite has an inconsistent PixelsPerUnit setting. These differences will be overridden in the final sprite.", MessageType.Warning); } } DrawSelectButton(source, rect1, sourceTexture); DrawFindButton(atlas, source, rect2, sourceTexture); DrawDestroyButton(atlas, source, rect3); } SpHelper.EndError(); }
private void DrawSource(SpAtlas atlas, SpSource source) { var background = default(GUIStyle); var sourceTexture = source.Texture; if (source.Flag == SpFlag.None && sourceTexture == null) { source.Flag = SpFlag.MarkedForDestruction; } if (source.Flag == SpFlag.JustCreated) { background = SpHelper.GreenBox; hasGreen = true; } else if (source.Flag == SpFlag.MarkedForDestruction) { background = SpHelper.RedBox; hasRed = true; } else { if (source.Dirty == true) { background = SpHelper.YellowBox; hasYellow = true; } } SpHelper.BeginError(background != null, background); { var rect = SpHelper.Reserve(); var rect0 = rect; rect0.xMax -= 100.0f; var rect1 = rect; rect1.xMin = rect1.xMax - 45.0f; rect1.x -= 55.0f; var rect2 = rect; rect2.xMin = rect2.xMax - 35.0f; rect2.x -= 20.0f; var rect3 = rect; rect3.xMin = rect3.xMax - 20.0f; if (EditorGUI.Foldout(rect0, currentSource == source, source.Name) == true) { EditorGUI.BeginChangeCheck(); { currentSource = source; EditorGUI.BeginDisabledGroup(source.Flag == SpFlag.MarkedForDestruction); { source.PadSize = EditorGUILayout.IntField("Pad Size", source.PadSize); source.PadStyle = (SpPadStyle)EditorGUILayout.EnumPopup("Pad Style", source.PadStyle); if (source.PadStyle == SpPadStyle.Transparent) { source.Trim = EditorGUILayout.Toggle("Trim", source.Trim); } DrawPivot(source); DrawBorder(source); } EditorGUI.EndDisabledGroup(); } if (EditorGUI.EndChangeCheck() == true) { source.Dirty = true; } } else if (currentSource == source) { currentSource = null; } DrawSelectButton(source, rect1, sourceTexture); DrawFindButton(atlas, source, rect2, sourceTexture); DrawDestroyButton(atlas, source, rect3); } SpHelper.EndError(); }