This commit is contained in:
CortexCore
2024-11-16 16:00:16 +08:00
parent 99cf181bbe
commit 99253854e8
284 changed files with 112566 additions and 21 deletions

View File

@@ -0,0 +1,140 @@
//
//AutoBlink.cs
//オート目パチスクリプト
//2014/06/23 N.Kobayashi
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class AutoBlink : MonoBehaviour
{
public bool isActive = true; //オート目パチ有効
public SkinnedMeshRenderer ref_SMR_EYE_DEF; //EYE_DEFへの参照
public SkinnedMeshRenderer ref_SMR_EL_DEF; //EL_DEFへの参照
public float ratio_Close = 85.0f; //閉じ目ブレンドシェイプ比率
public float ratio_HalfClose = 20.0f; //半閉じ目ブレンドシェイプ比率
[HideInInspector]
public float
ratio_Open = 0.0f;
private bool timerStarted = false; //タイマースタート管理用
private bool isBlink = false; //目パチ管理用
public float timeBlink = 0.4f; //目パチの時間
private float timeRemining = 0.0f; //タイマー残り時間
public float threshold = 0.3f; // ランダム判定の閾値
public float interval = 3.0f; // ランダム判定のインターバル
enum Status
{
Close,
HalfClose,
Open //目パチの状態
}
private Status eyeStatus; //現在の目パチステータス
void Awake ()
{
//ref_SMR_EYE_DEF = GameObject.Find("EYE_DEF").GetComponent<SkinnedMeshRenderer>();
//ref_SMR_EL_DEF = GameObject.Find("EL_DEF").GetComponent<SkinnedMeshRenderer>();
}
// Use this for initialization
void Start ()
{
ResetTimer ();
// ランダム判定用関数をスタートする
StartCoroutine ("RandomChange");
}
//タイマーリセット
void ResetTimer ()
{
timeRemining = timeBlink;
timerStarted = false;
}
// Update is called once per frame
void Update ()
{
if (!timerStarted) {
eyeStatus = Status.Close;
timerStarted = true;
}
if (timerStarted) {
timeRemining -= Time.deltaTime;
if (timeRemining <= 0.0f) {
eyeStatus = Status.Open;
ResetTimer ();
} else if (timeRemining <= timeBlink * 0.3f) {
eyeStatus = Status.HalfClose;
}
}
}
void LateUpdate ()
{
if (isActive) {
if (isBlink) {
switch (eyeStatus) {
case Status.Close:
SetCloseEyes ();
break;
case Status.HalfClose:
SetHalfCloseEyes ();
break;
case Status.Open:
SetOpenEyes ();
isBlink = false;
break;
}
//Debug.Log(eyeStatus);
}
}
}
void SetCloseEyes ()
{
ref_SMR_EYE_DEF.SetBlendShapeWeight (6, ratio_Close);
ref_SMR_EL_DEF.SetBlendShapeWeight (6, ratio_Close);
}
void SetHalfCloseEyes ()
{
ref_SMR_EYE_DEF.SetBlendShapeWeight (6, ratio_HalfClose);
ref_SMR_EL_DEF.SetBlendShapeWeight (6, ratio_HalfClose);
}
void SetOpenEyes ()
{
ref_SMR_EYE_DEF.SetBlendShapeWeight (6, ratio_Open);
ref_SMR_EL_DEF.SetBlendShapeWeight (6, ratio_Open);
}
// ランダム判定用関数
IEnumerator RandomChange ()
{
// 無限ループ開始
while (true) {
//ランダム判定用シード発生
float _seed = Random.Range (0.0f, 1.0f);
if (!isBlink) {
if (_seed > threshold) {
isBlink = true;
}
}
// 次の判定までインターバルを置く
yield return new WaitForSeconds (interval);
}
}
}
}

View File

