示例#1
0
 protected void startPrint()
 {
     if (m_currentTextures.Count > 0)
     {
         Texture2D texture = null;
         while (m_currentTextures.Count > 0)
         {
             texture = m_currentTextures[m_currentTextures.Count - 1];
             m_currentTextures.RemoveAt(m_currentTextures.Count - 1);
             Texture2D.DestroyImmediate(texture);
         }
     }
     m_currentPrintX = 0;
     m_currentPrintY = 0;
     if (m_printSize.x != m_canvasSize.x)
     {
         m_currentPrintX = Mathf.FloorToInt(m_canvas.width * 0.5f - m_printSize.x * 0.5f);
     }
     if (m_printSize.y != m_canvasSize.y)
     {
         m_currentPrintY = Mathf.FloorToInt(m_canvas.height * 0.5f - m_printSize.y * 0.5f);
     }
     for (int i = 0; i < m_frameTotal; i++)
     {
         m_currentTextures.Add(new Texture2D(m_printSize.x, m_printSize.y, m_outputTextureFormat, false));
     }
     m_currentFrame         = 0;
     m_currentIntervalCount = 0;
     m_currentTimePass      = 0;
     m_currentDuration      = m_duration > 0 ? m_duration : PrefabPrinterUtility.CalculateObjectDuraion(m_currentObject, true);
     m_currentIntervalTotal = m_ignoreZero ? (m_currentDuration / m_frameTotal) : (m_currentDuration / (m_frameTotal - 1));
     m_currentOutputPath    = System.IO.Path.Combine(Application.dataPath, m_outputFolder);
     m_currentObjectName    = m_currentObject.name;
     if (!System.IO.Directory.Exists(m_currentOutputPath))
     {
         System.IO.Directory.CreateDirectory(m_currentOutputPath);
     }
     if (m_outputCreateFolder)
     {
         m_currentOutputPath = System.IO.Path.Combine(m_currentOutputPath, m_currentObjectName);
         if (!System.IO.Directory.Exists(m_currentOutputPath))
         {
             System.IO.Directory.CreateDirectory(m_currentOutputPath);
         }
     }
     if (m_useSimulate)
     {
         PrefabPrinterUtility.StopObject(m_currentObject);
     }
     else
     {
         PrefabPrinterUtility.PlayObject(m_currentObject);
     }
     print();
     if (m_currentDuration <= 0)
     {
         completePrint();
     }
 }
示例#2
0
 protected void print()
 {
     m_currentFrame++;
     m_cachedTexture      = RenderTexture.active;
     RenderTexture.active = m_canvas;
     if (m_useSimulate)
     {
         float simulateTime = m_ignoreZero ? (m_currentFrame * m_currentIntervalTotal) : ((m_currentFrame - 1) * m_currentIntervalTotal);
         PrefabPrinterUtility.SimulateObject(m_currentObject, simulateTime);
     }
     m_camera.Render();
     m_currentTextures[m_currentFrame - 1].ReadPixels(new Rect(m_currentPrintX, m_currentPrintY, m_printSize.x, m_printSize.y), 0, 0);
     RenderTexture.active = m_cachedTexture;
 }