public void AddParameter(List <BehaviorParameter> parameterList) { for (int i = 0; i < parameterList.Count; ++i) { BehaviorParameter parameter = parameterList[i]; if (_allParameterDic.ContainsKey(parameter.parameterName)) { continue; } //Debug.LogError(parameter.parameterName + " " + (BehaviorParameterType)(parameter.parameterType)); _allParameterDic[parameter.parameterName] = parameter.Clone(); // 暂时这么处理,以后改成读取默认值 _allParameterDic[parameter.parameterName].intValue = 0; _allParameterDic[parameter.parameterName].floatValue = 0; _allParameterDic[parameter.parameterName].boolValue = false; } if (parameterList.Count > 0) { Debug.Log("暂时这么处理,以后改成读取默认值"); } }
public override ResultType DoAction() { if (null == human) { return(ResultType.Fail); } Vector3 targetPos = Vector3.zero; if (_parameterList.Count >= 0 && _parameterList[0].parameterName.CompareTo("MoveTarget") == 0) { BehaviorParameter parameter = _parameterList[0]; if (parameter.intValue == 0) { targetPos = human.KitchenPos(); } else if (parameter.intValue == 1) { targetPos = human.DiningTablePos(); } else if (parameter.intValue == 2) { targetPos = human.TVPos(); } } ResultType resultType = ResultType.Running; if (Vector3.Distance(human.Position(), targetPos) < 0.5f) { return(ResultType.Success); } human.Translate(targetPos); return(resultType); }
public bool Condition(BehaviorParameter parameter) { BehaviorCompare behaviorCompare = BehaviorCompare.EQUALS; if (parameter.parameterType == (int)(BehaviorParameterType.Int)) { int intValue = 0; if (!GetParameterValue(parameter.parameterName, ref intValue)) { return(false); } behaviorCompare = BehaviorParameter.CompareInt(intValue, parameter.intValue); } else if (parameter.parameterType == (int)(BehaviorParameterType.Long)) { long longValue = 0; if (!GetParameterValue(parameter.parameterName, ref longValue)) { return(false); } behaviorCompare = BehaviorParameter.CompareLong(longValue, parameter.longValue); } else if (parameter.parameterType == (int)(BehaviorParameterType.Float)) { float floatValue = 0; if (!GetParameterValue(parameter.parameterName, ref floatValue)) { return(false); } behaviorCompare = BehaviorParameter.CompareFloat(floatValue, parameter.floatValue); } else if (parameter.parameterType == (int)(BehaviorParameterType.Bool)) { bool boolValue = false; if (!GetParameterValue(parameter.parameterName, ref boolValue)) { return(false); } behaviorCompare = BehaviorParameter.CompareBool(boolValue, parameter.boolValue); } else if (parameter.parameterType == (int)(BehaviorParameterType.String)) { string stringValue = string.Empty; if (!GetParameterValue(parameter.parameterName, ref stringValue)) { return(false); } behaviorCompare = BehaviorParameter.CompareString(stringValue, parameter.stringValue); } int value = (parameter.compare) & (int)behaviorCompare; return(value > 0); //BehaviorParameter environmentParameter = null; //if (!_environmentParameterDic.TryGetValue(parameter.parameterName, out environmentParameter)) //{ // return false; //} //if (environmentParameter.parameterType != parameter.parameterType) //{ // //ProDebug.Logger.LogError("parameter Type not Equal:" + environmentParameter.parameterName + " " + environmentParameter.parameterType + " " + parameter.parameterType); // return false; //} //BehaviorCompare behaviorCompare = environmentParameter.Compare(parameter); //int value = (parameter.compare) & (int)behaviorCompare; //return value > 0; }
/// <summary> /// 获取配置文件中的监视设置 /// </summary> /// <returns></returns> private static DirectoryMonitor[] GetMonitorationSettings() { //读取配置文件. 加载根部: dirMonitor MonitorationsConfigurationHandler s = (MonitorationsConfigurationHandler)ConfigurationManager.GetSection("dirMonitor"); List <DirectoryMonitor> dms = new List <DirectoryMonitor>(); //读取单个监视设置 foreach (var m in s.Monitorations) { MonitorationConfigurationElement elementM = (MonitorationConfigurationElement)m; DirectoryMonitor dm = new DirectoryMonitor(); dm.CurrentLevelOnly = elementM.CurrentLevelOnly; //监视目标 dm.DirectoryToMonitor = elementM.Path.EndsWith("\\") ? elementM.Path.Remove(elementM.Path.Length - 1, 1) : elementM.Path; //行为列表 List <BehaviorsWapper> bws = new List <BehaviorsWapper>(); //读取处理行为 foreach (var b in elementM.Behaviors) { BehaviorsWapper w = new BehaviorsWapper(); BehaviorConfigurationElement elementB = (BehaviorConfigurationElement)b; //读取到处理行为类类型, 和所在DLL加载起来. //首先尝试直接反射出一个实例. 若失败, 则 //尝试手动加载程序集后再创建实例. String t = elementB.Type; try { w.Behavior = (IBehavior)Activator.CreateInstance(Type.GetType(t, true, true)); } catch (FileNotFoundException) { Assembly a = Assembly.LoadFrom(elementB.AssemblyFile); w.Behavior = (IBehavior)a.CreateInstance(t); } //-------------------------------------------- w.Enable = elementB.Enable; w.IsAsync = elementB.IsAsync; Dictionary <String, String> parameters = new Dictionary <string, string>(); //处理行为参数 foreach (var c in elementB.Parameters) { BehaviorParameter elementP = (BehaviorParameter)c; parameters.Add(elementP.Key, elementP.Value); } //将参数填回 w.Parameters = parameters; bws.Add(w); } dm.Behaviors = bws.ToArray(); dms.Add(dm); } return(dms.ToArray()); }
public bool Condition(BehaviorParameter parameter) { return(CompareParameter(parameter)); }