本文整理汇总了C#中Actor.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Actor.AddComponent方法的具体用法?C# Actor.AddComponent怎么用?C# Actor.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actor
的用法示例。
在下文中一共展示了Actor.AddComponent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadExtensions
private static void LoadExtensions(Actor actor, JToken source)
{
// Check for flyable
if (source["flyable"] != null && (bool)source["flyable"])
{
// Add component
UserFlyable flyable = actor.AddComponent<UserFlyable>();
if (source["flyable_maxspeed"] != null) flyable.MaxSpeed = (float)source["flyable_maxspeed"];
if (source["flyable_accel"] != null) flyable.Acceleration = (float)source["flyable_accel"];
if (source["flyable_drag"] != null) flyable.Resistance = (float)source["flyable_drag"];
if (source["flyable_sens"] != null) flyable.Sensitivity = (float)source["flyable_sens"];
actor.Init();
}
// Check for spinning
if (source["spinning"] != null && (bool)source["spinning"])
{
// Add component
Spinning spinning = actor.AddComponent<Spinning>();
if (source["spinning_axis"] != null) spinning.Axis = ParseVector3(source["spinning_axis"]);
if (source["spinning_speed"] != null) spinning.Speed = (float)source["spinning_speed"];
actor.Init();
}
}
示例2: Main
/// <summary>
/// Entry point for the application
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
// Create the message pool
MessagePool pool = new MessagePool();
// Create the root actor
Actor root = new Actor(pool);
// Attach core systems
root.AddComponent<UserInputHandler>();
root.AddComponent<Renderer>();
root.AddComponent<MaterialSystem>();
root.AddComponent<SceneManager>();
root.AddComponent<SceneLoader>();
root.AddComponent<Sleeper>().TargetFPS = 60.0f;
// Attach exit listener
bool exit = false;
Listener<ExitMessage> exitlistener = root.AddComponent<Listener<ExitMessage>>() as Listener<ExitMessage>;
exitlistener.OnMessageReceived += (msg) => exit = true;
// Initialise
root.Init();
// Send the initialise message
InitialiseMessage initmsg = new InitialiseMessage();
pool.SendMessage(initmsg);
// Load the scene
if (!root.GetComponent<SceneLoader>().LoadSceneFromFile("scene.json"))
{
Console.WriteLine("Failed to load scene!");
Console.ReadKey();
return;
}
// Setup the frame message
FrameMessage framemsg = new FrameMessage();
framemsg.FrameNumber = 0;
framemsg.DeltaTime = 0.0f;
// Setup the timer
Stopwatch frametimer = new Stopwatch();
// Loop until done
while (!exit)
{
// Send frame message
frametimer.Start();
pool.SendMessage(framemsg);
frametimer.Stop();
framemsg.DeltaTime = (float)frametimer.Elapsed.TotalSeconds;
frametimer.Reset();
// Increase frame number
framemsg.FrameNumber++;
// Process windows events
Application.DoEvents();
}
// Send the shutdown message
ShutdownMessage shutdownmsg = new ShutdownMessage();
pool.SendMessage(shutdownmsg);
// Delete root actor and clean up
root.Destroy(true);
}
示例3: LoadPrimitive
private Actor LoadPrimitive(JToken source)
{
// Create the actor
Actor actor = new Actor(Owner.MessagePool);
// Add the required components to it
Transform transform = actor.AddComponent<Transform>();
MeshRenderer renderer = actor.AddComponent<MeshRenderer>();
// Load generic transform
LoadTransform(transform, source);
// Load primitive
if (source["primitive"] != null)
{
bool usetexcoords = source["texcoords"] != null && (bool)source["texcoords"];
bool usetangents = source["tangents"] != null && (bool)source["tangents"];
string prim = (string)source["primitive"];
switch (prim)
{
case "sphere":
renderer.Mesh = MeshBuilder.BuildSphere(1.0f, 5, usetexcoords, usetangents);
break;
case "cube":
renderer.Mesh = MeshBuilder.BuildCube();
break;
case "fsquad":
renderer.Mesh = MeshBuilder.BuildFullscreenQuad();
break;
case "plane":
renderer.Mesh = MeshBuilder.BuildPlane(usetexcoords, usetangents);
break;
}
}
if (source["material"] != null) renderer.Materials = new Material[] { Owner.GetComponent<MaterialSystem>().GetMaterial((string)source["material"]) };
// Initialise and return
actor.Init();
return actor;
}
示例4: LoadPPEffect
private Actor LoadPPEffect(JToken source)
{
// Create the actor
Actor actor = new Actor(Owner.MessagePool);
// Add the required components to it
PostProcessEffect effect = actor.AddComponent<PostProcessEffect>();
// Load effect settings
if (source["material"] != null) effect.Material = Owner.GetComponent<MaterialSystem>().GetMaterial((string)source["material"]);
if (source["priority"] != null) effect.EffectPriority = (int)source["priority"];
// Initialise and return
actor.Parent = Owner;
actor.Init();
return actor;
}
示例5: LoadParticleSystem
private Actor LoadParticleSystem(JToken source)
{
// Create the actor
Actor actor = new Actor(Owner.MessagePool);
// Add the required components to it
Transform transform = actor.AddComponent<Transform>();
ParticleSystem psystem = actor.AddComponent<ParticleSystem>();
// Load generic transform
LoadTransform(transform, source);
// Load particle system settings
if (source["particlecount"] != null) psystem.ParticleCount = (int)source["particlecount"];
if (source["transfermode"] != null)
{
string transfermode = (string)source["transfermode"];
switch (transfermode)
{
case "add":
psystem.TransferMode = ParticleTransferMode.Add;
break;
case "alpha":
psystem.TransferMode = ParticleTransferMode.Alpha;
break;
}
}
if (source["material"] != null) psystem.Material = Owner.GetComponent<MaterialSystem>().GetMaterial((string)source["material"]);
if (source["particlelife"] != null) psystem.ParticleLife = (float)source["particlelife"];
if (source["startcolour"] != null) psystem.StartColour = ParseColor4(source["startcolour"]);
if (source["endcolour"] != null) psystem.EndColour = ParseColor4(source["endcolour"]);
if (source["startsize"] != null) psystem.StartSize = (float)source["startsize"];
if (source["endsize"] != null) psystem.EndSize = (float)source["endsize"];
if (source["initialvelocity"] != null) psystem.InitialVelocity = ParseVector3(source["initialvelocity"]);
if (source["randomvelocity"] != null) psystem.RandomVelocity = ParseVector3(source["randomvelocity"]);
if (source["randomposition"] != null) psystem.RandomPosition = ParseVector3(source["randomposition"]);
if (source["acceleration"] != null) psystem.Acceleration = ParseVector3(source["acceleration"]);
if (source["emissionrate"] != null) psystem.EmissionRate = (int)source["emissionrate"];
// Initialise and return
actor.Parent = Owner;
actor.Init();
return actor;
}
示例6: LoadModel
private Actor LoadModel(JToken source)
{
// Create the actor
Actor actor = new Actor(Owner.MessagePool);
// Add the required components to it
Transform transform = actor.AddComponent<Transform>();
// Load generic transform
LoadTransform(transform, source);
// Load model
if (source["model"] != null)
{
string model = (string)source["model"];
SBMLoader loader = new SBMLoader("models/" + model + ".sbm");
string err;
if (!loader.Load(out err))
{
Console.WriteLine("Failed to load model '{0}'! ({1})", model, err);
return null;
}
// Is there more than 1 mesh?
if (loader.MeshCount > 1)
{
for (int i = 0; i < loader.MeshCount; i++)
{
Actor tmp = new Actor(Owner.MessagePool);
tmp.AddComponent<Transform>();
MeshRenderer renderer = tmp.AddComponent<MeshRenderer>();
Mesh mesh;
string[] materialnames;
loader.GetMesh(i, out mesh, out materialnames);
Material[] materials = new Material[materialnames.Length];
for (int j = 0; j < materials.Length; j++)
{
materials[j] = Owner.GetComponent<MaterialSystem>().GetMaterial(materialnames[j]);
if (materials[j] == null) Console.WriteLine("Failed to load material '{0}'!", materialnames[j]);
}
renderer.Mesh = mesh;
renderer.Materials = materials;
tmp.Parent = actor;
tmp.Init();
}
}
else
{
MeshRenderer renderer = actor.AddComponent<MeshRenderer>();
Mesh mesh;
string[] materialnames;
loader.GetMesh(0, out mesh, out materialnames);
Material[] materials = new Material[materialnames.Length];
for (int j = 0; j < materials.Length; j++)
materials[j] = Owner.GetComponent<MaterialSystem>().GetMaterial(materialnames[j]);
renderer.Mesh = mesh;
renderer.Materials = materials;
}
}
// Initialise and return
actor.Init();
return actor;
}
示例7: LoadLight
private Actor LoadLight(JToken source)
{
// Create the actor
Actor actor = new Actor(Owner.MessagePool);
// Add the required components to it
Transform transform = actor.AddComponent<Transform>();
Light light = actor.AddComponent<Light>();
// Load generic transform
LoadTransform(transform, source);
// Load light type
if (source["light"] != null)
{
string lighttype = (string)source["light"];
switch (lighttype)
{
case "ambient":
light.Type = LightType.Ambient;
break;
case "directional":
light.Type = LightType.Directional;
break;
case "point":
light.Type = LightType.Point;
break;
case "spot":
light.Type = LightType.Spot;
break;
}
}
else
light.Type = LightType.None;
// Load generic light properties
if (source["colour"] != null) light.Colour = ParseColor3(source["colour"]);
if (source["range"] != null) light.Range = (float)source["range"];
// Load shadow caster
if (source["castshadows"] != null && (bool)source["castshadows"])
{
ShadowCaster caster = actor.AddComponent<ShadowCaster>();
caster.Resolution = 512;
if (source["shadowmapsize"] != null) caster.Resolution = (int)source["shadowmapsize"];
if (source["shadowcasterscale"] != null) caster.Scale = (int)source["shadowcasterscale"];
}
// Initialise and return
actor.Parent = Owner;
actor.Init();
return actor;
}
示例8: LoadCamera
private Actor LoadCamera(JToken source)
{
// Create the actor
Actor actor = new Actor(Owner.MessagePool);
// Add the required components to it
Transform transform = actor.AddComponent<Transform>();
Camera camera = actor.AddComponent<Camera>();
// Load generic transform
LoadTransform(transform, source);
// Load camera
if (source["projectiontype"] != null)
{
string proj = (string)source["projectiontype"];
if (proj == "perspective") camera.ProjectionType = CameraType.Perspective;
if (proj == "orthographic") camera.ProjectionType = CameraType.Orthographic;
}
if (source["fov"] != null) camera.FoV = (float)source["fov"];
if (source["nearz"] != null) camera.NearZ = (float)source["nearz"];
if (source["farz"] != null) camera.FarZ = (float)source["farz"];
if (source["viewport"] != null)
{
var viewport = new SlimDX.Direct3D11.Viewport(0.0f, 0.0f, (float)source["viewport"][0], (float)source["viewport"][1]);
viewport.MaxZ = 1.0f;
viewport.MinZ = 0.0f;
camera.Viewport = viewport;
}
if (source["skybox"] != null)
{
camera.Background = BackgroundType.Skybox;
camera.Skybox = Owner.GetComponent<MaterialSystem>().GetMaterial((string)source["skybox"]);
}
if (source["userendertarget"] != null && (bool)source["userendertarget"])
{
camera.Target = Owner.GetComponent<Renderer>().CreateRenderTarget(1, (int)camera.Viewport.Width, (int)camera.Viewport.Height, "camera_rt");
camera.Target.AddDepthComponent();
camera.Target.AddTextureComponent();
camera.Target.Finish();
}
if (source["reflectedcamera"] != null && (bool)source["reflectedcamera"])
{
ReflectedCamera reflectedcam = actor.AddComponent<ReflectedCamera>();
reflectedcam.ReflectionPlane = new Plane((float)source["reflectionplane"][0], (float)source["reflectionplane"][1], (float)source["reflectionplane"][2], (float)source["reflectionplane"][3]);
reflectedcam.MainCamera = actors[(string)source["reflectionmimic"]];
reflectedcam.ReflectionTarget = Owner.GetComponent<MaterialSystem>().GetMaterial((string)source["reflectiontarget"]);
}
if (source["enabled"] != null) camera.Enabled = (bool)source["enabled"];
if (source["priority"] != null) camera.RenderPriority = (int)source["priority"];
if (source["clip_plane"] != null)
{
camera.UseClipping = true;
camera.ClipPlane = new Plane((float)source["clip_plane"][0], (float)source["clip_plane"][1], (float)source["clip_plane"][2], (float)source["clip_plane"][3]);
}
// Initialise and return
actor.Init();
return actor;
}