コード例 #1
0
        private static string GetConstructor(ChannelsDefinition def)
        {
            string str = "";

            foreach (var channel in def.channels)
            {
                str += "        RegisterInputChannel(\"" + channel.name + "\", " + GetChannelDefault(channel) + ", " + channel.clears.ToString().ToLower() + ");\n";
            }

            return(str);
        }
コード例 #2
0
        private static string GetProperties(ChannelsDefinition def)
        {
            string str = "";

            foreach (var channel in def.channels)
            {
                str += GetProperty(channel);
            }

            return(str);
        }
コード例 #3
0
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("Generate Class"))
            {
                var path = AssetDatabase.GetAssetPath(target);
                if (path.Length > 0)
                {
                    ChannelsClassGenerator.GenerateClass(target as ChannelsDefinition);
                }
            }

            ChannelsDefinition def = target as ChannelsDefinition;

            DrawDefaultInspector();
        }
コード例 #4
0
        public static void GenerateClass(ChannelsDefinition def)
        {
            string generated = string.Format(classTemplate, def.name, GetConstructor(def), GetProperties(def), def.baseClass);

            string defPath = AssetDatabase.GetAssetPath(def);

            if (defPath.Length > 0)
            {
                string newPath = defPath.Substring(0, defPath.LastIndexOf(".")) + ".cs";

                StreamWriter outStream = new StreamWriter(newPath);
                outStream.Write(generated);
                outStream.Close();
                AssetDatabase.Refresh();
            }
        }