void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { GameObject target = targetObj as GameObject; // Copy plain old data target.name = this.name; target.active = this.active; target.initState = this.initState; if (!operation.Context.PreserveIdentity) { target.identifier = this.identifier; } // Copy Components from source to target for (int i = 0; i < this.compList.Count; i++) { operation.HandleObject(this.compList[i]); } // Copy child objects from source to target if (this.children != null) { for (int i = 0; i < this.children.Count; i++) { operation.HandleObject(this.children[i]); } } // Copy referenced and child objects operation.HandleObject(this.scene, ref target.scene, true); operation.HandleObject(this.prefabLink, ref target.prefabLink, true); }
void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { ExplicitCloneTestObjectA target = targetObj as ExplicitCloneTestObjectA; target.StringField = this.StringField; target.DataField = this.DataField; operation.HandleObject(this.ListField, ref target.ListField); operation.HandleObject(this.ListField2, ref target.ListField2); operation.HandleObject(this.DictField, ref target.DictField); }
void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { ExplicitCloneTestObjectA target = targetObj as ExplicitCloneTestObjectA; target.StringField = this.StringField; target.DataField = this.DataField; operation.HandleObject(this.ListField, ref target.ListField); operation.HandleObject(this.ListField2, ref target.ListField2); operation.HandleObject(this.DictField, ref target.DictField); }
public override void CopyDataTo(IDictionary source, IDictionary target, ICloneOperation operation) { Type dictType = source.GetType(); Type[] genArgs = dictType.GenericTypeArguments; TypeInfo firstGenArgInfo = genArgs[0].GetTypeInfo(); TypeInfo secondGenArgInfo = genArgs[1].GetTypeInfo(); // Determine unwrapping behavior to provide faster / more optimized loops. bool isKeyPlainOld = firstGenArgInfo.IsDeepCopyByAssignment(); bool isValuePlainOld = secondGenArgInfo.IsDeepCopyByAssignment(); // Copy all pairs. Don't check each pair, if the Type won't be unwrapped anyway. target.Clear(); if (!isKeyPlainOld && !isValuePlainOld) { foreach (DictionaryEntry pair in source) { object keyTarget = null; object valueTarget = null; operation.HandleObject(pair.Key, ref keyTarget); operation.HandleObject(pair.Value, ref valueTarget); target.Add(keyTarget, valueTarget); } } else if (!isKeyPlainOld) { foreach (DictionaryEntry pair in source) { object keyTarget = null; operation.HandleObject(pair.Key, ref keyTarget); target.Add(keyTarget, pair.Value); } } else if (!isValuePlainOld) { foreach (DictionaryEntry pair in source) { object valueTarget = null; operation.HandleObject(pair.Value, ref valueTarget); target.Add(pair.Key, valueTarget); } } else { foreach (DictionaryEntry pair in source) { target.Add(pair.Key, pair.Value); } } }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); TextRenderer target = targetObj as TextRenderer; target.blockAlign = this.blockAlign; target.colorTint = this.colorTint; operation.HandleValue(ref this.iconMat, ref target.iconMat); operation.HandleObject(this.text, ref target.text); operation.HandleObject(this.customMat, ref target.customMat); }
/// <summary> /// Special version of <see cref="ICloneOperation.HandleObject"/> for cases where the target object graph alreay /// exists and it is undesireable for a source value of null to overwrite a non-null target value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="operation"></param> /// <param name="source"></param> /// <param name="target"></param> /// <param name="dontNullifyExternal"></param> /// <returns></returns> public static void HandleObject <T>(this ICloneOperation operation, T source, ref T target, bool dontNullifyExternal) where T : class { if (object.ReferenceEquals(source, null) && dontNullifyExternal && !operation.IsTarget(target)) { return; } operation.HandleObject(source, ref target); }
void ICloneExplicit.CopyDataTo(object target, ICloneOperation operation) { operation.HandleObject(this, target); // Only assign WeakReferencedObject, if it was cloned as well. Otherwise, discard. ReferenceBehaviourTestObject testTarget = target as ReferenceBehaviourTestObject; testTarget.WeakReferencedObject = operation.GetWeakTarget(this.WeakReferencedObject); }
private static void CopyDataTo_DeepCopyByTraversal <TItem>(HashSet <TItem> source, HashSet <TItem> target, ICloneOperation operation) where TItem : class { target.Clear(); foreach (TItem value in source) { TItem handledObject = null; operation.HandleObject(value, ref handledObject); target.Add(handledObject); } }
void ICloneExplicit.CopyDataTo(object target, ICloneOperation operation) { operation.HandleObject(this, target); // If the source objects parent was cloned as well, assign its // cloned instance to our target object. WeakReferenceTestObject testTarget = target as WeakReferenceTestObject; testTarget.Parent = operation.GetWeakTarget(this.Parent); }
void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { GameObjectCopy target = targetObj as GameObjectCopy; // Copy plain old data target.name = this.name; target.initState = this.initState; if (!operation.Context.PreserveIdentity) { target.identifier = this.identifier; } // Copy Components from source to target for (int i = 0; i < this.compList.Count; i++) { operation.HandleObject(this.compList[i]); } // Copy child objects from source to target if (this.children != null) { for (int i = 0; i < this.children.Count; i++) { operation.HandleObject(this.children[i]); } } // Copy the objects parent scene as a weak reference, i.e. // by assignment, and only when the the scene is itself part of the // copied object graph. That way, cloning a GameObject but not its // scene will result in a clone that doesn't reference a parent scene. SceneCopy targetScene = operation.GetWeakTarget(this.scene); if (targetScene != null) { target.scene = targetScene; } // Copy the objects prefab link operation.HandleObject(this.prefabLink, ref target.prefabLink, true); }
private static void CopyDataTo_NotPlainOldData <TItem>(HashSet <TItem> source, HashSet <TItem> target, ICloneOperation operation) where TItem : class { target.Clear(); foreach (TItem value in source) { TItem handledObject = null; if (!operation.HandleObject(value, ref handledObject)) { continue; } target.Add(handledObject); } }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); SpriteRenderer target = targetObj as SpriteRenderer; target.rect = this.rect; target.colorTint = this.colorTint; target.rectMode = this.rectMode; target.offset = this.offset; operation.HandleValue(ref this.sharedMat, ref target.sharedMat); operation.HandleObject(this.customMat, ref target.customMat); }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); AnimSpriteRenderer target = targetObj as AnimSpriteRenderer; target.animFirstFrame = this.animFirstFrame; target.animFrameCount = this.animFrameCount; target.animDuration = this.animDuration; target.animLoopMode = this.animLoopMode; target.animTime = this.animTime; target.animPaused = this.animPaused; operation.HandleObject(this.customFrameSequence, ref target.customFrameSequence); }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); Transform target = targetObj as Transform; target.deriveAngle = this.deriveAngle; target.ignoreParent = this.ignoreParent; target.pos = this.pos; target.angle = this.angle; target.scale = this.scale; target.posAbs = this.posAbs; target.angleAbs = this.angleAbs; target.scaleAbs = this.scaleAbs; target.rotationDirAbs = this.rotationDirAbs; target.tempVel = this.tempVel; target.tempVelAbs = this.tempVelAbs; target.tempAngleVel = this.tempAngleVel; target.tempAngleVelAbs = this.tempAngleVelAbs; target.velAbs = this.velAbs; target.vel = this.vel; target.angleVel = this.angleVel; target.angleVelAbs = this.angleVelAbs; // Initialize parentTransform, because it's required for UpdateAbs but is null until OnLoaded, which will be called after applying prefabs. if (target.gameobj != null && target.gameobj.Parent != null) { target.parentTransform = target.gameobj.Parent.Transform; } // Handle parentTransform manually to prevent null-overwrites operation.HandleObject(this.parentTransform, ref target.parentTransform, true); // Update absolute transformation data, because the target is relative to a different parent. target.UpdateAbs(); }
void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { FormattedText target = targetObj as FormattedText; operation.HandleObject(this.icons, ref target.icons); operation.HandleObject(this.flowAreas, ref target.flowAreas); operation.HandleObject(this.fonts, ref target.fonts); target.icons = this.icons != null ? this.icons.Clone() as Icon[] : null; target.flowAreas = this.flowAreas != null ? this.flowAreas.Clone() as FlowArea[] : null; target.fonts = this.fonts != null ? this.fonts.Clone() as ContentRef<Font>[] : null; target.sourceText = this.sourceText; target.maxWidth = this.maxWidth; target.maxHeight = this.maxHeight; target.wrapMode = this.wrapMode; target.lineAlign = this.lineAlign; target.ApplySource(target.sourceText); }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); SpriteRenderer target = targetObj as SpriteRenderer; target.rect = this.rect; target.colorTint = this.colorTint; target.rectMode = this.rectMode; target.offset = this.offset; operation.HandleValue(ref this.sharedMat, ref target.sharedMat); operation.HandleObject(this.customMat, ref target.customMat); }
/// <summary> /// Special version of <see cref="ICloneOperation.HandleObject"/> for cases where the target object is stored /// in a data structure that does not allow by-ref access or re-assignment of the target object. When possible, /// prefer the by-ref base version. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="operation"></param> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> public static bool HandleObject <T>(this ICloneOperation operation, T source, T target = null) where T : class { T targetObj = target; return(operation.HandleObject(source, ref targetObj)); }
/// <summary> /// Special version of <see cref="ICloneOperation.HandleObject"/> for cases where the target object is stored /// in a data structure that does not allow by-ref access or re-assignment of the target object. When possible, /// prefer the by-ref base version. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="operation"></param> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> public static void HandleObject <T>(this ICloneOperation operation, T source, T target = null) where T : class { T targetObj = target; operation.HandleObject(source, ref targetObj); }
void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { operation.HandleObject(this, targetObj as ExplicitCloneTestObjectB); (targetObj as ExplicitCloneTestObjectB).SpecialSetupDone = true; }
void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { operation.HandleObject(this, targetObj as ExplicitCloneTestObjectB); (targetObj as ExplicitCloneTestObjectB).SpecialSetupDone = true; }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); RigidBody target = targetObj as RigidBody; // If we're cloning an initialized RigidBody, shut down the targets physics body. bool wasInitialized = target.bodyInitState == InitState.Initialized; if (wasInitialized) target.Shutdown(); target.bodyType = this.bodyType; target.linearDamp = this.linearDamp; target.angularDamp = this.angularDamp; target.fixedAngle = this.fixedAngle; target.ignoreGravity = this.ignoreGravity; target.continous = this.continous; target.linearVel = this.linearVel; target.angularVel = this.angularVel; target.revolutions = this.revolutions; target.explicitMass = this.explicitMass; target.colCat = this.colCat; target.colWith = this.colWith; if (this.shapes != null) { if (target.shapes == null) { target.shapes = new List<ShapeInfo>(this.shapes.Count); } else if (target.shapes.Count > this.shapes.Count) { // Remove exceeding shapes for (int i = target.shapes.Count - 1; i >= this.shapes.Count; i--) { target.RemoveShape(target.shapes[i]); } } // Synchronize existing shapes for (int i = 0; i < this.shapes.Count; i++) { bool isNew = (target.shapes.Count <= i); ShapeInfo sourceShape = this.shapes[i]; ShapeInfo targetShape = !isNew ? target.shapes[i] : null; if (operation.HandleObject(sourceShape, ref targetShape)) { if (isNew) target.shapes.Add(targetShape); else target.shapes[i] = targetShape; } } } else { target.ClearShapes(); } if (this.joints != null) { if (target.joints == null) { target.joints = new List<JointInfo>(this.joints.Count); } else if (target.joints.Count > this.joints.Count) { // Remove exceeding joints for (int i = target.joints.Count - 1; i >= this.joints.Count; i--) { target.RemoveJoint(target.joints[i]); } } // Synchronize existing joints for (int i = 0; i < this.joints.Count; i++) { bool isNew = (target.joints.Count <= i); JointInfo sourceJoint = this.joints[i]; JointInfo targetJoint = !isNew ? target.joints[i] : null; if (operation.HandleObject(sourceJoint, ref targetJoint)) { if (isNew) target.joints.Add(targetJoint); else target.joints[i] = targetJoint; } } } else { target.ClearJoints(); } // Make sure to re-initialize the targets body, if it was shut down if (wasInitialized) target.Initialize(); }
void ICloneExplicit.CopyDataTo(object target, ICloneOperation operation) { operation.HandleObject(this, target); this.OnCopyDataTo(target, operation); }
/// <summary> /// This method performs the <see cref="CopyTo"/> operation for custom Component Types. /// It uses reflection to perform the cloning operation automatically, but you can implement /// this method in order to handle certain fields and cases manually. See <see cref="ICloneExplicit.CopyDataTo"/> /// for a more thorough explanation. /// </summary> /// <param name="target">The target Component where this Components data is copied to.</param> /// <param name="operation"></param> protected virtual void OnCopyDataTo(object target, ICloneOperation operation) { operation.HandleObject(this, target); }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); AnimSpriteRenderer target = targetObj as AnimSpriteRenderer; target.animFirstFrame = this.animFirstFrame; target.animFrameCount = this.animFrameCount; target.animDuration = this.animDuration; target.animLoopMode = this.animLoopMode; target.animTime = this.animTime; target.animPaused = this.animPaused; operation.HandleObject(this.customFrameSequence, ref target.customFrameSequence); }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); TextRenderer target = targetObj as TextRenderer; target.blockAlign = this.blockAlign; target.colorTint = this.colorTint; operation.HandleValue(ref this.iconMat, ref target.iconMat); operation.HandleObject(this.text, ref target.text); operation.HandleObject(this.customMat, ref target.customMat); }
protected override void OnCopyDataTo(object targetObj, ICloneOperation operation) { base.OnCopyDataTo(targetObj, operation); Transform target = targetObj as Transform; target.deriveAngle = this.deriveAngle; target.ignoreParent = this.ignoreParent; target.pos = this.pos; target.angle = this.angle; target.scale = this.scale; target.posAbs = this.posAbs; target.angleAbs = this.angleAbs; target.scaleAbs = this.scaleAbs; target.tempVel = this.tempVel; target.tempVelAbs = this.tempVelAbs; target.tempAngleVel = this.tempAngleVel; target.tempAngleVelAbs = this.tempAngleVelAbs; target.velAbs = this.velAbs; target.vel = this.vel; target.angleVel = this.angleVel; target.angleVelAbs = this.angleVelAbs; // Initialize parentTransform, because it's required for UpdateAbs but is null until OnLoaded, which will be called after applying prefabs. if (target.gameobj != null && target.gameobj.Parent != null) target.parentTransform = target.gameobj.Parent.Transform; // Handle parentTransform manually to prevent null-overwrites operation.HandleObject(this.parentTransform, ref target.parentTransform, true); // Update absolute transformation data, because the target is relative to a different parent. target.UpdateAbs(); }