Ejemplo n.º 1
0
        private void OnEnable()
        {
            var headerpath = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("scriptex-header")[0]);

            header = AssetDatabase.LoadAssetAtPath <Texture>(headerpath);

            currentTemplate   = new ScriptTemplate();
            monoMethods       = MethodOption.Generate(ScriptType.MonoBehaviour);
            scriptableMethods = MethodOption.Generate(ScriptType.ScriptableObject);
            methodFilter      = string.Empty;
        }
Ejemplo n.º 2
0
        private void OnGUI()
        {
            MethodOption.MonoMethodsFromJson();

            EditorGUILayout.LabelField(new GUIContent(header), EditorStyles.helpBox);

            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical();
            currentTemplate.Name = EditorGUILayout.TextField("Name", currentTemplate.Name);
            if (!string.IsNullOrEmpty(warningBox))
            {
                EditorGUILayout.HelpBox(warningBox, MessageType.Error);
            }

            scriptType = (ScriptType)EditorGUILayout.EnumPopup("Script Type", scriptType);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(SmallBox(this.position.width));
            if (GUILayout.Button("Create Script"))
            {
                if (currentTemplate.Validate(out warningBox))
                {
                    CreateScript();
                    AssetDatabase.Refresh();
                    if (closeOnConfirm)
                    {
                        this.Close();
                    }
                }
            }
            closeOnConfirm = EditorGUILayout.ToggleLeft("Close on Confirm?", closeOnConfirm);
            EditorGUILayout.EndVertical();



            EditorGUILayout.Space();

            // METHOD LISTING
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            if (scriptType == ScriptType.MonoBehaviour || scriptType == ScriptType.ScriptableObject)
            {
                EditorGUILayout.LabelField("Methods", EditorStyles.boldLabel);
                methodFilter = EditorGUILayout.TextField("Search: ", methodFilter);
                System.Collections.Generic.IEnumerable <MethodOption> filteredOptions;
                if (string.IsNullOrEmpty(methodFilter))
                {
                    switch (scriptType)
                    {
                    case ScriptType.MonoBehaviour:
                        filteredOptions = monoMethods.Where(o => o.Name.ToUpper().Contains(methodFilter.ToUpper()));
                        break;

                    case ScriptType.ScriptableObject:
                        filteredOptions = scriptableMethods.Where(o => o.Name.ToUpper().Contains(methodFilter.ToUpper()));
                        break;

                    default:
                    case ScriptType.Normal:
                        filteredOptions = new System.Collections.Generic.List <MethodOption>();
                        break;
                    }
                }
                else
                {
                    switch (scriptType)
                    {
                    case ScriptType.MonoBehaviour:
                        filteredOptions = monoMethods;
                        break;

                    case ScriptType.ScriptableObject:
                        filteredOptions = scriptableMethods;
                        break;

                    default:
                    case ScriptType.Normal:
                        filteredOptions = new System.Collections.Generic.List <MethodOption>();
                        break;
                    }
                }
                filteredOptions = filteredOptions.OrderByDescending(o => o.Ranking);
                foreach (var option in filteredOptions)
                {
                    option.Include = EditorGUILayout.ToggleLeft(option.Name, option.Include);
                }
            }
            EditorGUILayout.EndScrollView();
        }