public void OnMessage(IProtocol protocol) { if (RobotManager.Get()) { RobotManager.Get().PushMessage(protocol); } }
private void StartDemo0() { StopDemo(); // 挂钩子 RobotManager.Get().protocolHook = this; simulator.StartCoroutine(Demo0Loop()); }
public void StopDebug() { StopAllCoroutines(); if (RobotManager.GetOrAlloc()) { RobotManager.GetOrAlloc().RewindRobots(); } }
private void StopDemo() { if (RobotManager.Get().protocolHook == this) { RobotManager.Get().protocolHook = null; } simulator.StopAllCoroutines(); simulator.StopDebug(); }
private void CheckWall() { // 方案1. 如果墙距离传感器发射点超过5cm,角模式旋转1度, 否则等待100ms;一直做这个步骤 // 方案2. 如果墙距离传感器发射点不超过5cm,停止轮模式,否则,设置成轮模式;一直做这个步骤 // 挂钩子 RobotManager.Get().protocolHook = this; simulator.StopDebug(); mToCheckDistance = true; mCurrent = null; simulator.StartCoroutine(CheckWallE()); }
private void Update() { if (!RobotManager.Get()) { return; } var firstRobot = RobotManager.GetOrAlloc().firstRobot; if (activeRobot != firstRobot) { activeRobot = firstRobot; RefreshUI(); } }
public void StopTest() { RobotManager.GetOrAlloc().Test(false); }
public void StartTest() { RobotManager.GetOrAlloc().Test(true); }
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); }