public void RunModifiers(Seeker.ModifierPass pass, Path p) { if (pass == Seeker.ModifierPass.PreProcess && this.preProcessPath != null) { this.preProcessPath(p); } else if (pass == Seeker.ModifierPass.PostProcess && this.postProcessPath != null) { this.postProcessPath(p); } for (int i = 0; i < this.modifiers.Count; i++) { MonoModifier monoModifier = this.modifiers[i] as MonoModifier; if (!(monoModifier != null) || monoModifier.enabled) { if (pass == Seeker.ModifierPass.PreProcess) { this.modifiers[i].PreProcess(p); } else if (pass == Seeker.ModifierPass.PostProcess) { this.modifiers[i].Apply(p); } } } }
public override void OnInspectorGUI() { DrawDefaultInspector(); Seeker script = target as Seeker; #if !UNITY_LE_4_3 Undo.RecordObject(script, "modify settings on Seeker"); #endif EditorGUILayoutx.SetTagField(new GUIContent("Valid Tags"), ref script.traversableTags); #if !ASTAR_NoTagPenalty EditorGUI.indentLevel = 0; tagPenaltiesOpen = EditorGUILayout.Foldout(tagPenaltiesOpen, new GUIContent("Tag Penalties", "Penalties for each tag")); if (tagPenaltiesOpen) { EditorGUI.indentLevel = 2; string[] tagNames = AstarPath.FindTagNames(); for (int i = 0; i < script.tagPenalties.Length; i++) { int tmp = EditorGUILayout.IntField((i < tagNames.Length ? tagNames[i] : "Tag " + i), (int)script.tagPenalties[i]); if (tmp < 0) { tmp = 0; } script.tagPenalties[i] = tmp; } if (GUILayout.Button("Edit Tag Names...")) { AstarPathEditor.EditTags(); } } EditorGUI.indentLevel = 1; #endif //Do some loading and checking if (!AstarPathEditor.stylesLoaded) { if (!AstarPathEditor.LoadStyles()) { if (AstarPathEditor.upArrow == null) { AstarPathEditor.upArrow = GUI.skin.FindStyle("Button"); AstarPathEditor.downArrow = AstarPathEditor.upArrow; } } else { AstarPathEditor.stylesLoaded = true; } } GUIStyle helpBox = GUI.skin.GetStyle("helpBox"); if (mods == null) { mods = new List <IPathModifier>(script.GetComponents <MonoModifier>() as IPathModifier[]); } else { mods.Clear(); mods.AddRange(script.GetComponents <MonoModifier>() as IPathModifier[]); } mods.Add(script.startEndModifier as IPathModifier); bool changed = true; while (changed) { changed = false; for (int i = 0; i < mods.Count - 1; i++) { if (mods[i].Priority < mods[i + 1].Priority) { IPathModifier tmp = mods[i + 1]; mods[i + 1] = mods[i]; mods[i] = tmp; changed = true; } } } for (int i = 0; i < mods.Count; i++) { if (mods.Count - i != mods[i].Priority) { mods[i].Priority = mods.Count - i; GUI.changed = true; EditorUtility.SetDirty(target); } } bool modifierErrors = false; IPathModifier prevMod = mods[0]; //Loops through all modifiers and checks if there are any errors in converting output between modifiers for (int i = 1; i < mods.Count; i++) { MonoModifier monoMod = mods[i] as MonoModifier; if ((prevMod as MonoModifier) != null && !(prevMod as MonoModifier).enabled) { if (monoMod == null || monoMod.enabled) { prevMod = mods[i]; } continue; } if ((monoMod == null || monoMod.enabled) && prevMod != mods[i] && !ModifierConverter.CanConvert(prevMod.output, mods[i].input)) { modifierErrors = true; } if (monoMod == null || monoMod.enabled) { prevMod = mods[i]; } } EditorGUI.indentLevel = 0; #if UNITY_LE_4_3 modifiersOpen = EditorGUILayout.Foldout(modifiersOpen, "Modifiers Priorities" + (modifierErrors ? " - Errors in modifiers!" : ""), EditorStyles.foldout); #else modifiersOpen = EditorGUILayout.Foldout(modifiersOpen, "Modifiers Priorities" + (modifierErrors ? " - Errors in modifiers!" : "")); #endif #if UNITY_LE_4_3 EditorGUI.indentLevel = 1; #endif if (modifiersOpen) { #if UNITY_LE_4_3 EditorGUI.indentLevel += 2; #endif //GUILayout.BeginHorizontal (); //GUILayout.Space (28); if (GUILayout.Button("Modifiers attached to this gameObject are listed here.\nModifiers with a higher priority (higher up in the list) will be executed first.\nClick here for more info", helpBox)) { Application.OpenURL(AstarPathEditor.GetURL("modifiers")); } EditorGUILayout.HelpBox("Original or All can be converted to anything\n" + "NodePath can be converted to VectorPath\n" + "VectorPath can only be used as VectorPath\n" + "Vector takes both VectorPath and StrictVectorPath\n" + "Strict... can be converted to the non-strict variant", MessageType.None); //GUILayout.EndHorizontal (); prevMod = mods[0]; for (int i = 0; i < mods.Count; i++) { //EditorGUILayout.LabelField (mods[i].GetType ().ToString (),mods[i].Priority.ToString ()); MonoModifier monoMod = mods[i] as MonoModifier; Color prevCol = GUI.color; if (monoMod != null && !monoMod.enabled) { GUI.color *= new Color(1, 1, 1, 0.5F); } GUILayout.BeginVertical(GUI.skin.box); if (i > 0) { if ((prevMod as MonoModifier) != null && !(prevMod as MonoModifier).enabled) { prevMod = mods[i]; } else { if ((monoMod == null || monoMod.enabled) && !ModifierConverter.CanConvert(prevMod.output, mods[i].input)) { //GUILayout.BeginHorizontal (); //GUILayout.Space (28); GUIUtilityx.SetColor(new Color(0.8F, 0, 0)); GUILayout.Label("Cannot convert " + prevMod.GetType().Name + "'s output to " + mods[i].GetType().Name + "'s input\nRearranging the modifiers might help", EditorStyles.whiteMiniLabel); GUIUtilityx.ResetColor(); //GUILayout.EndHorizontal (); } if (monoMod == null || monoMod.enabled) { prevMod = mods[i]; } } } GUILayout.Label("Input: " + mods[i].input, EditorStyles.wordWrappedMiniLabel); int newPrio = EditorGUILayoutx.UpDownArrows(new GUIContent(ObjectNames.NicifyVariableName(mods[i].GetType().ToString())), mods[i].Priority, EditorStyles.label, AstarPathEditor.upArrow, AstarPathEditor.downArrow); GUILayout.Label("Output: " + mods[i].output, EditorStyles.wordWrappedMiniLabel); GUILayout.EndVertical(); int diff = newPrio - mods[i].Priority; if (i > 0 && diff > 0) { mods[i - 1].Priority = mods[i].Priority; } else if (i < mods.Count - 1 && diff < 0) { mods[i + 1].Priority = mods[i].Priority; } mods[i].Priority = newPrio; GUI.color = prevCol; } #if UNITY_LE_4_3 EditorGUI.indentLevel -= 2; #endif } }
public void RunModifiers(Seeker.ModifierPass pass, Path p) { bool flag = true; while (flag) { flag = false; for (int i = 0; i < this.modifiers.Count - 1; i++) { if (this.modifiers[i].Priority < this.modifiers[i + 1].Priority) { IPathModifier value = this.modifiers[i]; this.modifiers[i] = this.modifiers[i + 1]; this.modifiers[i + 1] = value; flag = true; } } } switch (pass) { case Seeker.ModifierPass.PreProcess: if (this.preProcessPath != null) { this.preProcessPath(p); } break; case Seeker.ModifierPass.PostProcessOriginal: if (this.postProcessOriginalPath != null) { this.postProcessOriginalPath(p); } break; case Seeker.ModifierPass.PostProcess: if (this.postProcessPath != null) { this.postProcessPath(p); } break; } if (this.modifiers.Count == 0) { return; } ModifierData modifierData = ModifierData.All; IPathModifier pathModifier = this.modifiers[0]; for (int j = 0; j < this.modifiers.Count; j++) { MonoModifier monoModifier = this.modifiers[j] as MonoModifier; if (!(monoModifier != null) || monoModifier.enabled) { switch (pass) { case Seeker.ModifierPass.PreProcess: this.modifiers[j].PreProcess(p); break; case Seeker.ModifierPass.PostProcessOriginal: this.modifiers[j].ApplyOriginal(p); break; case Seeker.ModifierPass.PostProcess: { ModifierData modifierData2 = ModifierConverter.Convert(p, modifierData, this.modifiers[j].input); if (modifierData2 != ModifierData.None) { this.modifiers[j].Apply(p, modifierData2); modifierData = this.modifiers[j].output; } else { UnityEngine.Debug.Log(string.Concat(new string[] { "Error converting ", (j <= 0) ? "original" : pathModifier.GetType().Name, "'s output to ", this.modifiers[j].GetType().Name, "'s input.\nTry rearranging the modifier priorities on the Seeker." })); modifierData = ModifierData.None; } pathModifier = this.modifiers[j]; break; } } if (modifierData == ModifierData.None) { break; } } } }
/** Runs modifiers on path \a p */ public void RunModifiers(ModifierPass pass, Path p) { //Sort the modifiers based on priority (bubble sort (slow but since it's a small list, it works good)) bool changed = true; while (changed) { changed = false; for (int i = 0; i < modifiers.Count - 1; i++) { if (modifiers[i].Priority < modifiers[i + 1].Priority) { IPathModifier tmp = modifiers[i]; modifiers[i] = modifiers[i + 1]; modifiers[i + 1] = tmp; changed = true; } } } //Call eventual delegates switch (pass) { case ModifierPass.PreProcess: if (preProcessPath != null) { preProcessPath(p); } break; case ModifierPass.PostProcessOriginal: if (postProcessOriginalPath != null) { postProcessOriginalPath(p); } break; case ModifierPass.PostProcess: if (postProcessPath != null) { postProcessPath(p); } break; } //No modifiers, then exit here if (modifiers.Count == 0) { return; } ModifierData prevOutput = ModifierData.All; IPathModifier prevMod = modifiers[0]; //Loop through all modifiers and apply post processing for (int i = 0; i < modifiers.Count; i++) { //Cast to MonoModifier, i.e modifiers attached as scripts to the game object MonoModifier mMod = modifiers[i] as MonoModifier; //Ignore modifiers which are not enabled if (mMod != null && !mMod.enabled) { continue; } switch (pass) { case ModifierPass.PreProcess: modifiers[i].PreProcess(p); break; case ModifierPass.PostProcessOriginal: modifiers[i].ApplyOriginal(p); break; case ModifierPass.PostProcess: //Convert the path if necessary to match the required input for the modifier ModifierData newInput = ModifierConverter.Convert(p, prevOutput, modifiers[i].input); if (newInput != ModifierData.None) { modifiers[i].Apply(p, newInput); prevOutput = modifiers[i].output; } else { UnityEngine.Debug.Log("Error converting " + (i > 0 ? prevMod.GetType().Name : "original") + "'s output to " + (modifiers[i].GetType().Name) + "'s input.\nTry rearranging the modifier priorities on the Seeker."); prevOutput = ModifierData.None; } prevMod = modifiers[i]; break; } if (prevOutput == ModifierData.None) { break; } } }
public void RunModifiers(ModifierPass pass, Path p) { //Sort the modifiers based on priority bool changed = true; while (changed) { changed = false; for (int i = 0; i < modifiers.Count - 1; i++) { if (modifiers[i].Priority < modifiers[i + 1].Priority) { IPathModifier tmp = modifiers[i]; modifiers[i] = modifiers[i + 1]; modifiers[i + 1] = tmp; changed = true; } } } switch (pass) { case ModifierPass.PreProcess: if (preProcessPath != null) { preProcessPath(p); } break; case ModifierPass.PostProcessOriginal: if (postProcessOriginalPath != null) { postProcessOriginalPath(p); } break; case ModifierPass.PostProcess: if (postProcessPath != null) { postProcessPath(p); } break; } ModifierData prevOutput = ModifierData.All; IPathModifier prevMod = modifiers[0]; //Loop through all modifiers and apply post processing for (int i = 0; i < modifiers.Count; i++) { MonoModifier mMod = modifiers[i] as MonoModifier; //Ignore modifiers which are not enabled if (mMod != null && !mMod.enabled) { continue; } switch (pass) { case ModifierPass.PreProcess: modifiers[i].PreProcess(p); break; case ModifierPass.PostProcessOriginal: modifiers[i].ApplyOriginal(p); break; case ModifierPass.PostProcess: //UnityEngine.Debug.Log ("Applying Post"); //Convert the path if necessary to match the required input for the modifier ModifierData newInput = ModifierConverter.Convert(p, prevOutput, modifiers[i].input); if (newInput != ModifierData.None) { modifiers[i].Apply(p, newInput); prevOutput = modifiers[i].output; } else { UnityEngine.Debug.Log("Error converting " + (i > 0 ? prevMod.GetType().Name : "original") + "'s output to " + (modifiers[i].GetType().Name) + "'s input"); prevOutput = ModifierData.None; } prevMod = modifiers[i]; break; } if (prevOutput == ModifierData.None) { break; } } }