Beispiel #1
0
        private KdTree.ObstacleTreeNode Assign2Kdtree(KdtreeObstacleTreeNode treenode, Dictionary <int, KdtreeObstacle> dic, Dictionary <int, KdtreeObstacleTreeNode> treedic, Dictionary <int, Obstacle> obsdic)
        {
            if (treenode == null || treenode.id == -1)
            {
                return(null);
            }

            KdTree.ObstacleTreeNode kdnode = new KdTree.ObstacleTreeNode();
            kdnode.obstacle_ = CreateObstacle(dic[treenode.obstacleID], dic, obsdic);

            KdTree.ObstacleTreeNode left  = Assign2Kdtree(treenode.leftID != -1 ? treedic[treenode.leftID]:null, dic, treedic, obsdic);
            KdTree.ObstacleTreeNode right = Assign2Kdtree(treenode.rightID != -1 ?treedic[treenode.rightID]:null, dic, treedic, obsdic);

            ScriptCommand setleft_cmd  = ScriptCommand.Create((int)FrameWorkCmdDefine.SET_LEFT_LEAF);
            ScriptCommand setright_cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.SET_RIGHT_LEAF);

            setleft_cmd.CallParams.WriteObject(kdnode);
            setleft_cmd.CallParams.WriteObject(left);
            setleft_cmd.ExcuteAndRelease();

            setright_cmd.CallParams.WriteObject(kdnode);
            setright_cmd.CallParams.WriteObject(right);
            setright_cmd.ExcuteAndRelease();

            return(kdnode);
        }
Beispiel #2
0
        void OnDestroy()
        {
            ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.SceneLeave, 1);

            cmd.CallParams.WriteInt(GameSceneCtr.mIns.CurScene.buildIndex);
            cmd.ExcuteAndRelease();
        }
Beispiel #3
0
 public virtual void Release()
 {
     for (int i = this.uicontainer.Count - 1; i >= 0; i--)
     {
         GameUI        gameui = this.uicontainer[i];
         ScriptCommand cmd    = ScriptCommand.Create((int)FrameWorkCmdDefine.UICallRelease, 1);
         cmd.target = ScriptTarget.Sharp;
         cmd.CallParams.WriteObject(gameui);
         cmd.Excute();
     }
 }
Beispiel #4
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);
        }
Beispiel #5
0
        protected void CloseAtIndex(GameUI gameui, int index, bool force = false, AbstractParams p = null)
        {
            if (!removeList.Contains(gameui))
            {
                //check children
                GameUI[] childrenUI = gameui.GetComponentsInChildren <GameUI>();
                for (int i = 0; i < childrenUI.Length; ++i)
                {
                    if (childrenUI[i] != gameui)
                    {
                        for (int j = 0; j < uicontainer.Count; ++j)
                        {
                            if (uicontainer[j] == childrenUI[i])
                            {
                                CloseAtIndex(uicontainer[j], j, force);
                            }
                        }
                    }
                }

                ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.UICallExit);
                if (p != null)
                {
                    cmd.CallParams = p;
                }
                cmd.target = ScriptTarget.Sharp;
                cmd.CallParams.InsertObject(0, gameui);
                cmd.Excute();

                if (p != null)
                {
                    p.Release();
                }

                CacheCommand.CanCelAllBy(gameui);

                if (force)
                {
                    gameui.DestorySelf();
                }
                else
                {
                    DestroyUI(gameui);
                }

                removeList.Add(gameui);
            }
        }
Beispiel #6
0
 private void CallUI(GameUI ui, AbstractParams p)
 {
     if (ui.HasEnter)
     {
         ui.CallRefresh(p);
     }
     else
     {
         ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.UICallEnter);
         if (p != null)
         {
             cmd.CallParams = p;
         }
         cmd.CallParams.InsertObject(0, ui);
         cmd.target = ScriptTarget.Sharp;
         cmd.Excute();
     }
 }
