public override void OnInspectorGUI()
        {
            RememberNPC _target = (RememberNPC)target;

            if (_target.GetComponent <Hotspot>() != null && _target.GetComponent <RememberHotspot>() == null)
            {
                EditorGUILayout.BeginVertical("Button");
                EditorGUILayout.LabelField("NPC", EditorStyles.boldLabel);
                _target.startState = (AC_OnOff)CustomGUILayout.EnumPopup("Hotspot state on start:", _target.startState, "", "The state of the NPC's Hotspot component when the game begins");
                EditorGUILayout.EndVertical();
            }

            if (_target.GetComponent <NPC>() == null)
            {
                EditorGUILayout.HelpBox("This script expects an NPC component!", MessageType.Warning);
            }


            SharedGUI();
        }
Beispiel #2
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);
            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);
                    }
                }
            }
        }
Beispiel #3
0
        /**
         * <summary>Updates its own variables from a PlayerData class.</summary>
         * <param name = "playerData">The PlayerData class to load from</param>
         */
        public void LoadData(PlayerData playerData)
        {
            upMovementLocked    = playerData.playerUpLock;
            downMovementLocked  = playerData.playerDownLock;
            leftMovementLocked  = playerData.playerLeftlock;
            rightMovementLocked = playerData.playerRightLock;
            runningLocked       = (PlayerMoveLock)playerData.playerRunLock;
            freeAimLocked       = playerData.playerFreeAimLock;

            charState = (playerData.inCustomCharState) ? CharState.Custom : CharState.Idle;

            playerData.UpdateFromTempPosition(this);

            Teleport(new Vector3(playerData.playerLocX, playerData.playerLocY, playerData.playerLocZ));
            SetRotation(playerData.playerRotY);
            SetMoveDirectionAsForward();

            walkSpeedScale = playerData.playerWalkSpeed;
            runSpeedScale  = playerData.playerRunSpeed;

            // Animation clips
            GetAnimEngine().LoadPlayerData(playerData, this);

            // Sound
            walkSound = AssetLoader.RetrieveAsset(walkSound, playerData.playerWalkSound);
            runSound  = AssetLoader.RetrieveAsset(runSound, playerData.playerRunSound);

            // Portrait graphic
            portraitIcon.ReplaceTexture(AssetLoader.RetrieveAsset(portraitIcon.texture, playerData.playerPortraitGraphic));

            // Speech label
            SetName(playerData.playerSpeechLabel, playerData.playerDisplayLineID);

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

            if (playerData.playerLockDirection)
            {
                spriteDirection = playerData.playerSpriteDirection;
                UpdateFrameFlipping(true);
            }
            if (playerData.playerLockScale)
            {
                spriteScale = playerData.playerSpriteScale;
            }
            if (playerData.playerLockSorting)
            {
                if (spriteChild && spriteChild.GetComponent <Renderer>())
                {
                    spriteChild.GetComponent <Renderer>().sortingOrder     = playerData.playerSortingOrder;
                    spriteChild.GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer;
                }
                else if (GetComponent <Renderer>())
                {
                    GetComponent <Renderer>().sortingOrder     = playerData.playerSortingOrder;
                    GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer;
                }
            }

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

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

            // Active path
            Halt();
            ForceIdle();

            if (!string.IsNullOrEmpty(playerData.playerPathData) && GetComponent <Paths>())
            {
                Paths savedPath = GetComponent <Paths>();
                savedPath = Serializer.RestorePathData(savedPath, playerData.playerPathData);
                SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode, playerData.playerPathAffectY);
                isRunning  = playerData.playerIsRunning;
                lockedPath = false;
            }
            else if (playerData.playerActivePath != 0)
            {
                Paths savedPath = ConstantID.GetComponent <Paths> (playerData.playerActivePath);
                if (savedPath)
                {
                    lockedPath = playerData.playerLockedPath;

                    if (lockedPath)
                    {
                        SetLockedPath(savedPath);
                    }
                    else
                    {
                        SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode);
                    }
                }
                else
                {
                    Halt();
                    ForceIdle();
                }
            }
            else
            {
                Halt();
                ForceIdle();
            }

            // Previous path
            if (playerData.lastPlayerActivePath != 0)
            {
                Paths savedPath = ConstantID.GetComponent <Paths> (playerData.lastPlayerActivePath);
                if (savedPath)
                {
                    SetLastPath(savedPath, playerData.lastPlayerTargetNode, playerData.lastPlayerPrevNode);
                }
            }

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

            ignoreGravity = playerData.playerIgnoreGravity;

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

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

            ignoreGravity = playerData.playerIgnoreGravity;

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

            _spriteDirectionData.LoadData(playerData.spriteDirectionData);

            // Remember scripts
            if (!IsLocalPlayer())
            {
                KickStarter.levelStorage.LoadPlayerData(this, playerData);
            }
        }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #5
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))
            {
                FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection, false);
            }
            else
            {
                StopFollowing();
            }
            Halt();

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

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

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

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

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

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

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

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

            _spriteDirectionData.LoadData(data.spriteDirectionData);
        }