Ejemplo n.º 1
0
 public override void Declare(AC.Char _character)
 {
     character    = _character;
     turningStyle = TurningStyle.RootMotion;
 }
Ejemplo n.º 2
0
 public override void Declare(AC.Char _character)
 {
     character     = _character;
     turningStyle  = TurningStyle.Linear;
     isSpriteBased = true;
 }
Ejemplo n.º 3
0
        /**
         * <summary>The default Constructor.</summary>
         * <param name = "_speaker">The speaking character. If null, the line is considered a narration</param>
         * <param name = "_message">The subtitle text to display</param>
         * <param name = "lineID">The unique ID number of the line, as generated by the Speech Manager</param>
         * <param name = "_language">The currently-selected language</param>
         * <param name = "_isBackground">True if the line should play in the background, and not interrupt Actions or gameplay</param>
         * <param name = "_noAnimation">True if the speaking character should not play a talking animation</param>
         */
        public Speech(Char _speaker, string _message, int lineID, string _language, bool _isBackground, bool _noAnimation)
        {
            log.Clear ();
            isBackground = _isBackground;

            if (_speaker)
            {
                speaker = _speaker;
                speaker.isTalking = !_noAnimation;
                log.speakerName = _speaker.name;

                if (_speaker.GetComponent <Player>())
                {
                    if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow || !KickStarter.speechManager.usePlayerRealName)
                    {
                        log.speakerName = "Player";
                    }
                }

                if (_speaker.GetComponent <Hotspot>())
                {
                    if (_speaker.GetComponent <Hotspot>().hotspotName != "")
                    {
                        log.speakerName = _speaker.GetComponent <Hotspot>().hotspotName;
                    }
                }

                _speaker.ClearExpression ();

                if (!_noAnimation)
                {
                    if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Off)
                    {
                        speaker.isLipSyncing = false;
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Salsa2D || KickStarter.speechManager.lipSyncMode == LipSyncMode.FromSpeechText || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPamelaFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadSapiFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPapagayoFile)
                    {
                        speaker.StartLipSync (KickStarter.dialog.GenerateLipSyncShapes (KickStarter.speechManager.lipSyncMode, lineID, speaker.name, _language, _message));
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.RogoLipSync)
                    {
                        RogoLipSyncIntegration.Play (_speaker, speaker.name, lineID, _language);
                    }
                }
            }
            else
            {
                if (speaker)
                {
                    speaker.isTalking = false;
                }
                speaker = null;
                log.speakerName = "Narrator";
            }

            _message = AdvGame.ConvertTokens (_message);
            _message = DetermineGaps (_message);
            if (speechGaps.Count > 0)
            {
                gapIndex = 0;
                foreach (SpeechGap gap in speechGaps)
                {
                    if (gap.expressionID < 0)
                    {
                        displayDuration += (float) gap.waitTime;
                    }
                }
            }
            else
            {
                gapIndex = -1;
            }

            if (lineID > -1)
            {
                log.lineID = lineID;
            }

            // Play sound and time displayDuration to it
            if (lineID > -1 && log.speakerName != "" && KickStarter.speechManager.searchAudioFiles)
            {
                string fullFilename = "Speech/";
                string filename = KickStarter.speechManager.GetLineFilename (lineID);
                if (_language != "" && KickStarter.speechManager.translateAudio)
                {
                    // Not in original language
                    fullFilename += _language + "/";
                }
                if (KickStarter.speechManager.placeAudioInSubfolders)
                {
                    fullFilename += filename + "/";
                }
                fullFilename += filename + lineID;

                AudioClip clipObj = Resources.Load (fullFilename) as AudioClip;
                if (clipObj)
                {
                    AudioSource audioSource = null;

                    if (_speaker != null)
                    {
                        if (!_noAnimation)
                        {
                            if (KickStarter.speechManager.lipSyncMode == LipSyncMode.FaceFX)
                            {
                                FaceFXIntegration.Play (speaker, log.speakerName + lineID, clipObj);
                            }
                        }

                        if (_speaker.speechAudioSource)
                        {
                            _speaker.speechAudioSource.volume = Options.optionsData.speechVolume;
                            audioSource = _speaker.speechAudioSource;
                        }
                        else
                        {
                            ACDebug.LogWarning (_speaker.name + " has no audio source component!");
                        }
                    }
                    else if (KickStarter.player && KickStarter.player.speechAudioSource)
                    {
                        KickStarter.player.speechAudioSource.volume = Options.optionsData.speechVolume;
                        audioSource = KickStarter.player.speechAudioSource;
                    }
                    else
                    {
                        audioSource = KickStarter.dialog.GetDefaultAudioSource ();
                    }

                    if (audioSource != null)
                    {
                        audioSource.clip = clipObj;
                        audioSource.loop = false;
                        audioSource.Play();
                        hasAudio = true;
                    }

                    displayDuration = clipObj.length;
                }
                else
                {
                    displayDuration += KickStarter.speechManager.screenTimeFactor * (float) _message.Length;
                    if (displayDuration < 0.5f)
                    {
                        displayDuration = 0.5f;
                    }

                    ACDebug.Log ("Cannot find audio file: " + fullFilename);
                }
            }
            else
            {
                displayDuration += KickStarter.speechManager.screenTimeFactor * (float) _message.Length;
                if (displayDuration < 0.5f)
                {
                    displayDuration = 0.5f;
                }
            }

            log.fullText = _message;

            if (!CanScroll ())
            {
                if (continueIndex > 0)
                {
                    continueTime = (continueIndex / KickStarter.speechManager.textScrollSpeed);
                }

                if (speechGaps.Count > 0)
                {
                    displayText = log.fullText.Substring (0, speechGaps[0].characterIndex);
                }
                else
                {
                    displayText = log.fullText;
                }
            }
            else
            {
                displayText = "";
            }

            isAlive = true;
            isSkippable = true;
            pauseGap = false;
            endTime = displayDuration;
        }
Ejemplo n.º 4
0
 public virtual Vector3[] GetPointsArray(AC.Char _char, Vector3 startPosition, Vector3 targetPosition)
 {
     return(GetPointsArray(startPosition, targetPosition));
 }
