예제 #1
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
            }
        }
예제 #2
0
        public Vector3 GetPoint(float dist, Path_Comp path)
        {
            Vector3 point = Vector3.zero;

            point = transform.TransformPoint(path._path.GetPathPoint(dist, true).point);
            return(point);
        }
예제 #3
0
        void OnEnable()
        {
            _path_comp = GetComponent <Path_Comp>();

            _particle_system = GetComponent <ParticleSystem>();
            ParticleSystem.EmissionModule em = _particle_system.emission;
            em.enabled = false;

            _particle_array = new ParticleSystem.Particle[_particle_system.maxParticles];

            _particle_trackerArray = new PathParticleTracker[_particle_system.maxParticles];
            for (int i = 0; i < _particle_trackerArray.Length; i++)
            {
                _particle_trackerArray[i] = new PathParticleTracker();
            }

            _emissionRateTracker = 1.0f / emissionRate;


        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                _editorTimetracker = EditorApplication.timeSinceStartup;
            }
        #endif
        }
예제 #4
0
        public float GetNearestPoint(Vector3 position, Path_Comp path, float precision = 0.05f)
        {
            if (newNearestAlgorithm)
            {
                float f = GetNearestPointTree(position, path, 10, 10f, 20f);

                // 1024 recursions takes 7-12 ms
                // 512 recursions takes 3-5 ms
                // 400 and below takes 1-2 ms
                // 64 and less takes 0 ms!


                return(f);
            }
            else
            {
                float currentDistanceL = 9999f;
                float currentDistance;
                float currentClosestT = path.TotalDistance;
                for (float i = 0; i < path.TotalDistance; i += precision)
                {
                    currentDistance = (GetPoint(i, path) - position).sqrMagnitude;
                    if (currentDistance < currentDistanceL)
                    {
                        currentDistanceL = currentDistance;
                        currentClosestT  = i;
                    }
                }

                return(currentClosestT);
            }
        }
예제 #5
0
 public void GenerateStatic(Path_Comp path)
 {
     for (int i = 0; i < transform.childCount; i++)
     {
         //Add(staticPoints, transform.GetChild(i).position);
     }
 }
예제 #6
0
 public void GenerateDynamic(Path_Comp path)
 {
     for (int i = 0; i < transform.childCount; i++)
     {
         //Debug.Log(i);
         //dynamicPoints.Add(transform.GetChild(i).position);
     }
 }
예제 #7
0
        public Vector3 GetRightTangent(float dist, Path_Comp path)
        {
            //kinda false tangent gonna fix that soon
            //tangentdist should be 0.05 or smth
            Vector3 tangent = Vector3.zero;

            tangent = path.GetPathPoint(dist).right;
            return(tangent);
        }
예제 #8
0
        public Vector3 GetTangent(float dist, Path_Comp path)
        {
            //kinda false tangent gonna fix that soon
            //tangentdist should be 0.05 or smth
            Vector3 tangent = Vector3.zero;

            tangent = path.GetPathPoint(dist).forward;

            //StartCoroutine(Math_Functions.CatmullRomThread());
            return(tangent);
        }
예제 #9
0
        float GetNearestPointRef(Vector3 position, Path_Comp path, float precision = 0.05f)
        {
            float currentDistanceL = 9999f;
            float currentDistance;
            float currentClosestT = path.TotalDistance;

            for (float i = 0; i < path.TotalDistance; i += precision)
            {
                currentDistance = (GetPoint(i, path) - position).sqrMagnitude;
                if (currentDistance < currentDistanceL)
                {
                    currentDistanceL = currentDistance;
                    currentClosestT  = i;
                }
            }
            return(currentClosestT);
        }
예제 #10
0
        public float GetNearestPointTree(Vector3 position, Path_Comp path, int recursions, float range, float precision = 5f)
        {
            float   closestDistanceT = 99999f;
            float   closestDistance  = 99999f;
            Vector2 Scanrange        = Vector2.zero;

            for (float i = 0; i < path.TotalDistance; i += precision)
            {
                Vector3 po = GetPoint(i, path);
                float   d  = (position - po).sqrMagnitude;
                UnityEngine.Debug.DrawRay(po, Vector3.up);
                if (d < closestDistance)
                {
                    closestDistanceT = i;
                    closestDistance  = d;
                }
            }

            Scanrange = new Vector2(Mathf.Clamp(closestDistanceT - (range), 0f, 99999f), closestDistanceT + (range));

            for (int r = 1; r < recursions + 1; r++)
            {
                for (float i = Scanrange.x; i <= Scanrange.y; i += precision / r)
                {
                    Vector3 po = GetPoint(i, path);
                    UnityEngine.Debug.DrawRay(po, Vector3.up);
                    float d = (position - po).sqrMagnitude;

                    if (d < closestDistance)
                    {
                        closestDistanceT = i;
                        closestDistance  = d;
                    }
                }
                Scanrange = new Vector2(closestDistanceT - (range / r), closestDistanceT + (range / r));
            }



            return(closestDistanceT);
        }
예제 #11
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;
            }
        }
예제 #12
0
        public float GetNearestPointCustom(Vector3 position, Path_Comp path, float recursions, float precision = 0.05f)
        {
            if (newNearestAlgorithm)
            {
                //Stopwatch s = new Stopwatch();
                //s.Start();
                float f = GetNearestPointTree(position, path, (int)recursions, 10f, 20f);

                // 1024 recursions takes 7-12 ms
                // 512 recursions takes 3-5 ms
                // 400 and below takes 1-2 ms
                // 64 and less takes 0 ms!

                //s.Stop();

                //UnityEngine.Debug.Log(s.ElapsedMilliseconds);

                return(f);
            }
            else
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                float currentDistanceL = 9999f;
                float currentDistance;
                float currentClosestT = path.TotalDistance;
                for (float i = 0; i < path.TotalDistance; i += precision)
                {
                    currentDistance = (GetPoint(i, path) - position).sqrMagnitude;
                    if (currentDistance < currentDistanceL)
                    {
                        currentDistanceL = currentDistance;
                        currentClosestT  = i;
                    }
                }
                stopWatch.Stop();

                return(currentClosestT);
            }
        }
예제 #13
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);
        }
        void OnEnable()
        {
            _path_comp = GetComponent <Path_Comp>();

            _particle_system = GetComponent <ParticleSystem>();
            ParticleSystem.EmissionModule em = _particle_system.emission;
            em.enabled = false;

            _particle_array = new ParticleSystem.Particle[_particle_system.main.maxParticles];

            _particle_trackerArray = new PathParticleTracker[_particle_system.main.maxParticles];
            for (int i = 0; i < _particle_trackerArray.Length; i++)
            {
                _particle_trackerArray[i] = new PathParticleTracker();
            }

            if (_particle_system.main.prewarm)
            {
                float numRevive = Mathf.Floor(emissionRate * _particle_system.main.startLifetime.constant);
                for (int i = 0; i < numRevive; i++)
                {
                    _particle_trackerArray[i].Revive(_particle_system);
                    _particle_trackerArray[i].particle.remainingLifetime = _particle_trackerArray[i].particle.startLifetime * ((float)i / numRevive);
                }
            }

            _emissionRateTracker = 1.0f / emissionRate;


        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                _editorTimetracker = EditorApplication.timeSinceStartup;
            }
        #endif
        }
예제 #15
0
 void Start()
 {
     _path_comp       = GetComponent <Path_Comp>();
     _particle_system = GetComponent <ParticleSystem>();
     _particle_array  = new ParticleSystem.Particle[_particle_system.main.maxParticles];
 }
예제 #16
0
 // Use this for initialization
 void Start()
 {
     _pathComp = GetComponent <Path_Comp>();
 }