private List <SampleContainer> WriteSamplesToAsset() { if (m_generateSimpleData == null || m_generateSimpleData.Count == 0) { return(null); } List <SampleContainer> data = new List <SampleContainer>(); int width = m_width == 0 ? m_sampleManager.GetCaptureWidth() : m_width; int height = m_height == 0 ? m_sampleManager.GetCaptureHeight() : m_height; float playerHeight = m_sampleManager.GetPlayerHeight(); int obstacleLength = width * height; int playerLength = m_sampleManager.GetInputLayerLengthPlayer(width, playerHeight); int dataLength = obstacleLength + playerLength; foreach (SampleGenerationBase sampleGeneration in m_generateSimpleData) { List <SampleContainer> simpleData = sampleGeneration.GenerateSamples(width, height, obstacleLength, playerLength); for (int i = 0; i < simpleData.Count; i++) { data.Add(simpleData[i]); } } if (data.Count == 0) { Debug.Log("No data has been writen! Data length was 0. (Post)"); return(null); } return(data); }
public int GetCaptureWidth() { if (m_captureWidth <= 0) { return(m_screenshotManager.GetCaptureWidth()); } return(m_captureWidth); }
void Render() { SampleContainer sample = m_samples[m_currentSampleIndex]; int renderWidth = sample.m_width; int renderHeight = sample.m_height + 1; float pixelSize = m_screenshotManager.GetBackgroundHeight() * m_screenshotManager.GetCaptureWidth() / m_screenshotManager.GetCaptureHeight() / renderWidth; int height = (int)(m_screenshotManager.GetPlayerHeight() / pixelSize); if (m_screenshotManager.GetPlayerHeight() != pixelSize) { height += 1; } int playerLength = renderWidth * height; //m_rect = new Rect(0, 0, renderWidth, renderHeight); //m_renderTexture = new RenderTexture(renderWidth, renderHeight, 24); //m_screenshotTexture = m_image.texture as Texture2D;// new Texture2D(renderWidth, renderHeight, TextureFormat.RGB24, false); Destroy(m_image.texture); Destroy(m_screenshotTexture); m_screenshotTexture = new Texture2D(renderWidth, renderHeight, TextureFormat.RGB24, false); m_screenshotTexture.filterMode = FilterMode.Point; // input for (int h = 0; h < sample.m_height; h++) { for (int w = 0; w < sample.m_width; w++) { int index = w + h * sample.m_width; float obstacleInput = Mathf.Clamp01(sample.m_input[index]); int playerIndex = index + sample.m_width * sample.m_height; float playerInput = playerIndex >= sample.m_input.Length ? 0f : Mathf.Clamp01(sample.m_input[playerIndex]); if (index < playerLength && playerInput > 0) { m_screenshotTexture.SetPixel(w, h, new Color(0, playerInput, 0)); } else if (obstacleInput > 0) { m_screenshotTexture.SetPixel(w, h, new Color(obstacleInput, 0, 0)); } else { m_screenshotTexture.SetPixel(w, h, new Color(0, 0, 0)); } } } // desired output for (int i = 0; i < sample.m_desiredOutput.Length; i++) { int startIndex = (int)((float)sample.m_width * i / (sample.m_desiredOutput.Length)); int endIndex = (int)Mathf.Min(startIndex + (float)sample.m_width / sample.m_desiredOutput.Length, sample.m_width - 1); for (int j = startIndex; j <= endIndex; j++) { Color c = new Color(); if (i == 0) { c.g = sample.m_desiredOutput[0]; } if (i == 1) { c.r = sample.m_desiredOutput[2]; } if (i == 2) { c.b = sample.m_desiredOutput[1]; } m_screenshotTexture.SetPixel(j, renderHeight - 1, c);// new Color(sample.m_desiredOutput[0] * 255, sample.m_desiredOutput[1] * 255, sample.m_desiredOutput[2] * 255)); } } // apply m_screenshotTexture.Apply(); m_image.texture = m_screenshotTexture; }