Example #1
0
    private void HandleLuaEvent(LuaEvent luaEvent)
    {
        if (!this.handlers.TryGetValue(luaEvent.Name, out var handlers))
        {
            return;
        }

        foreach (var handler in handlers)
        {
            try
            {
                var result = handler.Invoke(luaEvent);
                if (result != null)
                {
                    if (result is LuaResult <object> objectResult)
                    {
                        this.luaEventService.TriggerEventFor(
                            luaEvent.Player,
                            luaEvent.Name + result.EventSuffix,
                            luaEvent.Player,
                            this.luaValueMapper.Map(objectResult.Data));
                    }
                    else
                    {
                        this.luaEventService.TriggerEventFor(luaEvent.Player, luaEvent.Name + result.EventSuffix, luaEvent.Player);
                    }
                }
            }
            catch (Exception)
            {
                this.luaEventService.TriggerEventFor(luaEvent.Player, luaEvent.Name + ".Error", luaEvent.Player);
            }
        }
    }
Example #2
0
    public void Close()
    {
        SafeRelease(ref updateFunc);
        SafeRelease(ref lateUpdateFunc);
        SafeRelease(ref fixedUpdateFunc);

        if (UpdateEvent != null)
        {
            UpdateEvent.Dispose();
            UpdateEvent = null;
        }

        if (LateUpdateEvent != null)
        {
            LateUpdateEvent.Dispose();
            LateUpdateEvent = null;
        }

        if (FixedUpdateEvent != null)
        {
            FixedUpdateEvent.Dispose();
            FixedUpdateEvent = null;
        }
        _luaState.Dispose();
        _luaState = null;
    }
Example #3
0
    void OnApplicationQuit()
    {
        if (luaState != null)
        {
            SafeRelease(ref updateFunc);
            SafeRelease(ref lateUpdateFunc);
            SafeRelease(ref fixedUpdateFunc);
            SafeRelease(ref levelLoaded);

            if (UpdateEvent != null)
            {
                UpdateEvent.Dispose();
                UpdateEvent = null;
            }

            if (LateUpdateEvent != null)
            {
                LateUpdateEvent.Dispose();
                LateUpdateEvent = null;
            }

            if (FixedUpdateEvent != null)
            {
                FixedUpdateEvent.Dispose();
                FixedUpdateEvent = null;
            }

            luaState.Dispose();
            luaState = null;
            Instance = null;
        }
    }
        public void Close()
        {
            SafeRelease(ref updateFunc);
            SafeRelease(ref lateUpdateFunc);
            SafeRelease(ref fixedUpdateFunc);

            if (UpdateEvent != null)
            {
                UpdateEvent.Dispose();
                UpdateEvent = null;
            }

            if (LateUpdateEvent != null)
            {
                LateUpdateEvent.Dispose();
                LateUpdateEvent = null;
            }

            if (FixedUpdateEvent != null)
            {
                FixedUpdateEvent.Dispose();
                FixedUpdateEvent = null;
            }
            lua.Dispose();
            lua    = null;
            loader = null;
        }
Example #5
0
    public void Destroy()
    {
        if (luaState != null)
        {
            if (UpdateEvent != null)
            {
                UpdateEvent.Dispose();
                UpdateEvent = null;
            }

            if (LateUpdateEvent != null)
            {
                LateUpdateEvent.Dispose();
                LateUpdateEvent = null;
            }

            if (FixedUpdateEvent != null)
            {
                FixedUpdateEvent.Dispose();
                FixedUpdateEvent = null;
            }

            luaState = null;
        }
    }
Example #6
0
    public void Destroy()
    {
        if (luaState != null)
        {
            SafeRelease(ref updateFunc);
            SafeRelease(ref lateUpdateFunc);
            SafeRelease(ref fixedUpdateFunc);

            if (UpdateEvent != null)
            {
                UpdateEvent.Dispose();
                UpdateEvent = null;
            }

            if (LateUpdateEvent != null)
            {
                LateUpdateEvent.Dispose();
                LateUpdateEvent = null;
            }

            if (FixedUpdateEvent != null)
            {
                FixedUpdateEvent.Dispose();
                FixedUpdateEvent = null;
            }

            luaState = null;
        }
    }
