Ejemplo n.º 1
0
        public static GenericMenu GeneratePropertyMenu(SkillProperty fsmProperty)
        {
            TypeHelpers.targetFsmProperty = fsmProperty;
            GenericMenu result     = new GenericMenu();
            Type        globalType = ReflectionUtils.GetGlobalType(fsmProperty.TargetTypeName);

            if (globalType != null)
            {
                TypeHelpers.AddPropertyMenuItems(ref result, globalType, "", 0, fsmProperty.setProperty);
            }
            return(result);
        }
Ejemplo n.º 2
0
        private static void OpenSubPropertyMenu()
        {
            SkillEditor.OnRepaint = (SkillEditor.RepaintDelegate)Delegate.Remove(SkillEditor.OnRepaint, new SkillEditor.RepaintDelegate(TypeHelpers.OpenSubPropertyMenu));
            string        text        = TypeHelpers.subPropertyPath;
            SkillProperty fsmProperty = TypeHelpers.targetFsmProperty;
            GenericMenu   genericMenu = new GenericMenu();
            Type          globalType  = ReflectionUtils.GetGlobalType(fsmProperty.TargetTypeName);

            if (globalType != null)
            {
                string path         = TypeHelpers.NicifyPropertyPath(text);
                Type   propertyType = ReflectionUtils.GetPropertyType(globalType, text);
                TypeHelpers.AddPropertyMenuItems(ref genericMenu, propertyType, path, 0, fsmProperty.setProperty);
            }
            TypeHelpers.subPropertyPath = "";
            genericMenu.ShowAsContext();
        }
Ejemplo n.º 3
0
 private static void AddPropertyMenuItems(ref GenericMenu menu, Type type, string path, int depth, bool setProperty)
 {
     if (type != null && !type.get_IsEnum() && depth < 3)
     {
         List <MemberInfo> fieldsAndProperties = ReflectionUtils.GetFieldsAndProperties(type, 20);
         fieldsAndProperties.Sort((MemberInfo x, MemberInfo y) => string.CompareOrdinal(x.get_Name(), y.get_Name()));
         using (List <MemberInfo> .Enumerator enumerator = fieldsAndProperties.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 MemberInfo current = enumerator.get_Current();
                 if (!TypeHelpers.FilterMember(current))
                 {
                     Type   memberUnderlyingType = ReflectionUtils.GetMemberUnderlyingType(current);
                     string name = current.get_Name();
                     bool   flag = memberUnderlyingType.get_IsClass() || (setProperty ? TypeHelpers.CanSetProperty(current) : TypeHelpers.CanGetProperty(current));
                     if (flag)
                     {
                         string text = (path != "") ? (path + '/' + name) : name;
                         if (TypeHelpers.HasProperties(memberUnderlyingType))
                         {
                             if (TypeHelpers.CanSetProperty(current))
                             {
                                 menu.AddItem(new GUIContent(text + '/' + Labels.StripNamespace(memberUnderlyingType.ToString())), false, new GenericMenu.MenuFunction2(TypeHelpers.SetFsmPropertyName), text);
                             }
                         }
                         else
                         {
                             menu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(TypeHelpers.SetFsmPropertyName), text);
                         }
                     }
                     if (string.IsNullOrEmpty(TypeHelpers.subPropertyPath) && depth > 0 && memberUnderlyingType.IsSubclassOf(typeof(Component)))
                     {
                         menu.AddItem(new GUIContent(path + Strings.get_SubMenu_More_()), false, new GenericMenu.MenuFunction2(TypeHelpers.GenerateSubPropertyMenu), path);
                         break;
                     }
                     if (flag || memberUnderlyingType.IsSubclassOf(typeof(Component)))
                     {
                         TypeHelpers.AddPropertyMenuItems(ref menu, memberUnderlyingType, (path != "") ? (path + '/' + name) : name, depth + 1, setProperty);
                     }
                 }
             }
         }
     }
 }