All Projects → tjcccc → ugui-dragdrop

tjcccc / ugui-dragdrop

Licence: MIT License
A practise of universal interaction in Unity UI (uGUI): Drag and drop an object for exchanging its position with others.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to ugui-dragdrop

MintAnimation
一款高效易用的Unity插值动画系统,可以快速制作UI动画
Stars: ✭ 84 (+300%)
Mutual labels:  ugui
Unity-VariableTileLayout
UI components for tile layout like Pinterenst.
Stars: ✭ 57 (+171.43%)
Mutual labels:  ugui
BlurringAtlasForUGUI
A blur effect for uGUI in Unity, that is effective even for atlas images including dynamic fonts.
Stars: ✭ 29 (+38.1%)
Mutual labels:  ugui
YLYRichText
a feature-rich, easy to use unity rich text plugin
Stars: ✭ 32 (+52.38%)
Mutual labels:  ugui
ugui-animated-progressbar
A progress bar with animation of uGUI.
Stars: ✭ 81 (+285.71%)
Mutual labels:  ugui
unity-ugui-edit-tools
编辑器下的界面工具集合
Stars: ✭ 30 (+42.86%)
Mutual labels:  ugui
DissolveEffectForTMPro
DissolveEffectForTMPro provide dissolve effect component for TextMeshPro in Unity.
Stars: ✭ 86 (+309.52%)
Mutual labels:  ugui
Unity-PullToRefresh
Pull to refresh for Unity UI.
Stars: ✭ 73 (+247.62%)
Mutual labels:  ugui
WDataTable
WDataTable,a data form component for unity by ugui.
Stars: ✭ 38 (+80.95%)
Mutual labels:  ugui
Xlua UGUI Demo
A MVC UGUI hot fix demo using Xlua.
Stars: ✭ 16 (-23.81%)
Mutual labels:  ugui
RubyTextMeshPro
Unity Text Mesh Proでルビ(フリガナ)のタグを追加しました.
Stars: ✭ 61 (+190.48%)
Mutual labels:  ugui
Uix-Page-Builder
Uix Page Builder is a design system that it is simple content creation interface.
Stars: ✭ 20 (-4.76%)
Mutual labels:  dragdrop
ReuseScroller
Reuse cell for uGUI ScrollView
Stars: ✭ 29 (+38.1%)
Mutual labels:  ugui
UCharts
UCharts allows creating radar charts, pie charts, half pie chart in your Unity3d Games.
Stars: ✭ 33 (+57.14%)
Mutual labels:  ugui
BezierCanvas
Adobe Illustrator's pen tool style bezier editor on Unity.
Stars: ✭ 126 (+500%)
Mutual labels:  ugui
UnityScreenNavigator
Library for screen transitions, transition animations, transition history stacking, and screen lifecycle management in Unity's uGUI.
Stars: ✭ 488 (+2223.81%)
Mutual labels:  ugui
TKinterDesigner
TKinterDesigner is a tool software to develop the Python User Interface for Python programmer.
Stars: ✭ 663 (+3057.14%)
Mutual labels:  dragdrop
unity-text-typer
Text typing effect for Unity uGUI Text components
Stars: ✭ 252 (+1100%)
Mutual labels:  ugui
AnKuchen
Control UI Prefab from Script Library
Stars: ✭ 83 (+295.24%)
Mutual labels:  ugui
CompositeToggle
Composite toggle system for unity
Stars: ✭ 38 (+80.95%)
Mutual labels:  ugui

Drag and Drop in uGUI

A practise of universal interaction in Unity UI (uGUI): Drag and drop an game object for exchanging its position with others.

中文版

Main Feature

In a game object group which is arranged by Unity UI grid system, when you drag one game object and drop it at some place in the group's area, the game object will exchange its position with the other one which is closest to the dropping place.

Environment and Dependency Plugins

  • Unity ver. 2019.3f1
  • DOTween ver. 1.1.310

Implementation Method

  1. Store the matrix Order and initial Position of every DragDrop GameObject.
  2. When a game object (DragDrop Handler) is being dragged, get the matrix Order and realtime Position of it.
  3. When the DragDrop GameObject is dropped, get the nearest GameObject by the dropping place's position and store the matrix Order of that game object (Replaced GameObject).
  4. Exchange the DragDrop Handler GameObject's matrix Order with the Replaced GameObject.
  5. Change the two GameObjects' Position by DOTween. You can also use your own tween ways.

How to Use

Scripts Structure

_Components/DragDrop/
├── DragDropContainer.cs  // Attached to the container of objects.
├── DragDropObject.cs  // Attached to the object substance.
└── DragDrop.cs  // Attached to DragDrop Handler of the object.

The reason for separating DragDropObject and DragDrop:

  • Make the structure more distinct.
  • For calculating the position easily.
  • To separate handler and substance. For instance: when you dragging an icon, you might need a semi-transparent icon image (the handler) to follow your mouse only and the real icon (substance) shouldn't change its position until you release the handler.

If you need realtime positions exchange, you can set the DragDropObject to invisible (e.g. alpha = 0). DragDropObject is necessary in current version, it stores the matrix Order.

DragDropContainer.cs Configuration

This script should be attached to the container game object which has Grid Layout Group component.

DragDropContainer

The RectTransform's Anchors property should not be set to Stretch. Otherwise, the game objects will be in disorder.

The RectTransform's Pivot property should be (0, 1):

// Script will do it for you.
girdRectTransform.pivot = new Vector2 (0, 1);
  • Grid Type: For Initializing DragDropContainer's grid. There're two options:
    • Static: Static Initialization. Game objects should be arranged in grid before project's running.
    • Dynamic: Dynamic Initialization. After one game object is loaded, it will be set as the child of DragDropContainer, then the ConnectRelatives() will be called to set their relationship; After all game objects are loaded, InitializeDragDrop() of DragDropContainer will be called to initialize them.
  • Canvas: DragDropContainer's UICanvas component. It is ensured that the dragging track of object will not be offset in different screen resolutions.
  • Auto Move Speed: Tween time (second) of positions exchange. Default: 0.2s.

DragDropObject.cs Configuration

This script should be attached to each child game object of DragDropContainer.

Notice: It is unable to exchange position with an inactive GameObject (or nothing).

DragDropObject

DragDrop.cs Configuration

This script should be attached to a child game object of DragDropObject. It is the handler for dragging, you should set a suitable size for it.

DragDrop

This script use Event Trigger which is provided by uGUI. You should add that component with 3 delegates:

  • Begin Drag: Invoke DragDrop.OnDragBegin().
  • Dragging: Invoke DragDrop.OnDrag().
  • End Drag: Invoke DragDrop.OnDragEnd().

Your can add your own methods into them.

Examples in Repository

Example 1

DragDropObject and DragDrop are both visible. The substance object will not be dragged visually.

Example 2

DragDropObject is invisible. The substance game object will follow you dragging directly.

Example 3

A game object grid with one row.

Example 4

A game object grid with different amount of columns and rows.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].