Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 道路追加機能 #388

Open
wants to merge 3 commits into
base: dev/v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Editor/RoadNetwork/AddSystem.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions Editor/RoadNetwork/AddSystem/RoadNetworkAddSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using PLATEAU.Editor.RoadNetwork.EditingSystemSubMod;
using PLATEAU.RoadAdjust.RoadNetworkToMesh;
using PLATEAU.RoadAdjust;
using PLATEAU.RoadNetwork.Structure;
using UnityEditor;
using UnityEngine;

namespace PLATEAU.Editor.RoadNetwork
{
internal class RoadNetworkAddSystem
{
public static RoadNetworkAddSystem Active { get; private set; }

public RoadNetworkAddSystemContext Context { get; private set; }
public RnRoadAddSystem RoadAddSystem { get; private set; }

private RoadNetworkAddSystem(PLATEAURnStructureModel structureModel)
{
Context = new RoadNetworkAddSystemContext(structureModel);

RoadAddSystem = new RnRoadAddSystem(Context);
RoadAddSystem.OnRoadAdded = (roadGroup) =>
{
// 道路モデル再生成
bool crosswalkExists = PLATEAUReproducedRoad.Find(ReproducedRoadType.Crosswalk, roadGroup.Roads[0].TargetTrans[0].transform, ReproducedRoadDirection.Next);
new RoadReproducer().Generate(new RrTargetRoadBases(Context.RoadNetwork, roadGroup.Roads), crosswalkExists ? CrosswalkFrequency.All : CrosswalkFrequency.Delete);

// スケルトン更新
Context.SkeletonData.UpdateData(roadGroup);
};
}

public static bool TryInitializeGlobal()
{
Active?.Terminate();

var structureModel = Object.FindObjectOfType<PLATEAURnStructureModel>();
if (structureModel == null)
return false;

Active = new RoadNetworkAddSystem(structureModel);

// SceneViewの更新イベントにフック
SceneView.duringSceneGui += Active.OnSceneGUI;

return true;
}

public static void TerminateGlobal()
{
if (Active == null)
return;

Active.Terminate();

// SceneViewの更新イベントから除外
SceneView.duringSceneGui -= Active.OnSceneGUI;

Active = null;

return;
}

private void Terminate()
{
RoadAddSystem.Deactivate();
}

private void OnSceneGUI(SceneView sceneView)
{
RoadAddSystem.HandleSceneGUI(sceneView);
}
}
}
11 changes: 11 additions & 0 deletions Editor/RoadNetwork/AddSystem/RoadNetworkAddSystem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Editor/RoadNetwork/AddSystem/RoadNetworkAddSystemContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using PLATEAU.RoadNetwork;
using PLATEAU.RoadNetwork.Structure;

namespace PLATEAU.Editor.RoadNetwork
{
internal class RoadNetworkAddSystemContext
{
public RnModel RoadNetwork { get; private set; }
public RoadNetworkSkeletonData SkeletonData { get; private set; }

public RoadNetworkAddSystemContext(PLATEAURnStructureModel structureModel)
{
SkeletonData = new RoadNetworkSkeletonData(structureModel);
RoadNetwork = structureModel.RoadNetwork;
}
}
}
11 changes: 11 additions & 0 deletions Editor/RoadNetwork/AddSystem/RoadNetworkAddSystemContext.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public RoadNetworkEditSceneViewGui(GameObject root, RnModel rnModel,

/// <summary> 道路のレーンをドラッグで編集する機能です。 </summary>
private WaySlider waySlider = new WaySlider();


/// <summary>
/// 計算や処理に必要な要素を初期化する
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using PLATEAU.Editor.RoadNetwork.EditingSystemSubMod;
using PLATEAU.RoadNetwork;
using PLATEAU.RoadNetwork.Structure;
using System.Collections.Generic;
Expand Down
81 changes: 81 additions & 0 deletions Editor/RoadNetwork/EditingSystem/RoadNetworkSkeletonData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using PLATEAU.RoadNetwork.Structure;
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Splines;

namespace PLATEAU.RoadNetwork
{
internal class RnIntersectionSkeleton
{
public RnIntersectionSkeleton(RnIntersection intersection)
{
Intersection = intersection;
}

public Vector3 Position { get; }
public RnIntersection Intersection { get; }
}

internal class RnRoadSkeleton
{
public RnRoadSkeleton(RnRoadGroup road)
{
Spline = CreateCenterSpline(road);
Road = road;
}

public Spline Spline { get; private set; }
public RnRoadGroup Road { get; }

public void UpdateSpline()
{
Road.TryCreateSimpleSpline(out var spline, out var width);
Spline = spline;
}

private static Spline CreateCenterSpline(RnRoadGroup road)
{
road.TryCreateSimpleSpline(out var spline, out var width);
List<BezierKnot> knots = new List<BezierKnot>();
BezierKnot prevKnot = new BezierKnot();
foreach (var knot in spline.Knots)
{
// 重複しているノットがあるので削除
if (prevKnot.Position.x == knot.Position.x &&
prevKnot.Position.z == knot.Position.z)
continue;

var newKnot = knot;
newKnot.Position += new float3(0f, 0f, 0f);
knots.Add(newKnot);

prevKnot = knot;
}
spline.Knots = knots.ToArray();

return spline;
}
}

internal class RoadNetworkSkeletonData
{
public List<RnIntersectionSkeleton> Intersections { get; private set; }
public List<RnRoadSkeleton> Roads { get; private set; }

public RoadNetworkSkeletonData(PLATEAURnStructureModel structureModel)
{
Roads = structureModel.RoadNetwork.Roads.Select(x => new RnRoadSkeleton(x.CreateRoadGroup())).ToList();

Intersections = structureModel.RoadNetwork.Intersections.Select(x => new RnIntersectionSkeleton(x)).ToList();
}

internal void UpdateData(RnRoadGroup roadGroup)
{
var roadSkeleton = Roads.FirstOrDefault(x => x.Road == roadGroup);
roadSkeleton?.UpdateSpline();
}
}
}
11 changes: 11 additions & 0 deletions Editor/RoadNetwork/EditingSystem/RoadNetworkSkeletonData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/RoadNetwork/EditingSystemSubMod/SplineSystems.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading