private void Start() { battleChat = GetComponent <BattleChat>(); editorToolScripts[0].desc = ConsumableManager.Instance.Get("build_tool"); editorToolScripts[1].desc = ConsumableManager.Instance.Get("line_tool"); editorToolScripts[2].desc = ConsumableManager.Instance.Get("replace_tool"); editorTool = new EditorTool[editorToolScripts.Length]; for (int i = 0; i < editorToolScripts.Length; i++) { Item i2 = null; long num = MyInfoManager.Instance.HaveFunction(editorToolScripts[i].desc.name); if (num >= 0) { i2 = MyInfoManager.Instance.GetItemBySequence(num); } if (editorToolScripts[i].desc.name == "build_tool") { editorTool[i] = new BuildTool(editorToolScripts[i], battleChat); } else if (editorToolScripts[i].desc.name == "line_tool") { editorTool[i] = new LineTool(editorToolScripts[i], i2, dummy, battleChat); } else if (editorToolScripts[i].desc.name == "replace_tool") { editorTool[i] = new ReplaceTool(editorToolScripts[i], i2, battleChat); } } editorTool[0].Activate(activate: true); }
private void OnGUI() { if (string.IsNullOrEmpty(TextureURL)) { BorderURL = EditorPrefs.GetString(LineTool.GetProjectKey("AnimationBorderURL_SliceSprites")); TextureURL = EditorPrefs.GetString(LineTool.GetProjectKey("AnimationTextureURL_SliceSprites")); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.TextField("TO DO!"); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //Select folder contain textures EditorGUILayout.BeginHorizontal(); TextureURL = EditorGUILayout.TextField("Textures URL", TextureURL); if (GUILayout.Button("Browser...", GUILayout.Width(100))) { TextureURL = EditorUtility.OpenFilePanel("Choose Textures File", TextureURL, ""); EditorPrefs.SetString(LineTool.GetProjectKey("AnimationTextureURL_SliceSprites"), TextureURL); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); BorderURL = EditorGUILayout.TextField("Border URL", BorderURL); if (GUILayout.Button("Browser...", GUILayout.Width(100))) { BorderURL = EditorUtility.OpenFolderPanel("Choose Boder File", BorderURL, ""); EditorPrefs.SetString(LineTool.GetProjectKey("AnimationBorderURL_SliceSprites"), BorderURL); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); }
/// <summary> /// 注册所有工具的相应部分上下文 /// </summary> private void Init() { _cursor = new Dictionary <string, Cursor>(); _cursor["Tool_Drag"] = Cursors.Arrow; _cursor["Tool_Rectangle"] = Cursors.Cross; _cursor["Tool_Triangle"] = Cursors.Cross; _cursor["Tool_Image"] = Cursors.Cross; _cursor["Tool_QRCode"] = Cursors.Cross; _cursor["Tool_Circle"] = Cursors.Cross; _cursor["Tool_Text"] = Cursors.IBeam; _cursor["Tool_Line"] = Cursors.Cross; _toolType = new Dictionary <string, ToolType>(); _toolType["Tool_Drag"] = ToolType.Drag; _toolType["Tool_Rectangle"] = ToolType.Rectangle; _toolType["Tool_Triangle"] = ToolType.Triangle; _toolType["Tool_Image"] = ToolType.Image; _toolType["Tool_QRCode"] = ToolType.QRCode; _toolType["Tool_Circle"] = ToolType.Circle; _toolType["Tool_Text"] = ToolType.Text; _toolType["Tool_Line"] = ToolType.Line; _paintTool = new Dictionary <string, PaintToolBase>(); _paintTool["Tool_Line"] = new LineTool(); _paintTool["Tool_Drag"] = new DragTool(); _paintTool["Tool_Triangle"] = new TriangleTool(); _paintTool["Tool_Circle"] = new CircleTool(); _paintTool["Tool_Rectangle"] = new RectangleTool(); _paintTool["Tool_Image"] = new ImageTool(); _paintTool["Tool_Text"] = new TextTool(); }
protected override void OnUpdate() { var lineTool = GetSingleton <LineTool>(); if (lineTool.State != LineToolState.Editing) { return; } Entities .WithStructuralChanges() .WithAll <NewLineCompleteEvent>() .ForEach((Entity eventEntity) => { if (lineTool.LineBehaviour) { lineTool.LineBehaviour.OnComplete(); } var line = EntityManager.GetComponentData <Line>(lineTool.Data.LineEntity); EntityManager.RemoveComponent <NewLine>(lineTool.Data.LineEntity); EntityManager.AddComponent <MergeCheck>(lineTool.Data.LineEntity); lineTool = LineTool.Default(); SetSingleton(lineTool); }).WithoutBurst().Run(); EntityManager.DestroyEntity(query); }
private void SetToolbox() { ToolBox = new Toolbox(); ToolBox.SetActiveCanvas(DrawingCanvas); LineTool LineToolStrip = new LineTool(); LineToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(LineToolStrip); EllipseTool EllipseToolStrip = new EllipseTool(); EllipseToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(EllipseToolStrip); RectangleTool RectangleToolStrip = new RectangleTool(); RectangleToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(RectangleToolStrip); ToolBox.AddSeparator(); SelectionTool SelectionToolStrip = new SelectionTool(); SelectionToolStrip.Click += new EventHandler(Toolbox_ItemClicked); ToolBox.AddTool(SelectionToolStrip); this.Controls.Add(ToolBox); }
public void DrawLine(int x, int y) { if (IsShapeOptionSelected(LineTool) == false) { LineTool.Click(); } DragAndDropOnCanvas(x, y); }
public DrawingToolsVM(Window parent, CanvasControlVM canvasControl, double fps) { var pencilTool = new PencilTool(_control.DrawingPanel, (x) => _window.GetDrawingColor(x), ChangeLine, fps); var lineTool = new LineTool(_control.DrawingPanel, (x) => _window.GetDrawingColor(x), () => pencilTool.Thickness, ChangeLine); var pickerTool = new PickerTool(_control.DrawingPanel, canvasControl.View, (x, y) => _window.SetDrawingColor(x, y)); _control.DrawingPanel.Children.Add(canvasControl.View); _control.Loaded += (s, e) => Control_Loaded(pencilTool, lineTool, pickerTool, parent); }
public void SetLine(LineTool l) { try { m_line = l; m_p1 = l.P1; m_p2 = l.P2; } catch (Exception ex) { throw ex; } }
/// <summary> /// constructor /// </summary> /// <param name="profile">ProfileWall or ProfileFloor</param> public NewPathReinforcementForm(Profile profile) : this() { m_profile = profile; m_to2DMatrix = m_profile.To2DMatrix; m_moveToCenterMatrix = m_profile.ToCenterMatrix(); m_tool = new LineTool(); this.KeyPreview = true; //respond Form events first m_pointsPreview = new List <List <XYZ> >(); m_sizePictureBox = this.pictureBox.Size; }
public void TestThatCreateLineCreatesDiagonalLine(int length) { LineTool lineTool = new LineTool(); System.Collections.Generic.IEnumerable <Coordinates> line = lineTool.CreateLine(new Coordinates(0, 0), new Coordinates(length - 1, length - 1), 1); Assert.Equal(length, line.Count()); for (int i = 0; i < length; i++) { Assert.Contains(new Coordinates(i, i), line); } }
private void FinishCreateRoad() { if (lineTool != null) { lineTool.Deactivate(); lineTool.OnFinishDrawing -= LineTool_OnFinishDrawing; lineTool.OnCancel -= LineTool_OnCancel; Destroy(lineTool.gameObject); lineTool = null; } EnableClassificationToggles(false); }
public void TestThatCreateLineCreatesDiagonalLine(int length) { LineTool lineTool = new LineTool(); var line = lineTool.CreateLine(new Coordinates(0, 0), new Coordinates(length - 1, length - 1), 1); Assert.Equal(length, line.Length); for (int i = 0; i < length; i++) { Assert.Contains(new Coordinates(i, i), line); } }
///------------------------------------------------------------------------------------------------- /// \fn private void MainView_MouseMove(object sender, MouseEventArgs e) /// /// \brief Event handler. Called by MainView for mouse move events /// /// \param sender Source of the event. /// \param e Mouse event information. ///------------------------------------------------------------------------------------------------- private void MainView_MouseMove(object sender, MouseEventArgs e) { if (isEnabled) { mainView.Image.Dispose(); mainView.Image = (Image)doubleBuffer.Clone(); using (Graphics g = Graphics.FromImage(mainView.Image)) { LineTool linetool = (LineTool)ToolKit.GetInstance().lineTool; linetool.Draw(g, Setting.GetInstance().Pen, arrayList[arrayList.Count - 1], e.Location); } } }
public DrawTools(MainWin window, PictureBox pic) { this.mainWindow = window; this.mainPicture = pic; this.pointerTool = new PointerTool(mainWindow, mainPicture); this.lineTool = new LineTool(mainWindow, mainPicture); this.rectTool = new RectTool(mainWindow, mainPicture); this.polyTool = new PolyTool(mainWindow, mainPicture); this.circleTool = new CircleTool(mainWindow, mainPicture); this.curveTool = new CurveTool(mainWindow, mainPicture); this.fillTool = new FillTool(mainWindow, mainPicture); this.resizeTool = new ResizeTool(mainWindow, mainPicture); this.cutTool = new CutTool(mainWindow, mainPicture); }
protected override void OnEndResize() { LineTool lLineTool = DrawingTool as LineTool; if ((LinePointIndex)MovingPointIndex == LinePointIndex.eStart) { lLineTool.StartPos = _MovingPoint; } else { lLineTool.EndPos = _MovingPoint; } _MovingPoint = Point.Empty; }
private void StartCreateRoad() { if (lineTool == null) { lineTool = Instantiate(lineToolPrefab); lineTool.name = lineToolPrefab.name; lineTool.ForceDrawingMethod(LineTool.Method.Dragging); lineTool.OnFinishDrawing += LineTool_OnFinishDrawing; lineTool.OnCancel += LineTool_OnCancel; } lineTool.Init(networkPatch, map); lineTool.Activate(); EnableClassificationToggles(true); }
private static void PerformLinearFill( Layer layer, Queue <FloodFillRange> floodFillQueue, Coordinates coords, int width, SKColor colorToReplace, ref Int32Rect dirtyRect, bool[] visited, List <Coordinates> output) { // Find the Left Edge of the Color Area int fillXLeft = coords.X; while (true) { // Indicate that this pixel has been checked int pixelIndex = (coords.Y * width) + fillXLeft; visited[pixelIndex] = true; // Move one pixel to the left fillXLeft--; // Exit the loop if we're at edge of the bitmap or the color area if (fillXLeft < 0 || visited[pixelIndex - 1] || layer.GetPixelWithOffset(fillXLeft, coords.Y) != colorToReplace) { break; } } int lastCheckedPixelLeft = fillXLeft + 1; // Find the Right Edge of the Color Area int fillXRight = coords.X; while (true) { int pixelIndex = (coords.Y * width) + fillXRight; visited[pixelIndex] = true; fillXRight++; if (fillXRight >= width || visited[pixelIndex + 1] || layer.GetPixelWithOffset(fillXRight, coords.Y) != colorToReplace) { break; } } int lastCheckedPixelRight = fillXRight - 1; int relativeY = coords.Y; LineTool.CalculateBresenhamLine(new Coordinates(lastCheckedPixelLeft, relativeY), new Coordinates(lastCheckedPixelRight, relativeY), output); dirtyRect = dirtyRect.Expand(new Int32Rect(lastCheckedPixelLeft, coords.Y, lastCheckedPixelRight - lastCheckedPixelLeft + 1, 1)); FloodFillRange range = new FloodFillRange(lastCheckedPixelLeft, lastCheckedPixelRight, coords.Y); floodFillQueue.Enqueue(range); }
public FormMain() { InitializeComponent(); //WindowState = FormWindowState.Maximized; openImageDialog.Title = "Открыть изображение"; saveImageDialog.Title = "Сохранить изображение"; templateShown = false; isTemplateOn = false; BackgroundImage = null; //is it correct way to clear BackgroundImage of the form? templatePanel.Enabled = false; templatePanel.Visible = false; templatePanelMinimized.Enabled = false; templatePanelMinimized.Visible = false; isImageSaved = false; snapshot = new Bitmap(mainPictureBox.Width, mainPictureBox.Height); backPic = new Bitmap(mainImagePanel.Width, mainImagePanel.Height); loadPic = null; mouseDown = false; clearFlag = false; loadPicFlag = false; activeToolControlName = null; activeColorControlName = null; width = lineThicknessTrackBar.Value; eraser = new EraserTool(width); pencil = new PencilTool(width); rect = new RectangleTool(width); line = new LineTool(width); ellipse = new EllipseTool(width); fill = new FillTool(); toolsList = new Dictionary <string, ITool>(); toolsList.Add("labelPencil", pencil); toolsList.Add("labelEraser", eraser); toolsList.Add("labelRect", rect); toolsList.Add("labelLine", line); toolsList.Add("labelEllipse", ellipse); toolsList.Add("labelFill", fill); loadTemplate = new FormLoadTemplate(); }
private void UpdateLineElementFromUI() { if (notateXpress != null && notateXpress.Layers.Count > 0) { LineTool lineElement = (LineTool)notateXpress.Layers[0].Elements[0]; Point[] points = lineElement.GetPoints(); points[0].X = (int)StartingPointXNumericUpDown.Value; points[0].Y = (int)StartingPointYNumericUpDown.Value; points[1].X = (int)EndingPointXNumericUpDown.Value; points[1].Y = (int)EndingPointYNumericUpDown.Value; lineElement.SetPoints(points); lineElement.PenWidth = (int)LineWidthNumericUpDown.Value; notateXpress.ToolbarDefaults.LineToolbarDefaults.PenWidth = (int)LineWidthNumericUpDown.Value; } }
public void Execute(ref LineTool tool) { lineTool = tool; // TODO: Load profile for line lineTool.Data.LineEntity = Line.New(NewLineCreateEvent.StartingPosition, Line.Prefab); EntityManager.SetComponentData(lineTool.Data.LineEntity, new NewLine { Modifiers = NewLineModifiers.Defaults() }); CreateLineJoinPoints(lineTool.Data); lineTool.State = LineToolState.Editing; tool = lineTool; }
private Tuple <Point, Point> GetStartEndPoints() { LineTool lLineTool = DrawingTool as LineTool; Point lStartPos = lLineTool.StartPos; Point lEndPos = lLineTool.EndPos; if (IsResizing) { if ((LinePointIndex)MovingPointIndex == LinePointIndex.eStart) { lStartPos = _MovingPoint; } else { lEndPos = _MovingPoint; } } return(new Tuple <Point, Point>(lStartPos, lEndPos)); }
/// <summary> /// 处理鼠标的点击的坐标是否靠近吸附点上 /// </summary> public void SetNewPoints(LineTool l, UnitPoint hitpoint, UnitPoint intersectpoint) { try { SetLine(l); double hitToVp1 = HitUtil.Distance(hitpoint, l.P1); double ispToVp1 = HitUtil.Distance(intersectpoint, l.P1); if (hitToVp1 <= ispToVp1) { m_p2 = intersectpoint; } else { m_p1 = intersectpoint; } ResetLine(); } catch (Exception ex) { throw ex; } }
// Should create line from [1,1] to [50,50] public void LineTest() { Line mockLine1 = new Line(); Line mockLine2 = new Line(); ITool CurrentTool = new LineTool(); // user clicked on point [1,1] CurrentTool.GetShape(new CanvasEventArgs(1, 1, MouseState.DOWN)); // user hold mouse and move CurrentTool.GetShape(new CanvasEventArgs(20, 20, MouseState.MOVE)); CurrentTool.GetShape(new CanvasEventArgs(30, 30, MouseState.MOVE)); // user release mouse Line l = (Line)CurrentTool.GetShape(new CanvasEventArgs(50, 50, MouseState.UP)).Shape; Assert.AreEqual(1, l.X1); Assert.AreEqual(50, l.X2); Assert.AreEqual(1, l.Y1); Assert.AreEqual(50, l.Y2); }
// Should create line from [1,1] to [50,50] public void LineTest() { Line mockLine1 = new Line(); Line mockLine2 = new Line(); ITool CurrentTool = new LineTool(); // user clicked on point [1,1] CurrentTool.GetShape(new CanvasEventArgs(new Point(1, 1), MouseState.DOWN), style); // user hold mouse and move CurrentTool.GetShape(new CanvasEventArgs(new Point(20, 20), MouseState.MOVE), style); CurrentTool.GetShape(new CanvasEventArgs(new Point(30, 30), MouseState.MOVE), style); // user release mouse ArrowLine l = (ArrowLine)CurrentTool.GetShape(new CanvasEventArgs(new Point(50, 50), MouseState.UP), style).TikzShape.Shape; Assert.AreEqual(1, l.X1); Assert.AreEqual(50, l.X2); Assert.AreEqual(1, l.Y1); Assert.AreEqual(50, l.Y2); }
private void InitTools() { polygonTool = new PolygonTool(mapControl, mapObjectLayer); lineTool = new LineTool(mapControl, mapObjectLayer); mapObjectEditing = new MapObjectEditing(mapControl, mapObjectLayer); boundingAreaTool = new BoundingAreaTool(mapControl, boundingAreaLayer); attractorTool = new AttractorTool(mapControl, attractorLayer); attractorEditing = new AttractorEditing(mapControl, attractorLayer, gridAttractorEditing, comboBoxAttractorType, comboBoxAttractorPerformance, upDownAttractorRadius); allTools = new Tool[] { polygonTool, lineTool, mapObjectEditing, boundingAreaTool, attractorTool, attractorEditing }; foreach (var tool in allTools) { tool.OnBegin += OnToolBegin; tool.OnEnd += OnToolEnd; } }
///------------------------------------------------------------------------------------------------- /// \fn private void MainView_MouseClick(object sender, MouseEventArgs e) /// /// \brief Event handler. Called by MainView for mouse click events /// /// \param sender Source of the event. /// \param e Mouse event information. ///------------------------------------------------------------------------------------------------- private void MainView_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (arrayList.Count == 0) { doubleBuffer = (Image)mainView.Image.Clone(); arrayList.Add(e.Location); this.isEnabled = true; return; } doubleBuffer = (Image)mainView.Image.Clone(); arrayList.Add(e.Location); using (Graphics g = Graphics.FromImage(mainView.Image)) { // g.DrawLine(Setting.GetInstance().Pen, (Point)arrayList[arrayList.Count - 2], e.Location); LineTool lineTool = (LineTool)ToolKit.GetInstance().lineTool; lineTool.Draw(g, Setting.GetInstance().Pen, arrayList[arrayList.Count - 2], e.Location); } } else { this.isEnabled = false; mainView.Image = (Image)doubleBuffer.Clone(); //save into actions array. Polygon polygon = new Polygon(); polygon.pen = Setting.GetInstance().Pen.Clone() as Pen; polygon.pointArray = new List <Point>(arrayList.ToArray()); Log.LogText(String.Format("Create Polygon")); History.GetInstance().PushBackAction( new MAction(this, polygon)); MakeAction(polygon); //some termination arrayList.Clear(); } }
public void InitDialog(ref LineTool tool, Brick brick) { long num = MyInfoManager.Instance.HaveFunction("line_tool"); if (num >= 0) { item = MyInfoManager.Instance.GetItemBySequence(num); } lineTool = tool; doneCount = 0; with = null; if (brick != null) { if (brick.ticket.Length <= 0 || MyInfoManager.Instance.HaveFunction(brick.ticket) >= 0) { with = brick; } else { SystemMsgManager.Instance.ShowMessage(StringMgr.Instance.Get("BUY_CREATIVE_TICKET")); } } progressing = false; }
///------------------------------------------------------------------------------------------------- /// \fn public override void MakeAction(ActionParameters_t toolParameters) /// /// \brief Makes an action /// /// \exception InvalidCastException Thrown when an object cannot be cast to a required type. /// /// \param toolParameters Options for controlling the tool. ///------------------------------------------------------------------------------------------------- public override void MakeAction(ActionParameters_t toolParameters) { try { Polygon polygon = (Polygon)toolParameters; using (Graphics g = Graphics.FromImage(mainView.Image)) { LineTool lineTool = (LineTool)ToolKit.GetInstance().lineTool; int length = polygon.pointArray.Count; for (int i = 0; i < length; i++) { lineTool.Draw(g, polygon.pen, polygon.pointArray[i % length], polygon.pointArray[(i + 1) % length]); } if (polygon.backColor != Color.White) { g.FillPolygon(new SolidBrush(polygon.backColor), polygon.pointArray.ToArray()); } } } catch (InvalidCastException) { throw; } }
private void OnGUI() { if (string.IsNullOrEmpty(TextureURL)) { saveURL = EditorPrefs.GetString(LineTool.GetProjectKey("AnimationSaveURL_FromGif")); TextureURL = EditorPrefs.GetString(LineTool.GetProjectKey("AnimationTextureURL_FromGif")); BorderURL = EditorPrefs.GetString(LineTool.GetProjectKey("AnimationBorderURL_FromGif")); GifDataURL = EditorPrefs.GetString(LineTool.GetProjectKey("AnimationGifDataURLURL_FromGif")); } //Select folder contain gif data EditorGUILayout.BeginHorizontal(); GifDataURL = EditorGUILayout.TextField("GifData URL ", GifDataURL); if (GUILayout.Button("Browser...", GUILayout.Width(100))) { GifDataURL = EditorUtility.OpenFolderPanel("Choose GifData File", GifDataURL, ""); EditorPrefs.SetString(LineTool.GetProjectKey("AnimationGifDataURLURL_FromGif"), GifDataURL); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //gif part List <Gif> gifs = new List <Gif>(); if (!string.IsNullOrEmpty(GifDataURL)) { string[] folder_paths = System.IO.Directory.GetDirectories(GifDataURL); foreach (string folder_path in folder_paths) { //Ignor FX folder cuz this file not right config name if (Path.GetFileName(folder_path) == "FX" || Path.GetFileName(folder_path) == "items") { continue; } var files = System.IO.Directory.GetFiles(folder_path, "*.gif"); foreach (var f in files) { var bytes = File.ReadAllBytes(f); var _gif = Gif.Decode(bytes); _gif.Name = Path.GetFileName(folder_path) + "_" + Path.GetFileName(f); gifs.Add(_gif); } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.TextArea("gif Count: " + gifs.Count); GUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); BorderURL = EditorGUILayout.TextField("BorderURL ", BorderURL); if (GUILayout.Button("Browser...", GUILayout.Width(100))) { if (string.IsNullOrEmpty(BorderURL)) { BorderURL = EditorUtility.OpenFilePanel("Choose Border File Path", Application.dataPath, "txt"); } else { BorderURL = EditorUtility.OpenFilePanel("Choose Border File Path", BorderURL, "txt"); } EditorPrefs.SetString(LineTool.GetProjectKey("AnimationBorderURL_FromGif"), BorderURL); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Get Info", GUILayout.Width(100), GUILayout.Height(30))) { string changeBorderContent = ""; foreach (var g in gifs) { var s = ""; s += g.Name + "|"; foreach (var f in g.Frames) { s += f.Delay + " "; } changeBorderContent += s + "\n"; } //Save borderData if (!string.IsNullOrEmpty(BorderURL) && !string.IsNullOrEmpty(changeBorderContent)) { System.IO.File.WriteAllText(BorderURL, changeBorderContent); EditorUtility.DisplayDialog("save gif info", "save Success", "OK"); } else { EditorUtility.DisplayDialog("Error", "pls select boder file path", "Gotta"); } } GUILayout.EndHorizontal(); //======== end read data from gif EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("======================================"); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); TextureURL = EditorGUILayout.TextField("Textures URL", TextureURL); if (GUILayout.Button("Browser...", GUILayout.Width(100))) { TextureURL = EditorUtility.OpenFolderPanel("Choose Textures File", TextureURL, ""); EditorPrefs.SetString(LineTool.GetProjectKey("AnimationTextureURL_FromGif"), TextureURL); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); var dataPath = Application.dataPath; //New one List <string> animatorNames = new List <string>(); List <string> fxTriggers = new List <string>(); List <Sprite> sprites = new List <Sprite>(); if (!string.IsNullOrEmpty(TextureURL)) { var files = System.IO.Directory.GetFiles(TextureURL, "*.png"); foreach (var f in files) { string shortPath = ""; if (f.Contains(dataPath)) { shortPath = f.Replace(dataPath, "Assets"); } var objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(shortPath); var _sprites = objects.Where(q => q is Sprite).Cast <Sprite>(); sprites.AddRange(_sprites); } //Thêm trigger cho anim foreach (var s in sprites) { // "name" + "-" + "trigger" var spriteName = s.name; var spriteName1 = spriteName.Replace('-', '_'); var strlist = spriteName1.Split('_'); if (!animatorNames.Contains(strlist[0].ToLower())) { animatorNames.Add(strlist[0].ToLower()); } if (strlist.Length >= 2) { var triggerName = strlist[1].ToLower(); if (!fxTriggers.Contains(triggerName)) { fxTriggers.Add(triggerName); } } } EditorGUILayout.TextArea("Animator Count: " + animatorNames.Count); EditorGUILayout.TextArea("Sprite Count: " + sprites.Count); EditorGUILayout.TextArea("Trigger Count: " + fxTriggers.Count); } GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("Generate", GUILayout.Width(100), GUILayout.Height(30))) { if (string.IsNullOrEmpty(BorderURL)) { EditorUtility.DisplayDialog("Error", "pls select boder file path", "Gotta"); return; } EmojiGif2AnimationData borderData = new EmojiGif2AnimationData(BorderURL); string existURL = string.IsNullOrEmpty(saveURL) ? Application.dataPath : saveURL; saveURL = EditorUtility.OpenFolderPanel("Choose Animator Save Folder", existURL, ""); //saveURL = EditorUtility.SaveFilePanel("Save Animation File", existURL, "EffectSprite2DName", "controller"); if (saveURL.Contains(dataPath)) { saveURL = saveURL.Replace(dataPath, "Assets"); } EditorPrefs.SetString(LineTool.GetProjectKey("AnimationSaveURL_FromGif"), saveURL); foreach (var a in animatorNames) { var newSaveURL = saveURL + "/" + a + ".controller"; var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(newSaveURL); if (controller != null) { var rootStateMachine = controller.layers[0].stateMachine; var emptyState = rootStateMachine.AddState("empty"); foreach (var trigger in fxTriggers) { var foundSprites = sprites.FindAll(xx => xx.name.ToLower().Contains(trigger) && xx.name.ToLower().Contains(a)); if (foundSprites == null || foundSprites.Count == 0) { continue; } string clipName = trigger; //select info from gif string info = ""; var gif_name = a + "_" + trigger + ".gif"; if (borderData.Borders.ContainsKey(gif_name)) { info = borderData.Borders[gif_name]; Debug.Log("info " + info); controller.AddParameter(trigger, AnimatorControllerParameterType.Trigger); var clip = createAnimationClip(foundSprites, clipName, info, true); AssetDatabase.AddObjectToAsset(clip, controller); var newState = rootStateMachine.AddState(trigger); newState.motion = clip; var trans = rootStateMachine.AddAnyStateTransition(newState); trans.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, trigger); trans.duration = 0; trans.hasExitTime = false; sprites.RemoveAll(xx => foundSprites.Contains(xx)); } else { continue; } } } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Close(); } GUILayout.EndHorizontal(); }
public IToolContext CreateToolContext() { var editorToolContext = new EditorToolContext() { ContainerFactory = this }; var hitTest = new HitTest(); var tools = new ObservableCollection <ITool>(); var noneTool = new NoneTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = false, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } }, new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = false, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } } }, Settings = new NoneToolSettings() }; var selectionTool = new SelectionTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = false, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new SelectionToolSettings() { Mode = SelectionMode.Point | SelectionMode.Shape, Targets = SelectionTargets.Shapes, SelectionModifier = Modifier.Control, ConnectionModifier = Modifier.Shift, SelectionStyle = "Selection", ClearSelectionOnClean = false, HitTestRadius = 7.0, ConnectPoints = true, ConnectTestRadius = 10.0, DisconnectPoints = true, DisconnectTestRadius = 10.0 } }; var pointTool = new PointTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new PointToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var lineTool = new LineTool() { Intersections = new ObservableCollection <IPointIntersection> { new LineLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new LineLineSettings() { IsEnabled = true } }, new RectangleLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new RectangleLineSettings() { IsEnabled = true } }, new EllipseLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new EllipseLineSettings() { IsEnabled = true } } }, Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new LineToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, SplitIntersections = false } }; var polyLineTool = new PolyLineTool() { Intersections = new ObservableCollection <IPointIntersection> { new LineLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new LineLineSettings() { IsEnabled = true } }, new RectangleLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new RectangleLineSettings() { IsEnabled = true } }, new EllipseLineIntersection() { Intersections = new ObservableCollection <IPointShape>(), Settings = new EllipseLineSettings() { IsEnabled = true } } }, Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new PolyLineToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var cubicBezierTool = new CubicBezierTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new CubicBezierToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var quadraticBezierTool = new QuadraticBezierTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new QuadraticBezierToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var conicTool = new ConicTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new ConicToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, Weight = 1.0 } }; var pathTool = new PathTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new PathToolSettings() { ConnectPoints = true, HitTestRadius = 7.0, FillType = PathFillType.Winding, IsFilled = true, IsClosed = true } }; pathTool.Settings.Tools = new ObservableCollection <ITool> { new LineTool(), new CubicBezierTool(), new QuadraticBezierTool(), new ConicTool(), new MoveTool(pathTool) }; pathTool.Settings.CurrentTool = pathTool.Settings.Tools[0]; var scribbleTool = new ScribbleTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = false, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new ScribbleToolSettings() { Simplify = true, Epsilon = 1.0, FillType = PathFillType.Winding, IsFilled = false, IsClosed = false } }; var rectangleTool = new RectangleTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new RectangleToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var ellipseTool = new EllipseTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new EllipseToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; var textTool = new TextTool() { Intersections = new ObservableCollection <IPointIntersection>(), Filters = new ObservableCollection <IPointFilter> { new GridSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new GridSnapSettings() { IsEnabled = true, EnableGuides = false, Mode = GridSnapMode.Horizontal | GridSnapMode.Vertical, GridSizeX = 15.0, GridSizeY = 15.0, GuideStyle = "Guide" } }, new LineSnapPointFilter() { Guides = new ObservableCollection <IBaseShape>(), Settings = new LineSnapSettings() { IsEnabled = true, EnableGuides = false, Target = LineSnapTarget.Shapes, Mode = LineSnapMode.Point | LineSnapMode.Middle | LineSnapMode.Nearest | LineSnapMode.Intersection | LineSnapMode.Horizontal | LineSnapMode.Vertical, Threshold = 10.0, GuideStyle = "Guide" } } }, Settings = new TextToolSettings() { ConnectPoints = true, HitTestRadius = 7.0 } }; void SetToolDefaults(ITool tool) { tool.CurrentIntersection = tool.Intersections.Count > 0 ? tool.Intersections[0] : null; tool.CurrentFilter = tool.Filters.Count > 0 ? tool.Filters[0] : null; } SetToolDefaults(noneTool); SetToolDefaults(selectionTool); SetToolDefaults(pointTool); SetToolDefaults(lineTool); SetToolDefaults(polyLineTool); SetToolDefaults(cubicBezierTool); SetToolDefaults(quadraticBezierTool); SetToolDefaults(conicTool); SetToolDefaults(pathTool); SetToolDefaults(scribbleTool); SetToolDefaults(rectangleTool); SetToolDefaults(ellipseTool); SetToolDefaults(textTool); tools.Add(noneTool); tools.Add(selectionTool); tools.Add(pointTool); tools.Add(lineTool); tools.Add(polyLineTool); tools.Add(cubicBezierTool); tools.Add(quadraticBezierTool); tools.Add(conicTool); tools.Add(pathTool); tools.Add(scribbleTool); tools.Add(rectangleTool); tools.Add(ellipseTool); tools.Add(textTool); editorToolContext.Selection = selectionTool; editorToolContext.HitTest = hitTest; editorToolContext.CurrentDirectory = null; editorToolContext.Files = new ObservableCollection <string>(); editorToolContext.StyleLibrary = null; editorToolContext.GroupLibrary = null; var pointTemplate = new RectangleShape(new PointShape(-4, -4, null), new PointShape(4, 4, null)) { Points = new ObservableCollection <IPointShape>(), Text = new Text(), StyleId = "PointTemplate" }; pointTemplate.StartPoint.Owner = pointTemplate; pointTemplate.Point.Owner = pointTemplate; editorToolContext.PointTemplate = pointTemplate; editorToolContext.ContainerViews = new ObservableCollection <IContainerView>(); editorToolContext.ContainerView = null; editorToolContext.Tools = tools; editorToolContext.CurrentTool = selectionTool; editorToolContext.EditMode = EditMode.Mouse; return(editorToolContext); }