Ejemplo n.º 1
0
        public void ExportData()
        {
            var    export = new Data.Exporter();
            string file   = export.Export(DataList);

            Process.Start(file);
        }
Ejemplo n.º 2
0
 internal void OpenGraph(Exporter exporter)
 {
     autoLoad      = false;
     this.exporter = exporter;
     this.ruleObj  = exporter.ruleObj;
     this.psdPath  = exporter.psdFile;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds and runs a webcam pipeline and records the data to a Psi store
        /// </summary>
        /// <param name="pathToStore">The path to directory where store should be saved.</param>
        public static void RecordAudioVideo(string pathToStore)
        {
            // Create the pipeline object.
            using (Pipeline pipeline = Pipeline.Create())
            {
                // Register an event handler to catch pipeline errors
                pipeline.PipelineCompleted += Pipeline_PipelineCompleted;

                // Create store
                Data.Exporter store = Store.Create(pipeline, ApplicationName, pathToStore);

                // Create our webcam
                MediaCapture webcam = new MediaCapture(pipeline, 1920, 1080, 30);

                // Create the AudioCapture component to capture audio from the default device in 16 kHz 1-channel
                IProducer <AudioBuffer> audioInput = new AudioCapture(pipeline, new AudioCaptureConfiguration()
                {
                    OutputFormat = WaveFormat.Create16kHz1Channel16BitPcm()
                });

                var images = webcam.Out.EncodeJpeg(90, DeliveryPolicy.LatestMessage).Out;

                // Attach the webcam's image output to the store. We will write the images to the store as compressed JPEGs.
                Store.Write(images, "Image", store, true, DeliveryPolicy.LatestMessage);

                // Attach the audio input to the store
                Store.Write(audioInput.Out, "Audio", store, true, DeliveryPolicy.LatestMessage);

                // Run the pipeline
                pipeline.RunAsync();

                Console.WriteLine("Press any key to finish recording");
                Console.ReadKey();
            }
        }
Ejemplo n.º 4
0
        public static void ChargeTextures(Data.Exporter exporter, GroupNodeItem groupnode)
        {
            //重新加载
            var atlaspath = string.Format(exportPath + "/{0}.png", exporter.name);

            Texture2D[] globleTextures    = LoadAllObjectFromDir <Texture2D>(exporter.ruleObj.globalTexture);
            Sprite[]    globleSprites     = LoadAllObjectFromDir <Sprite>(exporter.ruleObj.globalSprite);
            Sprite[]    fileSprites       = AssetDatabase.LoadAllAssetsAtPath(atlaspath).OfType <Sprite>().ToArray();
            Texture2D[] fileTextures      = LoadAllObjectFromDir <Texture2D>(exportPath); // AssetDatabase.LoadAllAssetsAtPath(pictureInfo.exportPath).OfType<Texture2D>().ToArray();
            Sprite[]    fileSingleSprites = LoadAllObjectFromDir <Sprite>(exportPath);    // AssetDatabase.LoadAllAssetsAtPath(pictureInfo.exportPath).OfType<Sprite>().ToArray();

            var pictureData = new List <Data.ImgNode>();

            groupnode.GetImgNodes(pictureData);

            foreach (var item in pictureData)
            {
                if (item.source == ImgSource.Globle)
                {
                    switch (item.type)
                    {
                    case ImgType.Image:
                    case ImgType.AtlasImage:
                        item.sprite = Array.Find(globleSprites, x => x.name == item.TextureName);
                        break;

                    case ImgType.Texture:
                        item.texture = Array.Find(globleTextures, x => x.name == item.TextureName);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (item.type)
                    {
                    case ImgType.Image:
                        item.sprite = Array.Find(fileSingleSprites, x => x.name == item.TextureName);
                        break;

                    case ImgType.AtlasImage:
                        item.sprite = Array.Find(fileSprites, x => x.name == item.TextureName);
                        break;

                    case ImgType.Texture:
                        item.texture = Array.Find(fileTextures, x => x.name == item.TextureName);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 将一组图片保存为atlas
        /// </summary>
        /// <param name="imgNodes"></param>
        /// <param name="exporter"></param>
        /// <param name="atlasName"></param>
        /// <returns></returns>
        public static void SaveToAtlas(Data.ImgNode[] imgNodes, Data.Exporter exporter)
        {
            if (imgNodes.Length == 0)
            {
                return;
            }
            var textures = imgNodes.Where(x => x.texture != null).Select(x => x.texture).ToArray();

            // The output of PackTextures returns a Rect array from which we can create our sprites
            Rect[]    rects;
            Texture2D atlas = new Texture2D(exporter.ruleObj.maxSize, exporter.ruleObj.maxSize);

            rects = atlas.PackTextures(textures, 2, exporter.ruleObj.maxSize);
            List <SpriteMetaData> Sprites = new List <SpriteMetaData>();

            // For each rect in the Rect Array create the sprite and assign to the SpriteMetaData
            for (int i = 0; i < rects.Length; i++)
            {
                // add the name and rectangle to the dictionary
                SpriteMetaData smd = new SpriteMetaData();
                smd.name      = textures[i].name;
                smd.rect      = new Rect(rects[i].xMin * atlas.width, rects[i].yMin * atlas.height, rects[i].width * atlas.width, rects[i].height * atlas.height);
                smd.pivot     = new Vector2(0.5f, 0.5f); // Center is default otherwise layers will be misaligned
                smd.alignment = (int)SpriteAlignment.Center;
                Sprites.Add(smd);
            }
            // Need to load the image first
            byte[] buf = EncordToPng(atlas);

            var atlaspath = string.Format(exportPath + "/{0}.png", exporter.name);

            File.WriteAllBytes(Path.GetFullPath(atlaspath), buf);
            AssetDatabase.Refresh();
            // Get our texture that we loaded
            TextureImporter textureImporter = AssetImporter.GetAtPath(atlaspath) as TextureImporter;

            // Make sure the size is the same as our atlas then create the spritesheet
            textureImporter.maxTextureSize   = exporter.ruleObj.maxSize;
            textureImporter.spritesheet      = Sprites.ToArray();
            textureImporter.textureType      = TextureImporterType.Sprite;
            textureImporter.spriteImportMode = SpriteImportMode.Multiple;
            textureImporter.spritePivot      = new Vector2(0.5f, 0.5f);

            ChargeTextureImportRule(textureImporter, exporter.ruleObj);

            AssetDatabase.ImportAsset(atlaspath, ImportAssetOptions.ForceUpdate);

            foreach (var node in imgNodes)
            {
                UnityEngine.Object.DestroyImmediate(node.texture);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Builds and runs a webcam pipeline and records the data to a Psi store
        /// </summary>
        /// <param name="pathToStore">The path to directory where store should be saved.</param>
        public static void RecordAudioVideo(string pathToStore)
        {
            // Create the pipeline object.
            using (Pipeline pipeline = Pipeline.Create())
            {
                var visualizationClient = new VisualizationClient();

                // Register an event handler to catch pipeline errors
                pipeline.PipelineCompletionEvent += PipelineCompletionEvent;

                // Clear all data if the visualizer is already open
                visualizationClient.ClearAll();

                // Set the visualization client to visualize live data
                visualizationClient.SetLiveMode();

                // Create store
                Data.Exporter store = Store.Create(pipeline, ApplicationName, pathToStore);

                // Create our webcam
                MediaCapture webcam = new MediaCapture(pipeline, 1920, 1080, 30);

                // Create the AudioCapture component to capture audio from the default device in 16 kHz 1-channel
                IProducer <AudioBuffer> audioInput = new AudioCapture(pipeline, new AudioCaptureConfiguration()
                {
                    OutputFormat = WaveFormat.Create16kHz1Channel16BitPcm()
                });

                var images = webcam.Out.EncodeJpeg(90, DeliveryPolicy.LatestMessage).Out;

                // Attach the webcam's image output to the store. We will write the images to the store as compressed JPEGs.
                Store.Write(images, "Image", store, true, DeliveryPolicy.LatestMessage);

                // Attach the audio input to the store
                Store.Write(audioInput.Out, "Audio", store, true, DeliveryPolicy.LatestMessage);

                // Create a XY panel in PsiStudio to display the images
                visualizationClient.AddXYPanel();
                images.Show(visualizationClient);

                // Create a timeline panel in PsiStudio to display the audio waveform
                visualizationClient.AddTimelinePanel();
                audioInput.Out.Show(visualizationClient);

                // Run the pipeline
                pipeline.RunAsync();

                Console.WriteLine("Press any key to finish recording");
                Console.ReadKey();
            }
        }
Ejemplo n.º 7
0
        private void RecordSelectedInformation()
        {
            if (m_TreeView == null || m_TreeView.selected.Count == 0)
            {
                return;
            }
            var psdLayers = m_TreeView.selected.ConvertAll(x => x.layer as IPsdLayer).ToArray();

            if (exporter == null)
            {
                exporter = ScriptableObject.CreateInstance <Data.Exporter>();
            }
            exporter.ruleObj = ruleObj;
            exporter.name    = "exporter" + System.DateTime.UtcNow.ToFileTimeUtc();
            ProjectWindowUtil.CreateAsset(exporter, exporter.name + ".asset");
            EditorUtility.SetDirty(exporter);

            ExportUtility.InitPsdExportEnvrioment(exporter, new Vector2(psd.Width, psd.Height));
            var rootNode = new GroupNodeItem(new Rect(Vector2.zero, exporter.ruleObj.defultUISize), 0, -1);

            rootNode.displayName = exporter.name;

            var groupDatas = ExportUtility.CreatePictures(psdLayers, new Vector2(psd.Width, psd.Height), exporter.ruleObj.defultUISize, exporter.ruleObj.forceSprite);

            if (groupDatas != null)
            {
                foreach (var groupData in groupDatas)
                {
                    rootNode.AddChild(groupData);
                    ExportUtility.ChargeTextures(exporter, groupData);
                }
            }
            var list = new List <GroupNodeItem>();

            TreeViewUtility.TreeToList <GroupNodeItem>(rootNode, list, true);
            exporter.groups = list.ConvertAll(x => x.data);
            EditorUtility.SetDirty(exporter);
        }
Ejemplo n.º 8
0
 public static void InitPsdExportEnvrioment(Data.Exporter obj, Vector2 rootSize0)
 {
     exporter = obj;
     rootSize = rootSize0;
     idSpan   = 1;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 将图片分别保存到本地
        /// </summary>
        /// <param name="imgType"></param>
        /// <param name="singleNodes"></param>
        /// <param name="pictureInfo"></param>
        public static void SaveToTextures(ImgType imgType, Data.ImgNode[] singleNodes, Data.Exporter pictureInfo)
        {
            foreach (var node in singleNodes)
            {
                byte[] buf = EncordToPng(node.texture);

                var rootPath = exportPath;

                if (node.source == ImgSource.Globle)
                {
                    if (node.type == ImgType.Image || node.type == ImgType.AtlasImage)
                    {
                        rootPath = pictureInfo.ruleObj.globalSprite;
                    }
                    else
                    {
                        rootPath = pictureInfo.ruleObj.globalTexture;
                    }

                    if (!Directory.Exists(rootPath))
                    {
                        Directory.CreateDirectory(rootPath);
                    }
                }

                var atlaspath = rootPath + "/" + string.Format("{0}.png", node.texture.name);
                File.WriteAllBytes(Path.GetFullPath(atlaspath), buf);
                AssetDatabase.Refresh();

                // Get our texture that we loaded
                TextureImporter textureImporter = AssetImporter.GetAtPath(atlaspath) as TextureImporter;

                // Make sure the size is the same as our atlas then create the spritesheet
                textureImporter.maxTextureSize   = pictureInfo.ruleObj.maxSize;
                textureImporter.spritePackingTag = pictureInfo.name;
                switch (imgType)
                {
                case ImgType.Image:
                    textureImporter.textureType         = TextureImporterType.Sprite;
                    textureImporter.spriteImportMode    = SpriteImportMode.Single;
                    textureImporter.alphaIsTransparency = true;
                    textureImporter.spritePivot         = new Vector2(0.5f, 0.5f);
                    break;

                case ImgType.Texture:
                    textureImporter.textureType = TextureImporterType.Default;
                    break;

                default:
                    break;
                }
                ChargeTextureImportRule(textureImporter, exporter.ruleObj);
                AssetDatabase.ImportAsset(atlaspath, ImportAssetOptions.ForceUpdate);
            }


            foreach (Data.ImgNode node in singleNodes)
            {
                UnityEngine.Object.DestroyImmediate(node.texture);
            }
        }