//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public IEnumerator Start() { _TreeTypeDictionary = new Dictionary <TreeType, Tree>(); _ActionPlanQueue = new Queue <OCActionPlanStep>(); foreach (TreeType type in Enum.GetValues(typeof(TreeType)).Cast <TreeType>()) { _TreeTypeDictionary.Add(type, BLOCBehaviours.InstantiateTree(type, this)); } OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(true); foreach (Tree tree in _TreeTypeDictionary.Values) { if (tree == null) { continue; } int index = tree.Name.LastIndexOf(".") + 1; if (index < 0 || index > tree.Name.Count()) { index = 0; } string treeName = tree.Name.Substring(index); foreach (OCAction action in actions) { if (action.FullName.Contains(treeName) || treeName.Contains("Behaviour")) { int actionTypeID = (int)Enum.Parse(typeof(BLOCBehaviours.ActionType), action.FullName); tree.SetTickForward(actionTypeID, action.ExecuteBehave); } } } OCActionPlanStep firstStep = new OCActionPlanStep(); firstStep.Behaviour = _TreeTypeDictionary[_TreeType]; firstStep.Arguments = new OCAction.OCActionArgs(_defaultSource, _defaultStartTarget, _defaultEndTarget); _ActionPlanQueue.Enqueue(firstStep); RunningActions = new List <string>(); //RunningActions.Add("StandIdleShow"); while (Application.isPlaying) { yield return(new WaitForSeconds(1.0f / 240.0f)); UpdateAI(); } }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public IEnumerator Start() { _TreeTypeDictionary = new Dictionary <TreeType, Tree>(); _ActionPlanQueue = new LinkedList <OCActionPlanStep>(); foreach (TreeType type in Enum.GetValues(typeof(TreeType)).Cast <TreeType>()) { _TreeTypeDictionary.Add(type, BLOCBehaviours.InstantiateTree(type, this)); } OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(true); foreach (Tree tree in _TreeTypeDictionary.Values) { if (tree == null) { continue; } int index = tree.Name.LastIndexOf(".") + 1; if (index < 0 || index > tree.Name.Count()) { index = 0; } string treeName = tree.Name.Substring(index); foreach (OCAction action in actions) { if (((action.FullName.Contains(treeName) || treeName.Contains("Behaviour")) && !(treeName == "GhostBehaviour" && action.name.Contains("Create")) && !(treeName == "GhostBehaviour" && action.name.Contains("Destroy"))) || (treeName == "TurnAndCreate" && action.FullName == "HoldRightHandCreate") || (treeName == "TurnAndCreate" && action.FullName == "HoldRightHandCreateBelow") || (treeName == "TurnAndCreate" && action.FullName == "StandTurnLeftMove") || (treeName == "TurnAndCreate" && action.FullName == "StandTurnRightMove") || (treeName == "TurnAndCreate" && action.FullName == "StandIdleShow") || (treeName == "TurnAndCreate" && action.FullName == "FallIdleShow") || (treeName == "TurnLeftOrRight" && action.FullName == "StandTurnLeftMove") || (treeName == "TurnLeftOrRight" && action.FullName == "StandTurnRightMove") || (treeName == "TurnLeftOrRight" && action.FullName == "StandIdleShow") || (treeName == "TurnLeftOrRight" && action.FullName == "FallIdleShow") || (treeName == "BothHandsTransfer" && action.FullName == "HoldBothHandsTransfer") ) { int actionTypeID = (int)Enum.Parse(typeof(BLOCBehaviours.ActionType), action.FullName); tree.SetTickForward(actionTypeID, action.ExecuteBehave); } } } OCActionPlanStep firstStep = OCScriptableObject.CreateInstance <OCActionPlanStep>(); firstStep.Behaviour = _TreeTypeDictionary[_TreeType]; firstStep.Arguments = new OCAction.OCActionArgs(_defaultSource, _defaultStartTarget, _defaultEndTarget); KeyValuePair <string, TreeType> keyValuePair = _ActionNameDictionary.First(s => s.Value == _TreeType); firstStep.Arguments.ActionName = keyValuePair.Key; _ActionPlanQueue.AddLast(firstStep); RunningActions = new List <string>(); //RunningActions.Add("StandIdleShow"); // vvvv Testing Nil's action for the SantaFe problem vvvv ///////////////////////////////////////////////////////////////////////////////// // XmlDocument doc = new XmlDocument(); // doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n<oc:action-plan xmlns:oc=\"http://www.opencog.org/brain\" demand=\"\" entity-id=\"OAC_AGI_Robot\" id=\"0\">\n<action name=\"step_forward\" sequence=\"1\"/>\n</oc:action-plan>"); // // XmlNodeList list = doc.GetElementsByTagName(OCEmbodimentXMLTags.ACTION_PLAN_ELEMENT); // XmlElement root = (XmlElement)list.Item(0);//MakeXMLElementRoot(doc); // // CharacterController charControl = gameObject.GetComponent<CharacterController>(); // bool tryParse = true; ///////////////////////////////////////////////////////////////////////////////// while (Application.isPlaying) { yield return(new WaitForSeconds(1.0f / 100.0f)); UpdateAI(); // if(tryParse && charControl.isGrounded) // { // OCConnectorSingleton.Instance.ParseActionPlanElement(root); // tryParse = false; // } } }