123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System;
- using UnityEngine;
- public class IKDragPoint : MonoBehaviour
- {
- public static bool IsDrag { get; private set; }
- private void Update()
- {
- if (this.axis_obj_ == null || this.target_trans_ == null)
- {
- return;
- }
- if ((this.axis_obj_.is_drag || this.axis_obj_.is_grip) && !this.is_drag_)
- {
- this.OnDragStart();
- IKDragPoint.IsDrag = true;
- }
- else if (this.is_drag_ && !this.axis_obj_.is_drag && !this.axis_obj_.is_grip)
- {
- this.OnDragEnd();
- IKDragPoint.IsDrag = false;
- if (this.PositonCorrectionEnabled)
- {
- this.target_trans_.localPosition = this.backup_local_pos_;
- }
- }
- this.is_drag_ = (this.axis_obj_.is_drag || this.axis_obj_.is_grip);
- if (this.is_drag_)
- {
- this.OnDrag();
- if (this.PositonCorrectionEnabled)
- {
- this.target_trans_.localPosition = this.backup_local_pos_;
- }
- return;
- }
- base.transform.position = this.target_trans_.position;
- }
- public void OnDestroy()
- {
- if (this.axis_obj_ != null)
- {
- UnityEngine.Object.Destroy(this.axis_obj_.gameObject);
- }
- this.axis_obj_ = null;
- }
- public void SetTargetIKPoint(GameObject obj)
- {
- this.target_trans_ = obj.transform;
- this.backup_local_pos_ = this.target_trans_.localPosition;
- this.Update();
- }
- public void SetWorldTransformAxis(WorldTransformAxis axis_obj)
- {
- this.axis_obj_ = axis_obj;
- this.Update();
- }
- public Transform target_ik_point_trans
- {
- get
- {
- return this.target_trans_;
- }
- }
- public WorldTransformAxis axis_obj
- {
- get
- {
- return this.axis_obj_;
- }
- }
- public bool visible
- {
- get
- {
- return this.axis_obj_.Visible;
- }
- set
- {
- this.axis_obj_.Visible = value;
- }
- }
- private void OnDragStart()
- {
- if (this.drag_start_event != null)
- {
- this.drag_start_event();
- }
- }
- private void OnDrag()
- {
- if (this.cur_drag_event != null)
- {
- this.cur_drag_event();
- }
- }
- private void OnDragEnd()
- {
- if (this.drag_end_event != null)
- {
- this.drag_end_event();
- }
- }
- public bool PositonCorrectionEnabled = true;
- public Action cur_drag_event;
- public Action drag_start_event;
- public Action drag_end_event;
- private Transform target_trans_;
- private Vector3 backup_local_pos_;
- private WorldTransformAxis axis_obj_;
- private bool is_drag_;
- }
|