Example #7
0
 void SafeRelease(ref LuaEvent luaEvent)
 {
     if (luaEvent != null)
     {
         luaEvent.Dispose();
         luaEvent = null;
     }
 }
Example #8
0
    private LuaEvent GetEvent(string eventName)
    {
        LuaTable table = _luaState.GetTable(eventName);
        LuaEvent e     = new LuaEvent(table);

        table.Dispose();
        table = null;
        return(e);
    }
        LuaEvent GetEvent(string name)
        {
            LuaTable table = lua.GetTable(name);
            LuaEvent e     = new LuaEvent(table);

            table.Dispose();
            table = null;
            return(e);
        }
Example #10
0
    public void HandleRequestAddParachute(LuaEvent luaEvent)
    {
        this.logger.LogInformation("{player} started parachuting", luaEvent.Player.Name);

        var otherPlayers = this.elementCollection
                           .GetByType <Player>()
                           .Except(new Player[] { luaEvent.Player });

        this.luaEventService.TriggerEventForMany(otherPlayers, "doAddParachuteToPlayer", luaEvent.Player);
    }
Example #11
0
    public void HandleRequestRemoveParachute(LuaEvent luaEvent)
    {
        luaEvent.Player.Weapons.Remove(Server.Enums.WeaponId.Parachute);
        this.logger.LogInformation("{player} finished parachuting", luaEvent.Player.Name);

        var otherPlayers = this.elementCollection
                           .GetByType <Player>()
                           .Except(new Player[] { luaEvent.Player });

        this.luaEventService.TriggerEventForMany(otherPlayers, "doAddParachuteToPlayer", luaEvent.Player);
    }
Example #12
0
 private void HandleLuaEvent(LuaEvent luaEvent)
 {
     if (this.eventHandlers.ContainsKey(luaEvent.Name))
     {
         var handlers = this.eventHandlers[luaEvent.Name];
         foreach (var handler in handlers)
         {
             handler.Invoke(luaEvent);
         }
     }
 }
Example #13
0
    private LuaEvent GetEvent(string name)
    {
        LuaTable table = this.luaState.GetTable(name, true);

        if (table == null)
        {
            throw new LuaException(string.Format("Lua table {0} not exists", name), null, 1);
        }
        LuaEvent result = new LuaEvent(table);

        table.Dispose();
        return(result);
    }
Example #14
0
 void Start()
 {
     try
     {
         UpdateEvent      = GetEvent("UpdateBeat");
         LateUpdateEvent  = GetEvent("LateUpdateBeat");
         FixedUpdateEvent = GetEvent("FixedUpdateBeat");
     }
     catch (Exception e)
     {
         Destroy(this);
         throw e;
     }
 }
Example #15
0
 private void Start()
 {
     try
     {
         this.UpdateEvent      = this.GetEvent("UpdateBeat");
         this.LateUpdateEvent  = this.GetEvent("LateUpdateBeat");
         this.FixedUpdateEvent = this.GetEvent("FixedUpdateBeat");
     }
     catch (Exception ex)
     {
         Object.Destroy(this);
         throw ex;
     }
 }
Example #16
0
    LuaEvent GetEvent(string name)
    {
        LuaTable table = luaState.GetTable(name);

        if (table == null)
        {
            throw new LuaException(string.Format("Lua table {0} not exists", name));
        }

        LuaEvent e = new LuaEvent(table);

        table.Dispose();
        table = null;
        return(e);
    }
Example #17
0
    void Start()
    {
        try
        {
            updateFunc      = GetLuaFunction("Update");
            lateUpdateFunc  = GetLuaFunction("LateUpdate");
            fixedUpdateFunc = GetLuaFunction("FixedUpdate");

            UpdateEvent      = GetEvent("UpdateBeat");
            LateUpdateEvent  = GetEvent("LateUpdateBeat");
            FixedUpdateEvent = GetEvent("FixedUpdateBeat");
        }
        catch (Exception e)
        {
            Destroy(this);
            throw e;
        }
    }
