示例#1
0
文件: Agent.cs 项目: KSLcom/duality
		protected override void OnCopyTo(Component target, CloneProvider provider)
		{
			base.OnCopyTo(target, provider);
			Agent other = (Agent)target;
			other.Radius			= this.radius;
			other.toiHorizon		= this.toiHorizon;
			other.Sampler			= provider.RequestObjectClone(this.sampler);
			other.Characteristics	= provider.RequestObjectClone(this.characteristics);
			other.target			= provider.RequestObjectClone(this.target);
			other.suggestedVel		= this.suggestedVel;
		}
示例#2
0
		[Test] public void PartialCloning()
		{
			Random rnd = new Random();
			TestObject sourceStatic = new TestObject { DictField = new Dictionary<string,TestObject>
			{
				{ "A", new TestObject() },
				{ "B", new TestObject() },
				{ "C", new TestObject() },
			}};
			TestObject sourceDynamic = new TestObject { DictField = new Dictionary<string,TestObject>
			{
				{ "A", sourceStatic.DictField["A"] },
				{ "B", sourceStatic.DictField["B"] },
				{ "C", sourceStatic.DictField["C"] },
				{ "Root", sourceStatic },
				{ "Local", new TestObject() },
			}};

			// Copy only the static source objects
			CloneProvider provider = new CloneProvider();
			TestObject targetStatic = provider.CloneObject(sourceStatic, true);

			// When copying them again, they shouldn't actually be copied because they're still in the cache
			TestObject targetStatic2 = provider.CloneObject(sourceStatic, true);
			Assert.AreSame(targetStatic, targetStatic2);

			// Now copy the dynamic source objects and expect all static references to be resolved correctly
			TestObject targetDynamic = provider.CloneObject(sourceDynamic, true);
			Assert.AreSame(targetStatic, targetDynamic.DictField["Root"]);
			Assert.AreSame(targetStatic.DictField["A"], targetDynamic.DictField["A"]);
			Assert.AreSame(targetStatic.DictField["B"], targetDynamic.DictField["B"]);
			Assert.AreSame(targetStatic.DictField["C"], targetDynamic.DictField["C"]);

			// Now clear the cache and expect new objects from clone operations
			provider.ClearCachedMapping();
			TestObject targetStatic3 = provider.CloneObject(sourceStatic, true);
			Assert.AreNotSame(targetStatic, targetStatic3);

			// Expect an exception when attempting to clone the old results without clearing the cache
			Assert.Throws<InvalidOperationException>(() => provider.CloneObject(targetStatic3, true));

			// It should work fine after clearing the cache though.
			provider.ClearCachedMapping();
			Assert.DoesNotThrow(() => provider.CloneObject(targetStatic3, true));
		}
示例#3
0
 static PrefabLink()
 {
     changeListValueCloneProvider = new CloneProvider();
     changeListValueCloneProvider.SetExplicitUnwrap(typeof(System.Collections.ICollection));
 }
示例#4
0
        void ICloneExplicit.CopyDataTo(object targetObj, CloneProvider provider)
        {
            PrefabLink castObj = targetObj as PrefabLink;

            castObj.prefab = this.prefab;
            castObj.obj = this.obj;
            castObj.changes = null;

            if (this.changes != null)
            {
                castObj.changes = new List<VarMod>(this.changes.Count);
                for (int i = 0; i < this.changes.Count; i++)
                {
                    VarMod newVarMod = this.changes[i];
                    newVarMod.childIndex = new List<int>(newVarMod.childIndex);
                    castObj.changes.Add(newVarMod);
                }
            }
        }
示例#5
0
		void ICloneExplicit.CopyDataTo(object targetObj, CloneProvider provider)
		{
			JointInfo targetJoint = targetObj as JointInfo;
			this.CopyTo(targetJoint);
		}
示例#6
0
		void ICloneExplicit.CopyDataTo(object targetObj, CloneProvider provider)
		{
			ShapeInfo targetShape = targetObj as ShapeInfo;
			this.OnCopyTo(targetShape);
		}