Ejemplo n.º 5
0
        protected void AddCharHoles(PolygonCollider2D[] navPolys, AC.Char charToExclude, NavigationMesh navigationMesh)
        {
            if (navigationMesh.characterEvasion == CharacterEvasion.None)
            {
                return;
            }

            ResetHoles(KickStarter.sceneSettings.navMesh, false);

            for (int p = 0; p < navPolys.Length; p++)
            {
                if (p > 0)
                {
                    return;
                }

                if (navPolys[p].transform.lossyScale != Vector3.one)
                {
                    ACDebug.LogWarning("Cannot create evasion Polygons inside NavMesh '" + navPolys[p].gameObject.name + "' because it has a non-unit scale.");
                    continue;
                }

                Vector2 navPosition = navPolys[p].transform.position;

                foreach (AC.Char character in KickStarter.stateHandler.Characters)
                {
                    // Discard if not inside
                    if (!navPolys[p].OverlapPoint(character.transform.position))
                    {
                        continue;
                    }

                    CircleCollider2D circleCollider2D = character.GetComponent <CircleCollider2D>();
                    if (circleCollider2D != null &&
                        (character.charState == CharState.Idle || navigationMesh.characterEvasion == CharacterEvasion.AllCharacters) &&
                        (charToExclude == null || character != charToExclude) &&
                        Perform2DOverlapPoint(character.Transform.position, results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0)
                    {
                        if (character.IsPlayer && KickStarter.settingsManager.movementMethod == MovementMethod.Direct)
                        {
                            // In this particular case, do not set Is Trigger
                        }
                        else
                        {
                            circleCollider2D.isTrigger = true;
                        }

                        List <Vector2> newPoints3D = new List <Vector2>();

                        Vector2 centrePoint = character.Transform.TransformPoint(circleCollider2D.offset);

                        float radius  = circleCollider2D.radius * character.Transform.localScale.x;
                        float yScaler = navigationMesh.characterEvasionYScale;

                        switch (navigationMesh.characterEvasionPoints)
                        {
                        case CharacterEvasionPoints.Four:
                            newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler));
                            break;

                        case CharacterEvasionPoints.Eight:
                            newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler));
                            break;

                        case CharacterEvasionPoints.Sixteen:
                            newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nne.x * radius, dir_nne.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nee.x * radius, dir_nee.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_see.x * radius, dir_see.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sse.x * radius, dir_sse.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_ssw.x * radius, dir_ssw.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sww.x * radius, dir_sww.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nww.x * radius, dir_nww.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nnw.x * radius, dir_nnw.y * radius * yScaler));
                            break;
                        }

                        navPolys[p].pathCount++;

                        List <Vector2> newPoints = new List <Vector2>();
                        for (int i = 0; i < newPoints3D.Count; i++)
                        {
                            // Only add a point if it is on the NavMesh
                            if (Perform2DOverlapPoint(newPoints3D[i], results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0)
                            {
                                newPoints.Add(newPoints3D[i] - navPosition);
                            }
                            else
                            {
                                Vector2 altPoint = GetLineIntersect(newPoints3D[i], centrePoint);
                                if (altPoint != Vector2.zero)
                                {
                                    newPoints.Add(altPoint - navPosition);
                                }
                            }
                        }

                        if (newPoints.Count > 1)
                        {
                            navPolys[p].SetPath(navPolys[p].pathCount - 1, newPoints.ToArray());
                        }
                    }
                }

                RebuildVertexArray(navPolys[p].transform, navPolys[p], p);
            }
        }
Ejemplo n.º 6
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)
        {
            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>();
                }
            }

            FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection);
            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?");
                }
            }

            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?");
                }
            }

            // 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)
                    {
                        followSortingMap.SetSortingMap(customSortingMap);
                    }
                }
            }
        }
Ejemplo n.º 7
0
		public float StartDialog (AC.Char _speakerChar, string message, int lineNumber, string language, bool _isBackground)
		{
			isMessageAlive = false;
			currentLineHasAudio = false;
			isBackground = _isBackground;

			if (_speakerChar)
			{
				speakerChar = _speakerChar;
				speakerChar.isTalking = true;

				speakerName = _speakerChar.name;
				if (_speakerChar.GetComponent <Player>())
				{
					speakerName = "Player";
				}
				
				if (_speakerChar.portraitIcon != null)
				{
					_speakerChar.portraitIcon.Reset ();
				}
				
				if (_speakerChar.GetComponent <Hotspot>())
				{
					if (_speakerChar.GetComponent <Hotspot>().hotspotName != "")
					{
						speakerName = _speakerChar.GetComponent <Hotspot>().hotspotName;
					}
				}

				if (speechManager.lipSyncMode == LipSyncMode.Off)
				{
					speakerChar.isLipSyncing = false;
				}
				else if (speechManager.lipSyncMode == LipSyncMode.FromSpeechText || speechManager.lipSyncMode == LipSyncMode.ReadPamelaFile || speechManager.lipSyncMode == LipSyncMode.ReadSapiFile)
				{
					speakerChar.StartLipSync (GenerateLipSyncShapes (speechManager.lipSyncMode, lineNumber, speakerName, language, message));
				}
			}
			else
			{
				if (speakerChar)
				{
					speakerChar.isTalking = false;
				}
				speakerChar = null;			
				speakerName = "Narrator";
			}
			
			// Play sound and time displayDuration to it
			if (lineNumber > -1 && speakerName != "" && speechManager.searchAudioFiles)
			{
				string filename = "Speech/";
				if (language != "" && speechManager.translateAudio)
				{
					// Not in original language
					filename += language + "/";
				}
				filename += speakerName + lineNumber;
				
				foundAudio = false;
				AudioClip clipObj = Resources.Load(filename) as AudioClip;
				if (clipObj)
				{
					AudioSource audioSource = null;
					currentLineHasAudio = true;

					if (_speakerChar != null)
					{
						if (speechManager.lipSyncMode == LipSyncMode.FaceFX)
						{
							FaceFXIntegration.Play (speakerChar, speakerName + lineNumber, clipObj);
						}

						if (_speakerChar.GetComponent <AudioSource>())
						{
							_speakerChar.GetComponent <AudioSource>().volume = options.optionsData.speechVolume;
							audioSource = _speakerChar.GetComponent <AudioSource>();
						}
						else
						{
							Debug.LogWarning (_speakerChar.name + " has no audio source component!");
						}
					}
					else if (KickStarter.player && KickStarter.player.GetComponent <AudioSource>())
					{
						KickStarter.player.GetComponent <AudioSource>().volume = options.optionsData.speechVolume;
						audioSource = KickStarter.player.GetComponent <AudioSource>();
					}
					else if (defaultAudioSource != null)
					{
						audioSource = defaultAudioSource;
					}
					
					if (audioSource != null)
					{
						audioSource.clip = clipObj;
						audioSource.loop = false;
						audioSource.Play();
						
						foundAudio = true;
					}
					
					displayDuration = clipObj.length;
				}
				else
				{
					displayDuration = speechManager.screenTimeFactor * (float) message.Length;
					if (displayDuration < 0.5f)
					{
						displayDuration = 0.5f;
					}
					
					Debug.Log ("Cannot find audio file: " + filename);
				}
			}
			else
			{
				displayDuration = speechManager.screenTimeFactor * (float) message.Length;
				if (displayDuration < 0.5f)
				{
					displayDuration = 0.5f;
				}
			}

			message = DetermineGaps (message);
			if (speechGaps.Count > 0)
			{
				gapIndex = 0;
				allGapText = message;

				foreach (SpeechGap gap in speechGaps)
				{
					displayDuration += (float) gap.waitTime;
				}
			}
			else
			{
				gapIndex = -1;
			}

			StopCoroutine ("StartMessage");
			StartCoroutine ("StartMessage", message);

			return displayDuration;
		}
