예제 #1
0
        private void DrawGizmos(bool selected)
        {
            Update_Path();

            if (transform.childCount > 1)
            {
            }
            else
            {
                return;
            }

            Path_Point prev = GetPathPoint(0.0f);
            float      dist = -gizmoLineSize;

            do
            {
                dist = Mathf.Clamp(dist + gizmoLineSize, 0, _path.TotalDistance);

                Path_Point next = GetPathPoint(dist);

                Gizmos.color = selected ? new Color(0, 1, 1, 1) : new Color(0, 1, 1, 0.5f);
                Gizmos.DrawLine(transform.TransformPoint(prev.point), transform.TransformPoint(next.point));
                Gizmos.color = selected ? Color.green : new Color(0, 1, 0, 0.5f);
                Gizmos.DrawLine(transform.TransformPoint(next.point), transform.TransformPoint(next.point) + transform.TransformDirection(next.up * gizmoLineSize));
                Gizmos.color = selected ? Color.red : new Color(1, 0, 0, 0.5f);
                Gizmos.DrawLine(transform.TransformPoint(next.point), transform.TransformPoint(next.point) + transform.TransformDirection(next.right * gizmoLineSize));

                prev = next;
            }while(dist < _path.TotalDistance);
        }
예제 #2
0
        private void Craft()
        {
            //初始化组件Path_camp
            _path = GetComponent <Path_Comp>();
            // struct Path_Point 包含point,forward,up,right;
            //GetPathPoint() 返回一个Path_Point 依据传入的distance(距离起始点的距离)
            Path_Point pointA  = _path.GetPathPoint(0.0f);//获得路径的起点
            Path_Point pointB  = pointA;
            Path_Point pointB2 = pointA;

            //_segment_length = max_z - min_z; 传入的dist 为距离起点的两两直线段距离
            for (float dist = 0.0f; dist < _path._path.TotalDistance; dist += _segment_length)
            {                                                                                                                  //对于dist=0,dist<总长度,dist=dist+分段的距离
                pointB  = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length, 0, _path._path.TotalDistance));               //确定B点的位置
                pointB2 = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length - (float)0.05, 0, _path._path.TotalDistance)); //确定B点的位置

                _helpTransform1.rotation = Quaternion.LookRotation(pointA.forward, pointA.up);                                 //游戏对象1的旋转=z轴朝向view,y轴朝向up
                _helpTransform1.position = transform.TransformPoint(pointA.point);                                             //对象1的位置是A点的位置

                _helpTransform2.rotation = Quaternion.LookRotation(pointB.forward, pointB.up);                                 //游戏对象2的旋转=z轴朝向view,y轴朝向up
                _helpTransform2.position = transform.TransformPoint(pointB.point);                                             //对象2的位置是B点的位置


                Add_Segment();    //添加分段

                pointA = pointB2; //A->B
            }
        }
