コード例 #1
0
        public float AddSegment(Vector3 endPos)
        {
            float distance = (lastPos - endPos).sqrMagnitude;

            if (distance < SEGMENT_DISTANCE_THRESHOLD)
            {
                return(0);
            }

            distance = Mathf.Sqrt(distance);
            segment element  = new segment();
            float   inkUsage = 0;

            element.proneTime     = Time.time + lifeTime;
            element.segmentObject = null;
            if (line.Count > 0)
            {
                element.segmentObject = Instantiate(segmentPrefab);                 //Pooling?
                element.segmentObject.transform.position = lastPos;
                element.segmentObject.transform.rotation = Quaternion.LookRotation(endPos - lastPos, Vector3.up);

                //WARNING: prefab dependent stuff. do not use or copy this code
                //element.segmentObject.transform.localScale = new Vector3(1.0f, 1.0f, (endPos - lastPos).magnitude);
                element.segmentObject.transform.GetChild(0).localScale     = new Vector3(1.0f, 1.0f, distance);
                element.segmentObject.transform.GetChild(1).localPosition *= distance;
                inkUsage = distance;
            }

            line.Enqueue(element);
            lastPos = endPos;
            Pen.s_changedBlocker?.Invoke();

            return(inkUsage);
        }
コード例 #2
0
        private void RemoveSegment()
        {
            segment element = line.Dequeue();

            Destroy(element.segmentObject);             //Pooling?
        }