示例#1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            object deserialized = serializer.Deserialize(reader);

            NonblockingWrapperBehavior obsoleteBehavior = deserialized as NonblockingWrapperBehavior;

            if (obsoleteBehavior == null)
            {
                return(deserialized);
            }
            else
            {
                IBehavior properBehavior             = obsoleteBehavior.Data.Behavior;
                IBackgroundBehaviorData blockingData = properBehavior.Data as IBackgroundBehaviorData;
                if (blockingData != null)
                {
                    blockingData.IsBlocking = obsoleteBehavior.Data.IsBlocking;
                }

                return(properBehavior);
            }
        }
示例#2
0
        private Rect DrawIsBlockingToggle(Rect rect, MetadataWrapper wrapper, Action <object> changeValueCallback, GUIContent label)
        {
            IDataOwner dataOwner = wrapper.Value as IDataOwner;

            rect = DrawRecursively(rect, wrapper, drawIsBlockingToggleName, changeValueCallback, label);

            if (dataOwner == null)
            {
                Debug.LogError("The target property of the DrawIsBlockingToggleAttribute has to implement IDataOwner.");
                return(rect);
            }

            IBackgroundBehaviorData backgroundBehaviorData = dataOwner.Data as IBackgroundBehaviorData;

            if (backgroundBehaviorData == null)
            {
                return(rect);
            }

            ITrainingDrawer boolDrawer = DrawerLocator.GetDrawerForValue(backgroundBehaviorData.IsBlocking, typeof(bool));

            rect.height += boolDrawer.Draw(new Rect(rect.x, rect.y + rect.height, rect.width, 0), backgroundBehaviorData.IsBlocking, (newValue) =>
            {
                backgroundBehaviorData.IsBlocking = (bool)newValue;
                changeValueCallback(wrapper);
            }, "Wait for completion").height;

            return(rect);
        }
示例#3
0
        /// <summary>
        /// Takes a <paramref name="collection"/> of entities and filters out the ones that must be skipped due to <paramref name="mode"/>
        /// or contains a <seealso cref="IBackgroundBehaviorData"/> with `IsBlocking` set to false.
        /// </summary>
        protected IEnumerable <IEntity> GetBlockingChildren(IEntityCollectionData collection, IMode mode)
        {
            return(collection.GetChildren()
                   .Where(child => mode.CheckIfSkipped(child.GetType()) == false)
                   .Where(child =>
            {
                IDataOwner dataOwner = child as IDataOwner;
                if (dataOwner == null)
                {
                    return true;
                }

                IBackgroundBehaviorData blockingData = dataOwner.Data as IBackgroundBehaviorData;
                return blockingData == null || blockingData.IsBlocking;
            }));
        }
示例#4
0
        private static IEnumerable <TEntity> GetBlockingChildren(TData data)
        {
            return(data.GetChildren()
                   .Where(child => data.Mode.CheckIfSkipped(child.GetType()) == false)
                   .Where(child =>
            {
                IDataOwner dataOwner = child as IDataOwner;
                if (dataOwner == null)
                {
                    return true;
                }

                IBackgroundBehaviorData blockingData = dataOwner.Data as IBackgroundBehaviorData;
                return blockingData == null || blockingData.IsBlocking;
            }));
        }