Exemplo n.º 1
0
        private static void CreateRobotTree(UnityObject[] objects, bool newTree)
        {
            if (objects != null && objects.Length > 0)
            {
                for (int i = 0; i < objects.Length; ++i)
                {
                    var go = objects[i] as GameObject;
                    if (go == null)
                    {
                        continue;
                    }

                    var newGo = newTree ? UnityObject.Instantiate(go) : go;
                    newGo.name = go.name;
                    var root = newGo.transform;
                    if (root)
                    {
                        var library = UbtrobotSettings.GetOrLoad().partsLibrary;

                        var children         = new List <Transform>();
                        var toRemoveChildren = new List <Transform>();

                        var it = root.GetChildren();
                        while (it != null && it.MoveNext())
                        {
                            children.Add(it.Current);
                        }

                        foreach (Transform tr in children)
                        {
                            var prefab = library.LoadPrefab(tr.name);
                            if (prefab != null)
                            {
                                prefab.transform.SetParent(root, false);
                                prefab.transform.CopyFrom(tr);
                            }
                            else
                            {
                                DebugUtility.LogError(LoggerTags.AssetManager, "Can't create part with {0}", tr.name);
                            }
                        }

                        children.ForEach(tr =>
                        {
                            if (toRemoveChildren.Contains(tr))
                            {
                                DestroyImmediate(tr.gameObject, false);
                            }
                        });
                        children.RemoveAll(tr => tr == null);

                        foreach (var tr in children)
                        {
                            tr.transform.SetParent(root, false);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void DoDrawGizmos()
        {
            var settings = UbtrobotSettings.GetOrLoad().gizmosSettings;

            if (settings == null)
            {
                return;
            }
            GizmosUtility.DrawMeshs(gameObject, settings.drawServo, settings.servoColor);
        }
Exemplo n.º 3
0
        public virtual void SetID(int id)
        {
            mPartID = id;
            CheckID();

            if (mNum1 != null && mNum2 != null)
            {
                UbtrobotSettings.GetOrLoad().numMaterials.GetIDMaterial(id, out var _10, out var _1);
                mNum1.sharedMaterial = _10;
                mNum2.sharedMaterial = _1;

                var localPos1 = mNum1.transform.localPosition;
                var localPos2 = mNum2.transform.localPosition;

                if (localPos2.y - localPos1.y < 0.001f || localPos2.y - localPos1.y > 0.0015f)
                {
                    localPos2.y = localPos1.y + 0.0011f;
                    mNum2.transform.localPosition = localPos2;
                }
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        protected override void DoDrawGizmos()
        {
            var settings = UbtrobotSettings.GetOrLoad().gizmosSettings;

            GizmosUtility.DrawMeshs(gameObject, settings.drawMotor, settings.motorColor);
        }