8000 Feature/trainunit by toropippi · Pull Request #461 · moorestech/moorestech · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature/trainunit #461

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

Merged
merged 7 commits into from
Jan 19, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Game.Block.Interface;
using Game.Block.Interface.Component;
using Game.Train.RailGraph;
using Game.Train.Utility;
using UnityEngine;

namespace Game.Block.Blocks.TrainRail
{
Expand All @@ -16,12 +19,15 @@ public class RailComponent : IBlockComponent
// このレールに関連付けられているRailNode(表と裏)
public RailNode FrontNode { get; private set; }
public RailNode BackNode { get; private set; }
//3D上のブロック座標
public UnityEngine.Vector3Int Position { get; private set; }
//3D上のブロック座標など
private BlockPositionInfo blockPositionInfo;
//制御点計算用ベジェ曲線微分強度
private float bezierStrength { get; set; } = 0.5f;//今後手動でいじれるようにするかも

// コンストラクタ
public RailComponent()
public RailComponent(BlockPositionInfo blockPositionInfo_)
{
blockPositionInfo = blockPositionInfo_;
// RailGraphにノードを登録
FrontNode = new RailNode();
BackNode = new RailNode();
Expand All @@ -32,27 +38,40 @@ public RailComponent()
//レール接続作業、手動でつなげたときを想定。自分の表or裏を起点に相手の表or裏につながる
//isFront_this:true 自分の表から相手のxに入る
//isFront_target:true 相手の表に入る
public void ConnectRailComponent(RailComponent targetRail, bool isFront_this, bool isFront_target)
//defaultdistanceはデバッグ時以外基本していしない
public void ConnectRailComponent(RailComponent targetRail, bool isFront_this, bool isFront_target, int defaultdistance = -1)
{
//距離を算出
var p0 = (Vector3)GetPosition();//自分のアンカーポイント
var p1 = GetControlPoint(isFront_this);//自分の制御点
var p2 = targetRail.GetControlPoint(!isFront_target);//相手の制御点
var p3 = (Vector3)targetRail.GetPosition();//相手のアンカーポイント
int distance = (int)(BezierUtility.GetBezierCurveLength(p0, p1, p2, p3) * BezierUtility.RAIL_LENGTH_SCALE + 0.5f);
if (defaultdistance != -1)
{
distance = defaultdistance;
}


if ((isFront_this == true) & (isFront_target == true))//表自→表相、裏相→表自
{
FrontNode.ConnectNode(targetRail.FrontNode, 1);
targetRail.BackNode.ConnectNode(BackNode, 1);
FrontNode.ConnectNode(targetRail.FrontNode, distance);
targetRail.BackNode.ConnectNode(BackNode, distance);
}
else if ((isFront_this == true) & (isFront_target == false))//表自→裏相、表相→裏自
{
FrontNode.ConnectNode(targetRail.BackNode, 1);
targetRail.FrontNode.ConnectNode(BackNode, 1);
FrontNode.ConnectNode(targetRail.BackNode, distance);
targetRail.FrontNode.ConnectNode(BackNode, distance);
}
else if ((isFront_this == false) & (isFront_target == true))//裏自→表相、裏相→表自
{
BackNode.ConnectNode(targetRail.FrontNode, 1);
targetRail.BackNode.ConnectNode(FrontNode, 1);
BackNode.ConnectNode(targetRail.FrontNode, distance);
targetRail.BackNode.ConnectNode(FrontNode, distance);
}
else if ((isFront_this == false) & (isFront_target == false))//裏自→裏相、表相→表自
{
BackNode.ConnectNode(targetRail.BackNode, 1);
targetRail.FrontNode.ConnectNode(FrontNode, 1);
BackNode.ConnectNode(targetRail.BackNode, distance);
targetRail.FrontNode.ConnectNode(FrontNode, distance);
}
}

Expand Down Expand Up @@ -80,6 +99,43 @@ public void DisconnectRailComponent(RailComponent targetRail, bool isFront_this,
}
}

// 自分の座標vector3intを返す
public Vector3Int GetPosition()
{
return blockPositionInfo.OriginalPos;
}
// 自分の向いている方角とbezierStrengthから制御点を計算してvector3で返す
public Vector3 GetControlPoint(bool isFront)
{
var dir = blockPositionInfo.BlockDirection;
//ここではdirがnorth,east,south,westのみを想定
Vector3 direction = new Vector3();
switch (dir)
{
case BlockDirection.North:
direction = new Vector3(0, 0, 1);
break;
case BlockDirection.East:
direction = new Vector3(1, 0, 0);
break;
case BlockDirection.South:
direction = new Vector3(0, 0, -1);
break;
case BlockDirection.West:
direction = new Vector3(-1, 0, 0);
break;
}
//isFrontがfalseの場合は反対側に制御点を設定
if (isFront == false)
{
return blockPositionInfo.OriginalPos - direction * bezierStrength;//多分vector3(0.5,0.5,0.5)が足されて中心になる
}
else
{
return blockPositionInfo.OriginalPos + direction * bezierStrength;
}
}

// このレールを破壊する処理
public void Destroy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class VanillaTrainRailTemplate : IBlockTemplate
{
public IBlock New(BlockMasterElement blockMasterElement, BlockInstanceId blockInstanceId, BlockPositionInfo blockPositionInfo)
{
var transformer = new RailComponent();
var transformer = new RailComponent(blockPositionInfo);
var components = new List<IBlockComponent>
{
transformer,
Expand All @@ -22,7 +22,7 @@ public IBlock New(BlockMasterElement blockMasterElement, BlockInstanceId blockIn

public IBlock Load(Dictionary<string, string> componentStates, BlockMasterElement blockMasterElement, BlockInstanceId blockInstanceId, BlockPositionInfo blockPositionInfo)
{
var transformer = new RailComponent();
var transformer = new RailComponent(blockPositionInfo);
var components = new List<IBlockComponent>
{
transformer,
Expand Down
Loading
Loading
0