protected void InitDll()
    {
        if (!FCDll.IsInitDll())
        {
            try
            {
                if (IsRecrodLog())
                {
                    FCLibHelper.fc_set_debug_print_func(print_error);
                    FCLibHelper.fc_set_output_error_func(print_error);

                    FCDll.InitDll();

                    FCLibHelper.fc_set_debug_print_func(print_error);
                    FCLibHelper.fc_set_output_error_func(print_error);
                }
                else
                {
                    FCDll.InitDll();
                }

                // 启动调试器, 启动后,就可以用工具附加调试了,默认端口是2600
                FCLibHelper.fc_switch_debug(true);
                // FCLibHelper.fc_start_debug(3000); // 指定3000这个端口并启动调试器
            }
            catch (Exception e)
            {
                print_error(e.ToString());
            }
            LoadByteCode(OnLoadScriptCallback);
        }
    }
    void  TestScriptFunc1()
    {
        try
        {
            int nV2 = FCLibHelper.fc_get_version();
            print_error("fc_get_version() is " + nV2);
            bool bDebugMode = FCLibHelper.fc_is_debug_mode();
            print_error("fc_is_debug_mode() is " + bDebugMode);
        }
        catch (Exception e)
        {
            print_error(e.ToString());
        }

        try
        {
            Vector3 v = new Vector3(1, 2, 3);
            FCDll.PushCallParam(v);
            FCLibHelper.fc_call(0, "csharp2fc_set_vector3");

            Vector4 v2 = new Vector4(22, 33, 44, 55);
            FCDll.PushCallParam(v2);
            FCLibHelper.fc_call(0, "csharp2fc_set_vector4");

            string szTest = "测试字符串传参";
            FCDll.PushCallParam(szTest);
            FCLibHelper.fc_call(0, "csharp2fc_set_string");
        }
        catch (Exception e)
        {
            print_error(e.ToString());
        }
    }
    void  InitDll()
    {
        if (!FCDll.IsInitDll())
        {
            try
            {
                FCLibHelper.fc_set_debug_print_func(print_error);
                FCLibHelper.fc_set_output_error_func(print_error);

                FCDll.InitDll();

                FCLibHelper.fc_set_debug_print_func(print_error);
                FCLibHelper.fc_set_output_error_func(print_error);

                // 注册两个测试函数
                FCLibHelper.fc_register_func("fc2csharp_set_vector3", fc2csharp_set_vector3);
                FCLibHelper.fc_register_func("fc2csharp_set_vector4", fc2csharp_set_vector4);
                FCLibHelper.fc_register_func("fc2csharp_set_string", fc2csharp_set_string);
            }
            catch (Exception e)
            {
                print_error(e.ToString());
            }
            StartCoroutine(LoadByteCode());
        }
    }
 private void OnApplicationQuit()
 {
     FCLibHelper.fc_switch_debug(false); // 停止调试吧
     Debug.Log("OnApplicationQuit");
     FCDll.ReleaseDll();                 // 这里其实需要延迟释放
     m_VMPtr = 0;
 }
Exemple #5
0
    public void InitDll()
    {
        if (!FCDll.IsInitDll())
        {
            try
            {
                FCLibHelper.fc_set_debug_print_func(print_error);
                FCLibHelper.fc_set_output_error_func(print_error);

                FCDll.InitDll();

                FCLibHelper.fc_set_debug_print_func(print_error);
                FCLibHelper.fc_set_output_error_func(print_error);

                // 启动调试器, 启动后,就可以用工具附加调试了,默认端口是2600
                FCLibHelper.fc_switch_debug(true);
                // FCLibHelper.fc_start_debug(3000); // 指定3000这个端口并启动调试器
            }
            catch (Exception e)
            {
                print_error(e.ToString());
            }
            StartCoroutine(LoadByteCode());
        }
    }
    protected override void OnAfterLoadScriptData()
    {
        // 在加载完脚本字码码后,才执行脚本函数吧
        Transform tfChild = transform.Find("Text");

        UnityEngine.UI.Text text = tfChild.GetComponent <UnityEngine.UI.Text>();
        FCDll.PushCallParam(text);
        //FCDll.PushCallObjectParam(text);
        FCLibHelper.fc_call(0, "HelloWord.SetText");
    }
Exemple #7
0
    public void OnButtonClicked(string szName)
    {
        CreateScript(); // 延迟执行吧

        if (m_nScriptInsPtr != 0)
        {
            FCDll.PushCallParam(szName);  // 传点击的按钮的参数
            FCLibHelper.fc_call(m_nScriptInsPtr, "OnButtonClicked");
        }
    }
 // 功能:Unity脚本编译后的重新初始化脚本引擎
 public void OnAfterScriptCompiler(LPInitCallback pFunc)
 {
     if (FCLibHelper.fc_is_init())
     {
         m_bLoadScript = false;
         FCLibHelper.fc_set_debug_print_func(print_error);
         FCLibHelper.fc_set_output_error_func(print_error);
         FCDll.ReleaseDll();
         InitDll();
         InitCall(pFunc);
     }
 }
