示例#1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, ShowDrawerChainAttribute attribute, GUIContent label)
        {
            OdinDrawer[] drawers = DrawerLocator.GetDrawersForProperty(property);

            AllEditorGUI.BeginBox("Drawers");
            for (int i = 0; i < drawers.Length; i++)
            {
                bool highlight = drawers[i].GetType().Assembly != typeof(ShowDrawerChainAttributeDrawer).Assembly;

                if (highlight)
                {
                    GUIHelper.PushColor(Color.green);
                }

                EditorGUILayout.LabelField(i + ": " + drawers[i].GetType().GetNiceName());
                var rect = GUILayoutUtility.GetLastRect();

                GUI.Label(rect, DrawerLocator.GetDrawerPriority(drawers[i].GetType()).ToString(), SirenixGUIStyles.RightAlignedGreyMiniLabel);

                if (highlight)
                {
                    GUIHelper.PopColor();
                }
            }
            AllEditorGUI.EndBox();

            this.CallNextDrawer(property, label);
        }
示例#2
0
        private void OnGUI()
        {
            if (TrainingWindow.IsOpen && TrainingWindow.GetWindow().GetChapter() != null)
            {
                step = TrainingWindow.GetWindow().GetChapter().ChapterMetadata.LastSelectedStep;
            }

            titleContent = new GUIContent("Step");

            if (step == null)
            {
                return;
            }

            ITrainingDrawer drawer = DrawerLocator.GetDrawerForValue(step, typeof(Step));

            stepRect.width = position.width;

            if (stepRect.height > position.height - EditorGUIUtility.singleLineHeight)
            {
                stepRect.width -= GUI.skin.verticalScrollbar.fixedWidth;
            }

            scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPosition, stepRect, false, false);
            {
                stepRect = drawer.Draw(stepRect, step, SetStep, "Step");
            }
            GUI.EndScrollView();
        }
        private static void RegisterDrawer()
        {
            DrawerLocator.RegisterCustomDrawerLocator(new CustomDrawerLocator((valueType, attributeType) =>
            {
                if (attributeType != null)
                {
                    return(null);
                }

                if (valueType == null)
                {
                    return(null);
                }

                if (valueType.IsArray && valueType.GetArrayRank() == 2)
                {
                    Type drawerType;
                    if (valueType.GetElementType().IsEnum)
                    {
                        drawerType = typeof(TwoDimensionalEnumArrayDrawer <,>)
                                     .MakeGenericType(valueType, valueType.GetElementType());
                    }
                    else if (valueType.GetElementType().InheritsFrom(typeof(UnityEngine.Object)))
                    {
                        drawerType = typeof(TwoDimensionalUnityObjectArrayDrawer <,>)
                                     .MakeGenericType(valueType, valueType.GetElementType());
                    }
                    else
                    {
                        drawerType = typeof(TwoDimensionalGenericArrayDrawer <,>)
                                     .MakeGenericType(valueType, valueType.GetElementType());
                    }

                    return(new DrawerInfo(drawerType, valueType, null));
                }

                return(null);
            }));
        }
        public override void AssignDefaults()
        {
            base.AssignDefaults();

            DrawerLocator locator = ScriptableObject.CreateInstance <DrawerLocator>();
            MonoScript    script  = MonoScript.FromScriptableObject(locator);

            locator.hideFlags = HideFlags.HideAndDontSave;
            var stateDrawerPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(script)) + "/Gizmos/";

            textureEntityStateIcon = GetTexture(stateDrawerPath + "entity_state.png");
            textureFolderIcon      = GetTexture(stateDrawerPath + "folder.png");

            if (m_filterBoxStyle == null)
            {
                var InspectorSkin =
                    UnityEngine.Object.Instantiate(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector));
                InspectorSkin.hideFlags      = HideFlags.HideAndDontSave;
                m_filterBoxStyle             = InspectorSkin.FindStyle("SearchTextField");
                m_filterBoxCancelButtonStyle = InspectorSkin.FindStyle("SearchCancelButton");
            }
        }
