using UnityEngine;
public class MovableContent : MonoBehaviour
{
[SerializeField]
private float m_ClickHoldTime = 0.1f;
private float m_timeHold = 0f;
private bool m_EditingContent = false;
private Transform m_CameraTransform;
private float m_MovePlaneDistance;
private void Start()
{
m_CameraTransform = Camera.main.transform;
StoreContent();
}
private void Update()
{
if (m_EditingContent)
{
Vector3 projection = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, m_MovePlaneDistance));
transform.position = projection;
}
}
private void StoreContent()
{
//if (!ContentStorageManager.Instance.contentList.Contains(this))
//{
// ContentStorageManager.Instance.contentList.Add(this);
//}
//ContentStorageManager.Instance.SaveContents();
}
public void RemoveContent()
{
//if (ContentStorageManager.Instance.contentList.Contains(this))
//{
// ContentStorageManager.Instance.contentList.Remove(this);
//}
//ContentStorageManager.Instance.SaveContents();
//Destroy(gameObject);
}
private void OnMouseDrag()
{
m_timeHold += Time.deltaTime;
if (m_timeHold >= m_ClickHoldTime && !m_EditingContent)
{
m_MovePlaneDistance = Vector3.Dot(transform.position - m_CameraTransform.position, m_CameraTransform.forward) / m_CameraTransform.forward.sqrMagnitude;
m_EditingContent = true;
}
}
private void OnMouseUp()
{
StoreContent();
m_timeHold = 0f;
m_EditingContent = false;
}
}
Unity空间中移动物体
原创
©著作权归作者所有:来自51CTO博客作者DaLiangChen的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:对象与面板链接画线功能
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Android AI应用开发:物体检测
基于Google ML模型开发Android物体检测应用
物体检测 ML 项目源码 -
As中移动物体边界问题
As中移动物体边界问题
web AS 边界