示例#7
0
 protected override void OnCopyTo(Resource r, CloneProvider provider)
 {
     base.OnCopyTo(r, provider);
     Prefab c = r as Prefab;
     c.objTree = provider.RequestObjectClone(this.objTree);
 }
示例#8
0
        void ICloneable.CopyDataTo(object targetObj, CloneProvider provider)
        {
            Resource target = targetObj as Resource;

            this.OnCopyTo(target, provider);
        }
示例#9
0
 /// <summary>
 /// Deep-copies this Resource to the specified target Resource. The target Resource's Type must
 /// match this Resource's Type.
 /// </summary>
 /// <param name="r">The target Resource to copy this Resource's data to</param>
 public void CopyTo(Resource r)
 {
     CloneProvider.DeepCopyTo(this, r);
 }
示例#10
0
 /// <summary>
 /// Creates a deep copy of this Resource.
 /// </summary>
 /// <returns></returns>
 public Resource Clone()
 {
     return(CloneProvider.DeepClone(this));
 }
示例#11
0
        [Test] public void PartialCloning()
        {
            Random     rnd          = new Random();
            TestObject sourceStatic = new TestObject {
                DictField = new Dictionary <string, TestObject>
                {
                    { "A", new TestObject() },
                    { "B", new TestObject() },
                    { "C", new TestObject() },
                },
                HashsetField = new HashSet <TestObject>
                {
                    new TestObject()
                }
            };
            TestObject sourceDynamic = new TestObject {
                DictField = new Dictionary <string, TestObject>
                {
                    { "A", sourceStatic.DictField["A"] },
                    { "B", sourceStatic.DictField["B"] },
                    { "C", sourceStatic.DictField["C"] },
                    { "Root", sourceStatic },
                    { "Local", new TestObject() },
                },
                HashsetField = new HashSet <TestObject>
                {
                    sourceStatic.HashsetField.First()
                }
            };

            // Copy only the static source objects
            CloneProvider provider     = new CloneProvider();
            TestObject    targetStatic = provider.CloneObject(sourceStatic, true);

            // When copying them again, they shouldn't actually be copied because they're still in the cache
            TestObject targetStatic2 = provider.CloneObject(sourceStatic, true);

            Assert.AreSame(targetStatic, targetStatic2);

            // Now copy the dynamic source objects and expect all static references to be resolved correctly
            TestObject targetDynamic = provider.CloneObject(sourceDynamic, true);

            Assert.AreSame(targetStatic, targetDynamic.DictField["Root"]);
            Assert.AreSame(targetStatic.DictField["A"], targetDynamic.DictField["A"]);
            Assert.AreSame(targetStatic.DictField["B"], targetDynamic.DictField["B"]);
            Assert.AreSame(targetStatic.DictField["C"], targetDynamic.DictField["C"]);
            Assert.AreSame(targetStatic.HashsetField.First(), targetDynamic.HashsetField.First());

            // Now clear the cache and expect new objects from clone operations
            provider.ClearCachedMapping();
            TestObject targetStatic3 = provider.CloneObject(sourceStatic, true);

            Assert.AreNotSame(targetStatic, targetStatic3);

            // Expect an exception when attempting to clone the old results without clearing the cache
            Assert.Throws <InvalidOperationException>(() => provider.CloneObject(targetStatic3, true));

            // It should work fine after clearing the cache though.
            provider.ClearCachedMapping();
            Assert.DoesNotThrow(() => provider.CloneObject(targetStatic3, true));
        }
示例#12
0
文件: Pixmap.cs 项目: KSLcom/duality
			void ICloneExplicit.CopyDataTo(object targetObj, CloneProvider provider)
			{
				Layer targetLayer = targetObj as Layer;
				targetLayer.width = this.width;
				targetLayer.height = this.height;
				targetLayer.data = this.data == null ? null : this.data.Clone() as ColorRgba[];
			}