Esempio n. 1
0
    public float CreateSpline(Transform[] nodes, bool drawLine, float drawDistance)
    {
        int nodesLength = nodes.Length + 1;

        float curveLength = 0.0f;

        chainKeys [0] = new SplineKeyframe(0, nodes [0].position);



        for (int i = 1; i < nodesLength - 1; i++)
        {
            curveLength  += Vector3.Distance(nodes [i].position, nodes [i - 1].position);
            chainKeys [i] = new SplineKeyframe(curveLength, nodes [i].position);
        }

        curveLength += Vector3.Distance(nodes [0].position, nodes [nodesLength - 2].position);
        chainKeys [nodesLength - 1] = new SplineKeyframe(curveLength, nodes [0].position);

        this.keys = chainKeys;

        this.Smooth();

        if (drawLine)
        {
            for (float d = 0; d < curveLength; d += drawDistance)
            {
                Debug.DrawLine(this.Evaluate(d), this.Evaluate(d + drawDistance), Color.red);
            }
        }
        return(curveLength);
    }
    public void CreateSpline(Transform[] nodes, bool smooth, bool close, bool drawLine, float drawDistance)
    {
        int   nodesLength = close? nodes.Length + 1: nodes.Length;
        float curveLength = 0.0f;

        SplineKeyframe[] chainKeys;

        if (this.keys == null || this.keys.Length != nodesLength)
        {
            chainKeys = new SplineKeyframe[nodesLength];
        }
        else
        {
            chainKeys = this.keys;
        }

        if (nodesLength > 0)
        {
            chainKeys[0] = new SplineKeyframe(0, nodes[0].position);
        }

        for (int i = 1; i < nodesLength - 1; i++)
        {
            curveLength += Vector3.Distance(nodes[i].position, nodes[i - 1].position);
            chainKeys[i] = new SplineKeyframe(curveLength, nodes[i].position);
        }

        if (close && nodesLength > 2)
        {
            curveLength += Vector3.Distance(nodes[0].position, nodes[nodesLength - 2].position);
            chainKeys[nodesLength - 1] = new SplineKeyframe(curveLength, nodes[0].position);
        }
        else
        {
            curveLength += Vector3.Distance(nodes[nodesLength - 2].position, nodes[nodesLength - 1].position);
            chainKeys[nodesLength - 1] = new SplineKeyframe(curveLength, nodes[nodesLength - 1].position);
        }

        this.keys = chainKeys;

        if (smooth)
        {
            this.Smooth();
        }

        if (drawLine)
        {
            for (float d = 0; d < curveLength; d += drawDistance)
            {
                Debug.DrawLine(this.Evaluate(d), this.Evaluate(d + drawDistance), Color.red);
            }
        }

        _splineLength = curveLength;
    }
Esempio n. 3
0
 public void AddKey(SplineKeyframe valueKeyframe)
 {
     _curveX.AddKey(valueKeyframe.time, valueKeyframe.valueX);
     _curveY.AddKey(valueKeyframe.time, valueKeyframe.valueY);
     _curveZ.AddKey(valueKeyframe.time, valueKeyframe.valueZ);
 }
Esempio n. 4
0
	public void AddKey (SplineKeyframe valueKeyframe)
	{
		_curveX.AddKey(valueKeyframe.time, valueKeyframe.valueX);
		_curveY.AddKey(valueKeyframe.time, valueKeyframe.valueY);
		_curveZ.AddKey(valueKeyframe.time, valueKeyframe.valueZ);
	}
Esempio n. 5
0
	public AnimationSpline (WrapMode wrapMode, SplineKeyframe[] keys)
	{
		CreateSpline (wrapMode);
		SetKeys(keys);
	}
Esempio n. 6
0
	public void CreateSpline (Transform[] nodes, bool smooth, bool close, bool drawLine, float drawDistance)
	{
		int nodesLength = close? nodes.Length + 1: nodes.Length;
		float curveLength = 0.0f;
		SplineKeyframe[] chainKeys;
		
		if(this.keys == null || this.keys.Length != nodesLength)
		chainKeys = new SplineKeyframe[nodesLength];
		else 
		chainKeys = this.keys;
		
		if(nodesLength > 0)
		chainKeys[0] = new SplineKeyframe(0, nodes[0].position);
		
		
		
		for(int i = 1; i < nodesLength - 1; i++)
		{
			curveLength += Vector3.Distance(nodes[i].position, nodes[i - 1].position);
			chainKeys[i] = new SplineKeyframe(curveLength, nodes[i].position);
		}
		
		if(close && nodesLength > 2)
		{
		curveLength += Vector3.Distance(nodes[0].position, nodes[nodesLength - 2].position);
		chainKeys[nodesLength - 1] = new SplineKeyframe(curveLength, nodes[0].position);
		}
		else
		{
		curveLength += Vector3.Distance(nodes[nodesLength - 2].position, nodes[nodesLength - 1].position);
		chainKeys[nodesLength - 1] = new SplineKeyframe(curveLength, nodes[nodesLength - 1].position);
		}
		this.keys = chainKeys;

		if(smooth)
		this.Smooth();
		
		if(drawLine)
		{
			/*for (float d = 0; d < curveLength; d+= drawDistance) 
			{
				Debug.DrawLine(this.Evaluate(d), this.Evaluate(d + drawDistance), Color.red);
			}*/
		}
		_splineLength = curveLength;
	}
Esempio n. 7
0
	private void SetKeys (SplineKeyframe[] valueKeyframe )
	{
		this._keys = valueKeyframe;
		int _length = length;
		Keyframe[] KeyframeX = new Keyframe[_length];
		Keyframe[] KeyframeY = new Keyframe[_length];
		Keyframe[] KeyframeZ = new Keyframe[_length];
		for(int i = 0; i < _length; i++)
		{
			KeyframeX[i] = new Keyframe(this._keys[i].time, this._keys[i].valueX, this._keys[i].inTangent, this._keys[i].outTangent);
			KeyframeX[i].tangentMode = this._keys[i].tangentMode;
			KeyframeY[i] = new Keyframe(this._keys[i].time, this._keys[i].valueY, this._keys[i].inTangent, this._keys[i].outTangent);
			KeyframeY[i].tangentMode = this._keys[i].tangentMode;
			KeyframeZ[i] = new Keyframe(this._keys[i].time, this._keys[i].valueZ, this._keys[i].inTangent, this._keys[i].outTangent);
			KeyframeZ[i].tangentMode = this._keys[i].tangentMode;
		}
		_curveX.keys = KeyframeX;
		_curveY.keys = KeyframeY;
		_curveZ.keys = KeyframeZ;
	}