Flatkit 추가 및 설정
This commit is contained in:
9
Assets/FlatKit/Demos/Common/Scripts/Motion/Editor.meta
Normal file
9
Assets/FlatKit/Demos/Common/Scripts/Motion/Editor.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f2b8436fbb9bd045ab8bdccf8490ae1
|
||||
folderAsset: yes
|
||||
timeCreated: 1452853741
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Dustyroom {
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(LinearMotion))]
|
||||
public class LinearMotionEditor : UnityEditor.Editor {
|
||||
private SerializedProperty _translationMode;
|
||||
private SerializedProperty _translationVector;
|
||||
private SerializedProperty _translationSpeed;
|
||||
private SerializedProperty _translationAcceleration;
|
||||
|
||||
private SerializedProperty _rotationMode;
|
||||
private SerializedProperty _rotationAxis;
|
||||
private SerializedProperty _rotationSpeed;
|
||||
private SerializedProperty _rotationAcceleration;
|
||||
|
||||
private SerializedProperty _useLocalCoordinate;
|
||||
|
||||
private static readonly GUIContent TextRotation = new GUIContent("Rotation");
|
||||
private static readonly GUIContent TextAcceleration = new GUIContent("Acceleration");
|
||||
private static readonly GUIContent TextTranslation = new GUIContent("Translation");
|
||||
private static readonly GUIContent TextSpeed = new GUIContent("Speed");
|
||||
private static readonly GUIContent TextVector = new GUIContent("Vector");
|
||||
private static readonly GUIContent TextLocalCoordinate = new GUIContent("Local Coordinate");
|
||||
|
||||
void OnEnable() {
|
||||
_translationMode = serializedObject.FindProperty("translationMode");
|
||||
_translationVector = serializedObject.FindProperty("translationVector");
|
||||
_translationSpeed = serializedObject.FindProperty("translationSpeed");
|
||||
_translationAcceleration = serializedObject.FindProperty("translationAcceleration");
|
||||
|
||||
_rotationMode = serializedObject.FindProperty("rotationMode");
|
||||
_rotationAxis = serializedObject.FindProperty("rotationAxis");
|
||||
_rotationSpeed = serializedObject.FindProperty("rotationSpeed");
|
||||
_rotationAcceleration = serializedObject.FindProperty("rotationAcceleration");
|
||||
|
||||
_useLocalCoordinate = serializedObject.FindProperty("useLocalCoordinate");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.PropertyField(_translationMode, TextTranslation);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
if (_translationMode.hasMultipleDifferentValues ||
|
||||
_translationMode.enumValueIndex == (int) LinearMotion.TranslationMode.Vector) {
|
||||
EditorGUILayout.PropertyField(_translationVector, TextVector);
|
||||
}
|
||||
|
||||
if (_translationMode.hasMultipleDifferentValues ||
|
||||
_translationMode.enumValueIndex != 0) {
|
||||
EditorGUILayout.PropertyField(_translationSpeed, TextSpeed);
|
||||
EditorGUILayout.PropertyField(_translationAcceleration, TextAcceleration);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.PropertyField(_rotationMode, TextRotation);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
if (_rotationMode.hasMultipleDifferentValues ||
|
||||
_rotationMode.enumValueIndex == (int) LinearMotion.RotationMode.Vector) {
|
||||
EditorGUILayout.PropertyField(_rotationAxis, TextVector);
|
||||
}
|
||||
|
||||
if (_rotationMode.hasMultipleDifferentValues ||
|
||||
_rotationMode.enumValueIndex != 0) {
|
||||
EditorGUILayout.PropertyField(_rotationSpeed, TextSpeed);
|
||||
EditorGUILayout.PropertyField(_rotationAcceleration, TextAcceleration);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.PropertyField(_useLocalCoordinate, TextLocalCoordinate);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fc5aa7ff4bc94e60a8415d6b0755c76
|
||||
timeCreated: 1452496761
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
96
Assets/FlatKit/Demos/Common/Scripts/Motion/LinearMotion.cs
Normal file
96
Assets/FlatKit/Demos/Common/Scripts/Motion/LinearMotion.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Dustyroom {
|
||||
public class LinearMotion : MonoBehaviour {
|
||||
public enum TranslationMode {
|
||||
Off,
|
||||
XAxis,
|
||||
YAxis,
|
||||
ZAxis,
|
||||
Vector
|
||||
}
|
||||
|
||||
public enum RotationMode {
|
||||
Off,
|
||||
XAxis,
|
||||
YAxis,
|
||||
ZAxis,
|
||||
Vector
|
||||
}
|
||||
|
||||
public TranslationMode translationMode = TranslationMode.Off;
|
||||
public Vector3 translationVector = Vector3.forward;
|
||||
public float translationSpeed = 1.0f;
|
||||
public RotationMode rotationMode = RotationMode.Off;
|
||||
public Vector3 rotationAxis = Vector3.up;
|
||||
public float rotationSpeed = 50.0f;
|
||||
public bool useLocalCoordinate = true;
|
||||
public float translationAcceleration = 0f;
|
||||
public float rotationAcceleration = 0f;
|
||||
|
||||
private Vector3 TranslationVector {
|
||||
get {
|
||||
switch (translationMode) {
|
||||
case TranslationMode.XAxis: return Vector3.right;
|
||||
case TranslationMode.YAxis: return Vector3.up;
|
||||
case TranslationMode.ZAxis: return Vector3.forward;
|
||||
case TranslationMode.Vector: return translationVector;
|
||||
case TranslationMode.Off:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 RotationVector {
|
||||
get {
|
||||
switch (rotationMode) {
|
||||
case RotationMode.XAxis: return Vector3.right;
|
||||
case RotationMode.YAxis: return Vector3.up;
|
||||
case RotationMode.ZAxis: return Vector3.forward;
|
||||
case RotationMode.Vector: return rotationAxis;
|
||||
case RotationMode.Off:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (translationMode != TranslationMode.Off) {
|
||||
Vector3 positionDelta = TranslationVector * translationSpeed * Time.deltaTime;
|
||||
|
||||
if (useLocalCoordinate) {
|
||||
transform.localPosition += positionDelta;
|
||||
}
|
||||
else {
|
||||
transform.position += positionDelta;
|
||||
}
|
||||
}
|
||||
|
||||
if (rotationMode == RotationMode.Off) return;
|
||||
|
||||
Quaternion rotationDelta = Quaternion.AngleAxis(
|
||||
rotationSpeed * Time.deltaTime, RotationVector);
|
||||
if (useLocalCoordinate) {
|
||||
transform.localRotation = rotationDelta * transform.localRotation;
|
||||
}
|
||||
else {
|
||||
transform.rotation = rotationDelta * transform.rotation;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate() {
|
||||
translationSpeed += translationAcceleration;
|
||||
rotationSpeed += rotationAcceleration;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3db4c4a72731246b2b1ad1e73178c04e
|
||||
timeCreated: 1452494131
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
141
Assets/FlatKit/Demos/Common/Scripts/Motion/OrbitMotion.cs
Normal file
141
Assets/FlatKit/Demos/Common/Scripts/Motion/OrbitMotion.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Dustyroom {
|
||||
public class OrbitMotion : MonoBehaviour {
|
||||
public enum TargetMode {
|
||||
Transform,
|
||||
Position
|
||||
}
|
||||
|
||||
public TargetMode targetMode = TargetMode.Position;
|
||||
public Transform targetTransform;
|
||||
public bool followTargetTransform = true;
|
||||
public Vector3 targetOffset = Vector3.zero;
|
||||
public Vector3 targetPosition;
|
||||
|
||||
[Space] public float distanceHorizontal = 60.0f;
|
||||
public float distanceVertical = 60.0f;
|
||||
public float xSpeed = 120.0f;
|
||||
public float ySpeed = 120.0f;
|
||||
public float damping = 3f;
|
||||
|
||||
[Space] public bool clampAngle = false;
|
||||
public float yMinLimit = -20f;
|
||||
public float yMaxLimit = 80f;
|
||||
|
||||
[Space] public bool allowZoom = false;
|
||||
public float distanceMin = .5f;
|
||||
public float distanceMax = 15f;
|
||||
|
||||
float _x = 0.0f;
|
||||
float _y = 0.0f;
|
||||
|
||||
[Space] public bool autoMovement = false;
|
||||
public float autoSpeedX = 0.2f;
|
||||
public float autoSpeedY = 0.1f;
|
||||
public float autoSpeedDistance = -0.1f;
|
||||
|
||||
[Space] public bool interactive = true;
|
||||
|
||||
private float _lastMoveTime;
|
||||
[HideInInspector] public float timeSinceLastMove;
|
||||
|
||||
void Start() {
|
||||
Vector3 angles = transform.eulerAngles;
|
||||
_x = angles.y;
|
||||
_y = angles.x;
|
||||
|
||||
// Make the rigid body not change rotation
|
||||
Rigidbody rigidbody = GetComponent<Rigidbody>();
|
||||
if (rigidbody != null) {
|
||||
rigidbody.freezeRotation = true;
|
||||
}
|
||||
|
||||
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
|
||||
xSpeed *= 0.2f;
|
||||
ySpeed *= 0.2f;
|
||||
#endif
|
||||
|
||||
if (targetMode == TargetMode.Transform) {
|
||||
if (targetTransform != null) {
|
||||
targetPosition = targetTransform.position + targetOffset;
|
||||
}
|
||||
else {
|
||||
Debug.LogWarning("Reference transform is not set.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (targetMode == TargetMode.Transform && followTargetTransform) {
|
||||
if (targetTransform != null) {
|
||||
targetPosition = targetTransform.position + targetOffset;
|
||||
}
|
||||
else {
|
||||
Debug.LogWarning("Reference transform is not set.");
|
||||
}
|
||||
}
|
||||
|
||||
//*
|
||||
bool isCameraMoving = false;
|
||||
#if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
|
||||
isCameraMoving = Input.GetTouch(0).deltaPosition.sqrMagnitude > 0f;
|
||||
#else
|
||||
isCameraMoving = Mathf.Abs(Input.GetAxis("Mouse X")) + Mathf.Abs(Input.GetAxis("Mouse Y")) > 0f;
|
||||
#endif
|
||||
if (isCameraMoving) {
|
||||
_lastMoveTime = Time.time;
|
||||
}
|
||||
|
||||
timeSinceLastMove = Time.time - _lastMoveTime;
|
||||
//*/
|
||||
|
||||
if (interactive && Input.GetMouseButton(0)) {
|
||||
#if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
|
||||
_x += Input.GetTouch(0).deltaPosition.x * xSpeed * 40f * 0.02f;
|
||||
_y -= Input.GetTouch(0).deltaPosition.y * ySpeed * 40f * 0.02f;
|
||||
#else
|
||||
_x += Input.GetAxis("Mouse X") * xSpeed * 40f * 0.02f;
|
||||
_y -= Input.GetAxis("Mouse Y") * ySpeed * 40f * 0.02f;
|
||||
#endif
|
||||
}
|
||||
else if (autoMovement) {
|
||||
_x += autoSpeedX * 40f * Time.deltaTime * 10f;
|
||||
_y -= autoSpeedY * 40f * Time.deltaTime * 10f;
|
||||
distanceHorizontal += autoSpeedDistance;
|
||||
}
|
||||
|
||||
if (clampAngle) {
|
||||
_y = ClampAngle(_y, yMinLimit, yMaxLimit);
|
||||
}
|
||||
|
||||
Quaternion rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(_y, _x, 0),
|
||||
Time.deltaTime * damping);
|
||||
|
||||
if (allowZoom) {
|
||||
distanceHorizontal = Mathf.Clamp(
|
||||
distanceHorizontal - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax);
|
||||
}
|
||||
|
||||
float rotationX = rotation.eulerAngles.x;
|
||||
if (rotationX > 90f) {
|
||||
rotationX -= 360f;
|
||||
}
|
||||
|
||||
float usedDistance = Mathf.Lerp(distanceHorizontal, distanceVertical, Mathf.Abs(rotationX / 90f));
|
||||
Vector3 negDistance = new Vector3(0.0f, 0.0f, -usedDistance);
|
||||
Vector3 position = rotation * negDistance + targetPosition;
|
||||
|
||||
transform.rotation = rotation;
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
private static float ClampAngle(float angle, float min, float max) {
|
||||
if (angle < -360f)
|
||||
angle += 360f;
|
||||
if (angle > 360f)
|
||||
angle -= 360f;
|
||||
return Mathf.Clamp(angle, min, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afc635dbcae404d4f8e03f5219dc8099
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user