From c635f463d8a5b3f7b2b8624ad1e7ff45ac501884 Mon Sep 17 00:00:00 2001 From: liutao <821580467@qq.com> Date: Thu, 15 Aug 2024 14:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=89=A7=E6=83=85=E3=80=91=E4=BD=BF?= =?UTF-8?q?=E7=94=A8fullpath=E7=B4=A2=E5=BC=95obj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Story/Cmp/Impl/StoryCommonManager.cs | 3 +- .../Cmp/Impl/StroyCommonActiveManager.cs | 5 +-- .../CommonAction/CommonActionBehaviour.cs | 12 ++++--- .../Timeline/CommonAction/CommonActionClip.cs | 2 +- .../Scripts/Gameplay/Story/StoryManager.cs | 29 ++++++++++++++++ .../CommonAction/CommonActionClipEditor.cs | 3 +- .../CommonAction/CommonActionEditor.cs | 34 +++++++++++++++++-- 7 files changed, 76 insertions(+), 12 deletions(-) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StoryCommonManager.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StoryCommonManager.cs index 7b5ba18f8b3..64a9f41f9e6 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StoryCommonManager.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StoryCommonManager.cs @@ -23,7 +23,8 @@ namespace Gameplay.Story.Cmp.Impl { continue; } - if (asset.controlObj == null) + var searchTrans = StoryManager.instance.SearchTrans(asset.objFullPath); + if (searchTrans == null) { continue; } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StroyCommonActiveManager.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StroyCommonActiveManager.cs index 5e8f365605d..bb7d6fd2297 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StroyCommonActiveManager.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Impl/StroyCommonActiveManager.cs @@ -23,12 +23,13 @@ namespace Gameplay.Story.Cmp.Impl { return; } - if (asset.controlObj == null) + var searchTrans = StoryManager.instance.SearchTrans(asset.objFullPath); + if (searchTrans == null) { return; } if (asset.actionType != ECommonActionType.ActiveSet) return; - var obj = asset.controlObj; + var obj = searchTrans.gameObject; if (dataDict.TryGetValue(obj, out var data)) { // 存在已有 diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionBehaviour.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionBehaviour.cs index 473bf29bafc..54d27e92e72 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionBehaviour.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionBehaviour.cs @@ -24,8 +24,8 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction return; } - var obj = clipRef.controlObj; - if (obj == null) + var searchTrans = StoryManager.instance.SearchTrans(clipRef.objFullPath); + if (searchTrans == null) { return; } @@ -37,10 +37,10 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction switch (clipRef.actionParam1) { case 1: - obj.SetActive(true); + searchTrans.gameObject.SetActive(true); break; case 2: - obj.SetActive(false); + searchTrans.gameObject.SetActive(false); break; } break; @@ -51,7 +51,9 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction private void _SampleParticle(double time) { - var particleSystem = clipRef.controlObj.GetComponentInChildren(); + var searchTrans = StoryManager.instance.SearchTrans(clipRef.objFullPath); + if (searchTrans == null) return; + var particleSystem = searchTrans.GetComponentInChildren(); if (particleSystem == null) return; particleSystem.Simulate((float)time, true, false); } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionClip.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionClip.cs index 4b50ffd4aad..36f6a8705c5 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionClip.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/Cmp/Timeline/CommonAction/CommonActionClip.cs @@ -7,7 +7,7 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction public class CommonActionClip : PlayableAsset { - public GameObject controlObj; + public string objFullPath; public ECommonActionType actionType; diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/StoryManager.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/StoryManager.cs index 8a8391234db..96eaf236180 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/StoryManager.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Story/StoryManager.cs @@ -102,6 +102,35 @@ namespace Gameplay.Story } + public Transform SearchTrans(string path) + { + if (string.IsNullOrEmpty(path)) return null; + return cmpRef.transform.Find(path); + } + + public string GetFullPath(Transform trans) + { + var combinePath = trans.name; + var workTrans = trans.parent; + bool isNotRoot = true; + while (workTrans) + { + if (workTrans == cmpRef.transform) + { + isNotRoot = false; + break; + } + combinePath += workTrans.name + "/"; + workTrans = workTrans.parent; + } + if (isNotRoot) + { + Debug.LogError("路径不在StoryManager下面"); + return ""; + } + return combinePath; + } + public void Init(CmpStoryManager cmp, bool force = false) { diff --git a/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionClipEditor.cs b/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionClipEditor.cs index 10a8ddde51d..7bbe41847e4 100644 --- a/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionClipEditor.cs +++ b/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionClipEditor.cs @@ -17,7 +17,8 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction return; } - var obj = clipAsset.controlObj; + var searchTrans = StoryManager.instance.SearchTrans(clipAsset.objFullPath); + var obj = searchTrans.gameObject; if (obj == null) { clip.displayName = "未指定控制对象"; diff --git a/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionEditor.cs b/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionEditor.cs index 17372af0691..0c46284b1e7 100644 --- a/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionEditor.cs +++ b/ProjectNLD/Assets/Editor/Story/Timeline/CommonAction/CommonActionEditor.cs @@ -1,3 +1,4 @@ +using Gameplay.Skill; using Sirenix.OdinInspector.Editor; using UnityEditor; using UnityEngine; @@ -16,6 +17,8 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction } } + private GameObject _cacheObj; + public override void OnInspectorGUI() { // base.OnInspectorGUI(); @@ -25,9 +28,36 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction EditorGUILayout.LabelField("clip is null"); return; } - - clip.controlObj = EditorGUILayout.ObjectField("控制对象", clip.controlObj, typeof(GameObject), true) as GameObject; + if (StoryManager.instance == null) + { + EditorGUILayout.LabelField("StoryManager.instance is null"); + return; + } + + if (_cacheObj == null && !string.IsNullOrEmpty(clip.objFullPath)) + { + var searchTrans = StoryManager.instance.SearchTrans(clip.objFullPath); + if (searchTrans != null) + { + _cacheObj = searchTrans.gameObject; + } + } + + var newObj = EditorGUILayout.ObjectField("控制对象", _cacheObj, typeof(GameObject), true) as GameObject; + if (newObj != _cacheObj) + { + _cacheObj = newObj; + if (_cacheObj == null) + { + clip.objFullPath = ""; + } + else + { + clip.objFullPath = StoryManager.instance.GetFullPath(_cacheObj.transform); + } + EditorUtility.SetDirty(clip); + } clip.actionType = (ECommonActionType)EditorGUILayout.EnumPopup("操作类型", clip.actionType); switch (clip.actionType) {