Пример #1
0
 public virtual void DrawContext(AttributeData data, bool showRemove = false, bool isRoot = true)
 {
     if (this.labelRect.AddWidth(20).Clicked(1))
     {
         this.contextOpen = true;
         GenericMenu    menu            = new GenericMenu();
         AttributeMode  mode            = this.attribute.info.mode;
         AttributeUsage usage           = data.usage;
         bool           advanced        = EditorPref.Get <bool>(data.path + "Advanced");
         MenuFunction   toggleAdvanced  = () => { EditorPref.Set <bool>(data.path + "Advanced", !advanced); };
         MenuFunction   removeAttribute = () => { this.attribute.Remove(data); };
         MenuFunction   modeNormal      = () => { this.attribute.info.mode = AttributeMode.Normal; };
         MenuFunction   modeLinked      = () => { this.attribute.info.mode = AttributeMode.Linked; };
         MenuFunction   modeFormula     = () => { this.attribute.info.mode = AttributeMode.Formula; };
         MenuFunction   modeGroup       = () => { this.attribute.info.mode = AttributeMode.Group; };
         MenuFunction   usageDirect     = () => {
             data.usage         = AttributeUsage.Direct;
             data.referencePath = "";
             data.referenceID   = "";
             data.reference     = null;
         };
         MenuFunction usageShaped = () => { data.usage = AttributeUsage.Shaped; };
         MenuFunction fixType     = () => { this.SwapType(0, typeof(DataType), this.attribute.defaultSet); };
         bool         normal      = this.attribute.info.mode == AttributeMode.Normal;
         if (this.attribute.locked)
         {
             menu.AddDisabledItem(new GUIContent("Attribute Locked"));
             menu.ShowAsContext();
             return;
         }
         if (isRoot || mode.Matches("Normal", "Linked"))
         {
             if (mode.Matches("Normal", "Linked") && usage.Matches("Shaped") && this.attribute.canAdvanced)
             {
                 menu.AddItem(new GUIContent("Advanced"), advanced, toggleAdvanced);
                 menu.AddSeparator("/");
             }
             if (this.attribute.canDirect)
             {
                 menu.AddItem(new GUIContent("Direct"), normal && (usage == AttributeUsage.Direct), fixType + modeNormal + usageDirect);
             }
             if (this.attribute.canShape)
             {
                 menu.AddItem(new GUIContent("Shaped"), normal && (usage == AttributeUsage.Shaped), fixType + modeNormal + usageShaped);
             }
             if (this.attribute.canLink)
             {
                 menu.AddItem(new GUIContent("Linked"), (mode == AttributeMode.Linked), fixType + modeLinked + usageShaped);
             }
             menu.AddSeparator("/");
             if (this.attribute.canFormula)
             {
                 menu.AddItem(new GUIContent("Formula"), (mode == AttributeMode.Formula), modeFormula);
             }
             if (this.attribute.canGroup)
             {
                 menu.AddItem(new GUIContent("Group"), (mode == AttributeMode.Group), modeGroup);
             }
         }
         else if (mode.Matches("Formula"))
         {
             menu.AddItem(new GUIContent("Advanced"), advanced, toggleAdvanced);
             this.DrawTypeMenu(data, menu);
             menu.AddSeparator("/");
             if (this.attribute.canDirect)
             {
                 menu.AddItem(new GUIContent("Direct"), usage == AttributeUsage.Direct, usageDirect);
             }
             if (this.attribute.canShape)
             {
                 menu.AddItem(new GUIContent("Shaped"), usage == AttributeUsage.Shaped, usageShaped);
             }
         }
         if (showRemove)
         {
             if (!mode.Matches("Group"))
             {
                 menu.AddSeparator("/");
             }
             menu.AddItem(new GUIContent("Remove"), false, removeAttribute);
         }
         menu.ShowAsContext();
     }
     if (this.contextOpen && Event.current.button == 0)
     {
         this.dirty       = true;
         this.contextOpen = false;
     }
 }