コード例 #1
0
ファイル: UTStructGen.cs プロジェクト: hexthedev/HexUN
        /// <summary>
        /// Generates a serializable public property that allows a struct to the both serialize
        /// a field and have public property get and set funcitons so that interfaces can be used to define
        /// properties
        /// </summary>
        /// <param name="gtStruct">the target</param>
        /// <param name="name">name of the property. This is be modifed to use _a... for field and A... for property </param>
        /// <param name="type">The type</param>
        /// <param name="comment">The comment in the tool tip of the field and intellisense of property</param>
        /// <param name="defaultValue">the default value, null if no value</param>
        public static void Utility_SerialzablePublicProperty(
            this GTStruct gtStruct,
            string name,
            string type,
            string comment,
            string defaultValue = null)
        {
            string fieldName    = $"_{name.EnforceFirstCharLowerCase()}";
            string propertyName = name.EnforceFistCharCaptial();

            using (GTField f = gtStruct.Generate_Field <GTField>())
            {
                f.Generate_Attribute <GTAttribute>().SetRequired("SerializeField");

                using (GTAttribute att = f.Generate_Attribute <GTAttribute>())
                {
                    att.SetRequired("Tooltip");
                    att.Add_Args(new Arg_Basic($"\"{comment}\""));
                }

                f.SetRequired(type, fieldName, EKeyword.PRIVATE);

                using (GTValue val = f.Generate_DefaultValue <GTValue>())
                {
                    val.SetRequired(defaultValue);
                }
            }

            using (GTProperty_OneLine p = gtStruct.Generate_Property <GTProperty_OneLine>())
            {
                p.Generate_Comment <GTComment>().SetRequired(comment);

                p.SetRequired(type, propertyName, EKeyword.PUBLIC);
                p.GetFunction = new GTProperty_OneLine.FunctionParams()
                {
                    IsPresent = true, Statement = $"{fieldName};"
                };
                p.SetFunction = new GTProperty_OneLine.FunctionParams()
                {
                    IsPresent = true, Statement = $"{fieldName} = value;"
                };
            }
        }
コード例 #2
0
ファイル: UTEventGeneration.cs プロジェクト: hexthedev/HexUN
        /// <summary>
        /// Generates the scriptable object event files associated with the given EventGenerationArgs at the path specified
        /// </summary>
        /// <param name="args"></param>
        /// <param name="sb"></param>
        /// <param name="folderPath"></param>
        public static void GenerateSOEvents(this EventGenerationArgs args, StringBuilder sb, PathString folderPath)
        {
            sb.Clear();
            // Generate the SO Event file
            using (GTFile file = new GTFile(sb, folderPath.InsertAtEnd($"{args.SoEvtName}.cs"), Encoding.UTF8))
            {
                using (GTUsings us = file.Generate_Usings <GTUsings>())
                {
                    List <string> usings = new List <string>();

                    usings.Add("UnityEngine");
                    usings.Add("HexUN.Events");
                    if (args.EvtTypeNamespace != null)
                    {
                        usings.Add(args.EvtTypeNamespace);
                    }

                    us.Add_Usings(usings.Where(u => u != args.EvtNamespace).Distinct().ToArray());
                }

                using (GTNamespace nm = file.Generate_Namespace <GTNamespace>())
                {
                    nm.SetRequired(args.EvtNamespace);

                    using (GTClass cls = nm.Generate_NamespaceObject <GTClass>())
                    {
                        using (GTAttribute attr = cls.Generate_Attribute <GTAttribute>())
                        {
                            attr.SetRequired("CreateAssetMenu");

                            attr.Add_Args(
                                new Arg_Named("fileName", $"\"{args.SoEvtName}\""),
                                new Arg_Named("menuName", $"\"{args.MenuPath}/{args.ReadableEvtType}\"")
                                );
                        }

                        cls.SetRequired(args.SoEvtName, EKeyword.PUBLIC);

                        cls.Add_Inheritances(
                            $"ScriptableObjectEvent<{args.EvtType}>"
                            );
                    }
                }
            }

            // Generate the SO Event Listener file
            sb.Clear();
            using (GTFile file = new GTFile(sb, folderPath.InsertAtEnd($"{args.SoEvtListenerName}.cs"), Encoding.UTF8))
            {
                using (GTUsings us = file.Generate_Usings <GTUsings>())
                {
                    List <string> usings = new List <string>();

                    usings.Add("HexUN.Events");
                    usings.Add("UnityEngine");
                    usings.Add("UnityEngine.Events");
                    if (args.EvtTypeNamespace != null)
                    {
                        usings.Add(args.EvtTypeNamespace);
                    }


                    us.Add_Usings(usings.Where(u => u != args.EvtNamespace).Distinct().ToArray());
                }

                using (GTNamespace nm = file.Generate_Namespace <GTNamespace>())
                {
                    nm.SetRequired(args.EvtNamespace);

                    using (GTClass cls = nm.Generate_NamespaceObject <GTClass>())
                    {
                        using (GTAttribute att = cls.Generate_Attribute <GTAttribute>())
                        {
                            att.SetRequired("AddComponentMenu");
                            att.Add_Args(new Arg_Basic($"\"{args.MenuPath}/{args.ReadableEvtType}/{args.SoEvtListenerName}\""));
                        }

                        cls.SetRequired(args.SoEvtListenerName, EKeyword.PUBLIC);

                        cls.Add_Inheritances(
                            $"ScriptableObjectEventListener<{args.EvtType}, {args.SoEvtName}, {args.UnityEvtName}>"
                            );
                    }
                }
            }
        }