public void OnInspectorGUI(GridGraph graph, GridGraphRule rule) { var target = rule as RuleElevationPenalty; if (target.curve == null || target.curve.length == 0) { target.curve = AnimationCurve.Linear(0, 0, 1, 1); } target.penaltyScale = EditorGUILayout.FloatField("Penalty Scale", target.penaltyScale); target.penaltyScale = Mathf.Max(target.penaltyScale, 1.0f); EditorGUILayout.LabelField("Elevation Range", ""); EditorGUI.BeginChangeCheck(); EditorGUI.indentLevel++; target.elevationRange.x = EditorGUILayout.FloatField("Min", target.elevationRange.x); target.elevationRange.y = EditorGUILayout.FloatField("Max", target.elevationRange.y); target.elevationRange.x = Mathf.Max(target.elevationRange.x, 0); target.elevationRange.y = Mathf.Max(target.elevationRange.y, target.elevationRange.x + 1.0f); EditorGUI.indentLevel--; if (EditorGUI.EndChangeCheck()) { lastChangedTime = Time.realtimeSinceStartup; } target.curve = EditorGUILayout.CurveField(target.curve, Color.red, new Rect(0, 0, 1, 1)); EditorGUILayout.HelpBox("Nodes will get a penalty between 0 and " + target.penaltyScale.ToString("0") + " depending on their elevation above the grid graph plane", MessageType.None); }
public void OnSceneGUI(GridGraph graph, GridGraphRule rule) { var target = rule as RuleElevationPenalty; // Draw some helpful gizmos in the scene view for a few seconds whenever the settings change const float FullAlphaTime = 2.0f; const float FadeoutTime = 0.5f; float alpha = Mathf.SmoothStep(1, 0, (Time.realtimeSinceStartup - lastChangedTime - FullAlphaTime) / FadeoutTime); if (alpha <= 0) { return; } var currentTransform = graph.transform * Matrix4x4.Scale(new Vector3(graph.width, 1, graph.depth)); Handles.matrix = currentTransform.matrix; var zTest = Handles.zTest; Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual; Handles.color = GizmoColorMin * new Color(1.0f, 1.0f, 1.0f, alpha); Handles.DrawAAConvexPolygon(new Vector3[] { new Vector3(0, target.elevationRange.x, 0), new Vector3(1, target.elevationRange.x, 0), new Vector3(1, target.elevationRange.x, 1), new Vector3(0, target.elevationRange.x, 1) }); Handles.color = GizmoColorMax * new Color(1.0f, 1.0f, 1.0f, alpha); Handles.DrawAAConvexPolygon(new Vector3[] { new Vector3(0, target.elevationRange.y, 0), new Vector3(1, target.elevationRange.y, 0), new Vector3(1, target.elevationRange.y, 1), new Vector3(0, target.elevationRange.y, 1) }); Handles.zTest = zTest; Handles.matrix = Matrix4x4.identity; // Repaint the scene view until the alpha goes to zero SceneView.RepaintAll(); }
IGridGraphRuleEditor GetEditor(GridGraphRule rule) { if (ruleEditors == null) { FindRuleEditors(); } IGridGraphRuleEditor ruleEditor; if (!ruleEditorInstances.TryGetValue(rule, out ruleEditor)) { if (ruleEditors.ContainsKey(rule.GetType())) { ruleEditor = ruleEditorInstances[rule] = (IGridGraphRuleEditor)System.Activator.CreateInstance(ruleEditors[rule.GetType()]); } } return(ruleEditor); }
public void OnInspectorGUI(GridGraph graph, GridGraphRule rule) { var target = rule as RuleAnglePenalty; if (target.curve == null || target.curve.length == 0) { target.curve = AnimationCurve.Linear(0, 0, 90, 1); } target.penaltyScale = EditorGUILayout.FloatField("Penalty Scale", target.penaltyScale); if (target.penaltyScale < 1) { target.penaltyScale = 1; } target.curve = EditorGUILayout.CurveField(target.curve, Color.red, new Rect(0, 0, 90, 1)); EditorGUILayout.HelpBox("Nodes will get a penalty between 0 and " + target.penaltyScale.ToString("0") + " depending on the slope angle", MessageType.None); }
public void OnInspectorGUI(GridGraph graph, GridGraphRule rule) { var target = rule as RulePerLayerModifications; for (int i = 0; i < target.layerRules.Length; i++) { GUILayout.BeginHorizontal(); target.layerRules[i].layer = EditorGUILayout.LayerField((int)target.layerRules[i].layer); target.layerRules[i].action = (RulePerLayerModifications.RuleAction)EditorGUILayout.EnumPopup(target.layerRules[i].action); if (target.layerRules[i].action == RulePerLayerModifications.RuleAction.SetTag) { target.layerRules[i].tag = Pathfinding.Util.EditorGUILayoutHelper.TagField("", target.layerRules[i].tag, AstarPathEditor.EditTags); } else { EditorGUILayout.LabelField(""); } if (GUILayout.Button("", AstarPathEditor.astarSkin.FindStyle("SimpleDeleteButton"))) { var ls = target.layerRules.ToList(); ls.RemoveAt(i); target.layerRules = ls.ToArray(); } GUILayout.Space(5); GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); GUILayout.Space(32); if (GUILayout.Button("Add per layer rule", GUILayout.MaxWidth(160))) { var ls = target.layerRules.ToList(); ls.Add(new RulePerLayerModifications.PerLayerRule()); target.layerRules = ls.ToArray(); } GUILayout.EndHorizontal(); }
public void OnInspectorGUI(GridGraph graph, GridGraphRule rule) { var target = rule as RuleTexture; target.texture = GraphEditor.ObjectField(new GUIContent("Texture"), target.texture, typeof(Texture2D), false, true) as Texture2D; GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Generate Reference")) { SaveReferenceTexture(graph); EditorUtility.DisplayDialog("Reference texture saved", "A texture has been saved in which every pixel corresponds to one node. The red channel represents if a node is walkable or not. The green channel represents the (normalized) Y coordinate of the nodes.", "Ok"); } GUILayout.EndHorizontal(); if (target.texture != null) { string path = AssetDatabase.GetAssetPath(target.texture); if (path != "") { var importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer != null && !importer.isReadable) { if (GraphEditor.FixLabel("Texture is not readable")) { importer.isReadable = true; EditorUtility.SetDirty(importer); AssetDatabase.ImportAsset(path); } } } } target.scalingMode = (RuleTexture.ScalingMode)EditorGUILayout.EnumPopup("Scaling Mode", target.scalingMode); if (target.scalingMode == RuleTexture.ScalingMode.FixedScale) { EditorGUI.indentLevel++; target.nodesPerPixel = EditorGUILayout.FloatField("Nodes Per Pixel", target.nodesPerPixel); EditorGUI.indentLevel--; } for (int i = 0; i < 4; i++) { char channelName = "RGBA"[i]; target.channels[i] = (RuleTexture.ChannelUse)EditorGUILayout.Popup("" + channelName, (int)target.channels[i], ChannelUseNames); if (target.channels[i] != RuleTexture.ChannelUse.None) { EditorGUI.indentLevel++; if (target.channels[i] != RuleTexture.ChannelUse.Walkable) { target.channelScales[i] = EditorGUILayout.FloatField("Scale", target.channelScales[i]); } string help = ""; switch (target.channels[i]) { case RuleTexture.ChannelUse.Penalty: help = "Penalty goes from 0 to " + target.channelScales[i].ToString("0") + " depending on the " + channelName + " channel value"; break; case RuleTexture.ChannelUse.Position: help = "Nodes will have their Y coordinate set to a value between 0 and " + target.channelScales[i].ToString("0") + " depending on the " + channelName + " channel"; if (graph.collision.heightCheck) { EditorGUILayout.HelpBox("Height testing is enabled but the node positions will be overwritten by the texture data. You should disable either height testing or this feature.", MessageType.Error); } break; case RuleTexture.ChannelUse.WalkablePenalty: help = "If the " + channelName + " channel is 0, the node is made unwalkable. Otherwise the penalty goes from 0 to " + target.channelScales[i].ToString("0") + " depending on the " + channelName + " channel value"; break; case RuleTexture.ChannelUse.Walkable: help = "If the " + channelName + " channel is 0, the node is made unwalkable."; break; } EditorGUILayout.HelpBox(help, MessageType.None); if ((target.channels[i] == RuleTexture.ChannelUse.Penalty || target.channels[i] == RuleTexture.ChannelUse.WalkablePenalty) && target.channelScales[i] < 0) { EditorGUILayout.HelpBox("Negative penalties are not supported. You can instead raise the penalty of other nodes.", MessageType.Error); } EditorGUI.indentLevel--; } } }
public void OnSceneGUI(GridGraph graph, GridGraphRule rule) { }
public void RemoveRule(GridGraphRule rule) { rules.Remove(rule); lastHash = -1; }
public void AddRule(GridGraphRule rule) { rules.Add(rule); lastHash = -1; }