Ejemplo n.º 8
0
        public Speech(Char _speaker, string _message, int lineID, string _language, bool _isBackground, bool _noAnimation)
        {
            log.Clear();
            isBackground = _isBackground;

            if (_speaker)
            {
                speaker           = _speaker;
                speaker.isTalking = !_noAnimation;
                log.speakerName   = _speaker.name;

                if (_speaker.GetComponent <Player>())
                {
                    if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow || !KickStarter.speechManager.usePlayerRealName)
                    {
                        log.speakerName = "Player";
                    }
                }

                if (_speaker.GetComponent <Hotspot>())
                {
                    if (_speaker.GetComponent <Hotspot>().hotspotName != "")
                    {
                        log.speakerName = _speaker.GetComponent <Hotspot>().hotspotName;
                    }
                }

                if (_speaker.portraitIcon != null)
                {
                    _speaker.portraitIcon.Reset();
                }

                if (!_noAnimation)
                {
                    if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Off)
                    {
                        speaker.isLipSyncing = false;
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Salsa2D || KickStarter.speechManager.lipSyncMode == LipSyncMode.FromSpeechText || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPamelaFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadSapiFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPapagayoFile)
                    {
                        speaker.StartLipSync(KickStarter.dialog.GenerateLipSyncShapes(KickStarter.speechManager.lipSyncMode, lineID, log.speakerName, _language, _message));
                    }
                }
            }
            else
            {
                if (speaker)
                {
                    speaker.isTalking = false;
                }
                speaker         = null;
                log.speakerName = "Narrator";
            }

            _message = AdvGame.ConvertTokens(_message);

            if (lineID > -1)
            {
                log.lineID = lineID;
            }

            // Play sound and time displayDuration to it
            if (lineID > -1 && log.speakerName != "" && KickStarter.speechManager.searchAudioFiles)
            {
                string fullFilename = "Speech/";
                string filename     = KickStarter.speechManager.GetLineFilename(lineID);
                if (_language != "" && KickStarter.speechManager.translateAudio)
                {
                    // Not in original language
                    fullFilename += _language + "/";
                }
                if (KickStarter.speechManager.placeAudioInSubfolders)
                {
                    fullFilename += filename + "/";
                }
                fullFilename += filename + lineID;

                AudioClip clipObj = Resources.Load(fullFilename) as AudioClip;
                if (clipObj)
                {
                    AudioSource audioSource = null;

                    if (_speaker != null)
                    {
                        if (!_noAnimation)
                        {
                            if (KickStarter.speechManager.lipSyncMode == LipSyncMode.FaceFX)
                            {
                                FaceFXIntegration.Play(speaker, log.speakerName + lineID, clipObj);
                            }
                        }

                        if (_speaker.GetComponent <AudioSource>())
                        {
                            _speaker.GetComponent <AudioSource>().volume = KickStarter.options.optionsData.speechVolume;
                            audioSource = _speaker.GetComponent <AudioSource>();
                        }
                        else
                        {
                            Debug.LogWarning(_speaker.name + " has no audio source component!");
                        }
                    }
                    else if (KickStarter.player && KickStarter.player.GetComponent <AudioSource>())
                    {
                        KickStarter.player.GetComponent <AudioSource>().volume = KickStarter.options.optionsData.speechVolume;
                        audioSource = KickStarter.player.GetComponent <AudioSource>();
                    }
                    else
                    {
                        audioSource = KickStarter.dialog.GetDefaultAudioSource();
                    }

                    if (audioSource != null)
                    {
                        audioSource.clip = clipObj;
                        audioSource.loop = false;
                        audioSource.Play();
                        hasAudio = true;
                    }

                    displayDuration = clipObj.length;
                }
                else
                {
                    displayDuration = KickStarter.speechManager.screenTimeFactor * (float)_message.Length;
                    if (displayDuration < 0.5f)
                    {
                        displayDuration = 0.5f;
                    }

                    Debug.Log("Cannot find audio file: " + fullFilename);
                }
            }
            else
            {
                displayDuration = KickStarter.speechManager.screenTimeFactor * (float)_message.Length;
                if (displayDuration < 0.5f)
                {
                    displayDuration = 0.5f;
                }
            }

            _message = DetermineGaps(_message);

            if (speechGaps.Count > 0)
            {
                gapIndex = 0;
                foreach (SpeechGap gap in speechGaps)
                {
                    displayDuration += (float)gap.waitTime;
                }
            }
            else
            {
                gapIndex = -1;
            }

            log.fullText = _message;

            if (!KickStarter.speechManager.scrollSubtitles)
            {
                if (continueIndex > 0)
                {
                    continueTime = Time.time + (continueIndex / KickStarter.speechManager.textScrollSpeed);
                }

                if (speechGaps.Count > 0)
                {
                    displayText = log.fullText.Substring(0, speechGaps[0].characterIndex);
                }
                else
                {
                    displayText = log.fullText;
                }
            }
            else
            {
                displayText = "";
            }

            isAlive     = true;
            isSkippable = true;
            pauseGap    = false;
            endTime     = Time.time + displayDuration;
        }
Ejemplo n.º 9
0
        /**
         * <summary>Calculates a path between two points.</summary>
         * <param name = "startPosition">The start position</param>
         * <param name = "targetPosition">The intended end position</param>
         * <param name = "_char">The character (see Char) who this path is for (only used in PolygonCollider pathfinding)</param>
         * <returns>The path to take, as an array of Vector3s.</returns>
         */
        public virtual Vector3[] GetPointsArray(Vector3 startPosition, Vector3 targetPosition, AC.Char _char = null)
        {
            List <Vector3> pointsList = new List <Vector3>();

            pointsList.Add(targetPosition);
            return(pointsList.ToArray());
        }
Ejemplo n.º 10
0
        /**
         * <summary>Calculates a path between multiple points.</summary>
         * <param name = "startPosition">The start position</param>
         * <param name = "targetPositions">An array of positions to travel through along the path, with the last entry being the intended destination</param>
         * <param name = "_char">The character (see Char) who this path is for (only used in PolygonCollider pathfinding)</param>
         * <returns>The path to take, as an array of Vector3s.</returns>
         */
        public Vector3[] GetPointsArray(Vector3 startPosition, Vector3[] targetPositions, AC.Char _char = null)
        {
            if (targetPositions == null || targetPositions.Length == 0)
            {
                return(GetPointsArray(startPosition, startPosition, _char));
            }

            List <Vector3> pointsList = new List <Vector3>();

            for (int i = 0; i < targetPositions.Length; i++)
            {
                Vector3   partialStartPosition = (i > 0) ? targetPositions[i - 1] : startPosition;
                Vector3[] partialPointsArray   = GetPointsArray(partialStartPosition, targetPositions[i], _char);

                foreach (Vector3 partialPoint in partialPointsArray)
                {
                    if (pointsList.Count == 0 || pointsList[pointsList.Count - 1] != partialPoint)
                    {
                        pointsList.Add(partialPoint);
                    }
                }
            }

            return(pointsList.ToArray());
        }
Ejemplo n.º 11
0
 public override void Declare(AC.Char _character)
 {
     character        = _character;
     turningStyle     = TurningStyle.RootMotion;
     updateHeadAlways = (character != null && character.ikHeadTurning);
 }
