コード例 #1
0
ファイル: ScriptLogicCtr.cs プロジェクト: zwwl0801/RvoProject
        private void RegisterLua(ScriptCommand cmd, string path, string methodname)
        {
#if TOLUA
            Script_LuaLogicAttribute att = new Script_LuaLogicAttribute(cmd.CMD, path, methodname);
            ScriptPkg pkg = ScriptPkg.CreateLua(att);
            //add
            var dic = new SimpleDictionary <int, ScriptPkg>();
            dic.Add((int)cmd.target, pkg);
            ScriptDic[cmd.CMD] = dic;
#endif
        }
コード例 #2
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();
     }
 }
コード例 #3
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);
        }
コード例 #4
0
ファイル: ScriptLogicCtr.cs プロジェクト: zwwl0801/RvoProject
        public void PushCommand(ScriptCommand command)
        {
            if (!command.isDone)
            {
                CommandQueue.Enqueue(command);

                DispathCommand();
            }
            else
            {
                LogMgr.LogError("消息已经完成");
            }
        }
コード例 #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);
            }
        }
コード例 #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();
     }
 }
コード例 #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();
            }
        }
コード例 #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);
        }
コード例 #9
0
ファイル: FSMRunner.cs プロジェクト: zwwl0801/RvoProject
            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);
            }
コード例 #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
        }
コード例 #11
0
ファイル: ScriptLogicCtr.cs プロジェクト: zwwl0801/RvoProject
        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);
            }
        }
コード例 #12
0
ファイル: ScriptLogicCtr.cs プロジェクト: zwwl0801/RvoProject
        private void Registernew(ScriptCommand cmd)
        {
            if (ScriptDic.ContainsKey(cmd.CMD) && ScriptDic[cmd.CMD].ContainsKey((int)cmd.target))
            {
                return;
            }

            if (cmd.InitParams.NextValue() == (int)ParamType.STRING)
            {
                string classname = cmd.InitParams.ReadString();
                if (cmd.InitParams.NextValue() == (int)ParamType.STRING)
                {
                    string methodname = cmd.InitParams.ReadString();
                    //csharp
                    if (cmd.target == ScriptTarget.Sharp)
                    {
                        Type type = Type.GetType(classname);
                        if (type != null)
                        {
                            MethodInfo method = type.GetMethod(methodname, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                            if (method != null)
                            {
                                ScriptPkg pkg = ScriptPkg.CreateSharp(method, methodname);
                                //add

                                if (!ScriptDic.ContainsKey(cmd.CMD))
                                {
                                    var dic = new SimpleDictionary <int, ScriptPkg>();
                                    dic.Add((int)cmd.target, pkg);
                                    ScriptDic[cmd.CMD] = dic;
                                }
                                else
                                {
                                    ScriptDic[cmd.CMD][(int)cmd.target] = pkg;
                                }
                            }
                            else
                            {
                                LogMgr.LogWarningFormat("Missing method :{0} in {1}", methodname, classname);
                            }
                        }
                        else
                        {
                            LogMgr.LogWarningFormat("Missing Type :{0}", classname);
                        }
                    }
                    else if (cmd.target == ScriptTarget.Lua)
                    {
                        RegisterLua(cmd, classname, methodname);
                    }
                }
                else
                {
                    LogMgr.LogWarningFormat("cant register automatically :{0} for {1}", cmd.CMD, classname);
                }
            }
            else
            {
                object o = null;
                if (cmd.InitParams.NextValue() == (int)ParamType.UNITYOBJECT)
                {
                    o = cmd.InitParams.ReadUnityObject();
                }
                else if (cmd.InitParams.NextValue() == (int)ParamType.OBJECT)
                {
                    o = cmd.InitParams.ReadObject();
                }

                if (o != null)
                {
                    if (cmd.InitParams.NextValue() == (int)ParamType.STRING)
                    {
                        string classname = cmd.InitParams.ReadString();
                        if (cmd.InitParams.NextValue() == (int)ParamType.STRING)
                        {
                            string methodname = cmd.InitParams.ReadString();
                            if (cmd.target == ScriptTarget.Sharp)
                            {
                                Type type = Type.GetType(classname);
                                if (type != null)
                                {
                                    MethodInfo method = type.GetMethod(methodname, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                                    if (method != null)
                                    {
                                        ScriptPkg pkg = ScriptPkg.CreateSharp(method, methodname, o);
                                        //add

                                        if (!ScriptDic.ContainsKey(cmd.CMD))
                                        {
                                            var dic = new SimpleDictionary <int, ScriptPkg>();
                                            dic.Add((int)cmd.target, pkg);
                                            ScriptDic[cmd.CMD] = dic;
                                        }
                                        else
                                        {
                                            ScriptDic[cmd.CMD][(int)cmd.target] = pkg;
                                        }
                                    }
                                    else
                                    {
                                        LogMgr.LogWarningFormat("Missing method :{0} in {1}", methodname, classname);
                                    }
                                }
                                else
                                {
                                    LogMgr.LogWarningFormat("Missing Type :{0}", classname);
                                }
                            }
                            else if (cmd.target == ScriptTarget.Lua)
                            {
                                RegisterLua(cmd, classname, methodname);
                            }
                        }
                        else
                        {
                            LogMgr.LogWarningFormat("Missing Type :{0}", classname);
                        }
                    }
                    else
                    {
                        LogMgr.LogWarningFormat("cant register automatically :{0} ", cmd.CMD);
                    }
                }
            }
        }