Exemple #1
0
        /**
         * <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);

            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);
                    }
                }
            }
        }
        /**
         * <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    = 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   = "";
                    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;
            }

            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", gameObject);
                        playerData.customSortingMapID = 0;
                    }
                }
                else
                {
                    playerData.customSortingMapID = 0;
                }
            }
            else
            {
                playerData.followSortingMap   = false;
                playerData.customSortingMapID = 0;
            }
            return(playerData);
        }
Exemple #3
0
        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 && director.playableAsset)
            {
                TimelineAsset timeline = (TimelineAsset)director.playableAsset;

                if (timeline)
                {
                    if (saveTimelineAsset)
                    {
                        TimelineAsset _timeline = AssetLoader.RetrieveAsset(timeline, data.timelineAssetID);
                        if (_timeline)
                        {
                            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)
                                    {
                                        ConstantID savedObject = ConstantID.GetComponent(bindingID, gameObject.scene, true);
                                        if (savedObject)
                                        {
                                            director.SetGenericBinding(track, savedObject.gameObject);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
                        #endif

            director.time = data.currentTime;
            if (data.isPlaying)
            {
                director.Play();
            }
            else
            {
                director.Stop();

                if (evaluateWhenStopped)
                {
                    director.Evaluate();
                }
            }
        }
Exemple #4
0
        /**
         * <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);
        }
Exemple #5
0
        /**
         * <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)
        {
            VideoPlayerData data = Serializer.LoadScriptData <VideoPlayerData> (stringData);

            if (data == null)
            {
                return;
            }
            SavePrevented = data.savePrevented; if (savePrevented)
            {
                return;
            }

            if (GetComponent <VideoPlayer>())
            {
                VideoPlayer videoPlayer = GetComponent <VideoPlayer>();

                if (saveClipAsset)
                {
                    VideoClip _clip = AssetLoader.RetrieveAsset(videoPlayer.clip, data.clipAssetID);
                    if (_clip != null)
                    {
                        videoPlayer.clip = _clip;
                    }
                }

                //videoPlayer.frame = data.currentFrame;
                videoPlayer.time = data.currentTime;

                if (data.isPlaying)
                {
                    if (!videoPlayer.isPrepared)
                    {
                        loadTime      = data.currentTime;
                        playAfterLoad = true;
                        videoPlayer.prepareCompleted += OnPrepareVideo;
                        videoPlayer.Prepare();
                    }
                    else
                    {
                        videoPlayer.Play();
                    }
                }
                else
                {
                    if (data.currentTime > 0f)
                    {
                        if (!videoPlayer.isPrepared)
                        {
                            loadTime      = data.currentTime;
                            playAfterLoad = false;
                            videoPlayer.prepareCompleted += OnPrepareVideo;
                            videoPlayer.Prepare();
                        }
                        else
                        {
                            videoPlayer.Pause();
                        }
                    }
                    else
                    {
                        videoPlayer.Stop();
                    }
                }
            }
        }
Exemple #6
0
        /**
         * <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;
        }
Exemple #7
0
        /**
         * <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);
            }
        }
Exemple #8
0
        override public float Run()
        {
            if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
            {
                if (KickStarter.sceneChanger.GetSubScenes().Length > 0)
                {
                    //	ACDebug.LogWarning ("Cannot switch players while multiple scenes are open!");
                    //	return 0f;
                }

                if (KickStarter.settingsManager.players.Count > 0 && KickStarter.settingsManager.players.Count > playerNumber && playerNumber > -1)
                {
                    if (KickStarter.player != null && KickStarter.player.ID == playerID)
                    {
                        ACDebug.Log("Cannot switch player - already controlling the desired prefab.");
                        return(0f);
                    }

                    if (KickStarter.settingsManager.players[playerNumber].playerOb != null)
                    {
                        KickStarter.saveSystem.SaveCurrentPlayerData();

                        Vector3    oldPlayerPosition = Vector3.zero;
                        Quaternion oldPlayerRotation = new Quaternion();
                        Vector3    oldPlayerScale    = Vector3.one;

                        if (KickStarter.player != null)
                        {
                            oldPlayerPosition = KickStarter.player.transform.position;
                            oldPlayerRotation = KickStarter.player.transform.rotation;
                            oldPlayerScale    = KickStarter.player.transform.localScale;
                        }

                        if (oldPlayer == OldPlayer.ReplaceWithNPC && oldPlayerNPC != null &&
                            (newPlayerPosition == NewPlayerPosition.ReplaceNPC || newPlayerPosition == NewPlayerPosition.AppearAtMarker || newPlayerPosition == NewPlayerPosition.AppearInOtherScene))
                        {
                            oldPlayerNPC.transform.position   = oldPlayerPosition;
                            oldPlayerNPC.transform.rotation   = oldPlayerRotation;
                            oldPlayerNPC.transform.localScale = oldPlayerScale;
                        }

                        Quaternion newRotation = Quaternion.identity;
                        if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
                        {
                            newRotation = oldPlayerRotation;
                        }
                        else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC && newPlayerNPC)
                        {
                            newRotation = newPlayerNPC.transform.rotation;
                        }
                        else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker && newPlayerMarker)
                        {
                            newRotation = newPlayerMarker.transform.rotation;
                        }

                        KickStarter.ResetPlayer(KickStarter.settingsManager.players[playerNumber].playerOb, playerID, true, newRotation, keepInventory);
                        Player newPlayer = KickStarter.player;
                        PlayerMenus.ResetInventoryBoxes();

                        if (restorePreviousData && KickStarter.saveSystem.DoesPlayerDataExist(playerID, true))
                        {
                            if (newPlayerNPC)
                            {
                                newPlayerNPC.transform.position += new Vector3(100f, -100f, 100f);
                            }

                            int sceneToLoad = KickStarter.saveSystem.GetPlayerScene(playerID);
                            if (sceneToLoad >= 0 && sceneToLoad != UnityVersionHandler.GetCurrentSceneNumber())
                            {
                                KickStarter.saveSystem.loadingGame = LoadingGame.JustSwitchingPlayer;
                                KickStarter.sceneChanger.ChangeScene(new SceneInfo("", sceneToLoad), true, false, newPlayerNPC_ID);
                            }
                            else
                            {
                                string sceneToLoadName = KickStarter.saveSystem.GetPlayerSceneName(playerID);
                                if (sceneToLoadName != "" && sceneToLoadName != UnityVersionHandler.GetCurrentSceneName())
                                {
                                    KickStarter.saveSystem.loadingGame = LoadingGame.JustSwitchingPlayer;
                                    KickStarter.sceneChanger.ChangeScene(new SceneInfo(sceneToLoadName, -1), true, false, newPlayerNPC_ID);
                                }
                            }
                        }
                        else
                        {
                            if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
                            {
                                newPlayer.Teleport(oldPlayerPosition);
                                newPlayer.SetRotation(oldPlayerRotation);
                                newPlayer.transform.localScale = oldPlayerScale;
                            }
                            else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC)
                            {
                                if (newPlayerNPC)
                                {
                                    newPlayer.Teleport(newPlayerNPC.transform.position);
                                    newPlayer.SetRotation(newPlayerNPC.transform.rotation);
                                    newPlayer.transform.localScale = newPlayerNPC.transform.localScale;

                                    newPlayerNPC.transform.position += new Vector3(100f, -100f, 100f);
                                }
                            }
                            else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker)
                            {
                                if (newPlayerMarker)
                                {
                                    newPlayer.Teleport(newPlayerMarker.transform.position);
                                    newPlayer.SetRotation(newPlayerMarker.transform.rotation);
                                    newPlayer.transform.localScale = newPlayerMarker.transform.localScale;
                                }
                            }
                            else if (newPlayerPosition == NewPlayerPosition.AppearInOtherScene)
                            {
                                if (newPlayerNPC)
                                {
                                    newPlayerNPC.transform.position += new Vector3(100f, -100f, 100f);
                                }

                                if (chooseNewSceneBy == ChooseSceneBy.Name && newPlayerSceneName == UnityVersionHandler.GetCurrentSceneName())
                                {
                                }
                                else if (chooseNewSceneBy == ChooseSceneBy.Number && newPlayerScene == UnityVersionHandler.GetCurrentSceneNumber())
                                {
                                }
                                else
                                {
                                    KickStarter.sceneChanger.ChangeScene(new SceneInfo(chooseNewSceneBy, newPlayerSceneName, newPlayerScene), true, false, newPlayerNPC_ID);
                                }
                            }
                        }

                        if (KickStarter.mainCamera.attachedCamera)
                        {
                            KickStarter.mainCamera.attachedCamera.MoveCameraInstant();
                        }

                        AssetLoader.UnloadAssets();
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot switch player - no player prefabs is defined.");
                    }
                }
            }

            return(0f);
        }
Exemple #9
0
        /**
         * <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 != 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);
        }
Exemple #10
0
		public override float Run ()
		{
			if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
			{
				PlayerPrefab newPlayerPrefab = KickStarter.settingsManager.GetPlayerPrefab (playerID);

				if (newPlayerPrefab != null)
				{
					if (KickStarter.player != null && KickStarter.player.ID == playerID)
					{
						Log ("Cannot switch player - already controlling the desired prefab.");
						return 0f;
					}
					
					if (newPlayerPrefab.playerOb != null)
					{
						KickStarter.saveSystem.SaveCurrentPlayerData ();
						
						Vector3 oldPlayerPosition = Vector3.zero;
						Quaternion oldPlayerRotation = new Quaternion ();
						Vector3 oldPlayerScale = Vector3.one;

						PlayerData oldPlayerData = new PlayerData ();
						NPCData oldNPCData = new NPCData ();
						bool recordedOldPlayerData = false;
						bool recordedOldNPCData = false;

						if (KickStarter.player != null)
						{
							oldPlayerPosition = KickStarter.player.transform.position;
							oldPlayerRotation = KickStarter.player.TransformRotation;
							oldPlayerScale = KickStarter.player.transform.localScale;

							oldPlayerData = KickStarter.player.SavePlayerData (oldPlayerData);
							recordedOldPlayerData = true;
						}

						if (newPlayerPosition != NewPlayerPosition.ReplaceCurrentPlayer)
						{
							if (oldPlayer == OldPlayer.ReplaceWithAssociatedNPC &&
								(runtimeOldPlayerNPC == null || !runtimeOldPlayerNPC.gameObject.activeInHierarchy) &&
								KickStarter.player.associatedNPCPrefab != null)
							{
								GameObject newObject = (GameObject) Instantiate (KickStarter.player.associatedNPCPrefab.gameObject);
								newObject.name = KickStarter.player.associatedNPCPrefab.gameObject.name;
								runtimeOldPlayerNPC = newObject.GetComponent <NPC>();
							}

							if ((oldPlayer == OldPlayer.ReplaceWithNPC || oldPlayer == OldPlayer.ReplaceWithAssociatedNPC) &&
								runtimeOldPlayerNPC != null && runtimeOldPlayerNPC.gameObject.activeInHierarchy)
							{
								runtimeOldPlayerNPC.Teleport (oldPlayerPosition);
								runtimeOldPlayerNPC.SetRotation (oldPlayerRotation);
								runtimeOldPlayerNPC.transform.localScale = oldPlayerScale;

								if (recordedOldPlayerData)
								{
									ApplyRenderData (runtimeOldPlayerNPC, oldPlayerData);
								}

								// Force the rotation / sprite child to update
								runtimeOldPlayerNPC._Update ();
							}
						}

						if (runtimeNewPlayerNPC == null || newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC)
						{
							// Try to find from associated NPC prefab

							if (newPlayerPrefab.playerOb.associatedNPCPrefab != null)
							{
								ConstantID prefabID = newPlayerPrefab.playerOb.associatedNPCPrefab.GetComponent <ConstantID>();
								if (prefabID != null && prefabID.constantID != 0)
								{
									newPlayerNPC_ID = prefabID.constantID;
									runtimeNewPlayerNPC = AssignFile <NPC> (prefabID.constantID, null);
								}
							}
						}

						Quaternion newRotation = Quaternion.identity;
						if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
						{
							newRotation = oldPlayerRotation;
						}
						else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC && runtimeNewPlayerNPC != null)
						{
							newRotation = runtimeNewPlayerNPC.TransformRotation;
						}
						else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker && runtimeNewPlayerMarker != null)
						{
							newRotation = runtimeNewPlayerMarker.transform.rotation;
						}

						if (runtimeNewPlayerNPC != null)
						{
							oldNPCData = runtimeNewPlayerNPC.SaveData (oldNPCData);
						}

						bool replacesOldPlayer = newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer &&
												 (!restorePreviousData || !KickStarter.saveSystem.DoesPlayerDataExist (playerID, true));
						KickStarter.ResetPlayer (newPlayerPrefab.playerOb, playerID, true, newRotation, keepInventory, false, replacesOldPlayer, alwaysSnapCamera);
						Player newPlayer = KickStarter.player;
						PlayerMenus.ResetInventoryBoxes ();

						if (replacesOldPlayer && recordedOldPlayerData)
						{
							ApplyRenderData (newPlayer, oldPlayerData);
						}

						if (restorePreviousData && KickStarter.saveSystem.DoesPlayerDataExist (playerID, true))
						{
							int sceneToLoad = KickStarter.saveSystem.GetPlayerScene (playerID);
							if (sceneToLoad >= 0 && sceneToLoad != UnityVersionHandler.GetCurrentSceneNumber ())
							{
								KickStarter.saveSystem.loadingGame = LoadingGame.JustSwitchingPlayer;
								KickStarter.sceneChanger.ChangeScene (new SceneInfo (string.Empty, sceneToLoad), true, false);
							}
							else
							{
								// Same scene
								if (runtimeNewPlayerNPC != null)
								{
									newPlayer.RepositionToTransform (runtimeNewPlayerNPC.transform);
									runtimeNewPlayerNPC.HideFromView (newPlayer);
								}	
							}
						}
						else
						{
							// No data to restore

							if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
							{
								newPlayer.Teleport (oldPlayerPosition);
								newPlayer.SetRotation (oldPlayerRotation);
								newPlayer.transform.localScale = oldPlayerScale;
							}
							else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC || newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC)
							{
								if (runtimeNewPlayerNPC != null)
								{
									newPlayer.RepositionToTransform (runtimeNewPlayerNPC.transform);
									runtimeNewPlayerNPC.HideFromView (newPlayer);

									if (recordedOldNPCData)
									{
										ApplyRenderData (newPlayer, oldNPCData);
									}
								}
							}
							else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker)
							{
								if (runtimeNewPlayerMarker)
								{
									newPlayer.RepositionToTransform (runtimeNewPlayerMarker.transform);
								}
							}
							else if (newPlayerPosition == NewPlayerPosition.AppearInOtherScene)
							{
								if (chooseNewSceneBy == ChooseSceneBy.Name && newPlayerSceneName == UnityVersionHandler.GetCurrentSceneName () ||
									(chooseNewSceneBy == ChooseSceneBy.Number && newPlayerScene == UnityVersionHandler.GetCurrentSceneNumber ()))
								{
									// Already in correct scene
									if (runtimeNewPlayerNPC && runtimeNewPlayerNPC.gameObject.activeInHierarchy)
									{
										newPlayer.RepositionToTransform (runtimeNewPlayerNPC.transform);
										runtimeNewPlayerNPC.HideFromView (newPlayer);
									}
								}
								else
								{
									KickStarter.sceneChanger.ChangeScene (new SceneInfo (chooseNewSceneBy, newPlayerSceneName, newPlayerScene), true, false, true);
								}
							}
						}
						
						if (KickStarter.mainCamera.attachedCamera && alwaysSnapCamera)
						{
							KickStarter.mainCamera.attachedCamera.MoveCameraInstant ();
						}
						
						AssetLoader.UnloadAssets ();
					}
					else
					{
						LogWarning ("Cannot switch player - no player prefabs is defined.");
					}
				}
			}
			
			return 0f;
		}
Exemple #11
0
        /**
         * <summary>Updates its own variables from a NPCData class.</summary>
         * <param name = "data">The NPCData class to load from</param>
         */
        public void LoadData(NPCData data)
        {
            charState = (data.inCustomCharState) ? CharState.Custom : CharState.Idle;

            EndPath();

            GetAnimEngine().LoadNPCData(data, this);

            walkSound = AssetLoader.RetrieveAsset(walkSound, data.walkSound);
            runSound  = AssetLoader.RetrieveAsset(runSound, data.runSound);

            if (!string.IsNullOrEmpty(data.speechLabel))
            {
                SetName(data.speechLabel, data.displayLineID);
            }

            portraitIcon.ReplaceTexture(AssetLoader.RetrieveAsset(portraitIcon.texture, data.portraitGraphic));

            walkSpeedScale = data.walkSpeed;
            runSpeedScale  = data.runSpeed;

            // Rendering
            lockDirection = data.lockDirection;
            lockScale     = data.lockScale;
            if (spriteChild && spriteChild.GetComponent <FollowSortingMap>())
            {
                spriteChild.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting;
            }
            else if (GetComponent <FollowSortingMap>())
            {
                GetComponent <FollowSortingMap>().lockSorting = data.lockSorting;
            }
            else
            {
                ReleaseSorting();
            }

            if (data.lockDirection)
            {
                spriteDirection = data.spriteDirection;
                UpdateFrameFlipping(true);
            }
            if (data.lockScale)
            {
                spriteScale = data.spriteScale;
            }
            if (data.lockSorting)
            {
                if (spriteChild && spriteChild.GetComponent <Renderer>())
                {
                    spriteChild.GetComponent <Renderer>().sortingOrder     = data.sortingOrder;
                    spriteChild.GetComponent <Renderer>().sortingLayerName = data.sortingLayer;
                }
                else if (GetComponent <Renderer>())
                {
                    GetComponent <Renderer>().sortingOrder     = data.sortingOrder;
                    GetComponent <Renderer>().sortingLayerName = data.sortingLayer;
                }
            }

            AC.Char charToFollow = null;
            if (data.followTargetID != 0)
            {
                RememberNPC followNPC = ConstantID.GetComponent <RememberNPC> (data.followTargetID);
                if (followNPC.GetComponent <AC.Char>())
                {
                    charToFollow = followNPC.GetComponent <AC.Char>();
                }
            }

            if (charToFollow != null || (data.followTargetIsPlayer && KickStarter.player != null))
            {
                FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection);
            }
            else
            {
                StopFollowing();
            }
            Halt();

            if (!string.IsNullOrEmpty(data.pathData) && GetComponent <Paths>())
            {
                Paths savedPath = GetComponent <Paths>();
                savedPath = Serializer.RestorePathData(savedPath, data.pathData);
                SetPath(savedPath, data.targetNode, data.prevNode, data.pathAffectY);
                isRunning = data.isRunning;
            }
            else if (data.pathID != 0)
            {
                Paths pathObject = ConstantID.GetComponent <Paths> (data.pathID);

                if (pathObject != null)
                {
                    SetPath(pathObject, data.targetNode, data.prevNode);
                }
                else
                {
                    ACDebug.LogWarning("Trying to assign a path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject);
                }
            }

            if (data.lastPathID != 0)
            {
                Paths pathObject = ConstantID.GetComponent <Paths> (data.lastPathID);

                if (pathObject != null)
                {
                    SetLastPath(pathObject, data.lastTargetNode, data.lastPrevNode);
                }
                else
                {
                    ACDebug.LogWarning("Trying to assign the previous path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject);
                }
            }

            // Head target
            if (data.isHeadTurning)
            {
                ConstantID _headTargetID = ConstantID.GetComponent <ConstantID> (data.headTargetID);
                if (_headTargetID != null)
                {
                    SetHeadTurnTarget(_headTargetID.transform, new Vector3(data.headTargetX, data.headTargetY, data.headTargetZ), true);
                }
                else
                {
                    ClearHeadTurnTarget(true);
                }
            }
            else
            {
                ClearHeadTurnTarget(true);
            }

            if (GetComponentsInChildren <FollowSortingMap>() != null)
            {
                FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>();
                SortingMap         customSortingMap  = ConstantID.GetComponent <SortingMap> (data.customSortingMapID);

                foreach (FollowSortingMap followSortingMap in followSortingMaps)
                {
                    followSortingMap.followSortingMap = data.followSortingMap;
                    if (!data.followSortingMap && customSortingMap != null)
                    {
                        followSortingMap.SetSortingMap(customSortingMap);
                    }
                    else
                    {
                        followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap);
                    }
                }
            }

            if (GetAnimEngine() != null && GetAnimEngine().IKEnabled)
            {
                LeftHandIKController.LoadData(data.leftHandIKState);
                RightHandIKController.LoadData(data.rightHandIKState);
            }

            _spriteDirectionData.LoadData(data.spriteDirectionData);
        }