/// <summary> /// Gets a context value local to a drawer type for a given key, and creates a new instance of <see cref="T" /> /// as a default value if the context doesn't already exist. /// </summary> /// <returns>Returns true if a new context was created.</returns> public bool Get <TValue>(OdinDrawer drawerInstance, string key, out PropertyContext <TValue> context) { bool isNew; this.TryGetDrawerContext(drawerInstance.GetType(), key, out context, out isNew); return(isNew); }
/// <summary> /// Gets a context value local to a drawer type for a given key, and creates a new instance of <see cref="T" /> as a default value if the context doesn't already exist. /// </summary> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="drawerInstance">An instance of the drawer type linked to the context value to get.</param> /// <returns> /// The found context. /// </returns> /// <exception cref="System.ArgumentNullException">drawerInstance is null</exception> public PropertyContext <TValue> Get <TValue>(OdinDrawer drawerInstance) where TValue : new() { if (drawerInstance == null) { throw new ArgumentNullException("drawerInstance"); } return(this.Get <TValue>(drawerInstance.GetType(), "_")); }
/// <summary> /// Gets a context value local to a drawer type for a given key, and creates a new instance of <see cref="T" /> as a default value if the context doesn't already exist. /// </summary> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="drawerInstance">An instance of the drawer type linked to the context value to get.</param> /// <param name="defaultValue">The default value.</param> /// <returns> /// The found context. /// </returns> /// <exception cref="ArgumentNullException">drawerInstance</exception> /// <exception cref="System.ArgumentNullException">drawerInstance is null</exception> public PropertyContext <TValue> Get <TValue>(OdinDrawer drawerInstance, TValue defaultValue) { if (drawerInstance == null) { throw new ArgumentNullException("drawerInstance"); } return(this.Get(drawerInstance.GetType(), "_", defaultValue)); }
/// <summary> /// <para>Gets a context value local to a drawer type for a given key, using a given delegate to generate a default value if the context doesn't already exist.</para> /// </summary> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="drawerInstance">An instance of the drawer type linked to the context value to get.</param> /// <param name="key">The key of the context value to get.</param> /// <param name="getDefaultValue">A delegate for generating a default value.</param> /// <returns> /// The found context. /// </returns> /// <exception cref="System.ArgumentNullException">drawerInstance is null</exception> public PropertyContext <TValue> Get <TValue>(OdinDrawer drawerInstance, string key, Func <TValue> getDefaultValue) { if (drawerInstance == null) { throw new ArgumentNullException("drawerInstance"); } return(this.Get(drawerInstance.GetType(), key, getDefaultValue)); }
/// <summary> /// <para>Gets a temporary context value local to a drawer type for a given key, and creates a new instance of <see cref="T" /> as a default value if the context doesn't already exist.</para> /// <para>Temporary context values are reset at the start of every GUI frame; arrays are set to default values, collections are cleared, and context types that implement <see cref="ITemporaryContext" /> have <see cref="ITemporaryContext.Reset" /> called.</para> /// </summary> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="drawerInstance">An instance of the drawer type linked to the context value to get.</param> /// <param name="key">The key of the context value to get.</param> /// <returns> /// The found context. /// </returns> /// <exception cref="System.ArgumentNullException">drawerInstance is null</exception> public TemporaryPropertyContext <TValue> GetTemporary <TValue>(OdinDrawer drawerInstance, string key) where TValue : new() { if (drawerInstance == null) { throw new ArgumentNullException("drawerInstance"); } return(this.GetTemporary <TValue>(drawerInstance.GetType(), key)); }
/// <summary> /// Calls the next drawer in the draw chain. /// </summary> /// <param name="label">The label to pass on to the next drawer.</param> protected bool CallNextDrawer(GUIContent label) { //var nextDrawer = DrawerLocator.GetNextDrawer(this, property); OdinDrawer nextDrawer = null; var chain = this.property.GetActiveDrawerChain(); if (chain.MoveNext()) { nextDrawer = chain.Current; } if (nextDrawer != null) { //nextDrawer.DrawProperty(label); nextDrawer.DrawPropertyLayout(label); return(true); } else if (property.ValueEntry != null) { var rect = EditorGUILayout.GetControlRect(); if (label == null) { GUI.Label(rect, this.Property.NiceName); } else { GUI.Label(rect, label); } //GUILayout.BeginHorizontal(); //{ // if (label != null) // { // EditorGUILayout.PrefixLabel(label); // } // SirenixEditorGUI.WarningMessageBox("There is no custom drawer defined for type '" + property.ValueEntry.TypeOfValue.GetNiceName() + "', and the type has no members to draw."); //} //GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); { if (label != null) { EditorGUILayout.PrefixLabel(label); } SirenixEditorGUI.WarningMessageBox("There is no drawer defined for property " + property.NiceName + " of type " + property.Info.PropertyType + "."); } GUILayout.EndHorizontal(); } return(false); }
private UniqueDrawerKey(InspectorProperty property, OdinDrawer drawer) { this.property = property; this.drawCount = property.DrawCount; this.drawer = drawer; unchecked { int hash = 17; hash = hash * 29 + this.property.GetHashCode(); hash = hash * 29 + this.drawCount; hash = hash * 29 + this.drawer.GetHashCode(); this.hashCode = hash; } }
/// <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); }
/// <summary> /// Gets a context value local to a drawer type for a given key, and creates a new instance of <see cref="T" /> /// as a default value if the context doesn't already exist. /// </summary> /// <returns>Returns true if a new context was created.</returns> public bool Get <TValue>(OdinDrawer drawerInstance, string key, out TValue context) where TValue : class, new() { PropertyContext <TValue> pContext; bool isNew; this.TryGetDrawerContext(drawerInstance.GetType(), key, out pContext, out isNew); if (isNew) { pContext.Value = new TValue(); } context = pContext.Value; return(isNew); }
/// <summary> /// Gets the next drawer for a given drawer and a given property, if any exists. /// </summary> public static OdinDrawer GetNextDrawer(OdinDrawer drawer, InspectorProperty property) { OdinDrawer[] drawers = GetDrawersForProperty(property); OdinDrawer next = null; for (int i = 0; i < drawers.Length; i++) { if (object.ReferenceEquals(drawers[i], drawer) && i + 1 < drawers.Length) { next = drawers[i + 1]; break; } } return(next); }
/// <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)); }
/// <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); }
/// <summary> /// Gets a unique key for any given property within a drawer. /// </summary> /// <param name="property">The property.</param> /// <param name="drawer">The drawer.</param> /// <returns></returns> public static UniqueDrawerKey Create(InspectorProperty property, OdinDrawer drawer) { return(new UniqueDrawerKey(property, drawer)); }
/// <summary> /// Gets a unique key for any given property within a drawer. /// </summary> /// <param name="entry">The property entry.</param> /// <param name="drawer">The drawer.</param> /// <returns></returns> public static UniqueDrawerKey Create(IPropertyValueEntry entry, OdinDrawer drawer) { return(new UniqueDrawerKey(entry.Property, drawer)); }