Пример #1
0
    private bool LoadJValue(string sLuaFileName)
    {
        Util.ClearMemory();
        string       sLuaCode = File.ReadAllText(sLuaFileName);
        LuaScriptMgr mgr      = new LuaScriptMgr();

        mgr.DoString(sLuaCode);
        LuaFunction func = mgr.GetLuaFunction("GetJValueByLatticeIndex");

        if (null == func)
        {
            ShowErrorMessage("GetJValueByLatticeIndex function cannot been found.");
            mgr.Destroy();
            return(false);
        }

        for (int x = 0; x < m_iResolution; ++x)
        {
            for (int y = 0; y < m_iResolution; ++y)
            {
                object[] r = func.Call2(x, y);
                if (1 != r.Length || !(r[0] is double))
                {
                    ShowErrorMessage("Call function GetJValueByLatticeIndex failed, function may have error.");
                    mgr.Destroy();
                    return(false);
                }
                _jvalues[y * m_iResolution + x] = (float)(double)r[0];
            }
        }
        mgr.Destroy();
        SetJTexture(_jvalues);
        return(true);
    }
Пример #2
0
    private bool LoadJXValue(string sLuaFileName)
    {
        Util.ClearMemory();
        string       sLuaCode = File.ReadAllText(sLuaFileName);
        LuaScriptMgr mgr      = new LuaScriptMgr();

        mgr.DoString(sLuaCode);

        LuaFunction func1 = mgr.GetLuaFunction("GetJxPeroidLength");

        if (null == func1)
        {
            ShowErrorMessage("GetJxPeroidLength function cannot been found.");
            mgr.Destroy();
            return(false);
        }

        object[] r1 = func1.Call();
        if (1 != r1.Length || !(r1[0] is double))
        {
            ShowErrorMessage("GetJxPeroidLength function should return a number.");
            mgr.Destroy();
            return(false);
        }

        //The 2.0f multipler is For Runge–Kutta, we need t + dt and t + 0.5 dt both!
        int iStepLength = Mathf.RoundToInt((float)(double)r1[0] * 2.0f);

        float[] jxvalue = null;
        if (iStepLength > 0)
        {
            LuaFunction func2 = mgr.GetLuaFunction("GetJxValueInPeroid");
            if (null == func2)
            {
                ShowErrorMessage("GetJxValueInPeroid function cannot been found.");
                mgr.Destroy();
                return(false);
            }

            jxvalue = new float[iStepLength];
            for (int y = 0; y < iStepLength; ++y)
            {
                object[] r2 = func2.Call(y / (float)iStepLength);
                if (1 != r2.Length || !(r2[0] is double))
                {
                    ShowErrorMessage("GetJxValueInPeroid function should return a number.");
                    mgr.Destroy();
                    return(false);
                }

                jxvalue[y] = (float)(double)r2[0];
            }
        }
        mgr.Destroy();
        SetJXTexture(iStepLength, jxvalue);
        return(true);
    }
Пример #3
0
 void OnDestroy()
 {
     if (onDestroyFn != null)
     {
         onDestroyFn.Call();
     }
     updateFn = null;
     if (lua != null)
     {
         lua.Destroy();
     }
     lua       = null;
     _instance = null;
     if (net != null)
     {
         net.Dispose();
     }
     net = null;
     if (ChatNet != null)
     {
         ChatNet.Dispose();
     }
     ChatNet = null;
     luacache.Clear();
 }
Пример #4
0
    static int Destroy(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        LuaScriptMgr obj = LuaScriptMgr.GetNetObject <LuaScriptMgr>(L, 1);

        obj.Destroy();
        return(0);
    }
Пример #5
0
 /// <summary>
 /// 析构函数
 /// </summary>
 void OnDestroy()
 {
     if (Const.DebugMode)
     {
         Application.logMessageReceived -= HandleLog;
     }
     CallMethod("OnDestroy");   //初始化完成
     Debugger.Log("~GameManager was destroyed");
     uluaMgr.Destroy();
 }
Пример #6
0
 /// <summary>
 /// 析构函数
 /// </summary>
 void OnDestroy()
 {
     ioo.networkManager.Unload();
     if (uluaMgr != null)
     {
         uluaMgr.Destroy();
         uluaMgr = null;
     }
     Debug.Log("~GameManager was destroyed");
 }
