Пример #1
0
 /// <summary>
 /// 创建目录
 /// </summary>
 /// <param name="path"></param>
 public static void CreateDirectory(string path)
 {
     if (!Directory.Exists(path))
     {
         Directory.CreateDirectory(path);
     }
 }
Пример #2
0
 /// <summary>
 /// 删除目录
 /// </summary>
 /// <param name="path"></param>
 public static void Delete(string path)
 {
     if (Directory.Exists(path))
     {
         Directory.Delete(path);
     }
 }
Пример #3
0
        public void Cleanup()
        {
            var dir = Path.GetDirectoryName(m_UserSettingsRepo.path);

            if (Directory.Exists(dir))
            {
                Directory.Delete(dir);
            }
        }
        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();
            }
        }
Пример #5
0
        private static void OpenBuildFolder()
        {
            var path = System.IO.Directory.GetCurrentDirectory() + "\\" + "Release" + "\\";

            if (Directory.Exists(path))
            {
                var processStartInfo = new ProcessStartInfo
                {
                    Arguments = path,
                    FileName  = "explorer.exe"
                };

                Process.Start(processStartInfo);
            }
        }
Пример #6
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);
 *
 */
        }
Пример #7
0
 /// <summary>
 /// 是否存在
 /// </summary>
 /// <param name="path"></param>
 public static bool Exists(string path)
 {
     return(Directory.Exists(path));;
 }
Пример #8
0
        static void OnToolsGUI(string rootNs, string viewNs, string constNs, string dataNs, string autoDir,
                               string scriptDir)
        {
            EditorGUILayout.LabelField("生成目录", generateDir);
            if (GUILayout.Button("设置生成目录"))
            {
                generateDir = EditorUtility.OpenFolderPanel("选择生成目录", Application.dataPath, "");
            }
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("资源目录", sourDir);
            if (GUILayout.Button("设置资源目录"))
            {
                sourDir = EditorUtility.OpenFolderPanel("选择资源目录", Application.dataPath, "");
            }
            EditorGUILayout.Space();

            nameSpace = EditorGUILayout.TextField("命名空间", nameSpace);

            HasParentClass = EditorGUILayout.Toggle("是否具有父类", HasParentClass);
            if (HasParentClass)
            {
                parentClass     = EditorGUILayout.TextField("父类名", parentClass);
                IsGenericParent = EditorGUILayout.Toggle("父类是否是泛型类", IsGenericParent);
                if (IsGenericParent)
                {
                    IsGenericParamSelf = EditorGUILayout.Toggle("泛型参数是不是本类名", IsGenericParamSelf);
                    if (!IsGenericParamSelf)
                    {
                        GenericParam = EditorGUILayout.TextField("泛型参数", GenericParam);
                    }
                }
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("开始生成", GUILayout.Height(3 * EditorGUIUtility.singleLineHeight)))
            {
                if (!Directory.Exists(generateDir))
                {
                    Debug.LogError("生成目录不存在:" + generateDir);
                    return;
                }

                if (!Directory.Exists(sourDir))
                {
                    Debug.LogError("资源目录不存在:" + sourDir);
                    return;
                }

                if (string.IsNullOrEmpty(nameSpace))
                {
                    Debug.LogError("命名空间不能为空");
                    return;
                }

                if (HasParentClass)
                {
                    if (string.IsNullOrEmpty(parentClass))
                    {
                        Debug.LogError("父类不能为空");
                        return;
                    }
                    else
                    {
                        if (IsGenericParent && !IsGenericParamSelf && string.IsNullOrEmpty(GenericParam))
                        {
                            Debug.LogError("泛型参数不能为空");
                            return;
                        }
                    }
                }

                Create();
            }
        }
 public void TearDown()
 {
     Directory.Delete(_dirThree);
     Directory.Delete(_dirTwo);
     Directory.Delete(_dirOne);
 }
 public void Setup()
 {
     Directory.CreateDirectory(_dirOne);
     Directory.CreateDirectory(_dirTwo);
     Directory.CreateDirectory(_dirThree);
 }