/** * <summary>Updates its own variables from a NPCData class.</summary> * <param name = "data">The NPCData class to load from</param> */ public void LoadData(NPCData data) { EndPath(); if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity) { idleAnimSprite = data.idleAnim; walkAnimSprite = data.walkAnim; talkAnimSprite = data.talkAnim; runAnimSprite = data.runAnim; } else if (animationEngine == AnimationEngine.Legacy) { idleAnim = AssetLoader.RetrieveAsset(idleAnim, data.idleAnim); walkAnim = AssetLoader.RetrieveAsset(walkAnim, data.walkAnim); runAnim = AssetLoader.RetrieveAsset(runAnim, data.talkAnim); talkAnim = AssetLoader.RetrieveAsset(talkAnim, data.runAnim); } else if (animationEngine == AnimationEngine.Mecanim) { moveSpeedParameter = data.walkAnim; talkParameter = data.talkAnim; turnParameter = data.runAnim;; } walkSound = AssetLoader.RetrieveAsset(walkSound, data.walkSound); runSound = AssetLoader.RetrieveAsset(runSound, data.runSound); if (data.speechLabel != "") { SetName(data.speechLabel, data.displayLineID); } portraitIcon.texture = AssetLoader.RetrieveAsset(portraitIcon.texture, data.portraitGraphic); walkSpeedScale = data.walkSpeed; runSpeedScale = data.runSpeed; // Rendering lockDirection = data.lockDirection; lockScale = data.lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else { ReleaseSorting(); } if (data.lockDirection) { spriteDirection = data.spriteDirection; } if (data.lockScale) { spriteScale = data.spriteScale; } if (data.lockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = data.sortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = data.sortingOrder; GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } } AC.Char charToFollow = null; if (data.followTargetID != 0) { RememberNPC followNPC = Serializer.returnComponent <RememberNPC> (data.followTargetID); if (followNPC.GetComponent <AC.Char>()) { charToFollow = followNPC.GetComponent <AC.Char>(); } } FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection); Halt(); if (data.pathData != null && data.pathData != "" && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, data.pathData); SetPath(savedPath, data.targetNode, data.prevNode, data.pathAffectY); isRunning = data.isRunning; } else if (data.pathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.pathID); if (pathObject != null) { SetPath(pathObject, data.targetNode, data.prevNode); } else { ACDebug.LogWarning("Trying to assign a path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } if (data.lastPathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.lastPathID); if (pathObject != null) { SetLastPath(pathObject, data.lastTargetNode, data.lastPrevNode); } else { ACDebug.LogWarning("Trying to assign the previous path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } // Head target if (data.isHeadTurning) { ConstantID _headTargetID = Serializer.returnComponent <ConstantID> (data.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(data.headTargetX, data.headTargetY, data.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = Serializer.returnComponent <SortingMap> (data.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = data.followSortingMap; if (!data.followSortingMap) { followSortingMap.SetSortingMap(customSortingMap); } } } }
/** * <summary>Updates its own variables from a NPCData class.</summary> * <param name = "data">The NPCData class to load from</param> */ public void LoadData(NPCData data) { charState = (data.inCustomCharState) ? CharState.Custom : CharState.Idle; EndPath(); GetAnimEngine().LoadNPCData(data, this); walkSound = AssetLoader.RetrieveAsset(walkSound, data.walkSound); runSound = AssetLoader.RetrieveAsset(runSound, data.runSound); if (!string.IsNullOrEmpty(data.speechLabel)) { SetName(data.speechLabel, data.displayLineID); } portraitIcon.ReplaceTexture(AssetLoader.RetrieveAsset(portraitIcon.texture, data.portraitGraphic)); walkSpeedScale = data.walkSpeed; runSpeedScale = data.runSpeed; // Rendering lockDirection = data.lockDirection; lockScale = data.lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else { ReleaseSorting(); } if (data.lockDirection) { spriteDirection = data.spriteDirection; UpdateFrameFlipping(true); } if (data.lockScale) { spriteScale = data.spriteScale; } if (data.lockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = data.sortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = data.sortingOrder; GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } } AC.Char charToFollow = null; if (data.followTargetID != 0) { RememberNPC followNPC = ConstantID.GetComponent <RememberNPC> (data.followTargetID); if (followNPC.GetComponent <AC.Char>()) { charToFollow = followNPC.GetComponent <AC.Char>(); } } if (charToFollow != null || (data.followTargetIsPlayer && KickStarter.player != null)) { FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection); } else { StopFollowing(); } Halt(); if (!string.IsNullOrEmpty(data.pathData) && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, data.pathData); SetPath(savedPath, data.targetNode, data.prevNode, data.pathAffectY); isRunning = data.isRunning; } else if (data.pathID != 0) { Paths pathObject = ConstantID.GetComponent <Paths> (data.pathID); if (pathObject != null) { SetPath(pathObject, data.targetNode, data.prevNode); } else { ACDebug.LogWarning("Trying to assign a path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } if (data.lastPathID != 0) { Paths pathObject = ConstantID.GetComponent <Paths> (data.lastPathID); if (pathObject != null) { SetLastPath(pathObject, data.lastTargetNode, data.lastPrevNode); } else { ACDebug.LogWarning("Trying to assign the previous path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } // Head target if (data.isHeadTurning) { ConstantID _headTargetID = ConstantID.GetComponent <ConstantID> (data.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(data.headTargetX, data.headTargetY, data.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = ConstantID.GetComponent <SortingMap> (data.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = data.followSortingMap; if (!data.followSortingMap && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } if (GetAnimEngine() != null && GetAnimEngine().IKEnabled) { LeftHandIKController.LoadData(data.leftHandIKState); RightHandIKController.LoadData(data.rightHandIKState); } _spriteDirectionData.LoadData(data.spriteDirectionData); }
/** * <summary>Updates a NPCData class with its own variables that need saving.</summary> * <param name = "npcData">The original NPCData class</param> * <returns>The updated NPCData class</returns> */ public NPCData SaveData(NPCData npcData) { npcData.RotX = TransformRotation.eulerAngles.x; npcData.RotY = TransformRotation.eulerAngles.y; npcData.RotZ = TransformRotation.eulerAngles.z; if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity) { npcData.idleAnim = idleAnimSprite; npcData.walkAnim = walkAnimSprite; npcData.talkAnim = talkAnimSprite; npcData.runAnim = runAnimSprite; } else if (animationEngine == AnimationEngine.Legacy) { npcData.idleAnim = AssetLoader.GetAssetInstanceID(idleAnim); npcData.walkAnim = AssetLoader.GetAssetInstanceID(walkAnim); npcData.runAnim = AssetLoader.GetAssetInstanceID(runAnim); npcData.talkAnim = AssetLoader.GetAssetInstanceID(talkAnim); } else if (animationEngine == AnimationEngine.Mecanim) { npcData.walkAnim = moveSpeedParameter; npcData.talkAnim = talkParameter; npcData.runAnim = turnParameter; } npcData.walkSound = AssetLoader.GetAssetInstanceID(walkSound); npcData.runSound = AssetLoader.GetAssetInstanceID(runSound); npcData.speechLabel = GetName(); npcData.displayLineID = displayLineID; npcData.portraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture); npcData.walkSpeed = walkSpeedScale; npcData.runSpeed = runSpeedScale; // Rendering npcData.lockDirection = lockDirection; npcData.lockScale = lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { npcData.lockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting; } else if (GetComponent <FollowSortingMap>()) { npcData.lockSorting = GetComponent <FollowSortingMap>().lockSorting; } else { npcData.lockSorting = false; } npcData.spriteDirection = spriteDirection; npcData.spriteScale = spriteScale; if (spriteChild && spriteChild.GetComponent <Renderer>()) { npcData.sortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder; npcData.sortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName; } else if (GetComponent <Renderer>()) { npcData.sortingOrder = GetComponent <Renderer>().sortingOrder; npcData.sortingLayer = GetComponent <Renderer>().sortingLayerName; } npcData.pathID = 0; npcData.lastPathID = 0; if (GetPath()) { npcData.targetNode = GetTargetNode(); npcData.prevNode = GetPreviousNode(); npcData.isRunning = isRunning; npcData.pathAffectY = GetPath().affectY; if (GetPath() == GetComponent <Paths>()) { npcData.pathData = Serializer.CreatePathData(GetComponent <Paths>()); } else { if (GetPath().GetComponent <ConstantID>()) { npcData.pathID = GetPath().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("Want to save path data for " + name + " but path has no ID!", gameObject); } } } if (GetLastPath()) { npcData.lastTargetNode = GetLastTargetNode(); npcData.lastPrevNode = GetLastPrevNode(); if (GetLastPath().GetComponent <ConstantID>()) { npcData.lastPathID = GetLastPath().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("Want to save previous path data for " + name + " but path has no ID!", gameObject); } } if (followTarget) { if (!followTargetIsPlayer) { if (followTarget.GetComponent <ConstantID>()) { npcData.followTargetID = followTarget.GetComponent <ConstantID>().constantID; npcData.followTargetIsPlayer = followTargetIsPlayer; npcData.followFrequency = followFrequency; npcData.followDistance = followDistance; npcData.followDistanceMax = followDistanceMax; npcData.followFaceWhenIdle = followFaceWhenIdle; npcData.followRandomDirection = followRandomDirection; } else { ACDebug.LogWarning("Want to save follow data for " + name + " but " + followTarget.name + " has no ID!", gameObject); } } else { npcData.followTargetID = 0; npcData.followTargetIsPlayer = followTargetIsPlayer; npcData.followFrequency = followFrequency; npcData.followDistance = followDistance; npcData.followDistanceMax = followDistanceMax; //followFaceWhenIdle = false; npcData.followFaceWhenIdle = followFaceWhenIdle; npcData.followRandomDirection = followRandomDirection; } } else { npcData.followTargetID = 0; npcData.followTargetIsPlayer = false; npcData.followFrequency = 0f; npcData.followDistance = 0f; npcData.followDistanceMax = 0f; npcData.followFaceWhenIdle = false; npcData.followRandomDirection = false; } if (headFacing == HeadFacing.Manual && headTurnTarget != null) { npcData.isHeadTurning = true; npcData.headTargetID = Serializer.GetConstantID(headTurnTarget); if (npcData.headTargetID == 0) { ACDebug.LogWarning("The NPC " + gameObject.name + "'s head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID", gameObject); } npcData.headTargetX = headTurnTargetOffset.x; npcData.headTargetY = headTurnTargetOffset.y; npcData.headTargetZ = headTurnTargetOffset.z; } else { npcData.isHeadTurning = false; npcData.headTargetID = 0; npcData.headTargetX = 0f; npcData.headTargetY = 0f; npcData.headTargetZ = 0f; } if (GetComponentInChildren <FollowSortingMap>() != null) { FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>(); npcData.followSortingMap = followSortingMap.followSortingMap; if (!npcData.followSortingMap && followSortingMap.GetSortingMap() != null) { if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null) { npcData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("The NPC " + gameObject.name + "'s SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID"); npcData.customSortingMapID = 0; } } else { npcData.customSortingMapID = 0; } } else { npcData.followSortingMap = false; npcData.customSortingMapID = 0; } return(npcData); }
private void Export() { #if UNITY_WEBPLAYER ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again."); #else if (speechManager == null || exportColumns == null || exportColumns.Count == 0 || speechManager.lines == null || speechManager.lines.Count == 0) { return; } string suggestedFilename = string.Empty; if (AdvGame.GetReferences().settingsManager) { suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - "; } suggestedFilename += "GameText.csv"; string fileName = EditorUtility.SaveFilePanel("Export game text", "Assets", suggestedFilename, "csv"); if (fileName.Length == 0) { return; } string[] sceneNames = speechManager.GetSceneNames(); List <SpeechLine> exportLines = new List <SpeechLine>(); foreach (SpeechLine line in speechManager.lines) { if (filterByType) { if (line.textType != typeFilter) { continue; } } if (filterByScene) { if (sceneNames != null && sceneNames.Length > sceneFilter) { string selectedScene = sceneNames[sceneFilter] + ".unity"; string scenePlusExtension = (string.IsNullOrEmpty(line.scene)) ? string.Empty : (line.scene + ".unity"); if ((string.IsNullOrEmpty(line.scene) && sceneFilter == 0) || sceneFilter == 1 || (!string.IsNullOrEmpty(line.scene) && sceneFilter > 1 && line.scene.EndsWith(selectedScene)) || (!string.IsNullOrEmpty(line.scene) && sceneFilter > 1 && scenePlusExtension.EndsWith(selectedScene))) { } else { continue; } } } if (filterByText) { if (!line.Matches(textFilter, filterSpeechLine)) { continue; } } if (filterByTag) { if (tagFilter == -1 || (tagFilter < speechManager.speechTags.Count && line.tagID == speechManager.speechTags[tagFilter].ID)) { } else { continue; } } exportLines.Add(new SpeechLine(line)); } if (doRowSorting) { switch (rowSorting) { case RowSorting.ByID: exportLines.Sort((a, b) => a.lineID.CompareTo(b.lineID)); break; case RowSorting.ByDescription: exportLines.Sort((a, b) => string.Compare(a.description, b.description, System.StringComparison.Ordinal)); break; case RowSorting.ByType: exportLines.Sort((a, b) => string.Compare(a.textType.ToString(), b.textType.ToString(), System.StringComparison.Ordinal)); break; case RowSorting.ByAssociatedObject: exportLines.Sort((a, b) => string.Compare(a.owner, b.owner, System.StringComparison.Ordinal)); break; case RowSorting.ByScene: exportLines.Sort((a, b) => string.Compare(a.scene, b.scene, System.StringComparison.Ordinal)); break; default: break; } } List <string[]> output = new List <string[]>(); string[] languagesArray = speechManager.languages.ToArray(); List <string> headerList = new List <string>(); headerList.Add("ID"); foreach (ExportColumn exportColumn in exportColumns) { headerList.Add(exportColumn.GetHeader(languagesArray)); } output.Add(headerList.ToArray()); foreach (SpeechLine line in exportLines) { List <string> rowList = new List <string>(); rowList.Add(line.lineID.ToString()); foreach (ExportColumn exportColumn in exportColumns) { string cellText = exportColumn.GetCellText(line); rowList.Add(cellText); } output.Add(rowList.ToArray()); } string fileContents = CSVReader.CreateCSVGrid(output); if (!string.IsNullOrEmpty(fileContents) && Serializer.SaveFile(fileName, fileContents)) { int numLines = exportLines.Count; ACDebug.Log(numLines.ToString() + " line" + ((numLines != 1) ? "s" : string.Empty) + " exported."); } #endif }