Пример #1
0
        void CreatePreviewLine()
        {
            UnityEngine.Profiling.Profiler.BeginSample("PointerScript.CreatePreviewLine");
            if (m_PreviewLine == null && m_CurrentBrush.m_BrushPrefab != null)
            {
                // We don't have the transform for the line because it hasn't been created
                // yet, but we can assume that the line transform == the canvas transform,
                // since the line is parented to the canvas with an identity local transform.
                // See also the TODO in GetTransformForLine; fixing that will resolve this wart.
                Transform       notReallyTheLineTransformButCloseEnough = App.Instance.m_CanvasTransform;
                TrTransform     xf_LS = GetTransformForLine(notReallyTheLineTransformButCloseEnough);
                BaseBrushScript line  = BaseBrushScript.Create(
                    App.Instance.m_CanvasTransform,
                    xf_LS,
                    m_CurrentBrush, m_CurrentColor, m_CurrentBrushSize);

                line.gameObject.name = string.Format("Preview {0}", m_CurrentBrush.m_Description);
                line.SetPreviewMode();

                m_PreviewLine = line;
                ResetPreviewProperties();

                m_PreviewControlPoints.Clear();
            }
            UnityEngine.Profiling.Profiler.EndSample();
        }
Пример #2
0
        /// Creates and returns a BatchSubset in the passed Canvas.
        /// If stroke contains too many CPs to fit, it will be cut short.
        /// This differs from what TB does, which is to create multiple subsets.
        public static BatchSubset CreateSubsetFromStroke(CanvasScript canvas, Stroke stroke)
        {
            // See PointerScript.RecreateLineFromMemory

            BrushDescriptor desc = BrushCatalog.m_Instance.GetBrush(stroke.m_BrushGuid);

            var             cp0 = stroke.m_ControlPoints[0];
            var             xf0 = TrTransform.TRS(cp0.m_Pos, cp0.m_Orient, stroke.m_BrushScale);
            BaseBrushScript bbs = BaseBrushScript.Create(
                canvas.transform, xf0, desc, stroke.m_Color, stroke.m_BrushSize);

            try {
                bbs.SetIsLoading();
                Assert.True(bbs.Canvas != null);

                foreach (var cp in stroke.m_ControlPoints)
                {
                    bbs.UpdatePosition_LS(
                        TrTransform.TRS(cp.m_Pos, cp.m_Orient, stroke.m_BrushScale), cp.m_Pressure);
                }
                return(bbs.FinalizeBatchedBrush());
            } finally {
                UnityEngine.Object.DestroyImmediate(bbs.gameObject);
            }
        }
Пример #3
0
        /// Pass a Canvas parent, and a transform in that canvas's space.
        /// If overrideDesc passed, use that for the visuals -- m_CurrentBrush does not change.
        public void CreateNewLine(CanvasScript canvas, TrTransform xf_CS,
                                  ParametricStrokeCreator creator, BrushDescriptor overrideDesc = null)
        {
            // If straightedge is enabled, we may have a minimum size requirement.
            // Initialize parametric stroke creator for our type of straightedge.
            // Maybe change the brush to a proxy brush.
            BrushDescriptor desc = overrideDesc != null ? overrideDesc : m_CurrentBrush;

            m_CurrentCreator = creator;

            // Parametric creators want control over the brush size.
            if (m_CurrentCreator != null)
            {
                m_ParametricCreatorBackupStrokeSize = m_CurrentBrushSize;
                m_CurrentBrushSize = m_CurrentCreator.ProcessBrushSize(m_CurrentBrushSize);
            }

            m_LastUsedBrushSize_CS = (1 / Coords.CanvasPose.scale) * BrushSizeAbsolute;
            m_LineLength_CS        = 0.0f;

            float jitteredBrushSize = m_CurrentBrushSize;

            if (PointerManager.m_Instance.JitterEnabled)
            {
                jitteredBrushSize = PointerManager.m_Instance.GenerateJitteredSize(desc, m_CurrentBrushSize);
            }

            m_CurrentLine = BaseBrushScript.Create(
                canvas.transform, xf_CS,
                desc, m_CurrentColor, jitteredBrushSize);
        }