/// <summary> /// 绘制字段 /// </summary> /// <param name="taskGameObjects">目标物体</param> /// <param name="name">绘制名称</param> /// <returns>绘制高度</returns> public static int DrawField(TaskGameObjects taskGameObjects, string name) { if (taskGameObjects == null) { return(0); } taskGameObjects.InitializeEditorData(name); taskGameObjects._reorderableList.DoLayoutList(); int count = taskGameObjects.GUIDs.Count; if (count <= 0) { count = 1; } return(20 + count * 22); }
/// <summary> /// 在场景中搜索任务目标 /// </summary> private static void SearchTaskTarget(TaskGameObjects taskGameObjects, int index) { if (taskGameObjects.GUIDs[index] == "<None>") { return; } if (taskGameObjects._gameObjects[index] != null) { return; } PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { taskGameObjects._gameObjects[index] = prefabStage.prefabContentsRoot.FindChildren(taskGameObjects.Paths[index]); if (taskGameObjects._gameObjects[index] == null) { TaskTarget[] targets = prefabStage.prefabContentsRoot.GetComponentsInChildren <TaskTarget>(true); foreach (TaskTarget target in targets) { if (taskGameObjects.GUIDs[index] == target.GUID) { taskGameObjects._gameObjects[index] = target.gameObject; taskGameObjects.Paths[index] = target.transform.FullName(); taskGameObjects.Paths[index] = taskGameObjects.Paths[index].Substring(taskGameObjects.Paths[index].IndexOf("/") + 1); break; } } } } else { taskGameObjects._gameObjects[index] = GameObject.Find(taskGameObjects.Paths[index]); if (taskGameObjects._gameObjects[index] == null) { TaskTarget[] targets = UnityEngine.Object.FindObjectsOfType <TaskTarget>(); foreach (TaskTarget target in targets) { if (taskGameObjects.GUIDs[index] == target.GUID) { taskGameObjects._gameObjects[index] = target.gameObject; taskGameObjects.Paths[index] = target.transform.FullName(); break; } } } } if (taskGameObjects._gameObjects[index] != null) { TaskTarget target = taskGameObjects._gameObjects[index].GetComponent <TaskTarget>(); if (!target) { target = taskGameObjects._gameObjects[index].AddComponent <TaskTarget>(); target.GUID = taskGameObjects.GUIDs[index]; EditorUtility.SetDirty(taskGameObjects._gameObjects[index]); } } }