记一次xlua热更问题(lua给c#加事件)

1.lua中Vector2的变量不能用Vector3来赋值。

2.lua中自己写的方法调用原类中变量

由于lua中的变量都相当于静态变量,都是跟着类走的,不跟着实例走,所以必须要在自己写的函数内部获取到要修复的这个类的实例,这里采用射线检测

local OpenGunState = function()
    local theaterRect = nil;

    --射线检测ui
    eventSystem = CS.UnityEngine.EventSystems.EventSystem.current;
    pointerEventData = CS.UnityEngine.EventSystems.PointerEventData(eventSystem);
    pointerEventData.position = CS.UnityEngine.Vector2(CS.UnityEngine.Input.mousePosition.x,CS.UnityEngine.Input.mousePosition.y);
    local uiRaycastResult = CS.System.Collections.Generic.List(CS.UnityEngine.EventSystems.RaycastResult)();
    eventSystem:RaycastAll(pointerEventData, uiRaycastResult);
    for i=0,uiRaycastResult.Count-1 do
        theaterRect = uiRaycastResult[i].gameObject:GetComponent(typeof(CS.TheaterFormationRectItem));
        if(theaterRect ~= nil) then
            break;
        end
    end

    if theaterRect ~= nil then
   ----省略
    end
    uiRaycastResult = nil;
end
 后期又找到一种方法
在前期加个:https://blog.csdn.net/qq_39435884/article/details/108487617
CS.EventTriggerListener.Get(self.btnSelf.gameObject).onDown = function()
        theaterRect = self;
    end
在初始化函数中注册onDown事件,在onDown的时候为全局的theaterRect赋值,这种方法有个弊端,EventTriggerListener是一个实现了所有输入事件的脚本(ondrag,onclick),要注意层级问题。
posted @   mc宇少  阅读(465)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2018-09-06 Rigidbody.Is Kinematic和碰撞体
2018-09-06 匿名方法和委托
点击右上角即可分享
微信分享提示