예제 #3
0
        private void CreateBolt(LineRenderer line)
        {
            //lineObject.material.SetTextureScale("_MainTex", new Vector2(distance * zigZagPerMeter, 1.0f));
            //lineObject.numPositions = vertexCount;

            float totalDistance = _pathComp.TotalDistance;
            int   numPositions  = Mathf.CeilToInt(totalDistance * zigZagPerMeter);

            Vector3[] points = new Vector3[numPositions];

            line.positionCount = numPositions;
            line.material.SetTextureScale("_MainTex", new Vector2(totalDistance * zigZagPerMeter, 1.0f));

            // set the ends
            points[0] = _pathComp.GetPathPoint(0.0f).point;
            points[numPositions - 1] = _pathComp.GetPathPoint(totalDistance).point;


            Vector2 previousOffset = Vector2.zero;

            for (int i = 1; i < numPositions - 1; i++)
            {
                Path_Point pathPoint = _pathComp.GetPathPoint(Math_Functions.Value_from_another_Scope(i, 0, numPositions - 1, 0, totalDistance));


                Vector2 offset = new Vector2(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f));

                offset        *= zigZagIntensity;
                previousOffset = offset;

                points[i] = pathPoint.point + (pathPoint.right * offset.x) + (pathPoint.up * offset.y);
            }

            line.SetPositions(points);
        }
        void LateUpdate()
        {
            if (_particle_array == null)
            {
                Start();
            }

            if (isRectangleSizeUpdating)
            {
                Calculate_The_Four_Corners();
            }

            _numParticles = _particle_system.GetParticles(_particle_array);

            if (_numParticles > 0)
            {
                for (int i = 0; i < _numParticles; i++)
                {
                    ParticleSystem.Particle obj = _particle_array[i];

                    // This made it based on the particle lifetime
//					float normalizedLifetime = (1.0f - obj.remainingLifetime / obj.startLifetime);
//
//					if(hasRandomStartingPoints){
//						normalizedLifetime += Get_Value_From_Random_Seed_0t1(obj.randomSeed, 100.0f);
//						normalizedLifetime = normalizedLifetime % 1.0f;
//					}
//
//					Path_Point axis = _path.GetPathPoint(_path.TotalDistance * normalizedLifetime, isSmooth);


                    // This made it based on the paritcle speed
                    float dist = (obj.startLifetime - obj.remainingLifetime) * obj.velocity.magnitude;
                    if (hasRandomStartingPoints)
                    {
                        dist += Get_Value_From_Random_Seed_0t1(obj.randomSeed, 100.0f) * _path.TotalDistance;
                    }
                    dist = dist % _path.TotalDistance;

                    Path_Point axis = _path.GetPathPoint(dist, isSmooth);


                    Vector2 offset = Vector2.zero;

                    if (pathWidth > 0)
                    {
                        offset  = Math_Functions.AngleToVector2D(obj.randomSeed % 360.0f);
                        offset *= Get_Value_From_Random_Seed_0t1(obj.randomSeed, 150.0f) * pathWidth;
                    }

                    _particle_array[i].position = axis.point +
                                                  (isFlat ? Vector3.zero :  axis.right * offset.x) +
                                                  (axis.up * offset.y);

                    _particle_array[i].velocity = axis.forward * _particle_array[i].velocity.magnitude;
                }

                _particle_system.SetParticles(_particle_array, _numParticles);
            }
        }
예제 #5
0
        private void Craft()
        {
            _path = GetComponent <Path_Comp>();
            Path_Point pointA = _path.GetPathPoint(0.0f);
            Path_Point pointB = pointA;

            for (float dist = 0.0f; dist < _path._path.TotalDistance; dist += _segment_length)
            {
                pointB = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length, 0, _path._path.TotalDistance));

                _helpTransform1.rotation = Quaternion.LookRotation(pointA.forward, pointA.up);
                _helpTransform1.position = transform.TransformPoint(pointA.point);

                _helpTransform2.rotation = Quaternion.LookRotation(pointB.forward, pointB.up);
                _helpTransform2.position = transform.TransformPoint(pointB.point);

                Add_Segment();

                pointA = pointB;
            }
        }
예제 #6
0
        public Vector3[] GetTrackPoints()
        {
            ScanSourceMesh();

            _path = GetComponent <Path_Comp>();
            Path_Point pointA = _path.GetPathPoint(0.0f);
            Path_Point pointB = pointA;

            int totalTrackPoints = (int)(_path._path.TotalDistance / _segment_length) + 1;

            trackPoints = new Vector3[totalTrackPoints];
            int count = 0;

            for (float dist = 0.0f; dist < _path._path.TotalDistance; dist += _segment_length)
            {
                pointB = _path.GetPathPoint(Mathf.Clamp(dist + _segment_length, 0, _path._path.TotalDistance));

                trackPoints[count] = pointA.point;
                count++;
                pointA = pointB;
            }

            return(trackPoints);
        }
예제 #7
0
        void LateUpdate()
        {
            if (_particle_array == null)
            {
                Start();
                _path_comp.Update_Path();
            }
            else if (isPathUpdating)
            {
                _path_comp.Update_Path();
            }



            _numParticles = _particle_system.GetParticles(_particle_array);

            if (_numParticles > 0)
            {
                for (int i = 0; i < _numParticles; i++)
                {
                    ParticleSystem.Particle obj = _particle_array[i];
                    Path_Point axis             = _path_comp.GetPathPoint(_path_comp.TotalDistance * (1.0f - obj.remainingLifetime / obj.startLifetime));
                    Vector2    offset           = Math_Functions.AngleToVector2D(obj.randomSeed % 360.0f);

                    offset *= (((float)obj.randomSeed % 100.0f) / 100.0f) * pathWidth;

                    _particle_array[i].position = axis.point +
                                                  (axis.right * offset.x) +
                                                  (axis.up * offset.y);

                    _particle_array[i].velocity = axis.forward * _particle_array[i].velocity.magnitude;
                }

                _particle_system.SetParticles(_particle_array, _numParticles);
            }
        }
