/** * <summary>Updates its own variables from a PlayerData class.</summary> * <param name = "playerData">The PlayerData class to load from</param> */ public void LoadData(PlayerData playerData) { upMovementLocked = playerData.playerUpLock; downMovementLocked = playerData.playerDownLock; leftMovementLocked = playerData.playerLeftlock; rightMovementLocked = playerData.playerRightLock; runningLocked = (PlayerMoveLock)playerData.playerRunLock; freeAimLocked = playerData.playerFreeAimLock; charState = (playerData.inCustomCharState) ? CharState.Custom : CharState.Idle; playerData.UpdateFromTempPosition(this); Teleport(new Vector3(playerData.playerLocX, playerData.playerLocY, playerData.playerLocZ)); SetRotation(playerData.playerRotY); SetMoveDirectionAsForward(); walkSpeedScale = playerData.playerWalkSpeed; runSpeedScale = playerData.playerRunSpeed; // Animation clips GetAnimEngine().LoadPlayerData(playerData, this); // Sound walkSound = AssetLoader.RetrieveAsset(walkSound, playerData.playerWalkSound); runSound = AssetLoader.RetrieveAsset(runSound, playerData.playerRunSound); // Portrait graphic portraitIcon.ReplaceTexture(AssetLoader.RetrieveAsset(portraitIcon.texture, playerData.playerPortraitGraphic)); // Speech label SetName(playerData.playerSpeechLabel, playerData.playerDisplayLineID); // Rendering lockDirection = playerData.playerLockDirection; lockScale = playerData.playerLockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting; } else { ReleaseSorting(); } if (playerData.playerLockDirection) { spriteDirection = playerData.playerSpriteDirection; UpdateFrameFlipping(true); } if (playerData.playerLockScale) { spriteScale = playerData.playerSpriteScale; } if (playerData.playerLockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder; GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer; } } // Inactive following AC.Char charToFollow = null; if (playerData.followTargetID != 0) { RememberNPC followNPC = ConstantID.GetComponent <RememberNPC> (playerData.followTargetID); if (followNPC.GetComponent <AC.Char> ()) { charToFollow = followNPC.GetComponent <AC.Char> (); } } if (charToFollow != null || (playerData.followTargetIsPlayer && KickStarter.player != null)) { FollowAssign(charToFollow, playerData.followTargetIsPlayer, playerData.followFrequency, playerData.followDistance, playerData.followDistanceMax, playerData.followFaceWhenIdle, playerData.followRandomDirection); } else { StopFollowing(); } // Active path Halt(); ForceIdle(); if (!string.IsNullOrEmpty(playerData.playerPathData) && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, playerData.playerPathData); SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode, playerData.playerPathAffectY); isRunning = playerData.playerIsRunning; lockedPath = false; } else if (playerData.playerActivePath != 0) { Paths savedPath = ConstantID.GetComponent <Paths> (playerData.playerActivePath); if (savedPath) { lockedPath = playerData.playerLockedPath; if (lockedPath) { SetLockedPath(savedPath); } else { SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode); } } else { Halt(); ForceIdle(); } } else { Halt(); ForceIdle(); } // Previous path if (playerData.lastPlayerActivePath != 0) { Paths savedPath = ConstantID.GetComponent <Paths> (playerData.lastPlayerActivePath); if (savedPath) { SetLastPath(savedPath, playerData.lastPlayerTargetNode, playerData.lastPlayerPrevNode); } } // Head target lockHotspotHeadTurning = playerData.playerLockHotspotHeadTurning; if (playerData.isHeadTurning) { ConstantID _headTargetID = ConstantID.GetComponent <ConstantID> (playerData.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(playerData.headTargetX, playerData.headTargetY, playerData.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } ignoreGravity = playerData.playerIgnoreGravity; if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = ConstantID.GetComponent <SortingMap> (playerData.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = playerData.followSortingMap; if (!playerData.followSortingMap && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } ignoreGravity = playerData.playerIgnoreGravity; if (GetAnimEngine() != null && GetAnimEngine().IKEnabled) { LeftHandIKController.LoadData(playerData.leftHandIKState); RightHandIKController.LoadData(playerData.rightHandIKState); } _spriteDirectionData.LoadData(playerData.spriteDirectionData); // Remember scripts if (!IsLocalPlayer()) { KickStarter.levelStorage.LoadPlayerData(this, playerData); } }
/** * <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)) { FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection, false); } 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) { 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) { 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) { 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) { 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 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); }
/** * <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() && GetAnimator().GetComponent <RememberAnimator>()); // Animation npcData = GetAnimEngine().SaveNPCData(npcData, this); 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 = GetSpriteDirectionToSave(); 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) { 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>()) { FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>(); npcData.followSortingMap = followSortingMap.followSortingMap; if (!npcData.followSortingMap && followSortingMap.GetSortingMap()) { ConstantID followSortingMapConstantID = followSortingMap.GetSortingMap().GetComponent <ConstantID>(); if (followSortingMapConstantID) { npcData.customSortingMapID = followSortingMapConstantID.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; } npcData.leftHandIKState = LeftHandIKController.CreateSaveData(); npcData.rightHandIKState = RightHandIKController.CreateSaveData(); npcData.spriteDirectionData = spriteDirectionData.SaveData(); return(npcData); }