@@ -0,0 +1,144 @@
//
//AutoBlinkforSD.cs
//SDユニティちゃん用オート目パチスクリプト
//2014/12/10 N.Kobayashi
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class AutoBlinkforSD : MonoBehaviour
{
public bool isActive = true; //オート目パチ有効
public SkinnedMeshRenderer ref_face; //_faceへの参照
public float ratio_Close = 85.0f; //閉じ目ブレンドシェイプ比率
public float ratio_HalfClose = 20.0f; //半閉じ目ブレンドシェイプ比率
public int index_EYE_blk = 0; //目パチ用モーフのindex
public int index_EYE_sml = 1; //目パチさせたくないモーフのindex
public int index_EYE_dmg = 15; //目パチさせたくないモーフのindex
[HideInInspector]
public float
ratio_Open = 0.0f;
private bool timerStarted = false; //タイマースタート管理用
private bool isBlink = false; //目パチ管理用
public float timeBlink = 0.4f; //目パチの時間
private float timeRemining = 0.0f; //タイマー残り時間
public float threshold = 0.3f; // ランダム判定の閾値
public float interval = 3.0f; // ランダム判定のインターバル
enum Status
{
Close,
HalfClose,
Open //目パチの状態
}
private Status eyeStatus; //現在の目パチステータス
void Awake ()
{
//ref_SMR_EYE_DEF = GameObject.Find("EYE_DEF").GetComponent<SkinnedMeshRenderer>();
//ref_SMR_EL_DEF = GameObject.Find("EL_DEF").GetComponent<SkinnedMeshRenderer>();
}
// Use this for initialization
void Start ()
{
ResetTimer ();
// ランダム判定用関数をスタートする
StartCoroutine ("RandomChange");
}
//タイマーリセット
void ResetTimer ()
{
timeRemining = timeBlink;
timerStarted = false;
}
// Update is called once per frame
void Update ()
{
if (!timerStarted) {
eyeStatus = Status.Close;
timerStarted = true;
}
if (timerStarted) {
timeRemining -= Time.deltaTime;
if (timeRemining <= 0.0f) {
eyeStatus = Status.Open;
ResetTimer ();
} else if (timeRemining <= timeBlink * 0.3f) {
eyeStatus = Status.HalfClose;
}
}
}
void LateUpdate ()
{
if (isActive) {
if (isBlink) {
switch (eyeStatus) {
case Status.Close:
SetCloseEyes ();
break;
case Status.HalfClose:
SetHalfCloseEyes ();
break;
case Status.Open:
SetOpenEyes ();
isBlink = false;
break;
}
//Debug.Log(eyeStatus);
}
}
}
void SetCloseEyes ()
{
ref_face.SetBlendShapeWeight (index_EYE_blk, ratio_Close);
}
void SetHalfCloseEyes ()
{
ref_face.SetBlendShapeWeight (index_EYE_blk, ratio_HalfClose);
}
void SetOpenEyes ()
{
ref_face.SetBlendShapeWeight (index_EYE_blk, ratio_Open);
}
// ランダム判定用関数
IEnumerator RandomChange ()
{
// 無限ループ開始
while (true) {
//ランダム判定用シード発生
float _seed = Random.Range (0.0f, 1.0f);
if (!isBlink) {
if (_seed > threshold) {
//目パチさせたくないモーフの時だけ飛ばす.
if(ref_face.GetBlendShapeWeight(index_EYE_sml)==0.0f && ref_face.GetBlendShapeWeight(index_EYE_dmg)==0.0f){
isBlink = true;
}
}
}
// 次の判定までインターバルを置く
yield return new WaitForSeconds (interval);
}
}
}
}

View File

