/** * <summary>Serialises appropriate GameObject values into a string.</summary> * <returns>The data, serialised as a string</returns> */ public override string SaveData() { TimelineData timelineData = new TimelineData(); timelineData.objectID = constantID; timelineData.savePrevented = savePrevented; #if UNITY_2017_1_OR_NEWER PlayableDirector director = GetComponent <PlayableDirector>(); timelineData.isPlaying = (director.state == PlayState.Playing); timelineData.currentTime = director.time; timelineData.trackObjectData = ""; timelineData.timelineAssetID = ""; if (director.playableAsset != null) { TimelineAsset timeline = (TimelineAsset)director.playableAsset; if (timeline != null) { if (saveTimelineAsset) { timelineData.timelineAssetID = AssetLoader.GetAssetInstanceID(timeline); } if (saveBindings) { int[] bindingIDs = new int[timeline.outputTrackCount]; for (int i = 0; i < bindingIDs.Length; i++) { TrackAsset trackAsset = timeline.GetOutputTrack(i); GameObject trackObject = director.GetGenericBinding(trackAsset) as GameObject; bindingIDs[i] = 0; if (trackObject != null) { ConstantID cIDComponent = trackObject.GetComponent <ConstantID>(); if (cIDComponent != null) { bindingIDs[i] = cIDComponent.constantID; } } } for (int i = 0; i < bindingIDs.Length; i++) { timelineData.trackObjectData += bindingIDs[i].ToString(); if (i < (bindingIDs.Length - 1)) { timelineData.trackObjectData += ","; } } } } } #else ACDebug.LogWarning("The 'Remember Director' component is only compatible with Unity 5.6 onward.", this); #endif return(Serializer.SaveScriptData <TimelineData> (timelineData)); }
/** * <summary>Serialises appropriate GameObject values into a string.</summary> * <returns>The data, serialised as a string</returns> */ public override string SaveData() { VideoPlayerData videoPlayerData = new VideoPlayerData(); videoPlayerData.objectID = constantID; videoPlayerData.savePrevented = savePrevented; if (GetComponent <VideoPlayer>()) { VideoPlayer videoPlayer = GetComponent <VideoPlayer>(); videoPlayerData.isPlaying = videoPlayer.isPlaying; videoPlayerData.currentFrame = videoPlayer.frame; videoPlayerData.currentTime = videoPlayer.time; if (saveClipAsset) { if (videoPlayer.clip != null) { videoPlayerData.clipAssetID = AssetLoader.GetAssetInstanceID(videoPlayer.clip); } } } return(Serializer.SaveScriptData <VideoPlayerData> (videoPlayerData)); }
/** * <summary>Updates a SoundData class with its own variables that need saving.</summary> * <param name = "soundData">The original SoundData class</param> * <returns>The updated SoundData class</returns> */ public SoundData GetSaveData(SoundData soundData) { soundData.isPlaying = IsPlaying(); soundData.isLooping = audioSource.loop; soundData.samplePoint = audioSource.timeSamples; soundData.relativeVolume = relativeVolume; soundData.maxVolume = maxVolume; soundData.smoothVolume = smoothVolume; soundData.fadeTime = fadeTime; soundData.originalFadeTime = originalFadeTime; soundData.fadeType = (int)fadeType; soundData.otherVolume = otherVolume; soundData.originalRelativeVolume = originalRelativeVolume; soundData.targetRelativeVolume = targetRelativeVolume; soundData.relativeChangeTime = relativeChangeTime; soundData.originalRelativeChangeTime = originalRelativeChangeTime; if (audioSource.clip != null) { soundData.clipID = AssetLoader.GetAssetInstanceID(audioSource.clip); } return(soundData); }
public override string SaveData() { Sound sound = GetComponent <Sound>(); AudioSource audioSource = GetComponent <AudioSource>(); SoundData soundData = new SoundData(); soundData.objectID = constantID; if (sound.IsFadingOut()) { soundData.isPlaying = false; } else { soundData.isPlaying = sound.IsPlaying(); } soundData.isLooping = audioSource.loop; soundData.samplePoint = audioSource.timeSamples; soundData.relativeVolume = sound.relativeVolume; if (audioSource.clip != null) { soundData.clipID = AssetLoader.GetAssetInstanceID(audioSource.clip); } return(Serializer.SaveScriptData <SoundData> (soundData)); }
/** * <summary>Serialises appropriate GameObject values into a string.</summary> * <returns>The data, serialised as a string</returns> */ public override string SaveData() { TimelineData timelineData = new TimelineData(); timelineData.objectID = constantID; timelineData.savePrevented = savePrevented; PlayableDirector director = GetComponent <PlayableDirector>(); timelineData.isPlaying = (director.state == PlayState.Playing); timelineData.currentTime = director.time; timelineData.trackObjectData = string.Empty; timelineData.timelineAssetID = string.Empty; if (director.playableAsset != null) { #if !ACIgnoreTimeline TimelineAsset timeline = (TimelineAsset)director.playableAsset; if (timeline != null) { if (saveTimelineAsset) { timelineData.timelineAssetID = AssetLoader.GetAssetInstanceID(timeline); } if (saveBindings) { int[] bindingIDs = new int[timeline.outputTrackCount]; for (int i = 0; i < bindingIDs.Length; i++) { TrackAsset trackAsset = timeline.GetOutputTrack(i); GameObject trackObject = director.GetGenericBinding(trackAsset) as GameObject; bindingIDs[i] = 0; if (trackObject != null) { ConstantID cIDComponent = trackObject.GetComponent <ConstantID>(); if (cIDComponent != null) { bindingIDs[i] = cIDComponent.constantID; } } } for (int i = 0; i < bindingIDs.Length; i++) { timelineData.trackObjectData += bindingIDs[i].ToString(); if (i < (bindingIDs.Length - 1)) { timelineData.trackObjectData += ","; } } } } #endif } return(Serializer.SaveScriptData <TimelineData> (timelineData)); }
public override NPCData SaveNPCData(NPCData npcData, NPC npc) { npcData.idleAnim = AssetLoader.GetAssetInstanceID(npc.idleAnim); npcData.walkAnim = AssetLoader.GetAssetInstanceID(npc.walkAnim); npcData.runAnim = AssetLoader.GetAssetInstanceID(npc.runAnim); npcData.talkAnim = AssetLoader.GetAssetInstanceID(npc.talkAnim); return(npcData); }
public override PlayerData SavePlayerData(PlayerData playerData, Player player) { playerData.playerIdleAnim = AssetLoader.GetAssetInstanceID(player.idleAnim); playerData.playerWalkAnim = AssetLoader.GetAssetInstanceID(player.walkAnim); playerData.playerRunAnim = AssetLoader.GetAssetInstanceID(player.runAnim); playerData.playerTalkAnim = AssetLoader.GetAssetInstanceID(player.talkAnim); return(playerData); }
public override string SaveData() { AnimatorData animatorData = new AnimatorData(); animatorData.objectID = constantID; animatorData.savePrevented = savePrevented; if (saveController && _animator.runtimeAnimatorController != null) { animatorData.controllerID = AssetLoader.GetAssetInstanceID(_animator.runtimeAnimatorController); } animatorData.parameterData = ParameterValuesToString(Animator.parameters); animatorData.layerWeightData = LayerWeightsToString(); animatorData.stateData = StatesToString(); return(Serializer.SaveScriptData <AnimatorData> (animatorData)); }
/** * <summary>Serialises appropriate GameObject values into a string.</summary> * <returns>The data, serialised as a string</returns> */ public override string SaveData() { MaterialData materialData = new MaterialData(); materialData.objectID = constantID; List <string> materialIDs = new List <string>(); Material[] mats = GetComponent <Renderer>().materials; foreach (Material material in mats) { materialIDs.Add(AssetLoader.GetAssetInstanceID(material)); } materialData._materialIDs = ArrayToString <string> (materialIDs.ToArray()); return(Serializer.SaveScriptData <MaterialData> (materialData)); }
private string SoundsToString(AudioClip[] audioClips) { StringBuilder soundString = new StringBuilder(); for (int i = 0; i < audioClips.Length; i++) { if (audioClips[i] != null) { soundString.Append(AssetLoader.GetAssetInstanceID(audioClips[i])); if (i < audioClips.Length - 1) { soundString.Append(SaveSystem.pipe); } } } return(soundString.ToString()); }
public override float Run() { if (newPortraitGraphic == null) { return(0f); } if (runtimeChar != null) { runtimeChar.portraitIcon.ReplaceTexture(newPortraitGraphic); } else if (playerID >= 0 && KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow && KickStarter.saveSystem.CurrentPlayerID != playerID) { // Special case: Player is not in the scene, so manually update their PlayerData PlayerData playerData = KickStarter.saveSystem.GetPlayerData(playerID); if (playerData != null) { playerData.playerPortraitGraphic = AssetLoader.GetAssetInstanceID(newPortraitGraphic); } } return(0f); }
/** * <summary>Updates a PlayerData class with its own variables that need saving.</summary> * <param name = "playerData">The original PlayerData class</param> * <returns>The updated PlayerData class</returns> */ public PlayerData SavePlayerData(PlayerData playerData) { playerData.playerID = ID; playerData.playerLocX = transform.position.x; playerData.playerLocY = transform.position.y; playerData.playerLocZ = transform.position.z; playerData.playerRotY = TransformRotation.eulerAngles.y; playerData.playerWalkSpeed = walkSpeedScale; playerData.playerRunSpeed = runSpeedScale; // Animation clips if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity) { playerData.playerIdleAnim = idleAnimSprite; playerData.playerWalkAnim = walkAnimSprite; playerData.playerRunAnim = runAnimSprite; playerData.playerTalkAnim = talkAnimSprite; } else if (animationEngine == AnimationEngine.Legacy) { playerData.playerIdleAnim = AssetLoader.GetAssetInstanceID(idleAnim); playerData.playerWalkAnim = AssetLoader.GetAssetInstanceID(walkAnim); playerData.playerRunAnim = AssetLoader.GetAssetInstanceID(runAnim); playerData.playerTalkAnim = AssetLoader.GetAssetInstanceID(talkAnim); } else if (animationEngine == AnimationEngine.Mecanim) { playerData.playerWalkAnim = moveSpeedParameter; playerData.playerTalkAnim = talkParameter; playerData.playerRunAnim = turnParameter; } // Sound playerData.playerWalkSound = AssetLoader.GetAssetInstanceID(walkSound); playerData.playerRunSound = AssetLoader.GetAssetInstanceID(runSound); // Portrait graphic playerData.playerPortraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture); // Speech label playerData.playerSpeechLabel = GetName(); playerData.playerDisplayLineID = displayLineID; // Rendering playerData.playerLockDirection = lockDirection; playerData.playerLockScale = lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting; } else if (GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = GetComponent <FollowSortingMap>().lockSorting; } else { playerData.playerLockSorting = false; } playerData.playerSpriteDirection = spriteDirection; playerData.playerSpriteScale = spriteScale; if (spriteChild && spriteChild.GetComponent <Renderer>()) { playerData.playerSortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName; } else if (GetComponent <Renderer>()) { playerData.playerSortingOrder = GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = GetComponent <Renderer>().sortingLayerName; } playerData.playerActivePath = 0; playerData.lastPlayerActivePath = 0; if (GetPath()) { playerData.playerTargetNode = GetTargetNode(); playerData.playerPrevNode = GetPrevNode(); playerData.playerIsRunning = isRunning; playerData.playerPathAffectY = activePath.affectY; if (GetComponent <Paths>() && GetPath() == GetComponent <Paths>()) { playerData.playerPathData = Serializer.CreatePathData(GetComponent <Paths>()); playerData.playerLockedPath = false; } else { playerData.playerPathData = ""; playerData.playerActivePath = Serializer.GetConstantID(GetPath().gameObject); playerData.playerLockedPath = lockedPath; } } if (GetLastPath()) { playerData.lastPlayerTargetNode = GetLastTargetNode(); playerData.lastPlayerPrevNode = GetLastPrevNode(); playerData.lastPlayerActivePath = Serializer.GetConstantID(GetLastPath().gameObject); } playerData.playerIgnoreGravity = ignoreGravity; // Head target playerData.playerLockHotspotHeadTurning = lockHotspotHeadTurning; if (headFacing == HeadFacing.Manual && headTurnTarget != null) { playerData.isHeadTurning = true; playerData.headTargetID = Serializer.GetConstantID(headTurnTarget); if (playerData.headTargetID == 0) { ACDebug.LogWarning("The Player's head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID"); } playerData.headTargetX = headTurnTargetOffset.x; playerData.headTargetY = headTurnTargetOffset.y; playerData.headTargetZ = headTurnTargetOffset.z; } else { playerData.isHeadTurning = false; playerData.headTargetID = 0; playerData.headTargetX = 0f; playerData.headTargetY = 0f; playerData.headTargetZ = 0f; } if (GetComponentInChildren <FollowSortingMap>() != null) { FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>(); playerData.followSortingMap = followSortingMap.followSortingMap; if (!playerData.followSortingMap && followSortingMap.GetSortingMap() != null) { if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null) { playerData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("The Player's SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID"); playerData.customSortingMapID = 0; } } else { playerData.customSortingMapID = 0; } } else { playerData.followSortingMap = false; playerData.customSortingMapID = 0; } return(playerData); }
/** * <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; npcData.inCustomCharState = (charState == CharState.Custom && GetAnimator() != null && GetAnimator().GetComponent <RememberAnimator>()); 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); }
/** * <summary>Updates a PlayerData class with its own variables that need saving.</summary> * <param name = "playerData">The original PlayerData class</param> * <returns>The updated PlayerData class</returns> */ public PlayerData SaveData(PlayerData playerData) { playerData.playerID = ID; playerData.playerLocX = transform.position.x; playerData.playerLocY = transform.position.y; playerData.playerLocZ = transform.position.z; playerData.playerRotY = TransformRotation.eulerAngles.y; playerData.inCustomCharState = (charState == CharState.Custom && GetAnimator() != null && GetAnimator().GetComponent <RememberAnimator>()); playerData.playerWalkSpeed = walkSpeedScale; playerData.playerRunSpeed = runSpeedScale; playerData.playerUpLock = upMovementLocked; playerData.playerDownLock = downMovementLocked; playerData.playerLeftlock = leftMovementLocked; playerData.playerRightLock = rightMovementLocked; playerData.playerRunLock = (int)runningLocked; playerData.playerFreeAimLock = freeAimLocked; // Animation clips playerData = GetAnimEngine().SavePlayerData(playerData, this); // Sound playerData.playerWalkSound = AssetLoader.GetAssetInstanceID(walkSound); playerData.playerRunSound = AssetLoader.GetAssetInstanceID(runSound); // Portrait graphic playerData.playerPortraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture); // Speech label playerData.playerSpeechLabel = GetName(); playerData.playerDisplayLineID = displayLineID; // Rendering playerData.playerLockDirection = lockDirection; playerData.playerLockScale = lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting; } else if (GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = GetComponent <FollowSortingMap>().lockSorting; } else { playerData.playerLockSorting = false; } playerData.playerSpriteDirection = GetSpriteDirectionToSave(); playerData.playerSpriteScale = spriteScale; if (spriteChild && spriteChild.GetComponent <Renderer>()) { playerData.playerSortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName; } else if (GetComponent <Renderer>()) { playerData.playerSortingOrder = GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = GetComponent <Renderer>().sortingLayerName; } playerData.playerActivePath = 0; playerData.lastPlayerActivePath = 0; if (GetPath()) { playerData.playerTargetNode = GetTargetNode(); playerData.playerPrevNode = GetPreviousNode(); playerData.playerIsRunning = isRunning; playerData.playerPathAffectY = activePath.affectY; if (GetComponent <Paths>() && GetPath() == GetComponent <Paths>()) { playerData.playerPathData = Serializer.CreatePathData(GetComponent <Paths>()); playerData.playerLockedPath = false; } else { playerData.playerPathData = string.Empty; playerData.playerActivePath = Serializer.GetConstantID(GetPath().gameObject); playerData.playerLockedPath = lockedPath; } } if (GetLastPath()) { playerData.lastPlayerTargetNode = GetLastTargetNode(); playerData.lastPlayerPrevNode = GetLastPrevNode(); playerData.lastPlayerActivePath = Serializer.GetConstantID(GetLastPath().gameObject); } playerData.playerIgnoreGravity = ignoreGravity; // Head target playerData.playerLockHotspotHeadTurning = lockHotspotHeadTurning; if (headFacing == HeadFacing.Manual && headTurnTarget != null) { playerData.isHeadTurning = true; playerData.headTargetID = Serializer.GetConstantID(headTurnTarget); if (playerData.headTargetID == 0) { ACDebug.LogWarning("The Player's head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID", gameObject); } playerData.headTargetX = headTurnTargetOffset.x; playerData.headTargetY = headTurnTargetOffset.y; playerData.headTargetZ = headTurnTargetOffset.z; } else { playerData.isHeadTurning = false; playerData.headTargetID = 0; playerData.headTargetX = 0f; playerData.headTargetY = 0f; playerData.headTargetZ = 0f; } FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>(); if (followSortingMap != null) { playerData.followSortingMap = followSortingMap.followSortingMap; if (!playerData.followSortingMap && followSortingMap.GetSortingMap() != null) { if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null) { playerData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("The Player's SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID", gameObject); playerData.customSortingMapID = 0; } } else { playerData.customSortingMapID = 0; } } else { playerData.followSortingMap = false; playerData.customSortingMapID = 0; } // Inactive Player follow if (followTarget != null && !IsActivePlayer()) { if (!followTargetIsPlayer) { if (followTarget.GetComponent <ConstantID> ()) { playerData.followTargetID = followTarget.GetComponent <ConstantID> ().constantID; playerData.followTargetIsPlayer = followTargetIsPlayer; playerData.followFrequency = followFrequency; playerData.followDistance = followDistance; playerData.followDistanceMax = followDistanceMax; playerData.followFaceWhenIdle = followFaceWhenIdle; playerData.followRandomDirection = followRandomDirection; } else { ACDebug.LogWarning("Want to save follow data for " + name + " but " + followTarget.name + " has no ID!", gameObject); } } else { playerData.followTargetID = 0; playerData.followTargetIsPlayer = followTargetIsPlayer; playerData.followFrequency = followFrequency; playerData.followDistance = followDistance; playerData.followDistanceMax = followDistanceMax; playerData.followFaceWhenIdle = followFaceWhenIdle; playerData.followRandomDirection = followRandomDirection; } } else { playerData.followTargetID = 0; playerData.followTargetIsPlayer = false; playerData.followFrequency = 0f; playerData.followDistance = 0f; playerData.followDistanceMax = 0f; playerData.followFaceWhenIdle = false; playerData.followRandomDirection = false; } playerData.leftHandIKState = LeftHandIKController.CreateSaveData(); playerData.rightHandIKState = RightHandIKController.CreateSaveData(); playerData.spriteDirectionData = spriteDirectionData.SaveData(); // Remember scripts if (!IsLocalPlayer() && gameObject.activeInHierarchy) { playerData = KickStarter.levelStorage.SavePlayerData(this, playerData); } return(playerData); }
public override string SaveData() { NPCData npcData = new NPCData(); npcData.objectID = constantID; if (gameObject.layer == LayerMask.NameToLayer(KickStarter.settingsManager.hotspotLayer)) { npcData.isOn = true; } else { npcData.isOn = false; } npcData.LocX = transform.position.x; npcData.LocY = transform.position.y; npcData.LocZ = transform.position.z; npcData.RotX = transform.eulerAngles.x; npcData.RotY = transform.eulerAngles.y; npcData.RotZ = transform.eulerAngles.z; npcData.ScaleX = transform.localScale.x; npcData.ScaleY = transform.localScale.y; npcData.ScaleZ = transform.localScale.z; if (GetComponent <NPC>()) { NPC npc = GetComponent <NPC>(); if (npc.animationEngine == AnimationEngine.Sprites2DToolkit || npc.animationEngine == AnimationEngine.SpritesUnity) { npcData.idleAnim = npc.idleAnimSprite; npcData.walkAnim = npc.walkAnimSprite; npcData.talkAnim = npc.talkAnimSprite; npcData.runAnim = npc.runAnimSprite; } else if (npc.animationEngine == AnimationEngine.Legacy) { npcData.idleAnim = AssetLoader.GetAssetInstanceID(npc.idleAnim); npcData.walkAnim = AssetLoader.GetAssetInstanceID(npc.walkAnim); npcData.runAnim = AssetLoader.GetAssetInstanceID(npc.runAnim); npcData.talkAnim = AssetLoader.GetAssetInstanceID(npc.talkAnim); } else if (npc.animationEngine == AnimationEngine.Mecanim) { npcData.walkAnim = npc.moveSpeedParameter; npcData.talkAnim = npc.talkParameter; npcData.runAnim = npc.turnParameter; } npcData.walkSound = AssetLoader.GetAssetInstanceID(npc.walkSound); npcData.runSound = AssetLoader.GetAssetInstanceID(npc.runSound); npcData.speechLabel = npc.speechLabel; npcData.portraitGraphic = AssetLoader.GetAssetInstanceID(npc.portraitIcon.texture); npcData.walkSpeed = npc.walkSpeedScale; npcData.runSpeed = npc.runSpeedScale; // Rendering npcData.lockDirection = npc.lockDirection; npcData.lockScale = npc.lockScale; if (npc.spriteChild && npc.spriteChild.GetComponent <FollowSortingMap>()) { npcData.lockSorting = npc.spriteChild.GetComponent <FollowSortingMap>().lockSorting; } else if (npc.GetComponent <FollowSortingMap>()) { npcData.lockSorting = npc.GetComponent <FollowSortingMap>().lockSorting; } else { npcData.lockSorting = false; } npcData.spriteDirection = npc.spriteDirection; npcData.spriteScale = npc.spriteScale; if (npc.spriteChild && npc.spriteChild.GetComponent <Renderer>()) { npcData.sortingOrder = npc.spriteChild.GetComponent <Renderer>().sortingOrder; npcData.sortingLayer = npc.spriteChild.GetComponent <Renderer>().sortingLayerName; } else if (npc.GetComponent <Renderer>()) { npcData.sortingOrder = npc.GetComponent <Renderer>().sortingOrder; npcData.sortingLayer = npc.GetComponent <Renderer>().sortingLayerName; } npcData.pathID = 0; npcData.lastPathID = 0; if (npc.GetPath(true)) { npcData.targetNode = npc.GetTargetNode(true); npcData.prevNode = npc.GetPrevNode(true); npcData.isRunning = npc.isRunning; npcData.pathAffectY = npc.activePath.affectY; if (npc.GetPath(true) == GetComponent <Paths>()) { npcData.pathData = Serializer.CreatePathData(GetComponent <Paths>()); } else { if (npc.GetPath(true).GetComponent <ConstantID>()) { npcData.pathID = npc.GetPath(true).GetComponent <ConstantID>().constantID; } else { Debug.LogWarning("Want to save path data for " + name + " but path has no ID!"); } } } if (npc.GetPath(false)) { npcData.lastTargetNode = npc.GetTargetNode(false); npcData.lastPrevNode = npc.GetPrevNode(false); if (npc.GetPath(false).GetComponent <ConstantID>()) { npcData.lastPathID = npc.GetPath(false).GetComponent <ConstantID>().constantID; } else { Debug.LogWarning("Want to save previous path data for " + name + " but path has no ID!"); } } if (npc.followTarget) { if (!npc.followTargetIsPlayer) { if (npc.followTarget.GetComponent <ConstantID>()) { npcData.followTargetID = npc.followTarget.GetComponent <ConstantID>().constantID; npcData.followTargetIsPlayer = npc.followTargetIsPlayer; npcData.followFrequency = npc.followFrequency; npcData.followDistance = npc.followDistance; npcData.followDistanceMax = npc.followDistanceMax; } else { Debug.LogWarning("Want to save follow data for " + name + " but " + npc.followTarget.name + " has no ID!"); } } else { npcData.followTargetID = 0; npcData.followTargetIsPlayer = npc.followTargetIsPlayer; npcData.followFrequency = npc.followFrequency; npcData.followDistance = npc.followDistance; npcData.followDistanceMax = npc.followDistanceMax; } } else { npcData.followTargetID = 0; npcData.followTargetIsPlayer = false; npcData.followFrequency = 0f; npcData.followDistance = 0f; npcData.followDistanceMax = 0f; } if (npc.headFacing == HeadFacing.Manual) { npcData.isHeadTurning = true; npcData.headTargetX = npc.headTurnTarget.x; npcData.headTargetY = npc.headTurnTarget.y; npcData.headTargetZ = npc.headTurnTarget.z; } else { npcData.isHeadTurning = false; npcData.headTargetX = 0f; npcData.headTargetY = 0f; npcData.headTargetZ = 0f; } } return(Serializer.SaveScriptData <NPCData> (npcData)); }