示例#5
0
        private void OnGUI()
        {
            if (step == null)
            {
                return;
            }

            ITrainingDrawer drawer = DrawerLocator.GetDrawerForValue(step, typeof(Step));

            stepRect.width = position.width;

            if (stepRect.height > position.height)
            {
                stepRect.width -= GUI.skin.verticalScrollbar.fixedWidth;
            }

            scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPosition, stepRect, false, false);
            {
                Rect stepDrawingRect = new Rect(stepRect.position + new Vector2(border, border), stepRect.size - new Vector2(border * 2f, border * 2f));
                stepDrawingRect = drawer.Draw(stepDrawingRect, step, ModifyStep, "Step");
                stepRect        = new Rect(stepDrawingRect.position - new Vector2(border, border), stepDrawingRect.size + new Vector2(border * 2f, border * 2f));
            }
            GUI.EndScrollView();
        }
示例#6
0
        /// <summary>
        /// Returns all properties and fields of the object that have to be drawn by training drawers.
        /// </summary>
        public static IEnumerable <MemberInfo> GetFieldsAndPropertiesToDraw(object value)
        {
            IEnumerable <MemberInfo> result = new List <MemberInfo>();

            if (value == null)
            {
                return(result);
            }

            Type type = value.GetType();

            if (fieldAndPropertiesToDrawCache.ContainsKey(type))
            {
                return(fieldAndPropertiesToDrawCache[type]);
            }

            HashSet <MethodInfo> getOverloads = new HashSet <MethodInfo>();

            IEnumerable <PropertyInfo> properties = new List <PropertyInfo>();

            // Get all fields which do not have HideInInspectorAttribute and have DataMember attribute,
            // which aren't IMetadata fields.
            // Do it all the way up in the inheritance tree, skipping properties which were defined in more concrete implementation of the class.
            while (type != null)
            {
                result = result.Concat(type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                       .GroupBy(propertyInfo => propertyInfo.Name)
                                       .SelectMany(groupByName => groupByName.GroupBy(propertyInfo => propertyInfo.DeclaringType).Select(groupByDeclaringType => groupByDeclaringType.First()))
                                       .Where(fieldInfo => fieldInfo.FieldType.GetInterfaces().Contains(typeof(IMetadata)) == false)
                                       .Cast <MemberInfo>());

                type = type.BaseType;
            }

            type = value.GetType();

            while (type != null)
            {
                properties = properties.Concat(type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                               .Where(propertyInfo => propertyInfo.CanRead && propertyInfo.CanWrite)
                                               .Where(propertyInfo => propertyInfo.PropertyType.GetInterfaces().Contains(typeof(IMetadata)) == false));

                type = type.BaseType;
            }

            result = result.Concat(properties.GroupBy(propertyInfo => propertyInfo.Name)
                                   .SelectMany(groupByName => groupByName.GroupBy(propertyInfo => propertyInfo.DeclaringType).Select(groupByDeclaringType => groupByDeclaringType.First()))
                                   .Where(propertyInfo =>
            {
                MethodInfo get = propertyInfo.GetGetMethod(true);
                if (getOverloads.Contains(get))
                {
                    return(false);
                }

                MethodInfo baseGet = get.GetBaseDefinition();

                getOverloads.Add(baseGet);
                return(true);
            })
                                   .Cast <MemberInfo>());

            type = value.GetType();

            fieldAndPropertiesToDrawCache[type] = result.Where(memberInfo => memberInfo.GetAttributes <HideInTrainingInspectorAttribute>(true).Any() == false)
                                                  .Where(memberInfo => memberInfo.GetAttributes <DataMemberAttribute>(true).Any() && DrawerLocator.GetDrawerForMember(memberInfo, value) != null)
                                                  .OrderBy(memberInfo =>
            {
                DrawingPriorityAttribute priorityAttribute = memberInfo.GetAttributes(true).FirstOrDefault(attribute => attribute is DrawingPriorityAttribute) as DrawingPriorityAttribute;

                if (priorityAttribute == null)
                {
                    return(int.MaxValue);
                }

                return(priorityAttribute.Priority);
            }).ToList();

            return(fieldAndPropertiesToDrawCache[type]);
        }
