public override AIAction MakeInstance() { AINodeEvaluate eval = base.MakeInstance() as AINodeEvaluate; for (int i = 0; i < behaviours.Length; i++) { eval.behaviours[i] = eval.behaviours[i].MakeInstance(); } return(eval); }
// Use this for initialization void Start() { character = GetComponent <Character>(); ai = GetComponent <AICharacterControl>(); List <AIAction> extras = new List <AIAction>(); Patrolling patrol = GetComponent <Patrolling>(); if (patrol) { extras.Add(ScriptableObject.CreateInstance <AIPatrol>()); } int numActions = behaviours.Length + extras.Count; // set up a suitable rootnode, either a single power, or a group of them which compete! if (numActions == 0) { rootNode = null; } else if (numActions == 1) { if (behaviours.Length > 0) { rootNode = behaviours[0].MakeInstance(); } else { rootNode = extras[0].MakeInstance(); } } else { AIAction[] actions = new AIAction[numActions]; for (int i = 0; i < behaviours.Length; i++) { actions[i] = behaviours[i].MakeInstance(); } for (int i = 0; i < extras.Count; i++) { actions[i + behaviours.Length] = extras[i].MakeInstance(); } AINodeEvaluate evalNode = ScriptableObject.CreateInstance <AINodeEvaluate>(); evalNode.behaviours = actions; rootNode = evalNode; } patrolling = GetComponent <Patrolling>(); }