static void ConfigUICharacters(StoryData root, Dictionary <int, GameObject> uiDict, Dictionary <int, Sprite> spDict) { if (root == null || root.uiChars == null || root.uiChars.Length < 1 || uiDict == null || uiDict.Count < 1 ) { return; } foreach (var c in root.uiChars) { GameObject dialogGo = null; if (uiDict.TryGetValue(c.dialogId, out dialogGo)) { if (dialogGo != null) { c.preset.SetSayDialog = dialogGo.GetComponent <Fungus.SayDialog>(); } } if (c.portraits != null && c.portraits.Length > 0) { var list = c.preset.Portraits; if (list == null) { list = new List <Sprite>(); } foreach (var p in c.portraits) { if (spDict != null && spDict.ContainsKey(p.id)) { list.Add(spDict[p.id]); } } c.preset.Portraits = list; } GameObject portraitGo = null; if (uiDict.TryGetValue(c.portraitId, out portraitGo)) { if (portraitGo != null) { c.preset.displayPortrait = portraitGo.GetComponent <Fungus.DialogPortrait>(); portraitGo.SetActive(false); } } } }
private static void ConfigVCams(StoryData root, Dictionary <int, GameObject> goDict) { if (root == null || root.vCams == null || root.vCams.Length < 1) { return; } foreach (var setting in root.vCams) { var tmpGo = FindNode(root.transform, setting.followID, setting.followNestPath, goDict); if (tmpGo != null) { setting.vCam.m_Follow = tmpGo.transform; } tmpGo = FindNode(root.transform, setting.lookatID, setting.lookatNestPath, goDict); if (tmpGo != null) { setting.vCam.m_LookAt = tmpGo.transform; } } }
static void FinishStory(StoryData root) { root.OnFlowEnd(""); }
private static void ConfigTimeline(StoryData root, Dictionary <int, GameObject> goDict) { if (root == null || root.timlineData == null || root.timlineData.Length < 1) { return; } foreach (var data in root.timlineData) { if (data.pdTrans == null || data.tlAsset == null) { #if UNITY_EDITOR Debug.LogError("[Story Data Error] -- PlayableDirector is Missing!"); #endif continue; } var pd = data.pdTrans.gameObject.AddComponent <PlayableDirector>(); var tlAsset = Object.Instantiate(data.tlAsset); pd.playableAsset = tlAsset; pd.playOnAwake = false; pd.timeUpdateMode = DirectorUpdateMode.Manual; pd.gameObject.AddComponent <PlayableDirectorManualCtrl>(); if (data.bindingData != null) { foreach (var d in data.bindingData) { GameObject tmpGo = null; if (d.go != null) { tmpGo = d.go; } else { tmpGo = FindNode(root.transform, d.nodeId, d.nestPath, goDict); } if (tmpGo == null) { continue; } var track = tlAsset.GetOutputTrack(d.index); if (d.typeStr == "GameObject") { pd.SetGenericBinding(track, tmpGo); } else { Object comp = tmpGo.GetComponent(d.typeStr); if (comp != null) { if (track is UnityEngine.Timeline.AnimationTrack) { var anim = comp as Animator; if (anim != null && anim.runtimeAnimatorController != null) { var parentTrans = tmpGo.transform.parent; if (parentTrans == null || parentTrans.name != "roleAnchro") { anim.runtimeAnimatorController = null; } } } pd.SetGenericBinding(track, comp); } #if UNITY_EDITOR else { Debug.LogError("[Story Data Error] -- SetGenericBinding faild :" + tmpGo.name + "type:" + d.typeStr); } #endif } } } if (data.exposeData != null) { foreach (var d in data.exposeData) { if (d.obj == null) { GameObject tmpGo = FindNode(root.transform, d.nodeId, d.nestPath, goDict); if (tmpGo == null) { continue; } if (d.typeStr == "GameObject") { pd.SetReferenceValue(d.propId, tmpGo); } else { Object comp = tmpGo.GetComponent(d.typeStr); if (comp != null) { pd.SetReferenceValue(d.propId, comp); } #if UNITY_EDITOR else { Debug.LogError("[Story Data Error] -- SetReferenceValue faild :" + tmpGo.name + "type:" + d.typeStr); } #endif } } else { if (d.typeStr == "GameObject") { pd.SetReferenceValue(d.propId, d.obj); } else { Object comp = d.obj.GetComponent(d.typeStr); if (comp != null) { pd.SetReferenceValue(d.propId, comp); } #if UNITY_EDITOR else { Debug.LogError("[Story Data Error] -- SetReferenceValue faild :" + d.obj.name + "type:" + d.typeStr); } #endif } } } } //binding camera if (mainCam != null) { var camBrain = mainCam.GetComponent <Cinemachine.CinemachineBrain>(); for (int i = 0; i < tlAsset.outputTrackCount; i++) { var track = tlAsset.GetOutputTrack(i) as Cinemachine.Timeline.CinemachineTrack; if (track != null) { pd.SetGenericBinding(track, camBrain); } } } //create wwise track if (data.audioInfo != null && data.audioInfo.Length > 0) { var commitTargetTrack = tlAsset.CreateTrack <PlayableTrack>(null, "WwiseCtrl"); PlayableTrack subCommitTargetTrack = null; double lastEnd = 0f; foreach (var info in data.audioInfo) { TimelineClip clip = null; if (info.startTime < lastEnd) { if (subCommitTargetTrack == null) { subCommitTargetTrack = tlAsset.CreateTrack <PlayableTrack>(null, "WwiseCtrl1"); } clip = subCommitTargetTrack.CreateClip <WwiseEvent>(); } else { clip = commitTargetTrack.CreateClip <WwiseEvent>(); } var asset = clip.asset as WwiseEvent; asset.audioName = info.audioName; clip.start = info.startTime; clip.duration = 0.1; lastEnd = clip.start + clip.duration; } } } }
private static void CreateStageNodes( StoryData root , Dictionary <string, GameObject> stageNodes , Dictionary <int, GameObject> battlePosNode , ref Dictionary <int, GameObject> goDict) { if (root == null || root.stageDatas == null || root.stageDatas.Length < 1) { return; } HashSet <GameObject> settedNodes = new HashSet <GameObject>(); foreach (var data in root.stageDatas) { if (goDict.ContainsKey(data.id)) { #if UNITY_EDITOR Debug.LogError("[Story Data Error] -- Same Role ID!!! "); #endif continue; } GameObject nodeGo = null; if (data.battlePosId > 0 && battlePosNode != null && battlePosNode.ContainsKey(data.battlePosId)) { nodeGo = battlePosNode[data.battlePosId]; } else if (data.battlePosId < 0 && stageNodes != null && !string.IsNullOrEmpty(data.path) && stageNodes.ContainsKey(data.path)) { nodeGo = stageNodes[data.path]; } if (nodeGo == null) { #if UNITY_EDITOR Debug.LogError("[Story Data Error] -- Can not find Stage Node :" + data.path + "|||" + data.battlePosId); #endif continue; } Transform nestRoot = null; if (data.nestId < 0) { nestRoot = root.stageRoot.transform.Find(data.nestPath); } else if (goDict.ContainsKey(data.nestId)) { var nestRootParent = goDict[data.nestId]; nestRoot = nestRootParent.transform.Find(data.nestPath); } if (nestRoot == null) { #if UNITY_EDITOR Debug.LogError("[Story Data Error] -- Can not find Stage Node Nest Root!"); #endif continue; } if (settedNodes.Contains(nodeGo)) { var existOne = nodeGo; nodeGo = GameObject.Instantiate(existOne); nodeGo.name = existOne.name; if (root.additionalNodes == null) { root.additionalNodes = new List <GameObject>(); } root.additionalNodes.Add(nodeGo); } else { settedNodes.Add(nodeGo); } if (data.nestId >= 0 || data.battlePosId < 0) { nodeGo.transform.SetParent(nestRoot); nodeGo.transform.localPosition = data.initPos; nodeGo.transform.localEulerAngles = data.initRotate; nodeGo.transform.localScale = data.initScale; } if (!nodeGo.activeSelf) { nodeGo.SetActive(true); } if (goDict.ContainsKey(data.id)) { #if UNITY_EDITOR Debug.LogError("[Story Data Error] -- Repeat GUID in StoryData"); #endif } else { goDict.Add(data.id, nodeGo); } } }