@@ -0,0 +1,176 @@
//CameraController.cs for UnityChan
//Original Script is here:
//TAK-EMI / CameraController.cs
//https://gist.github.com/TAK-EMI/d67a13b6f73bed32075d
//https://twitter.com/TAK_EMI
//
//Revised by N.Kobayashi 2014/5/15
//Change : To prevent rotation flips on XY plane, use Quaternion in cameraRotate()
//Change : Add the instrustion window
//Change : Add the operation for Mac
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
enum MouseButtonDown
{
MBD_LEFT = 0,
MBD_RIGHT,
MBD_MIDDLE,
};
public class CameraController : MonoBehaviour
{
[SerializeField]
private Vector3 focus = Vector3.zero;
[SerializeField]
private GameObject focusObj = null;
public bool showInstWindow = true;
private Vector3 oldPos;
void setupFocusObject(string name)
{
GameObject obj = this.focusObj = new GameObject(name);
obj.transform.position = this.focus;
obj.transform.LookAt(this.transform.position);
return;
}
void Start ()
{
if (this.focusObj == null)
this.setupFocusObject("CameraFocusObject");
Transform trans = this.transform;
transform.parent = this.focusObj.transform;
trans.LookAt(this.focus);
return;
}
void Update ()
{
this.mouseEvent();
return;
}
//Show Instrustion Window
void OnGUI()
{
if(showInstWindow){
GUI.Box(new Rect(Screen.width -210, Screen.height - 100, 200, 90), "Camera Operations");
GUI.Label(new Rect(Screen.width -200, Screen.height - 80, 200, 30),"RMB / Alt+LMB: Tumble");
GUI.Label(new Rect(Screen.width -200, Screen.height - 60, 200, 30),"MMB / Alt+Cmd+LMB: Track");
GUI.Label(new Rect(Screen.width -200, Screen.height - 40, 200, 30),"Wheel / 2 Fingers Swipe: Dolly");
}
}
void mouseEvent()
{
float delta = Input.GetAxis("Mouse ScrollWheel");
if (delta != 0.0f)
this.mouseWheelEvent(delta);
if (Input.GetMouseButtonDown((int)MouseButtonDown.MBD_LEFT) ||
Input.GetMouseButtonDown((int)MouseButtonDown.MBD_MIDDLE) ||
Input.GetMouseButtonDown((int)MouseButtonDown.MBD_RIGHT))
this.oldPos = Input.mousePosition;
this.mouseDragEvent(Input.mousePosition);
return;
}
void mouseDragEvent(Vector3 mousePos)
{
Vector3 diff = mousePos - oldPos;
if(Input.GetMouseButton((int)MouseButtonDown.MBD_LEFT))
{
//Operation for Mac : "Left Alt + Left Command + LMB Drag" is Track
if(Input.GetKey(KeyCode.LeftAlt) && Input.GetKey(KeyCode.LeftCommand))
{
if (diff.magnitude > Vector3.kEpsilon)
this.cameraTranslate(-diff / 100.0f);
}
//Operation for Mac : "Left Alt + LMB Drag" is Tumble
else if (Input.GetKey(KeyCode.LeftAlt))
{
if (diff.magnitude > Vector3.kEpsilon)
this.cameraRotate(new Vector3(diff.y, diff.x, 0.0f));
}
//Only "LMB Drag" is no action.
}
//Track
else if (Input.GetMouseButton((int)MouseButtonDown.MBD_MIDDLE))
{
if (diff.magnitude > Vector3.kEpsilon)
this.cameraTranslate(-diff / 100.0f);
}
//Tumble
else if (Input.GetMouseButton((int)MouseButtonDown.MBD_RIGHT))
{
if (diff.magnitude > Vector3.kEpsilon)
this.cameraRotate(new Vector3(diff.y, diff.x, 0.0f));
}
this.oldPos = mousePos;
return;
}
//Dolly
public void mouseWheelEvent(float delta)
{
Vector3 focusToPosition = this.transform.position - this.focus;
Vector3 post = focusToPosition * (1.0f + delta);
if (post.magnitude > 0.01)
this.transform.position = this.focus + post;
return;
}
void cameraTranslate(Vector3 vec)
{
Transform focusTrans = this.focusObj.transform;
vec.x *= -1;
focusTrans.Translate(Vector3.right * vec.x);
focusTrans.Translate(Vector3.up * vec.y);
this.focus = focusTrans.position;
return;
}
public void cameraRotate(Vector3 eulerAngle)
{
//Use Quaternion to prevent rotation flips on XY plane
Quaternion q = Quaternion.identity;
Transform focusTrans = this.focusObj.transform;
focusTrans.localEulerAngles = focusTrans.localEulerAngles + eulerAngle;
//Change this.transform.LookAt(this.focus) to q.SetLookRotation(this.focus)
if(this.focus != Vector3.zero){// for Error: "Look Rotation Viewing Vector Is Zero"
q.SetLookRotation (this.focus) ;
}
return;
}
}
}

