|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
//Author:ZCG
|
|
|
|
|
//CreatTime:12/1/2017
|
|
|
|
|
/// <summary>
|
|
|
|
|
///<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>ٱ۵ȣ<EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ObjStretch: MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
initY = objUp[0].localPosition.y;//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ڸ߶<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
InputControl();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void Init()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void InputControl()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
|
|
|
|
|
Stretch();
|
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.S))
|
|
|
|
|
Shorten();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹؼ<EFBFBD><EFBFBD>ֻ<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected Transform[] GetObj(string keyword)
|
|
|
|
|
{
|
|
|
|
|
List<Transform> childs = new List<Transform>();
|
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var child = transform.GetChild(i);
|
|
|
|
|
if (child.name.Contains(keyword))
|
|
|
|
|
{
|
|
|
|
|
childs.Add(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return childs.ToArray();
|
|
|
|
|
}
|
|
|
|
|
[Tooltip("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ڣ<EFBFBD>")]
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ڣ<EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Transform[] objUp;
|
|
|
|
|
private Vector3 speedVec = new Vector3(0, 1, 0);
|
|
|
|
|
[Tooltip("ÿһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
|
|
|
|
|
public float nodeLength;
|
|
|
|
|
[Tooltip("<EFBFBD>ٶ<EFBFBD>")]
|
|
|
|
|
public float speed;
|
|
|
|
|
private float initY;
|
|
|
|
|
//<EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
private int index = 0;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void Stretch()
|
|
|
|
|
{
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD>ݸ߶ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵڼ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (objUp[index].localPosition.y < (index+1) * nodeLength)
|
|
|
|
|
{
|
|
|
|
|
for (int i = index; i < objUp.Length; i++)//<EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
|
|
|
|
objUp[i].localPosition += speed * Time.deltaTime * speedVec;
|
|
|
|
|
}
|
|
|
|
|
else if(index < objUp.Length - 1)
|
|
|
|
|
{
|
|
|
|
|
index++;
|
|
|
|
|
Stretch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <EFBFBD>ջ<EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void Shorten()
|
|
|
|
|
{
|
|
|
|
|
//<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD>չ
|
|
|
|
|
if (objUp[index].localPosition.y > initY)
|
|
|
|
|
{
|
|
|
|
|
for (int i = index; i < objUp.Length; i++)//<EFBFBD>ƶ<EFBFBD>ÿһ<EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
objUp[i].localPosition -= speed * Time.deltaTime * speedVec;
|
|
|
|
|
}
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD>꿪ʼ<EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
if (index > 0 && objUp[index].localPosition.y <= objUp[index - 1].localPosition.y)
|
|
|
|
|
{
|
|
|
|
|
index--;
|
|
|
|
|
Shorten();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|