Exemplo n.º 1
0
        protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            base.OnSetupCloneTargets(targetObj, setup);
            Transform target = targetObj as Transform;

            setup.HandleObject(this.parentTransform, target.parentTransform, CloneBehavior.WeakReference);
        }
Exemplo n.º 2
0
        protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            base.OnSetupCloneTargets(targetObj, setup);
            SpriteRenderer target = targetObj as SpriteRenderer;

            setup.HandleObject(this.customMat, target.customMat);
        }
Exemplo n.º 3
0
        public virtual void CreateTargetObject(T source, ref T target, ICloneTargetSetup setup)
        {
            Type     objType     = source.GetType();
            TypeInfo objTypeInfo = objType.GetTypeInfo();

            target = objTypeInfo.CreateInstanceOf() as T;
        }
Exemplo n.º 4
0
        protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            base.OnSetupCloneTargets(targetObj, setup);
            AnimSpriteRenderer target = targetObj as AnimSpriteRenderer;

            setup.HandleObject(this.customFrameSequence, target.customFrameSequence);
        }
Exemplo n.º 5
0
        void ICloneExplicit.SetupCloneTargets(object target, ICloneTargetSetup setup)
        {
            ExplicitCloneTestObjectA targetCast = target as ExplicitCloneTestObjectA;

            setup.HandleObject(this.ListField, targetCast.ListField);
            setup.HandleObject(this.ListField2, targetCast.ListField2);
            setup.HandleObject(this.DictField, targetCast.DictField);
        }
Exemplo n.º 6
0
        void ICloneExplicit.SetupCloneTargets(object target, ICloneTargetSetup setup)
        {
            ExplicitCloneTestObjectA targetCast = target as ExplicitCloneTestObjectA;

            setup.HandleObject(this.ListField, targetCast.ListField);
            setup.HandleObject(this.ListField2, targetCast.ListField2);
            setup.HandleObject(this.DictField, targetCast.DictField);
        }
Exemplo n.º 7
0
 public override void CreateTargetObject(Regex source, ref Regex target, ICloneTargetSetup setup)
 {
     // Since Regex patterns can't be modified after creation, we'll always
     // need to set up a new one as part of the copy operation.
     if (source == null)
     {
         target = null;
     }
     else
     {
         target = new Regex(source.ToString(), source.Options, source.MatchTimeout);
     }
 }
Exemplo n.º 8
0
        public override void SetupCloneTargets(Delegate source, Delegate target, ICloneTargetSetup setup)
        {
            if (source == null)
            {
                return;
            }

            // Flag all invocation targets as weak references.
            Delegate[] invokeList = source.GetInvocationList();
            for (int i = 0; i < invokeList.Length; i++)
            {
                setup.HandleObject(invokeList[i].Target, null, CloneBehavior.WeakReference);
            }
        }
Exemplo n.º 9
0
 public override void CreateTargetObject(Delegate source, ref Delegate target, ICloneTargetSetup setup)
 {
     // Because delegates are immutable, we'll need to defer their creation until we know exactly how the cloned object graph looks like.
     target = null;
 }
Exemplo n.º 10
0
 public override void CreateTargetObject(CultureInfo source, ref CultureInfo target, ICloneTargetSetup setup)
 {
     // We'll just use the predefined Clone method that CultureInfo already provides
     if (source == null)
     {
         target = null;
     }
     else
     {
         target = source.Clone() as CultureInfo;
     }
 }
