public void OnRecorderSelected() { var clip = this.target as RecorderClip; if (m_Editor != null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; } if (m_recorderSelector.selectedRecorder == null) { return; } if (clip.m_Settings != null && RecordersInventory.GetRecorderInfo(m_recorderSelector.selectedRecorder).settings != clip.m_Settings.GetType()) { UnityHelpers.Destroy(clip.m_Settings, true); clip.m_Settings = null; } if (clip.m_Settings == null) { clip.m_Settings = RecordersInventory.GenerateNewSettingsAsset(clip, m_recorderSelector.selectedRecorder); } m_Editor = Editor.CreateEditor(clip.m_Settings) as RecorderEditor; AssetDatabase.Refresh(); }
void SaveRT(RenderTexture input) { if (input == null) { return; } var width = input.width; var height = input.height; var tex = new Texture2D(width, height, TextureFormat.RGBA32, false); var backupActive = RenderTexture.active; RenderTexture.active = input; tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); RenderTexture.active = backupActive; byte[] bytes; bytes = tex.EncodeToPNG(); UnityHelpers.Destroy(tex); File.WriteAllBytes("Recorder/DebugDump.png", bytes); }
void OnRecorderSelected(Type selectedRecorder) { var clip = (RecorderClip)target; if (m_Editor != null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; } if (selectedRecorder == null) { return; } if (clip.settings != null && RecordersInventory.GetRecorderInfo(selectedRecorder).settingsType != clip.settings.GetType()) { Undo.DestroyObjectImmediate(clip.settings); clip.settings = null; } if (clip.settings == null) { clip.settings = RecordersInventory.CreateDefaultRecorderSettings(selectedRecorder); Undo.RegisterCreatedObjectUndo(clip.settings, "Recorder Create Settings"); AssetDatabase.AddObjectToAsset(clip.settings, clip); } m_Editor = (RecorderEditor)CreateEditor(clip.settings); }
void ResetSettings() { UnityHelpers.Destroy(m_Editor); m_Editor = null; m_RecorderSelector = null; UnityHelpers.Destroy(((RecorderClip)target).settings, true); }
void ResetSettings() { UnityHelpers.Destroy(m_Editor); m_Editor = null; m_recorderSelector = null; UnityHelpers.Destroy((target as RecorderClip).m_Settings, true); }
public void Configuration(IAppBuilder app) { var config = Startup.HttpConfiguration; config.DependencyResolver = new UnityDependencyResolver(UnityHelpers.GetConfiguredContainer()); ConfigureWebApi(app, config); }
/// <inheritdoc/> protected override void Dispose(bool disposing) { if (disposing) { m_InputStrategy.ReleaseCamera(); UnityHelpers.Destroy(m_UICamera); if (m_ModifiedResolution) { if (GameViewSize.modifiedResolutionCount > 0) { GameViewSize.modifiedResolutionCount--; // don't allow negative if called twice } if (GameViewSize.modifiedResolutionCount == 0) { GameViewSize.RestoreSize(); } } if (m_VFlipper != null) { m_VFlipper.Dispose(); } } base.Dispose(disposing); }
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner) { var playable = ScriptPlayable <RecorderPlayableBehaviour> .Create(graph); var behaviour = playable.GetBehaviour(); if (recorderType != null && UnityHelpers.IsPlaying()) { behaviour.session = new RecordingSession() { m_Recorder = RecordersInventory.GenerateNewRecorder(recorderType, m_Settings), m_RecorderGO = SceneHook.HookupRecorder(), }; behaviour.OnEnd = () => { try { if (OnClipDone != null) { OnClipDone(this); } } catch (Exception ex) { Debug.Log("OnClipDone call back generated an exception: " + ex.Message); Debug.LogException(ex); } }; } return(playable); }
protected override void Dispose(bool disposing) { if (disposing) { if (m_hookedCameras != null) { foreach (var c in m_hookedCameras) { if (c != null) { if (c.camera.rect.width == 1f && c.camera.rect.height == 1f) { UnityHelpers.Destroy(c.camera.targetTexture); } c.camera.targetTexture = c.textureBackup; } } m_hookedCameras.Clear(); } UnityHelpers.Destroy(m_renderRT); foreach (var rt in m_accumulateRTs) { UnityHelpers.Destroy(rt); } UnityHelpers.Destroy(m_superMaterial); UnityHelpers.Destroy(m_accumulateMaterial); UnityHelpers.Destroy(m_normalizeMaterial); } base.Dispose(disposing); }
public void OnRecorderSelected() { if (m_Editor != null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; } if (m_recorderSelector.selectedRecorder == null) { return; } if (m_WindowSettingsAsset.m_Settings != null && RecordersInventory.GetRecorderInfo(m_recorderSelector.selectedRecorder).settings != m_WindowSettingsAsset.m_Settings.GetType()) { UnityHelpers.Destroy(m_WindowSettingsAsset.m_Settings, true); m_WindowSettingsAsset.m_Settings = null; } if (m_WindowSettingsAsset.m_Settings == null) { m_WindowSettingsAsset.m_Settings = RecordersInventory.GenerateNewSettingsAsset(m_WindowSettingsAsset, m_recorderSelector.selectedRecorder); } m_Editor = Editor.CreateEditor(m_WindowSettingsAsset.m_Settings) as RecorderEditor; AssetDatabase.Refresh(); }
void OnRecorderSelected(Type selectedRecorder) { var clip = (RecorderClip)target; if (m_Editor != null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; } if (selectedRecorder == null) { return; } if (clip.settings != null && RecordersInventory.GetRecorderInfo(selectedRecorder).settingsType != clip.settings.GetType()) { UnityHelpers.Destroy(clip.settings, true); clip.settings = null; } if (clip.settings == null) { clip.settings = RecordersInventory.CreateDefaultRecorderSettings(selectedRecorder); AssetDatabase.AddObjectToAsset(clip.settings, clip); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } m_Editor = (RecorderEditor)CreateEditorWithContext(new UnityObject[] { clip.settings }, SceneHook.GetRecorderBindings()); AssetDatabase.Refresh(); }
public virtual void ReleaseCamera() { UnityHelpers.Destroy(m_CopyMaterial); // Case REC-62 Multiple Recorder produce flipped content // Important to set m_CopyMaterial to null because the getter // might try to return a material that already was destroyed. m_CopyMaterial = null; }
private Material _matSRGBConversion = null; // a shader for doing linear to sRGB conversion protected internal override void BeginRecording(RecordingSession session) { if (cbSettings.renderTexture == null) { return; // error will have been triggered in RenderTextureInputSettings.CheckForErrors() } OutputHeight = cbSettings.OutputHeight; OutputWidth = cbSettings.OutputWidth; OutputRenderTexture = cbSettings.renderTexture; m_needToFlipVertically = cbSettings.FlipFinalOutput; // whether or not the recorder settings have the flip box checked var movieRecorderSettings = session.settings as MovieRecorderSettings; if (movieRecorderSettings != null) { bool encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip; m_needToFlipVertically = m_needToFlipVertically ? encoderAlreadyFlips : !encoderAlreadyFlips; } var requiredColorSpace = ImageRecorderSettings.ColorSpaceType.sRGB_sRGB; if (session.settings is ImageRecorderSettings) { requiredColorSpace = ((ImageRecorderSettings)session.settings).OutputColorSpaceComputed; } else if (session.settings is MovieRecorderSettings) { requiredColorSpace = ImageRecorderSettings.ColorSpaceType.sRGB_sRGB; // always sRGB } var renderTextureColorSpace = UnityHelpers.GetColorSpaceType(cbSettings.renderTexture.graphicsFormat); // the color space of the RenderTexture var projectColorSpace = PlayerSettings.colorSpace; // Log warnings in unsupported contexts if (projectColorSpace == ColorSpace.Gamma) { if (requiredColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB) { Debug.LogWarning($"Gamma color space does not support linear output format. This operation is not supported."); } if (renderTextureColorSpace != ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB) { Debug.LogWarning($"Gamma color space does not support non-linear textures. This operation is not supported."); } } // We convert from linear to sRGB if the project is linear + the source RT is linear + the output color space is sRGB m_needToConvertLinearToSRGB = (projectColorSpace == ColorSpace.Linear && renderTextureColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB) && requiredColorSpace == ImageRecorderSettings.ColorSpaceType.sRGB_sRGB; // We convert from sRGB to linear if the RT is sRGB (gamma) and the output color space is linear (e.g., linear EXR) m_needToConvertSRGBToLinear = renderTextureColorSpace == ImageRecorderSettings.ColorSpaceType.sRGB_sRGB && requiredColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB; if (m_needToFlipVertically || m_needToConvertLinearToSRGB || m_needToConvertSRGBToLinear) { workTexture = new RenderTexture(OutputRenderTexture); workTexture.name = "RenderTextureInput_intermediate"; } }
protected internal override void BeginRecording(RecordingSession session) { OutputWidth = scSettings.OutputWidth; OutputHeight = scSettings.OutputHeight; if (OutputWidth <= 0 || OutputHeight <= 0) { return; // error will be handled by ImageInputSettings.CheckForErrors. Otherwise we get a failure at RenderTexture.GetTemporary() } int w, h; GameViewSize.GetGameRenderSize(out w, out h); if (w != OutputWidth || h != OutputHeight) { var size = GameViewSize.SetCustomSize(OutputWidth, OutputHeight) ?? GameViewSize.AddSize(OutputWidth, OutputHeight); if (GameViewSize.modifiedResolutionCount == 0) { GameViewSize.BackupCurrentSize(); } else { if (size != GameViewSize.currentSize) { Debug.LogError("Requesting a resolution change while a recorder's input has already requested one! Undefined behaviour."); } } GameViewSize.modifiedResolutionCount++; m_ModifiedResolution = true; GameViewSize.SelectSize(size); } // Initialize the temporary texture for forcing opacity m_TempCaptureTextureOpaque = RenderTexture.GetTemporary(OutputWidth, OutputHeight); #if !UNITY_2019_1_OR_NEWER // Before 2019.1, we capture synchronously into a Texture2D, so we don't need to create // a RenderTexture that is used for reading asynchronously. return; #else m_CaptureTexture = new RenderTexture(OutputWidth, OutputHeight, 0, RenderTextureFormat.ARGB32) { wrapMode = TextureWrapMode.Repeat }; m_CaptureTexture.Create(); m_CaptureTexture.name = "GameViewInput_mCaptureTexture"; var movieRecorderSettings = session.settings as MovieRecorderSettings; bool encoderAlreadyFlips = false; if (movieRecorderSettings != null) { encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip; } NeedToFlipVertically = UnityHelpers.NeedToActuallyFlip(false, this, encoderAlreadyFlips); OutputRenderTexture = m_CaptureTexture; #endif }
private async void Sphere_Click(object sender, RoutedEventArgs e) { await UnityHelpers.LoadSceneAsync("SphereScene"); await new MessageDialog("Loaded").ShowAsync(); await UnityBridge.Instance.InvokeAsync(() => DoSomething()); await new MessageDialog("Did Something").ShowAsync(); }
/// <summary> /// /// </summary> public override void PreSetup() { if (this._manager == null) { this._manager = FindObjectOfType <AbstractNeodroidManager>(); } if (this._camera == null) { this._camera = this.GetComponent <Camera>(); } if (this._texture) { UnityHelpers.Destroy(this._texture); } if (this._manager?.SimulatorConfiguration?.SimulationType != SimulationType.Frame_dependent_) { if (this.disable_camera_when_unused) { this._camera.enabled = false; } } var target_texture = this._camera.targetTexture; if (!target_texture) { #if NEODROID_DEBUG Debug.LogWarning($"RenderTexture target not available on {this.Identifier} not available, allocating a default!"); #endif this._rt = new RenderTexture(NeodroidConstants._Default_Width, NeodroidConstants._Default_Height, 0, RenderTextureFormat.ARGBFloat) { filterMode = FilterMode.Point, name = $"rt_{this.Identifier}", enableRandomWrite = true }; this._rt.Create(); this._camera.targetTexture = this._rt; this._texture = new Texture2D(NeodroidConstants._Default_Width, NeodroidConstants._Default_Height, NeodroidConstants._Default_TextureFormat, false, this.linear_space); } else { this._texture = new Texture2D(target_texture.width, target_texture.height, target_texture.graphicsFormat, _flags); } }
protected internal override void EndRecording(RecordingSession session) { base.EndRecording(session); if (workTexture != null) { UnityHelpers.Destroy(workTexture); workTexture = null; } }
public override void SetEntity(ZoneRenderer zoneRenderer, Entity entity) { base.SetEntity(zoneRenderer, entity); var ship = entity as Ship; if (ship == null) { Debug.LogError($"Attempted to assign non-ship entity to {gameObject.name} ship instance prefab!"); return; } Ship = ship; var drive = ship.GetBehavior <AetherDrive>(); if (drive != null) { var particles = Instantiate(UnityHelpers.LoadAsset <ParticleSystem>(drive.DriveData.Particles), transform, false); var main = particles.main; main.customSimulationSpace = LocalSpace; _aetherDrive = new AetherDriveInstance { Drive = drive, BaseEmission = particles.emission.rateOverTimeMultiplier, Particles = particles, BaseForce = particles.forceOverLifetime.z.curveMultiplier }; } _thrusters = ship.GetBehaviors <Thruster>().Select(thruster => { var effectData = (ThrusterData)thruster.Data; var particles = Instantiate(UnityHelpers.LoadAsset <ParticleSystem>(effectData.ParticlesPrefab), transform, false); var particlesShape = particles.shape; var thrusterHardpoint = ThrusterHardpoints .FirstOrDefault(t => t.name == ship.Hardpoints[thruster.Item.Position.x, thruster.Item.Position.y].Transform); particlesShape.meshRenderer = thrusterHardpoint?.Emitter; // if (!string.IsNullOrEmpty(thruster.Item.Data.SoundEffectTrigger) && thrusterHardpoint != null) // { // AkSoundEngine.RegisterGameObj(thrusterHardpoint.gameObject); // AkSoundEngine.PostEvent(thruster.Item.Data.SoundEffectTrigger, thrusterHardpoint.gameObject); // } return(new ThrusterInstance { Thruster = thruster, System = particles, BaseEmission = particles.emission.rateOverTimeMultiplier, MaxParticleCount = 0 }); }) .ToArray(); foreach (var particle in _thrusters) { particle.System.gameObject.SetActive(false); } }
public void OnGUI() { m_LastRepaint = DateTime.Now; // Bug? work arround: on Stop play, Enable is not called. if (m_Editor != null && m_Editor.target == null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; m_recorderSelector = null; } if (m_recorderSelector == null) { if (m_WindowSettingsAsset == null) { var candidates = AssetDatabase.FindAssets("t:RecorderWindowSettings"); if (candidates.Length > 0) { var path = AssetDatabase.GUIDToAssetPath(candidates[0]); m_WindowSettingsAsset = AssetDatabase.LoadAssetAtPath <RecorderWindowSettings>(path); } else { m_WindowSettingsAsset = ScriptableObject.CreateInstance <RecorderWindowSettings>(); AssetDatabase.CreateAsset(m_WindowSettingsAsset, "Assets/FrameRecordingSettings.asset"); AssetDatabase.SaveAssets(); } } m_recorderSelector = new RecorderSelector(OnRecorderSelected, true); m_recorderSelector.Init(m_WindowSettingsAsset.m_Settings, m_StartingCategory); } if (m_State == EState.WaitingForPlayModeToStartRecording && EditorApplication.isPlaying) { DelayedStartRecording(); } using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) m_recorderSelector.OnGui(); if (m_Editor != null) { m_Editor.showBounds = true; using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) { EditorGUILayout.Separator(); m_Editor.OnInspectorGUI(); EditorGUILayout.Separator(); } RecordButtonOnGui(); } }
protected void ChangeInputSettings(int atIndex, RecorderInputSetting newSettings) { newSettings.name = GUID.Generate().ToString(); AssetDatabase.AddObjectToAsset(newSettings, serializedObject.targetObject); AssetDatabase.SaveAssets(); var arryItem = m_Inputs.GetArrayElementAtIndex(atIndex); UnityHelpers.Destroy(arryItem.objectReferenceValue, true); arryItem.objectReferenceValue = newSettings; }
protected internal override void EndRecording(RecordingSession session) { base.EndRecording(session); if (m_ColorRT != null) { UnityHelpers.Destroy(m_ColorRT); } if (m_TempRT != null) { UnityHelpers.Destroy(m_TempRT); } }
protected internal override void EndRecording(RecordingSession session) { base.EndRecording(session); if (workTexture != null) { UnityHelpers.Destroy(workTexture); workTexture = null; } NeedToFlipVertically = null; // This variable is not valid anymore }
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner) { var playable = ScriptPlayable <RecorderPlayableBehaviour> .Create(graph); var behaviour = playable.GetBehaviour(); if (recorderType != null && UnityHelpers.IsPlaying()) { behaviour.session = m_SceneHook.CreateRecorderSession(settings); } return(playable); }
void ResetSettings() { UnityHelpers.Destroy(m_Editor); m_Editor = null; m_recorderSelector = null; var path = AssetDatabase.GetAssetPath(m_WindowSettingsAsset); UnityHelpers.Destroy(m_WindowSettingsAsset, true); AssetDatabase.DeleteAsset(path); AssetDatabase.Refresh(ImportAssetOptions.Default); m_WindowSettingsAsset = null; }
public async void Calling_Home_Should_Return_Objects() { var testServer = TestServer.Create <Repository.Web.Startup>(); //We are cheating here and using the fact that unity gives back the last type registered UnityHelpers.GetConfiguredContainer().RegisterType <IItemRepository, TestItemRepository>(); var response = await testServer.HttpClient.GetAsync("/home/"); var result = await response.Content.ReadAsAsync <IList <string> >(); Assert.AreEqual(result[0], "TestItem"); }
RenderTexture m_TempCaptureTextureVFlip; // A temp RenderTexture for vertical flips protected internal override void BeginRecording(RecordingSession session) { var encoderAlreadyFlips = session.settings.EncoderAlreadyFlips(); NeedToFlipVertically = UnityHelpers.NeedToActuallyFlip(settings360.FlipFinalOutput, this, encoderAlreadyFlips); OutputWidth = settings360.OutputWidth; OutputHeight = settings360.OutputHeight; if (NeedToFlipVertically.Value) { m_TempCaptureTextureVFlip = RenderTexture.GetTemporary(OutputWidth, OutputHeight); } }
protected internal override void NewFrameReady(RecordingSession session) { Profiler.BeginSample("GameViewInput.NewFrameReady"); #if UNITY_2019_1_OR_NEWER ScreenCapture.CaptureScreenshotIntoRenderTexture(m_CaptureTexture); var movieRecorderSettings = session.settings as MovieRecorderSettings; bool needToFlip = scSettings.FlipFinalOutput; if (movieRecorderSettings != null) { bool encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip; needToFlip &= encoderAlreadyFlips; } if (needToFlip) { OutputRenderTexture = m_VFlipper?.Flip(m_CaptureTexture); } // Force opaque alpha channel MakeFullyOpaque(OutputRenderTexture); #else ReadbackTexture = ScreenCapture.CaptureScreenshotAsTexture(); var movieRecorderSettings = session.settings as MovieRecorderSettings; if (movieRecorderSettings != null) { var currEncoder = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected]; var requiredFormat = currEncoder.GetTextureFormat(movieRecorderSettings); var isGameView = movieRecorderSettings.ImageInputSettings is GameViewInputSettings; if (!currEncoder.PerformsVerticalFlip) { ReadbackTexture = UnityHelpers.FlipTextureVertically(ReadbackTexture, movieRecorderSettings.CaptureAlpha); } if (requiredFormat != ReadbackTexture.format) { if (requiredFormat == TextureFormat.RGB24 && ReadbackTexture.format == TextureFormat.RGBA32) { ReadbackTexture = UnityHelpers.RGBA32_to_RGB24(ReadbackTexture); } else { throw new Exception($"Unexpected conversion requested: from {ReadbackTexture.format} to {requiredFormat}."); } } } // Force opaque alpha channel MakeFullyOpaque(ReadbackTexture); #endif Profiler.EndSample(); }
public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.DependencyResolver = new UnityResolver( UnityHelpers.GetConfiguredContainer()); ConfigureOAuth(app); WebApiConfig.Register(config); app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); app.UseWebApi(config); }
/// <summary> /// Uses the UnityHelpers GetUnityPath method to find the path to the Unity executable, prints the output to the console and returns the result. /// </summary> /// <returns>The path to the Unity binary.</returns> private IEnumerable <string> GetUnityExecutablePath() { var unityExecutablePaths = UnityHelpers.GetUnityPaths(); ConsoleHelpers.Write("Unity binaries: "); ConsoleHelpers.WriteLine(); if (unityExecutablePaths.Count() <= 0) { ConsoleHelpers.ExitOnInput("Failed to find Unity editor binary", ConsoleColor.Red); } unityExecutablePaths.ToList().ForEach(p => ConsoleHelpers.WriteLine($"{p}", ConsoleColor.Green)); ConsoleHelpers.WriteLine(); return(unityExecutablePaths); }
void StopRecording() { if (m_Editor != null) { var settings = (RecorderSettings)m_Editor.target; if (settings != null) { var recorderGO = FrameRecorderGOControler.FindRecorder(settings); if (recorderGO != null) { UnityHelpers.Destroy(recorderGO); } } } }