View File

@@ -0,0 +1,77 @@
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class FaceUpdate : MonoBehaviour
{
public AnimationClip[] animations;
Animator anim;
public float delayWeight;
public bool isKeepFace = false;
public bool isGUI = true;
void Start ()
{
anim = GetComponent<Animator> ();
}
void OnGUI ()
{
if (isGUI)
{
GUILayout.Box("Face Update", GUILayout.Width(170), GUILayout.Height(25 * (animations.Length + 2)));
Rect screenRect = new Rect(10, 25, 150, 25 * (animations.Length + 1));
GUILayout.BeginArea(screenRect);
foreach (var animation in animations)
{
if (GUILayout.RepeatButton(animation.name))
{
anim.CrossFade(animation.name, 0);
}
}
isKeepFace = GUILayout.Toggle(isKeepFace, " Keep Face");
GUILayout.EndArea();
}
}
float current = 0;
void Update ()
{
if (Input.GetMouseButton (0)) {
current = 1;
} else if (!isKeepFace) {
current = Mathf.Lerp (current, 0, delayWeight);
}
anim.SetLayerWeight (1, current);
}
//アニメーションEvents側につける表情切り替え用イベントコール
public void OnCallChangeFace (string str)
{
int ichecked = 0;
foreach (var animation in animations) {
if (str == animation.name) {
ChangeFace (str);
break;
} else if (ichecked <= animations.Length) {
ichecked++;
} else {
//str指定が間違っている時にはデフォルトで
str = "default@unitychan";
ChangeFace (str);
}
}
}
void ChangeFace (string str)
{
isKeepFace = true;
current = 1;
anim.CrossFade (str, 0);
}
}
}

View File