Ejemplo n.º 12
0
        /**
         * <summary>The default Constructor.</summary>
         * <param name = "_speaker">The speaking character. If null, the line is considered a narration</param>
         * <param name = "_message">The subtitle text to display</param>
         * <param name = "lineID">The unique ID number of the line, as generated by the Speech Manager</param>
         * <param name = "_language">The currently-selected language</param>
         * <param name = "_isBackground">True if the line should play in the background, and not interrupt Actions or gameplay</param>
         * <param name = "_noAnimation">True if the speaking character should not play a talking animation</param>
         * <param name = "_runActionListInBackground">True if the ActionList that contains the call is set to Run In Background</param>
         */
        public Speech(Char _speaker, string _message, int lineID, string _language, bool _isBackground, bool _noAnimation, bool _runActionListInBackground = false)
        {
            // Clear rich text
            boldTagIndex = italicTagIndex = sizeTagIndex = colorTagIndex = -1;
            closingTags  = "";

            log.Clear();
            isBackground = _isBackground;
            runActionListInBackground = _runActionListInBackground;

            if (_speaker)
            {
                speaker           = _speaker;
                speaker.isTalking = !_noAnimation;
                log.speakerName   = _speaker.name;

                if (_speaker.GetComponent <Player>())
                {
                    if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow || !KickStarter.speechManager.usePlayerRealName)
                    {
                        log.speakerName = "Player";
                    }
                }

                if (_speaker.GetComponent <Hotspot>())
                {
                    if (_speaker.GetComponent <Hotspot>().hotspotName != "")
                    {
                        log.speakerName = _speaker.GetComponent <Hotspot>().hotspotName;
                    }
                }

                _speaker.ClearExpression();

                if (!_noAnimation)
                {
                    if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Off)
                    {
                        speaker.isLipSyncing = false;
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.Salsa2D || KickStarter.speechManager.lipSyncMode == LipSyncMode.FromSpeechText || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPamelaFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadSapiFile || KickStarter.speechManager.lipSyncMode == LipSyncMode.ReadPapagayoFile)
                    {
                        speaker.StartLipSync(KickStarter.dialog.GenerateLipSyncShapes(KickStarter.speechManager.lipSyncMode, lineID, speaker.name, _language, _message));
                    }
                    else if (KickStarter.speechManager.lipSyncMode == LipSyncMode.RogoLipSync)
                    {
                        RogoLipSyncIntegration.Play(_speaker, lineID, _language);
                    }
                }
            }
            else
            {
                if (speaker)
                {
                    speaker.isTalking = false;
                }
                speaker         = null;
                log.speakerName = "Narrator";
            }

            _message = DetermineGaps(_message);
            if (speechGaps.Count > 0)
            {
                gapIndex = 0;

                /*foreach (SpeechGap gap in speechGaps)
                 * {
                 *      if (gap.expressionID < 0)
                 *      {
                 *              displayDuration += (float) gap.waitTime;
                 *      }
                 * }*/
            }
            else
            {
                gapIndex = -1;
            }

            if (lineID > -1)
            {
                log.lineID = lineID;
            }

            // Play sound and time displayDuration to it
            if (lineID > -1 && log.speakerName != "" && KickStarter.speechManager.searchAudioFiles)
            {
                AudioClip clipObj = null;

                if (KickStarter.speechManager.autoNameSpeechFiles)
                {
                    string fullFilename = "Speech/";
                    string filename     = KickStarter.speechManager.GetLineFilename(lineID);
                    if (_language != "" && KickStarter.speechManager.translateAudio)
                    {
                        // Not in original language
                        fullFilename += _language + "/";
                    }
                    if (KickStarter.speechManager.placeAudioInSubfolders)
                    {
                        fullFilename += filename + "/";
                    }
                    fullFilename += filename + lineID;

                    clipObj = Resources.Load(fullFilename) as AudioClip;

                    if (clipObj == null && KickStarter.speechManager.fallbackAudio && Options.GetLanguage() > 0)
                    {
                        fullFilename = "Speech/";
                        if (KickStarter.speechManager.placeAudioInSubfolders)
                        {
                            fullFilename += filename + "/";
                        }
                        fullFilename += filename + lineID;
                        clipObj       = Resources.Load(fullFilename) as AudioClip;
                    }

                    if (clipObj == null)
                    {
                        ACDebug.Log("Cannot find audio file: " + fullFilename);
                    }
                }
                else
                {
                    clipObj = KickStarter.runtimeLanguages.GetLineCustomAudioClip(lineID, Options.GetLanguage());

                    if (clipObj == null && KickStarter.speechManager.fallbackAudio && Options.GetLanguage() > 0)
                    {
                        clipObj = KickStarter.runtimeLanguages.GetLineCustomAudioClip(lineID, 0);
                    }
                }

                if (clipObj)
                {
                    audioSource = null;

                    if (_speaker != null)
                    {
                        if (!_noAnimation)
                        {
                            if (KickStarter.speechManager.lipSyncMode == LipSyncMode.FaceFX)
                            {
                                FaceFXIntegration.Play(speaker, log.speakerName + lineID, clipObj);
                            }
                        }

                        if (_speaker.speechAudioSource)
                        {
                            audioSource = _speaker.speechAudioSource;
                            _speaker.SetSpeechVolume(Options.optionsData.speechVolume);
                        }
                        else
                        {
                            ACDebug.LogWarning(_speaker.name + " has no audio source component!");
                        }
                    }

                    /*else if (KickStarter.player && KickStarter.player.speechAudioSource)
                     * {
                     *      KickStarter.player.SetSpeechVolume (Options.optionsData.speechVolume);
                     *      audioSource = KickStarter.player.speechAudioSource;
                     * }*/
                    else
                    {
                        audioSource = KickStarter.dialog.GetNarratorAudioSource();

                        if (audioSource == null)
                        {
                            ACDebug.LogWarning("Cannot play audio for speech line '" + _message + "' as there is no AudioSource - assign a new 'Default Sound' in the Scene Manager.");
                        }
                    }

                    if (audioSource != null)
                    {
                        audioSource.clip = clipObj;
                        audioSource.loop = false;
                        audioSource.Play();
                        hasAudio = true;
                    }

                    displayDuration = clipObj.length;
                }
                else
                {
                    displayDuration += KickStarter.speechManager.screenTimeFactor * GetLengthWithoutRichText(_message);
                    displayDuration  = Mathf.Max(displayDuration, KickStarter.speechManager.minimumDisplayTime);
                }
            }
            else
            {
                displayDuration += KickStarter.speechManager.screenTimeFactor * GetLengthWithoutRichText(_message);
                displayDuration  = Mathf.Max(displayDuration, KickStarter.speechManager.minimumDisplayTime);
            }

            log.fullText = _message;
            KickStarter.eventManager.Call_OnStartSpeech(_speaker, log.fullText, lineID);

            if (!CanScroll())
            {
                if (continueIndex > 0)
                {
                    continueTime = (continueIndex / KickStarter.speechManager.textScrollSpeed);
                }

                if (speechGaps.Count > 0)
                {
                    displayText = log.fullText.Substring(0, speechGaps[0].characterIndex);
                }
                else
                {
                    displayText = log.fullText;
                }
            }
            else
            {
                displayText = "";
                KickStarter.eventManager.Call_OnStartSpeechScroll(_speaker, log.fullText, lineID);
            }

            isAlive     = true;
            isSkippable = true;
            pauseGap    = false;
            endTime     = displayDuration;
            minSkipTime = KickStarter.speechManager.skipThresholdTime;
        }
