using System; using System.Collections.Generic; using UnityEngine; namespace HutongGames.PlayMaker.Actions { [ActionCategory(OnlineMapsCategories.DRAWING)] [Tooltip("Draw txt file")] public class DrawTXT : FsmStateAction { public FsmObject textAsset; public FsmColor color = Color.red; public FsmBool closed = false; public FsmFloat width = 1; [UIHint(UIHint.Variable)] public FsmObject storeDrawingElement; public override void Reset() { textAsset = null; storeDrawingElement = null; color = Color.red; closed = false; width = 1; } public override void OnEnter() { DoEnter(); Finish(); } private void DoEnter() { TextAsset asset = textAsset.Value as TextAsset; string[] lines = asset.text.Split(new[] {(char)13}, StringSplitOptions.RemoveEmptyEntries); List points = new List(); foreach (string line in lines) { if (string.IsNullOrEmpty(line)) continue; string[] parts = line.Trim(' ', '\t').Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 2) continue; points.Add(double.Parse(parts[1])); points.Add(double.Parse(parts[0])); } OnlineMapsDrawingElement el = null; if (closed.Value) el = new OnlineMapsDrawingPoly(points, color.Value, width.Value); else el = new OnlineMapsDrawingLine(points, color.Value, width.Value); OnlineMapsDrawingElementManager.AddItem(el); if (!storeDrawingElement.IsNone) storeDrawingElement.Value = new DrawingElementWrapper(el); } } }