FairyGUI 代码生成插件

 

 

生成的代码

/** This is an automatically generated class by FairyGUI. Please do not modify it. **/

using FairyGUI;

namespace ETModel
 {

	[ObjectSystem]
	public class UI_CanteraComponentAwakeSystem : AwakeSystem<UI_CanteraComponent, GObject> {

		public override void Awake(UI_CanteraComponent self, GObject go) {
			self.Awake(go);
		}
	}

	public partial class UI_CanteraComponent : FUI {
		public const string UIPackageName = "ComponentPackage";
		public const string UIResName = "CanteraComponent";
		public const string UIName = "ComponentPackage.CanteraComponent";
		public GComponent self;

		public GButton m_closeBtn;
		public GButton m_settingBtn;
		public GLoader m_icon;
		public GTextField m_describe;
		public GList m_powerStarList;
		public GList m_timeStarList;
		public GButton m_leftBtn;
		public GButton m_rightBtn;
		public GProgressBar m_power;
		public GProgressBar m_time;

		public void Awake(GObject go) {
			if (go == null) {
				return;
			}
			GObject = go;
			Name = UIName;
			self = (GComponent)go;
			self.Add(this);
			var com = go.asCom;
			if (com != null) {
				this.m_closeBtn = (GButton)com.GetChildAt(4);
				this.m_settingBtn = (GButton)com.GetChildAt(5);
				this.m_icon = (GLoader)com.GetChildAt(6);
				this.m_describe = (GTextField)com.GetChildAt(7);
				this.m_powerStarList = (GList)com.GetChildAt(10);
				this.m_timeStarList = (GList)com.GetChildAt(11);
				this.m_leftBtn = (GButton)com.GetChildAt(12);
				this.m_rightBtn = (GButton)com.GetChildAt(13);
				this.m_power = (GProgressBar)com.GetChildAt(16);
				this.m_time = (GProgressBar)com.GetChildAt(17);
				OnInitialization();
			}
		}

		partial void OnInitialization();

		public override void Dispose() {
			base.Dispose();
			self.Remove();
			self = null;
			m_closeBtn = null;
			m_settingBtn = null;
			m_icon = null;
			m_describe = null;
			m_powerStarList = null;
			m_timeStarList = null;
			m_leftBtn = null;
			m_rightBtn = null;
			m_power = null;
			m_time = null;
		}
	}
}

 

--region LuaCodeWriter
local LuaCodeWriter = fclass()

function LuaCodeWriter:ctor(config)
    config = config or {}
    self.blockStart = config.blockStart or '{'
    self.blockEnd = config.blockEnd or '}'
    self.blockFromNewLine = config.blockFromNewLine
    if self.blockFromNewLine == nil then
        self.blockFromNewLine = true
    end
    if config.usingTabs then
        self.indentStr = '\t'
    else
        self.indentStr = '    '
    end
    self.usingTabs = config.usingTabs
    self.endOfLine = config.endOfLine or '\n'
    self.lines = {}
    self.indent = 0

    self:writeMark()
end

function LuaCodeWriter:writeMark()
    table.insert(self.lines, '--- This is an automatically generated class by FairyGUI. Please do not modify it. ---')
    table.insert(self.lines, '')
end

function LuaCodeWriter:writeln(format, ...)
    if not format then
        table.insert(self.lines, '')
        return
    end

    local str = ''
    for i = 0, self.indent - 1 do
        str = str .. self.indentStr
    end
    str = str .. string.format(format, ...)
    table.insert(self.lines, str)

    return self
end

