/// <summary> /// Loads the specified spell in the editor /// </summary> /// <param name="rSpell">Spell to edit</param> public void LoadSpell(Spell rSpell, bool rForceRefresh = false) { if (!rForceRefresh && Spell == rSpell) { return; } RootAsset = rSpell; Spell = rSpell; mCanvas.Clear(); SpellMenuPanel.IsDirty = false; SpellNodePanel.IsEnabled = false; SpellLinkPanel.IsEnabled = false; if (Spell != null) { // Extract out the nodes and add them to the canvas UnityEngine.Object[] lObjects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(RootAssetPath); for (int i = 0; i < lObjects.Length; i++) { Node lNode = lObjects[i] as Node; if (lNode != null) { // Ensure the links are valid and remove them if not for (int j = lNode.Links.Count - 1; j >= 0; j--) { NodeLink lLink = lNode.Links[j]; if (lLink == null || lLink.StartNode == null || lLink.EndNode == null) { Debug.Log("SpellEditor.LoadSpell - removing Link link:" + lLink.name); lNode.Links.RemoveAt(j); } } // Add the node to the canvas lNode.Canvas = mCanvas; mCanvas.Nodes.Add(lNode); } } } // Set the asset path so when the window reloads, we can load it SpellEditorWindow lWindow = SpellEditorWindow.Instance; // EditorWindow.GetWindow<SpellEditorWindow>(); if (lWindow != null) { lWindow.AssetPath = RootAssetPath; } Repaint(); }
private static bool AutoOpenCanvas(int rInstanceID, int rLine) { if (Selection.activeObject != null && Selection.activeObject is Spell) { SpellEditorWindow.OpenSpellEditor(); if (Instance != null) { string lAssetPath = AssetDatabase.GetAssetPath(rInstanceID); Instance.AssetPath = lAssetPath; Instance.Editor.LoadRootAsset(lAssetPath); return(true); } } return(false); }
/// <summary> /// Automatically opens the window when the spell is selected. /// </summary> public static bool OpenSpellEditor(int rInstanceID) { if (rInstanceID != 0) { SpellEditorWindow.OpenSpellEditor(); if (Instance != null) { string lAssetPath = AssetDatabase.GetAssetPath(rInstanceID); Instance.AssetPath = lAssetPath; Instance.Editor.LoadRootAsset(lAssetPath); return(true); } } return(false); }
/// <summary> /// Allows us to draw each item in the list /// </summary> /// <param name="rRect"></param> /// <param name="rIndex"></param> /// <param name="rIsActive"></param> /// <param name="rIsFocused"></param> private void DrawItemListItem(Rect rRect, int rIndex, bool rIsActive, bool rIsFocused) { if (rIndex < mTarget._Spells.Count) { SpellInventoryItem lItem = mTarget._Spells[rIndex]; rRect.y += 2; Rect lNameRect = new Rect(rRect.x, rRect.y, rRect.width - 60f, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(lNameRect, string.Format("[{0}] {1}", rIndex, lItem.Name)); Rect lButtonRect = new Rect(lNameRect.x + lNameRect.width + 10f, lNameRect.y, 50f, lNameRect.height); if (GUI.Button(lButtonRect, "open", EditorHelper.LinkLabel)) { int lInstance = lItem.SpellPrefab.GetInstanceID(); SpellEditorWindow.OpenSpellEditor(lInstance); } } }
public static SpellEditorWindow OpenSpellEditor() { //Debug.Log("SpellEditorWindow.OpenSpellEditor() Instance:" + (Instance == null ? "null" : "value")); if (EditorApplication.isCompiling) { //Debug.Log("Compiling "); return(null); } Instance = GetWindow <SpellEditorWindow>("Spell Editor"); Instance.minSize = new Vector2(400f, 300f); Instance.titleContent = new GUIContent("Spell Editor"); Instance.Editor = new SpellEditor(); //Instance.Editor = ScriptableObject.CreateInstance<SpellEditor>(); Instance.Editor.Initialize(Instance.position.width, Instance.position.height); Instance.Editor.RepaintEvent = Instance.OnRepaint; Instance.wantsMouseMove = true; return(Instance); }
/// <summary> /// Called multiple times per second on all visible windows. /// </summary> protected override void OnEnable() { //Debug.Log("SpellEditorWindow.OnEnable() Instance:" + (Instance == null ? "null" : "value")); if (Instance == null) { //Instance = GetWindow<SpellEditorWindow>("Spell Editor"); Instance = this; } if (Editor == null) { //Debug.Log(" Create Editor"); if (EditorApplication.isCompiling) { //Debug.Log(" Compiling "); return; } Editor = new SpellEditor(); //Editor = ScriptableObject.CreateInstance<SpellEditor>(); Editor.Initialize(Instance.position.width, Instance.position.height); Editor.RepaintEvent = Instance.OnRepaint; } string lPath = Editor.RootAssetPath; if (lPath.Length == 0) { lPath = AssetPath; } if (lPath.Length > 0) { Editor.LoadRootAsset(lPath); } }