Example #1
0
 public static Component[] GetComponents(this IDataObject data, Type cmpType, DataObjectStorage storage = DataObjectStorage.Reference)
 {
     Component[] components;
     if (!data.TryGetComponents(cmpType, storage, out components))
     {
         return(null);
     }
     else
     {
         return(components);
     }
 }
Example #2
0
 public static GameObject[] GetGameObjects(this IDataObject data, DataObjectStorage storage = DataObjectStorage.Reference)
 {
     GameObject[] objects;
     if (!data.TryGetGameObjects(storage, out objects))
     {
         return(null);
     }
     else
     {
         return(objects);
     }
 }
Example #3
0
        public static bool TryGetGameObjects(this IDataObject data, DataObjectStorage storage, out GameObject[] objects)
        {
            // Retrieve all GameObjects from the data object
            IEnumerable <object> wrappedData;

            if (!data.TryGetWrappedData(GameObjectFormat, storage, out wrappedData))
            {
                objects = null;
                return(false);
            }

            // Return the retrieved GameObjects
            objects = wrappedData.OfType <GameObject>().ToArray();
            return(objects.Any());
        }
Example #4
0
        public static bool ContainsComponents(this IDataObject data, Type cmpType, DataObjectStorage storage = DataObjectStorage.Reference)
        {
            IEnumerable <object> wrappedData;

            if (!data.TryGetWrappedData(ComponentFormat, storage, out wrappedData))
            {
                return(false);
            }

            if (cmpType == null)
            {
                cmpType = typeof(Component);
            }
            return(wrappedData.Any(c => cmpType.IsInstanceOfType(c)));
        }
Example #5
0
        public static bool TryGetComponents(this IDataObject data, Type cmpType, DataObjectStorage storage, out Component[] components)
        {
            if (cmpType == null)
            {
                cmpType = typeof(Component);
            }

            // Retrieve all kinds of components from the data object
            IEnumerable <object> wrappedData;

            if (!data.TryGetWrappedData(ComponentFormat, storage, out wrappedData))
            {
                components = null;
                return(false);
            }

            // Filter and return components that match the specified type
            components = wrappedData.Where(c => cmpType.IsInstanceOfType(c)).OfType <Component>().ToArray();
            return(components.Any());
        }
Example #6
0
        public static bool TryGetWrappedData(this IDataObject data, string dataFormat, DataObjectStorage storage, out IEnumerable <object> wrappedData)
        {
            // Retrieve wrapped data of the specified format and storage type
            string wrappedFormat        = GetWrappedDataFormat(dataFormat, storage);
            SerializableWrapper wrapper = data.GetData(wrappedFormat) as SerializableWrapper;

            if (wrapper != null && wrapper.Data != null && wrapper.Data.Count > 0)
            {
                wrappedData = wrapper.Data;
                return(true);
            }

            // If retrieving by-value failed, try retrieving by-reference and cloning the result
            if (storage == DataObjectStorage.Value)
            {
                IEnumerable <object> byReferenceData;
                if (data.TryGetWrappedData(dataFormat, DataObjectStorage.Reference, out byReferenceData))
                {
                    wrappedData = byReferenceData.Select(obj => obj.DeepClone()).ToArray();
                    return(true);
                }
            }

            wrappedData = null;
            return(false);
        }
Example #7
0
        /// <summary>
        /// Retrieves the specified non-<see cref="SerializableAttribute"/> data from the specified data object using a serializable wrapper.
        /// </summary>
        /// <param name="dataFormat">The format of the data being retrieved</param>
        /// <param name="storage">Whether to look for stored references or values</param>
        public static IEnumerable <object> GetWrappedData(this IDataObject data, string dataFormat, DataObjectStorage storage)
        {
            IEnumerable <object> wrappedData;

            if (!data.TryGetWrappedData(dataFormat, storage, out wrappedData))
            {
                return(null);
            }
            else
            {
                return(wrappedData);
            }
        }
Example #8
0
        /// <summary>
        /// Determines whether the specified format of wrapped non-<see cref="SerializableAttribute"/> data is available in the data object.
        /// </summary>
        /// <param name="dataFormat">The format of data to look for</param>
        /// <param name="storage">Whether to look for stored references or values</param>
        public static bool GetWrappedDataPresent(this IDataObject data, string dataFormat, DataObjectStorage storage)
        {
            string wrappedFormat        = GetWrappedDataFormat(dataFormat, storage);
            bool   defaultFormatPresent = data.GetDataPresent(wrappedFormat);

            if (defaultFormatPresent)
            {
                return(true);
            }

            // If retrieving by-value failed, try retrieving a reference which can be cloned later
            if (storage == DataObjectStorage.Value && data.GetWrappedDataPresent(dataFormat, DataObjectStorage.Reference))
            {
                return(true);
            }

            return(false);
        }
Example #9
0
        /// <summary>
        /// Stores the specified non-<see cref="SerializableAttribute"/> data inside the specified data object using a serializable wrapper.
        /// </summary>
        /// <param name="dataFormat">The format of the data being stored</param>
        /// <param name="storage">The type of data being stored</param>
        public static void SetWrappedData(this IDataObject data, IEnumerable <object> values, string dataFormat, DataObjectStorage storage)
        {
            object[]            valuesArr     = values.ToArray();
            string              wrappedFormat = GetWrappedDataFormat(dataFormat, storage);
            SerializableWrapper wrapper       = storage == DataObjectStorage.Reference
                                ? new SerializableReferenceWrapper(valuesArr)
                                : new SerializableWrapper(valuesArr);

            data.SetData(wrappedFormat, wrapper);

            // Reference data is automatically stored as a value as well
            if (storage == DataObjectStorage.Reference)
            {
                data.SetWrappedData(valuesArr, dataFormat, DataObjectStorage.Value);
            }
        }
Example #10
0
        private static string GetWrappedDataFormat(string dataFormat, DataObjectStorage storage)
        {
            string prefix = (storage == DataObjectStorage.Reference) ? ReferencePrefix : ValuePrefix;

            return(prefix + dataFormat);
        }
Example #11
0
 public static bool ContainsGameObjects(this IDataObject data, DataObjectStorage storage = DataObjectStorage.Reference)
 {
     return(data.GetWrappedDataPresent(GameObjectFormat, storage));
 }
Example #12
0
 public static void SetGameObjects(this IDataObject data, IEnumerable <GameObject> obj, DataObjectStorage storage = DataObjectStorage.Reference)
 {
     GameObject[] objArray = obj.ToArray();
     if (objArray.Length > 0)
     {
         data.SetWrappedData(objArray, GameObjectFormat, storage);
     }
 }
Example #13
0
 public static void SetComponents(this IDataObject data, IEnumerable <Component> cmp, DataObjectStorage storage = DataObjectStorage.Reference)
 {
     Component[] cmpArray = cmp.ToArray();
     if (cmpArray.Length > 0)
     {
         data.SetWrappedData(cmpArray, ComponentFormat, storage);
     }
 }