CHIVA\bj 6 месяцев назад
Родитель
Сommit
b24cab9962

+ 13 - 0
Framework/SimulationToolDev/AnimationDriver/AnimationDriver-Example/SimpleMoveItem/SimpleMoveItem.cs

@@ -53,6 +53,19 @@ public class SimpleMoveItem : SerializedMonoBehaviour
         }
     }
 
+    public void SetKeyValue(GameObject target, float lerp)
+    {
+        lerp = Mathf.Clamp(lerp, 0, 1);
+        if (moveObjs.ContainsKey(target))
+        {
+            var item = moveObjs[target];
+            target.transform.position = Vector3.Lerp(item.position, item.position + item.TransformDirection(localMovePos), lerp);
+            target.transform.rotation = item.rotation;
+
+            target.transform.RotateAround(item.position, item.TransformDirection(localMovePos), rotAngle * lerp);
+        }
+    }
+
 #if UNITY_EDITOR
 
     [FoldoutGroup("快捷编辑", Order = -1)]

+ 5 - 0
Framework/SimulationToolDev/OperationDriver/OperationData-Example/TriggerMode/OpTrigger_Toolbackpack/OpTrigger_ToolPack.cs

@@ -213,6 +213,9 @@ public class OpTrigger_ToolPack : OperationData_TriggerMode
     [ValueDropdown("GetToolNames", DropdownTitle = "正确的工具组")]
     public List<string> choseToolNames = new List<string>();
 
+    [LabelText("使用特殊触发动画(螺丝类)")]
+    public bool useToolIndependentAni=false;
+
     /// <summary>
     /// 学习模式延迟提示高亮时长
     /// </summary>
@@ -259,6 +262,8 @@ public class OpTrigger_ToolPack : OperationData_TriggerMode
                 timer = 0;
                 OperateSetting.Instance.m_CurrentStepRightToolNames = choseToolNames;
 
+                this.GetComponent<ToolPackInteractive_IndependentAni>().Init();
+
                 break;
         }
     }

+ 92 - 0
Framework/SimulationToolDev/OperationDriver/OperationData-Example/TriggerMode/OpTrigger_Toolbackpack/ToolPackInteractive_IndependentAni.cs

@@ -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;
+}

+ 11 - 0
Framework/SimulationToolDev/OperationDriver/OperationData-Example/TriggerMode/OpTrigger_Toolbackpack/ToolPackInteractive_IndependentAni.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 0a489369442e1fe41aed59b391940582
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: