rabidus-test/Assets/BNG Framework/Editor/GrabPointTriggerEditor.cs

38 lines
987 B
C#
Raw Normal View History

2023-07-24 16:38:13 +03:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace BNG {
[CustomEditor(typeof(GrabPointTrigger))]
[CanEditMultipleObjects]
public class GrabPointTriggerEditor : Editor {
GrabPointTrigger grabTrigger;
public override void OnInspectorGUI() {
base.OnInspectorGUI();
grabTrigger = (GrabPointTrigger)target;
if (grabTrigger.GrabObject != null && GUILayout.Button("Populate Grab Points from " + grabTrigger.GrabObject.transform.name)) {
AutoPopulateGrabPoints();
}
}
public void AutoPopulateGrabPoints() {
if (grabTrigger.GrabObject) {
var newPoints = grabTrigger.GrabObject.GetComponentsInChildren<GrabPoint>().ToList();
if(newPoints != null) {
grabTrigger.GrabPoints = newPoints;
}
}
}
}
}