private void UnloadNavMesh(int navMeshInt) { NavigationMesh navMesh = Serializer.returnComponent <NavigationMesh> (navMeshInt); if (navMesh && KickStarter.sceneSettings && KickStarter.sceneSettings.navigationMethod != AC_NavigationMethod.UnityNavigation) { if (KickStarter.sceneSettings.navMesh) { NavigationMesh oldNavMesh = KickStarter.sceneSettings.navMesh; oldNavMesh.TurnOff(); } navMesh.TurnOn(); KickStarter.sceneSettings.navMesh = navMesh; // Bugfix: Need to cycle this otherwise weight caching doesn't always work navMesh.TurnOff(); navMesh.TurnOn(); } }
/** * <summary>Returns the currently-loaded scene's save data to the appriopriate Remember components.</summary> * <param name = "restoringSaveFile">True if the game is currently loading a saved game file, as opposed to just switching scene</param> */ public void ReturnCurrentLevelData(bool restoringSaveFile) { foreach (SingleLevelData levelData in allLevelData) { if (levelData.sceneNumber == UnityVersionHandler.GetCurrentSceneNumber()) { KickStarter.actionListManager.LoadData(levelData.activeLists); UnloadCutsceneOnLoad(levelData.onLoadCutscene); UnloadCutsceneOnStart(levelData.onStartCutscene); UnloadNavMesh(levelData.navMesh); UnloadPlayerStart(levelData.playerStart); UnloadSortingMap(levelData.sortingMap); UnloadTintMap(levelData.tintMap); UnloadTransformData(levelData.allTransformData); foreach (ScriptData _scriptData in levelData.allScriptData) { Remember saveObject = Serializer.returnComponent <Remember> (_scriptData.objectID); if (saveObject != null && _scriptData.data != null && _scriptData.data.Length > 0) { // May have more than one Remember script on the same object, so check all Remember[] saveScripts = saveObject.gameObject.GetComponents <Remember>(); foreach (Remember saveScript in saveScripts) { saveScript.LoadData(_scriptData.data, restoringSaveFile); } } } UnloadVariablesData(levelData.localVariablesData); KickStarter.sceneSettings.UpdateAllSortingMaps(); break; } } AssetLoader.UnloadAssets(); }
private IEnumerator OnCompleteSceneChange() { if (KickStarter.eventManager != null) { KickStarter.eventManager.Call_OnAfterChangeScene(); } int _removeNPCID = removeNPCID; removeNPCID = 0; yield return(new WaitForEndOfFrame()); if (_removeNPCID != 0) { NPC npcToRemove = Serializer.returnComponent <NPC> (_removeNPCID); if (npcToRemove != null) { npcToRemove.transform.position += new Vector3(100f, -100f, 100f); } _removeNPCID = 0; } }
public T IDToField <T> (T field, int _constantID, bool moreInfo) where T : Behaviour { if (isAssetFile || (!isAssetFile && (field == null || !field.gameObject.activeInHierarchy))) { T newField = field; if (_constantID != 0) { newField = Serializer.returnComponent <T> (_constantID); if (field != null && field.GetComponent <ConstantID>() != null && field.GetComponent <ConstantID>().constantID == _constantID) { } else if (newField != null && !Application.isPlaying) { field = newField; } EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Recorded ConstantID: " + _constantID.ToString(), EditorStyles.miniLabel); if (field == null) { if (GUILayout.Button("Search scenes", EditorStyles.miniButton)) { AdvGame.FindObjectWithConstantID(_constantID); } } EditorGUILayout.EndHorizontal(); if (field == null && moreInfo) { EditorGUILayout.HelpBox("Further controls cannot display because the referenced object cannot be found.", MessageType.Warning); } EditorGUILayout.EndVertical(); } } return(field); }
/** * <summary>Updates its own variables from a PlayerData class.</summary> * <param name = "playerData">The PlayerData class to load from</param> * <param name = "justAnimationData">If True, then only animation data (and sound) changes will be loaded, as opposed to position, rotaion, etc</param> */ public void LoadPlayerData(PlayerData playerData, bool justAnimationData = false) { if (!justAnimationData) { Teleport(new Vector3(playerData.playerLocX, playerData.playerLocY, playerData.playerLocZ)); SetRotation(playerData.playerRotY); SetMoveDirectionAsForward(); } walkSpeedScale = playerData.playerWalkSpeed; runSpeedScale = playerData.playerRunSpeed; // Animation clips if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity) { idleAnimSprite = playerData.playerIdleAnim; walkAnimSprite = playerData.playerWalkAnim; talkAnimSprite = playerData.playerTalkAnim; runAnimSprite = playerData.playerRunAnim; } else if (animationEngine == AnimationEngine.Legacy) { idleAnim = AssetLoader.RetrieveAsset <AnimationClip> (idleAnim, playerData.playerIdleAnim); walkAnim = AssetLoader.RetrieveAsset <AnimationClip> (walkAnim, playerData.playerWalkAnim); talkAnim = AssetLoader.RetrieveAsset <AnimationClip> (talkAnim, playerData.playerTalkAnim); runAnim = AssetLoader.RetrieveAsset <AnimationClip> (runAnim, playerData.playerRunAnim); } else if (animationEngine == AnimationEngine.Mecanim) { moveSpeedParameter = playerData.playerWalkAnim; talkParameter = playerData.playerTalkAnim; turnParameter = playerData.playerRunAnim; } // Sound walkSound = AssetLoader.RetrieveAsset(walkSound, playerData.playerWalkSound); runSound = AssetLoader.RetrieveAsset(runSound, playerData.playerRunSound); // Portrait graphic portraitIcon.texture = AssetLoader.RetrieveAsset(portraitIcon.texture, playerData.playerPortraitGraphic); // Speech label if (playerData.playerSpeechLabel != "") { SetName(playerData.playerSpeechLabel, playerData.playerDisplayLineID); } speechLabel = playerData.playerSpeechLabel; // 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; } 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; } } if (!justAnimationData) { // Active path Halt(); ForceIdle(); if (playerData.playerPathData != null && 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 = Serializer.returnComponent <Paths> (playerData.playerActivePath); if (savedPath) { lockedPath = playerData.playerLockedPath; if (lockedPath) { SetLockedPath(savedPath); } else { SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode); } } } // Previous path if (playerData.lastPlayerActivePath != 0) { Paths savedPath = Serializer.returnComponent <Paths> (playerData.lastPlayerActivePath); if (savedPath) { SetLastPath(savedPath, playerData.lastPlayerTargetNode, playerData.lastPlayerPrevNode); } } // Head target lockHotspotHeadTurning = playerData.playerLockHotspotHeadTurning; if (playerData.isHeadTurning) { ConstantID _headTargetID = Serializer.returnComponent <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 = Serializer.returnComponent <SortingMap> (playerData.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = playerData.followSortingMap; if (!playerData.followSortingMap) { followSortingMap.SetSortingMap(customSortingMap); } } } } ignoreGravity = playerData.playerIgnoreGravity; }
/** * <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) { conversationOnEnd = Serializer.returnComponent <Conversation> (convID, (subScene != null) ? subScene.gameObject : null); } // Parameter data parameterData = dataArray[6]; // ActionList int ID = 0; if (int.TryParse(listName, out ID)) { // Scene ConstantID constantID = Serializer.returnComponent <ConstantID> (ID, (subScene != null) ? subScene.gameObject : null); if (constantID != null && 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 != null && 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); }
private void UnloadTransformData(List <TransformData> _transforms, SubScene subScene) { // Delete any objects (if told to) RememberTransform[] currentTransforms = UnityVersionHandler.GetOwnSceneComponents <RememberTransform> ((subScene != null) ? subScene.gameObject : null); foreach (RememberTransform transformOb in currentTransforms) { if (transformOb.saveScenePresence) { // Was object not saved? bool found = false; foreach (TransformData _transform in _transforms) { if (_transform.objectID == transformOb.constantID) { found = !_transform.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("", typeof(GameObject)); } foreach (TransformData _transform in _transforms) { RememberTransform saveObject = Serializer.returnComponent <RememberTransform> (_transform.objectID, (subScene != null) ? subScene.gameObject : null); if (saveObject == null) { // Restore any deleted objects (if told to) if (_transform.bringBack && !_transform.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 ((_transform.linkedPrefabID != 0 && prefabID == _transform.linkedPrefabID) || (_transform.linkedPrefabID == 0 && prefabID == _transform.objectID)) { GameObject newObject = (GameObject)Instantiate(prefabGameObject); newObject.name = prefabGameObject.name; saveObject = newObject.GetComponent <RememberTransform>(); foundObject = true; if (_transform.linkedPrefabID != 0 && prefabID == _transform.linkedPrefabID) { // Spawned object has wrong ID, re-assign it ConstantID[] idScripts = saveObject.GetComponents <ConstantID>(); foreach (ConstantID idScript in idScripts) { idScript.constantID = _transform.objectID; } } break; } } } } if (!foundObject) { ACDebug.LogWarning("Could not find Resources prefab with ID " + _transform.objectID + " - is it placed in a Resources folder?"); } } } if (saveObject != null) { saveObject.LoadTransformData(_transform); } } Resources.UnloadUnusedAssets(); KickStarter.stateHandler.IgnoreNavMeshCollisions(); }
/** * <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(); 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); portraitIcon.ClearSprites(); portraitIcon.ClearCache(); 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>(); } } 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 (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 && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } }
protected T LinkUIElement <T> () where T : Behaviour { T field = Serializer.returnComponent <T> (linkedUiID); return(field); }
public void LoadData(string dataString) { if (parameterType == ParameterType.Float) { floatValue = 0f; float.TryParse(dataString, out floatValue); } else if (parameterType == ParameterType.String) { stringValue = AdvGame.PrepareStringForLoading(dataString); } else if (parameterType == ParameterType.GameObject) { gameObject = null; int constantID = 0; if (int.TryParse(dataString, out constantID)) { ConstantID _constantID = Serializer.returnComponent <ConstantID> (constantID); if (_constantID != null) { gameObject = _constantID.gameObject; } } } else if (parameterType == ParameterType.UnityObject) { if (dataString == "") { objectValue = null; } else { Object[] objects = (Object[])Resources.LoadAll(""); foreach (Object _object in objects) { if (_object.name == dataString) { objectValue = _object; return; } } } } else if (parameterType == 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; } } else { intValue = 0; int.TryParse(dataString, out intValue); } }
/** * <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> * <param name = "restoringSaveFile">True if the game is currently loading a saved game file, as opposed to just switching scene</param> */ public override void LoadData(string stringData, bool restoringSaveFile = false) { TimelineData data = Serializer.LoadScriptData <TimelineData> (stringData); if (data == null) { return; } SavePrevented = data.savePrevented; if (savePrevented) { return; } PlayableDirector director = GetComponent <PlayableDirector>(); 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 = Serializer.returnComponent <ConstantID> (bindingID, gameObject); if (savedObject != null) { director.SetGenericBinding(track, savedObject.gameObject); } } } } } } } } director.time = data.currentTime; if (data.isPlaying) { director.Play(); } else { director.Stop(); } }
private void UnloadTransformData(List <TransformData> _transforms, SubScene subScene) { // Delete any objects (if told to) RememberTransform[] currentTransforms = UnityVersionHandler.GetOwnSceneComponents <RememberTransform> ((subScene != null) ? subScene.gameObject : null); foreach (RememberTransform transformOb in currentTransforms) { if (transformOb.saveScenePresence) { // Was object not saved? bool found = false; foreach (TransformData _transform in _transforms) { if (_transform.objectID == transformOb.constantID) { found = true; } } if (!found) { // Can't find: delete KickStarter.sceneChanger.ScheduleForDeletion(transformOb.gameObject); } } } foreach (TransformData _transform in _transforms) { RememberTransform saveObject = Serializer.returnComponent <RememberTransform> (_transform.objectID); // Restore any deleted objects (if told to) if (saveObject == null && _transform.bringBack) { Object[] assets = Resources.LoadAll("SaveableData/Prefabs", typeof(GameObject)); if (assets == null || assets.Length == 0) { assets = Resources.LoadAll("", typeof(GameObject)); } foreach (Object asset in assets) { if (asset is GameObject) { GameObject assetObject = (GameObject)asset; if (assetObject.GetComponent <RememberTransform>() && assetObject.GetComponent <RememberTransform>().constantID == _transform.objectID) { GameObject newObject = (GameObject)Instantiate(assetObject.gameObject); newObject.name = assetObject.name; saveObject = newObject.GetComponent <RememberTransform>(); } } } Resources.UnloadUnusedAssets(); } if (saveObject != null) { saveObject.LoadTransformData(_transform); } } KickStarter.stateHandler.GatherObjects(); }
/** * <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; } 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); }
public override void LoadData(string stringData) { NPCData data = Serializer.LoadScriptData <NPCData> (stringData); if (data == null) { return; } 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); if (GetComponent <NPC>()) { NPC npc = GetComponent <NPC>(); npc.EndPath(); if (npc.animationEngine == AnimationEngine.Sprites2DToolkit || npc.animationEngine == AnimationEngine.SpritesUnity) { npc.idleAnimSprite = data.idleAnim; npc.walkAnimSprite = data.walkAnim; npc.talkAnimSprite = data.talkAnim; npc.runAnimSprite = data.runAnim; } else if (npc.animationEngine == AnimationEngine.Legacy) { npc.idleAnim = AssetLoader.RetrieveAsset(npc.idleAnim, data.idleAnim); npc.walkAnim = AssetLoader.RetrieveAsset(npc.walkAnim, data.walkAnim); npc.runAnim = AssetLoader.RetrieveAsset(npc.runAnim, data.talkAnim); npc.talkAnim = AssetLoader.RetrieveAsset(npc.talkAnim, data.runAnim); } else if (npc.animationEngine == AnimationEngine.Mecanim) { npc.moveSpeedParameter = data.walkAnim; npc.talkParameter = data.talkAnim; npc.turnParameter = data.runAnim;; } npc.walkSound = AssetLoader.RetrieveAsset(npc.walkSound, data.walkSound); npc.runSound = AssetLoader.RetrieveAsset(npc.runSound, data.runSound); npc.speechLabel = data.speechLabel; npc.portraitIcon.texture = AssetLoader.RetrieveAsset(npc.portraitIcon.texture, data.portraitGraphic); npc.walkSpeedScale = data.walkSpeed; npc.runSpeedScale = data.runSpeed; // Rendering npc.lockDirection = data.lockDirection; npc.lockScale = data.lockScale; if (npc.spriteChild && npc.spriteChild.GetComponent <FollowSortingMap>()) { npc.spriteChild.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else if (npc.GetComponent <FollowSortingMap>()) { npc.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else { npc.ReleaseSorting(); } if (data.lockDirection) { npc.spriteDirection = data.spriteDirection; } if (data.lockScale) { npc.spriteScale = data.spriteScale; } if (data.lockSorting) { if (npc.spriteChild && npc.spriteChild.GetComponent <Renderer>()) { npc.spriteChild.GetComponent <Renderer>().sortingOrder = data.sortingOrder; npc.spriteChild.GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } else if (npc.GetComponent <Renderer>()) { npc.GetComponent <Renderer>().sortingOrder = data.sortingOrder; npc.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>(); } } npc.FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax); npc.Halt(); if (data.pathData != null && data.pathData != "" && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, data.pathData); npc.SetPath(savedPath, data.targetNode, data.prevNode, data.pathAffectY); npc.isRunning = data.isRunning; } else if (data.pathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.pathID); if (pathObject != null) { npc.SetPath(pathObject, data.targetNode, data.prevNode); } else { Debug.LogWarning("Trying to assign a path for NPC " + this.name + ", but the path was not found - was it deleted?"); } } if (data.lastPathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.lastPathID); if (pathObject != null) { npc.SetLastPath(pathObject, data.lastTargetNode, data.lastPrevNode); } else { Debug.LogWarning("Trying to assign the previous path for NPC " + this.name + ", but the path was not found - was it deleted?"); } } // Head target if (data.isHeadTurning) { npc.SetHeadTurnTarget(new Vector3(data.headTargetX, data.headTargetY, data.headTargetZ), true); } else { npc.ClearHeadTurnTarget(true); } } }
/** * <summary>Updates its own variables from a PlayerData class.</summary> * <param name = "playerData">The PlayerData class to load from</param> * <param name = "justAnimationData">If True, then only animation data (and sound) changes will be loaded, as opposed to position, rotaion, etc</param> */ public void LoadPlayerData(PlayerData playerData, bool justAnimationData = false) { if (!justAnimationData) { charState = (playerData.inCustomCharState) ? CharState.Custom : CharState.Idle; 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 if (!string.IsNullOrEmpty(playerData.playerSpeechLabel)) { SetName(playerData.playerSpeechLabel, playerData.playerDisplayLineID); } speechLabel = playerData.playerSpeechLabel; // 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; } 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; } } if (!justAnimationData) { // 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 = Serializer.returnComponent <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 = Serializer.returnComponent <Paths> (playerData.lastPlayerActivePath); if (savedPath) { SetLastPath(savedPath, playerData.lastPlayerTargetNode, playerData.lastPlayerPrevNode); } } // Head target lockHotspotHeadTurning = playerData.playerLockHotspotHeadTurning; if (playerData.isHeadTurning) { ConstantID _headTargetID = Serializer.returnComponent <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 = Serializer.returnComponent <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; // Remember scripts if (!IsLocalPlayer()) { KickStarter.levelStorage.LoadPlayerData(this, playerData); } }