Пример #1
0
        public static void FromTiltImage(TiltImages75 tiltImage)
        {
            var refImage = ReferenceImageCatalog.m_Instance.FileNameToImage(tiltImage.FileName);
            var groupIds = tiltImage.GroupIds;

            for (int i = 0; i < tiltImage.Transforms.Length; ++i)
            {
                ImageWidget image = Instantiate(WidgetManager.m_Instance.ImageWidgetPrefab);
                image.m_LoadingFromSketch  = true;
                image.transform.parent     = App.Instance.m_CanvasTransform;
                image.transform.localScale = Vector3.one;
                if (refImage != null)
                {
                    refImage.SynchronousLoad();
                    image.ReferenceImage = refImage;
                }
                else
                {
                    image.SetMissing(tiltImage.AspectRatio, tiltImage.FileName);
                }
                image.SetSignedWidgetSize(tiltImage.Transforms[i].scale);
                image.Show(bShow: true, bPlayAudio: false);
                image.transform.localPosition = tiltImage.Transforms[i].translation;
                image.transform.localRotation = tiltImage.Transforms[i].rotation;
                if (tiltImage.PinStates[i])
                {
                    image.PinFromSave();
                }
                if (tiltImage.TintStates[i])
                {
                    image.UseLegacyTint = true;
                }
                uint groupId = (groupIds != null && i < groupIds.Length) ? groupIds[i] : 0;
                image.Group = App.GroupManager.GetGroupFromId(groupId);
                TiltMeterScript.m_Instance.AdjustMeterWithWidget(image.GetTiltMeterCost(), up: true);
            }
        }
Пример #2
0
        public static TiltImages75[] GetTiltImages(GroupIdMapping groupIdMapping)
        {
            var imports = WidgetManager.m_Instance.ImageWidgets
                          .Where(w => w.gameObject.activeSelf).ToArray();

            if (imports.Length == 0)
            {
                return(null);
            }

            // From the list of image widgets in the sketch, create a map that contains a unique
            // entry per image, with associated metadata (transform and pin state) stored as arrays.
            Dictionary <string, List <WidgetMetadata> > imagesByFileName =
                new Dictionary <string, List <WidgetMetadata> >();
            Dictionary <string, float> aspectRatios = new Dictionary <string, float>();

            foreach (var image in imports)
            {
                string fileName = image.FileName;
                if (image.AspectRatio == null)
                {
                    Debug.LogError("Trying to save partially-initialized image {fileName}");
                }
                if (!imagesByFileName.ContainsKey(fileName))
                {
                    imagesByFileName[fileName] = new List <WidgetMetadata>();
                    aspectRatios[fileName]     = image.AspectRatio ?? 1;
                }
                WidgetMetadata newEntry = new WidgetMetadata();
                newEntry.xf      = image.SaveTransform;
                newEntry.pinned  = image.Pinned;
                newEntry.tinted  = image.UseLegacyTint;
                newEntry.groupId = groupIdMapping.GetId(image.Group);
                imagesByFileName[fileName].Add(newEntry);
            }

            // Build the save metadata from our unique map.
            List <TiltImages75> imageIndex = new List <TiltImages75>();

            foreach (var elem in imagesByFileName)
            {
                var val = new TiltImages75
                {
                    FileName    = elem.Key,
                    AspectRatio = aspectRatios[elem.Key]
                };

                // Order and align the metadata.
                WidgetMetadata[] ordered =
                    elem.Value.OrderBy(ByTranslation).ToArray();
                val.PinStates  = new bool[ordered.Length];
                val.TintStates = new bool[ordered.Length];
                val.Transforms = new TrTransform[ordered.Length];
                val.GroupIds   = new uint[ordered.Length];
                for (int i = 0; i < ordered.Length; ++i)
                {
                    val.PinStates[i]  = ordered[i].pinned;
                    val.TintStates[i] = ordered[i].tinted;
                    val.Transforms[i] = ordered[i].xf;
                    val.GroupIds[i]   = ordered[i].groupId;
                }
                imageIndex.Add(val);
            }
            return(imageIndex.OrderBy(i => i.FileName).ToArray());
        }