Пример #7
0
    private bool LoadManetic(string sLuaFileName)
    {
        Util.ClearMemory();
        string       sLuaCode = File.ReadAllText(sLuaFileName);
        LuaScriptMgr mgr      = new LuaScriptMgr();

        mgr.DoString(sLuaCode);
        LuaFunction func = mgr.GetLuaFunction("GetMagneticByLatticeIndex");

        if (null == func)
        {
            ShowErrorMessage("GetMagneticByLatticeIndex function cannot been found.");
            mgr.Destroy();
            return(false);
        }

        for (int x = 0; x < m_iResolution; ++x)
        {
            for (int y = 0; y < m_iResolution; ++y)
            {
                object[] r = func.Call2(x, y);
                if (3 != r.Length ||
                    !(r[0] is double) ||
                    !(r[1] is double) ||
                    !(r[2] is double))
                {
                    ShowErrorMessage("GetMagneticByLatticeIndex should return 3 numbers.");
                    mgr.Destroy();
                    return(false);
                }

                _mags[y * m_iResolution + x] = new Vector3(
                    (float)(double)r[0],
                    (float)(double)r[1],
                    (float)(double)r[2]);
            }
        }
        mgr.Destroy();
        SetCurrentState(_mags);
        return(true);
    }
Пример #8
0
        void OnDestroy()
        {
            if (m_ObjRootTran)
            {
                UnityEngine.Object.Destroy(m_ObjRootTran.gameObject);
                m_ObjRootTran = null;
            }

            ConnectionMgr.instance.Close();
            ms_luaMgr.Destroy();
            ms_resourceMgr.Destroy();
        }
Пример #9
0
    IEnumerator DelayCloseLua()
    {
        yield return(new WaitForEndOfFrame());

        mgr.Destroy();
        mgr = new LuaScriptMgr();
        mgr.Start();
        LuaState l         = mgr.lua;
        string   readToEnd = ConfigFileReader.FilePath(Path.Combine(Application.streamingAssetsPath, "LuaFile/LuaManager.lua"));

        mgr.DoString(readToEnd);
    }
Пример #10
0
 private void OnGUI()
 {
     if (GUI.Button(new Rect(20, 20, 200, 80), "Reflect"))
     {
         LuaState lua = new LuaState();
         lua.DoString(script);
         lua.Close();
     }
     if (GUI.Button(new Rect(20, 120, 200, 80), "Wrap"))
     {
         LuaScriptMgr lua = new LuaScriptMgr();
         lua.Start();
         lua.DoString(script2);
         lua.Destroy();
     }
 }
Пример #11
0
 private void OnGUI()
 {
     if (GUI.Button(new Rect(20, 20, 200, 80), "ReadFile"))
     {
         if (mgr == null)
         {
             mgr = new LuaScriptMgr();
             mgr.Start();
         }
         mgr.lua.DoFile("Logic/hotfix_hello");
     }
     if (GUI.Button(new Rect(20, 120, 200, 80), "Dispose"))
     {
         if (mgr != null)
         {
             mgr.Destroy();
             Debug.Log("destroy mgr");
         }
     }
 }
