示例#1
0
        public AbstractParams NotifyToLua(int luaCmd, AbstractParams p)
        {
            ScriptCommand cmd = ScriptCommand.Create(luaCmd);

            cmd.SetCallParams(p);
            cmd.Excute();

            AbstractParams ret = cmd.ReturnParams;

            cmd.Release(false);
            return(ret);
        }
示例#2
0
        void Add2Rvo()
        {
            BeginSample("Add2Rvo");
            float firsttime = Time.realtimeSinceStartup;

            if (ExactMode == ExactType.ZERO)
            {
                BeginSample("ZERO COST");
                int[] uses = new int[20];

                for (int i = 0; i < ObsTriangles.Length; i++)
                {
                    NavmeshTriangle node = ObsTriangles [i];

                    uses [0] = uses [1] = uses [2] = 0;

                    if (node != null)
                    {
                        for (int j = 0; j < node.connections.Count; j++)
                        {
                            NavmeshTriangle other = node.connections [j];
                            if (other != null)
                            {
                                int a = node.SharedEdge(other);
                                if (a != -1)
                                {
                                    uses [a] = 1;
                                }
                            }
                        }

                        for (int j = 0; j < 3; j++)
                        {
                            if (uses [j] == 0)
                            {
                                var v1 = node.GetVertex(j);
                                var v2 = node.GetVertex((j + 1) % 3);

                                Simulator.Instance.addObstacle(v1, v2);
                            }
                        }
                    }

                    ShowProgress("插入障碍点", (float)i / (ObsTriangles.Length));
                }
                EndSample();
            }


            if (ExactMode >= ExactType.ONE)
            {
                BeginSample("Buildsegments");
                Buildsegments();
                EndSample();

                BeginSample("RemoveUnused");
                RemoveUnused();
                EndSample();

                BeginSample("PushSegmentstoObstacles");
                PushSegmentstoObstacles();
                EndSample();
            }

            ShowProgress("准备构建ObstacleTree", 0);
            float time = Time.realtimeSinceStartup;

            BeginSample("processObstacles");
            if (processObstacles)
            {
                Simulator.Instance.processObstacles();
            }
            EndSample();
            LogMgr.LogFormat("Add2Rvo cost :{0}  processObstacles cost :{1} ", Time.realtimeSinceStartup - firsttime, Time.realtimeSinceStartup - time);
            ShowProgress("构建ObstacleTree 完成", 1);
            this.ClearProgressBar();
            EndSample();

#if !UNITY_EDITOR
            ObsTriangles   = null;
            segments       = null;
            tree           = null;
            point2triangle = null;
#else
            if (ObstacleDebug >= DebugMode.ShowAll && UnityEditor.EditorUtility.DisplayDialog("tips", "export kdtree asset or not ?", "OK", "NO"))
            {
                string assetpath = UnityEditor.EditorUtility.SaveFilePanelInProject("save", "kdtree", "asset", "please enter a filename");
                if (!string.IsNullOrEmpty(assetpath))
                {
                    KdtreeAsset   node = ScriptableObject.CreateInstance <KdtreeAsset> ();
                    ScriptCommand cmd  = ScriptCommand.Create((int)FrameWorkCmdDefine.GET_KDTREE);
                    cmd.Excute();

                    ScriptCommand obscmd = ScriptCommand.Create((int)FrameWorkCmdDefine.GET_OBSTACLES);
                    obscmd.Excute();

                    KdTree           tree      = cmd.ReturnParams.ReadObject() as KdTree;
                    IList <Obstacle> obstacles = obscmd.ReturnParams.ReadObject() as IList <Obstacle>;
                    node.CreateKdtree(tree, obstacles);

                    cmd.Release(true);
                    obscmd.Release(true);

                    UnityEditor.AssetDatabase.CreateAsset(node, assetpath);
                }
            }
#endif
        }
示例#3
0
        private void DispathCommand()
        {
            try
            {
                while (CommandQueue != null && CommandQueue.Count > 0)
                {
                    ScriptCommand cmd = CommandQueue.Dequeue();

                    if (cmd.isDone)
                    {
                        continue;
                    }

#if DYNAMIC_REGISTER
                    if (cmd.HasInitParams)
                    {
                        if (FrameWorkConfig.Open_DEBUG)
                        {
                            LogMgr.Log("will make a loader for script");
                        }

                        Registernew(cmd);
                    }
#endif

                    if (this.ScriptDic.ContainsKey(cmd.CMD))
                    {
                        SimpleDictionary <int, ScriptPkg> dic = this.ScriptDic[cmd.CMD];
                        int target = (int)cmd.target;

                        //double check
                        if (dic.ContainsKey(target))
                        {
                            if (cmd.HasCallParams)
                            {
                                cmd.ReturnParams = dic[target].Invoke(cmd.CallParams);
                            }
                            else
                            {
                                cmd.ReturnParams = dic[target].Invoke(null);
                            }

                            if (cmd.ReturnParams == null)
                            {
                                cmd.Release(true);
                            }
                            else
                            {
                                cmd.Release(false);
                            }
                        }
                        else
                        {
                            if (cmd.target == ScriptTarget.Unknown)
                            {
                                List <int>       keys   = dic.Keys;
                                List <ScriptPkg> values = dic.Values;
                                for (int i = 0; i < keys.Count; ++i)
                                {
                                    if (keys[i] != target)
                                    {
                                        //LogMgr.LogFormat("it will invoke {0} pkg  cmd:{1}", (ScriptTarget)keys[i],cmd.CMD);
                                        if (cmd.HasCallParams)
                                        {
                                            cmd.ReturnParams = values[i].Invoke(cmd.CallParams);
                                        }
                                        else
                                        {
                                            cmd.ReturnParams = values[i].Invoke(null);
                                        }

                                        if (cmd.ReturnParams == null)
                                        {
                                            cmd.Release(true);
                                        }
                                        else
                                        {
                                            cmd.Release(false);
                                        }

                                        break;
                                    }
                                }

                                ListPool.TryDespawn(keys);
                                ListPool.TryDespawn(values);
                            }
                        }
                    }
                    else
                    {
                        LogMgr.LogErrorFormat("命令消息错误:{0},未发现匹配的函数", cmd.CMD);
                    }
                }
            }
            catch (FrameWorkException ex)
            {
                LogMgr.LogException(ex);

                ex.RaiseExcption();
            }
            catch (Exception ex)
            {
                LogMgr.LogException(ex);
            }
        }