private void PasteActions() { List <ModelActionEditor> paste = new List <ModelActionEditor>(); if (Clipboard.TryPaste(out paste)) { foreach (var item in paste) { if (item.IsSkillAction) { SkillActions.Add(item); } else { ModelActions.Add(item); } item.IsSelected = false; } Clipboard.Clear(); } else { EditorUtility.DisplayDialog("粘贴异常", "行为数据粘贴失败,或者无数据可张贴~~", "确定"); } }
public ModelActionConfigEditor(string path) { _path = path; _modelActionCfg = XmlUtil.Deserialize(path, typeof(ModelActionConfig)) as ModelActionConfig; foreach (var item in _modelActionCfg.ModelActionList) { var action = new ModelActionEditor(this, item, false); action.ActState = ModelActionEditor.ActionState.New; ModelActions.Add(action); } foreach (var item in _modelActionCfg.SkillActionList) { var action = new ModelActionEditor(this, item, true); action.ActState = ModelActionEditor.ActionState.New; SkillActions.Add(action); } }
private void AddBaseModelAction(string name) { var baseModel = HomeConfigPreview.Instance.GetModelEditor(name); var modelDict = GetModelActionDict(); foreach (var item in baseModel.ModelActions) { if (modelDict.ContainsKey(item.ActionName)) { modelDict[item.ActionName].ActState = modelDict[item.ActionName].Equals(item) ? ModelActionEditor.ActionState.Inherit : ModelActionEditor.ActionState.Override; } else { var action = new ModelActionEditor(item); action.ActState = ModelActionEditor.ActionState.Inherit; ModelActions.Add(action); } } var skillDict = GetModelActionDict(); foreach (var item in baseModel.SkillActions) { if (skillDict.ContainsKey(item.ActionName)) { skillDict[item.ActionName].ActState = skillDict[item.ActionName].Equals(item) ? ModelActionEditor.ActionState.Inherit : ModelActionEditor.ActionState.Override; } else { var action = new ModelActionEditor(item); action.ActState = ModelActionEditor.ActionState.Inherit; SkillActions.Add(action); } } }
protected ModelActions GetPossibleActions(ModelActions totalactions) { //Loop through all actions, specified ModelActions possibleactions = new ModelActions(); foreach(ModelAction action in totalactions) { //Ignore Disabled actions if(action.Weight == 0 || action.Disabled) continue; //Ignore CallLimit/CallOnce actions that have already been called (max times) if(action.Accessed >= action.CallLimit) continue; //Note: CallFirst and CallLast imply CallOnce if(action.Accessed>0 && (action.CallFirst || action.CallLast)) continue; //Ignore Actions, that return Models when were over the limit of those models Type returntype = action.Method.ReturnType; if(!returntype.IsPrimitive && typeof(Model).IsAssignableFrom(returntype) && returntype != typeof(Model)) { Models found = (Models)this.Models.FindType(returntype).FindFlag((int)ModelItemFlags.Disabled, false); if(found.Count >= found.MaxInstances) continue; } //Determine if Requirements meet ModelRequirement failedrequirement = null; bool matched = MeetsRequirements(action.Requirements, out failedrequirement); if(matched) { //Requirements met, action can be called possibleactions.Add(action); } else { //Requirements not met, action can't be called //Unless the user wants this to be called, when the requirements aren't met if(this.InvalidActions && failedrequirement != null && failedrequirement.Throws) { //Note: We clone the action, and set the expected exception, just as if //it were an invalid action from the start. We also set the weight of the //invalid action, to the weight of the requirement, so it's not weighted //the same as the (positive) version that's specified at the action level ModelAction invalidaction = (ModelAction)action.Clone(); invalidaction.Exception = failedrequirement.Exception; invalidaction.ExceptionId = failedrequirement.ExceptionId; invalidaction.Weight = failedrequirement.Weight; possibleactions.Add(invalidaction); } } } possibleactions.SortByWeightDesc(); //Sort all actions, across models return possibleactions; }
//Methods //FIXME: should this be public? It is difficult to extend the behavior of the engine without //hosting the extension in the same assembly, unless we do this. internal ModelActions GetPossibleActions() { //Default - exclude: invalid, callbefore, callafter, calllast, which are handled seperatly. ModelActionFlags exclude = ModelActionFlags.CallBefore | ModelActionFlags.CallAfter | ModelActionFlags.CallLast; if(!this.InvalidActions) exclude |= (ModelActionFlags)ModelItemFlags.Invalid; //Loop through all models ModelActions totalactions = new ModelActions(); foreach(Model model in this.Models) { //Ignore disabled models if(model.Weight == 0 || model.Disabled) continue; totalactions.Add(model.Actions.FindFlag(exclude, false)); } //Delegate return this.GetPossibleActions(totalactions); }