Esempio n. 1
0
        private string GenerateOnInspectorGUIBodyMethodButtons(Type type, string varName)
        {
            StringBuilder sb = new StringBuilder($"\n{tabLevel}// Buttons");

            BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic;

            var members = type.GetMethods(bindingFlags);

            foreach (var m in members)
            {
                MessageLogger.LogMethodName(m.ToString());

                var attributes = m.GetCustomAttributes(typeof(ContextMenu), false);
                foreach (var a in attributes)
                {
                    MessageLogger.LogAttributeType(a);

                    string buttonStart = $"\n{tabLevel}if(GUILayout.Button(\"{GetLabelName(m.Name)}\"))\n{tabLevel}{{\n";
                    Indent();
                    string buttonBody = $"{tabLevel}{varName}.{m.Name}();\n";
                    Dedent();
                    string buttonEnd = $"{tabLevel}}}\n";

                    sb.Append($"{buttonStart}{buttonBody}{buttonEnd}");
                }
            }

            return(sb.ToString());
        }
Esempio n. 2
0
        // This bad boy needs work
        private string ParseFieldsAndProperties(string varName, string name, string type, bool isEnum, bool isSerializable, Type t)
        {
            MessageLogger.LogFieldOrPropertyInfo(name, type, isEnum, isSerializable);

            StringBuilder layoutGenerator = new StringBuilder();

            // Special cases:
            if (isEnum)
            {
                layoutGenerator.Append(GenerateEditorGUILayoutEnumPopup(varName, name, type));
                return(layoutGenerator.ToString());
            }

            string result = LookUpFieldType(type);

            if (string.IsNullOrEmpty(result))
            {
                // These will not be written for the custom Inspector!
                if (type.Equals("System.Object") || type.Contains("Dict") || type.Contains("Quaternion"))
                {
                    string errorMessage = GenerateErrorMessage(name, type);

                    layoutGenerator.Append(errorMessage);

                    MessageLogger.ErrorOmittedFieldOrProperty(errorMessage.Trim());
                }
                else if (!isSerializable)
                {
                    if (IsMonoBehaviour(t))
                    {
                        layoutGenerator.Append(GoBackAndAddSerializedProperty(name));
                    }
                    else if (IsScriptableObject(t))
                    {
                        layoutGenerator.Append(GoBackAndAddSerializedProperty(name));
                    }
                }
                else
                {
                    layoutGenerator.Append(GoBackAndAddSerializedProperty(name));
                }
            }
            else if (result.Equals("_USEPROP_"))
            {
                layoutGenerator.Append(GoBackAndAddSerializedProperty(name));
            }
            // Default case
            else
            {
                layoutGenerator.Append(GenerateEditorGUILayoutForGivenType(varName, name, result, type));
            }

            return(layoutGenerator.ToString());
        }
Esempio n. 3
0
        public string Build(string[] parts)
        {
            StringBuilder builder = new StringBuilder();

            foreach (var part in parts)
            {
                builder.Append(part);
            }

            MessageLogger.SuccessBuildSucceded();

            return(builder.ToString());
        }
Esempio n. 4
0
        public void WriteToFile(string path, string className, string content, bool isText)
        {
            if (isText == false)
            {
                CreateEditorFolder(path);

                File.WriteAllText($"{path}/Editor/{className}Editor.cs", content);
                MessageLogger.SuccessTextFileWrite(path, className);
            }
            else
            {
                File.WriteAllText($"{path}/{className}Editor.txt", content);
                MessageLogger.SuccessEditorFileWrite(path, className);
            }

            AssetDatabase.Refresh();
        }
Esempio n. 5
0
        /// <summary>
        /// Attempt to compile a csharp script (.cs) at the given path.
        /// <para>Succesfull compilation will result in the return of the class's Type, else return null.</para>
        /// </summary>
        public Type GetTypeForCompiledClassAtPath(string path)
        {
            CompilerParameters parameters = CreateCompileParameters();

            CompilerResults results = LoadAndCompile(path, parameters);

            if (results.Errors.HasErrors)
            {
                foreach (var error in results.Errors)
                {
                    MessageLogger.ErrorCompileErrors(error);
                }

                MessageLogger.ErrorFailedToCompileClassAt(path);
                return(null);
            }

            var type = GetType(results);

            return(type);
        }