Ejemplo n.º 13
0
        private void Finish()
        {
            bool is2D = false;

            GameObject newCharacterOb = baseObject;
            GameObject newBaseObject  = baseObject;

            if (IsFirstPerson())
            {
                newBaseObject = new GameObject("Player");
                newBaseObject.AddComponent <Paths>();
                newBaseObject.AddComponent <Rigidbody>();
                Player playerScript = newBaseObject.AddComponent <Player>();
                playerScript.animationEngine = animationEngine;
                newBaseObject.tag            = Tags.player;
                CapsuleCollider capsuleCollider = newBaseObject.AddComponent <CapsuleCollider>();
                capsuleCollider.center = new Vector3(0f, 1f, 0f);
                capsuleCollider.height = 2f;

                GameObject cameraObject = new GameObject("First person camera");
                cameraObject.transform.parent   = newBaseObject.transform;
                cameraObject.transform.position = new Vector3(0f, 1.5f, 0f);
                Camera cam = cameraObject.AddComponent <Camera>();
                cam.enabled = false;
                cameraObject.AddComponent <FirstPersonCamera>();

                newBaseObject.layer = LayerMask.NameToLayer("Ignore Raycast");
                return;
            }

            if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex)
            {
                string _name = charName;
                if (charName == null || charName.Length == 0)
                {
                    _name = ("My new " + charType.ToString());
                }

                if (!enforce3D)
                {
                    is2D = true;

                    FollowSortingMap followSortingMap = newCharacterOb.AddComponent <FollowSortingMap>();
                    followSortingMap.followSortingMap = true;
                }

                newBaseObject = new GameObject(_name);
                newCharacterOb.transform.parent      = newBaseObject.transform;
                newCharacterOb.transform.position    = Vector3.zero;
                newCharacterOb.transform.eulerAngles = Vector3.zero;

                newBaseObject.layer = LayerMask.NameToLayer("Ignore Raycast");
            }

            if (animationEngine == AnimationEngine.Mecanim || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex)
            {
                if (newCharacterOb.GetComponent <Animator>() == null)
                {
                    newCharacterOb.AddComponent <Animator>();
                }
            }
            else if (animationEngine == AnimationEngine.Legacy)
            {
                if (newCharacterOb.GetComponent <Animation>() == null)
                {
                    newCharacterOb.AddComponent <Animation>();
                }
            }

            if (newBaseObject.GetComponent <AudioSource>() == null)
            {
                newBaseObject.AddComponent <AudioSource>();
            }

            if (newBaseObject.GetComponent <Paths>() == null)
            {
                newBaseObject.AddComponent <Paths>();
            }

            AC.Char charScript = null;
            if (charType == CharType.Player)
            {
                charScript        = newBaseObject.AddComponent <Player>();
                newBaseObject.tag = Tags.player;
            }
            else if (charType == CharType.NPC)
            {
                charScript = newBaseObject.AddComponent <NPC>();

                if (is2D)
                {
                    BoxCollider2D boxCollider = newCharacterOb.AddComponent <BoxCollider2D>();
                    UnityVersionHandler.SetBoxCollider2DCentre(boxCollider, new Vector2(0f, 1f));
                    boxCollider.size      = new Vector2(1f, 2f);
                    boxCollider.isTrigger = true;
                }
                else
                {
                    CapsuleCollider capsuleCollider = newCharacterOb.AddComponent <CapsuleCollider>();
                    capsuleCollider.center = new Vector3(0f, 1f, 0f);
                    capsuleCollider.height = 2f;
                }

                Hotspot hotspot = newCharacterOb.AddComponent <Hotspot>();
                if (is2D)
                {
                    hotspot.drawGizmos = false;
                }
                hotspot.hotspotName = charName;
            }

            if (is2D)
            {
                newBaseObject.AddComponent <CircleCollider2D>();

                if (charType == CharType.Player)
                {
                    if (newBaseObject.GetComponent <Rigidbody2D>() == null)
                    {
                        newBaseObject.AddComponent <Rigidbody2D>();
                    }
                    charScript.ignoreGravity = true;
                }
            }
            else
            {
                if (newBaseObject.GetComponent <Rigidbody>() == null)
                {
                    newBaseObject.AddComponent <Rigidbody>();
                }
                if (charType == CharType.Player)
                {
                    CapsuleCollider capsuleCollider = newBaseObject.AddComponent <CapsuleCollider>();
                    capsuleCollider.center = new Vector3(0f, 1f, 0f);
                    capsuleCollider.height = 2f;
                    newBaseObject.layer    = LayerMask.NameToLayer("Ignore Raycast");
                }
            }

            if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex)
            {
                charScript.spriteChild = newCharacterOb.transform;
            }

            if (charType == CharType.Player && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.hotspotDetection == HotspotDetection.PlayerVicinity)
            {
                GameObject detectorOb = new GameObject("HotspotDetector");
                detectorOb.transform.parent   = newBaseObject.transform;
                detectorOb.transform.position = Vector3.zero;
                detectorOb.AddComponent <DetectHotspots>();

                if (is2D)
                {
                    CircleCollider2D circleCollider = detectorOb.AddComponent <CircleCollider2D>();
                    circleCollider.isTrigger = true;
                }
                else
                {
                    SphereCollider sphereCollider = detectorOb.AddComponent <SphereCollider>();
                    sphereCollider.isTrigger = true;
                }
            }

            charScript.animationEngine = animationEngine;
            if (animationEngine == AC.AnimationEngine.Custom)
            {
                charScript.customAnimationClass = customAnimationClass;
            }
            charScript.speechLabel = charName;

            GameObject soundChild = new GameObject("Sound child");

            soundChild.transform.parent        = newBaseObject.transform;
            soundChild.transform.localPosition = Vector3.zero;
            soundChild.AddComponent <AudioSource>();
            Sound sound = soundChild.AddComponent <Sound>();

            charScript.soundChild = sound;

            baseObject = null;
            charName   = "";
            EditorGUIUtility.PingObject(newBaseObject);
        }
Ejemplo n.º 14
0
 private void Callback(object obj)
 {
     AC.Char t = (AC.Char)target;
     ModifyAction(t, expressionToAffect, obj.ToString());
     EditorUtility.SetDirty(t);
 }
Ejemplo n.º 15
0
		private void OnDestroy ()
		{
			playerInput = null;
			speakerChar = null;
			speechManager = null;
			defaultAudioSource = null;
		}
