private void DrawnNodeWithLinks(PatrolGraphNode PatrolGraphNode) { if (!this.ProcessedPatrolGraphNodeBuffer.Contains(PatrolGraphNode)) { Handles.DrawWireDisc(PatrolGraphNode.WorldPosition, Vector3.up, 1); Handles.Label(PatrolGraphNode.WorldPosition + new Vector3(0, 1, 0), PatrolGraphNode.name, MyEditorStyles.LabelWhite); if (PatrolGraphNode.WorldRotationEnabled) { HandlesHelper.DrawArrow(PatrolGraphNode.WorldPosition, PatrolGraphNode.WorldPosition + (Quaternion.Euler(PatrolGraphNode.WorldRotation) * Vector3.forward), Color.yellow); } foreach (var patrolGraphNodeLink in PatrolGraphNode.Links) { Color linkColor = Color.black; if (patrolGraphNodeLink.AIMovementSpeed == AIMovementSpeedAttenuationFactor.WALK) { linkColor = Color.green; } else if (patrolGraphNodeLink.AIMovementSpeed == AIMovementSpeedAttenuationFactor.RUN) { linkColor = Color.red; } HandlesHelper.DrawArrow(PatrolGraphNode.WorldPosition, patrolGraphNodeLink.PatrolGraphNode.WorldPosition, linkColor); } this.ProcessedPatrolGraphNodeBuffer.Add(PatrolGraphNode); foreach (var patrolGraphNodeLink in PatrolGraphNode.Links) { DrawnNodeWithLinks(patrolGraphNodeLink.PatrolGraphNode); } } }
public static void Draw(object drawableObject, Transform objectTransform, CommonGameConfigurations CommonGameConfigurations) { if (drawableObject.GetType().GetCustomAttribute <SceneHandleDrawAttribute>(true) != null) { var fields = ReflectionHelper.GetAllFields(drawableObject.GetType()); foreach (var field in fields) { var DrawConfigurationAttribute = field.GetCustomAttribute <DrawConfigurationAttribute>() as DrawConfigurationAttribute; if (DrawConfigurationAttribute != null) { var configurationAsset = CommonGameConfigurations.GetConfiguration(DrawConfigurationAttribute.ConfigurationType); if (configurationAsset != null) { configurationAsset.GetEntryTry((Enum)field.GetValue(drawableObject), out var configurationDataObject); if (configurationDataObject != null) { Draw(configurationDataObject, objectTransform, CommonGameConfigurations); } } } var DrawNestedAttribute = field.GetCustomAttribute <DrawNestedAttribute>() as DrawNestedAttribute; if (DrawNestedAttribute != null) { Draw(field.GetValue(drawableObject), objectTransform, CommonGameConfigurations); } var AbstractSceneHandleAttributes = field.GetCustomAttributes <AbstractSceneHandleAttribute>(true); if (AbstractSceneHandleAttributes != null) { foreach (var AbstractSceneHandleAttribute in AbstractSceneHandleAttributes) { if (AbstractSceneHandleAttribute.GetType() == typeof(WireArcAttribute)) { var WireArcAttribute = (WireArcAttribute)AbstractSceneHandleAttribute; var semiAngle = GetFieldValue <float>(drawableObject, field); SetupColors(WireArcAttribute.GetColor()); DrawLabel(field.Name, WireArcAttribute.Radius, objectTransform); Handles.DrawWireArc(objectTransform.position, Vector3.up, objectTransform.forward, semiAngle, WireArcAttribute.Radius); Handles.DrawWireArc(objectTransform.position, Vector3.up, objectTransform.forward, -semiAngle, WireArcAttribute.Radius); } else if (AbstractSceneHandleAttribute.GetType() == typeof(WireCircleAttribute)) { var WireCircleAttribute = (WireCircleAttribute)AbstractSceneHandleAttribute; var radius = GetFieldValue <float>(drawableObject, field); SetupColors(WireCircleAttribute.GetColor()); DrawLabel(field.Name, radius, objectTransform); DrawLabel(field.Name, radius, objectTransform); Handles.DrawWireDisc(objectTransform.position, objectTransform.up, radius); } else if (AbstractSceneHandleAttribute.GetType() == typeof(WireCircleWorldAttribute)) { var WireCircleWorldAttribute = (WireCircleWorldAttribute)AbstractSceneHandleAttribute; Vector3 worldPositionCenter = Vector3.zero; float radius; if (WireCircleWorldAttribute.UseTransform) { worldPositionCenter = objectTransform.position; } else { worldPositionCenter = GetPositionFromObject(drawableObject.GetType().GetField(WireCircleWorldAttribute.PositionFieldName).GetValue(drawableObject)); } if (!string.IsNullOrEmpty(WireCircleWorldAttribute.RadiusFieldName)) { radius = (float)drawableObject.GetType().GetField(WireCircleWorldAttribute.RadiusFieldName).GetValue(drawableObject); } else { radius = WireCircleWorldAttribute.Radius; } SetupColors(WireCircleWorldAttribute.GetColor()); DrawLabel(field.Name, radius, worldPositionCenter); DrawLabel(field.Name, radius, worldPositionCenter); Handles.DrawWireDisc(worldPositionCenter, Vector3.up, radius); } else if (AbstractSceneHandleAttribute.GetType() == typeof(WireBoxAttribute)) { var WireBoxAttribute = (WireBoxAttribute)AbstractSceneHandleAttribute; var center = (Vector3)drawableObject.GetType().GetField(WireBoxAttribute.CenterFieldName).GetValue(drawableObject); var size = (Vector3)drawableObject.GetType().GetField(WireBoxAttribute.SizeFieldName).GetValue(drawableObject); SetupColors(WireBoxAttribute.GetColor()); HandlesHelper.DrawBox(center, size, objectTransform, WireBoxAttribute.GetColor(), drawableObject.GetType().Name, MyEditorStyles.SceneDrawDynamicLabelStyle); } else if (AbstractSceneHandleAttribute.GetType() == typeof(WireFrustumAttribute)) { var WireFrustumAttribute = (WireFrustumAttribute)AbstractSceneHandleAttribute; var frustum = (FrustumV2)field.GetValue(drawableObject); SetupColors(WireFrustumAttribute.GetColor()); DrawFrustum(frustum, objectTransform, false); } else if (AbstractSceneHandleAttribute.GetType() == typeof(WireRoundedFrustumAttribute)) { var WireRoundedFrustumAttribute = (WireRoundedFrustumAttribute)AbstractSceneHandleAttribute; var frustum = (FrustumV2)field.GetValue(drawableObject); SetupColors(WireRoundedFrustumAttribute.GetColor()); DrawFrustum(frustum, objectTransform, true); } else if (AbstractSceneHandleAttribute.GetType() == typeof(WireDirectionalLineAttribute)) { var WireLineAttribute = (WireDirectionalLineAttribute)AbstractSceneHandleAttribute; var lineLength = (float)field.GetValue(drawableObject); SetupColors(WireLineAttribute.GetColor()); Handles.DrawLine(objectTransform.transform.position, objectTransform.transform.position + new Vector3(WireLineAttribute.dX, WireLineAttribute.dY, WireLineAttribute.dZ) * lineLength); } else if (AbstractSceneHandleAttribute.GetType() == typeof(WireArrowAttribute)) { var WireArrowAttribute = (WireArrowAttribute)AbstractSceneHandleAttribute; Vector3 Source = WireArrowAttribute.Source; Vector3 Target = WireArrowAttribute.Target; if (!string.IsNullOrEmpty(WireArrowAttribute.SourceFieldName)) { Source = GetPositionFromObject(drawableObject.GetType().GetField(WireArrowAttribute.SourceFieldName).GetValue(drawableObject)); } if (!string.IsNullOrEmpty(WireArrowAttribute.TargetFieldName)) { Target = GetPositionFromObject(drawableObject.GetType().GetField(WireArrowAttribute.TargetFieldName).GetValue(drawableObject)); } SetupColors(WireArrowAttribute.GetColor()); HandlesHelper.DrawArrow(Source, Target, WireArrowAttribute.GetColor(), WireArrowAttribute.ArrowSemiAngle, WireArrowAttribute.ArrowLength); } } } } } }