Example #18
0
    void Start()
    {
        luaState.Start();
        luaState.DoFile("Main.lua");

        updateFunc      = luaState.GetFunction("Update");
        lateUpdateFunc  = luaState.GetFunction("LateUpdate");
        fixedUpdateFunc = luaState.GetFunction("FixedUpdate");
        levelLoaded     = luaState.GetFunction("OnLevelWasLoaded");

        LuaFunction main = luaState.GetFunction("Main");

        main.Call();
        main.Dispose();
        main = null;

        UpdateEvent      = GetEvent("UpdateBeat");
        LateUpdateEvent  = GetEvent("LateUpdateBeat");
        FixedUpdateEvent = GetEvent("FixedUpdateBeat");
    }
Example #19
0
        public void InitStart()
        {
            InitLuaPath();
            InitLuaBundle();
            this.lua.Start();    //启动LUAVM

            lua.DoFile("Main.lua");

            updateFunc      = lua.GetFunction("Update");
            lateUpdateFunc  = lua.GetFunction("LateUpdate");
            fixedUpdateFunc = lua.GetFunction("FixedUpdate");

            LuaFunction main = lua.GetFunction("Main");

            main.Call();
            main.Dispose();
            main = null;

            UpdateEvent      = GetEvent("UpdateBeat");
            LateUpdateEvent  = GetEvent("LateUpdateBeat");
            FixedUpdateEvent = GetEvent("FixedUpdateBeat");
        }
Example #20
0
 public void Destroy()
 {
     if (this.luaState != null)
     {
         if (this.UpdateEvent != null)
         {
             this.UpdateEvent.Dispose();
             this.UpdateEvent = null;
         }
         if (this.LateUpdateEvent != null)
         {
             this.LateUpdateEvent.Dispose();
             this.LateUpdateEvent = null;
         }
         if (this.FixedUpdateEvent != null)
         {
             this.FixedUpdateEvent.Dispose();
             this.FixedUpdateEvent = null;
         }
         this.luaState = null;
     }
 }
Example #21
0
 /// <summary>
 /// Raises a Lua event with the specified name and caller object.
 /// </summary>
 /// <param name="eventName">The name of the event. Scripts use this to check what type of event occurred.</param>
 /// <param name="caller">The caller of the event. Scripts can use this to check if they should handle this event.</param>
 public static void RaiseEvent(string eventName, object caller)
 {
     LuaEvent?.Invoke(eventName, caller);
 }
