internal static AICanvas Deserialize(AIUI host, string data) { var canvasElement = SerializationMaster.Deserialize(data); var canvas = new AICanvas { offset = canvasElement.ValueOrDefault <Vector2>(ElementName.Offset), zoom = canvasElement.ValueOrDefault(ElementName.Zoom, 1f) }; var selectorViews = canvasElement.Elements(ElementName.SelectorView); foreach (var sve in selectorViews) { var sv = ReadSelectorView(sve, host); canvas.views.Add(sv); } var linkViews = canvasElement.Elements(ElementName.AILinkView); foreach (var lve in linkViews) { var lv = ReadAILinkView(lve, host); canvas.views.Add(lv); } return(canvas); }
internal static string Serialize(AICanvas canvas) { var root = new StageElement( ElementName.Canvas, SerializationMaster.Stage(ElementName.Offset, canvas.offset), SerializationMaster.ToStageValue(ElementName.Zoom, canvas.zoom)); var views = canvas.views; int svCount = views.Count; for (int i = 0; i < svCount; i++) { var view = views[i]; StageElement viewElement; if (view is SelectorView) { viewElement = WriteSelectorView((SelectorView)view); } else if (view is AILinkView) { viewElement = WriteAILinkView((AILinkView)view); } else { throw new NotImplementedException("The view type has not been implemented for serialization."); } root.Add(viewElement); } return(SerializationMaster.Serialize(root)); }
private bool LoadFrom(AIStorage data, bool refreshState) { _aiStorage = data; try { if (EditorApplication.isPlaying) { _ai = _visualizedAI = AIManager.GetAI(new Guid(data.aiId)); } else { _ai = _visualizedAI = SerializationMaster.Deserialize <UtilityAI>(_aiStorage.configuration); } this.canvas = GuiSerializer.Deserialize(this, _aiStorage.editorConfiguration); } catch (Exception e) { if (EditorUtility.DisplayDialog("Load Error", "The AI could not be loaded, deserialization failed - see the console for details.\n\nDo you wish to open the AI repair tool?.", "Yes", "No")) { RepairWindow.ShowWindow(data.name, data.aiId); } Debug.LogWarning("Failed to load AI: " + e.Message); return(false); } var selectorViews = this.canvas.selectorViews.ToArray(); int selectorCount = _ai.selectorCount; if (!VerifyCountMatch(selectorCount, selectorViews.Length)) { return(false); } for (int i = 0; i < selectorCount; i++) { if (!selectorViews[i].Reconnect(_ai[i])) { return(false); } } if (refreshState) { this.inspectorState.Refresh(); } return(true); }
private void InitNew(string name) { this.canvas = new AICanvas(); this.name = name; }