using System; using System.Collections.Generic; using System.Globalization; 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; [Tooltip("Follow Relief.")] public FsmBool followRelief = false; public FsmInt lineSeparatorCharCode = 13; public FsmString partSeparator = ";"; [UIHint(UIHint.Variable)] public FsmObject storeDrawingElement; public override void Reset() { textAsset = null; storeDrawingElement = null; color = Color.red; closed = false; followRelief = 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)lineSeparatorCharCode.Value }, StringSplitOptions.RemoveEmptyEntries); List points = new List(); foreach (string line in lines) { if (string.IsNullOrEmpty(line)) continue; string[] parts = line.Split(new[] { partSeparator.Value }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 2) continue; points.Add(double.Parse(parts[1].Trim(' ', '\t'), CultureInfo.InvariantCulture)); points.Add(double.Parse(parts[0].Trim(' ', '\t'), CultureInfo.InvariantCulture)); } OnlineMapsDrawingElement el = null; if (closed.Value) el = new OnlineMapsDrawingPoly(points, color.Value, width.Value); else { el = new OnlineMapsDrawingLine(points, color.Value, width.Value); if (!followRelief.IsNone) (el as OnlineMapsDrawingLine).followRelief = followRelief.Value; } OnlineMapsDrawingElementManager.AddItem(el); if (!storeDrawingElement.IsNone) storeDrawingElement.Value = new DrawingElementWrapper(el); } } }