Example #22
0
 public void HandleLuaEvent(LuaEvent luaEvent) => LuaEventTriggered?.Invoke(luaEvent);
    IEnumerator PreStartCheck()
    {
        if (GLog.IsLogInfoEnabled)
        {
            GLog.LogInfo("PreStartCheck run 0");
        }
        string ready = LuaEvent.TrigClrEvent <string>("SDK_READY_TO_START");

        if (GLog.IsLogInfoEnabled)
        {
            GLog.LogInfo("PreStartCheck run 1");
        }
        if (!string.IsNullOrEmpty(ready))
        {
            if (GLog.IsLogInfoEnabled)
            {
                GLog.LogInfo("PreStartCheck run 2");
            }
            while (ready != "ready")
            {
                yield return(null);

                if (GLog.IsLogInfoEnabled)
                {
                    GLog.LogInfo("PreStartCheck run 3");
                }
                ready = LuaEvent.TrigClrEvent <string>("SDK_READY_TO_START");
            }
        }

#if EFUN_SDK_EN || EFUN_SDK_TW
        // obb
        ResManager.Init();
#endif

        if (GLog.IsLogInfoEnabled)
        {
            GLog.LogInfo("PreStartCheck run 4");
        }
        var workpending = ResManager.MovePendingUpdate(LoadingReport);
        if (workpending != null)
        {
            while (workpending.MoveNext())
            {
                yield return(workpending.Current);

                if (GLog.IsLogInfoEnabled)
                {
                    GLog.LogInfo("PreStartCheck run 5");
                }
            }
        }

#if UNITY_EDITOR && !USE_CLIENT_RES_MANAGER
        ResManager.RecordCacheVersion("editor", int.MaxValue);
#else
        IEnumerator work = null;
        try
        {
            SetLoadingPhaseAmount(3);
            SetLoadingPhase(0);
            work = ResManager.DecompressScriptBundle("default", LoadingReport);
        }
        catch (Exception e)
        {
            if (GLog.IsLogErrorEnabled)
            {
                GLog.LogException(e);
            }
            LoadingReportError();
            yield break;
        }
        if (work != null)
        {
            while (true)
            {
                try
                {
                    if (!work.MoveNext())
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (GLog.IsLogErrorEnabled)
                    {
                        GLog.LogException(e);
                    }
                    LoadingReportError();
                    yield break;
                }
                yield return(work.Current);
            }
        }
        foreach (var flag in ResManager.GetDistributeFlags())
        {
            try
            {
                //SetLoadingPhase(loadingPhase + 1);
                work = ResManager.DecompressScriptBundle("distribute/" + flag, LoadingReport);
            }
            catch (Exception e)
            {
                if (GLog.IsLogErrorEnabled)
                {
                    GLog.LogException(e);
                }
                LoadingReportError();
                yield break;
            }
            if (work != null)
            {
                while (true)
                {
                    try
                    {
                        if (!work.MoveNext())
                        {
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        if (GLog.IsLogErrorEnabled)
                        {
                            GLog.LogException(e);
                        }
                        LoadingReportError();
                        yield break;
                    }
                    yield return(work.Current);
                }
            }
        }
        try
        {
            SetLoadingPhase(loadingPhase + 1);
            work = ResManager.UpdateResourceBundleLocalAll(LoadingReport);
        }
        catch (Exception e)
        {
            if (GLog.IsLogErrorEnabled)
            {
                GLog.LogException(e);
            }
            LoadingReportError();
            yield break;
        }
        if (work != null)
        {
            while (true)
            {
                try
                {
                    if (!work.MoveNext())
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (GLog.IsLogErrorEnabled)
                    {
                        GLog.LogException(e);
                    }
                    LoadingReportError();
                    yield break;
                }
                yield return(work.Current);
            }
        }
        try
        {
            SetLoadingPhase(loadingPhase + 1);
            work = ResManager.SplitResIndexAsyncAll(LoadingReport);
        }
        catch (Exception e)
        {
            if (GLog.IsLogErrorEnabled)
            {
                GLog.LogException(e);
            }
            LoadingReportError();
            yield break;
        }
        if (work != null)
        {
            while (true)
            {
                try
                {
                    if (!work.MoveNext())
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (GLog.IsLogErrorEnabled)
                    {
                        GLog.LogException(e);
                    }
                    LoadingReportError();
                    yield break;
                }
                yield return(work.Current);
            }
        }
        yield return(new WaitForEndOfFrame());

        if (ResManager.TryGetAssetDesc("Assets/CapstonesRes/Common/Fonts/CapstonesPlaceHolder.otf") != null)
        {
            ResManager.MarkPermanent("Assets/CapstonesRes/Common/Fonts/DistributeFontInfo.fi.txt");
            ResManager.MarkPermanent("Assets/CapstonesRes/Common/Fonts/CapstonesPlaceHolder.otf");
            ResManager.LoadRes("Assets/CapstonesRes/Common/Fonts/DistributeFontInfo.fi.txt");
            ResManager.LoadRes("Assets/CapstonesRes/Common/Fonts/CapstonesPlaceHolder.otf");
        }
#endif

        LoadingReport("WaitForBiReport", null);
        yield return(new WaitForEndOfFrame());

        try
        {
            //ResManager.UnloadAllRes();
            GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
        catch (Exception e)
        {
            if (GLog.IsLogErrorEnabled)
            {
                GLog.LogException(e);
            }
            LoadingReportError();
            yield break;
        }

        //LuaBehaviour.luaEnv.DoString("require 'main'");
        UnityEngine.SceneManagement.SceneManager.LoadScene("DemoEntry");

        yield break;
    }