コード例 #1
0
 public void OnMessage(IProtocol protocol)
 {
     if (RobotManager.Get())
     {
         RobotManager.Get().PushMessage(protocol);
     }
 }
コード例 #2
0
 private void StartDemo0()
 {
     StopDemo();
     // 挂钩子
     RobotManager.Get().protocolHook = this;
     simulator.StartCoroutine(Demo0Loop());
 }
コード例 #3
0
 public void StopDebug()
 {
     StopAllCoroutines();
     if (RobotManager.GetOrAlloc())
     {
         RobotManager.GetOrAlloc().RewindRobots();
     }
 }
コード例 #4
0
 private void StopDemo()
 {
     if (RobotManager.Get().protocolHook == this)
     {
         RobotManager.Get().protocolHook = null;
     }
     simulator.StopAllCoroutines();
     simulator.StopDebug();
 }
コード例 #5
0
 private void CheckWall()
 {
     // 方案1. 如果墙距离传感器发射点超过5cm,角模式旋转1度, 否则等待100ms;一直做这个步骤
     // 方案2. 如果墙距离传感器发射点不超过5cm,停止轮模式,否则,设置成轮模式;一直做这个步骤
     // 挂钩子
     RobotManager.Get().protocolHook = this;
     simulator.StopDebug();
     mToCheckDistance = true;
     mCurrent         = null;
     simulator.StartCoroutine(CheckWallE());
 }
コード例 #6
0
        private void Update()
        {
            if (!RobotManager.Get())
            {
                return;
            }
            var firstRobot = RobotManager.GetOrAlloc().firstRobot;

            if (activeRobot != firstRobot)
            {
                activeRobot = firstRobot;
                RefreshUI();
            }
        }
コード例 #7
0
 public void StopTest()
 {
     RobotManager.GetOrAlloc().Test(false);
 }
コード例 #8
0
 public void StartTest()
 {
     RobotManager.GetOrAlloc().Test(true);
 }
コード例 #9
0
        public void LoadRobot(LitJson.JsonData jsonData, Action <IRobot> onCompleted)
        {
            if (jsonData == null)
            {
                Misc.SafeInvoke(onCompleted, null);
                return;
            }
            IRobot robot     = null;
            bool   hideLines = Application.isPlaying;

            try
            {
                ProfilingUtility.BeginSample("RobotFactory.LoadRobot");
                DefaultRobotSerializer defaultRobotSerializer = new DefaultRobotSerializer();
                var dataModel = defaultRobotSerializer.FromJson(jsonData);
                if (dataModel != null)
                {
                    ProfilingUtility.BeginSample("RobotFactory.LoadRobot.PrepareParts");
                    var parts = new Dictionary <string, Queue <GameObject> >(dataModel.assetDatas.Count);
                    foreach (var item in dataModel.assetDatas)
                    {
                        string resID = item.Key;
                        // 去掉线
                        if (hideLines && resID.StartsWith("W") && resID.IndexOf('_') > 0)
                        {
                            continue;
                        }

                        var count = item.Value;
                        while (count > 0)
                        {
                            var part = UbtrobotSettings.GetOrLoad().partsLibrary.Instantiate(resID);
                            if (part == null)
                            {
                                DebugUtility.LogError(LoggerTags.Project, "Missing part : {0}", resID);
                                break;
                            }

                            if (hideLines && resID == "Battery")
                            {
                                part.transform.SetActive("Battery_02", false);
                            }

                            if (!parts.TryGetValue(resID, out var list))
                            {
                                list         = new Queue <GameObject>();
                                parts[resID] = list;
                            }
                            count--;
                            list.Enqueue(part.gameObject);
                        }
                    }
                    ProfilingUtility.EndSample();
                    ProfilingUtility.BeginSample("RobotFactory.LoadRobot.Rebuild");
                    var robotTransform = dataModel.Rebuild(null, parts);
                    ProfilingUtility.EndSample();
                    robot = robotTransform != null?robotTransform.GetComponent <IRobot>() : null;

                    if (robot != null)
                    {
                        if (Application.isPlaying)
                        {
                            RobotManager.GetOrAlloc().AddRobot(robot);
                        }
                        else
                        {
                            robot.AutoInitialize();
                        }
                    }
                }
                ProfilingUtility.EndSample();
            }
            catch (Exception ex)
            {
                DebugUtility.LogException(ex);
            }
            Misc.SafeInvoke(onCompleted, robot);
        }