Skip to content

Commit 6056cab

Browse files
committed
further abstracted animation system for flexibility
1 parent dd30296 commit 6056cab

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

Assets/SilVR/4D-Chess-Udon/Scripts/Chess4DBoard.cs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,26 @@ void SetChildObjectsRendering(GameObject root, int square, Mesh[] mesh_set, Mate
220220
/// Animating Pieces ///
221221
/// ///
222222
///////////////////////////////////////
223+
public void SetPiecePosition(int from, int to)
224+
{
225+
Vector3 pos = PosFromIndex(to);
226+
GameObject piece = FetchGameobjectsChild(squares_root, from);
227+
piece.transform.position = pos;
228+
229+
}
230+
public void UpdateAssignedTargetsIfNotNull(float speed)
231+
{
232+
int PIECE_TARGET_INDEX = 0;
233+
UpdateTargetIfNotNull(PIECE_TARGET_INDEX, speed);
234+
}
235+
236+
public void AddTargets(int square)
237+
{
238+
GameObject piece = FetchGameobjectsChild(squares_root, square);
239+
int PIECE_TARGET_INDEX = 0;
240+
AddTarget(PIECE_TARGET_INDEX, square, piece);
241+
242+
}
223243

224244
GameObject FetchGameobjectsChild(GameObject root, int square)
225245
{
@@ -486,9 +506,10 @@ void Update()
486506
}
487507
}
488508

489-
// Move the target piece towards its target position, if its not null.
509+
// Move the target pieces towards its target position, if its not null.
490510
// 0 specifices the first target, and move speed sets how far to move the piece per frame.
491-
UpdateTargetIfNotNull(0, move_speed * Time.deltaTime);
511+
// Abstracted for easy overriding
512+
UpdateAssignedTargetsIfNotNull(move_speed * Time.deltaTime);
492513

493514
// Set the turn indicator to show whos turn it is to play.
494515
// TODO: Get this out of update function
@@ -1112,15 +1133,18 @@ public void MakeMove(int from, int to)
11121133

11131134
SetArrow(piece_arrow, from, to);
11141135

1115-
// Set our new target piece
11161136
target_piece = to;
1117-
AddTarget(0, to, FetchGameobjectsChild(squares_root, to));
1137+
AddTargets(to);
1138+
SetPiecePosition(to, from);
1139+
1140+
// Set our new target piece
1141+
//AddTarget(0, to, FetchGameobjectsChild(squares_root, to));
11181142

11191143
// Grab the square gameobject of the piece we need to grab
1120-
GameObject square = squares_root.transform.GetChild(target_piece).gameObject;
1144+
//GameObject square = squares_root.transform.GetChild(target_piece).gameObject;
11211145

11221146
// and move it to where it is moving from, so we can automatically move it towards its new position
1123-
square.transform.position = PosFromIndex(from);
1147+
//square.transform.position = PosFromIndex(from);
11241148
}
11251149

11261150

@@ -1145,11 +1169,12 @@ public void UnmakeMove(int from, int to, int captured, int promoted)
11451169

11461170
// Target the new piece, that should be the piece that moved on this encoded move.
11471171
target_piece = from;
1148-
AddTarget(0, from, FetchGameobjectsChild(squares_root, from));
1149-
1172+
AddTargets(from);
1173+
//AddTarget(0, from, FetchGameobjectsChild(squares_root, from));
1174+
SetPiecePosition(from, to);
11501175
// and move it to where its moving from (the move's "to coordinate"), so it can be auto moved in update.
1151-
GameObject square = squares_root.transform.GetChild(target_piece).gameObject;
1152-
square.transform.position = PosFromIndex(to);
1176+
//GameObject square = squares_root.transform.GetChild(target_piece).gameObject;
1177+
//square.transform.position = PosFromIndex(to);
11531178
}
11541179

11551180

0 commit comments

Comments
 (0)