function LuaCodeWriter:startBlock()
    if self.blockFromNewLine or #self.lines == 0 then
        self:writeln(self.blockStart)
    else
        local str = self.lines[#self.lines]
        self.lines[#self.lines] = str .. ' ' .. self.blockStart
    end
    self.indent = self.indent + 1

    return self
end

function LuaCodeWriter:endBlock()
    self.indent = self.indent - 1
    self:writeln(self.blockEnd)

    return self
end

function LuaCodeWriter:incIndent()
    self.indent = self.indent + 1

    return self
end

function LuaCodeWriter:decIndent()
    self.indent = self.indent - 1

    return self
end

function LuaCodeWriter:reset()
    if #self.lines > 0 then
        self.lines = {}
    end
    self.indent = 0

    self:writeMark()
end

function LuaCodeWriter:tostring()
    return table.concat(self.lines, self.endOfLine)
end

function LuaCodeWriter:save(filePath)
    local str = table.concat(self.lines, self.endOfLine)

    CS.System.IO.File.WriteAllText(filePath, str)
end

--endregion

local projectCustomPropertiesDic;

local customPropKeys = {
    key_gen_lua = { name = "key_gen_lua", default_value = "true" },
    key_lua_file_extension_name = { name = "key_lua_file_extension_name", default_value = "lua" },
    key_lua_path_root = { name = "key_lua_path_root", default_value = "UIGenCode/" },
    key_wrapper_namespace = { name = "key_wrapper_namespace", default_value = "CS.FairyGUI" },
}

local function get_project_custom_property_value(key_name)
    if (projectCustomPropertiesDic and projectCustomPropertiesDic:ContainsKey(key_name)) then
        return projectCustomPropertiesDic:get_Item(key_name);
    else
        return customPropKeys[key_name].default_value;
    end
end

function onPublish(handler)
    if not handler.genCode or handler.publishDescOnly then
        return
    end

    projectCustomPropertiesDic = App.project:GetSettings("CustomProperties").elements;

    local gen_lua = get_project_custom_property_value(customPropKeys.key_gen_lua.name);
    if (gen_lua == "true") then
        handler.genCode = false --prevent default output
        App.consoleView:Clear();
        fprint("Handling gen lua code in plugin.")
        genCode(handler)
    end
end

-- this is copied from Editor-Install-Path/Resources/Data/StreamingAssets/Scripts
function genCode(handler) 
    local settings = handler.project:GetSettings("Publish").codeGeneration
    local codePkgName = handler:ToFilename(handler.pkg.name); --convert chinese to pinyin, remove special chars etc.
    local exportCodePath = handler.exportCodePath..'/'..codePkgName
    local namespaceName = codePkgName
    local ns = 'fgui'
    
    if settings.packageName~=nil and settings.packageName~='' then
        namespaceName = settings.packageName..'.'..namespaceName;
    end
    
    --CollectClasses(stripeMemeber, stripeClass, fguiNamespace)
    local classes = handler:CollectClasses(settings.ignoreNoname, settings.ignoreNoname, ns)
    
    handler:SetupCodeFolder(exportCodePath, "ts") --check if target folder exists, and delete old files

    local getMemberByName = settings.getMemberByName

    local classCnt = classes.Count
    local writer = CodeWriter.new({ blockFromNewLine=false, usingTabs = true  })

    --FUIPackageStart--
    writer:writeln('namespace ETModel')
    writer:startBlock()
    writer:writeln('public static partial class FUIPackage')
    writer:startBlock()

    writer:writeln('public const string %s = "%s";',codePkgName,codePkgName)

    -- 生成所有的
    local itemCount = handler.items.Count
    for i=0,itemCount-1 do
        --fprint(handler.items[i].path)
        local path = string.format('%s%s%s',codePkgName,handler.items[i].path,handler.items[i].name)
        --writer:writeln('public const string %s = "ui://%s";//%s',string.gsub(path,'/','_'),string.format('%s/%s',codePkgName,handler.items[i].name),string.format('ui://%s%s',handler.pkg.id,handler.items[i].id))
        writer:writeln('public const string %s = "ui://%s";',string.gsub(path,'/','_'),string.format('%s%s',handler.pkg.id,handler.items[i].id))
    end

    writer:endBlock()--class
    writer:endBlock()--namespace
    local binderPackageName = 'Package'..codePkgName
    writer:save(exportCodePath..'/'..binderPackageName..'.cs')
    --FUIPackageEnd--
    
    for i=0,classCnt-1 do
        local classInfo = classes[i]
        local members = classInfo.members
        local references = classInfo.references
        writer:reset()

        --local refCount = references.Count
        writer:writeln('using FairyGUI;')
        writer:writeln('using ETModel;')
        writer:writeln()
        writer:writeln('namespace ETHotfix')
        writer:writeln()
        writer:startBlock()
        writer:writeln()
        writer:writeln('[ObjectSystem]')
        writer:writeln('public class %sAwakeSystem : AwakeSystem<%s, GObject>',classInfo.className,classInfo.className)
        writer:startBlock()
        writer:writeln()
        writer:writeln('public override void Awake(%s self, GObject go)',classInfo.className)
        writer:startBlock()
        writer:writeln('self.Awake(go);')
        writer:endBlock()
        writer:endBlock()
        writer:writeln()


        writer:writeln('public partial class %s : %s', classInfo.className, 'FUI')
        writer:startBlock()
        writer:writeln('public const string UIPackageName = "%s";', handler.pkg.name)
        writer:writeln('public const string UIResName = "%s";', classInfo.resName)
        writer:writeln('public const string UIName = "%s.%s";', handler.pkg.name,classInfo.resName)
        writer:writeln('public GComponent self;', classInfo.resName)
        writer:writeln()

        local memberCnt = members.Count
        for j=0,memberCnt-1 do
            local memberInfo = members[j]
            local typeName = memberInfo.type
            -- 判断是不是我们自定义类型
            if string.find(typeName,'fgui')==nil then
                writer:writeln('public %s %s;', typeName,memberInfo.varName)
            else
                writer:writeln('public %s %s;', string.gsub(memberInfo.type,'fgui.',''),memberInfo.varName)
            end
        end
        --writer:writeln('public static string URL = "ui://%s%s";', handler.pkg.id, classInfo.classId)
        writer:writeln()

        writer:writeln('public void Awake(GObject go)')
        writer:startBlock()
        writer:writeln('if (go == null)')
        writer:startBlock()
        writer:writeln('return;')
        writer:endBlock()
        writer:writeln('GObject = go;')
        writer:writeln('Name = UIName;')
        writer:writeln('self = (GComponent)go;')
        writer:writeln('self.Add(this);')
        writer:writeln('var com = go.asCom;')
        writer:writeln('if (com != null)')
        writer:startBlock()
        for j=0,memberCnt-1 do
            local memberInfo = members[j]
            local typeName = memberInfo.type
            if memberInfo.group==0 then
                 -- 判断是不是我们自定义类型
                if getMemberByName then
                    if string.find(typeName,'fgui')==nil then
                        writer:writeln('this.%s = ComponentFactory.Create<%s, GObject>( com.GetChildAt(%s));', memberInfo.varName, typeName, memberInfo.name)
                    else
                        writer:writeln('this.%s = (%s)com.GetChild("%s");', memberInfo.varName, string.gsub(memberInfo.type,'fgui.',''), memberInfo.name)
                    end
                else
                    if string.find(typeName,'fgui')==nil then
                        writer:writeln('this.%s = ComponentFactory.Create<%s, GObject>( com.GetChildAt(%s));', memberInfo.varName, typeName, memberInfo.index)
                    else
                        writer:writeln('this.%s = (%s)com.GetChildAt(%s);', memberInfo.varName, string.gsub(memberInfo.type,'fgui.',''), memberInfo.index)
                    end
                end
            elseif memberInfo.group==1 then
                if getMemberByName then
                    writer:writeln('this.%s = com.GetController("%s");', memberInfo.varName, memberInfo.name)
                else
                    writer:writeln('this.%s = com.GetControllerAt(%s);', memberInfo.varName, memberInfo.index)
                end
            else
                if getMemberByName then
                    writer:writeln('this.%s = com.GetTransition("%s");', memberInfo.varName, memberInfo.name)
                else
                    writer:writeln('this.%s = com.GetTransitionAt(%s);', memberInfo.varName, memberInfo.index)
                end
            end
        end
        --writer:writeln('OnInitialization();')
        writer:endBlock()
        writer:endBlock()
        writer:writeln()
        --writer:writeln('partial void OnInitialization();')
        writer:writeln()
        writer:writeln('public override void Dispose()')
        writer:startBlock()
        writer:writeln('base.Dispose();')
        writer:writeln('self.Remove();')
        writer:writeln('self = null;')

        for j=0,memberCnt-1 do
            local memberInfo = members[j]
            local typeName = memberInfo.type
            if memberInfo.group==0 then
                 -- 判断是不是我们自定义类型
                 if string.find(typeName,'fgui')==nil then
                    writer:writeln('%s.Dispose();', memberInfo.varName)
                end
                    writer:writeln('%s = null;', memberInfo.varName)
            else
                if getMemberByName then
                    writer:writeln('%s = null;', memberInfo.varName)
                else
                    writer:writeln('%s = null;', memberInfo.varName)
                end
            end
        end

        writer:endBlock()
        writer:endBlock() --class
        writer:endBlock()

        writer:save(exportCodePath..'/'..classInfo.className..'.cs')
    end

end

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
-------------------- FairyGUI Copyright © 2014-2020 FairyGUI.com Version 3.4.0 support@fairygui.com -------------------- FairyGUI is a flexible UI framework for Unity, working with the professional FREE Game UI Editor: FairyGUI Editor. Download the editor from here: http://en.fairygui.com/ -------------------- Get Started -------------------- Run demos in Assets/FairyGUI/Examples/Scenes. The UI project is in Examples-UIProject.zip, unzip it anywhere. Use FairyGUI Editor to open it. Using FairyGUI in Unity: * Place a UIPanel in scene by using editor menu GameObject/FairyGUI/UIPanel. * Or using UIPackage.CreateObject to create UI component dynamically, and then use GRoot.inst.AddChild to show it on screen. ----------------- Version History ----------------- 3.4.0 - NEW: Add multi-display support. - NEW: Add API DynamicFont(name, font). - IMPROVED: Compatibility with 2018.3. - FIXED: Incorrect letter spacing on mobile platform. - FIXED: Same transition hook may be called twice. - FIXED: Exception raised when texture was disposed before object was disposed. 3.3.0 - NEW: Add textfield maxwidth feature. - NEW: Add API to query package dependencies. - IMPROVED: Graphics module refactor. Now it is more convenient to create various shapes(pie, lines, polygon etc) and do mesh deform. Memory usage on building mesh is also dropped. Also supports automatically setup uv for arbitrary quad to avoid seam between 2 triangles. All shaders are updated, don't forget to replace shaders in your project. - IMPROVED: Text-Brighter mechanism is removed, so FairyGUI-Text-Brighter.shader is removed. - IMPROVED: Add support for shrinking multi-line text. - IMPROVED: Improve Lua support. 3.2.0 - NEW: Add DisplayObjectInfo component. Define script symbol FAIRYGUI_TEST to enable it. - FIXED: A virtual list scrolling bug. - FIXED: A BlendMode bug. 3.1.0 - NEW: Draw extra 8 directions instead of 4 directions to archive text outline effect. Toggle option is UIConfig.enhancedTextOutlineEffect. - IMPROVED: Eexecution efficiency optimizations. - IMPROVED: GoWrapper now supports multiple materials. - FIXED: Correct cleanup action for RemovePackage. 3.0.0 From this version, we change package data format to binary. Editor version 3.9.0 with 'binary format' option checked in publish dialog is required to generating this kind of format. Old XML format is not supported anymore. - NEW: Add UIPackage.UnloadAssets and UIPackage.ReloadAssets to allow unload package resources without removing the package. - NEW: Add TransitionActionType.Text and TransitionActionType.Icon. 2.4.0 - NEW: GTween is introduced, DOTween is no longer used inside FairyGUI. - NEW: Transitions now support playing partially and pausing. - IMPROVED: Change the way of registering bitmap font. - FIXED: A GButton pivot issue. - FIXED: Correct text align behavior. 2.3.0 - NEW: Allow loader to load component. - NEW: Add text template feature. - FIXED: Exclude invisible object in FairyBatching. 2.2.0 - NEW: Modify shaders to fit linear color space. - IMPROVED: Improve relation system to handle conditions that anchor is set. - IMPROVED: Eliminate GC in transition. - FIXED: Fixed a bug of unloading bundle in UIPackage. - FIXED: Fixed issue that some blend mode(multiply, screen) works improperly. 2.1.0 - NEW: Add GGraph.DrawRoundRect. - NEW: Add FillType.ScaleNoBorder. - FIXED: Repair potential problems of virtual list. - FIXED: Fixed a bug in handling shared materials. 2.0.0 - NEW: RTL Text rendering support. Define scripting symbols RTL_TEXT_SUPPORT to enabled it. - NEW: Support for setting GObject.data in editor. - NEW: Support for setting selectedIcon of list item in editor. - IMPROVED: Add UIConfig.depthSupportForPaitingMode. - IMPROVED: Set sorting order of popup automatically. - FIXED: Fixed a text layout bug when line spacing is negative. - FIXED: Reset ScrollPane.draggingPane when an active scrollPane is being disposed. - FIXED: Fixed a bug of skew rendering.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鱼游戏开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值