本文整理汇总了C#中Behaviac.Design.NodeViewData.IsBehaviorReferenced方法的典型用法代码示例。如果您正苦于以下问题:C# NodeViewData.IsBehaviorReferenced方法的具体用法?C# NodeViewData.IsBehaviorReferenced怎么用?C# NodeViewData.IsBehaviorReferenced使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Behaviac.Design.NodeViewData
的用法示例。
在下文中一共展示了NodeViewData.IsBehaviorReferenced方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertNewNode
/// <summary>
/// Attaches a dragged node from the node explorer to an existing node.
/// </summary>
/// <param name="nvd">The node the new node will be attached to.</param>
/// <param name="mode">The way the new node will be attached.</param>
/// <param name="nodetag">The tag of the you want to create.</param>
/// <param name="label">The label of the new node.</param>
private void InsertNewNode(NodeViewData nvd, NodeAttachMode mode, NodeTag nodetag, PointF mousePos) {
if (nodetag.Type != NodeTagType.Behavior && nodetag.Type != NodeTagType.Prefab && nodetag.Type != NodeTagType.Node) {
throw new Exception("Only behaviours, prefabs and nodes can be attached to a behaviour tree");
}
Node newnode = null;
bool isPrefabInstance = false;
// when we attach a behaviour we must create a special referenced behaviour node
if (nodetag.Type == NodeTagType.Behavior || nodetag.Type == NodeTagType.Prefab) {
if (!File.Exists(nodetag.Filename)) {
if (!SaveBehavior(nodetag.Filename)) {
return;
}
}
// get the behavior we want to reference
BehaviorNode behavior = _behaviorTreeList.LoadBehavior(nodetag.Filename);
// a behaviour reference itself
if (nvd != null && nvd.IsBehaviorReferenced(behavior)) {
if (DialogResult.Cancel == MessageBox.Show(Resources.CircularReferencedInfo, Resources.Warning, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) {
return;
}
}
if (nodetag.Type == NodeTagType.Prefab) {
behavior = (BehaviorNode)behavior.Clone();
}
Behavior rootB = _rootNodeView.RootBehavior as Behavior;
Behavior b = behavior as Behavior;
if (rootB.AgentType == null) {
rootB.AgentType = b.AgentType;
} else if (!IsCompatibleAgentType(rootB, b)) {
return;
}
// behavior
if (nodetag.Type == NodeTagType.Behavior) {
// create the referenced behaviour node for the behaviour
ReferencedBehavior refnode = Node.CreateReferencedBehaviorNode(_rootNodeView.RootBehavior, behavior, mode == NodeAttachMode.None || ((Node)this.RootNode).IsFSM);
newnode = (Node)refnode;
//the comment seems too long to overlap the node
//newnode.CommentText = Resources.ThisIsReferenceTree;
newnode.CommentBackground = Node.CommentColor.Gray;
}
// prefab
else {
// Copy all Pars from the prefab file into the current behavior node.
List<ParInfo> pars = new List<ParInfo>();
foreach(ParInfo par in b.LocalVars) {
bool found = false;
foreach(ParInfo rootPar in rootB.LocalVars) {
if (par.Name == rootPar.Name) {
if (par.Type != rootPar.Type) {
string errorMsg = string.Format(Resources.ParErrorInfo, par.Name, b.Label, rootB.Label);
MessageBox.Show(errorMsg, Resources.LoadError, MessageBoxButtons.OK);
return;
}
found = true;
break;
}
}
if (!found) {
pars.Add(par);
}
}
rootB.LocalVars.AddRange(pars);
// The first child should be the root node of the prefab tree.
Node behaviorNode = (Node)behavior;
if (behaviorNode.Children.Count > 0) {
newnode = (Node)behaviorNode.Children[0];
string prefab = Path.GetFileNameWithoutExtension(behavior.Filename);
newnode.CommentText = string.Format("Prefab[{0}]", prefab);
isPrefabInstance = true;
string prefabName = FileManagers.FileManager.GetRelativePath(behavior.Filename);
newnode.SetPrefab(prefabName);
}
}
} else {
//.........这里部分代码省略.........
示例2: InsertNewNode
/// <summary>
/// Attaches a dragged node from the node explorer to an existing node.
/// </summary>
/// <param name="nvd">The node the new node will be attached to.</param>
/// <param name="mode">The way the new node will be attached.</param>
/// <param name="nodetag">The tag of the you want to create.</param>
/// <param name="label">The label of the new node.</param>
private void InsertNewNode(NodeViewData nvd, NodeAttachMode mode, NodeTag nodetag)
{
// check if the attach mode is valid
if (mode == NodeAttachMode.Attachment || mode == NodeAttachMode.None)
throw new Exception("A node cannot be created with the given attach mode");
if (nodetag.Type != NodeTagType.Behavior && nodetag.Type != NodeTagType.Prefab && nodetag.Type != NodeTagType.Node)
throw new Exception("Only behaviours, prefabs and nodes can be attached to a behaviour tree");
Node node = nvd.Node;
Node newnode = null;
bool isPrefabInstance = false;
// when we attach a behaviour we must create a special referenced behaviour node
if (nodetag.Type == NodeTagType.Behavior || nodetag.Type == NodeTagType.Prefab)
{
if (!File.Exists(nodetag.Filename))
{
if (!SaveBehavior(nodetag.Filename))
return;
}
// get the behavior we want to reference
BehaviorNode behavior = _behaviorTreeList.LoadBehavior(nodetag.Filename);
// a behaviour reference itself
if (nvd.IsBehaviorReferenced(behavior))
{
if (DialogResult.Cancel == MessageBox.Show(Resources.CircularReferencedInfo, Resources.Warning, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
return;
}
if (nodetag.Type == NodeTagType.Prefab)
{
behavior = (BehaviorNode)behavior.Clone();
}
Behavior rootB = _rootNode.RootBehavior as Behavior;
Behavior b = behavior as Behavior;
if (rootB.AgentType == null)
{
rootB.AgentType = b.AgentType;
}
else if (!IsCompatibleAgentType(rootB, b))
{
return;
}
// behavior
if (nodetag.Type == NodeTagType.Behavior)
{
// create the referenced behaviour node for the behaviour
ReferencedBehaviorNode refnode = Node.CreateReferencedBehaviorNode(_rootNode.RootBehavior, behavior);
// register the view so it gets updated when the referenced behaviour gets updated.
refnode.ReferencedBehaviorWasModified += new ReferencedBehavior.ReferencedBehaviorWasModifiedEventDelegate(refnode_ReferencedBehaviorWasModified);
newnode = (Node)refnode;
newnode.CommentText = Resources.ThisIsReferenceTree;
newnode.CommentBackground = Node.CommentColor.Gray;
}
// prefab
else
{
// Copy all Pars from the prefab file into the current behavior node.
List<ParInfo> pars = new List<ParInfo>();
foreach (ParInfo par in b.Pars)
{
bool found = false;
foreach (ParInfo rootPar in rootB.Pars)
{
if (par.Name == rootPar.Name)
{
if (par.Type != rootPar.Type)
{
string errorMsg = string.Format(Resources.ParErrorInfo, par.Name, b.Label, rootB.Label);
MessageBox.Show(errorMsg, Resources.LoadError, MessageBoxButtons.OK);
return;
}
found = true;
break;
}
}
if (!found)
pars.Add(par);
}
rootB.Pars.AddRange(pars);
if (ParSettingsDock.IsVisible())
ParSettingsDock.Inspect((Node)_rootNode.RootBehavior);
//.........这里部分代码省略.........