Пример #12
0
    public static CGroupTable BuildGroupTable(string sLuaFileName)
    {
        string       sLuaCode = File.ReadAllText(sLuaFileName);
        LuaScriptMgr mgr      = new LuaScriptMgr();

        mgr.DoString(sLuaCode);

        LuaFunction func1 = mgr.GetLuaFunction("GetGroupElementNumber");

        if (null == func1)
        {
            CManager.ShowMessage("GetGroupElementNumber function cannot been found.");
            mgr.Destroy();
            return(null);
        }
        object[] r1 = func1.Call();
        if (2 != r1.Length || !(r1[0] is double && r1[1] is double))
        {
            string sRetInfo = r1.Length + " values:";
            for (int i = 0; i < r1.Length; ++i)
            {
                sRetInfo += (null == r1[i] ? "null" : r1[i].GetType().Name) + ",";
            }
            CManager.ShowMessage("GetGroupElementNumber must return two integers, now return is " + sRetInfo);
            mgr.Destroy();
            return(null);
        }

        int m = Mathf.RoundToInt((float)(double)r1[0]);
        int n = Mathf.RoundToInt((float)(double)r1[1]);

        Debug.Log(string.Format("table m:{0} and n:{1}", m, n));
        if (m + n - 1 >= 4096)
        {
            CManager.ShowMessage(string.Format("mus thave m + n - 1 < 4096, but now m={0}, n={1}", m, n));
            mgr.Destroy();
            return(null);
        }

        LuaFunction func2 = mgr.GetLuaFunction("GetIGTableNumber");

        if (null == func2)
        {
            CManager.ShowMessage("GetIGTableNumber function cannot been found.");
            mgr.Destroy();
            return(null);
        }
        object[] r2 = func2.Call();
        if (1 != r2.Length || !(r2[0] is double))
        {
            string sRetInfo = r2.Length + " values:";
            for (int i = 0; i < r2.Length; ++i)
            {
                sRetInfo += (null == r2[i] ? "null" : r2[i].GetType().Name) + ",";
            }
            CManager.ShowMessage("GetIGTableNumber must return one integer, now return is " + sRetInfo);
            mgr.Destroy();
            return(null);
        }
        int ig = Mathf.RoundToInt((float)(double)r2[0]);

        CGroupTable gt = new CGroupTable
        {
            m_sFileName = "",
            m_eType     = CGroupTable.GroupTableType.Lua,

            m_iM = (short)m,
            m_iN = (short)n,
            m_MI = new short[m + n - 1, m + n - 1],
            m_EI = new float[m],
            m_IG = new short[ig],
        };

        //Fill MT
        LuaFunction func3 = mgr.GetLuaFunction("GetMTTable");

        if (null == func3)
        {
            CManager.ShowMessage("GetMTTable function cannot been found.");
            mgr.Destroy();
            return(null);
        }
        for (int i = 0; i < m + n - 1; ++i)
        {
            for (int j = 0; j < m + n - 1; ++j)
            {
                object[] r3 = func3.Call2(i + 1, j + 1);
                if (1 != r3.Length || !(r3[0] is double))
                {
                    string sRetInfo = r3.Length + " values:";
                    for (int k = 0; k < r3.Length; ++i)
                    {
                        sRetInfo += (null == r3[k] ? "null" : r3[k].GetType().Name) + ",";
                    }
                    CManager.ShowMessage("GetMTTable must return one integer, now return is " + sRetInfo);
                    mgr.Destroy();
                    return(null);
                }

                gt.m_MI[i, j] = (short)(Mathf.RoundToInt((float)(double)r3[0]) - 1);
            }
        }

        //Fill EI
        LuaFunction func4 = mgr.GetLuaFunction("GetETTable");

        if (null == func4)
        {
            CManager.ShowMessage("GetETTable function cannot been found.");
            mgr.Destroy();
            return(null);
        }
        for (int i = 0; i < m; ++i)
        {
            object[] r4 = func4.Call(i + 1);
            if (1 != r4.Length || !(r4[0] is double))
            {
                string sRetInfo = r4.Length + " values:";
                for (int k = 0; k < r4.Length; ++i)
                {
                    sRetInfo += (null == r4[k] ? "null" : r4[k].GetType().Name) + ",";
                }
                CManager.ShowMessage("GetETTable must return one float, now return is " + sRetInfo);
                mgr.Destroy();
                return(null);
            }
            gt.m_EI[i] = (float)(double)r4[0];
        }

        //Fill IG
        LuaFunction func5 = mgr.GetLuaFunction("GetIGTable");

        if (null == func5)
        {
            CManager.ShowMessage("GetIGTable function cannot been found.");
            mgr.Destroy();
            return(null);
        }
        for (int i = 0; i < ig; ++i)
        {
            object[] r5 = func5.Call(i + 1);
            if (1 != r5.Length || !(r5[0] is double))
            {
                string sRetInfo = r5.Length + " values:";
                for (int k = 0; k < r5.Length; ++i)
                {
                    sRetInfo += (null == r5[k] ? "null" : r5[k].GetType().Name) + ",";
                }
                CManager.ShowMessage("GetIGTable must return one integer, now return is " + sRetInfo);
                mgr.Destroy();
                return(null);
            }
            gt.m_IG[i] = (short)(Mathf.RoundToInt((float)(double)r5[0]) - 1);
        }
        mgr.Destroy();
        return(gt);
    }
Пример #13
0
 public void Destroy()
 {
     luaMgr.Destroy();
 }