コード例 #1
0
        public void AddToQueue(PixelRenderer subject, bool doUpdate)
        {
            #if (UNITY_EDITOR)
            // Prevent triggering of render from scene view
            if (new List <Camera>(UnityEditor.SceneView.GetAllSceneCameras()).Contains(Camera.current))
            {
                return;
            }
            #endif
            // Don't add to queue if the active camera is already the render camera
            if (Camera.current == renderCamera)
            {
                return;
            }

            // Get the subject bounding rect
            Rect bounds = subject.Bounds;

            if (doUpdate)
            {
                // Prep the subject and sub-sprites
                subject.Prep(tempLayer);
                subject.BroadcastMessage("PrepSubSprite", tempLayer, SendMessageOptions.DontRequireReceiver);

                // Position the render camera
                renderCamera.transform.position = (Vector3)((Vector2)subject.transform.position + bounds.position) + Vector3.forward * renderCamera.transform.position.z;
                renderCamera.orthographicSize   = bounds.size.y / 2;
                renderCamera.targetTexture      = subject.RenderTarget;

                // Take the picture
                renderCamera.Render();
                renderCamera.targetTexture = null;

                // Release the subject and sub-sprites
                subject.Release();
                subject.BroadcastMessage("ReleaseSubSprite", SendMessageOptions.DontRequireReceiver);
            }

            // Add item to draw queue
            Matrix4x4 transformMatrix = new Matrix4x4(
                new Vector4(bounds.size.x, 0, 0, 0),
                new Vector4(0, bounds.size.y, 0, 0),
                new Vector4(0, 0, 1, 0),
                new Vector4(subject.transform.position.x + bounds.position.x, subject.transform.position.y + bounds.position.y, 0, 1)
                );
            //transformMatrix = mainCamera.transform.worldToLocalMatrix * transformMatrix;

            int          order = subject.orderInLayer + SortingLayer.GetLayerValueFromName(subject.sortingLayer) * sortingLayerContribution;
            DrawMeshItem item  = new DrawMeshItem(subject.RenderTarget, transformMatrix, subject.material ? subject.material : defaultMaterial, subject.outlineColor, subject.palette ? subject.palette : defaultPalette);
            while (drawQueue.ContainsKey(order))
            {
                order++;
            }
            drawQueue.Add(order, item);
        }
コード例 #2
0
        public void ConvertQueue()
        {
            while (drawQueue.Count > 0)
            {
                // Pop item off front of queue
                DrawMeshItem item = drawQueue.Values[0];
                drawQueue.RemoveAt(0);

                // Set property block texture and submit to command buffer
                propertyBlock.SetTexture("_MainTex", item.texture);
                propertyBlock.SetColor("_OutlineColor", item.outlineColor);
                propertyBlock.SetTexture("_PaletteTex", item.palette);

                commandBuffer.DrawMesh(drawMesh, item.transform, item.material, 0, 0, propertyBlock);
            }
        }