forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneViewGrid.cs
More file actions
73 lines (64 loc) · 2.35 KB
/
Copy pathSceneViewGrid.cs
File metadata and controls
73 lines (64 loc) · 2.35 KB
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEditor;
using System.Collections;
namespace UnityEditor
{
[System.Serializable]
internal class SceneViewGrid
{
static PrefColor kViewGridColor = new PrefColor("Scene/Grid", .5f, .5f, .5f, .4f);
public void Register(SceneView source)
{
// hook up the anims, so repainting can work correctly
xGrid.valueChanged.AddListener(source.Repaint);
yGrid.valueChanged.AddListener(source.Repaint);
zGrid.valueChanged.AddListener(source.Repaint);
}
[SerializeField]
AnimBool xGrid = new AnimBool();
[SerializeField]
AnimBool yGrid = new AnimBool();
[SerializeField]
AnimBool zGrid = new AnimBool();
public DrawGridParameters PrepareGridRender(Camera camera, Vector3 pivot, Quaternion rotation,
float size, bool orthoMode, bool gridVisible
)
{
bool _xGrid = false, _yGrid = false, _zGrid = false;
if (gridVisible)
{
if (orthoMode)
{
Vector3 fwd = rotation * Vector3.forward;
// Show horizontal grid as long as angle is not too small
if (Mathf.Abs(fwd.y) > 0.2f)
_yGrid = true;
// Show xy and zy planes only when straight on
else if (fwd == Vector3.left || fwd == Vector3.right)
_xGrid = true;
else if (fwd == Vector3.forward || fwd == Vector3.back)
_zGrid = true;
}
else
{
_yGrid = true;
}
}
xGrid.target = _xGrid;
yGrid.target = _yGrid;
zGrid.target = _zGrid;
DrawGridParameters parameters;
parameters.pivot = pivot;
parameters.color = kViewGridColor;
parameters.size = size;
parameters.alphaX = xGrid.faded;
parameters.alphaY = yGrid.faded;
parameters.alphaZ = zGrid.faded;
return parameters;
}
}
} // namespace