コード例 #1
0
 /// <summary>
 /// 创建目录
 /// </summary>
 /// <param name="path"></param>
 public static void CreateDirectory(string path)
 {
     if (!Directory.Exists(path))
     {
         Directory.CreateDirectory(path);
     }
 }
コード例 #2
0
        public void Bake()
        {
            if (baking)
            {
                reserveBaking = true;
                return;
            }

            var terrainPath = AssetDatabase.GetAssetPath(targetTerrain.terrainData);
            var terrainDir  = Path.GetDirectoryName(terrainPath);
            var terrainName = Path.GetFileNameWithoutExtension(terrainPath);
            var bakeDir     = Path.Combine(terrainDir, terrainName + "_MassiveGrass");

            Directory.CreateDirectory(bakeDir);
            Debug.Log("BakeDir: " + bakeDir);

            Debug.Log("Baking");
            baking = true;
            foreach (var texture2D in bakedAlphaMaps)
            {
                DestroyImmediate(texture2D);
            }

            bakedAlphaMaps.Clear();

            // Bake
            var terrainData = targetTerrain.terrainData;
            var w           = terrainData.alphamapWidth;
            var h           = terrainData.alphamapHeight;
            var layers      = terrainData.alphamapLayers;

            for (var i = 0; i < layers; i++)
            {
                var texturePath = Path.Combine(bakeDir, "alphamap" + i + ".png");
                AssetDatabase.DeleteAsset(texturePath);
                var     texture = AlphamapBaker.CreateAndBake(targetTerrain, new [] { i });
                byte [] pngData = texture.EncodeToPNG();
                File.WriteAllBytes(texturePath, pngData);
                AssetDatabase.ImportAsset(texturePath);
                Debug.Log("load " + texturePath);

                var importer = AssetImporter.GetAtPath(texturePath) as TextureImporter;
                importer.isReadable = true;
                AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);

                var tex = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePath);
                bakedAlphaMaps.Add(tex);
            }

            baking = false;
            Debug.Log("Baking Done");
            if (reserveBaking)
            {
                reserveBaking = false;
                Bake();
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        public static void TakeScreenshot(string name)
        {
            var path = Path.GetDirectoryName(name);

            Directory.CreateDirectory(path);
            // Take the screenshot
            ScreenCapture.CaptureScreenshot(name); // TODO: VERY broken, unitys fault

/*
 *    //Wait for 4 frames
 *    for (int i = 0; i < 5; i++)
 *    {
 *      yield return null;
 *    }
 *
 *    // Read the data from the file
 *    byte[] data = File.ReadAllBytes(Application.persistentDataPath + "/" + name);
 *
 *    // Create the texture
 *    Texture2D screenshotTexture = new Texture2D(Screen.width, Screen.height);
 *
 *    // Load the image
 *    screenshotTexture.LoadImage(data);
 *
 *    // Create a sprite
 *    Sprite screenshotSprite = Sprite.Create(screenshotTexture, new Rect(0, 0, Screen.width, Screen.height), new Vector2(0.5f, 0.5f));
 *
 *    // Set the sprite to the screenshotPreview
 *    screenshotPreview.GetComponent<Image>().sprite = screenshotSprite;
 *
 *    OR
 *
 *        Texture2D screenImage = new Texture2D(Screen.width, Screen.height);
 *  //Get Image from screen
 *  screenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
 *  screenImage.Apply();
 *  //Convert to png
 *  byte[] imageBytes = screenImage.EncodeToPNG();
 *
 *  //Save image to file
 *  System.IO.File.WriteAllBytes(path, imageBytes);
 *
 */
        }
コード例 #4
0
 public void Setup()
 {
     Directory.CreateDirectory(_dirOne);
     Directory.CreateDirectory(_dirTwo);
     Directory.CreateDirectory(_dirThree);
 }