Exemplo n.º 11
0
        public override void SetupCloneTargets(IDictionary source, IDictionary target, ICloneTargetSetup setup)
        {
            Type dictType = source.GetType();

            Type[]   genArgs          = dictType.GenericTypeArguments;
            TypeInfo firstGenArgInfo  = genArgs[0].GetTypeInfo();
            TypeInfo secondGenArgInfo = genArgs[1].GetTypeInfo();

            // Handle all keys and values. Reuse existing objects wherever possible.
            if (!firstGenArgInfo.IsPlainOldData())
            {
                if (source == target)
                {
                    foreach (object key in source.Keys)
                    {
                        setup.HandleObject(key, key);
                    }
                }
                else
                {
                    foreach (var key in source.Keys)
                    {
                        setup.HandleObject(key, null);
                    }
                }
            }
            if (!secondGenArgInfo.IsPlainOldData())
            {
                if (source == target)
                {
                    foreach (object val in source.Values)
                    {
                        setup.HandleObject(val, val);
                    }
                }
                else
                {
                    foreach (DictionaryEntry entry in source)
                    {
                        setup.HandleObject(entry.Value, target[entry.Key]);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public override void SetupCloneTargets(IEnumerable source, IEnumerable target, ICloneTargetSetup setup)
        {
            ReflectedHashsetData reflectedHashsetData = GetReflectedHashsetData(source.GetType());

            if (!reflectedHashsetData.IsDeepCopyByAssignment)
            {
                if (source == target)
                {
                    foreach (object value in source)
                    {
                        setup.HandleObject(value, value);
                    }
                }
                else
                {
                    // In a hashset, there is no defined item identity, so we cannot find an equivalent
                    // between a source item and a target item. Map the source to null, so a new target will
                    // be created during the clone operation.
                    foreach (object value in source)
                    {
                        setup.HandleObject(value, null);
                    }
                }
            }
        }
Exemplo n.º 13
0
 void ICloneExplicit.SetupCloneTargets(object target, ICloneTargetSetup setup)
 {
     setup.HandleObject(this, target);
     this.OnSetupCloneTargets(target, setup);
 }
Exemplo n.º 14
0
 public override void SetupCloneTargets(Delegate source, Delegate target, ICloneTargetSetup setup)
 {
 }
Exemplo n.º 15
0
        void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            Component target = targetObj as Component;

            this.OnSetupCloneTargets(targetObj, setup);
        }
Exemplo n.º 16
0
 public override void SetupCloneTargets(Bitmap source, Bitmap target, ICloneTargetSetup setup)
 {
 }
Exemplo n.º 17
0
 public override void CreateTargetObject(Bitmap source, ref Bitmap target, ICloneTargetSetup setup)
 {
     target = new Bitmap(source.Width, source.Height);
 }
Exemplo n.º 18
0
 void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
 {
     setup.HandleObject(this, targetObj);
 }
Exemplo n.º 19
0
        void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            GameObject target        = targetObj as GameObject;
            bool       isPrefabApply = setup.Context is ApplyPrefabContext;

            if (!isPrefabApply)
            {
                // Destroy additional Components in the target GameObject
                if (target.compMap.Count > 0)
                {
                    List <Type> removeComponentTypes = null;
                    foreach (var pair in target.compMap)
                    {
                        if (!this.compMap.ContainsKey(pair.Key))
                        {
                            if (removeComponentTypes == null)
                            {
                                removeComponentTypes = new List <Type>();
                            }
                            removeComponentTypes.Add(pair.Key);
                        }
                    }
                    if (removeComponentTypes != null)
                    {
                        foreach (Type type in removeComponentTypes)
                        {
                            target.RemoveComponent(type);
                        }
                    }
                }
                // Destroy additional child objects in the target GameObject
                if (target.children != null)
                {
                    int thisChildCount = this.children != null ? this.children.Count : 0;
                    for (int i = target.children.Count - 1; i >= thisChildCount; i--)
                    {
                        target.children[i].Dispose();
                    }
                }
            }

            // Create missing Components in the target GameObject
            foreach (var pair in this.compMap)
            {
                Component targetComponent = target.AddComponent(pair.Key);
                setup.HandleObject(pair.Value, targetComponent, CloneBehavior.ChildObject);
            }
            // Create missing child objects in the target GameObject
            if (this.children != null)
            {
                for (int i = 0; i < this.children.Count; i++)
                {
                    GameObject targetChild;
                    if (target.children != null && target.children.Count > i)
                    {
                        targetChild = target.children[i];
                    }
                    else
                    {
                        targetChild = new GameObject(string.Empty, target);
                    }

                    setup.HandleObject(this.children[i], targetChild, CloneBehavior.ChildObject);
                }
            }

            // Handle referenced and child objects
            setup.HandleObject(this.scene, target.scene, CloneBehavior.WeakReference);
            setup.HandleObject(this.prefabLink, target.prefabLink);
        }
Exemplo n.º 20
0
		protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
		{
			base.OnSetupCloneTargets(targetObj, setup);
			RigidBody target = targetObj as RigidBody;

			// Handle ownership of shapes and joints
			if (this.shapes != null)
			{
				for (int i = 0; i < this.shapes.Count; i++)
				{
					ShapeInfo sourceShape = this.shapes[i];
					ShapeInfo targetShape = (target.shapes != null && target.shapes.Count > i) ? target.shapes[i] : null;
					setup.HandleObject(sourceShape, targetShape, CloneBehavior.ChildObject);
				}
			}
			if (this.joints != null)
			{
				for (int i = 0; i < this.joints.Count; i++)
				{
					JointInfo sourceJoint = this.joints[i];
					JointInfo targetJoint = (target.joints != null && target.joints.Count > i) ? target.joints[i] : null;
					setup.HandleObject(sourceJoint, targetJoint, CloneBehavior.ChildObject);
				}
			}
		}
Exemplo n.º 21
0
 /// <summary>
 /// This method prepares the <see cref="CopyTo"/> operation for custom Component Types.
 /// It uses reflection to prepare the cloning operation automatically, but you can implement
 /// this method in order to handle certain fields and cases manually. See <see cref="ICloneExplicit.SetupCloneTargets"/>
 /// for a more thorough explanation.
 /// </summary>
 /// <param name="setup"></param>
 protected virtual void OnSetupCloneTargets(object target, ICloneTargetSetup setup)
 {
     setup.HandleObject(this, target);
 }
Exemplo n.º 22
0
 public override void SetupCloneTargets(Regex source, Regex target, ICloneTargetSetup setup)
 {
     // Nothing to investigate or set up
 }
Exemplo n.º 23
0
 /// <summary>
 /// This method prepares the <see cref="CopyTo"/> operation for custom Resource Types.
 /// It uses reflection to prepare the cloning operation automatically, but you can implement
 /// this method in order to handle certain fields and cases manually. See <see cref="ICloneExplicit.SetupCloneTargets"/>
 /// for a more thorough explanation.
 /// </summary>
 /// <param name="setup"></param>
 protected virtual void OnSetupCloneTargets(object target, ICloneTargetSetup setup)
 {
 }
Exemplo n.º 24
0
        protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            base.OnSetupCloneTargets(targetObj, setup);
            Transform target = targetObj as Transform;

            setup.HandleObject(this.parentTransform, target.parentTransform, CloneBehavior.WeakReference);
        }
Exemplo n.º 25
0
        void ICloneSurrogate.SetupCloneTargets(object source, object target, out bool requireLateSetup, ICloneTargetSetup setup)
        {
            requireLateSetup = false;

            T targetCast = target as T;

            if (object.ReferenceEquals(targetCast, null) || this.IsImmutableTarget)
            {
                this.CreateTargetObject(source as T, ref targetCast, setup);
                if (!object.ReferenceEquals(targetCast, null))
                {
                    // If the source is null, map the old target to the new
                    setup.AddTarget(source ?? target, targetCast);
                }
                else
                {
                    requireLateSetup = true;
                }
            }
            else if (!object.ReferenceEquals(targetCast, null))
            {
                // If the source is null, map the old target to the new
                setup.AddTarget(source ?? target, target);
            }
            this.SetupCloneTargets(source as T, targetCast, setup);
        }
Exemplo n.º 26
0
 void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
 {
 }
Exemplo n.º 27
0
 public abstract void SetupCloneTargets(T source, T target, ICloneTargetSetup setup);
Exemplo n.º 28
0
 public override void SetupCloneTargets(CultureInfo source, CultureInfo target, ICloneTargetSetup setup)
 {
     // Nothing to investigate or set up
 }
Exemplo n.º 29
0
 void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
 {
     setup.HandleObject(this, targetObj);
 }
Exemplo n.º 30
0
        protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            base.OnSetupCloneTargets(targetObj, setup);
            AnimSpriteRenderer target = targetObj as AnimSpriteRenderer;

            setup.HandleObject(this.customFrameSequence, target.customFrameSequence);
        }
Exemplo n.º 31
0
		protected override void OnSetupCloneTargets(object targetObj, ICloneTargetSetup setup)
		{
			base.OnSetupCloneTargets(targetObj, setup);
			SpriteRenderer target = targetObj as SpriteRenderer;

			setup.HandleObject(this.customMat, target.customMat);
		}
Exemplo n.º 32
0
 void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
 {
 }
Exemplo n.º 33
0
        void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup)
        {
            FormattedText target = targetObj as FormattedText;

            setup.HandleObject(this.icons, target.icons);
            setup.HandleObject(this.flowAreas, target.flowAreas);
            setup.HandleObject(this.fonts, target.fonts);
        }
Exemplo n.º 34
0
 protected override void OnSetupCloneTargets(object target, ICloneTargetSetup setup)
 {
 }