本文整理汇总了C#中DomNode.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# DomNode.Cast方法的具体用法?C# DomNode.Cast怎么用?C# DomNode.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomNode
的用法示例。
在下文中一共展示了DomNode.Cast方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DomNode
/// <summary>
/// Finish MEF intialization for the component by creating DomNode tree for application data.</summary>
void IInitializable.Initialize()
{
m_mainform.Shown += (sender, e) =>
{
// create root node.
var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement);
rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game");
// create Orc game object and add it to rootNode.
var orc = CreateOrc();
rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc);
// add a child Orc.
var orcChildList = orc.GetChildList(Schema.orcType.orcChild);
orcChildList.Add(CreateOrc("Child Orc1"));
rootNode.InitializeExtensions();
var edContext = rootNode.Cast<GameEditingContext>();
edContext.Set(orc);
// set active context and select orc object.
m_contextRegistry.ActiveContext = rootNode;
};
}
示例2: Write
// Scan for all sub-circuits that are referenced directly or indirectly by a module in
// the root of the document
public override void Write(DomNode root, Stream stream, Uri uri)
{
m_usedSubCircuits = new HashSet<Sce.Atf.Controls.Adaptable.Graphs.SubCircuit>();
foreach (var module in root.Cast<Circuit>().Elements)
FindUsedSubCircuits(module.DomNode);
base.Write(root, stream, uri);
}
示例3: Write
// Scan for all sub-circuits that are referenced directly or indirectly by a module in
// the root of the document
public override void Write(DomNode root, Stream stream, Uri uri)
{
#pragma warning disable 618 //mastered sub-circuits are obsolete
m_usedSubCircuits = new HashSet<Sce.Atf.Controls.Adaptable.Graphs.SubCircuit>();
foreach (var module in root.Cast<Circuit>().Elements)
FindUsedSubCircuits(module.DomNode);
#pragma warning restore 618
base.Write(root, stream, uri);
}
示例4: AddChild
public bool AddChild(object child)
{
bool added = false;
ILayer layer = child.As<ILayer>();
if (layer != null)
{
if (!Layers.Contains(layer))
{
Layers.Add(layer);
added = true;
}
}
else
{
IReference<IGameObject> reference = child.As<IReference<IGameObject>>();
if (reference != null)
{
if (reference.Target != null
&& !this.Contains(reference.Target)
&& !GameObjectReferences.Contains(reference))
{
GameObjectReferences.Add(reference);
added = true;
}
}
else
{
IGameObject gameObject = child.As<IGameObject>();
if (gameObject != null && !this.Contains(gameObject))
{
DomNode referenceNode = new DomNode(Schema.gameObjectReferenceType.Type);
reference = referenceNode.Cast<IReference<IGameObject>>();
reference.Target = gameObject;
GameObjectReferences.Add(reference);
added = true;
}
}
}
return added;
}
示例5: Init
private void Init()
{
NativeObjectAdapter curLevel = GameEngine.GetGameLevel();
try
{
// create new document by creating a Dom node of the root type defined by the schema
DomNode rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement);
INameable nameable = rootNode.Cast<INameable>();
nameable.Name = "ThumbnailGenerator";
NativeObjectAdapter gameLevel = rootNode.Cast<NativeObjectAdapter>();
GameEngine.CreateObject(gameLevel);
GameEngine.SetGameLevel(gameLevel);
gameLevel.UpdateNativeOjbect();
NativeGameWorldAdapter gworld = rootNode.Cast<NativeGameWorldAdapter>();
m_game = rootNode.Cast<IGame>();
IGameObjectFolder rootFolder = m_game.RootGameObjectFolder;
m_renderSurface = new TextureRenderSurface(96, 96);
m_renderState = new RenderState();
m_renderState.RenderFlag = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit | GlobalRenderFlags.Shadows;
}
finally
{
GameEngine.SetGameLevel(curLevel);
}
m_mainWindow.Closed += delegate
{
GameEngine.DestroyObject(m_game.Cast<NativeObjectAdapter>());
m_renderSurface.Dispose();
m_renderState.Dispose();
};
}
示例6: ProjectGhost
/// <summary>
/// Projects the ghost</summary>
private void ProjectGhost(DomNode ghost,
Ray3F rayw,
HitRecord? hit)
{
ITransformable xformnode = ghost.Cast<ITransformable>();
IBoundable bnode = ghost.As<IBoundable>();
AABB box = bnode.BoundingBox;
Vec3F pt;
if (hit.HasValue && hit.Value.hasNormal)
{
Vec3F rad = box.Radius;
Vec3F norm = hit.Value.normal;
Vec3F absNorm = Vec3F.Abs(norm);
Vec3F offset = Vec3F.ZeroVector;
if (absNorm.X > absNorm.Y)
{
if (absNorm.X > absNorm.Z)
offset.X = norm.X > 0 ? rad.X : -rad.X;
else
offset.Z = norm.Z > 0 ? rad.Z : -rad.Z;
}
else
{
if (absNorm.Y > absNorm.Z)
offset.Y = norm.Y > 0 ? rad.Y : -rad.Y;
else
offset.Z = norm.Z > 0 ? rad.Z : -rad.Z;
}
Vec3F localCenter = box.Center - xformnode.Translation;
pt = hit.Value.hitPt + (offset - localCenter);
}
else
{
float offset = 6.0f * box.Radius.Length;
pt = rayw.Origin + offset * rayw.Direction;
}
if (ViewType == ViewTypes.Front)
pt.Z = 0.0f;
else if (ViewType == ViewTypes.Top)
pt.Y = 0.0f;
else if (ViewType == ViewTypes.Left)
pt.X = 0.0f;
xformnode.Translation = pt;
}
示例7: UnregisterControl
/// <summary>
/// Unregisters the Control from the IContextRegistry and IControlHostService and disposes
/// it and sets the circuitNode's ViewingContext's Control property to null.</summary>
private void UnregisterControl(DomNode circuitNode, Control control)
{
//it's OK if the CircuitEditingContext was already removed or wasn't added to IContextRegistry.
m_contextRegistry.RemoveContext(circuitNode.As<CircuitEditingContext>());
m_controlHostService.UnregisterControl(control);
control.Visible = false;
control.Dispose();
m_circuitNodeControls.Remove(circuitNode);
circuitNode.Cast<ViewingContext>().Control = null;
}
示例8: New
public static Settings New(ChildInfo childInfo)
{
DomNode node = new DomNode(Schema.settingsType.Type, childInfo);
return node.Cast<Settings>();
}
示例9: Read
/// <summary>
/// Reads in the data for an EventSequenceDocument from the given stream</summary>
/// <remarks>This method proves the concept that a document can be persisted in a custom
/// file format that is not XML.</remarks>
/// <param name="stream">Stream with event sequence data</param>
/// <returns>A valid EventSequenceDocument if successful or null if the stream's data is invalid</returns>
public static EventSequenceDocument Read(Stream stream)
{
using (StreamReader reader = new StreamReader(stream))
{
string line = reader.ReadLine();
if (line != "eventSequence")
return null;
DomNode root = new DomNode(DomTypes.eventSequenceType.Type, DomTypes.eventSequenceRootElement);
bool readLineForEvent = true;
while (true)
{
// The root has a sequence of children that are eventType nodes.
if (readLineForEvent)
line = reader.ReadLine();
if (string.IsNullOrEmpty(line))
break;
readLineForEvent = true;
DomNode eventNode;
if (!ReadEvent(line, out eventNode))
break;
root.GetChildList(DomTypes.eventSequenceType.eventChild).Add(eventNode);
// Each eventType node may have zero or more resourceType nodes.
while (true)
{
line = reader.ReadLine();
if (string.IsNullOrEmpty(line))
break;
DomNode resourceNode;
if (!ReadResource(line, out resourceNode))
{
// might be a line for an event
readLineForEvent = false;
break;
}
eventNode.GetChildList(DomTypes.eventType.resourceChild).Add(resourceNode);
}
}
return root.Cast<EventSequenceDocument>();
}
}
示例10: CreateTestCircuitProgrammatically
// Create circuit DOM hierarchy programmatically
static public DomNode CreateTestCircuitProgrammatically(SchemaLoader schemaLoader)
{
var rootNode = new DomNode(Schema.circuitDocumentType.Type, Schema.circuitRootElement);
// create an empty root prototype folder( required child by schema)
rootNode.SetChild(
Schema.circuitDocumentType.prototypeFolderChild,
new DomNode(Schema.prototypeFolderType.Type));
var circuit = rootNode.Cast<Circuit>();
var inputFiles = new DomNode(Schema.groupType.Type).Cast<Group>();
inputFiles.Id = "groupInputFiles";
inputFiles.Name = "Input Files".Localize();
inputFiles.Bounds = new Rectangle(64, 96, 0, 0); // set node location, size will be auto-computed
var firstWavgGroup = new DomNode(Schema.groupType.Type).Cast<Group>();
firstWavgGroup.Id = "first.Wav";
firstWavgGroup.Name = "first".Localize("as in, 'the first file'") + ".wav";
var buttonType = schemaLoader.GetNodeType(Schema.NS + ButtonTypeName);
var button1 = new DomNode(buttonType).Cast<Module>();
button1.Id = "button1";
button1.Bounds = new Rectangle(0, 0, 0, 0);
var button2 = new DomNode(buttonType).Cast<Module>();
button2.Bounds = new Rectangle(0, 64, 0, 0);
button2.Id = "button2";
firstWavgGroup.Elements.Add(button1);
firstWavgGroup.Elements.Add(button2);
firstWavgGroup.Expanded = true;
firstWavgGroup.Update();
var secondWavgGroup = new DomNode(Schema.groupType.Type).Cast<Group>();
secondWavgGroup.Id = "second.Wav";
secondWavgGroup.Name = "second".Localize("as in, 'the second file'") + ".wav";
var button3 = new DomNode(buttonType).Cast<Module>();
button3.Id = "button3";
button3.Bounds = new Rectangle(0, 0, 0, 0);
var button4 = new DomNode(buttonType).Cast<Module>();
button4.Bounds = new Rectangle(0, 64, 0, 0);
button4.Id = "button4";
secondWavgGroup.Elements.Add(button3);
secondWavgGroup.Elements.Add(button4);
secondWavgGroup.Expanded = true;
secondWavgGroup.Update();
secondWavgGroup.Bounds = new Rectangle(0, 224, 0, 0);
inputFiles.Elements.Add(firstWavgGroup);
inputFiles.Elements.Add(secondWavgGroup);
inputFiles.Update();
inputFiles.Expanded = true;
circuit.Elements.Add(inputFiles);
var structure = new DomNode(Schema.groupType.Type).Cast<Group>();
structure.Id = "structure".Localize("this is the name of a group of circuit elements; the name is arbitrary");
structure.Name = "structure".Localize("this is the name of a group of circuit elements; the name is arbitrary");
structure.Bounds = new Rectangle(352, 96, 0, 0);
var subStream0 = new DomNode(Schema.groupType.Type).Cast<Group>();
subStream0.Id = "subStream0".Localize("this is the name of a group of circuit elements; the name is arbitrary");
subStream0.Name = "sub-stream 0".Localize("this is the name of a group of circuit elements; the name is arbitrary");
var lightType = schemaLoader.GetNodeType(Schema.NS + LightTypeName);
var light1 = new DomNode(lightType).Cast<Module>();
light1.Id = "light1";
light1.Bounds = new Rectangle(0, 0, 0, 0);
var light2 = new DomNode(lightType).Cast<Module>();
light2.Id = "light2";
light2.Bounds = new Rectangle(0, 64, 0, 0);
var light3 = new DomNode(lightType).Cast<Module>();
light3.Id = "light3";
light3.Bounds = new Rectangle(0, 128, 0, 0);
var light4 = new DomNode(lightType).Cast<Module>();
light4.Id = "light4";
light4.Bounds = new Rectangle(0, 192, 0, 0);
var light5 = new DomNode(lightType).Cast<Module>();
light5.Id = "light5";
light5.Bounds = new Rectangle(0, 256, 0, 0);
var light6 = new DomNode(lightType).Cast<Module>();
light6.Id = "light6";
light6.Bounds = new Rectangle(0, 320, 0, 0);
subStream0.Elements.Add(light1);
subStream0.Elements.Add(light2);
//.........这里部分代码省略.........
示例11: Init
private void Init()
{
if (m_game != null)
return;
NativeObjectAdapter curLevel = GameEngine.GetGameLevel();
try
{
// create new document by creating a Dom node of the root type defined by the schema
DomNode rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement);
INameable nameable = rootNode.As<INameable>();
nameable.Name = "Game";
NativeObjectAdapter gameLevel = rootNode.Cast<NativeObjectAdapter>();
GameEngine.CreateObject(gameLevel);
GameEngine.SetGameLevel(gameLevel);
gameLevel.UpdateNativeOjbect();
NativeGameWorldAdapter gworld = rootNode.Cast<NativeGameWorldAdapter>();
m_game = rootNode.Cast<IGame>();
IGameObjectFolder rootFolder = m_game.RootGameObjectFolder;
m_renderSurface.Game = m_game;
}
finally
{
GameEngine.SetGameLevel(curLevel);
}
m_mainWindow.Closed += delegate
{
GameEngine.DestroyObject(m_game.Cast<NativeObjectAdapter>());
m_renderSurface.Dispose();
};
}
示例12: New
public static Character New(ChildInfo childInfo)
{
DomNode node = new DomNode(Schema.characterType.Type, childInfo);
return node.Cast<Character>();
}