@@ -0,0 +1,112 @@
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
//
// ↑↓キーでループアニメーションを切り替えるスクリプトランダム切り替え付きVer.3
// 2014/04/03 N.Kobayashi
//
// Require these components when using this script
[RequireComponent(typeof(Animator))]
public class IdleChanger : MonoBehaviour
{
private Animator anim; // Animatorへの参照
private AnimatorStateInfo currentState; // 現在のステート状態を保存する参照
private AnimatorStateInfo previousState; // ひとつ前のステート状態を保存する参照
public bool _random = false; // ランダム判定スタートスイッチ
public float _threshold = 0.5f; // ランダム判定の閾値
public float _interval = 10f; // ランダム判定のインターバル
//private float _seed = 0.0f; // ランダム判定用シード
public bool isGUI = true;
// Use this for initialization
void Start ()
{
// 各参照の初期化
anim = GetComponent<Animator> ();
currentState = anim.GetCurrentAnimatorStateInfo (0);
previousState = currentState;
// ランダム判定用関数をスタートする
StartCoroutine ("RandomChange");
}
// Update is called once per frame
void Update ()
{
// ↑キー/スペースが押されたら、ステートを次に送る処理
if (Input.GetKeyDown ("up") || Input.GetButton ("Jump")) {
// ブーリアンNextをtrueにする
anim.SetBool ("Next", true);
}
// ↓キーが押されたら、ステートを前に戻す処理
if (Input.GetKeyDown ("down")) {
// ブーリアンBackをtrueにする
anim.SetBool ("Back", true);
}
// "Next"フラグがtrueの時の処理
if (anim.GetBool ("Next")) {
// 現在のステートをチェックし、ステート名が違っていたらブーリアンをfalseに戻す
currentState = anim.GetCurrentAnimatorStateInfo (0);
if (previousState.fullPathHash != currentState.fullPathHash) {
anim.SetBool ("Next", false);
previousState = currentState;
}
}
// "Back"フラグがtrueの時の処理
if (anim.GetBool ("Back")) {
// 現在のステートをチェックし、ステート名が違っていたらブーリアンをfalseに戻す
currentState = anim.GetCurrentAnimatorStateInfo (0);
if (previousState.fullPathHash != currentState.fullPathHash) {
anim.SetBool ("Back", false);
previousState = currentState;
}
}
}
void OnGUI ()
{
if (isGUI)
{
GUI.Box(new Rect(Screen.width - 110, 10, 100, 90), "Change Motion");
if (GUI.Button(new Rect(Screen.width - 100, 40, 80, 20), "Next"))
anim.SetBool("Next", true);
if (GUI.Button(new Rect(Screen.width - 100, 70, 80, 20), "Back"))
anim.SetBool("Back", true);
}
}
// ランダム判定用関数
IEnumerator RandomChange ()
{
// 無限ループ開始
while (true) {
//ランダム判定スイッチオンの場合
if (_random) {
// ランダムシードを取り出し、その大きさによってフラグ設定をする
float _seed = Random.Range (0.0f, 1.0f);
if (_seed < _threshold) {
anim.SetBool ("Back", true);
} else if (_seed >= _threshold) {
anim.SetBool ("Next", true);
}
}
// 次の判定までインターバルを置く
yield return new WaitForSeconds (_interval);
}
}
}
}

View File

@@ -0,0 +1,92 @@
//
//RandomWind.cs for unity-chan!
//
//Original Script is here:
//ricopin / RandomWind.cs
//Rocket Jump : http://rocketjump.skr.jp/unity3d/109/
//https://twitter.com/ricopin416
//
//修正2014/12/20
//風の方向変化/重力影響を追加.
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class RandomWind : MonoBehaviour
{
private SpringBone[] springBones;
public bool isWindActive = false;
private bool isMinus = false; //風方向反転用.
public float threshold = 0.5f; // ランダム判定の閾値.
public float interval = 5.0f; // ランダム判定のインターバル.
public float windPower = 1.0f; //風の強さ.
public float gravity = 0.98f; //重力の強さ.
public bool isGUI = true;
// Use this for initialization
void Start ()
{
springBones = GetComponent<SpringManager> ().springBones;
StartCoroutine ("RandomChange");
}
// Update is called once per frame
void Update ()
{
Vector3 force = Vector3.zero;
if (isWindActive) {
if(isMinus){
force = new Vector3 (Mathf.PerlinNoise (Time.time, 0.0f) * windPower * -0.001f , gravity * -0.001f , 0);
}else{
force = new Vector3 (Mathf.PerlinNoise (Time.time, 0.0f) * windPower * 0.001f, gravity * -0.001f, 0);
}
for (int i = 0; i < springBones.Length; i++) {
springBones [i].springForce = force;
}
}
}
void OnGUI ()
{
if (isGUI)
{
Rect rect1 = new Rect(10, Screen.height - 40, 400, 30);
isWindActive = GUI.Toggle(rect1, isWindActive, "Random Wind");
}
}
// ランダム判定用関数.
IEnumerator RandomChange ()
{
// 無限ループ開始.
while (true) {
//ランダム判定用シード発生.
float _seed = Random.Range (0.0f, 1.0f);
if (_seed > threshold) {
//_seedがthreshold以上の時、符号を反転する.
isMinus = true;
}else{
isMinus = false;
}
// 次の判定までインターバルを置く.
yield return new WaitForSeconds (interval);
}
}
}
}

