OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.render-pipelines.core@6.9.0 / Editor / LookDev / ComparisonGizmoState.cs
1 using System;
2 using UnityEditor.AnimatedValues;
3 using UnityEngine;
4
5 namespace UnityEditor.Rendering.Experimental.LookDev
6 {
7     [Serializable]
8     public class ComparisonGizmoState
9     {
10         public const float thickness = 0.0028f;
11         public const float thicknessSelected = 0.015f;
12         public const float circleRadius = 0.014f;
13         public const float circleRadiusSelected = 0.03f;
14         public const float blendFactorCircleRadius = 0.01f;
15         public const float blendFactorCircleRadiusSelected = 0.03f;
16         
17         public Vector2 point1 { get; private set; }
18         public Vector2 point2 { get; private set; }
19         [field: SerializeField]
20         public Vector2 center { get; private set; } = Vector2.zero;
21         [field: SerializeField]
22         public float angle { get; private set; }
23         [field: SerializeField]
24         public float length { get; private set; } = 0.2f;
25         public Vector4 plane { get; private set; }
26         public Vector4 planeOrtho { get; private set; }
27         [field: SerializeField]
28         public float blendFactor { get; set; }
29
30         public float blendFactorMaxGizmoDistance
31             => length - circleRadius - blendFactorCircleRadius;
32
33         public float blendFactorMinGizmoDistance
34             => length - circleRadius - blendFactorCircleRadiusSelected;
35
36         internal void Init()
37             => Update(center, length, angle);
38         
39         //TODO: optimize
40         private Vector4 Get2DPlane(Vector2 firstPoint, float angle)
41         {
42             Vector4 result = new Vector4();
43             angle = angle % (2.0f * (float)Math.PI);
44             Vector2 secondPoint = new Vector2(firstPoint.x + Mathf.Sin(angle), firstPoint.y + Mathf.Cos(angle));
45             Vector2 diff = secondPoint - firstPoint;
46             if (Mathf.Abs(diff.x) < 1e-5)
47             {
48                 result.Set(-1.0f, 0.0f, firstPoint.x, 0.0f);
49                 float sign = Mathf.Cos(angle) > 0.0f ? 1.0f : -1.0f;
50                 result *= sign;
51             }
52             else
53             {
54                 float slope = diff.y / diff.x;
55                 result.Set(-slope, 1.0f, -(firstPoint.y - slope * firstPoint.x), 0.0f);
56             }
57
58             if (angle > Mathf.PI)
59                 result = -result;
60
61             float length = Mathf.Sqrt(result.x * result.x + result.y * result.y);
62             result = result / length;
63             return result;
64         }
65
66         public void Update(Vector2 point1, Vector2 point2)
67         {
68             this.point1 = point1;
69             this.point2 = point2;
70             center = (point1 + point2) * 0.5f;
71             length = (point2 - point1).magnitude * 0.5f;
72
73             Vector3 verticalPlane = Get2DPlane(center, 0.0f);
74             float side = Vector3.Dot(new Vector3(point1.x, point1.y, 1.0f), verticalPlane);
75             angle = (Mathf.Deg2Rad * Vector2.Angle(new Vector2(0.0f, 1.0f), (point1 - point2).normalized));
76             if (side > 0.0f)
77                 angle = 2.0f * Mathf.PI - angle;
78
79             plane = Get2DPlane(center, angle);
80             planeOrtho = Get2DPlane(center, angle + 0.5f * (float)Mathf.PI);
81         }
82
83         public void Update(Vector2 center, float length, float angle)
84         {
85             this.center = center;
86             this.length = length;
87             this.angle = angle;
88
89             plane = Get2DPlane(center, angle);
90             planeOrtho = Get2DPlane(center, angle + 0.5f * (float)Mathf.PI);
91
92             Vector2 dir = new Vector2(planeOrtho.x, planeOrtho.y);
93             point1 = center + dir * length;
94             point2 = center - dir * length;
95         }
96     }
97 }