Init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ťԤ<C5A5><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>UI<55>ᴩ<E1B4A9><CDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public class BtnPreHandler3 : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
ModelController.CanControl = false;
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
Invoke("EnableClick", 0.2f);
|
||||
}
|
||||
|
||||
void EnableClick()
|
||||
{
|
||||
if (!ModelController.CanControl)
|
||||
{
|
||||
ModelController.CanControl = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa321e809939e1149bfa7308e79fb85e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraTargetMove : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
public Vector3 pivotOffset = Vector3.zero;
|
||||
public float distance = 10.0f;
|
||||
public float minDistance = 2f;
|
||||
public float maxDistance = 15f;
|
||||
public float zoomSpeed = 1f;
|
||||
public float xSpeed = 250.0f;
|
||||
public float ySpeed = 250.0f;
|
||||
public bool allowYTilt = true;
|
||||
public float yMinLimit = -90f;
|
||||
public float yMaxLimit = 90f;
|
||||
private float x = 0.0f;
|
||||
private float y = 0.0f;
|
||||
private float targetX = 0f;
|
||||
private float targetY = 0f;
|
||||
public float targetDistance = 0f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var angles = transform.eulerAngles;
|
||||
targetX = x = angles.x;
|
||||
targetY = y = ClampAngle(angles.y, yMinLimit, yMaxLimit);
|
||||
targetDistance = distance;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!target) return;
|
||||
var scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (scroll > 0.0f) targetDistance -= zoomSpeed;
|
||||
else if (scroll < 0.0f)
|
||||
targetDistance += zoomSpeed;
|
||||
targetDistance = Mathf.Clamp(targetDistance, minDistance, maxDistance);
|
||||
if (Input.GetMouseButton(1) || (Input.GetMouseButton(0) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))))
|
||||
{
|
||||
targetX += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
|
||||
if (allowYTilt)
|
||||
{
|
||||
targetY -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
|
||||
targetY = ClampAngle(targetY, yMinLimit, yMaxLimit);
|
||||
}
|
||||
}
|
||||
|
||||
x = targetX;
|
||||
y = targetY;
|
||||
Quaternion rotation = Quaternion.Euler(y, x, 0);
|
||||
distance = targetDistance;
|
||||
Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position + pivotOffset;
|
||||
transform.rotation = rotation;
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
|
||||
private static float ClampAngle(float angle, float min, float max)
|
||||
{
|
||||
if (angle < -360) angle += 360;
|
||||
if (angle > 360) angle -= 360;
|
||||
return Mathf.Clamp(angle, min, max);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ee6ae5e4dfaf484388ff7d5cb6c0756
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,100 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ModelController : MonoBehaviour
|
||||
{
|
||||
public Transform imgModel;
|
||||
|
||||
public GameObject model; // Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
||||
|
||||
public Transform cameraTransform;
|
||||
|
||||
public float rotateSpeed = 2f; // <20><>ת<EFBFBD>ٶ<EFBFBD>
|
||||
public float scaleSpeed = 0.1f; // <20><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
||||
public float maxScale = 5f;
|
||||
public float minScale = 1f;
|
||||
|
||||
public static bool CanControl = true;
|
||||
|
||||
private Vector3 oldPosition;
|
||||
private Vector3 oldRotation;
|
||||
|
||||
// <20><>תʹ<D7AA>ñ<EFBFBD><C3B1><EFBFBD>
|
||||
Vector3 mPrevPos = Vector3.zero;
|
||||
Vector3 mPosDelta = Vector3.zero;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
||||
Vector2 finger1Position;
|
||||
Vector2 finger2Position;
|
||||
float scroll;
|
||||
float currentScale = 1f;
|
||||
|
||||
Vector3 tmpPos;
|
||||
|
||||
bool isTouchDown;
|
||||
bool isFirst = true;
|
||||
float x, y;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!ModelPlayerEx.Instance.IsDetailShow && CanControl &&
|
||||
model != null && ModelPlayerEx.Instance.ModelSeted)
|
||||
{
|
||||
if (Input.GetMouseButton(0) || (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved))
|
||||
{
|
||||
//if (isFirst)
|
||||
//{
|
||||
// isFirst = false;
|
||||
// mPrevPos = Input.mousePosition;
|
||||
//}
|
||||
//mPrevPos = Input.mousePosition;
|
||||
//mPosDelta = Input.mousePosition - mPrevPos;
|
||||
|
||||
x = Input.GetAxis("Mouse X") * rotateSpeed;
|
||||
y = Input.GetAxis("Mouse Y") * rotateSpeed;
|
||||
model.transform.Rotate(Camera.main.transform.up, -x * rotateSpeed, Space.World);
|
||||
model.transform.Rotate(Camera.main.transform.right, y * rotateSpeed, Space.World);
|
||||
}
|
||||
|
||||
//mPrevPos = Input.mousePosition;
|
||||
|
||||
|
||||
if (Input.touchCount == 2)
|
||||
{
|
||||
Touch touch1 = Input.GetTouch(0);
|
||||
Touch touch2 = Input.GetTouch(1);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָλ<D6B8><CEBB>
|
||||
finger1Position = touch1.position;
|
||||
finger2Position = touch2.position;
|
||||
|
||||
// <20><><EFBFBD>㵱ǰ<E3B5B1><C7B0>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD>
|
||||
float distance = Vector2.Distance(finger1Position, finger2Position);
|
||||
float previousDistance = Vector2.Distance(finger1Position - touch1.deltaPosition, finger2Position - touch2.deltaPosition);
|
||||
scroll = (previousDistance - distance) / 5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
}
|
||||
|
||||
if (scroll >= 0.1f)
|
||||
{
|
||||
currentScale *= (1f + scaleSpeed);
|
||||
if (currentScale > maxScale)
|
||||
currentScale = maxScale;
|
||||
//model.transform.localScale = Vector3.one * currentScale;
|
||||
imgModel.transform.localScale = Vector3.one * currentScale;
|
||||
}
|
||||
else if (scroll <= -0.1f)
|
||||
{
|
||||
currentScale /= (1f + scaleSpeed);
|
||||
if (currentScale < minScale)
|
||||
currentScale = minScale;
|
||||
//model.transform.localScale = Vector3.one * currentScale;
|
||||
imgModel.transform.localScale = Vector3.one * currentScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ff5fb8b797eb6f4f90da3f2ac2ff3f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
135
Assets/Roaming/Extenders/ModelPlayerEx/Scripts/ModelPlayerEx.cs
Normal file
135
Assets/Roaming/Extenders/ModelPlayerEx/Scripts/ModelPlayerEx.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ModelPlayerEx : MonoBehaviour
|
||||
{
|
||||
public static ModelPlayerEx Instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public ModelController ctrlModel;
|
||||
|
||||
public GameObject objPanelModel;
|
||||
|
||||
public Transform tranModelParent;
|
||||
|
||||
public Text txtTitle;
|
||||
|
||||
public Text txtDetails;
|
||||
|
||||
public Transform imgModel;
|
||||
|
||||
public bool ModelSeted;
|
||||
|
||||
public bool IsDetailShow;
|
||||
|
||||
GameObject tmp;
|
||||
|
||||
static bool FirstShow = true;
|
||||
|
||||
Animator anim;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void ShowModel(Data info, GameObject obj)
|
||||
{
|
||||
if (FirstShow)
|
||||
{
|
||||
OnBtnHelpClick();
|
||||
FirstShow = false;
|
||||
}
|
||||
|
||||
BaseController.CanControl = false;
|
||||
|
||||
AudioManager.Instance.PauseBackgroundMusic();
|
||||
|
||||
objPanelModel.SetActive(true);
|
||||
|
||||
tmp = Instantiate(obj, tranModelParent);
|
||||
tmp.transform.localPosition = new Vector3(0, 0, 0);
|
||||
tmp.transform.localRotation = Quaternion.identity;
|
||||
// tmp.transform.localScale = Vector3.one * 3;
|
||||
tmp.layer = LayerMask.NameToLayer("Model");
|
||||
foreach (var item in tmp.GetComponentsInChildren<Transform>())
|
||||
{
|
||||
item.gameObject.layer = LayerMask.NameToLayer("Model");
|
||||
}
|
||||
ctrlModel.model = tmp;
|
||||
ctrlModel.imgModel = imgModel;
|
||||
|
||||
txtTitle.text = info.Title;
|
||||
txtDetails.text = info.DataDetails[0];
|
||||
|
||||
Invoke("SetModel", 1f);
|
||||
}
|
||||
|
||||
void SetModel()
|
||||
{
|
||||
ModelSeted = true;
|
||||
}
|
||||
|
||||
public void OnBtnCloseClick()
|
||||
{
|
||||
BaseController.CanControl = true;
|
||||
|
||||
objPanelModel.SetActive(false);
|
||||
|
||||
IsDetailShow = false;
|
||||
|
||||
Destroy(tmp);
|
||||
|
||||
imgModel.transform.localScale = Vector3.one;
|
||||
|
||||
AudioManager.Instance.ResumeBackgroundMusic();
|
||||
|
||||
if (anim.GetCurrentAnimatorClipInfo(0).Length > 0)
|
||||
{
|
||||
AnimationClip clip = anim.GetCurrentAnimatorClipInfo(0)[0].clip;
|
||||
anim.Play(clip.name, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBtnAnimClick()
|
||||
{
|
||||
if (tmp != null)
|
||||
{
|
||||
Animator anim = tmp.GetComponentInChildren<Animator>();
|
||||
if(anim != null)
|
||||
{
|
||||
anim.SetTrigger("Show");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject pnlDetail;
|
||||
|
||||
public void OnBtnDetailClick()
|
||||
{
|
||||
pnlDetail.SetActive(!pnlDetail.activeSelf);
|
||||
|
||||
IsDetailShow = pnlDetail.activeSelf;
|
||||
}
|
||||
bool isShowHelp;
|
||||
|
||||
public void OnBtnHelpClick()
|
||||
{
|
||||
if (!isShowHelp)
|
||||
{
|
||||
anim.SetTrigger("ShowHelp");
|
||||
isShowHelp = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnShowHelpEnded()
|
||||
{
|
||||
isShowHelp = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77fb5487c4911734e8d35efb6f2f3a3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user