当前位置:网站首页>Simply drag objects to the item bar
Simply drag objects to the item bar
2022-04-23 04:41:00 【Longpangpang's blog】
Code : Need to move the code on the object ( Here is the blood bottle )
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class DragDrop : MonoBehaviour,IPointerDownHandler,IBeginDragHandler ,IEndDragHandler,IDragHandler{
private RectTransform m_rectTransform;
public Canvas m_Canvas;
private CanvasGroup m_CanvasGroup;
void Start()
{
m_rectTransform = GetComponent<RectTransform>();
m_CanvasGroup = GetComponent<CanvasGroup>();
}
/// <summary>
/// Before starting drag and drop
/// </summary>
/// <param name="eventData"></param>
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log("OnBeginDrag");
m_CanvasGroup.blocksRaycasts = false;
m_CanvasGroup.alpha = 0.6f;
}
/// <summary>
/// Drag and drop
/// </summary>
/// <param name="eventData"></param>
public void OnDrag(PointerEventData eventData)
{
m_rectTransform.anchoredPosition += eventData.delta/ m_Canvas.scaleFactor;
}
/// <summary>
/// Drag end
/// </summary>
/// <param name="eventData"></param>
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("OnEndDrag Drag end ");
m_CanvasGroup.blocksRaycasts = true;
m_CanvasGroup.alpha = 1f;
}
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log("OnPointerDown");
}
}
Code : Item grid code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class IteamSlot : MonoBehaviour, IDropHandler
{
public void OnDrop(PointerEventData eventData)
{
if(eventData.pointerDrag!=null)
{
eventData.pointerDrag.GetComponent<RectTransform>().anchoredPosition = GetComponent<RectTransform>().anchoredPosition;
}
}
}
Just put the script on the grid ,
A little bad , Move the mouse to the grid to have the effect of putting it in ( You can try if you need )
版权声明
本文为[Longpangpang's blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230441112339.html
边栏推荐
- Flink's important basics
- Bacterial infection and antibiotic use
- Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
- 【论文阅读】【3d目标检测】Voxel Transformer for 3D Object Detection
- test
- Supplement 14: cmake practice project notes (to be continued 4 / 22)
- Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
- IEEE Transactions on industrial information (TII)
- Spark FAQ sorting - must see before interview
- 阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)
猜你喜欢
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
MySQL queries users logged in for at least N consecutive days
Jetpack 之 LifeCycle 组件使用详解
520. Detect capital letters
Installation and deployment of Flink and wordcount test
383. Ransom letter
MYSQL查询至少连续n天登录的用户
递归调用--排列的穷举
Druid -- JDBC tool class case
协程与多进程的完美结合
随机推荐
Interaction of diet gut microbiota on cardiovascular disease
阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)
【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
229. Find mode II
Recommended scheme for national production of electronic components for wireless charging
Fusobacterium -- symbiotic bacteria, opportunistic bacteria, oncobacterium
Redis command Encyclopedia
IDE Idea 自动编译 与 On Upate Action 、 On Frame Deactivation 的配置
Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
Solutions to the failure of sqoop connection to MySQL
Bridge between ischemic stroke and intestinal flora: short chain fatty acids
Leetcode - > 1 sum of two numbers
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
/etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
The last day of 2021 is the year of harvest.
在AWS控制台创建VPC(无图版)
Supplement: Annotation
leetcode008--实现strStr()函数
AWS EKS 部署要点以及控制台与eksctl创建的差异
1个需求的一生,团队协作在云效钉钉小程序上可以这么玩