コード例 #1
0
        /// <summary>
        /// Gets a <see cref="GlobalPersistentContext{T}"/> object and creates a <see cref="LocalPersistentContext{T}"/> object for it.
        /// </summary>
        /// <typeparam name="TValue">The type of the value of the context.</typeparam>
        /// <param name="drawer">The instance of the drawer.</param>
        /// <param name="key">The key for the context.</param>
        /// <param name="defaultValue">The default value for the context.</param>
        public LocalPersistentContext <TValue> GetPersistent <TValue>(OdinDrawer drawer, string key, TValue defaultValue)
        {
            PropertyContext <LocalPersistentContext <TValue> > context;

            if (this.Get <LocalPersistentContext <TValue> >(drawer, key, out context))
            {
                context.Value = LocalPersistentContext <TValue> .Create(PersistentContext.Get(
                                                                            TwoWaySerializationBinder.Default.BindToName(drawer.GetType()),
                                                                            TwoWaySerializationBinder.Default.BindToName(this.property.Tree.TargetType),
                                                                            this.property.Path,
                                                                            new DrawerStateSignature(this.property.RecursiveDrawDepth, InlineEditorAttributeDrawer.CurrentInlineEditorDrawDepth, this.property.DrawerChainIndex),
                                                                            key,
                                                                            defaultValue));
            }

            return(context.Value);
        }
コード例 #2
0
        /// <summary>
        /// Gets a persistent value that will survive past multiple Unity Editor Application sessions.
        /// The value is stored in the PersistentContextCache, which has a customizable max cache size.
        /// </summary>
        public static LocalPersistentContext <T> GetPersistentValue <T>(this OdinDrawer drawer, string key, T defaultValue = default(T))
        {
            var a = TwoWaySerializationBinder.Default.BindToName(drawer.GetType());
            var b = TwoWaySerializationBinder.Default.BindToName(drawer.Property.Tree.TargetType);
            var c = drawer.Property.Path;
            var d = new DrawerStateSignature(drawer.Property.RecursiveDrawDepth, InlineEditorAttributeDrawer.CurrentInlineEditorDrawDepth, drawer.Property.DrawerChainIndex);
            var e = key;

            GlobalPersistentContext <T> global;

            if (PersistentContext.Get(a, b, c, d, e, out global))
            {
                global.Value = defaultValue;
            }

            return(LocalPersistentContext <T> .Create(global));
        }
コード例 #3
0
        /// <summary>
        /// Gets a <see cref="GlobalPersistentContext{T}"/> object and creates a <see cref="LocalPersistentContext{T}"/> object for it.
        /// Returns <c>true</c> when the <see cref="GlobalPersistentContext{T}"/> is first created. Otherwise <c>false</c>.
        /// </summary>
        /// <typeparam name="TValue">The type of the value of the context.</typeparam>
        /// <param name="drawer">The instance of the drawer.</param>
        /// <param name="key">The key for the context.</param>
        /// <param name="context">The <see cref="LocalPersistentContext{T}"/> object.</param>
        /// <returns>Returns <c>true</c> when the <see cref="GlobalPersistentContext{T}"/> is first created. Otherwise <c>false</c>.</returns>
        public bool GetPersistent <TValue>(OdinDrawer drawer, string key, out LocalPersistentContext <TValue> context)
        {
            bool isNew = false;
            PropertyContext <LocalPersistentContext <TValue> > propertyContext;

            if (this.Get <LocalPersistentContext <TValue> >(drawer, key, out propertyContext))
            {
                GlobalPersistentContext <TValue> global;
                isNew = PersistentContext.Get(
                    TwoWaySerializationBinder.Default.BindToName(drawer.GetType()),
                    TwoWaySerializationBinder.Default.BindToName(this.property.Tree.TargetType),
                    this.property.Path,
                    new DrawerStateSignature(this.property.RecursiveDrawDepth, InlineEditorAttributeDrawer.CurrentInlineEditorDrawDepth, this.property.DrawerChainIndex),
                    key,
                    out global);

                propertyContext.Value = LocalPersistentContext <TValue> .Create(global);
            }

            context = propertyContext.Value;

            return(isNew);
        }