Ejemplo n.º 16
0
        protected void SharedGUITwo(AC.Char _target)
        {
            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Physics settings:", EditorStyles.boldLabel);
            _target.ignoreGravity = EditorGUILayout.Toggle("Ignore gravity?", _target.ignoreGravity);
            if (_target.GetComponent <Rigidbody>() != null || _target.GetComponent <Rigidbody2D>() != null)
            {
                _target.freezeRigidbodyWhenIdle = EditorGUILayout.Toggle("Freeze Rigidbody when Idle?", _target.freezeRigidbodyWhenIdle);
                if (_target.GetComponent <Rigidbody>() != null)
                {
                    _target.useRigidbodyForMovement = EditorGUILayout.Toggle("Move with Rigidbody?", _target.useRigidbodyForMovement);

                    if (_target.useRigidbodyForMovement)
                    {
                        if (_target.GetAnimator() != null && _target.GetAnimator().applyRootMotion)
                        {
                            EditorGUILayout.HelpBox("Rigidbody movement will be disabled as 'Root motion' is enabled in the Animator.", MessageType.Info);
                        }
                        else if (_target.GetComponent <Rigidbody>().interpolation == RigidbodyInterpolation.None)
                        {
                            EditorGUILayout.HelpBox("For smooth movement, the Rigidbody's 'Interpolation' should be set to either 'Interpolate' or 'Extrapolate'.", MessageType.Warning);
                        }
                    }
                }
                else if (_target.GetComponent <Rigidbody2D>() != null)
                {
                    _target.useRigidbody2DForMovement = EditorGUILayout.Toggle("Move with Rigidbody 2D?", _target.useRigidbody2DForMovement);

                    if (_target.useRigidbody2DForMovement)
                    {
                        if (_target.GetAnimator() != null && _target.GetAnimator().applyRootMotion)
                        {
                            EditorGUILayout.HelpBox("Rigidbody movement will be disabled as 'Root motion' is enabled in the Animator.", MessageType.Info);
                        }
                        else if (_target.GetComponent <Rigidbody2D>().interpolation == RigidbodyInterpolation2D.None)
                        {
                            EditorGUILayout.HelpBox("For smooth movement, the Rigidbody's 'Interpolation' should be set to either 'Interpolate' or 'Extrapolate'.", MessageType.Warning);
                        }
                    }
                }
            }

            if (_target.GetComponent <Collider>() != null && _target.GetComponent <CharacterController>() == null)
            {
                _target.groundCheckLayerMask = LayerMaskField("Ground-check layer(s):", _target.groundCheckLayerMask);
            }
            EditorGUILayout.EndVertical();


            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Audio clips:", EditorStyles.boldLabel);

            _target.walkSound = (AudioClip)EditorGUILayout.ObjectField("Walk sound:", _target.walkSound, typeof(AudioClip), false);
            _target.runSound  = (AudioClip)EditorGUILayout.ObjectField("Run sound:", _target.runSound, typeof(AudioClip), false);
            if (AdvGame.GetReferences() != null && AdvGame.GetReferences().speechManager != null && AdvGame.GetReferences().speechManager.scrollSubtitles)
            {
                _target.textScrollClip = (AudioClip)EditorGUILayout.ObjectField("Text scroll override:", _target.textScrollClip, typeof(AudioClip), false);
            }
            _target.soundChild        = (Sound)EditorGUILayout.ObjectField("SFX Sound child:", _target.soundChild, typeof(Sound), true);
            _target.speechAudioSource = (AudioSource)EditorGUILayout.ObjectField("Speech AudioSource:", _target.speechAudioSource, typeof(AudioSource), true);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Dialogue settings:", EditorStyles.boldLabel);

            _target.speechColor         = EditorGUILayout.ColorField("Speech text colour:", _target.speechColor);
            _target.speechLabel         = EditorGUILayout.TextField("Speaker label:", _target.speechLabel);
            _target.speechMenuPlacement = (Transform)EditorGUILayout.ObjectField("Speech menu placement child:", _target.speechMenuPlacement, typeof(Transform), true);
            if (_target.useExpressions)
            {
                EditorGUILayout.LabelField("Default portrait graphic:");
            }
            else
            {
                EditorGUILayout.LabelField("Portrait graphic:");
            }
            _target.portraitIcon.ShowGUI(false);

            _target.useExpressions = EditorGUILayout.Toggle("Use expressions?", _target.useExpressions);
            if (_target.useExpressions)
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical("Button");
                for (int i = 0; i < _target.expressions.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Expression #" + _target.expressions[i].ID.ToString(), EditorStyles.boldLabel);
                    if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                    {
                        ExpressionSideMenu(_target, i);
                    }
                    EditorGUILayout.EndHorizontal();
                    _target.expressions[i].ShowGUI();
                }

                if (GUILayout.Button("Add new expression"))
                {
                    _target.expressions.Add(new Expression(GetExpressionIDArray(_target.expressions)));
                }
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 17
0
        /**
         * <summary>Serialises appropriate GameObject values into a string.</summary>
         * <returns>The data, serialised as a string</returns>
         */
        public TransformData SaveTransformData()
        {
            TransformData transformData = new TransformData();

            transformData.objectID = constantID;

            transformData.LocX = transform.position.x;
            transformData.LocY = transform.position.y;
            transformData.LocZ = transform.position.z;

            transformData.RotX = transform.eulerAngles.x;
            transformData.RotY = transform.eulerAngles.y;
            transformData.RotZ = transform.eulerAngles.z;

            transformData.ScaleX = transform.localScale.x;
            transformData.ScaleY = transform.localScale.y;
            transformData.ScaleZ = transform.localScale.z;

            transformData.bringBack = saveScenePresence;

            if (saveParent)
            {
                // Attempt to find the "hand" bone of a character
                Transform t = transform.parent;

                if (t == null)
                {
                    transformData.parentID = 0;
                    return(transformData);
                }

                while (t.parent != null)
                {
                    t = t.parent;

                    if (t.GetComponent <AC.Char>())
                    {
                        AC.Char parentCharacter = t.GetComponent <AC.Char>();

                        if (parentCharacter is Player || (parentCharacter.GetComponent <ConstantID>() && parentCharacter.GetComponent <ConstantID>().constantID != 0))
                        {
                            if (transform.parent == parentCharacter.leftHandBone || transform.parent == parentCharacter.rightHandBone)
                            {
                                if (parentCharacter is Player)
                                {
                                    transformData.parentIsPlayer = true;
                                    transformData.parentIsNPC    = false;
                                    transformData.parentID       = 0;
                                }
                                else
                                {
                                    transformData.parentIsPlayer = false;
                                    transformData.parentIsNPC    = true;
                                    transformData.parentID       = parentCharacter.GetComponent <ConstantID>().constantID;
                                }

                                if (transform.parent == parentCharacter.leftHandBone)
                                {
                                    transformData.heldHand = Hand.Left;
                                }
                                else
                                {
                                    transformData.heldHand = Hand.Right;
                                }

                                return(transformData);
                            }
                        }

                        break;
                    }
                }

                if (transform.parent.GetComponent <ConstantID>() && transform.parent.GetComponent <ConstantID>().constantID != 0)
                {
                    transformData.parentID = transform.parent.GetComponent <ConstantID>().constantID;
                }
                else
                {
                    transformData.parentID = 0;
                    ACDebug.LogWarning("Could not save " + this.name + "'s parent since it has no Constant ID");
                }
            }

            return(transformData);
        }
Ejemplo n.º 18
0
        public override Vector3[] GetPointsArray(Vector3 _originPos, Vector3 _targetPos, AC.Char _char = null)
        {
            if (KickStarter.sceneSettings == null || KickStarter.sceneSettings.navMesh == null)
            {
                return(base.GetPointsArray(_originPos, _targetPos, _char));
            }

            PolygonCollider2D[] polys = KickStarter.sceneSettings.navMesh.PolygonCollider2Ds;
            if (polys == null || polys.Length == 0)
            {
                return(base.GetPointsArray(_originPos, _targetPos, _char));
            }

            CalcSearchRadius(KickStarter.sceneSettings.navMesh);

            AddCharHoles(polys, _char, KickStarter.sceneSettings.navMesh);

            List <Vector3> pointsList3D = new List <Vector3> ();

            if (IsLineClear(_originPos, _targetPos))
            {
                pointsList3D.Add(_targetPos);
                return(pointsList3D.ToArray());
            }

            // Iterate through polys, find originPos neareset to _originPos
            int     nearestOriginIndex = -1;
            float   minDist            = 0f;
            Vector2 originPos          = Vector2.zero;
            Vector2 originPos2D        = new Vector2(_originPos.x, _originPos.y);

            for (int i = 0; i < polys.Length; i++)
            {
                Vector2 testOriginPos = GetNearestToMesh(_originPos, polys[i], (polys.Length > 1));
                float   dist          = (originPos2D - testOriginPos).sqrMagnitude;
                if (nearestOriginIndex < 0 || dist < minDist)
                {
                    minDist            = dist;
                    originPos          = testOriginPos;
                    nearestOriginIndex = i;
                }
            }
            if (nearestOriginIndex < 0)
            {
                nearestOriginIndex = 0;
            }
            Vector2 targetPos = GetNearestToMesh(_targetPos, polys[nearestOriginIndex], (polys.Length > 1));

            Vector2[] pointsList = allVertexData[nearestOriginIndex];
            pointsList = AddEndsToList(pointsList, originPos, targetPos);

            bool useCache = (KickStarter.sceneSettings.navMesh.characterEvasion == CharacterEvasion.None);

            float[,] weight = pointsToWeight(pointsList, useCache, nearestOriginIndex);
            int[] precede = buildSpanningTree(0, 1, weight);
            if (precede == null)
            {
                ACDebug.LogWarning("Pathfinding error - cannot build spanning tree from " + originPos + " to " + targetPos);
                pointsList3D.Add(_targetPos);
                return(pointsList3D.ToArray());
            }

            int[] _path = getShortestPath(0, 1, precede);
            foreach (int i in _path)
            {
                if (i < pointsList.Length)
                {
                    Vector3 vertex = new Vector3(pointsList[i].x, pointsList[i].y, _originPos.z);
                    pointsList3D.Insert(0, vertex);
                }
            }

            if (pointsList3D.Count > 1)
            {
                if (pointsList3D[0] == _originPos || (Mathf.Approximately(pointsList3D[0].x, originPos.x) && Mathf.Approximately(pointsList3D[0].y, originPos.y)))
                {
                    pointsList3D.RemoveAt(0);                           // Remove origin point from start
                }
            }
            else if (pointsList3D.Count == 0)
            {
                ACDebug.LogError("Error attempting to pathfind to point " + _targetPos + " corrected = " + targetPos);
                pointsList3D.Add(originPos);
            }

            return(pointsList3D.ToArray());
        }
Ejemplo n.º 19
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;
            }
            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 (!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 = 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);
                    }
                }
            }
        }