View File

@@ -0,0 +1,41 @@
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class RefleshProbe : MonoBehaviour {
bool isReflesh = false;
bool isButtonActive = true;
public ReflectionProbe probeComponent;
private int renderID;
// Update is called once per frame
void Update ()
{
if (isReflesh){
renderID = probeComponent.RenderProbe();
//isButtonActive = false;
isReflesh = false;
}
if (probeComponent.IsFinishedRendering(renderID)){
isButtonActive = true;
}
}
void OnGUI ()
{
GUI.Box (new Rect (Screen.width - 110, Screen.height - 65, 100, 50), "ReflectionProbe");
if(isButtonActive){
if (GUI.Button (new Rect (Screen.width - 100, Screen.height - 40, 80, 20), "Reflesh")){
isReflesh = true;
isButtonActive = false;
}
}
}
}
}

View File

@@ -0,0 +1,47 @@
//
// QualitySettings/Shadows内のShadow Distance/Shadow Cascades/Cascade splitsをシーンから設定する.
//
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
[ExecuteInEditMode]
public class SetShadowQuality : MonoBehaviour {
public enum CascadeMode {
Zero = 0,
Two = 2,
Four = 4,
}
public ShadowProjection shadowProjection = ShadowProjection.CloseFit;
public float shadowDistance = 150.0f;
public CascadeMode cascadeMode = CascadeMode.Four;
public float twoCascadeSetting = 33.3f;
public Vector3 fourCascadeSetting = new Vector3(6.7f,13.3f,26.7f);
private Vector3 settingFor4Cascades;
// Use this for initialization
void Start () {
}
void Update()
{
settingFor4Cascades = new Vector3((fourCascadeSetting.x)/100f,
(fourCascadeSetting.x + fourCascadeSetting.y)/100f,
(fourCascadeSetting.x + fourCascadeSetting.y + fourCascadeSetting.z)/100f);
}
void LateUpdate () {
QualitySettings.shadowProjection = shadowProjection;
QualitySettings.shadowDistance = shadowDistance;
QualitySettings.shadowCascades = (int)cascadeMode;
QualitySettings.shadowCascade2Split = twoCascadeSetting/100f;
QualitySettings.shadowCascade4Split = settingFor4Cascades;
}
}
}

View File

@@ -0,0 +1,17 @@
//
// SetShadowResolution.cs
// シャドウマップにカスタムレゾリューションを設定するスクリプト.
// メインライトにアタッチすること.
//
using UnityEngine;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class SetShadowResolution : MonoBehaviour {
public int resolution;
void Update () {
GetComponent<Light>().shadowCustomResolution = resolution;
}
}
}

View File

