本文整理汇总了C#中GameObject.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.Clone方法的具体用法?C# GameObject.Clone怎么用?C# GameObject.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.Clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Inject
/// <summary>
/// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab.
/// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it
/// will be used for the Prefab.
/// </summary>
/// <param name="obj">The object to inject as Prefab root object.</param>
public void Inject(GameObject obj)
{
// Dispose old content
if (obj == null)
{
if (this.objTree != null)
{
this.objTree.Dispose();
this.objTree = null;
}
}
// Inject new content
else
{
obj.OnSaving(true);
if (this.objTree != null)
obj.CopyTo(this.objTree);
else
this.objTree = obj.Clone();
obj.OnSaved(true);
this.objTree.BreakPrefabLink();
// Prevent recursion
foreach (GameObject child in this.objTree.ChildrenDeep)
{
if (child.PrefabLink != null && child.PrefabLink.Prefab == this)
{
child.BreakPrefabLink();
}
}
}
}
示例2: Inject
/// <summary>
/// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab.
/// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it
/// will be used for the Prefab.
/// </summary>
/// <param name="obj">The object to inject as Prefab root object.</param>
public void Inject(GameObject obj)
{
if (obj == null)
{
if (this.objTree != null)
{
this.objTree.Dispose();
this.objTree = null;
}
}
else
{
obj.OnSaving(true);
this.objTree = obj.Clone();
obj.OnSaved(true);
this.objTree.Parent = null;
this.objTree.prefabLink = null;
// Prevent recursion
foreach (GameObject child in this.objTree.ChildrenDeep)
if (child.PrefabLink != null && child.PrefabLink.Prefab == this)
child.BreakPrefabLink();
}
}
示例3: Init
public override void Init()
{
road = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road.jpg");
roadCorner = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner.jpg");
curbModel = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb.obj");
curbCorner = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb_corner.obj");
Random rand = new Random();
int xAmt = rand.Next(2, 7), zAmt = rand.Next(2, 7), scaleX = rand.Next(10, 30), scaleZ = rand.Next(10, 30);
int offset = 3;
AddRoadCorner(new Line(new Vector3f(0, 0, -2), new Vector3f(0, 0, 0)));
for (int x = 0; x <= xAmt; x++)
{
for (int i = 0; i < zAmt; i++)
{
AddRoad(new Line(new Vector3f(x * scaleX, 0, i * scaleZ), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2)));
AddRoadCorner(new Line(new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ)));
if (x == 0)
{
// long bar
Node curb2 = (Node)curbModel.Clone();
tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - 1);
tmpVec.y = HeightRoad(tmpVec);
curb2.SetLocalTranslation(tmpVec);
curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180));
curb2.SetLocalScale(new Vector3f(1, 1, scaleZ));
curbNode.AddChild(curb2);
}
else if (x == (xAmt - 1))
{
Node curb2 = (Node)curbModel.Clone();
tmpVec.Set((x + 1) * scaleX + 1, 0, (i) * scaleZ - 1);
tmpVec.y = HeightRoad(tmpVec);
curb2.SetLocalTranslation(tmpVec);
curb2.SetLocalScale(new Vector3f(1, 1, scaleZ));
curbNode.AddChild(curb2);
}
Node curb0 = (Node)curbModel.Clone();
tmpVec.Set(x * scaleX + 1, 0, i * scaleZ + 1);
tmpVec.y = HeightRoad(tmpVec);
curb0.SetLocalTranslation(tmpVec);
curb0.SetLocalScale(new Vector3f(1, 1, scaleZ - offset - 1));
curbNode.AddChild(curb0);
Node curb1 = (Node)curbModel.Clone();
tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - offset);
tmpVec.y = HeightRoad(tmpVec);
curb1.SetLocalTranslation(tmpVec);
curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180));
curb1.SetLocalScale(new Vector3f(1, 1, scaleZ - offset - 1));
curbNode.AddChild(curb1);
if (x != 0)
{
Node curbCorner1 = (Node)curbCorner.Clone();
tmpVec.Set((x) * scaleX - 2, 0, (i + 1) * scaleZ - offset + 1);
tmpVec.y = HeightRoad(tmpVec);
curbCorner1.SetLocalTranslation(tmpVec);
curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90));
curbNode.AddChild(curbCorner1);
}
if (x != xAmt)
{
Node curbCorner0 = (Node)curbCorner.Clone();
tmpVec.Set(x * scaleX + 2, 0, i * scaleZ);
tmpVec.y = HeightRoad(tmpVec);
curbCorner0.SetLocalTranslation(tmpVec);
curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90));
curbNode.AddChild(curbCorner0);
}
}
}
for (int z = 0; z <= zAmt; z++)
{
for (int i = 0; i < xAmt; i++)
{
AddRoad(new Line(new Vector3f(i * scaleX + 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1)));
AddRoadCorner(new Line(new Vector3f((i + 1) * scaleX - 1, 0, z * scaleZ - 1), new Vector3f((i + 1) * scaleX + 1, 0, z * scaleZ - 1)));
// long pieces
if (z == 0)
{
// long bar
Node curb2 = (Node)curbModel.Clone();
tmpVec.Set(i * scaleX, 0, z * scaleZ - 2);
tmpVec.y = HeightRoad(tmpVec);
curb2.SetLocalTranslation(tmpVec);
curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90));
curb2.SetLocalScale(new Vector3f(scaleX, 1, 1));
curbNode.AddChild(curb2);
}
//.........这里部分代码省略.........
示例4: Init
public override void Init()
{
Environment.AmbientLight.Color.Set(0.4f, 0.25f, 0.1f, 1.0f);
Environment.FogColor.Set(0.2f, 0.3f, 0.45f, 1.0f);
Environment.DirectionalLight.Direction.Set(0.6f, 1, 0.6f).NormalizeStore();
Environment.DirectionalLight.Color.Set(1.0f, 0.85f, 0.65f, 1.0f);
((PerspectiveCamera)Camera).FieldOfView = 75;
Camera.Far = 330;
ShadowMappingComponent smc;
RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment, new int[] { 2048, 1024 }));
smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;
RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter());
const float curb_scale_y = 0.4f;
road = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road.jpg");
roadnrm = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_nrm.jpg");
roadCorner = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner.jpg");
roadCornernrm = AssetManager.LoadTexture(AssetManager.GetAppPath() + "\\textures\\road_corner_nrm.jpg");
curbModel = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb.obj");
curbCorner = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\curb_corner.obj");
curbCorner.SetLocalScale(new Vector3f(1, curb_scale_y, 1));
Random rand = new Random();
int xAmt = rand.Next(2, 7), zAmt = rand.Next(2, 7), scaleX = rand.Next(10, 30), scaleZ = rand.Next(10, 30);
int offset = 3;
AddRoadCorner(new Line(new Vector3f(0, 0, -2), new Vector3f(0, 0, 0)));
for (int x = 0; x <= xAmt; x++)
{
for (int i = 0; i < zAmt; i++)
{
AddRoad(new Line(new Vector3f(x * scaleX, 0, i * scaleZ), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2)));
AddRoadCorner(new Line(new Vector3f(x * scaleX, 0, (i + 1) * scaleZ - 2), new Vector3f(x * scaleX, 0, (i + 1) * scaleZ)));
if (x == 0)
{
// long bar
Node curb2 = (Node)curbModel.Clone();
tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - 1);
tmpVec.y = HeightRoad(tmpVec);
curb2.SetLocalTranslation(tmpVec);
curb2.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180));
curb2.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ));
curbNode.AddChild(curb2);
}
else if (x == (xAmt - 1))
{
Node curb2 = (Node)curbModel.Clone();
tmpVec.Set((x + 1) * scaleX + 1, 0, (i) * scaleZ - 1);
tmpVec.y = HeightRoad(tmpVec);
curb2.SetLocalTranslation(tmpVec);
curb2.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ));
curbNode.AddChild(curb2);
}
Node curb0 = (Node)curbModel.Clone();
tmpVec.Set(x * scaleX + 1, 0, i * scaleZ + 1);
tmpVec.y = HeightRoad(tmpVec);
curb0.SetLocalTranslation(tmpVec);
curb0.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ - offset - 1));
curbNode.AddChild(curb0);
Node curb1 = (Node)curbModel.Clone();
tmpVec.Set(x * scaleX - 1, 0, (i + 1) * scaleZ - offset);
tmpVec.y = HeightRoad(tmpVec);
curb1.SetLocalTranslation(tmpVec);
curb1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180));
curb1.SetLocalScale(new Vector3f(1, curb_scale_y, scaleZ - offset - 1));
curbNode.AddChild(curb1);
if (x != 0)
{
Node curbCorner1 = (Node)curbCorner.Clone();
tmpVec.Set((x) * scaleX - 2, 0, (i + 1) * scaleZ - offset + 1);
tmpVec.y = HeightRoad(tmpVec);
curbCorner1.SetLocalTranslation(tmpVec);
curbCorner1.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 180 + 90));
curbNode.AddChild(curbCorner1);
}
if (x != xAmt)
{
Node curbCorner0 = (Node)curbCorner.Clone();
tmpVec.Set(x * scaleX + 2, 0, i * scaleZ);
tmpVec.y = HeightRoad(tmpVec);
curbCorner0.SetLocalTranslation(tmpVec);
curbCorner0.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, 90));
curbNode.AddChild(curbCorner0);
}
}
}
for (int z = 0; z <= zAmt; z++)
//.........这里部分代码省略.........