|
|
@@ -0,0 +1,92 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// 独立动画触发类型
|
|
|
+/// </summary>
|
|
|
+public enum IndependentAniTriigerType
|
|
|
+{
|
|
|
+ click,
|
|
|
+ press
|
|
|
+}
|
|
|
+
|
|
|
+[RequireComponent(typeof(OpTrigger_ToolPack))]
|
|
|
+/// <summary>
|
|
|
+/// 工具交互-独立动画控制
|
|
|
+/// </summary>
|
|
|
+public class ToolPackInteractive_IndependentAni : MonoBehaviour
|
|
|
+{
|
|
|
+ public IndependentAniTriigerType m_IndependentAniTriigerType = IndependentAniTriigerType.press;
|
|
|
+ [HideInInspector]
|
|
|
+ public OpTrigger_ToolPack m_ToolPack;
|
|
|
+ public OpTrigger_ToolPack ToolPack
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ if (m_ToolPack == null)
|
|
|
+ {
|
|
|
+ m_ToolPack = this.GetComponent<OpTrigger_ToolPack>();
|
|
|
+ }
|
|
|
+ return m_ToolPack;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public SimpleMoveItem m_TargetSimplaeMoveItem;
|
|
|
+ public bool isActive;
|
|
|
+ private RayCastItem m_CurrentRayCastItem;
|
|
|
+ private Dictionary<RayCastItem, SimplaeModelAssociation> mRayCastItemValues = new Dictionary<RayCastItem, SimplaeModelAssociation>();
|
|
|
+ public void Init()
|
|
|
+ {
|
|
|
+ mRayCastItemValues.Clear();
|
|
|
+ foreach (var item in ToolPack.targetObjs)
|
|
|
+ {
|
|
|
+ SimplaeModelAssociation simplaeModelAssociation = new SimplaeModelAssociation();
|
|
|
+ foreach (var moveItem in m_TargetSimplaeMoveItem.moveObjs)
|
|
|
+ {
|
|
|
+ if (Vector3.Distance(moveItem.Key.transform.position, item.transform.position) < 0.01f)
|
|
|
+ {
|
|
|
+ simplaeModelAssociation.model = moveItem.Key;
|
|
|
+ simplaeModelAssociation.value = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mRayCastItemValues.Add(item, simplaeModelAssociation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void Update()
|
|
|
+ {
|
|
|
+ if (!isActive || !m_TargetSimplaeMoveItem) return;
|
|
|
+
|
|
|
+ if (Input.GetMouseButton(0))
|
|
|
+ {
|
|
|
+ m_CurrentRayCastItem = null;
|
|
|
+ foreach (var item in ToolPack.targetObjs)
|
|
|
+ {
|
|
|
+ if (CameraRayCastManager.Instance.CheckCurrentHoverItem(item))
|
|
|
+ {
|
|
|
+ m_CurrentRayCastItem = item;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!mRayCastItemValues.ContainsKey(m_CurrentRayCastItem)) return;
|
|
|
+
|
|
|
+ mRayCastItemValues[m_CurrentRayCastItem].value += 1 / m_TargetSimplaeMoveItem.duration * Time.deltaTime;
|
|
|
+ mRayCastItemValues[m_CurrentRayCastItem].value = Mathf.Clamp(mRayCastItemValues[m_CurrentRayCastItem].value, 0, 1);
|
|
|
+ m_TargetSimplaeMoveItem.SetKeyValue(mRayCastItemValues[m_CurrentRayCastItem].model, mRayCastItemValues[m_CurrentRayCastItem].value);
|
|
|
+ m_CurrentRayCastItem.transform.position = mRayCastItemValues[m_CurrentRayCastItem].model.transform.position;
|
|
|
+ m_CurrentRayCastItem.transform.rotation = mRayCastItemValues[m_CurrentRayCastItem].model.transform.rotation;
|
|
|
+
|
|
|
+ if (mRayCastItemValues[m_CurrentRayCastItem].value == 1)
|
|
|
+ {
|
|
|
+ mRayCastItemValues[m_CurrentRayCastItem].model.SetActive(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+public class SimplaeModelAssociation
|
|
|
+{
|
|
|
+ public GameObject model;
|
|
|
+ public float value;
|
|
|
+}
|