예제 #8
0
        //Gizmos是用于在场景视图可视化调试或辅助设置。==================game视图中不可用,需要对点做模型,并且提供平移
        private void DrawGizmos(bool selected)
        {
            Update_Path();

            if (transform.childCount <= 1)
            {
                return;
            }

            Path_Point prev = GetPathPoint(0.0f);
            //gizmoLineSize=1.0f; [Range(0.01f, 1.0f)],用来变形的常量
            float dist = -gizmoLineSize;

            //print (dist);
            //print (gizmoLineSize);
            //int i = 0;
            do
            {
                //i += 1;

                //gizmoLineSize / 10 : 控制曲线上点与点的距离
                dist = Mathf.Clamp(dist + gizmoLineSize / 10, 0, _path.TotalDistance);

                //=======!!!此处不断依据CatmullRom算法,找到一个个点
                Path_Point next = GetPathPoint(dist);
                //print("前点:"+prev.point.x+","+prev.point.y+","+prev.point.z);
                //print("前点方向:"+prev.forward);

                //print("后点:"+next.point.x +","+next.point.y+","+next.point.z);
                float distance = Vector3.Distance(prev.point, next.point);
                distance = distance / 2;
                //print("点间距/2:"+distance);
                Vector3 V = next.point - prev.point;
                V = V.normalized;
                //print("两点之间的向量:"+V);//后点-前点
                float angle = Vector3.Angle(prev.forward, V);
                //print("两向量之间的夹角:"+angle);
                //print(Mathf.Sin(angle));
                //print(Mathf.Sin(90));

                //r=(length/2)/sina
                float radius = distance / Mathf.Sin(Math_Functions.DegreesToRadians(angle));
                //print("第" + i + "个点" + "前点:" + prev.point.x + "," + prev.point.y + "," + prev.point.z + "后点:" + next.point.x + "," + next.point.y + "," + next.point.z + "两向量之间的夹角:" + angle + "前点处的转弯半径:" + radius);

                if (radius < 2.7 && radius != 0)
                {
                    Gizmos.color = selected ? Color.red : new Color(1, 0, 0, 0.5f);
                    Gizmos.DrawLine(transform.TransformPoint(prev.point), transform.TransformPoint(next.point));
                    Gizmos.color = selected ? Color.green : new Color(0, 1, 0, 0.5f);
                    //Gizmos.DrawLine(transform.TransformPoint(next.point), transform.TransformPoint(next.point) + transform.TransformDirection(next.up * gizmoLineSize));
                    Gizmos.color = selected ? new Color(0, 1, 1, 1) : new Color(0, 1, 1, 0.5f);
                    //Gizmos.DrawLine(transform.TransformPoint(next.point), transform.TransformPoint(next.point) + transform.TransformDirection(next.right * gizmoLineSize));
                }
                else
                {
                    Gizmos.color = selected ? new Color(0, 1, 1, 1) : new Color(0, 1, 1, 0.5f);
                    Gizmos.DrawLine(transform.TransformPoint(prev.point), transform.TransformPoint(next.point));
                    Gizmos.color = selected ? Color.green : new Color(0, 1, 0, 0.5f);
                    //Gizmos.DrawLine(transform.TransformPoint(next.point), transform.TransformPoint(next.point) + transform.TransformDirection(next.up * gizmoLineSize));
                    Gizmos.color = selected ? Color.red : new Color(1, 0, 0, 0.5f);
                    // Gizmos.DrawLine(transform.TransformPoint(next.point), transform.TransformPoint(next.point) + transform.TransformDirection(next.right * gizmoLineSize));
                }
                prev = next;
            } while (dist < _path.TotalDistance);
        }