using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Colosseum.AI;
using Colosseum.AI.BehaviorActions.Conditions;
using Colosseum.Enemy;
using Colosseum.Skills;
using UnityEditor;
using UnityEngine;
namespace Colosseum.Editor
{
///
/// 드로그 Behavior Graph authoring 자산을 현재 BT 우선순위 구조로 재생성합니다.
/// Check 노드는 ConditionalGuardAction + Condition 조합으로 구현됩니다.
///
public static class RebuildDrogBehaviorAuthoringGraph
{
private const string GraphAssetPath = "Assets/_Game/AI/BT_Drog.asset";
private const string DefaultPunishPatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_밟기.asset";
private const string DefaultSignaturePatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_집행.asset";
private const string DefaultMobilityPatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_도약.asset";
private const string DefaultSecondaryPatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_연타2.asset";
private const string DefaultComboPatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_연타3-강타.asset";
private const string DefaultPrimaryPatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_연타1.asset";
private const string DefaultPressurePatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_연타4-발구르기.asset";
private const string DefaultUtilityPatternPath = "Assets/_Game/Data/Patterns/Data_Pattern_Drog_투척.asset";
private const string DefaultPhase3TransitionSkillPath = "Assets/_Game/Data/Skills/Data_Skill_Drog_포효.asset";
private const float DefaultDownedTargetSearchRadius = 6f;
private const float DefaultLeapTargetMinDistance = 8f;
private const float DefaultThrowTargetMinDistance = 5f;
private const float DefaultPrimaryBranchAttackRange = 3f;
private const float DefaultTargetSearchRange = 20f;
private const float DefaultThrowAvailabilityDelay = 4f;
private const float DefaultPhaseTransitionLockDuration = 1.25f;
private const float DefaultPhase3SignatureDelay = 0.25f;
private const float DefaultPhase2EnterHealthPercent = 75f;
private const float DefaultPhase3EnterHealthPercent = 40f;
[MenuItem("Tools/Colosseum/Rebuild Drog Behavior Authoring Graph")]
private static void Rebuild()
{
UnityEngine.Object graphAsset = AssetDatabase.LoadMainAssetAtPath(GraphAssetPath);
if (graphAsset == null)
{
// 에셋이 없으면 기존 에셋 경로의 타입을 리플렉션으로 찾아 생성합니다.
// BehaviorAuthoringGraph는 Unity.Behavior.Editor 어셈블리에 있습니다.
Type authoringGraphType = null;
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
authoringGraphType = assembly.GetType("Unity.Behavior.Authoring.BehaviorAuthoringGraph");
if (authoringGraphType != null)
break;
}
if (authoringGraphType == null)
{
Debug.LogError("[DrogBTRebuild] BehaviorAuthoringGraph 타입을 모든 어셈블리에서 찾지 못했습니다.");
return;
}
graphAsset = ScriptableObject.CreateInstance(authoringGraphType);
if (graphAsset == null)
{
Debug.LogError("[DrogBTRebuild] BehaviorAuthoringGraph 인스턴스를 생성할 수 없습니다.");
return;
}
AssetDatabase.CreateAsset(graphAsset, GraphAssetPath);
AssetDatabase.SaveAssets();
Debug.Log("[DrogBTRebuild] 새 그래프 자산을 생성했습니다.");
}
try
{
Type authoringGraphType = graphAsset.GetType();
Assembly authoringAssembly = authoringGraphType.Assembly;
Assembly runtimeAssembly = typeof(Unity.Behavior.BehaviorGraph).Assembly;
// 기본 리플렉션 메서드
MethodInfo createNodeMethod = authoringGraphType.BaseType?.GetMethod("CreateNode", BindingFlags.Instance | BindingFlags.Public);
MethodInfo connectEdgeMethod = authoringGraphType.BaseType?.GetMethod("ConnectEdge", BindingFlags.Instance | BindingFlags.Public);
MethodInfo createNodePortsMethod = authoringGraphType.BaseType?.GetMethod("CreateNodePortsForNode", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
MethodInfo buildRuntimeGraphMethod = authoringGraphType.GetMethod("BuildRuntimeGraph", BindingFlags.Instance | BindingFlags.Public);
MethodInfo saveAssetMethod = authoringGraphType.BaseType?.GetMethod("SaveAsset", BindingFlags.Instance | BindingFlags.Public);
MethodInfo setAssetDirtyMethod = authoringGraphType.BaseType?.GetMethod("SetAssetDirty", BindingFlags.Instance | BindingFlags.Public);
MethodInfo getNodeInfoMethod = authoringAssembly.GetType("Unity.Behavior.NodeRegistry", true)
?.GetMethod("GetInfo", BindingFlags.Static | BindingFlags.NonPublic);
if (createNodeMethod == null || connectEdgeMethod == null || buildRuntimeGraphMethod == null || saveAssetMethod == null || setAssetDirtyMethod == null || getNodeInfoMethod == null)
{
Debug.LogError("[DrogBTRebuild] Behavior Authoring 리플렉션 메서드를 찾지 못했습니다.");
return;
}
// ConditionalGuard 리플렉션 타입 (internal)
Type conditionalGuardType = runtimeAssembly.GetType("Unity.Behavior.ConditionalGuardAction");
Type conditionUtilityType = authoringAssembly.GetType("Unity.Behavior.ConditionUtility");
Type conditionModelType = authoringAssembly.GetType("Unity.Behavior.ConditionModel");
Type graphNodeModelType = authoringAssembly.GetType("Unity.Behavior.BehaviorGraphNodeModel");
Type conditionInfoType = authoringAssembly.GetType("Unity.Behavior.ConditionInfo");
if (conditionalGuardType == null) { Debug.LogError("[DrogBTRebuild] ConditionalGuardAction 타입을 찾지 못했습니다."); return; }
if (conditionUtilityType == null) { Debug.LogError("[DrogBTRebuild] ConditionUtility 타입을 찾지 못했습니다."); return; }
if (conditionModelType == null) { Debug.LogError("[DrogBTRebuild] ConditionModel 타입을 찾지 못했습니다."); return; }
if (graphNodeModelType == null) { Debug.LogError("[DrogBTRebuild] BehaviorGraphNodeModel 타입을 찾지 못했습니다."); return; }
if (conditionInfoType == null)
{
Debug.LogError("[DrogBTRebuild] ConditionInfo 타입을 찾지 못했습니다.");
return;
}
Type branchCompositeType = runtimeAssembly.GetType("Unity.Behavior.BranchingConditionComposite");
if (branchCompositeType == null)
{
Debug.LogError("[DrogBTRebuild] BranchingConditionComposite 타입을 찾지 못했습니다.");
return;
}
// SetField(string, VariableModel, Type) — 제네릭 버전과 구분하기 위해 파라미터 수로 필터링
MethodInfo setFieldMethod = conditionModelType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
.FirstOrDefault(m => m.Name == "SetField" && !m.IsGenericMethod && m.GetParameters().Length == 3);
// SetField(string, T) — BehaviorGraphNodeModel 기반 클래스에서 조회 (ConditionModel과 Action 노드 모두 사용)
MethodInfo setFieldValueMethod = graphNodeModelType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
.FirstOrDefault(m => m.Name == "SetField" && m.IsGenericMethod && m.GetParameters().Length == 2);
if (setFieldMethod == null)
{
Debug.LogError("[DrogBTRebuild] ConditionModel.SetField 메서드를 찾지 못했습니다.");
return;
}
if (setFieldValueMethod == null)
{
Debug.LogError("[DrogBTRebuild] SetField 제네릭 메서드를 찾지 못했습니다.");
return;
}
// 기존 에셋의 서브에셋(BehaviorGraph 등)에서 깨진 managed references 클리어
Type behaviorGraphType = typeof(Unity.Behavior.BehaviorGraph);
UnityEngine.Object[] subAssets = AssetDatabase.LoadAllAssetsAtPath(GraphAssetPath);
foreach (var subAsset in subAssets)
{
if (subAsset != null && subAsset.GetType() == behaviorGraphType)
{
UnityEditor.SerializationUtility.ClearAllManagedReferencesWithMissingTypes(subAsset);
EditorUtility.SetDirty(subAsset);
}
}
// AuthoringGraph 자체에서도 깨진 references 클리어
UnityEditor.SerializationUtility.ClearAllManagedReferencesWithMissingTypes(graphAsset);
// 노드 클리어 — 전체 타입 계층에서 필드 찾기
FieldInfo nodesField = FindFieldInHierarchy(authoringGraphType, "m_RootNodes");
if (nodesField == null)
{
Debug.LogError("[DrogBTRebuild] m_RootNodes 필드를 타입 계층 전체에서 찾지 못했습니다.");
return;
}
nodesField.SetValue(graphAsset, Activator.CreateInstance(nodesField.FieldType));
FieldInfo nodesListField = FindFieldInHierarchy(authoringGraphType, "m_Nodes");
if (nodesListField != null)
nodesListField.SetValue(graphAsset, Activator.CreateInstance(nodesListField.FieldType));
FieldInfo nodeModelsInfoField = FindFieldInHierarchy(authoringGraphType, "m_NodeModelsInfo");
if (nodeModelsInfoField != null)
nodeModelsInfoField.SetValue(graphAsset, Activator.CreateInstance(nodeModelsInfoField.FieldType));
FieldInfo runtimeGraphField = FindFieldInHierarchy(authoringGraphType, "m_RuntimeGraph");
if (runtimeGraphField != null)
runtimeGraphField.SetValue(graphAsset, null);
// 클리어 후 에셋을 저장하고 다시 로드하여 잔류 참조가 메모리에 남지 않게 합니다.
EditorUtility.SetDirty(graphAsset);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
// 에셋을 다시 로드 (직렬화된 상태에서 로드하여 클리어 상태 확보)
graphAsset = AssetDatabase.LoadMainAssetAtPath(GraphAssetPath);
if (graphAsset == null)
{
Debug.LogError("[DrogBTRebuild] 에셋 재로드 실패.");
return;
}
authoringGraphType = graphAsset.GetType();
object targetVariable = EnsureBlackboardVariable("Target", null);
if (targetVariable == null)
{
Debug.LogError("[DrogBTRebuild] Target 블랙보드 변수를 찾지 못했습니다.");
return;
}
// 구조 노드
object startNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, runtimeAssembly.GetType("Unity.Behavior.Start", true), new Vector2(-1320f, -920f));
object repeatNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, runtimeAssembly.GetType("Unity.Behavior.RepeaterModifier", true), new Vector2(-1320f, -720f));
// ── 드로그 패턴과 판단 수치는 노드 로컬 값으로 두고, Target만 블랙보드로 공유합니다. ──
RemoveBlackboardVariables(
"PunishPattern",
"SignaturePattern",
"MobilityPattern",
"ComboPattern",
"PrimaryPattern",
"UtilityPattern",
"PunishSearchRadius",
"MobilityTriggerDistance",
"UtilityTriggerDistance",
"PrimaryAttackRange",
"Phase2HealthPercent",
"Phase3HealthPercent",
"SightRange",
"AttackRange",
"MoveSpeed");
BossPatternData punishPattern = LoadRequiredAsset(DefaultPunishPatternPath, "밟기 패턴");
BossPatternData signaturePattern = LoadRequiredAsset(DefaultSignaturePatternPath, "집행 개시 패턴");
BossPatternData mobilityPattern = LoadRequiredAsset(DefaultMobilityPatternPath, "점프 패턴");
BossPatternData secondaryPattern = LoadRequiredAsset(DefaultSecondaryPatternPath, "연타2 패턴");
BossPatternData comboPattern = LoadRequiredAsset(DefaultComboPatternPath, "연타3-강타 패턴");
BossPatternData primaryPattern = LoadRequiredAsset(DefaultPrimaryPatternPath, "기본 근접 패턴");
BossPatternData pressurePattern = LoadRequiredAsset(DefaultPressurePatternPath, "연타4-발구르기 패턴");
BossPatternData utilityPattern = LoadRequiredAsset(DefaultUtilityPatternPath, "투척 패턴");
SkillData phase3TransitionSkill = LoadRequiredAsset(DefaultPhase3TransitionSkillPath, "Phase 3 포효 스킬");
if (punishPattern == null || signaturePattern == null || mobilityPattern == null ||
secondaryPattern == null || comboPattern == null || primaryPattern == null || pressurePattern == null ||
utilityPattern == null || phase3TransitionSkill == null)
{
Debug.LogError("[DrogBTRebuild] 프리팹에서 필수 패턴 에셋을 읽지 못했습니다.");
return;
}
// ── 계단식 우선순위 체인 ──
// 설계안 우선순위: 밟기 > 집행 개시 > 조합 > 도약 > 기본 루프 > 유틸리티
// 각 Branch는 조건만 판정하고, 실제 대상 선택/검증/실행은 Sequence 내부 노드로 드러냅니다.
// 마지막까지 모든 조건이 false이면 Chase (fallback)
//
// 연결 흐름: Branch.True → FloatingPort(True).InputPort → FloatingPort(True).OutputPort → Action.InputPort
// CreateNodePortsForNode를 호출하여 FloatingPortNodeModel을 자동 생성해야 합니다.
//
// 레이아웃 패턴 (사용자 조정 기준):
// Branch: (-800, y)
// True Floating: (-597, y + 110)
// False Floating: (-1011, y + 114)
// Action: (-598, y + 199)
const float branchX = -800f;
const float rootRefreshX = branchX - 540f;
const float mainSequenceX = branchX + 340f;
const float mainValidateX = branchX + 700f;
const float mainUseX = branchX + 1100f;
const float truePortOffsetX = 203f;
const float truePortOffsetY = 120f;
const float falsePortOffsetX = -211f;
const float falsePortOffsetY = 124f;
const float startY = -700f;
const float rootRefreshY = startY - 120f;
const float stepY = 620f;
const float nestedBranchOffsetY = 180f;
const float nestedActionOffsetY = 360f;
// 루프 시작마다 주 대상을 블랙보드에 동기화한 뒤 패턴 우선순위 체인으로 들어갑니다.
object rootRefreshNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(RefreshPrimaryTargetAction), new Vector2(rootRefreshX, rootRefreshY));
SetNodeFieldValue(rootRefreshNode, "SearchRange", DefaultTargetSearchRange, setFieldValueMethod);
// #1 Punish — 밟기 (전제 조건: 다운된 대상이 반경 이내에 있어야 함)
object downBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY));
AttachPatternReadyCondition(downBranch, punishPattern, authoringAssembly);
AttachConditionWithValue(downBranch, typeof(IsDownedTargetInRangeCondition), "SearchRadius", DefaultDownedTargetSearchRadius, authoringAssembly);
AttachPhaseConditionIfNeeded(downBranch, punishPattern, authoringAssembly);
SetBranchRequiresAll(downBranch, true);
object downSequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY));
object downSelectNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(SelectNearestDownedTargetAction), new Vector2(mainValidateX, startY));
SetNodeFieldValue(downSelectNode, "SearchRadius", DefaultDownedTargetSearchRadius, setFieldValueMethod);
LinkTarget(downSelectNode, targetVariable);
object downUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY));
SetNodeFieldValue(downUseNode, "Pattern", punishPattern, setFieldValueMethod);
LinkTarget(downUseNode, targetVariable);
ConnectChildren(graphAsset, connectEdgeMethod, downSequence, downSelectNode, downUseNode);
// #2 Signature — 집행 개시 (Sequence: 패턴 실행 → 결과 분기)
// signatureBranch.True → Sequence:
// Child 1: 현재 주 대상 검증
// Child 2: 집행개시 패턴 실행 (ChargeWait 포함)
// Child 3: Branch(차단 성공 여부) → 보스 경직 또는 범위 효과
object signatureBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY + stepY));
AttachPatternReadyCondition(signatureBranch, signaturePattern, authoringAssembly);
AttachPhaseConditionIfNeeded(signatureBranch, signaturePattern, authoringAssembly);
AttachConditionWithValue(signatureBranch, typeof(IsPhaseElapsedTimeAboveCondition), "Seconds", DefaultPhase3SignatureDelay, authoringAssembly);
SetBranchRequiresAll(signatureBranch, true);
// Sequence: 패턴 실행 → 결과 분기
object signatureSequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY + stepY));
object signatureValidateNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(ValidateTargetAction), new Vector2(mainValidateX, startY + stepY));
LinkTarget(signatureValidateNode, targetVariable);
// Child 2: 집행 패턴 실행
object signatureUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY + stepY));
SetNodeFieldValue(signatureUseNode, "Pattern", signaturePattern, setFieldValueMethod);
SetNodeFieldValue(signatureUseNode, "ContinueOnResolvedFailure", true, setFieldValueMethod);
LinkTarget(signatureUseNode, targetVariable);
// Child 3: 패턴 완료 시 결과 분기
// 패턴이 실패 결과로 끝나면 True → 보스 경직, 성공적으로 완수되면 False → 범위 효과 적용
object outcomeBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(mainUseX + 320f, startY + stepY));
AttachConditionWithValue(outcomeBranch, typeof(IsPatternExecutionResultCondition), "Result", BossPatternExecutionResult.Failed, authoringAssembly);
object staggerNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(BossStaggerAction), new Vector2(mainUseX + 520f, startY + stepY + nestedBranchOffsetY));
object failureEffectsNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(SignatureFailureEffectsAction), new Vector2(mainUseX + 520f, startY + stepY + nestedActionOffsetY));
// outcomeBranch True → 보스 경직 (패턴 실패 결과)
ConnectBranch(graphAsset, connectEdgeMethod, outcomeBranch, "True", staggerNode);
// outcomeBranch False → 실패 효과 (패턴 성공 완수)
ConnectBranch(graphAsset, connectEdgeMethod, outcomeBranch, "False", failureEffectsNode);
// Sequence에 자식 연결
ConnectChildren(graphAsset, connectEdgeMethod, signatureSequence, signatureValidateNode, signatureUseNode, outcomeBranch);
// 메인 체인: signatureBranch.True → Sequence
ConnectBranch(graphAsset, connectEdgeMethod, signatureBranch, "True", signatureSequence);
// #3 Combo — 연타3-강타
object comboBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY + stepY * 2));
AttachPatternReadyCondition(comboBranch, comboPattern, authoringAssembly);
AttachPhaseConditionIfNeeded(comboBranch, comboPattern, authoringAssembly);
SetBranchRequiresAll(comboBranch, true);
object comboSequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY + stepY * 2));
object comboValidateNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(ValidateTargetAction), new Vector2(mainValidateX, startY + stepY * 2));
LinkTarget(comboValidateNode, targetVariable);
object comboUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY + stepY * 2));
SetNodeFieldValue(comboUseNode, "Pattern", comboPattern, setFieldValueMethod);
LinkTarget(comboUseNode, targetVariable);
ConnectChildren(graphAsset, connectEdgeMethod, comboSequence, comboValidateNode, comboUseNode);
ConnectBranch(graphAsset, connectEdgeMethod, comboBranch, "True", comboSequence);
// #4 Mobility — 도약 (전제 조건: 지나치게 먼 대상이 존재해야 함)
object leapBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY + stepY * 3));
AttachPatternReadyCondition(leapBranch, mobilityPattern, authoringAssembly);
AttachConditionWithValue(leapBranch, typeof(IsTargetBeyondDistanceCondition), "MinDistance", DefaultLeapTargetMinDistance, authoringAssembly);
AttachPhaseConditionIfNeeded(leapBranch, mobilityPattern, authoringAssembly);
SetBranchRequiresAll(leapBranch, true);
object leapSequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY + stepY * 3));
object leapSelectNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(SelectTargetByDistanceAction), new Vector2(mainValidateX, startY + stepY * 3));
SetNodeFieldValue(leapSelectNode, "MinRange", DefaultLeapTargetMinDistance, setFieldValueMethod);
SetNodeFieldValue(leapSelectNode, "MaxRange", DefaultTargetSearchRange, setFieldValueMethod);
SetNodeFieldValue(leapSelectNode, "SelectionMode", DistanceTargetSelectionMode.Farthest, setFieldValueMethod);
LinkTarget(leapSelectNode, targetVariable);
object leapUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY + stepY * 3));
SetNodeFieldValue(leapUseNode, "Pattern", mobilityPattern, setFieldValueMethod);
LinkTarget(leapUseNode, targetVariable);
ConnectChildren(graphAsset, connectEdgeMethod, leapSequence, leapSelectNode, leapUseNode);
// #5 Primary — 연타1
object primaryBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY + stepY * 4));
object primaryRangeCondModel = AttachCondition(primaryBranch, typeof(IsTargetInAttackRangeCondition), authoringAssembly);
if (primaryRangeCondModel != null) setFieldMethod.Invoke(primaryRangeCondModel, new object[] { "Target", targetVariable, typeof(GameObject) });
if (primaryRangeCondModel != null) SetConditionFieldValue(primaryRangeCondModel, "AttackRange", DefaultPrimaryBranchAttackRange);
AttachPatternReadyCondition(primaryBranch, primaryPattern, authoringAssembly);
AttachPhaseConditionIfNeeded(primaryBranch, primaryPattern, authoringAssembly);
SetBranchRequiresAll(primaryBranch, true);
object primarySequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY + stepY * 4));
object primaryValidateNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(ValidateTargetAction), new Vector2(mainValidateX, startY + stepY * 4));
LinkTarget(primaryValidateNode, targetVariable);
object primaryUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY + stepY * 4));
SetNodeFieldValue(primaryUseNode, "Pattern", primaryPattern, setFieldValueMethod);
LinkTarget(primaryUseNode, targetVariable);
ConnectChildren(graphAsset, connectEdgeMethod, primarySequence, primaryValidateNode, primaryUseNode);
// #6 Secondary Basic — 연타2
object secondaryBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY + stepY * 5));
object secondaryRangeCondModel = AttachCondition(secondaryBranch, typeof(IsTargetInAttackRangeCondition), authoringAssembly);
if (secondaryRangeCondModel != null) setFieldMethod.Invoke(secondaryRangeCondModel, new object[] { "Target", targetVariable, typeof(GameObject) });
if (secondaryRangeCondModel != null) SetConditionFieldValue(secondaryRangeCondModel, "AttackRange", DefaultPrimaryBranchAttackRange);
AttachPatternReadyCondition(secondaryBranch, secondaryPattern, authoringAssembly);
AttachPhaseConditionIfNeeded(secondaryBranch, secondaryPattern, authoringAssembly);
SetBranchRequiresAll(secondaryBranch, true);
object secondarySequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY + stepY * 5));
object secondaryValidateNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(ValidateTargetAction), new Vector2(mainValidateX, startY + stepY * 5));
LinkTarget(secondaryValidateNode, targetVariable);
object secondaryUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY + stepY * 5));
SetNodeFieldValue(secondaryUseNode, "Pattern", secondaryPattern, setFieldValueMethod);
LinkTarget(secondaryUseNode, targetVariable);
ConnectChildren(graphAsset, connectEdgeMethod, secondarySequence, secondaryValidateNode, secondaryUseNode);
// #7 Pressure — 연타4-발구르기
object pressureBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY + stepY * 6));
object pressureRangeCondModel = AttachCondition(pressureBranch, typeof(IsTargetInAttackRangeCondition), authoringAssembly);
if (pressureRangeCondModel != null) setFieldMethod.Invoke(pressureRangeCondModel, new object[] { "Target", targetVariable, typeof(GameObject) });
if (pressureRangeCondModel != null) SetConditionFieldValue(pressureRangeCondModel, "AttackRange", DefaultPrimaryBranchAttackRange);
AttachPatternReadyCondition(pressureBranch, pressurePattern, authoringAssembly);
AttachPhaseConditionIfNeeded(pressureBranch, pressurePattern, authoringAssembly);
SetBranchRequiresAll(pressureBranch, true);
object pressureSequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY + stepY * 6));
object pressureValidateNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(ValidateTargetAction), new Vector2(mainValidateX, startY + stepY * 6));
LinkTarget(pressureValidateNode, targetVariable);
object pressureUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY + stepY * 6));
SetNodeFieldValue(pressureUseNode, "Pattern", pressurePattern, setFieldValueMethod);
LinkTarget(pressureUseNode, targetVariable);
ConnectChildren(graphAsset, connectEdgeMethod, pressureSequence, pressureValidateNode, pressureUseNode);
// #8 Utility — 유틸리티 (전제 조건: 원거리 대상이 존재해야 함)
object utilityBranch = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, branchCompositeType, new Vector2(branchX, startY + stepY * 7));
AttachPatternReadyCondition(utilityBranch, utilityPattern, authoringAssembly);
AttachConditionWithValue(utilityBranch, typeof(IsTargetBeyondDistanceCondition), "MinDistance", DefaultThrowTargetMinDistance, authoringAssembly);
AttachConditionWithValue(utilityBranch, typeof(IsPhaseElapsedTimeAboveCondition), "Seconds", DefaultThrowAvailabilityDelay, authoringAssembly);
AttachPhaseConditionIfNeeded(utilityBranch, utilityPattern, authoringAssembly);
SetBranchRequiresAll(utilityBranch, true);
object utilitySequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod,
runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true),
new Vector2(mainSequenceX, startY + stepY * 7));
object utilitySelectNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(SelectAlternateTargetByDistanceAction), new Vector2(mainValidateX, startY + stepY * 7));
SetNodeFieldValue(utilitySelectNode, "MinRange", DefaultThrowTargetMinDistance, setFieldValueMethod);
SetNodeFieldValue(utilitySelectNode, "MaxRange", DefaultTargetSearchRange, setFieldValueMethod);
LinkTarget(utilitySelectNode, targetVariable);
object utilityUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(UsePatternByRoleAction), new Vector2(mainUseX, startY + stepY * 7));
SetNodeFieldValue(utilityUseNode, "Pattern", utilityPattern, setFieldValueMethod);
LinkTarget(utilityUseNode, targetVariable);
ConnectChildren(graphAsset, connectEdgeMethod, utilitySequence, utilitySelectNode, utilityUseNode);
// #9 Chase — fallback (Branch 아님, Sequence 사용)
object chaseSequence = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, runtimeAssembly.GetType("Unity.Behavior.SequenceComposite", true), new Vector2(branchX, startY + stepY * 8));
object chaseRefreshNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(RefreshPrimaryTargetAction), new Vector2(branchX + 160f, startY + stepY * 8 + 80f));
SetNodeFieldValue(chaseRefreshNode, "SearchRange", DefaultTargetSearchRange, setFieldValueMethod);
object chaseHasTargetNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(ValidateTargetAction), new Vector2(branchX + 320f, startY + stepY * 8 + 80f));
object chaseUseNode = CreateNode(graphAsset, createNodeMethod, getNodeInfoMethod, typeof(ChaseTargetAction), new Vector2(branchX + 480f, startY + stepY * 8 + 80f));
SetNodeFieldValue(chaseUseNode, "StopDistance", DefaultPrimaryBranchAttackRange, setFieldValueMethod);
Connect(graphAsset, connectEdgeMethod, GetDefaultOutputPort(rootRefreshNode), GetDefaultInputPort(downBranch));
List