/// <summary> /// Returns the default spell that is to be cast /// </summary> /// <returns></returns> public virtual Spell InstantiateSpell(int rIndex = -1) { int lIndex = rIndex; if (lIndex < 0) { lIndex = _DefaultSpellIndex; } if (lIndex >= 0 && lIndex < _Spells.Count) { Spell lPrefab = _Spells[lIndex].SpellPrefab; //Utilities.Profiler.Start("CopySpell", ""); #if UNITY_EDITOR && NO_ALLOCATION Spell lInstance = ScriptableObjectPool.DeepCopy(lPrefab, true) as Spell; #else Spell lInstance = ScriptableObjectPool.Allocate(lPrefab, true) as Spell; #endif //Debug.Log("deep copy:" + Utilities.Profiler.Stop("CopySpell").ToString("f4")); if (lInstance != null) { lInstance.Prefab = lPrefab; lInstance.Owner = gameObject; lInstance.SpellInventory = this; lInstance.State = EnumSpellState.READY; _ActiveSpells.Add(lInstance); return(lInstance); } } return(null); }
/// <summary> /// Activate the node contents and flag the node as working /// </summary> /// <param name="rNode">Node to activate</param> public void ActivateNode(Node rNode, object rData = null) { Node lNode = rNode; // If the node isn't immediate, we'll create an instance of it so we can // loop over and over as needed. This instance is a shallow copy. So, we're not // creating new instances of children. //if (!lNode.IsImmediate) { // Create an instance of the node. lNode = ScriptableObject.Instantiate <Node>(rNode); lNode.ID = rNode.ID; // Tell all the node links that this is the start node. We shallow copy them // as well so the StartNode can be different each instance for (int i = 0; i < lNode.Links.Count; i++) { NodeLink lLink = ScriptableObject.Instantiate <NodeLink>(lNode.Links[i]); lLink.StartNode = lNode; // Creates instances for each of the actions if (lLink.Actions != null && lLink.Actions.Count > 0) { for (int j = 0; j < lLink.Actions.Count; j++) { NodeLinkAction lLinkAction = ScriptableObject.Instantiate <NodeLinkAction>(lLink.Actions[j]); lLinkAction._Link = lLink; lLink.Actions[j] = lLinkAction; } } lNode.Links[i] = lLink; } // We do want a deep copy of the content. lNode.Content = ScriptableObjectPool.DeepCopy(lNode.Content, true); if (ShowDebug) { Utilities.Debug.Log.FileWrite(string.Format("Spell[{0}].ActivateNode() - Instance created for", Name, lNode.Content.GetType().Name)); } } // If we're dealing with a spell action, activate SpellAction lAction = lNode.Content as SpellAction; if (lAction != null) { lNode.State = EnumNodeState.WORKING; lAction.Spell = this; lAction.Node = lNode; lAction.Activate(0, rData); if (ShowDebug) { Utilities.Debug.Log.FileWrite(string.Format("Spell[{0}].ActivateNode() - Activated: {1}", Name, lAction.GetType().Name)); } // If the action takes time, add it to your queue if (lNode.State == EnumNodeState.WORKING) { if (!mActiveNodes.Contains(lNode)) { mActiveNodes.Add(lNode); if (ShowDebug) { Utilities.Debug.Log.FileWrite(string.Format("Spell[{0}].ActivateNode() - Added to active nodes: {1}", Name, lAction.GetType().Name)); } } } // if it's an instant action, we want to move to the next node else { if (ShowDebug) { Utilities.Debug.Log.FileWrite(string.Format("Spell[{0}].ActivateNode() - Testing links: {1}", Name, lAction.GetType().Name)); } // Process the node links to see if they should be activated for (int i = 0; i < lNode.Links.Count; i++) { bool lActivate = lNode.Links[i].TestActivate(); if (lActivate) { ActivateLink(lNode.Links[i], lNode.Data); } } } } // We may still have links that need to process else { lNode.State = EnumNodeState.SUCCEEDED; if (ShowDebug) { Utilities.Debug.Log.FileWrite(string.Format("Spell[{0}].ActivateNode() - No action, testing links: {1}", Name, lAction.GetType().Name)); } // Process the node links to see if they should be activated for (int i = 0; i < lNode.Links.Count; i++) { bool lActivate = lNode.Links[i].TestActivate(); if (lActivate) { ActivateLink(lNode.Links[i], lNode.Data); } } } }