Exemplo n.º 1
0
        void SetNewNode(Vector3 nodePos, Color nodeColor, TrailData trailData, Trail trail)
        {
            Node node;

            node.time    = Time.time;
            node.pos     = nodePos;
            node.trailId = trailData.currentTrailId;
            node.color   = color;

            trailData.currentNodeIdx++;

            if (trailData.currentNodeIdx >= nodeNum)
            {
                trailData.currentNodeIdx = 0;
            }

            // update trail
            trailData.trails[trailData.currentTrailId] = trail;

            // write new node
            trailData.nodes[trailData.currentNodeIdx] = node;

            trailData.trailBuffer.SetData(trailData.trails, trailData.currentTrailId, trailData.currentTrailId, 1);
            trailData.nodeBuffer.SetData(trailData.nodes, trailData.currentNodeIdx, trailData.currentNodeIdx, 1);
        }
Exemplo n.º 2
0
 void Start()
 {
     trailDatas = new TrailData[Enum.GetValues(typeof(TrailType)).Length];
     for (int i = 0; i < trailDatas.Length; i++)
     {
         trailDatas[i] = new TrailData(trailNum, nodeNum, (TrailType)i);
     }
 }
Exemplo n.º 3
0
        public void InputPoint(Input input, bool isNewTrail)
        {
            TrailData trailData = trailDatas[(int)currentTrailType];

            if (isNewTrail)
            {
                trailData.currentTrailId++;
            }

            if (trailData.currentTrailId < trailNum)
            {
                Trail trail = trailData.trails[trailData.currentTrailId];
                if (isNewTrail)
                {
                    trail.type          = (int)currentTrailType;
                    trail.witdh         = width;
                    trail.particleSpeed = particleSpeed;
                }

                float dist = 0;
                if (trailData.currentNodeIdx >= 0)
                {
                    dist = Vector3.Distance(input.pos, trailData.nodes[trailData.currentNodeIdx].pos);
                }

                //input positionと前フレームでの最後の点を結ぶ
                //一定の距離で正規化して配置。そのため、厳密には、マウスの点を通らない可能性あり
                while (dist > updateDistaceMin && !isNewTrail)
                {
                    Vector3 currentNodePos = trailData.nodes[trailData.currentNodeIdx].pos;
                    Vector3 nodePos        = currentNodePos + updateDistaceMin * (input.pos - trailData.nodes[trailData.currentNodeIdx].pos).normalized;
                    SetNewNode(nodePos, new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value, 1), trailData, trail);

                    dist = Vector3.Distance(input.pos, nodePos);
                }

                //ラインの最初の点だけは指定された位置
                if (isNewTrail)
                {
                    SetNewNode(input.pos, new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value, 1), trailData, trail);
                }
            }
        }