Ejemplo n.º 20
0
 /**
  * <summary>Initialises the engine.</summary>
  * <param name = "_character">The Player/NPC that this instance is controlling.</param>
  */
 public virtual void Declare(AC.Char _character)
 {
     character     = _character;
     turningStyle  = TurningStyle.Script;
     isSpriteBased = false;
 }
        private void AddCharHoles(PolygonCollider2D[] navPolys, AC.Char charToExclude, NavigationMesh navigationMesh)
        {
            if (navigationMesh.characterEvasion == CharacterEvasion.None)
            {
                return;
            }

            ResetHoles(KickStarter.sceneSettings.navMesh, false);

            for (int p = 0; p < navPolys.Length; p++)
            {
                if (p > 0)
                {
                    return;
                }

                if (navPolys[p].transform.lossyScale != Vector3.one)
                {
                    ACDebug.LogWarning("Cannot create evasion Polygons inside NavMesh '" + navPolys[p].gameObject.name + "' because it has a non-unit scale.");
                    continue;
                }

                Vector2 navPosition = navPolys[p].transform.position;

                foreach (AC.Char character in KickStarter.stateHandler.Characters)
                {
                    CircleCollider2D circleCollider2D = character.GetComponent <CircleCollider2D>();
                    if (circleCollider2D != null &&
                        (character.charState == CharState.Idle || navigationMesh.characterEvasion == CharacterEvasion.AllCharacters) &&
                        (charToExclude == null || character != charToExclude) &&
                        UnityVersionHandler.Perform2DOverlapPoint(character.transform.position, NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0)
                    {
                        circleCollider2D.isTrigger = true;
                        List <Vector2> newPoints3D = new List <Vector2>();

                                                #if UNITY_5 || UNITY_2017_1_OR_NEWER
                        Vector2 centrePoint = character.transform.TransformPoint(circleCollider2D.offset);
                                                #else
                        Vector2 centrePoint = character.transform.TransformPoint(circleCollider2D.center);
                                                #endif

                        float radius  = circleCollider2D.radius * character.transform.localScale.x;
                        float yScaler = navigationMesh.characterEvasionYScale;

                        if (navigationMesh.characterEvasionPoints == CharacterEvasionPoints.Four)
                        {
                            newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler));
                        }
                        else if (navigationMesh.characterEvasionPoints == CharacterEvasionPoints.Eight)
                        {
                            newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler));
                        }
                        else if (navigationMesh.characterEvasionPoints == CharacterEvasionPoints.Sixteen)
                        {
                            newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nne.x * radius, dir_nne.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nee.x * radius, dir_nee.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_see.x * radius, dir_see.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sse.x * radius, dir_sse.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_ssw.x * radius, dir_ssw.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_sww.x * radius, dir_sww.y * radius * yScaler));

                            newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nww.x * radius, dir_nww.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler));
                            newPoints3D.Add(centrePoint + new Vector2(dir_nnw.x * radius, dir_nnw.y * radius * yScaler));
                        }

                        navPolys[p].pathCount++;

                        List <Vector2> newPoints = new List <Vector2>();
                        for (int i = 0; i < newPoints3D.Count; i++)
                        {
                            // Only add a point if it is on the NavMesh
                            if (UnityVersionHandler.Perform2DOverlapPoint(newPoints3D[i], NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0)
                            {
                                newPoints.Add(newPoints3D[i] - navPosition);
                            }
                            else
                            {
                                Vector2 altPoint = GetLineIntersect(newPoints3D[i], centrePoint);
                                if (altPoint != Vector2.zero)
                                {
                                    newPoints.Add(altPoint - navPosition);
                                }
                            }
                        }

                        if (newPoints.Count > 1)
                        {
                            navPolys[p].SetPath(navPolys[p].pathCount - 1, newPoints.ToArray());
                        }
                    }
                }

                RebuildVertexArray(navPolys[p].transform, navPolys[p], p);
            }
        }
        public override Vector3[] GetPointsArray(Vector3 startPosition, Vector3 targetPosition, AC.Char _char = null)
        {
            NavMeshPath _path = new NavMeshPath();

            if (!NavMesh.CalculatePath(startPosition, targetPosition, -1, _path))
            {
                // Could not find path with current vectors
                float maxDistance  = 0.001f;
                float originalDist = Vector3.Distance(startPosition, targetPosition);

                NavMeshHit hit = new NavMeshHit();
                for (maxDistance = 0.001f; maxDistance < originalDist; maxDistance += 0.05f)
                {
                    if (NavMesh.SamplePosition(startPosition, out hit, maxDistance, -1))
                    {
                        startPosition = hit.position;
                        break;
                    }
                }

                bool foundNewEnd = false;
                for (maxDistance = 0.001f; maxDistance < originalDist; maxDistance += 0.05f)
                {
                    if (NavMesh.SamplePosition(targetPosition, out hit, maxDistance, -1))
                    {
                        targetPosition = hit.position;
                        foundNewEnd    = true;
                        break;
                    }
                }

                if (!foundNewEnd)
                {
                    return(new Vector3[0]);
                }

                NavMesh.CalculatePath(startPosition, targetPosition, -1, _path);
            }

            List <Vector3> pointArray = new List <Vector3>();

            foreach (Vector3 corner in _path.corners)
            {
                pointArray.Add(corner);
            }
            if (pointArray.Count > 1 && pointArray[0].x == startPosition.x && pointArray[0].z == startPosition.z)
            {
                pointArray.RemoveAt(0);
            }
            else if (pointArray.Count == 0)
            {
                pointArray.Clear();
                pointArray.Add(targetPosition);
            }

            return(pointArray.ToArray());
        }
        public override Vector3[] GetPointsArray(Vector3 originPos, Vector3 targetPos, AC.Char _char = null)
        {
            List <Vector3> pointsList = new List <Vector3>();

            if (KickStarter.sceneSettings && KickStarter.sceneSettings.navMesh && KickStarter.sceneSettings.navMesh.GetComponent <Collider>())
            {
                Vector3 originalOriginPos = originPos;
                Vector3 originalTargetPos = targetPos;
                originPos = GetNearestToMesh(originPos);
                targetPos = GetNearestToMesh(targetPos);

                pointsList.Add(originPos);

                if (!IsLineClear(targetPos, originPos, false))
                {
                    pointsList = FindComplexPath(originPos, targetPos, false);

                    if (pathFailed)
                    {
                        Vector3 newTargetPos = GetLineBreak(pointsList [pointsList.Count - 1], targetPos);

                        if (newTargetPos != Vector3.zero)
                        {
                            targetPos = newTargetPos;

                            if (!IsLineClear(targetPos, originPos, true))
                            {
                                pointsList = FindComplexPath(originPos, targetPos, true);

                                if (pathFailed)
                                {
                                    // Couldn't find an alternative, so just clear the path
                                    pointsList.Clear();
                                    pointsList.Add(originPos);
                                }
                            }
                            else
                            {
                                // Line between origin and new target is clear
                                pointsList.Clear();
                                pointsList.Add(originPos);
                            }
                        }
                    }
                }

                // Finally, remove any extraneous points
                if (pointsList.Count > 2)
                {
                    for (int i = 0; i < pointsList.Count; i++)
                    {
                        for (int j = i; j < pointsList.Count; j++)
                        {
                            if (IsLineClear(pointsList[i], pointsList[j], false) && j > i + 1)
                            {
                                // Point i+1 is irrelevant, remove and reset
                                pointsList.RemoveRange(i + 1, j - i - 1);
                                j = 0;
                                i = 0;
                            }
                        }
                    }
                }
                pointsList.Add(targetPos);

                if (pointsList[0] == originalOriginPos)
                {
                    pointsList.RemoveAt(0);                             // Remove origin point from start
                }
                // Special case: where player is stuck on a Collider above the mesh
                if (pointsList.Count == 1 && pointsList[0] == originPos)
                {
                    pointsList[0] = originalTargetPos;
                }
            }
            else
            {
                // Special case: no Collider, no path
                pointsList.Add(targetPos);
            }

            return(pointsList.ToArray());
        }
