/// <summary>
        /// Returns metadata to build editor window
        /// </summary>
        /// <returns></returns>
        public StateMachineMetadata GetMetadataAsset()
        {
            var asset = AssetDatabase.LoadAllAssetsAtPath(GetAssetPath()).OfType <StateMachineMetadata>().FirstOrDefault();

            if (asset == null)
            {
                asset = StateMachineMetadata.Create();
                AppendSubAsset(asset);
            }
            return(asset);
        }
        void OnGUI()
        {
            // Initialize
            if (metaData == null)
            {
                metaData = StateMachineAsset.GetStateMachineAsset().Metadata;
            }
            if (!initDone)
            {
                InitStyles();
            }

            // Draw environment (inclusing zoom and position)
            BeginMainWindow(metaData.WindowOffset, metaData.WindowZoomPivot, metaData.WindowZoom);

            DrawGrid(displayArea, 20, 0.2f, Color.gray);
            DrawGrid(displayArea, 100, 0.4f, Color.gray);

            DrawLinkLines();

            BeginWindows();
            foreach (var node in metaData.StateNodes)
            {
                node.Center = GUI.Window(node.Id, node.Window, DrawNode, "", _nodeStyles.GetStyle(node)).center;
            }
            EndWindows();
            DrawMouseLine();

            EndMainWindow();

            // Handle input (mouse and keyboard)
            HandleEvents();

            // Draw UI (top bars and instructions)
            GUILayout.BeginVertical();
            DrawToolBar();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("Middle button to pan and zoom."));
            GUILayout.FlexibleSpace();
            GUILayout.Label(new GUIContent("Right click to create transitions"));
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            EditorUtility.SetDirty(metaData);
        }