Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (15)
Tags (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
Branches (15)
Tags (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
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (15)
Tags (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
CollisionModuleUI.cs 29.03 KB
Copy Edit Raw Blame History
Unity Technologies authored 2019年09月25日 22:28 +08:00 . Unity 202010a5 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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using System.Collections.Generic;
using UnityEditorInternal;
namespace UnityEditor
{
class CollisionModuleUI : ModuleUI
{
// Keep in sync with CollisionModule.h
const int k_MaxNumPlanes = 6;
enum CollisionTypes { Plane = 0, World = 1 }
enum CollisionModes { Mode3D = 0, Mode2D = 1 }
enum PlaneVizType { Grid, Solid }
SerializedProperty m_Type;
SerializedProperty[] m_Planes = new SerializedProperty[k_MaxNumPlanes];
SerializedMinMaxCurve m_Dampen;
SerializedMinMaxCurve m_Bounce;
SerializedMinMaxCurve m_LifetimeLossOnCollision;
SerializedProperty m_MinKillSpeed;
SerializedProperty m_MaxKillSpeed;
SerializedProperty m_RadiusScale;
SerializedProperty m_CollidesWith;
SerializedProperty m_CollidesWithDynamic;
SerializedProperty m_MaxCollisionShapes;
SerializedProperty m_Quality;
SerializedProperty m_VoxelSize;
SerializedProperty m_CollisionMessages;
SerializedProperty m_CollisionMode;
SerializedProperty m_ColliderForce;
SerializedProperty m_MultiplyColliderForceByCollisionAngle;
SerializedProperty m_MultiplyColliderForceByParticleSpeed;
SerializedProperty m_MultiplyColliderForceByParticleSize;
SerializedProperty[] m_ShownPlanes;
List<Transform> m_ScenePlanes = new List<Transform>();
static PlaneVizType m_PlaneVisualizationType = PlaneVizType.Solid;
static float m_ScaleGrid = 1.0f;
static bool s_VisualizeBounds = false;
static Transform s_SelectedTransform; // static so to ensure only one selected Transform across multiple particle systems
internal static PrefColor s_CollisionBoundsColor = new PrefColor("Particle System/Collision Bounds", 0.0f, 1.0f, 0.0f, 1.0f);
static EditMode.SceneViewEditMode[] s_SceneViewEditModes = new[]
{
EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove,
EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate
};
static readonly string s_UndoCollisionPlaneString = L10n.Tr("Modified Collision Plane Transform");
class Texts
{
public GUIContent lifetimeLoss = EditorGUIUtility.TrTextContent("Lifetime Loss", "When particle collides, it will lose this fraction of its Start Lifetime");
public GUIContent planes = EditorGUIUtility.TrTextContent("Planes", "Planes are defined by assigning a reference to a transform. This transform can be any transform in the scene and can be animated. Multiple planes can be used. Note: the Y-axis is used as the plane normal.");
public GUIContent createPlane = EditorGUIUtility.TrTextContent("", "Create an empty GameObject and assign it as a plane.");
public GUIContent minKillSpeed = EditorGUIUtility.TrTextContent("Min Kill Speed", "When particles collide and their speed is lower than this value, they are killed.");
public GUIContent maxKillSpeed = EditorGUIUtility.TrTextContent("Max Kill Speed", "When particles collide and their speed is higher than this value, they are killed.");
public GUIContent dampen = EditorGUIUtility.TrTextContent("Dampen", "When particle collides, it will lose this fraction of its speed. Unless this is set to 0.0, particle will become slower after collision.");
public GUIContent bounce = EditorGUIUtility.TrTextContent("Bounce", "When particle collides, the bounce is scaled with this value. The bounce is the upwards motion in the plane normal direction.");
public GUIContent radiusScale = EditorGUIUtility.TrTextContent("Radius Scale", "Scale particle bounds by this amount to get more precise collisions.");
public GUIContent visualization = EditorGUIUtility.TrTextContent("Visualization", "Only used for visualizing the planes: Wireframe or Solid.");
public GUIContent scalePlane = EditorGUIUtility.TrTextContent("Scale Plane", "Resizes the visualization planes.");
public GUIContent visualizeBounds = EditorGUIUtility.TrTextContent("Visualize Bounds", "Render the collision bounds of the particles.");
public GUIContent collidesWith = EditorGUIUtility.TrTextContent("Collides With", "Collides the particles with colliders included in the layermask.");
public GUIContent collidesWithDynamic = EditorGUIUtility.TrTextContent("Enable Dynamic Colliders", "Should particles collide with dynamic objects?");
public GUIContent maxCollisionShapes = EditorGUIUtility.TrTextContent("Max Collision Shapes", "How many collision shapes can be considered for particle collisions. Excess shapes will be ignored. Terrains take priority.");
public GUIContent quality = EditorGUIUtility.TrTextContent("Collision Quality", "Quality of world collisions. Medium and low quality are approximate and may leak particles.");
public GUIContent voxelSize = EditorGUIUtility.TrTextContent("Voxel Size", "Size of voxels in the collision cache. Smaller values improve accuracy but require higher memory usage and are less efficient.");
public GUIContent collisionMessages = EditorGUIUtility.TrTextContent("Send Collision Messages", "Send collision callback messages.");
public GUIContent collisionType = EditorGUIUtility.TrTextContent("Type", "Collide with a list of Planes, or the Physics World.");
public GUIContent collisionMode = EditorGUIUtility.TrTextContent("Mode", "Use 3D Physics or 2D Physics.");
public GUIContent colliderForce = EditorGUIUtility.TrTextContent("Collider Force", "Control the strength of particle forces on colliders.");
public GUIContent multiplyColliderForceByCollisionAngle = EditorGUIUtility.TrTextContent("Multiply by Collision Angle", "Should the force be proportional to the angle of the particle collision? A particle collision directly along the collision normal produces all the specified force whilst collisions away from the collision normal produce less force.");
public GUIContent multiplyColliderForceByParticleSpeed = EditorGUIUtility.TrTextContent("Multiply by Particle Speed", "Should the force be proportional to the particle speed?");
public GUIContent multiplyColliderForceByParticleSize = EditorGUIUtility.TrTextContent("Multiply by Particle Size", "Should the force be proportional to the particle size?");
public GUIContent[] collisionTypes = new GUIContent[]
{
EditorGUIUtility.TrTextContent("Planes"),
EditorGUIUtility.TrTextContent("World")
};
public GUIContent[] collisionModes = new GUIContent[]
{
EditorGUIUtility.TrTextContent("3D"),
EditorGUIUtility.TrTextContent("2D")
};
public GUIContent[] qualitySettings = new GUIContent[]
{
EditorGUIUtility.TrTextContent("High"),
EditorGUIUtility.TrTextContent("Medium (Static Colliders)"),
EditorGUIUtility.TrTextContent("Low (Static Colliders)")
};
public GUIContent[] planeVizTypes = new GUIContent[]
{
EditorGUIUtility.TrTextContent("Grid"),
EditorGUIUtility.TrTextContent("Solid")
};
public GUIContent[] toolContents =
{
EditorGUIUtility.TrIconContent("MoveTool", "Move plane editing mode."),
EditorGUIUtility.TrIconContent("RotateTool", "Rotate plane editing mode.")
};
}
private static Texts s_Texts;
public CollisionModuleUI(ParticleSystemUI owner, SerializedObject o, string displayName)
: base(owner, o, "CollisionModule", displayName)
{
m_ToolTip = "Allows you to specify multiple collision planes that the particle can collide with.";
}
private bool editingPlanes
{
get
{
return ((EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove ||
EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate) &&
EditMode.IsOwner(m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.customEditor));
}
set
{
if (!value && editingPlanes)
EditMode.QuitEditMode();
SceneView.RepaintAll();
}
}
protected override void Init()
{
// Already initialized?
if (m_Type != null)
return;
if (s_Texts == null)
s_Texts = new Texts();
m_Type = GetProperty("type");
List<SerializedProperty> shownPlanes = new List<SerializedProperty>();
for (int i = 0; i < m_Planes.Length; ++i)
{
m_Planes[i] = GetProperty("plane" + i); // Keep name in sync with transfer func in CollisionModule.h
System.Diagnostics.Debug.Assert(m_Planes[i] != null);
// Always show the first plane
if (i == 0 || m_Planes[i].objectReferenceValue != null)
shownPlanes.Add(m_Planes[i]);
}
m_ShownPlanes = shownPlanes.ToArray();
m_Dampen = new SerializedMinMaxCurve(this, s_Texts.dampen, "m_Dampen");
m_Dampen.m_AllowCurves = false;
m_Bounce = new SerializedMinMaxCurve(this, s_Texts.bounce, "m_Bounce");
m_Bounce.m_AllowCurves = false;
m_LifetimeLossOnCollision = new SerializedMinMaxCurve(this, s_Texts.lifetimeLoss, "m_EnergyLossOnCollision");
m_LifetimeLossOnCollision.m_AllowCurves = false;
m_MinKillSpeed = GetProperty("minKillSpeed");
m_MaxKillSpeed = GetProperty("maxKillSpeed");
m_RadiusScale = GetProperty("radiusScale");
m_PlaneVisualizationType = (PlaneVizType)EditorPrefs.GetInt("PlaneColisionVizType", (int)PlaneVizType.Solid);
m_ScaleGrid = EditorPrefs.GetFloat("ScalePlaneColision", 1f);
s_VisualizeBounds = EditorPrefs.GetBool("VisualizeBounds", false);
m_CollidesWith = GetProperty("collidesWith");
m_CollidesWithDynamic = GetProperty("collidesWithDynamic");
m_MaxCollisionShapes = GetProperty("maxCollisionShapes");
m_Quality = GetProperty("quality");
m_VoxelSize = GetProperty("voxelSize");
m_CollisionMessages = GetProperty("collisionMessages");
m_CollisionMode = GetProperty("collisionMode");
m_ColliderForce = GetProperty("colliderForce");
m_MultiplyColliderForceByCollisionAngle = GetProperty("multiplyColliderForceByCollisionAngle");
m_MultiplyColliderForceByParticleSpeed = GetProperty("multiplyColliderForceByParticleSpeed");
m_MultiplyColliderForceByParticleSize = GetProperty("multiplyColliderForceByParticleSize");
SyncVisualization();
}
public override void UndoRedoPerformed()
{
base.UndoRedoPerformed();
SyncVisualization();
}
protected override void SetVisibilityState(VisibilityState newState)
{
base.SetVisibilityState(newState);
// Show tools again when module is not visible
if (newState != VisibilityState.VisibleAndFoldedOut)
{
s_SelectedTransform = null;
editingPlanes = false;
}
else
{
SyncVisualization();
}
}
override public void OnInspectorGUI(InitialModuleUI initial)
{
EditorGUI.BeginChangeCheck();
CollisionTypes type = (CollisionTypes)GUIPopup(s_Texts.collisionType, m_Type, s_Texts.collisionTypes);
if (EditorGUI.EndChangeCheck())
SyncVisualization();
if (type == CollisionTypes.Plane)
{
DoListOfPlanesGUI();
EditorGUI.BeginChangeCheck();
m_PlaneVisualizationType = (PlaneVizType)GUIPopup(s_Texts.visualization, (int)m_PlaneVisualizationType, s_Texts.planeVizTypes);
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetInt("PlaneColisionVizType", (int)m_PlaneVisualizationType);
}
EditorGUI.BeginChangeCheck();
m_ScaleGrid = GUIFloat(s_Texts.scalePlane, m_ScaleGrid, "f2");
if (EditorGUI.EndChangeCheck())
{
m_ScaleGrid = Mathf.Max(0f, m_ScaleGrid);
EditorPrefs.SetFloat("ScalePlaneColision", m_ScaleGrid);
}
GUIButtonGroup(s_SceneViewEditModes, s_Texts.toolContents, m_ParticleSystemUI.GetBounds, m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.customEditor);
}
else
{
GUIPopup(s_Texts.collisionMode, m_CollisionMode, s_Texts.collisionModes);
}
GUIMinMaxCurve(s_Texts.dampen, m_Dampen);
GUIMinMaxCurve(s_Texts.bounce, m_Bounce);
GUIMinMaxCurve(s_Texts.lifetimeLoss, m_LifetimeLossOnCollision);
GUIFloat(s_Texts.minKillSpeed, m_MinKillSpeed);
GUIFloat(s_Texts.maxKillSpeed, m_MaxKillSpeed);
GUIFloat(s_Texts.radiusScale, m_RadiusScale);
if (type == CollisionTypes.World)
{
GUIPopup(s_Texts.quality, m_Quality, s_Texts.qualitySettings);
EditorGUI.indentLevel++;
GUILayerMask(s_Texts.collidesWith, m_CollidesWith);
GUIInt(s_Texts.maxCollisionShapes, m_MaxCollisionShapes);
if (m_Quality.intValue == 0)
GUIToggle(s_Texts.collidesWithDynamic, m_CollidesWithDynamic);
else
GUIFloat(s_Texts.voxelSize, m_VoxelSize);
EditorGUI.indentLevel--;
GUIFloat(s_Texts.colliderForce, m_ColliderForce);
EditorGUI.indentLevel++;
GUIToggle(s_Texts.multiplyColliderForceByCollisionAngle, m_MultiplyColliderForceByCollisionAngle);
GUIToggle(s_Texts.multiplyColliderForceByParticleSpeed, m_MultiplyColliderForceByParticleSpeed);
GUIToggle(s_Texts.multiplyColliderForceByParticleSize, m_MultiplyColliderForceByParticleSize);
EditorGUI.indentLevel--;
}
GUIToggle(s_Texts.collisionMessages, m_CollisionMessages);
EditorGUI.BeginChangeCheck();
s_VisualizeBounds = GUIToggle(s_Texts.visualizeBounds, s_VisualizeBounds);
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetBool("VisualizeBounds", s_VisualizeBounds);
}
}
protected override void OnModuleEnable()
{
base.OnModuleEnable();
SyncVisualization();
}
protected override void OnModuleDisable()
{
base.OnModuleDisable();
editingPlanes = false;
}
private void SyncVisualization()
{
m_ScenePlanes.Clear();
if (m_ParticleSystemUI.multiEdit)
{
foreach (ParticleSystem ps in m_ParticleSystemUI.m_ParticleSystems)
{
if (ps.collision.type != ParticleSystemCollisionType.Planes)
continue;
for (int planeIndex = 0; planeIndex < k_MaxNumPlanes; planeIndex++)
{
var transform = ps.collision.GetPlane(planeIndex);
if (transform != null && !m_ScenePlanes.Contains(transform))
m_ScenePlanes.Add(transform);
}
}
}
else
{
CollisionTypes type = (CollisionTypes)m_Type.intValue;
if (type != CollisionTypes.Plane)
{
editingPlanes = false;
return;
}
for (int i = 0; i < m_ShownPlanes.Length; ++i)
{
Transform transform = m_ShownPlanes[i].objectReferenceValue as Transform;
if (transform != null && !m_ScenePlanes.Contains(transform))
m_ScenePlanes.Add(transform);
}
}
}
private static GameObject CreateEmptyGameObject(string name, ParticleSystem parentOfGameObject)
{
GameObject go = new GameObject(name);
if (go)
{
if (parentOfGameObject)
go.transform.parent = parentOfGameObject.transform;
Undo.RegisterCreatedObjectUndo(go, "Created `" + name + "`");
return go;
}
return null;
}
private bool IsListOfPlanesValid()
{
if (m_ParticleSystemUI.multiEdit)
{
for (int planeIndex = 0; planeIndex < k_MaxNumPlanes; planeIndex++)
{
int hasPlane = -1;
foreach (ParticleSystem ps in m_ParticleSystemUI.m_ParticleSystems)
{
int planeValue = (ps.collision.GetPlane(planeIndex) != null) ? 1 : 0;
if (hasPlane == -1)
{
hasPlane = planeValue;
}
else if (planeValue != hasPlane)
{
return false;
}
}
}
}
return true;
}
private void DoListOfPlanesGUI()
{
// only show the list of planes when we can edit them safely
if (!IsListOfPlanesValid())
{
EditorGUILayout.HelpBox("Plane list editing is only available when all selected systems contain the same number of planes", MessageType.Info, true);
return;
}
EditorGUI.BeginChangeCheck();
int buttonPressedIndex = GUIListOfFloatObjectToggleFields(s_Texts.planes, m_ShownPlanes, null, s_Texts.createPlane, !m_ParticleSystemUI.multiEdit);
bool listChanged = EditorGUI.EndChangeCheck();
if (buttonPressedIndex >= 0 && !m_ParticleSystemUI.multiEdit)
{
GameObject go = CreateEmptyGameObject("Plane Transform " + (buttonPressedIndex + 1), m_ParticleSystemUI.m_ParticleSystems[0]);
go.transform.localPosition = new Vector3(0, 0, 10 + buttonPressedIndex); // ensure each plane is not at same pos
go.transform.localEulerAngles = (new Vector3(-90, 0, 0)); // make the plane normal point towards the forward axis of the particle system
m_ShownPlanes[buttonPressedIndex].objectReferenceValue = go;
listChanged = true;
}
// Minus button
Rect rect = GUILayoutUtility.GetRect(0, EditorGUI.kSingleLineHeight); //GUILayoutUtility.GetLastRect();
rect.x = rect.xMax - kPlusAddRemoveButtonWidth * 2 - kPlusAddRemoveButtonSpacing;
rect.width = kPlusAddRemoveButtonWidth;
if (m_ShownPlanes.Length > 1)
{
if (MinusButton(rect))
{
m_ShownPlanes[m_ShownPlanes.Length - 1].objectReferenceValue = null;
List<SerializedProperty> shownPlanes = new List<SerializedProperty>(m_ShownPlanes);
shownPlanes.RemoveAt(shownPlanes.Count - 1);
m_ShownPlanes = shownPlanes.ToArray();
listChanged = true;
}
}
// Plus button
if (m_ShownPlanes.Length < k_MaxNumPlanes && !m_ParticleSystemUI.multiEdit)
{
rect.x += kPlusAddRemoveButtonWidth + kPlusAddRemoveButtonSpacing;
if (PlusButton(rect))
{
List<SerializedProperty> shownPlanes = new List<SerializedProperty>(m_ShownPlanes);
shownPlanes.Add(m_Planes[shownPlanes.Count]);
m_ShownPlanes = shownPlanes.ToArray();
}
}
if (listChanged)
SyncVisualization();
}
override public void OnSceneViewGUI()
{
RenderCollisionBounds();
CollisionPlanesSceneGUI();
}
private void CollisionPlanesSceneGUI()
{
if (m_ScenePlanes.Count == 0)
return;
Event evt = Event.current;
Color origCol = Handles.color;
Color col = new Color(1, 1, 1, 0.5F);
for (int i = 0; i < m_ScenePlanes.Count; ++i)
{
if (m_ScenePlanes[i] == null)
continue;
Transform transform = m_ScenePlanes[i];
Vector3 position = transform.position;
Quaternion rotation = transform.rotation;
Vector3 right = rotation * Vector3.right;
Vector3 up = rotation * Vector3.up;
Vector3 forward = rotation * Vector3.forward;
bool isPlayingAndStatic = EditorApplication.isPlaying && transform.gameObject.isStatic;
if (editingPlanes)
{
if (Object.ReferenceEquals(s_SelectedTransform, transform))
{
EditorGUI.BeginChangeCheck();
var newPosition = transform.position;
var newRotation = transform.rotation;
using (new EditorGUI.DisabledScope(isPlayingAndStatic))
{
if (isPlayingAndStatic)
Handles.ShowSceneViewLabel(position, Handles.s_StaticLabel);
if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove)
newPosition = Handles.PositionHandle(position, rotation);
else if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate)
newRotation = Handles.RotationHandle(rotation, position);
}
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(transform, s_UndoCollisionPlaneString);
transform.position = newPosition;
transform.rotation = newRotation;
ParticleSystemEditorUtils.PerformCompleteResimulation();
}
}
else
{
float handleSize = HandleUtility.GetHandleSize(position) * 0.6f;
EventType oldEventType = evt.type;
// we want ignored mouse up events to check for dragging off of scene view
if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp)
oldEventType = evt.rawType;
Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.RectangleHandleCap);
// Detect selected plane (similar to TreeEditor)
if (oldEventType == EventType.MouseDown && evt.type == EventType.Used)
{
s_SelectedTransform = transform;
oldEventType = EventType.Used;
GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514)
}
}
}
Handles.color = col;
Color color = Handles.s_ColliderHandleColor * 0.9f;
if (isPlayingAndStatic)
color.a *= 0.2f;
if (m_PlaneVisualizationType == PlaneVizType.Grid)
{
DrawGrid(position, right, forward, up, color);
}
else
{
DrawSolidPlane(position, rotation, color, Color.yellow);
}
}
Handles.color = origCol;
}
void RenderCollisionBounds()
{
if (s_VisualizeBounds == false)
return;
Color oldColor = Handles.color;
Handles.color = s_CollisionBoundsColor;
Matrix4x4 oldMatrix = Handles.matrix;
Vector3[] points0 = new Vector3[20];
Vector3[] points1 = new Vector3[20];
Vector3[] points2 = new Vector3[20];
Handles.SetDiscSectionPoints(points0, Vector3.zero, Vector3.forward, Vector3.right, 360, 1.0f);
Handles.SetDiscSectionPoints(points1, Vector3.zero, Vector3.up, -Vector3.right, 360, 1.0f);
Handles.SetDiscSectionPoints(points2, Vector3.zero, Vector3.right, Vector3.up, 360, 1.0f);
Vector3[] points = new Vector3[points0.Length + points1.Length + points2.Length];
points0.CopyTo(points, 0);
points1.CopyTo(points, 20);
points2.CopyTo(points, 40);
foreach (ParticleSystem ps in m_ParticleSystemUI.m_ParticleSystems)
{
if (!ps.collision.enabled)
continue;
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount];
int count = ps.GetParticles(particles);
Matrix4x4 transform = Matrix4x4.identity;
if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Local)
{
transform = ps.localToWorldMatrix;
}
for (int i = 0; i < count; i++)
{
ParticleSystem.Particle particle = particles[i];
Vector3 size = particle.GetCurrentSize3D(ps);
float radius = System.Math.Max(size.x, System.Math.Max(size.y, size.z)) * 0.5f * ps.collision.radiusScale;
Handles.matrix = transform * Matrix4x4.TRS(particle.position, Quaternion.identity, new Vector3(radius, radius, radius));
Handles.DrawPolyLine(points);
}
}
Handles.color = oldColor;
Handles.matrix = oldMatrix;
}
private static void DrawSolidPlane(Vector3 pos, Quaternion rot, Color faceColor, Color edgeColor)
{
if (Event.current.type != EventType.Repaint)
return;
var oldMatrix = Handles.matrix;
float scale = 10 * m_ScaleGrid;
Handles.matrix = Matrix4x4.TRS(pos, rot, new Vector3(scale, scale, scale)) * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one); // Rotate plane by 90
Handles.DrawSolidRectangleWithOutline(new Rect(-0.5f, -0.5f, 1, 1), faceColor, edgeColor);
Handles.DrawLine(Vector3.zero, Vector3.back / scale);
Handles.matrix = oldMatrix;
}
private static void DrawGrid(Vector3 pos, Vector3 axis1, Vector3 axis2, Vector3 normal, Color color)
{
if (Event.current.type != EventType.Repaint)
return;
HandleUtility.ApplyWireMaterial();
if (color.a > 0)
{
GL.Begin(GL.LINES);
float lineLength = 10f;
int numLines = 11;
lineLength *= m_ScaleGrid;
numLines = (int)lineLength;
numLines = Mathf.Clamp(numLines, 10, 40);
if (numLines % 2 == 0)
numLines++;
float halfLength = lineLength * 0.5f;
float distBetweenLines = lineLength / (numLines - 1);
Vector3 v1 = axis1 * lineLength;
Vector3 v2 = axis2 * lineLength;
Vector3 dist1 = axis1 * distBetweenLines;
Vector3 dist2 = axis2 * distBetweenLines;
Vector3 startPos = pos - axis1 * halfLength - axis2 * halfLength;
for (int i = 0; i < numLines; i++)
{
if (i % 2 == 0)
GL.Color(color * 0.7f);
else
GL.Color(color);
// Axis1
GL.Vertex(startPos + i * dist1);
GL.Vertex(startPos + i * dist1 + v2);
// Axis2
GL.Vertex(startPos + i * dist2);
GL.Vertex(startPos + i * dist2 + v1);
}
GL.Color(color);
GL.Vertex(pos);
GL.Vertex(pos + normal);
GL.End();
}
}
override public void UpdateCullingSupportedString(ref string text)
{
text += "\nCollision module is enabled.";
}
}
} // namespace UnityEditor
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

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

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

取消
提交

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/billwillman/UnityCsReference.git
git@gitee.com:billwillman/UnityCsReference.git
billwillman
UnityCsReference
UnityCsReference
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

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