@@ -0,0 +1,135 @@
//
//SpringBone.cs for unity-chan!
//
//Original Script is here:
//ricopin / SpringBone.cs
//Rocket Jump : http://rocketjump.skr.jp/unity3d/109/
//https://twitter.com/ricopin416
//
//Revised by N.Kobayashi 2014/06/20
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class SpringBone : MonoBehaviour
{
//次のボーン
public Transform child;
//ボーンの向き
public Vector3 boneAxis = new Vector3 (-1.0f, 0.0f, 0.0f);
public float radius = 0.05f;
//各SpringBoneに設定されているstiffnessForceとdragForceを使用するか
public bool isUseEachBoneForceSettings = false;
//バネが戻る力
public float stiffnessForce = 0.01f;
//力の減衰力
public float dragForce = 0.4f;
public Vector3 springForce = new Vector3 (0.0f, -0.0001f, 0.0f);
public SpringCollider[] colliders;
public bool debug = true;
//Kobayashi:Thredshold Starting to activate activeRatio
public float threshold = 0.01f;
private float springLength;
private Quaternion localRotation;
private Transform trs;
private Vector3 currTipPos;
private Vector3 prevTipPos;
//Kobayashi
private Transform org;
//Kobayashi:Reference for "SpringManager" component with unitychan
private SpringManager managerRef;
private void Awake ()
{
trs = transform;
localRotation = transform.localRotation;
//Kobayashi:Reference for "SpringManager" component with unitychan
// GameObject.Find("unitychan_dynamic").GetComponent<SpringManager>();
managerRef = GetParentSpringManager (transform);
}
private SpringManager GetParentSpringManager (Transform t)
{
var springManager = t.GetComponent<SpringManager> ();
if (springManager != null)
return springManager;
if (t.parent != null) {
return GetParentSpringManager (t.parent);
}
return null;
}
private void Start ()
{
springLength = Vector3.Distance (trs.position, child.position);
currTipPos = child.position;
prevTipPos = child.position;
}
public void UpdateSpring ()
{
//Kobayashi
org = trs;
//回転をリセット
trs.localRotation = Quaternion.identity * localRotation;
float sqrDt = Time.deltaTime * Time.deltaTime;
//stiffness
Vector3 force = trs.rotation * (boneAxis * stiffnessForce) / sqrDt;
//drag
force += (prevTipPos - currTipPos) * dragForce / sqrDt;
force += springForce / sqrDt;
//前フレームと値が同じにならないように
Vector3 temp = currTipPos;
//verlet
currTipPos = (currTipPos - prevTipPos) + currTipPos + (force * sqrDt);
//長さを元に戻す
currTipPos = ((currTipPos - trs.position).normalized * springLength) + trs.position;
//衝突判定
for (int i = 0; i < colliders.Length; i++) {
if (Vector3.Distance (currTipPos, colliders [i].transform.position) <= (radius + colliders [i].radius)) {
Vector3 normal = (currTipPos - colliders [i].transform.position).normalized;
currTipPos = colliders [i].transform.position + (normal * (radius + colliders [i].radius));
currTipPos = ((currTipPos - trs.position).normalized * springLength) + trs.position;
}
}
prevTipPos = temp;
//回転を適用;
Vector3 aimVector = trs.TransformDirection (boneAxis);
Quaternion aimRotation = Quaternion.FromToRotation (aimVector, currTipPos - trs.position);
//original
//trs.rotation = aimRotation * trs.rotation;
//Kobayahsi:Lerp with mixWeight
Quaternion secondaryRotation = aimRotation * trs.rotation;
trs.rotation = Quaternion.Lerp (org.rotation, secondaryRotation, managerRef.dynamicRatio);
}
private void OnDrawGizmos ()
{
if (debug) {
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere (currTipPos, radius);
}
}
}
}

View File

@@ -0,0 +1,25 @@
//
//SpringCollider for unity-chan!
//
//Original Script is here:
//ricopin / SpringCollider.cs
//Rocket Jump : http://rocketjump.skr.jp/unity3d/109/
//https://twitter.com/ricopin416
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class SpringCollider : MonoBehaviour
{
//半径
public float radius = 0.5f;
private void OnDrawGizmosSelected ()
{
Gizmos.color = Color.green;
Gizmos.DrawWireSphere (transform.position, radius);
}
}
}

View File

