コード例 #1
0
        public static string Cut([CanBeNull] object target, [CanBeNull] LinkedMemberInfo memberInfo)
        {
            lastOperationFailed = true;

            if (memberInfo != null)
            {
                cutMemberInfo = SerializableMemberInfo.Serialize(memberInfo);
            }
            ObjectReference    = target as Object;
            hasObjectReference = objectReference != null;

            if (target != null)
            {
                copiedType = target.GetType();
            }
            else if (memberInfo != null)
            {
                copiedType = memberInfo.Type;
            }
            else
            {
                throw new NullReferenceException("Clipboard.Cut both target and memberInfo were null");
            }

            Content = PrettySerializer.Serialize(target);
            isCut   = true;

            lastOperationFailed = false;

            return(Content);
        }
コード例 #2
0
 public static byte[] Serialize([NotNull] LinkedMemberInfo memberInfo)
 {
     using (var serialize = new SerializableMemberInfo(memberInfo))
     {
         return(serialize.Serialize());
     }
 }
コード例 #3
0
        private static void OnCutPasted()
        {
            lastOperationFailed = false;

            if (cutMemberInfo != null)
            {
                // TO DO: Handle removing member from array.
                var memberInfo = SerializableMemberInfo.Deserialize(cutMemberInfo);

                if (memberInfo == null)
                {
                                        #if DEV_MODE
                    Debug.LogError("OnCutPasted failed to deserialized memberInfo");
                                        #endif
                }
                else if (memberInfo.Parent != null && memberInfo.Parent.IsCollection)
                {
                    int index  = memberInfo.CollectionIndex;
                    var values = memberInfo.Parent.GetValues();
                    for (int n = values.Length - 1; n >= 0; n--)
                    {
                        var value = values[n] as ICollection;
                        if (value != null && value.Count > index)
                        {
                            try
                            {
                                CollectionExtensions.RemoveAt(ref value, index, true);
                            }
                                                        #if DEV_MODE
                            catch (Exception e)
                            {
                                Debug.LogWarning(e);
                                                        #else
                            catch (Exception)
                            {
                                                        #endif
                                lastOperationFailed = true;
                                ClearCutData();
                                return;
                            }
                        }
                    }
                    memberInfo.Parent.SetValues(values);
                }
                else if (memberInfo.CanWrite)
                {
                    memberInfo.SetValue(memberInfo.DefaultValue());
                }
            }
            //if pasted target is not a field but a UnityObject
            //existing in the scene hierarchy, then destroy it
            else if (objectReference != null)
            {
                if (objectReference.IsSceneObject())
                {
                    Platform.Active.Destroy(objectReference);
                }
            }

            ClearCutData();
        }