/** * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary> * <param name = "stringData">The data, serialised as a string</param> */ public void LoadTransformData(TransformData data) { if (data == null) { return; } savePrevented = data.savePrevented; if (savePrevented) { return; } if (data.parentIsPlayer) { if (KickStarter.player) { if (data.heldHand == Hand.Left) { transform.parent = KickStarter.player.leftHandBone; } else { transform.parent = KickStarter.player.rightHandBone; } } } else if (data.parentID != 0) { ConstantID parentObject = Serializer.returnComponent <ConstantID> (data.parentID); if (parentObject != null) { if (data.parentIsNPC && parentObject.GetComponent <NPC>()) { if (data.heldHand == Hand.Left) { transform.parent = parentObject.GetComponent <NPC>().leftHandBone; } else { transform.parent = parentObject.GetComponent <NPC>().rightHandBone; } } else { transform.parent = parentObject.gameObject.transform; } } } else if (data.parentID == 0 && saveParent) { transform.parent = null; } transform.position = new Vector3(data.LocX, data.LocY, data.LocZ); transform.eulerAngles = new Vector3(data.RotX, data.RotY, data.RotZ); transform.localScale = new Vector3(data.ScaleX, data.ScaleY, data.ScaleZ); }
/** Creates a new instance of the class from string data */ public static IKCommand LoadData(string data) { string[] dataArray = data.Split(":"[0]); if (dataArray.Length != 2) { return(null); } string targetData = dataArray[0]; int targetID = 0; if (int.TryParse(targetData, out targetID)) { if (targetID != 0) { ConstantID targetConstantID = ConstantID.GetComponent(targetID); if (targetConstantID != null) { string curveData = dataArray[1]; AnimationCurve transitionCurve = StringToCurve(curveData); if (transitionCurve != null) { return(new IKCommand(targetConstantID.transform, transitionCurve, true)); } } else { ACDebug.LogWarning("Could not find IK target with Constant ID = " + targetID); } } } return(null); }
public void ShowStartDataGUI(string apiPrefix) { GUILayout.Label("Starting point data for Player " + ID.ToString() + ": " + ((playerOb) ? playerOb.name : "(EMPTY)"), EditorStyles.boldLabel); chooseSceneBy = (ChooseSceneBy)CustomGUILayout.EnumPopup("Choose scene by:", chooseSceneBy); switch (chooseSceneBy) { case ChooseSceneBy.Name: startingSceneName = CustomGUILayout.TextField("Scene name:", startingSceneName); break; case ChooseSceneBy.Number: startingSceneIndex = CustomGUILayout.IntField("Scene index:", startingSceneIndex); break; } useSceneDefaultPlayerStart = EditorGUILayout.Toggle("Use default PlayerStart?", useSceneDefaultPlayerStart); if (!useSceneDefaultPlayerStart) { PlayerStart playerStart = ConstantID.GetComponent <PlayerStart> (startingPlayerStartID); playerStart = (PlayerStart)CustomGUILayout.ObjectField <PlayerStart> ("PlayerStart:", playerStart, true, apiPrefix + ".startingPlayerStartID", "The PlayerStart that this character starts from."); startingPlayerStartID = FieldToID <PlayerStart> (playerStart, startingPlayerStartID); if (startingPlayerStartID != 0) { CustomGUILayout.BeginVertical(); EditorGUILayout.LabelField("Recorded ConstantID: " + startingPlayerStartID.ToString(), EditorStyles.miniLabel); CustomGUILayout.EndVertical(); } } }
/** * <summary>Updates the record of the Player's current position, based on data made when their scene was not active</summary> * <param name = "sceneInstance">The scene instance of the Player to affect</param> */ public void UpdateFromTempPosition(Player sceneInstance) { if (tempPlayerStart == 0) { return; } PlayerStart playerStart = null; switch (tempTeleportPlayerStartMethod) { case TeleportPlayerStartMethod.SceneDefault: playerStart = KickStarter.sceneSettings.defaultPlayerStart; break; case TeleportPlayerStartMethod.BasedOnPrevious: playerStart = KickStarter.sceneSettings.GetPlayerStart(playerID); break; case TeleportPlayerStartMethod.EnteredHere: // Search the scene the Player is in, in case the character is in a sub-scene Scene sceneToSearch = (sceneInstance.gameObject.IsPersistent()) ? SceneChanger.CurrentScene : sceneInstance.gameObject.scene; playerStart = ConstantID.GetComponent <PlayerStart> (tempPlayerStart, sceneToSearch); break; } UpdatePositionFromPlayerStart(playerStart); }
/** * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary> * <param name = "stringData">The data, serialised as a string</param> */ public override void LoadData(string stringData) { NavMesh2DData data = Serializer.LoadScriptData <NavMesh2DData> (stringData); if (data == null) { return; } SavePrevented = data.savePrevented; if (savePrevented) { return; } NavigationMesh navMesh = GetComponent <NavigationMesh>(); if (navMesh != null) { navMesh.polygonColliderHoles.Clear(); KickStarter.navigationManager.navigationEngine.ResetHoles(navMesh); if (!string.IsNullOrEmpty(data._linkedIDs)) { int[] linkedIDs = StringToIntArray(data._linkedIDs); for (int i = 0; i < linkedIDs.Length; i++) { PolygonCollider2D polyHole = ConstantID.GetComponent <PolygonCollider2D> (linkedIDs[i]); if (polyHole != null) { navMesh.AddHole(polyHole); } } } } }
private void UnloadPlayerStart(int playerStartInt, SceneSettings sceneSettings) { PlayerStart playerStart = ConstantID.GetComponent <PlayerStart> (playerStartInt, sceneSettings.gameObject.scene); if (playerStart) { sceneSettings.defaultPlayerStart = playerStart; } }
private void UnloadCutsceneOnStart(int cutsceneInt, SceneSettings sceneSettings) { Cutscene cutscene = ConstantID.GetComponent <Cutscene> (cutsceneInt, sceneSettings.gameObject.scene); if (cutscene) { sceneSettings.cutsceneOnStart = cutscene; } }
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount) { foreach (TimelineClip timelineClip in GetClips()) { SpeechPlayableClip clip = (SpeechPlayableClip)timelineClip.asset; timelineClip.displayName = clip.GetDisplayName(); Char speaker = null; if (Application.isPlaying) { if (isPlayerLine) { speaker = AssignPlayer(playerID); } else if (speakerConstantID != 0) { speaker = ConstantID.GetComponent <Char> (speakerConstantID); } } else { if (isPlayerLine) { if (KickStarter.settingsManager != null) { if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow && playerID >= 0) { PlayerPrefab playerPrefab = KickStarter.settingsManager.GetPlayerPrefab(playerID); if (playerPrefab != null) { speaker = playerPrefab.playerOb; } } else { speaker = KickStarter.settingsManager.GetDefaultPlayer(false); } } } else { speaker = SpeakerPrefab; } } clip.speechTrackPlaybackMode = playbackMode; clip.speaker = speaker; clip.trackInstanceID = GetInstanceID(); } ScriptPlayable <SpeechPlayableMixer> mixer = ScriptPlayable <SpeechPlayableMixer> .Create(graph); mixer.SetInputCount(inputCount); mixer.GetBehaviour().trackInstanceID = GetInstanceID(); mixer.GetBehaviour().playbackMode = playbackMode; return(mixer); }
private void UnloadSortingMap(int sortingMapInt, SceneSettings sceneSettings) { SortingMap sortingMap = ConstantID.GetComponent <SortingMap> (sortingMapInt, sceneSettings.gameObject.scene); if (sortingMap) { sceneSettings.sortingMap = sortingMap; KickStarter.sceneSettings.UpdateAllSortingMaps(); } }
/** * <summary>Updates its own variables from a VisibilityData class.</summary> * <param name = "data">The VisibilityData class to load from</param> */ public void LoadData(VisibilityData data) { useDefaultTintMap = data.useDefaultTintMap; SetIntensity(data.tintIntensity, 0f); if (!useDefaultTintMap && data.tintMapID != 0) { tintMap = ConstantID.GetComponent <TintMap> (data.tintMapID); } ResetTintMap(); }
/** * <summary>Updates the record of the Player's current position</summary> * <param name = "newSceneIndex">The scene in which to place the Player in</param> * <param name = "teleportPlayerStartMethod">How to select which PlayerStart to appear at (SceneDefault, BasedOnPrevious, EnteredHere)</param> * <param name = "playerStartID">The Constant ID value of the PlayerStart for the Player to appear at</param> */ public void UpdatePosition(int newSceneIndex, TeleportPlayerStartMethod teleportPlayerStartMethod, int playerStartID) { UpdateCurrentAndShiftPrevious(newSceneIndex); tempPlayerStart = 0; if (newSceneIndex == SceneChanger.CurrentSceneIndex) { // Updating position to the current scene PlayerStart playerStart = null; switch (teleportPlayerStartMethod) { case TeleportPlayerStartMethod.BasedOnPrevious: playerStart = KickStarter.sceneSettings.GetPlayerStart(playerID); break; case TeleportPlayerStartMethod.EnteredHere: if (playerStartID != 0) { playerStart = ConstantID.GetComponent <PlayerStart> (playerStartID); } break; case TeleportPlayerStartMethod.SceneDefault: playerStart = KickStarter.sceneSettings.defaultPlayerStart; break; default: break; } if (playerStart) { UpdatePositionFromPlayerStart(playerStart); } else if (teleportPlayerStartMethod == TeleportPlayerStartMethod.EnteredHere && playerStartID != 0) { ACDebug.LogWarning("Cannot find PlayerStart with Constant ID = " + playerStartID + " for Player ID = " + playerID + " in the current scene."); } else { ACDebug.LogWarning("Cannot find suitable PlayerStart for Player ID = " + playerID + " in the current scene"); } } else { // Position is being set in another scene, so keep a record of it tempTeleportPlayerStartMethod = teleportPlayerStartMethod; tempPlayerStart = (teleportPlayerStartMethod == TeleportPlayerStartMethod.EnteredHere) ? playerStartID : -1; } }
private void UnloadTintMap(int tintMapInt, SceneSettings sceneSettings) { TintMap tintMap = ConstantID.GetComponent <TintMap> (tintMapInt, sceneSettings.gameObject.scene); if (tintMap) { sceneSettings.tintMap = tintMap; // Reset all FollowTintMap components FollowTintMap[] followTintMaps = FindObjectsOfType(typeof(FollowTintMap)) as FollowTintMap[]; foreach (FollowTintMap followTintMap in followTintMaps) { followTintMap.ResetTintMap(); } } }
private void UnloadNavMesh(int navMeshInt, SceneSettings sceneSettings) { NavigationMesh navMesh = ConstantID.GetComponent <NavigationMesh> (navMeshInt, sceneSettings.gameObject.scene); if (navMesh != null && sceneSettings.navigationMethod != AC_NavigationMethod.UnityNavigation) { if (sceneSettings.navMesh) { NavigationMesh oldNavMesh = sceneSettings.navMesh; oldNavMesh.TurnOff(); } navMesh.TurnOn(); sceneSettings.navMesh = navMesh; // Bugfix: Need to cycle this otherwise weight caching doesn't always work navMesh.TurnOff(); navMesh.TurnOn(); } }
/** * <summary>Restores the class's data from a saved string.</summary> * <param name = "data">The saved string to restore from</param> * <param name = "subScene">If set, only data for a given subscene will be loaded. If null, only data for the active scene will be loaded</param> * <returns>True if the data was successfully restored</returns> */ public bool LoadData(string dataString, SubScene subScene = null) { if (string.IsNullOrEmpty(dataString)) { return(false); } string[] dataArray = dataString.Split(SaveSystem.colon[0]); // ID string listName = AdvGame.PrepareStringForLoading(dataArray[0]); resumeIndices = new int[0]; // Resume string[] resumeData = dataArray[1].Split("]"[0]); if (resumeData.Length > 0) { List <int> resumeIndexList = new List <int>(); for (int i = 0; i < resumeData.Length; i++) { int resumeIndex = -1; if (int.TryParse(resumeData[i], out resumeIndex) && resumeIndex >= 0) { resumeIndexList.Add(resumeIndex); } } resumeIndices = resumeIndexList.ToArray(); } // StartIndex int.TryParse(dataArray[2], out startIndex); // Skip queue int j = 0; int.TryParse(dataArray[3], out j); inSkipQueue = (j == 1) ? true : false; // IsRunning j = 0; int.TryParse(dataArray[4], out j); isRunning = (j == 1) ? true : false; // Conversation on end int convID = 0; int.TryParse(dataArray[5], out convID); if (convID != 0) { if (subScene != null) { conversationOnEnd = ConstantID.GetComponent <Conversation> (convID, subScene.gameObject.scene); } else { conversationOnEnd = ConstantID.GetComponent <Conversation> (convID); } } // Parameter data parameterData = dataArray[6]; // ActionList int ID = 0; if (int.TryParse(listName, out ID)) { // Scene ConstantID constantID = null; if (subScene != null) { constantID = ConstantID.GetComponent(ID, subScene.gameObject.scene); } else { constantID = ConstantID.GetComponent(ID); } if (constantID && constantID.GetComponent <ActionList>() != null) { actionList = constantID.GetComponent <ActionList>(); return(true); } } else { // Asset file ActionListAsset tempAsset = ScriptableObject.CreateInstance <ActionListAsset> (); actionListAsset = AssetLoader.RetrieveAsset <ActionListAsset> (tempAsset, listName); if (actionListAsset && actionListAsset != tempAsset) { return(true); } ACDebug.LogWarning("Could not restore data related to the ActionList asset '" + listName + "' - to restore it correctly, the asset must be placed in a folder named Resources."); } return(false); }
/** * <summary>Restores data from a data string</summary> * <param name="dataString">The data</param> */ public void LoadData(string dataString) { switch (parameterType) { case ParameterType.Float: floatValue = 0f; float.TryParse(dataString, out floatValue); break; case ParameterType.String: stringValue = AdvGame.PrepareStringForLoading(dataString); break; case ParameterType.GameObject: gameObject = null; int constantID = 0; if (int.TryParse(dataString, out constantID)) { ConstantID _constantID = ConstantID.GetComponent <ConstantID> (constantID); if (_constantID) { gameObject = _constantID.gameObject; } } break; case ParameterType.UnityObject: if (string.IsNullOrEmpty(dataString)) { objectValue = null; } else { Object[] objects = (Object[])Resources.LoadAll(""); foreach (Object _object in objects) { if (_object.name == dataString) { objectValue = _object; return; } } } break; case ParameterType.Vector3: if (!string.IsNullOrEmpty(dataString)) { dataString = AdvGame.PrepareStringForLoading(dataString); Vector3 _value = Vector3.zero; string[] valuesArray = dataString.Split(","[0]); if (valuesArray != null && valuesArray.Length == 3) { float xValue = 0f; float.TryParse(valuesArray[0], out xValue); float yValue = 0f; float.TryParse(valuesArray[1], out yValue); float zValue = 0f; float.TryParse(valuesArray[2], out zValue); _value = new Vector3(xValue, yValue, zValue); } vector3Value = _value; } break; default: intValue = 0; int.TryParse(dataString, out intValue); break; } }
private void UnloadTransformData(List <TransformData> allTransformData, Scene scene) { // Delete any objects (if told to) HashSet <RememberTransform> currentTransforms = ConstantID.GetComponents <RememberTransform> (scene); foreach (RememberTransform transformOb in currentTransforms) { if (transformOb.saveScenePresence) { // Was object not saved? bool found = false; foreach (TransformData transformData in allTransformData) { if (transformData.objectID == transformOb.constantID) { found = !transformData.savePrevented; } } if (!found) { // Can't find: delete KickStarter.sceneChanger.ScheduleForDeletion(transformOb.gameObject); } } } Object[] prefabAssets = Resources.LoadAll("SaveableData/Prefabs", typeof(GameObject)); if (prefabAssets == null || prefabAssets.Length == 0) { prefabAssets = Resources.LoadAll(string.Empty, typeof(GameObject)); } foreach (TransformData transformData in allTransformData) { RememberTransform saveObject = ConstantID.GetComponent <RememberTransform> (transformData.objectID, scene); if (saveObject == null) { // Restore any deleted objects (if told to) if (transformData.bringBack && !transformData.savePrevented) { bool foundObject = false; foreach (Object prefabAsset in prefabAssets) { if (prefabAsset is GameObject) { GameObject prefabGameObject = (GameObject)prefabAsset; if (prefabGameObject.GetComponent <RememberTransform>()) { int prefabID = prefabGameObject.GetComponent <ConstantID>().constantID; if ((transformData.linkedPrefabID != 0 && prefabID == transformData.linkedPrefabID) || (transformData.linkedPrefabID == 0 && prefabID == transformData.objectID)) { GameObject newObject = (GameObject)Instantiate(prefabGameObject); newObject.name = prefabGameObject.name; saveObject = newObject.GetComponent <RememberTransform>(); foundObject = true; if (transformData.linkedPrefabID != 0 && prefabID == transformData.linkedPrefabID) { // Spawned object has wrong ID, re-assign it ConstantID[] idScripts = saveObject.GetComponents <ConstantID>(); foreach (ConstantID idScript in idScripts) { idScript.constantID = transformData.objectID; } } break; } } } } if (!foundObject) { ACDebug.LogWarning("Could not find Resources prefab with ID " + transformData.objectID + " - is it placed in a Resources folder?"); } } } if (saveObject) { saveObject.LoadTransformData(transformData); } } Resources.UnloadUnusedAssets(); KickStarter.stateHandler.IgnoreNavMeshCollisions(); }
public override void LoadData(string stringData) { TimelineData data = Serializer.LoadScriptData <TimelineData> (stringData); if (data == null) { return; } SavePrevented = data.savePrevented; if (savePrevented) { return; } PlayableDirector director = GetComponent <PlayableDirector>(); #if !ACIgnoreTimeline if (director != null && director.playableAsset != null) { TimelineAsset timeline = (TimelineAsset)director.playableAsset; if (timeline != null) { if (saveTimelineAsset) { TimelineAsset _timeline = AssetLoader.RetrieveAsset(timeline, data.timelineAssetID); if (_timeline != null) { director.playableAsset = _timeline; timeline = _timeline; } } if (saveBindings && !string.IsNullOrEmpty(data.trackObjectData)) { string[] bindingIDs = data.trackObjectData.Split(","[0]); for (int i = 0; i < bindingIDs.Length; i++) { int bindingID = 0; if (int.TryParse(bindingIDs[i], out bindingID)) { if (bindingID != 0) { var track = timeline.GetOutputTrack(i); if (track != null) { ConstantID savedObject = ConstantID.GetComponent(bindingID, gameObject.scene, true); if (savedObject != null) { director.SetGenericBinding(track, savedObject.gameObject); } } } } } } } } #endif director.time = data.currentTime; if (data.isPlaying) { director.Play(); } else { director.Stop(); if (evaluateWhenStopped) { director.Evaluate(); } } }
/** Deprecated - use ConstantID.GetComponent instead */ public static T returnComponent <T> (int constantID) where T : Component { return(ConstantID.GetComponent <T> (constantID)); }
/** Deprecated - use ConstantID.GetComponent instead */ public static ConstantID returnConstantID(int constantID) { return(ConstantID.GetComponent(constantID)); }
/** * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary> * <param name = "stringData">The data, serialised as a string</param> */ public void LoadTransformData(TransformData data) { if (data == null) { return; } savePrevented = data.savePrevented; if (savePrevented) { return; } if (data.parentIsPlayer) { Player player = KickStarter.player; if (data.parentPlayerID >= 0) { player = null; PlayerPrefab playerPrefab = KickStarter.settingsManager.GetPlayerPrefab(data.parentPlayerID); if (playerPrefab != null) { player = playerPrefab.GetSceneInstance(); } } if (player) { if (data.heldHand == Hand.Left) { transform.parent = player.leftHandBone; } else { transform.parent = player.rightHandBone; } } } else if (data.parentID != 0) { ConstantID parentObject = ConstantID.GetComponent <ConstantID> (data.parentID); if (parentObject) { if (data.parentIsNPC) { Char _char = parentObject.GetComponent <NPC> (); if (_char && !_char.IsPlayer) { if (data.heldHand == Hand.Left) { transform.parent = _char.leftHandBone; } else { transform.parent = _char.rightHandBone; } } } else { transform.parent = parentObject.gameObject.transform; } } } else if (data.parentID == 0 && saveParent) { transform.parent = null; } switch (transformSpace) { case GlobalLocal.Global: transform.position = new Vector3(data.LocX, data.LocY, data.LocZ); transform.eulerAngles = new Vector3(data.RotX, data.RotY, data.RotZ); break; case GlobalLocal.Local: transform.localPosition = new Vector3(data.LocX, data.LocY, data.LocZ); transform.localEulerAngles = new Vector3(data.RotX, data.RotY, data.RotZ); break; } transform.localScale = new Vector3(data.ScaleX, data.ScaleY, data.ScaleZ); }
/** * <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); } }
public override void LoadData(string stringData) { MoveableData data = Serializer.LoadScriptData <MoveableData> (stringData); if (data == null) { loadedData = false; return; } SavePrevented = data.savePrevented; if (savePrevented) { return; } DragBase dragBase = GetComponent <DragBase>(); if (dragBase) { if (data.isOn) { dragBase.TurnOn(); } else { dragBase.TurnOff(); } } if (data.isOn) { gameObject.layer = LayerMask.NameToLayer(KickStarter.settingsManager.hotspotLayer); } else { gameObject.layer = LayerMask.NameToLayer(KickStarter.settingsManager.deactivatedLayer); } transform.position = new Vector3(data.LocX, data.LocY, data.LocZ); transform.eulerAngles = new Vector3(data.RotX, data.RotY, data.RotZ); transform.localScale = new Vector3(data.ScaleX, data.ScaleY, data.ScaleZ); Moveable_Drag moveable_Drag = GetComponent <Moveable_Drag>(); if (moveable_Drag) { moveable_Drag.LetGo(); if (moveable_Drag.dragMode == DragMode.LockToTrack) { DragTrack dragTrack = ConstantID.GetComponent <DragTrack> (data.trackID); if (dragTrack) { moveable_Drag.SnapToTrack(dragTrack, data.trackValue); } if (moveable_Drag.track) { moveable_Drag.trackValue = data.trackValue; moveable_Drag.revolutions = data.revolutions; moveable_Drag.StopAutoMove(); moveable_Drag.track.SetPositionAlong(data.trackValue, moveable_Drag); } } } Moveable moveable = GetComponent <Moveable>(); if (moveable) { moveable.LoadData(data); } loadedData = true; }
/** * <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); }