Ejemplo n.º 24
0
 /**
  * <summary>Initialises the engine.</summary>
  * <param name = "_character">The Player/NPC that this instance is controlling.</param>
  */
 public virtual void Declare(AC.Char _character)
 {
     character = _character;
     turningStyle = TurningStyle.Script;
     isSpriteBased = false;
 }
Ejemplo n.º 25
0
        protected void SharedGUITwo(AC.Char _target)
        {
            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Physics settings", EditorStyles.boldLabel);
            _target.ignoreGravity = CustomGUILayout.Toggle("Ignore gravity?", _target.ignoreGravity, "", "If True, the character will ignore the effects of gravity");
            if (_target.GetComponent <Rigidbody>() != null || _target.GetComponent <Rigidbody2D>() != null)
            {
                if (_target.motionControl == MotionControl.Automatic)
                {
                    _target.freezeRigidbodyWhenIdle = CustomGUILayout.Toggle("Freeze Rigidbody when Idle?", _target.freezeRigidbodyWhenIdle, "", "If True, the character's Rigidbody will be frozen in place when idle. This is to help slipping when on sloped surfaces");
                }

                if (_target.motionControl != MotionControl.Manual)
                {
                    if (_target.GetComponent <Rigidbody>() != null)
                    {
                        _target.useRigidbodyForMovement = CustomGUILayout.Toggle("Move with Rigidbody?", _target.useRigidbodyForMovement, "", "If True, then it will be moved by adding forces in FixedUpdate, as opposed to the transform being manipulated in Update");

                        if (_target.useRigidbodyForMovement)
                        {
                            if (_target.GetAnimator() != null && _target.GetAnimator().applyRootMotion)
                            {
                                EditorGUILayout.HelpBox("Rigidbody movement will be disabled as 'Root motion' is enabled in the Animator.", MessageType.Warning);
                            }
                            else if (_target.GetComponent <Rigidbody>().interpolation == RigidbodyInterpolation.None)
                            {
                                EditorGUILayout.HelpBox("For smooth movement, the Rigidbody's 'Interpolation' should be set to either 'Interpolate' or 'Extrapolate'.", MessageType.Warning);
                            }
                        }
                    }
                    else if (_target.GetComponent <Rigidbody2D>() != null)
                    {
                        _target.useRigidbody2DForMovement = CustomGUILayout.Toggle("Move with Rigidbody 2D?", _target.useRigidbody2DForMovement, "", "If True, then it will be moved by adding forces in FixedUpdate, as opposed to the transform being manipulated in Update");

                        if (_target.useRigidbody2DForMovement)
                        {
                            if (_target.GetAnimator() != null && _target.GetAnimator().applyRootMotion)
                            {
                                EditorGUILayout.HelpBox("Rigidbody movement will be disabled as 'Root motion' is enabled in the Animator.", MessageType.Warning);
                            }
                            else if (_target.GetComponent <Rigidbody2D>().interpolation == RigidbodyInterpolation2D.None)
                            {
                                EditorGUILayout.HelpBox("For smooth movement, the Rigidbody's 'Interpolation' should be set to either 'Interpolate' or 'Extrapolate'.", MessageType.Warning);
                            }

                            if (SceneSettings.CameraPerspective != CameraPerspective.TwoD)
                            {
                                EditorGUILayout.HelpBox("Rigidbody2D-based motion only allows for X and Y movement, not Z, which may not be appropriate for 3D.", MessageType.Warning);
                            }

                            if (_target.GetAnimEngine().isSpriteBased&& _target.turn2DCharactersIn3DSpace)
                            {
                                EditorGUILayout.HelpBox("For best results, 'Turn root object in 3D space?' above should be disabled.", MessageType.Warning);
                            }
                        }
                    }
                }
            }

            if (_target.GetComponent <Collider>() != null && _target.GetComponent <CharacterController>() == null)
            {
                _target.groundCheckLayerMask = LayerMaskField("Ground-check layer(s):", _target.groundCheckLayerMask);
            }
            EditorGUILayout.EndVertical();


            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Audio clips", EditorStyles.boldLabel);

            _target.walkSound = (AudioClip)CustomGUILayout.ObjectField <AudioClip> ("Walk sound:", _target.walkSound, false, "", "The sound to play when walking");
            _target.runSound  = (AudioClip)CustomGUILayout.ObjectField <AudioClip> ("Run sound:", _target.runSound, false, "", "The sound to play when running");
            if (AdvGame.GetReferences() != null && AdvGame.GetReferences().speechManager != null && AdvGame.GetReferences().speechManager.scrollSubtitles)
            {
                _target.textScrollClip = (AudioClip)CustomGUILayout.ObjectField <AudioClip> ("Text scroll override:", _target.textScrollClip, false, "", "The sound to play when the character's speech text is scrolling");
            }
            _target.soundChild        = (Sound)CustomGUILayout.ObjectField <Sound> ("SFX Sound child:", _target.soundChild, true, "", "");
            _target.speechAudioSource = (AudioSource)CustomGUILayout.ObjectField <AudioSource> ("Speech AudioSource:", _target.speechAudioSource, true, "", "The AudioSource from which to play speech audio");
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Dialogue settings", EditorStyles.boldLabel);

            _target.speechColor         = CustomGUILayout.ColorField("Speech text colour:", _target.speechColor, "", "");
            _target.speechLabel         = CustomGUILayout.TextField("Speaker label:", _target.speechLabel, "", "");
            _target.speechMenuPlacement = (Transform)CustomGUILayout.ObjectField <Transform> ("Speech menu placement child:", _target.speechMenuPlacement, true, "", "The Transform at which to place Menus set to appear 'Above Speaking Character'. If this is not set, the placement will be set automatically");

            if (_target.useExpressions)
            {
                EditorGUILayout.LabelField("Default portrait graphic:");
            }
            else
            {
                EditorGUILayout.LabelField("Portrait graphic:");
            }
            _target.portraitIcon.ShowGUI(false);

            _target.useExpressions = CustomGUILayout.Toggle("Use expressions?", _target.useExpressions, "", "If True, speech text can use expression tokens to change the character's expression");
            if (_target.useExpressions)
            {
                _target.GetAnimEngine().CharExpressionsGUI();

                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical("Button");
                for (int i = 0; i < _target.expressions.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Expression #" + _target.expressions[i].ID.ToString(), EditorStyles.boldLabel);

                    if (GUILayout.Button("", CustomStyles.IconCog))
                    {
                        ExpressionSideMenu(_target, i);
                    }
                    EditorGUILayout.EndHorizontal();
                    _target.expressions[i].ShowGUI();
                }

                if (GUILayout.Button("Add new expression"))
                {
                    _target.expressions.Add(new Expression(GetExpressionIDArray(_target.expressions)));
                }
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.EndVertical();
        }