@@ -0,0 +1,86 @@
//
//SpingManager.cs for unity-chan!
//
//Original Script is here:
//ricopin / SpingManager.cs
//Rocket Jump : http://rocketjump.skr.jp/unity3d/109/
//https://twitter.com/ricopin416
//
//Revised by N.Kobayashi 2014/06/24
// Y.Ebata
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class SpringManager : MonoBehaviour
{
//Kobayashi
// DynamicRatio is paramater for activated level of dynamic animation
public float dynamicRatio = 1.0f;
//Ebata
public float stiffnessForce;
public AnimationCurve stiffnessCurve;
public float dragForce;
public AnimationCurve dragCurve;
public SpringBone[] springBones;
void Start ()
{
UpdateParameters ();
}
#if UNITY_EDITOR
void Update ()
{
//Kobayashi
if(dynamicRatio >= 1.0f)
dynamicRatio = 1.0f;
else if(dynamicRatio <= 0.0f)
dynamicRatio = 0.0f;
//Ebata
UpdateParameters();
}
#endif
private void LateUpdate ()
{
//Kobayashi
if (dynamicRatio != 0.0f) {
for (int i = 0; i < springBones.Length; i++) {
if (dynamicRatio > springBones [i].threshold) {
springBones [i].UpdateSpring ();
}
}
}
}
private void UpdateParameters ()
{
UpdateParameter ("stiffnessForce", stiffnessForce, stiffnessCurve);
UpdateParameter ("dragForce", dragForce, dragCurve);
}
private void UpdateParameter (string fieldName, float baseValue, AnimationCurve curve)
{
#if UNITY_EDITOR
var start = curve.keys [0].time;
var end = curve.keys [curve.length - 1].time;
//var step = (end - start) / (springBones.Length - 1);
var prop = springBones [0].GetType ().GetField (fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
for (int i = 0; i < springBones.Length; i++) {
//Kobayashi
if (!springBones [i].isUseEachBoneForceSettings) {
var scale = curve.Evaluate (start + (end - start) * i / (springBones.Length - 1));
prop.SetValue (springBones [i], baseValue * scale);
}
}
#endif
}
}
}

View File

@@ -0,0 +1,83 @@
//
// Unityちゃん用の三人称カメラ
//
// 2013/06/07 N.Kobyasahi
//
using UnityEngine;
using System.Collections;
namespace UnityEngine.Rendering.Toon.Universal.Samples
{
public class ThirdPersonCamera : MonoBehaviour
{
public float smooth = 3f; // カメラモーションのスムーズ化用変数
Transform standardPos; // the usual position for the camera, specified by a transform in the game
Transform frontPos; // Front Camera locater
Transform jumpPos; // Jump Camera locater
// スムーズに繋がない時(クイック切り替え)用のブーリアンフラグ
bool bQuickSwitch = false; //Change Camera Position Quickly
void Start ()
{
// 各参照の初期化
standardPos = GameObject.Find ("CamPos").transform;
if (GameObject.Find ("FrontPos"))
frontPos = GameObject.Find ("FrontPos").transform;
if (GameObject.Find ("JumpPos"))
jumpPos = GameObject.Find ("JumpPos").transform;
//カメラをスタートする
transform.position = standardPos.position;
transform.forward = standardPos.forward;
}
void FixedUpdate () // このカメラ切り替えはFixedUpdate()内でないと正常に動かない
{
if (Input.GetButton ("Fire1")) { // left Ctlr
// Change Front Camera
setCameraPositionFrontView ();
} else if (Input.GetButton ("Fire2")) { //Alt
// Change Jump Camera
setCameraPositionJumpView ();
} else {
// return the camera to standard position and direction
setCameraPositionNormalView ();
}
}
void setCameraPositionNormalView ()
{
if (bQuickSwitch == false) {
// the camera to standard position and direction
transform.position = Vector3.Lerp (transform.position, standardPos.position, Time.fixedDeltaTime * smooth);
transform.forward = Vector3.Lerp (transform.forward, standardPos.forward, Time.fixedDeltaTime * smooth);
} else {
// the camera to standard position and direction / Quick Change
transform.position = standardPos.position;
transform.forward = standardPos.forward;
bQuickSwitch = false;
}
}
void setCameraPositionFrontView ()
{
// Change Front Camera
bQuickSwitch = true;
transform.position = frontPos.position;
transform.forward = frontPos.forward;
}
void setCameraPositionJumpView ()
{
// Change Jump Camera
bQuickSwitch = false;
transform.position = Vector3.Lerp (transform.position, jumpPos.position, Time.fixedDeltaTime * smooth);
transform.forward = Vector3.Lerp (transform.forward, jumpPos.forward, Time.fixedDeltaTime * smooth);
}
}
}