2024-04-28 14:41:33 -07:00

61 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion {
public class DoorwayConnectionSisterChain : MonoBehaviour {
public Doorway[] chain;
public bool loop = true;
[ContextMenu("Create Chain")]
public void CreateChain(){
if (chain == null) return;
if (chain.Length <= 1) return;
for(var i = 0; i < chain.Length; ++i){
var current = chain[i];
var list = new List<Doorway>();
// add prev
if (i > 0 || loop) {
var prev = chain[((i - 1) + chain.Length) % chain.Length];
list.Add(prev);
}
if (i < chain.Length - 1 || loop){
var next = chain[((i + 1) + chain.Length) % chain.Length];
list.Add(next);
}
var script = current.GetComponent<DoorwayConnectionSisterRuleInfo>();
if (script == null) {
script = current.gameObject.AddComponent<DoorwayConnectionSisterRuleInfo>();
}
script.sisters = list.ToArray();
}
}
public void OnDrawGizmosSelected(){
if (chain == null) return;
if (chain.Length <= 1) return;
for(var i = 0; i < chain.Length; ++i){
if (!loop && i == chain.Length - 1) continue;
var current = chain[i];
var next = chain[(i + 1) % chain.Length];
var color = new Color((float)i / chain.Length, 1f, 1f);
Gizmos.color = color;
Gizmos.DrawLine(current.transform.position, next.transform.position);
}
}
}
}