Files
ichni_Creator_Studio/Assets/Scripts/GameElements/Track/PathNode.cs

116 lines
3.7 KiB
C#
Raw Normal View History

2025-02-02 08:34:54 -05:00
using System;
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using Ichni;
using Ichni.RhythmGame.Beatmap;
using Lean.Pool;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Ichni.RhythmGame
{
public partial class PathNode : GameElement, IHaveTransformSubmodule, IHaveTimeDurationSubmodule, IHaveColorSubmodule
{
public Track track;
2025-02-02 21:59:43 -05:00
public int index => track.trackPathSubmodule.pathNodeList.IndexOf(this);
2025-02-02 21:59:43 -05:00
public SplinePoint node;
2025-02-02 21:59:43 -05:00
public TransformSubmodule transformSubmodule { get; set; }
public TimeDurationSubmodule timeDurationSubmodule { get; set; }
public ColorSubmodule colorSubmodule { get; set; }
public static PathNode GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated,
Track track)
{
2025-02-02 21:59:43 -05:00
PathNode pathNode = Instantiate(EditorManager.instance.basePrefabs.pathNode, track.transform)
.GetComponent<PathNode>();
2025-02-09 23:47:42 -05:00
pathNode.Initialize(elementName, id, tags, isFirstGenerated, track);
2025-02-02 21:59:43 -05:00
pathNode.track = track;
track.trackPathSubmodule.pathNodeList.Add(pathNode);
return pathNode;
}
protected override void SetDefaultSubmodules()
{
transformSubmodule = new TransformSubmodule(this);
timeDurationSubmodule = new TimeDurationSubmodule(this);
colorSubmodule = new ColorSubmodule(this);
submoduleList.Add(transformSubmodule);
submoduleList.Add(timeDurationSubmodule);
submoduleList.Add(colorSubmodule);
}
public override void AfterInitialize()
{
2025-02-07 10:49:26 -05:00
base.AfterInitialize();
Refresh();
if (track.trackPathSubmodule.pathNodeList.Count > 3)
{
track.trackPathSubmodule.ClosePath(track.trackPathSubmodule.isClosed);
}
}
}
2025-02-02 21:59:43 -05:00
public partial class PathNode
{
public override void Refresh()
{
Vector3 position = transformSubmodule.currentPosition;
Vector3 normal = Quaternion.Euler(transformSubmodule.currentEulerAngles) * Vector3.up;
float size = transformSubmodule.currentScale.x;
Color color = colorSubmodule.currentBaseColor;
2025-02-07 00:37:50 -05:00
transform.position = position;
transform.rotation = Quaternion.LookRotation(normal);
transform.localScale = Vector3.one * size;
node = new SplinePoint(position, Vector3.up, normal, size, color);
track.trackPathSubmodule.SetPathNode(this);
}
}
2025-02-02 21:59:43 -05:00
public partial class PathNode
{
public override void SaveBM()
{
matchedBM = new Beatmap.PathNode_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM);
2025-02-02 21:59:43 -05:00
}
}
namespace Beatmap
{
public class PathNode_BM : GameElement_BM
2025-02-02 21:59:43 -05:00
{
public PathNode_BM()
{
}
public PathNode_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement)
2025-02-02 21:59:43 -05:00
: base(elementName, elementGuid, tags, attachedElement)
{
2025-02-02 21:59:43 -05:00
}
public override void ExecuteBM()
{
matchedElement = PathNode.GenerateElement(elementName, elementGuid, tags, false,
2025-02-07 00:37:50 -05:00
GetElement(attachedElementGuid) as Track);
2025-02-02 21:59:43 -05:00
}
public override GameElement DuplicateBM(GameElement parent)
2025-02-02 21:59:43 -05:00
{
return PathNode.GenerateElement(elementName, elementGuid, tags, false, parent as Track);
2025-02-02 21:59:43 -05:00
}
}
}
}