Exemple #9
0
 public void  CallFunc(int arg0)
 {
     try
     {
         FCDll.PushCallParam(arg0);
         FCLibHelper.fc_call(m_nThisPtr, m_szFuncName);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
Exemple #10
0
 public void  CallFunc(int arg0, string arg1, Vector2 arg2)
 {
     try
     {
         FCDll.PushCallParam(arg0);
         FCDll.PushCallParam(arg1);
         FCDll.PushCallParam(ref arg2);
         FCLibHelper.fc_call(m_nThisPtr, m_szFuncName);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
Exemple #11
0
    void  Test()
    {
        TestExport ret = this;
        long       v   = FCGetObj.PushObj(TestExport.onPostRender);

        FCDll.PushCallParam(v);
        int[] buffer = new int[10];
        unsafe
        {
            fixed(void *p = buffer)
            {
            }
        }
        //this.GetRefList(ref arg0);
    }
    // 功能:根据脚本所传的参数,动态获取或创建一个关联的委托对象
    public T  GetDelegate <T>(long L, int nIndex = 0) where T : FCDelegateBase, new()
    {
        long pDelegatePtr = FCLibHelper.fc_get_param_ptr(L, nIndex);                            // 得到脚本委托参数(临时的,不可保留)
        long VM           = FCLibHelper.fc_get_vm_ptr(L);
        long nObjPtr      = FCLibHelper.fc_inport_delegate_get_obj_ptr(VM, pDelegatePtr);       // 得到脚本对象地址
        int  nClassNameID = FCLibHelper.fc_inport_delegate_get_class_name_id(VM, pDelegatePtr); // 类名
        int  nFuncNameID  = FCLibHelper.fc_inport_delegate_get_func_name_id(VM, pDelegatePtr);  // 函数名

        if (0 == nObjPtr && 0 == nClassNameID && 0 == nFuncNameID)
        {
            return(default(T)); // 返回空指针
        }
        FCDelegateKey key = new FCDelegateKey();

        key.nVMPtr     = VM;
        key.nThisPtr   = nObjPtr;
        key.nClassName = nClassNameID;
        key.nFuncName  = nFuncNameID;

        // -- 这个地方有必要加锁,如果不加锁的话,多线程执行脚本,并在脚本中使用委托,就会导致这里线程冲突
        if (VM != FCDll.GetMainVMPtr())
        {
            Debug.LogError("请注意多线程冲突的问题, 不可以在多线程中使用委托");
        }

        FCDelegateBase obj = null;

        if (m_Delegates.TryGetValue(key, out obj))
        {
            if (key.nVMPtr != VM)
            {
                Debug.LogError("多线程冲突, 记录有误,请检查对应的委托用法");
            }
            return((T)obj);
        }
        T pObj = new T();

        pObj.m_VMPtr      = VM;
        pObj.m_nThisPtr   = nObjPtr;
        pObj.m_szFuncName = GetDelegateFuncName(VM, pDelegatePtr);
        pObj.m_nClassName = nClassNameID;
        pObj.m_nFuncName  = nFuncNameID;
        m_Delegates[key]  = pObj;
        return(pObj);
    }
    protected void InitDll(bool bLoadByteCode = true)
    {
        if (!FCDll.IsInitDll())
        {
            m_bLoadScript = false;
            try
            {
                if (IsRecrodLog())
                {
                    FCLibHelper.fc_set_debug_print_func(print_error);
                    FCLibHelper.fc_set_output_error_func(print_error);

                    m_VMPtr = FCDll.InitDll();

                    FCLibHelper.fc_set_debug_print_func(print_error);
                    FCLibHelper.fc_set_output_error_func(print_error);
                }
                else
                {
                    m_VMPtr = FCDll.InitDll();
                }

#if  UNITY_EDITOR
                // 启动调试器, 启动后,就可以用工具附加调试了,默认端口是2600
                FCLibHelper.fc_switch_debug(true);
                // FCLibHelper.fc_start_debug(3000); // 指定3000这个端口并启动调试器
#endif
            }
            catch (Exception e)
            {
                print_error(e.ToString());
            }
            if (bLoadByteCode)
            {
                LoadByteCode(OnLoadScriptCallback);
            }
        }
    }
Exemple #14
0
    void CreateScript()
    {
        if (0 != m_nScriptInsPtr)
        {
            return;
        }
        m_VMPtr = FCDll.GetMainVMPtr();
        // 创建一个脚本
        if (string.IsNullOrEmpty(ScripClassName))
        {
            m_nScriptInsPtr = 0;
        }
        else
        {
            m_nScriptInsPtr = FCLibHelper.fc_instance(m_VMPtr, ScripClassName);
        }

        // 必要的话,调用下脚本中的Start函数
        if (m_nScriptInsPtr != 0)
        {
            // 假设存在transform变量
            SetScriptValue("transform", transform);
        }
        try
        {
            OnCreateScript();
        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
        if (m_nScriptInsPtr != 0)
        {
            FCLibHelper.fc_call(m_VMPtr, m_nScriptInsPtr, "Start");
        }
    }