Beispiel #7
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            Navmesh2Obstacle script = target as Navmesh2Obstacle;

            if (GUILayout.Button("Do Mesh 2 Obstacle"))
            {
                ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.DO_MESH_2_OBS);
                cmd.CallParams.WriteObject(script);
                cmd.ExcuteAndRelease();
            }

            if (GUILayout.Button("Add to rvo"))
            {
                ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.DO_ADD_2_RVO);
                cmd.CallParams.WriteObject(script);
                cmd.ExcuteAndRelease();
            }
        }
Beispiel #8
0
        public KdTree CopythisToKdtree(IList <Obstacle> target)
        {
            KdTree tree = new KdTree();

            Dictionary <int, KdtreeObstacle> dic = new Dictionary <int, KdtreeObstacle>();

            for (int i = 0; i < obstacles.Count; ++i)
            {
                dic[obstacles[i].id_] = obstacles[i];
            }

            Dictionary <int, KdtreeObstacleTreeNode> treedic = new Dictionary <int, KdtreeObstacleTreeNode>();

            for (int i = 0; i < treenodes.Count; ++i)
            {
                treedic[treenodes[i].id] = treenodes[i];
            }

            Dictionary <int, Obstacle> obsdic = new Dictionary <int, Obstacle>();

            KdTree.ObstacleTreeNode treenode    = Assign2Kdtree(treedic[0], dic, treedic, obsdic);
            ScriptCommand           setnode_cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.SET_KDTREE_TREENODE);

            setnode_cmd.CallParams.WriteObject(tree);
            setnode_cmd.CallParams.WriteObject(treenode);
            setnode_cmd.ExcuteAndRelease();

            //assign obstacles
            target.Clear();
            var en = obsdic.GetEnumerator();

            while (en.MoveNext())
            {
                target.Add(en.Current.Value);
            }

            return(tree);
        }
Beispiel #9
0
            internal void UpdateInFrame(long cnt)
            {
                if (runners.Count == 0)
                {
                    return;
                }

                List <NodeCanvas> values = GetAllFSM();

                for (int i = 0; i < values.Count; ++i)
                {
                    NodeCanvas nodecanvas = values[i];
                    if (nodestates.ContainsKey(nodecanvas))
                    {
                        FSMRunerState runningstate = nodestates[nodecanvas];
                        if (runningstate.isRunning && runningstate.current != null)
                        {
                            FSMElement current   = runningstate.current;
                            FSMElement laststate = runningstate.laststate;

                            if (laststate != null)
                            {
                                if (laststate != current)
                                {
                                    // LogMgr.LogError("this is  " + nodecanvas);
                                    ScriptCommand exitcmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallExit);
                                    exitcmd.CallParams.WriteObject(laststate);
                                    exitcmd.ExcuteAndRelease();

                                    ScriptCommand entercmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallEnter);
                                    entercmd.CallParams.WriteObject(current);
                                    entercmd.ExcuteAndRelease();
                                }
                            }
                            else
                            {
                                // LogMgr.LogError("this is  " + nodecanvas);
                                ScriptCommand cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallEnter);
                                cmd.CallParams.WriteObject(current);
                                cmd.ExcuteAndRelease();
                            }

                            runningstate.laststate = current;

                            bool ret = current.UpdateFrameInFSM(cnt);
                            if (!ret && runningstate.isRunning)
                            {
                                FSMElement next = current.SelectForNext();
                                if (next != null)
                                {
                                    runningstate.current = next;
                                }
                                else
                                {
                                    ScriptCommand exitcmd = ScriptCommand.Create((int)FrameWorkCmdDefine.FSMCallExit);
                                    exitcmd.CallParams.WriteObject(current);
                                    exitcmd.ExcuteAndRelease();

                                    runningstate.isRunning = false;
                                    this.CallFinishCanvas(nodecanvas);
                                }
                            }
                        }
                    }
                }

                ListPool.TryDespawn(values);
            }
Beispiel #10
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
        }