Skip to content

Commit 8be3c10

Browse files
Merge pull request #16 from Synesthesias/release/v2.1.0
Release/v2.1.0
2 parents c15b346 + 7cce677 commit 8be3c10

File tree

689 files changed

+130405
-4101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

689 files changed

+130405
-4101
lines changed
Binary file not shown.
Binary file not shown.

PlateauToolkit.Foundation/Editor/PlateauToolkitEditorGUILayout.cs

+30
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public static void BorderLine()
108108
EditorGUI.DrawRect(borderRect, PlateauToolkitGUIStyles.k_LineColor);
109109
}
110110

111+
public static void BorderLine(Color color, float height = 1f)
112+
{
113+
Rect borderRect = EditorGUILayout.GetControlRect(false, height, PlateauToolkitGUIStyles.BorderStyle);
114+
EditorGUI.DrawRect(borderRect, color);
115+
}
116+
111117
public static void Title(float windowWidth, string label)
112118
{
113119
EditorGUILayout.Space(15);
@@ -303,6 +309,30 @@ public bool TabButton(
303309
return button;
304310
}
305311

312+
public bool TabButton(string label)
313+
{
314+
float scopeWidth = m_IsPositionCenter ? 0 : m_Width;
315+
using (var scope = new EditorGUILayout.HorizontalScope(GUILayout.Height(m_Height), GUILayout.Width(scopeWidth)))
316+
{
317+
GUILayout.FlexibleSpace();
318+
319+
float centerY = (scope.rect.height - m_Height) / 2;
320+
float centerX = (scope.rect.width - m_Width) / 2;
321+
var buttonRect = new Rect(scope.rect.x + centerX, scope.rect.y + centerY, m_Width, m_Height);
322+
323+
GUI.DrawTexture(buttonRect, WhiteTexture, ScaleMode.StretchToFill, true, 0, m_Color, new Vector4(), new Vector4(6f, 6f, 0f, 0f));
324+
325+
bool button = GUILayout.Button(
326+
label,
327+
PlateauToolkitGUIStyles.ButtonStyle,
328+
GUILayout.Height(m_Height),
329+
GUILayout.Width(m_Width));
330+
331+
GUILayout.FlexibleSpace();
332+
return button;
333+
}
334+
}
335+
306336
public bool Button(string label)
307337
{
308338
float scopeWidth = m_IsPositionCenter ? 0 : m_Width;

PlateauToolkit.Rendering/Runtime/DayNightCycle/EnvironmentController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public Vector3 CalculateSunDirection(DateTime dateTime, float latitude, float lo
629629
Math.Cos(elipticalLongitude));
630630
double declination = Math.Asin(
631631
Math.Sin(rightAscension) * Math.Sin(obliquity));
632-
double hourAngle = NormalizeAngle(siderealTime * Math.PI / 180.0) - rightAscension;
632+
double hourAngle = rightAscension - NormalizeAngle(siderealTime * Math.PI / 180.0);
633633

634634
if (hourAngle > Math.PI)
635635
{

PlateauToolkit.Sandbox/Editor/ElectricPost.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
using PlateauToolkit.Editor;
2+
using PlateauToolkit.Sandbox.Runtime.ElectricPost;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using UnityEditor;
6+
using UnityEngine;
7+
using UnityEngine.Events;
8+
using EditorGUILayout = UnityEditor.EditorGUILayout;
9+
10+
namespace PlateauToolkit.Sandbox.Editor
11+
{
12+
/// <summary>
13+
/// 電柱コンポーネントのGUI表示
14+
/// </summary>
15+
public class PlateauSandboxElectricPostConnectionGUI
16+
{
17+
public PlateauSandboxElectricPostConnectionGUI(PlateauSandboxElectricPost own, bool isFront)
18+
{
19+
m_Context = PlateauSandboxElectricPostContext.GetCurrent();
20+
m_Own = own;
21+
m_IsFront = isFront;
22+
}
23+
private PlateauSandboxElectricPostContext m_Context;
24+
private PlateauSandboxElectricPost m_Own;
25+
private bool m_IsFront;
26+
private int m_SelectingIndex = -1;
27+
28+
public UnityEvent<PlateauSandboxElectricPost> OnDirectSelect = new ();
29+
public UnityEvent<bool> OnClickSelect = new ();
30+
31+
public void DrawLayout(List<PlateauSandboxElectricConnectInfo> connectedPosts)
32+
{
33+
GUILayout.Space(5);
34+
PlateauToolkitEditorGUILayout.BorderLine();
35+
GUILayout.Space(5);
36+
37+
// タイトル
38+
DrawTitle();
39+
40+
// 接続先の電柱
41+
if (connectedPosts != null)
42+
{
43+
foreach (var connectedPost in connectedPosts.ToList())
44+
{
45+
PlateauSandboxElectricPost selectingPost = null;
46+
47+
GUILayout.Space(5);
48+
selectingPost = DrawConnectedPost(connectedPost.m_OwnIndex, connectedPost.m_Target);
49+
GUILayout.Space(5);
50+
51+
using (new EditorGUILayout.HorizontalScope())
52+
{
53+
if (selectingPost != null)
54+
{
55+
DrawIsConnectedFront(connectedPost.m_OwnIndex, selectingPost);
56+
}
57+
}
58+
59+
GUILayout.Space(5);
60+
using (new EditorGUILayout.HorizontalScope())
61+
{
62+
GUILayout.FlexibleSpace();
63+
DrawSelectButton(connectedPost.m_OwnIndex, selectingPost);
64+
GUILayout.Space(5);
65+
DrawDeleteButton(connectedPost.m_OwnIndex, selectingPost);
66+
}
67+
68+
GUILayout.Space(5);
69+
}
70+
}
71+
72+
// 追加ボタン
73+
GUILayout.Space(15);
74+
using (new EditorGUILayout.HorizontalScope())
75+
{
76+
GUILayout.FlexibleSpace();
77+
DrawAddButton();
78+
GUILayout.FlexibleSpace();
79+
}
80+
GUILayout.Space(10);
81+
}
82+
83+
public void DrawTitle()
84+
{
85+
// タイトル
86+
EditorGUILayout.LabelField(m_IsFront ? "前方接続部" : "後方接続部", EditorStyles.boldLabel);
87+
}
88+
89+
public PlateauSandboxElectricPost DrawConnectedPost(int index, PlateauSandboxElectricPost target)
90+
{
91+
string focusName = "";
92+
if (target != null)
93+
{
94+
// フォーカス時の名前を設定
95+
focusName = $"{target.name}_{index}";
96+
GUI.SetNextControlName(focusName);
97+
}
98+
99+
// 接続先の電柱
100+
var selectedPost = EditorGUILayout.ObjectField(
101+
"",
102+
target,
103+
typeof(PlateauSandboxElectricPost), true) as PlateauSandboxElectricPost;
104+
105+
if (selectedPost != null &&
106+
selectedPost != target &&
107+
selectedPost != m_Own)
108+
{
109+
// ドロップで直接セット
110+
bool isOtherFront = selectedPost.IsTargetFacingForward(selectedPost.gameObject.transform.position);
111+
int otherIndex = selectedPost.AddConnectionAndWires(isOtherFront);
112+
113+
string wireID = m_Own.GetWireID();
114+
m_Own.SetConnectPoint(selectedPost, m_IsFront, isOtherFront, index, wireID, otherIndex);
115+
selectedPost.SetConnectPoint(m_Own, isOtherFront, m_IsFront, otherIndex, wireID, index);
116+
}
117+
118+
// Deleteイベント
119+
if (Event.current.keyCode == KeyCode.Delete ||
120+
Event.current.keyCode == KeyCode.Backspace)
121+
{
122+
if (GUI.GetNameOfFocusedControl() == focusName)
123+
{
124+
// 選択をnullに設定
125+
var post = m_Own.GetConnectedPost(m_IsFront, index);
126+
selectedPost?.ResetConnection(post.m_IsTargetFront, post.m_TargetIndex);
127+
m_Own.ResetConnection(m_IsFront, index);
128+
}
129+
}
130+
131+
return selectedPost;
132+
}
133+
134+
private void DrawIsConnectedFront(int count, PlateauSandboxElectricPost target)
135+
{
136+
var post = m_Own.GetConnectedPost(m_IsFront, count);
137+
138+
GUI.enabled = false;
139+
string text = post.m_IsTargetFront ? "接続部:前方" : "接続部:後方";
140+
EditorGUILayout.LabelField(text);
141+
GUI.enabled = true;
142+
}
143+
144+
private void DrawSelectButton(int index, PlateauSandboxElectricPost other)
145+
{
146+
bool isSelect = index == m_SelectingIndex;
147+
if (new PlateauToolkitImageButtonGUI(
148+
100,
149+
20,
150+
isSelect ? PlateauToolkitGUIStyles.k_ButtonCancelColor : PlateauToolkitGUIStyles.k_ButtonNormalColor,
151+
false)
152+
.Button("選択する"))
153+
{
154+
// 選択時
155+
if (!isSelect)
156+
{
157+
// ワイヤーを外す
158+
var post = m_Own.GetConnectedPost(m_IsFront, index);
159+
other?.ResetConnection(post.m_IsTargetFront, post.m_TargetIndex);
160+
m_Own.ResetConnection(m_IsFront, index);
161+
162+
// ワイヤーを非表示に
163+
m_Own.HideWire(m_IsFront, index);
164+
other?.HideWire(post.m_IsTargetFront, post.m_TargetIndex);
165+
166+
m_SelectingIndex = index;
167+
m_Context.SetSelectingPost(m_Own, m_IsFront, index);
168+
}
169+
else
170+
{
171+
m_SelectingIndex = -1;
172+
m_Context.ResetSelect();
173+
}
174+
OnClickSelect.Invoke(m_SelectingIndex >= 0);
175+
}
176+
}
177+
178+
private void DrawDeleteButton(int index, PlateauSandboxElectricPost other)
179+
{
180+
if (new PlateauToolkitImageButtonGUI(
181+
100,
182+
20,
183+
PlateauToolkitGUIStyles.k_ButtonPrimaryColor,
184+
false)
185+
.Button("削除する"))
186+
{
187+
188+
var post = m_Own.GetConnectedPost(m_IsFront, index);
189+
other?.RemoveConnection(post.m_IsTargetFront, post.m_TargetIndex);
190+
m_Own.RemoveConnection(m_IsFront, index);
191+
192+
Reset();
193+
}
194+
}
195+
196+
private void DrawAddButton()
197+
{
198+
if (new PlateauToolkitImageButtonGUI(
199+
150,
200+
20,
201+
PlateauToolkitGUIStyles.k_ButtonPrimaryColor,
202+
false)
203+
.Button("追加する"))
204+
{
205+
// ワイヤーを追加
206+
m_Own.AddConnectionAndWires(m_IsFront);
207+
}
208+
}
209+
210+
public void Reset()
211+
{
212+
m_Context.ResetSelect();
213+
m_SelectingIndex = -1;
214+
}
215+
}
216+
217+
}

PlateauToolkit.Sandbox/Editor/ElectricPost/PlateauSandboxElectricPostConnectionGUI.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using PlateauToolkit.Editor;
2+
using PlateauToolkit.Sandbox.Runtime;
3+
using PlateauToolkit.Sandbox.Runtime.ElectricPost;
4+
using System.Collections.Generic;
5+
using System.Threading.Tasks;
6+
using UnityEditor;
7+
using UnityEditor.EditorTools;
8+
using UnityEngine;
9+
10+
namespace PlateauToolkit.Sandbox.Editor
11+
{
12+
[CustomEditor(typeof(PlateauSandboxElectricPost))]
13+
public class PlateauSandboxElectricPostInspector : UnityEditor.Editor
14+
{
15+
private PlateauSandboxElectricPostContext m_Context;
16+
private PlateauSandboxElectricPost m_Target;
17+
18+
private PlateauSandboxElectricPostConnectionGUI m_FrontConnectionGUI;
19+
private PlateauSandboxElectricPostConnectionGUI m_BackConnectionGUI;
20+
21+
private void OnEnable()
22+
{
23+
m_Target = target as PlateauSandboxElectricPost;
24+
m_Context = PlateauSandboxElectricPostContext.GetCurrent();
25+
m_Context.OnSelected.AddListener(ResetSelect);
26+
27+
SetGUI();
28+
}
29+
30+
private void SetGUI()
31+
{
32+
if (m_FrontConnectionGUI == null)
33+
{
34+
m_FrontConnectionGUI = new PlateauSandboxElectricPostConnectionGUI(m_Target, true);
35+
m_FrontConnectionGUI.OnClickSelect.AddListener(SelectingPost);
36+
}
37+
if (m_BackConnectionGUI == null)
38+
{
39+
m_BackConnectionGUI = new PlateauSandboxElectricPostConnectionGUI(m_Target, false);
40+
m_BackConnectionGUI.OnClickSelect.AddListener(SelectingPost);
41+
}
42+
}
43+
44+
public override void OnInspectorGUI()
45+
{
46+
if (m_Context == null || m_Target == null)
47+
{
48+
return;
49+
}
50+
51+
serializedObject.Update();
52+
base.OnInspectorGUI();
53+
54+
m_FrontConnectionGUI.DrawLayout(m_Target.FrontConnectedPosts);
55+
m_BackConnectionGUI.DrawLayout(m_Target.BackConnectedPosts);
56+
57+
if (GUI.changed)
58+
{
59+
EditorUtility.SetDirty(m_Target);
60+
serializedObject.ApplyModifiedProperties();
61+
}
62+
63+
// キーイベント
64+
if (Event.current.keyCode == KeyCode.Escape)
65+
{
66+
ResetSelect();
67+
}
68+
}
69+
70+
private void SelectingPost(bool isSelecting)
71+
{
72+
if (isSelecting)
73+
{
74+
// 選択中状態に
75+
SetActiveTool();
76+
}
77+
else
78+
{
79+
ResetSelect();
80+
}
81+
}
82+
83+
private void ResetSelect()
84+
{
85+
GUIUtility.hotControl = 0;
86+
Event.current.Use();
87+
88+
ToolManager.RestorePreviousPersistentTool();
89+
m_FrontConnectionGUI.Reset();
90+
m_BackConnectionGUI.Reset();
91+
92+
m_Context.OnCancel.Invoke();
93+
}
94+
95+
private void SetActiveTool()
96+
{
97+
if (ToolManager.activeToolType != typeof(PlateauSandboxElectricPostSelectTool))
98+
{
99+
ToolManager.SetActiveTool<PlateauSandboxElectricPostSelectTool>();
100+
}
101+
else
102+
{
103+
ToolManager.RestorePreviousPersistentTool();
104+
}
105+
}
106+
}
107+
}

PlateauToolkit.Sandbox/Editor/ElectricPost/PlateauSandboxElectricPostInspector.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)