Пример #1
0
        static void ExportSkyToImage()
        {
            var renderpipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;

            if (renderpipeline == null)
            {
                Debug.LogError("HDRenderPipeline is not instantiated.");
                return;
            }

            var result = renderpipeline.ExportSkyToTexture(Camera.main);

            if (result == null)
            {
                return;
            }

            // Encode texture into PNG
            byte[] bytes = result.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);
            UnityObject.DestroyImmediate(result);

            string assetPath = EditorUtility.SaveFilePanel("Export Sky", "Assets", "SkyExport", "exr");

            if (!string.IsNullOrEmpty(assetPath))
            {
                File.WriteAllBytes(assetPath, bytes);
                AssetDatabase.Refresh();
            }
        }
Пример #2
0
            private static IEnumerator DestroyInSeconds(UnityObject o, float t)
            {
                float startTime = Time.realtimeSinceStartup;

                while (Time.realtimeSinceStartup <= startTime + t)
                {
                    yield return(null);
                }

                UnityObject.DestroyImmediate(o);
            }
Пример #3
0
        public void ExportMainEnvMapDialog()
        {
            var targetPath = ShowExportPathPanel("Save main env map texture", "_MainEnvMap", "exr");

            if (!string.IsNullOrEmpty(targetPath))
            {
                var resultTexture = CreateEnvMapTextureFromResult();
                File.WriteAllBytes(targetPath, resultTexture.EncodeToEXR(Texture2D.EXRFlags.OutputAsFloat));
                UnityObject.DestroyImmediate(resultTexture);

                SetImporterForEnvMapTexture(targetPath);
            }
        }
Пример #4
0
        public void ExportDelightedTextureDialog()
        {
            var targetPath = ShowExportPathPanel("Save de-lighted texture", "_NoLight", "png");

            if (!string.IsNullOrEmpty(targetPath))
            {
                var delightedTexture = CreateDelightedTextureFromResult();
                var bytes            = delightedTexture.EncodeToPNG();
                File.WriteAllBytes(targetPath, bytes);
                UnityObject.DestroyImmediate(delightedTexture);

                SetImporterForDelightedTexture(targetPath);
            }
        }
Пример #5
0
        public static void Destroy(UnityObject obj)
        {
            if (obj != null)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
                {
                    UnityObject.Destroy(obj);
                }
                else
                {
                    UnityObject.DestroyImmediate(obj);
                }
#else
                UnityObject.Destroy(obj);
#endif
            }
        }
Пример #6
0
            public static void Destroy(UnityObject o, float t = 0f)
            {
                if (Application.isPlaying)
                {
                    UnityObject.Destroy(o, t);
                }
#if UNITY_EDITOR && UNITY_EDITORVR
                else
                {
                    if (Mathf.Approximately(t, 0f))
                    {
                        UnityObject.DestroyImmediate(o);
                    }
                    else
                    {
                        VRView.StartCoroutine(DestroyInSeconds(o, t));
                    }
                }
#endif
            }
Пример #7
0
        static void AddAdditionalCameraData()
        {
            //var cameras = UnityObject.FindObjectsOfType(typeof(Camera)) as Camera[];

            //foreach (var camera in cameras)
            //{
            //    if (camera.GetComponent<ClusterAdditionalCameraData>() != null)
            //        UnityObject.DestroyImmediate(camera.GetComponent<ClusterAdditionalCameraData>());
            //    // Do not add a component if there already is one.
            //    if (camera.GetComponent<AdditionalCameraData>() == null)
            //        camera.gameObject.AddComponent<AdditionalCameraData>();
            //}

            var cameras = FindObjectsOfTypeAll <Camera>();

            foreach (var camera in cameras)
            {
                bool dirty = false;
                if (camera.GetComponent <ClusterAdditionalCameraData>() != null)
                {
                    UnityObject.DestroyImmediate(camera.GetComponent <ClusterAdditionalCameraData>());
                    dirty = true;
                }
                // Do not add a component if there already is one.
                if (camera.GetComponent <AdditionalCameraData>() == null)
                {
                    camera.gameObject.AddComponent <AdditionalCameraData>();
                    dirty = true;
                }

                if (dirty)
                {
                    EditorUtility.SetDirty(camera.gameObject);
                }
            }
        }