开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (15)
标签 (450)
master
2020.1
2020.2
2019.4
2019.3
2018.4
2017.4
2019.2
2019.1
2018.3
2018.2
2017.2
2018.1
2017.1
2017.3
202010b12
202010b11
202020a13
201940f1
2019年3月15日f1
202010b10
202020a12
202010b9
2019年3月14日f1
202020a11
2018年4月23日f1
2017440f1
2019年3月13日f1
202020a10
202010b8
2019年3月12日f1
202020a9
202010b7
2018年4月22日f1
202010b6
master
分支 (15)
标签 (450)
master
2020.1
2020.2
2019.4
2019.3
2018.4
2017.4
2019.2
2019.1
2018.3
2018.2
2017.2
2018.1
2017.1
2017.3
202010b12
202010b11
202020a13
201940f1
2019年3月15日f1
202010b10
202020a12
202010b9
2019年3月14日f1
202020a11
2018年4月23日f1
2017440f1
2019年3月13日f1
202020a10
202010b8
2019年3月12日f1
202020a9
202010b7
2018年4月22日f1
202010b6
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (15)
标签 (450)
master
2020.1
2020.2
2019.4
2019.3
2018.4
2017.4
2019.2
2019.1
2018.3
2018.2
2017.2
2018.1
2017.1
2017.3
202010b12
202010b11
202020a13
201940f1
2019年3月15日f1
202010b10
202020a12
202010b9
2019年3月14日f1
202020a11
2018年4月23日f1
2017440f1
2019年3月13日f1
202020a10
202010b8
2019年3月12日f1
202020a9
202010b7
2018年4月22日f1
202010b6
StackNodeDropTarget.cs 12.37 KB
一键复制 编辑 原始数据 按行查看 历史
Unity Technologies 提交于 2019年05月22日 19:46 +08:00 . Unity 201930a3 C# reference source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.UIElements.Experimental;
using UnityEngine.UIElements.StyleSheets;
namespace UnityEditor.Experimental.GraphView
{
public partial class StackNode : IDropTarget
{
private bool m_DragEntered; // Indicates whether a drag has entered
private IList<VisualElement> m_RemovedPreviews; // The preview being removed
private IList<VisualElement> m_CurrentPreviews; // The current preview
private int m_CurrentInsertIndex; // The current index where the dragged item will be inserted once dropped
private const string k_PreviewClass = "stack-node-preview";
private Func<GraphElement, VisualElement> m_DropPreviewTemplate;
private bool m_InstantAdd = false; // Temporarily set to true right after an item is detached from the stack to show its preview right away (instead of being animated)
private List<IValueAnimation> m_AddAnimations;
private List<IValueAnimation> m_RemoveAnimations;
private int m_AnimationDuration = 40;
private static CustomStyleProperty<int> s_AnimationDuration = new CustomStyleProperty<int>("--animation-duration");
private int animationDuration => m_AnimationDuration;
private List<GraphElement> m_DraggedElements;
protected bool dragEntered
{
get { return m_DragEntered; }
private set
{
if (m_DragEntered == value)
return;
m_DragEntered = value;
m_SeparatorContainer.visible = !value; // Hide the separators when while dragging
m_CurrentInsertIndex = -1;
}
}
public Func<GraphElement, VisualElement> dropPreviewTemplate
{
get { return m_DropPreviewTemplate ?? DefaultDropPreviewTemplate; }
set { m_DropPreviewTemplate = value; }
}
private VisualElement CreateDropPreview(GraphElement element)
{
VisualElement preview = dropPreviewTemplate(element);
preview.Add(new Label(element.title));
preview.AddToClassList(k_PreviewClass);
return preview;
}
private static VisualElement DefaultDropPreviewTemplate(GraphElement source)
{
VisualElement preview = new VisualElement();
preview.AddToClassList("default");
return preview;
}
private void AddPreview(IList<VisualElement> previews, int index, bool animated)
{
// Update the current preview with the newly added preview
m_CurrentPreviews = previews;
foreach (VisualElement preview in m_CurrentPreviews)
{
Insert(index++, preview);
}
if (animated)
{
m_AddAnimations = new List<IValueAnimation>(m_CurrentPreviews.Count);
foreach (VisualElement preview in m_CurrentPreviews)
{
Vector2 size = new Vector2(preview.style.width.value.value, preview.style.height.value.value);
Rect startRect = new Rect(Vector2.zero, size);
Rect endRect = startRect;
startRect.height = 0f;
var addAnimation = preview.experimental.animation.Start(startRect, endRect, animationDuration, UpdatePreviewLayout).KeepAlive();
m_AddAnimations.Add(addAnimation);
}
}
else
{
foreach (VisualElement currentPreview in m_CurrentPreviews)
{
currentPreview.style.position = Position.Relative;
}
}
}
private void RemovePreview(bool animated)
{
if (m_CurrentPreviews == null || m_RemovedPreviews != null)
return;
if (m_AddAnimations != null)
{
foreach (var addAnimation in m_AddAnimations)
{
addAnimation.Stop();
addAnimation.Recycle();
}
m_AddAnimations = null;
}
m_RemovedPreviews = m_CurrentPreviews;
if (animated)
{
m_RemoveAnimations = new List<IValueAnimation>(m_CurrentPreviews.Count);
foreach (VisualElement preview in m_RemovedPreviews)
{
Rect startRect = new Rect(Vector2.zero, preview.layout.size);
Rect endRect = startRect;
endRect.height = 0f;
var removeAnimations = preview.experimental.animation.Start(startRect, endRect, animationDuration, UpdatePreviewLayout).KeepAlive();
removeAnimations.onAnimationCompleted = OnRemoveAnimationFinished;
m_RemoveAnimations.Add(removeAnimations);
}
}
else
{
RemovePreviewHelper();
}
}
private void RemovePreviewHelper()
{
if (m_RemovedPreviews == null)
return;
foreach (VisualElement preview in m_RemovedPreviews)
{
preview.RemoveFromHierarchy();
}
if (m_RemovedPreviews == m_CurrentPreviews)
m_CurrentPreviews = null;
m_RemovedPreviews = null;
}
private void UpdatePreviewLayout(VisualElement preview, Rect layout)
{
if (preview != null)
{
preview.style.width = layout.width;
preview.style.height = layout.height;
}
}
private void OnRemoveAnimationFinished()
{
RemovePreviewHelper();
foreach (var a in m_RemoveAnimations)
{
a.Recycle();
}
m_RemoveAnimations = null;
// If a new preview was added while another one was been removed and that a drag exit occurred
// before the RemoveAnimation finished then removed this added preview
if (dragEntered == false && m_CurrentPreviews != null)
RemovePreview(true);
}
private void HandleDragAndDropEvent(IMouseEvent evt)
{
if ((m_AddAnimations != null && m_AddAnimations.Any(a => a.isRunning)) ||
(m_RemoveAnimations != null && m_RemoveAnimations.Any(a => a.isRunning)))
return;
// Nothing interesting to do if nothing is dragged.
if (m_DraggedElements == null || m_DraggedElements.Count == 0)
return;
dragEntered = true;
int insertIndex = 0;
Vector2 localMousePosition = graphView.ChangeCoordinatesTo(contentContainer, graphView.WorldToLocal(evt.mousePosition));
int previewIndex = m_CurrentPreviews?.FirstOrDefault()?.parent.IndexOf(m_CurrentPreviews.First()) ?? -1;
int maxIndex = 0;
// If there is no child then add at index 0
if (childCount != 0)
{
// Determine the insert index by traversing the stack from top to bottom ignoring the previews and footer.
// For each child element, use the vertical center as reference to determine if the dragged element should be inserted above or below it.
foreach (VisualElement child in Children())
{
Rect rect = child.layout;
if ((m_RemovedPreviews == null || !m_RemovedPreviews.Contains(child)) &&
(m_CurrentPreviews == null || !m_CurrentPreviews.Contains(child)))
{
maxIndex++;
if (localMousePosition.y > (rect.y + rect.height / 2))
{
++insertIndex;
}
}
}
}
// Call AcceptsElement to get the first insert index
AcceptsElement(m_DraggedElements.First(), ref insertIndex, maxIndex);
// Do nothing if the insert index has not changed
if (previewIndex == insertIndex)
return;
m_CurrentInsertIndex = insertIndex;
previewIndex = insertIndex;
// Remove the current preview if there is any with some animation
RemovePreview(true);
var previews = new List<VisualElement>();
foreach (GraphElement draggedElement in m_DraggedElements)
{
// Create a preview
VisualElement preview = CreateDropPreview(draggedElement);
float previewWidth = contentContainer.layout.width;
if (!m_InstantAdd)
{
previewWidth = contentContainer.layout.width > 0f
? contentContainer.layout.width
: draggedElement.layout.width;
}
preview.style.width = previewWidth;
preview.style.height = draggedElement.layout.height + separatorHeight;
previews.Add(preview);
}
// If there is already a preview being removed then adjust the insert index of the new preview
if (m_RemovedPreviews != null)
{
int removePreviewIndex = m_RemovedPreviews.FirstOrDefault()?.parent.IndexOf(m_RemovedPreviews.First()) ?? -1;
if (removePreviewIndex < previewIndex)
{
previewIndex += m_RemovedPreviews.Count;
}
}
AddPreview(previews, previewIndex, !m_InstantAdd);
}
protected virtual bool hasMultipleSelectionSupport { get { return false; } }
public bool CanAcceptDrop(List<ISelectable> selection)
{
return m_DraggedElements?.Count > 0;
}
public virtual bool DragExited()
{
dragEntered = false;
m_DraggedElements = null;
return true;
}
public virtual bool DragPerform(DragPerformEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget, ISelection dragSource)
{
HandleDragAndDropEvent(evt);
// Remove the current preview with no animation
RemovePreview(false);
if (m_CurrentInsertIndex != -1)
{
// Notify the model that an element should be inserted at the specified index
if (graphView != null && graphView.elementsInsertedToStackNode != null)
{
graphView.elementsInsertedToStackNode(this, m_CurrentInsertIndex, m_DraggedElements);
}
int cnt = 0;
foreach (GraphElement draggedElement in m_DraggedElements)
{
InsertElement(m_CurrentInsertIndex + cnt++, draggedElement);
}
}
dragEntered = false;
m_DraggedElements = null;
return true;
}
public virtual bool DragUpdated(DragUpdatedEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget, ISelection dragSource)
{
HandleDragAndDropEvent(evt);
return true;
}
public virtual bool DragEnter(DragEnterEvent evt, IEnumerable<ISelectable> selection, IDropTarget enteredTarget, ISelection dragSource)
{
int proposedIndex = -1;
int maxIndex = 1;
// We just want to know which elements are accepted. The actual index is not relevant to us at this point.
m_DraggedElements = selection
.OfType<GraphElement>()
.Where(e => e != this && AcceptsElementInternal(e, ref proposedIndex, maxIndex))
.ToList();
return true;
}
public virtual bool DragLeave(DragLeaveEvent evt, IEnumerable<ISelectable> selection, IDropTarget leftTarget, ISelection dragSource)
{
// Remove the current preview with some animation
RemovePreview(true);
dragEntered = false;
m_DraggedElements = null;
return true;
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/billwillman/UnityCsReference.git
git@gitee.com:billwillman/UnityCsReference.git
billwillman
UnityCsReference
UnityCsReference
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /