示例#1
0
 public Vector3 GetPoint(WaypointsMover mover, float time)
 {
     //if (IsCurved)
     {
         float fullLength     = BezierApproximation.GetLength(_moversParts[mover]);
         float remainedLength = fullLength * (time - 0.001f);
         for (int i = 0; i < _moversParts[mover].Count - 1; i++)
         {
             Vector3 point1     = _moversParts[mover][i];
             Vector3 point2     = _moversParts[mover][i + 1];
             float   lineLength = Vector3.Distance(point1, point2);
             if (lineLength < remainedLength)
             {
                 remainedLength -= lineLength;
             }
             else
             {
                 return(point1 + (point2 - point1).normalized * remainedLength);
             }
         }
         throw new Exception("Get point error for time:" + time + ", remainedLength: " + remainedLength);
     }
     //			else
     //			{
     //				Vector3 point1 = _moversParts[mover][0];
     //				Vector3 point2 = _moversParts[mover][1];
     //				float fullLength = Vector3.Distance(point1, point2);
     //				float remainedLength = fullLength*time;
     //				return point1 + (point2 - point1).normalized * remainedLength;
     //			}
 }
示例#2
0
        public void OnEnable()
        {
            _waypointsMover = target as WaypointsMover;

            if (Mathf.Abs(WaypointsMover.InitSpeed - _waypointsMover.Speed) < 0.00001f)
            {
                _waypointsMover.Speed = 0.2f * Camera.main.orthographicSize;
            }
        }
示例#3
0
    public void SpawnGems()
    {
        Path path = GemPaths[Random.Range(0, GemPaths.Length)];

        for (int i = 0; i < 10; i++)
        {
            WaypointsMover gem = Instantiate(GemPrefabs);
            gem.Go(path);
        }
    }
示例#4
0
 public void LaunchRockets()
 {
     foreach (Path path in RocketPaths)
     {
         WaypointsMover mover = Instantiate(RocketPrefab);
         mover.OneWayFinished += OnOneWayFinished;
         mover.Go(path);
         mover.transform.SetParent(transform);
     }
 }
示例#5
0
        private WaypointsMover GenerateCharacter(Path path)
        {
            Transform character = PrefabUtility.InstantiatePrefab(_levelsMap.CharacterPrefab) as Transform;

            character.transform.parent = _levelsMap.transform;
            WaypointsMover waypointsMover = character.gameObject.AddComponent <WaypointsMover>();

            waypointsMover.Path  = path;
            waypointsMover.Speed = Camera.main.orthographicSize;
            return(waypointsMover);
        }
示例#6
0
 public float GetLength(WaypointsMover mover, int fromInd, int toInd, bool isForwardDirection)
 {
     //if (IsCurved)
     {
         Vector3 handle1 = isForwardDirection ? GetHandle1(mover, fromInd) : GetHandle2(mover, fromInd);
         Vector3 handle2 = isForwardDirection ? GetHandle2(mover, toInd) : GetHandle1(mover, toInd);
         return(BezierApproximation.GetLength(_capturedPositions[mover][fromInd], handle1, _capturedPositions[mover][toInd], handle2, LinesCount));
     }
     //			else
     //			{
     //				return Vector3.Distance(_capturedPositions[mover][fromInd], _capturedPositions[mover][toInd]);
     //			}
 }
示例#7
0
    public Vector3 CapturePosition(WaypointsMover mover, int waypointIndex)
    {
        Transform waypoint = Waypoints[waypointIndex];
        //RandomWaypoint randomWaypoint = waypoint.GetComponent<RandomWaypoint>();
        Vector3 position = waypoint.position;

        if (!_capturedPositions.ContainsKey(mover))
        {
            _capturedPositions[mover] = new Dictionary <int, Vector3>();
        }

        _capturedPositions[mover][waypointIndex] = position;
        return(position);
    }
示例#8
0
        void OnOneWayFinished(object sender, EventArgs e)
        {
            WaypointsMover mover = sender as WaypointsMover;

            mover.OneWayFinished -= OnOneWayFinished;

            ParticleSystem explosion = Instantiate(ExplosionPrefab);

            explosion.transform.position = mover.transform.position;
            Destroy(explosion.gameObject, explosion.duration);

            mover.GetComponent <SpriteRenderer>().enabled = false;
            mover.GetComponentInChildren <ParticleSystem>().Stop();
            Destroy(mover.gameObject, 2f);
        }
示例#9
0
    public void StartNextPart(WaypointsMover mover, int fromInd, int toInd, bool isForwardDirection)
    {
        Vector3 toPosition = CapturePosition(mover, toInd);

        //if (IsCurved)
        {
            Vector3 handle1 = isForwardDirection ? GetHandle1(mover, fromInd) : GetHandle2(mover, fromInd);
            Vector3 handle2 = isForwardDirection ? GetHandle2(mover, toInd) : GetHandle1(mover, toInd);
            _moversParts[mover] = BezierApproximation.GetLines(_capturedPositions[mover][fromInd], handle1, toPosition, handle2, LinesCount);
        }
        //			else
        //			{
        //				_moversParts[mover] = new List<Vector3> {_capturedPositions[mover][fromInd], toPosition};
        //			}

        ClearDestroyedMovers();
    }
示例#10
0
 void Start()
 {
     arrow = FindObjectOfType <WaypointsMover>();
 }
示例#11
0
	public Vector3 CapturePosition(WaypointsMover mover, int waypointIndex)
	{
		Transform waypoint = Waypoints[waypointIndex];
		//RandomWaypoint randomWaypoint = waypoint.GetComponent<RandomWaypoint>();
		Vector3 position = waypoint.position;
		if (!_capturedPositions.ContainsKey(mover))
			_capturedPositions[mover] = new Dictionary<int, Vector3>();
		
		_capturedPositions[mover][waypointIndex] = position;
		return position;
	}
示例#12
0
	public float GetLength(WaypointsMover mover, int fromInd, int toInd, bool isForwardDirection)
	{
		//if (IsCurved)
		{
			Vector3 handle1 = isForwardDirection ? GetHandle1(mover, fromInd) : GetHandle2(mover, fromInd);
			Vector3 handle2 = isForwardDirection ? GetHandle2(mover, toInd) : GetHandle1(mover, toInd);
			return BezierApproximation.GetLength(_capturedPositions[mover][fromInd], handle1, _capturedPositions[mover][toInd], handle2, LinesCount);
		}
		//			else
		//			{
		//				return Vector3.Distance(_capturedPositions[mover][fromInd], _capturedPositions[mover][toInd]);
		//			}
	}
示例#13
0
	public void StartNextPart(WaypointsMover mover, int fromInd, int toInd, bool isForwardDirection)
	{
		Vector3 toPosition = CapturePosition(mover, toInd);
		//if (IsCurved)
		{
			Vector3 handle1 = isForwardDirection ? GetHandle1(mover, fromInd) : GetHandle2(mover, fromInd);
			Vector3 handle2 = isForwardDirection ? GetHandle2(mover, toInd) : GetHandle1(mover, toInd);
			_moversParts[mover] = BezierApproximation.GetLines(_capturedPositions[mover][fromInd], handle1, toPosition, handle2, LinesCount);
		}
		//			else
		//			{
		//				_moversParts[mover] = new List<Vector3> {_capturedPositions[mover][fromInd], toPosition};
		//			}
		
		ClearDestroyedMovers();
	}
示例#14
0
	public Vector3 GetPoint(WaypointsMover mover, float time)
	{
		//if (IsCurved)
		{
			float fullLength = BezierApproximation.GetLength(_moversParts[mover]);
			float remainedLength = fullLength*(time - 0.001f);
			for (int i = 0; i < _moversParts[mover].Count - 1; i++)
			{
				Vector3 point1 = _moversParts[mover][i];
				Vector3 point2 = _moversParts[mover][i + 1];
				float lineLength = Vector3.Distance(point1, point2);
				if (lineLength < remainedLength)
				{
					remainedLength -= lineLength;
				}
				else
				{
					return point1 + (point2 - point1).normalized*remainedLength;
				}
			}
			throw new Exception("Get point error for time:" + time + ", remainedLength: " + remainedLength);
		}
		//			else
		//			{
		//				Vector3 point1 = _moversParts[mover][0];
		//				Vector3 point2 = _moversParts[mover][1];
		//				float fullLength = Vector3.Distance(point1, point2);
		//				float remainedLength = fullLength*time;
		//				return point1 + (point2 - point1).normalized * remainedLength;
		//			}
	}
示例#15
0
	private Vector3 GetHandle2(WaypointsMover mover, int ind)
	{
		Vector3 dPos = _capturedPositions[mover][ind] - Waypoints[ind].position;
		return GetHandle2(ind) + dPos;
	}
示例#16
0
    private Vector3 GetHandle2(WaypointsMover mover, int ind)
    {
        Vector3 dPos = _capturedPositions[mover][ind] - Waypoints[ind].position;

        return(GetHandle2(ind) + dPos);
    }