Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public override void CreateTargetObjectLate(Delegate source, ref Delegate target, ICloneOperation operation)
        {
            Delegate[]         sourceInvokeList = (source != null) ? source.GetInvocationList() : null;
            Delegate[]         targetInvokeList = (target != null) ? target.GetInvocationList() : null;
            RawList <Delegate> mergedInvokeList = new RawList <Delegate>(
                ((sourceInvokeList != null) ? sourceInvokeList.Length : 0) +
                ((targetInvokeList != null) ? targetInvokeList.Length : 0));

            // Iterate over our sources invocation list and copy entries are part of the target object graph
            if (sourceInvokeList != null)
            {
                for (int i = 0; i < sourceInvokeList.Length; i++)
                {
                    if (sourceInvokeList[i].Target == null)
                    {
                        continue;
                    }

                    object invokeTargetObject = operation.GetWeakTarget(sourceInvokeList[i].Target);
                    if (invokeTargetObject != null)
                    {
                        MethodInfo method            = sourceInvokeList[i].GetMethodInfo();
                        Delegate   targetSubDelegate = method.CreateDelegate(sourceInvokeList[i].GetType(), invokeTargetObject);
                        mergedInvokeList.Add(targetSubDelegate);
                    }
                }
            }

            // Iterate over our targets invocation list and keep entries that are NOT part of the target object graph
            if (targetInvokeList != null)
            {
                for (int i = 0; i < targetInvokeList.Length; i++)
                {
                    if (targetInvokeList[i].Target == null)
                    {
                        continue;
                    }

                    if (!operation.IsTarget(targetInvokeList[i].Target))
                    {
                        MethodInfo method            = targetInvokeList[i].GetMethodInfo();
                        Delegate   targetSubDelegate = method.CreateDelegate(targetInvokeList[i].GetType(), targetInvokeList[i].Target);
                        mergedInvokeList.Add(targetSubDelegate);
                    }
                }
            }

            // Create a new delegate instance
            Delegate[] mergedInvokeArray = mergedInvokeList.Data;
            if (mergedInvokeArray.Length != mergedInvokeList.Count)
            {
                Array.Resize(ref mergedInvokeArray, mergedInvokeList.Count);
            }
            target = Delegate.Combine(mergedInvokeArray);
        }
Ejemplo n.º 4
0
        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);
        }