示例#7
0
        public virtual void AssignDefaults()
        {
            // create new skin instance
            var skinHover      = ScriptableObject.CreateInstance <GUISkin>();
            var skinSelected   = ScriptableObject.CreateInstance <GUISkin>();
            var skinUnselected = ScriptableObject.CreateInstance <GUISkin>();

            skinHover.hideFlags      = HideFlags.HideAndDontSave;
            skinSelected.hideFlags   = HideFlags.HideAndDontSave;
            skinUnselected.hideFlags = HideFlags.HideAndDontSave;

            // name the skins
            skinHover.name      = "Hover";
            skinSelected.name   = "Selected";
            skinUnselected.name = "Unselected";

            DrawerLocator locator = ScriptableObject.CreateInstance <DrawerLocator>();
            MonoScript    script  = MonoScript.FromScriptableObject(locator);

            locator.hideFlags = HideFlags.HideAndDontSave;


            var stateDrawerPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(script)) + "/Gizmos/";

            m_textureBlank = GetTexture(stateDrawerPath + "blank.png");
            m_textureGuide = GetTexture(stateDrawerPath + "guide.png");
            m_textureLastSiblingCollapsed   = GetTexture(stateDrawerPath + "last_sibling_collapsed.png");
            m_textureLastSiblingExpanded    = GetTexture(stateDrawerPath + "last_sibling_expanded.png");
            m_textureLastSiblingNoChild     = GetTexture(stateDrawerPath + "last_sibling_nochild.png");
            m_textureMiddleSiblingCollapsed = GetTexture(stateDrawerPath + "middle_sibling_collapsed.png");
            m_textureMiddleSiblingExpanded  = GetTexture(stateDrawerPath + "middle_sibling_expanded.png");
            m_textureMiddleSiblingNoChild   = GetTexture(stateDrawerPath + "middle_sibling_nochild.png");
            m_textureNormalChecked          = GetTexture(stateDrawerPath + "normal_checked.png");
            m_textureNormalUnchecked        = GetTexture(stateDrawerPath + "normal_unchecked.png");
            m_textureSelectedBackground     = GetTexture(stateDrawerPath + "selected_background_color.png");

            m_skinHover      = skinHover;
            m_skinSelected   = skinSelected;
            m_skinUnselected = skinUnselected;

            SetBackground(m_skinHover.button, null);
            SetBackground(m_skinHover.toggle, null);
            SetButtonFontSize(m_skinHover.button);
            SetButtonFontSize(m_skinHover.toggle);
            RemoveMargins(m_skinHover.button);
            RemoveMargins(m_skinHover.toggle);
            SetTextColor(m_skinHover.button, Color.yellow);
            SetTextColor(m_skinHover.toggle, Color.yellow);

            SetBackground(m_skinSelected.button, m_textureSelectedBackground);
            SetBackground(m_skinSelected.toggle, m_textureSelectedBackground);
            SetButtonFontSize(m_skinSelected.button);
            SetButtonFontSize(m_skinSelected.toggle);
            RemoveMargins(m_skinSelected.button);
            RemoveMargins(m_skinSelected.toggle);
            SetTextColor(m_skinSelected.button, Color.yellow);
            SetTextColor(m_skinSelected.toggle, Color.yellow);

            SetBackground(m_skinUnselected.button, null);
            SetBackground(m_skinUnselected.toggle, null);
            SetButtonFontSize(m_skinUnselected.button);
            SetButtonFontSize(m_skinUnselected.toggle);
            RemoveMargins(m_skinUnselected.button);
            RemoveMargins(m_skinUnselected.toggle);

            if (Application.HasProLicense())
            {
                SetTextColor(m_skinUnselected.button, Color.white);
                SetTextColor(m_skinUnselected.toggle, Color.white);
            }
            else
            {
                SetTextColor(m_skinUnselected.button, Color.black);
                SetTextColor(m_skinUnselected.toggle, Color.black);
            }
        }