【剧情】使用fullpath索引obj

main
刘涛 2024-08-15 14:40:14 +08:00
parent 3d65c94eef
commit c635f463d8
7 changed files with 76 additions and 12 deletions

View File

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

View File

@ -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))
{
// 存在已有

View File

@ -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<ParticleSystem>();
var searchTrans = StoryManager.instance.SearchTrans(clipRef.objFullPath);
if (searchTrans == null) return;
var particleSystem = searchTrans.GetComponentInChildren<ParticleSystem>();
if (particleSystem == null) return;
particleSystem.Simulate((float)time, true, false);
}

View File

@ -7,7 +7,7 @@ namespace Gameplay.Story.Cmp.Timeline.CommonAction
public class CommonActionClip : PlayableAsset
{
public GameObject controlObj;
public string objFullPath;
public ECommonActionType actionType;

View File

@ -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)
{

View File

@ -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 = "未指定控制对象";

View File

@ -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)
{