protected void SetOriginalDepth() { if (KickStarter.settingsManager == null) { return; } if (SceneSettings.IsTopDown()) { depthAxis = DepthAxis.Y; } else { depthAxis = DepthAxis.Z; } if (transform.parent) { originalDepth = transform.position - transform.parent.position; } else { originalDepth = transform.position; } }
protected void SetOriginalDepth() { if (depthSet) { return; } if (SceneSettings.IsTopDown()) { depthAxis = DepthAxis.Y; } else { depthAxis = DepthAxis.Z; } if (transform.parent) { originalDepth = transform.position - transform.parent.position; } else { originalDepth = transform.position; } depthSet = true; }
private void DirectControlPlayerPath(Vector2 moveKeys) { if (moveKeys != Vector2.zero) { Vector3 moveDirectionInput = Vector3.zero; if (SceneSettings.IsTopDown()) { moveDirectionInput = (moveKeys.y * Vector3.forward) + (moveKeys.x * Vector3.right); } else { moveDirectionInput = (moveKeys.y * KickStarter.mainCamera.ForwardVector()) + (moveKeys.x * KickStarter.mainCamera.RightVector()); } if (Vector3.Dot(moveDirectionInput, KickStarter.player.GetMoveDirection()) > 0f) { // Move along path, because movement keys are in the path's forward direction KickStarter.player.isRunning = KickStarter.playerInput.IsPlayerControlledRunning(); KickStarter.player.charState = CharState.Move; } } else { if (KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; } } }
// Drag functions private void DragPlayer(bool doRotation, Vector2 moveKeys) { if (KickStarter.playerInput.GetDragState() == DragState.None) { KickStarter.playerInput.ResetDragMovement(); if (KickStarter.player.charState == CharState.Move) { if (KickStarter.playerInteraction.GetHotspotMovingTo() == null) { KickStarter.player.charState = CharState.Decelerate; } } } if (KickStarter.playerInput.GetDragState() == DragState.Player) { Vector3 moveDirectionInput = Vector3.zero; if (SceneSettings.IsTopDown()) { moveDirectionInput = (moveKeys.y * Vector3.forward) + (moveKeys.x * Vector3.right); } else { moveDirectionInput = (moveKeys.y * KickStarter.mainCamera.ForwardVector()) + (moveKeys.x * KickStarter.mainCamera.RightVector()); } if (KickStarter.playerInput.IsDragMoveSpeedOverWalkThreshold()) { KickStarter.player.isRunning = KickStarter.playerInput.IsPlayerControlledRunning(); KickStarter.player.charState = CharState.Move; if (doRotation) { KickStarter.player.SetLookDirection(moveDirectionInput, false); KickStarter.player.SetMoveDirectionAsForward(); } else { if (KickStarter.playerInput.GetDragVector().y < 0f) { KickStarter.player.SetMoveDirectionAsForward(); } else { KickStarter.player.SetMoveDirectionAsBackward(); } } } else { if (KickStarter.player.charState == CharState.Move && KickStarter.playerInteraction.GetHotspotMovingTo() == null) { KickStarter.player.charState = CharState.Decelerate; } } } }
private void SetDesired() { Vector2 targetOffset = GetOffsetForPosition(target.transform.position); if (targetOffset.x < (perspectiveOffset.x - freedom.x)) { desiredOffset.x = targetOffset.x + freedom.x; } else if (targetOffset.x > (perspectiveOffset.x + freedom.x)) { desiredOffset.x = targetOffset.x - freedom.x; } desiredOffset.x += afterOffset.x; if (directionInfluence.x != 0f) { desiredOffset.x += Vector3.Dot(target.forward, transform.right) * directionInfluence.x; } if (limitHorizontal) { desiredOffset.x = ConstrainAxis(desiredOffset.x, constrainHorizontal); } if (targetOffset.y < (perspectiveOffset.y - freedom.y)) { desiredOffset.y = targetOffset.y + freedom.y; } else if (targetOffset.y > (perspectiveOffset.y + freedom.y)) { desiredOffset.y = targetOffset.y - freedom.y; } desiredOffset.y += afterOffset.y; if (directionInfluence.y != 0f) { if (SceneSettings.IsTopDown()) { desiredOffset.y += Vector3.Dot(target.forward, transform.up) * directionInfluence.y; } else { desiredOffset.y += Vector3.Dot(target.forward, transform.forward) * directionInfluence.y; } } if (limitVertical) { desiredOffset.y = ConstrainAxis(desiredOffset.y, constrainVertical); } }
protected Vector3 GetLookVector(string direction) { Vector3 lookVector = Vector3.zero; Vector3 upVector = Camera.main.transform.up; Vector3 rightVector = Camera.main.transform.right - new Vector3(0f, 0.01f); // Angle slightly so that left->right rotations face camera if (SceneSettings.IsTopDown()) { upVector = -Camera.main.transform.forward; } if (direction == "down") { lookVector = -upVector; } else if (direction == "left") { lookVector = -rightVector; } else if (direction == "right") { lookVector = rightVector; } else if (direction == "up") { lookVector = upVector; } else if (direction == "downleft") { lookVector = (-upVector - rightVector).normalized; } else if (direction == "downright") { lookVector = (-upVector + rightVector).normalized; } else if (direction == "upleft") { lookVector = (upVector - rightVector).normalized; } else if (direction == "upright") { lookVector = (upVector + rightVector).normalized; } else { //TODO: face object in here } lookVector = new Vector3(lookVector.x, 0f, lookVector.y); return(lookVector); }
private Vector3 GetLookVector() { Vector3 lookVector = Vector3.zero; Vector3 upVector = Camera.main.transform.up; Vector3 rightVector = Camera.main.transform.right - new Vector3(0f, 0.01f); // Angle slightly so that left->right rotations face camera if (SceneSettings.IsTopDown()) { upVector = -Camera.main.transform.forward; } if (direction == CharDirection.Down) { lookVector = -upVector; } else if (direction == CharDirection.Left) { lookVector = -rightVector; } else if (direction == CharDirection.Right) { lookVector = rightVector; } else if (direction == CharDirection.Up) { lookVector = upVector; } else if (direction == CharDirection.DownLeft) { lookVector = (-upVector - rightVector).normalized; } else if (direction == CharDirection.DownRight) { lookVector = (-upVector + rightVector).normalized; } else if (direction == CharDirection.UpLeft) { lookVector = (upVector - rightVector).normalized; } else if (direction == CharDirection.UpRight) { lookVector = (upVector + rightVector).normalized; } lookVector = new Vector3(lookVector.x, 0f, lookVector.y); return(lookVector); }
/** * Sets the camera's rotation and projection according to the chosen settings in SettingsManager. */ public void SetCorrectRotation() { if (KickStarter.settingsManager) { if (SceneSettings.IsTopDown()) { transform.rotation = Quaternion.Euler(90f, 0, 0); return; } if (SceneSettings.IsUnity2D()) { Camera.orthographic = true; } } transform.rotation = Quaternion.Euler(0, 0, 0); }
/** * Initialises the Player's animation. */ public void Initialise() { if (GetAnimation()) { // Hack: Force idle of Legacy characters AdvGame.PlayAnimClip(GetAnimation(), AdvGame.GetAnimLayerInt(AnimLayer.Base), idleAnim, AnimationBlendMode.Blend, WrapMode.Loop, 0f, null, false); } else if (spriteChild) { // Hack: update 2D sprites PrepareSpriteChild(SceneSettings.IsTopDown(), SceneSettings.IsUnity2D()); UpdateSpriteChild(SceneSettings.IsTopDown(), SceneSettings.IsUnity2D()); } UpdateScale(); GetAnimEngine().TurnHead(Vector2.zero); GetAnimEngine().PlayIdle(); }
/** * <summary>Calculates the player's position relative to the next scene's PlayerStart.</summary> * <param name = "marker">The Marker of the GameObject that marks the position that the player should be placed relative to.</param> */ public void SetRelativePosition(Marker marker) { if (KickStarter.player == null || marker == null) { relativePosition = Vector2.zero; } else { relativePosition = KickStarter.player.Transform.position - marker.Position; if (SceneSettings.IsUnity2D()) { relativePosition.z = 0f; } else if (SceneSettings.IsTopDown()) { relativePosition.y = 0f; } } }
/** * Initialises the Player's animation. */ public void Initialise() { if (GetAnimation()) { // Hack: Force idle of Legacy characters AdvGame.PlayAnimClip(GetAnimation(), AdvGame.GetAnimLayerInt(AnimLayer.Base), idleAnim, AnimationBlendMode.Blend, WrapMode.Loop, 0f, null, false); } else if (spriteChild) { // Hack: update 2D sprites if (spriteChild.GetComponent <FollowSortingMap>()) { KickStarter.sceneSettings.UpdateAllSortingMaps(); } PrepareSpriteChild(SceneSettings.IsTopDown(), SceneSettings.IsUnity2D()); UpdateSpriteChild(SceneSettings.IsTopDown(), SceneSettings.IsUnity2D()); } UpdateScale(); GetAnimEngine().PlayIdle(); }
private Vector2 GetOffsetForPosition(Vector3 targetPosition) { Vector2 targetOffset = new Vector2(); float forwardOffsetScale = 93 - (299 * _camera.nearClipPlane); if (SceneSettings.IsTopDown()) { if (_camera.orthographic) { targetOffset.x = transform.position.x; targetOffset.y = transform.position.z; } else { targetOffset.x = -(targetPosition.x - transform.position.x) / (forwardOffsetScale * (targetPosition.y - transform.position.y)); targetOffset.y = -(targetPosition.z - transform.position.z) / (forwardOffsetScale * (targetPosition.y - transform.position.y)); } } else { if (_camera.orthographic) { targetOffset = transform.TransformVector(new Vector3(targetPosition.x, targetPosition.y, -targetPosition.z)); } else { float rightDot = Vector3.Dot(transform.right, targetPosition - transform.position); float forwardDot = Vector3.Dot(transform.forward, targetPosition - transform.position); float upDot = Vector3.Dot(transform.up, targetPosition - transform.position); targetOffset.x = rightDot / (forwardOffsetScale * forwardDot); targetOffset.y = upDot / (forwardOffsetScale * forwardDot); } } return(targetOffset); }
/** * <summary>Checks if the GameObject's rotation matches the intended rotation, according to the chosen settings in SettingsManager.</summary> * <returns>True if the GameObject's rotation matches the intended rotation<returns> */ public bool IsCorrectRotation() { if (SceneSettings.IsTopDown()) { if (transform.rotation == Quaternion.Euler(90f, 0f, 0f)) { return(true); } return(false); } if (SceneSettings.CameraPerspective != CameraPerspective.TwoD) { return(true); } if (transform.rotation == Quaternion.Euler(0f, 0f, 0f)) { return(true); } return(false); }
public override void OnInspectorGUI() { SortingMap _target = (SortingMap)target; EditorGUILayout.BeginVertical("Button"); _target.mapType = (SortingMapType)EditorGUILayout.EnumPopup("Affect sprite's:", _target.mapType); _target.affectScale = EditorGUILayout.Toggle("Affect Character scale?", _target.affectScale); if (_target.affectScale) { _target.affectSpeed = EditorGUILayout.Toggle("Affect Character speed?", _target.affectSpeed); _target.sortingMapScaleType = (SortingMapScaleType)EditorGUILayout.EnumPopup("Character scaling mode:", _target.sortingMapScaleType); if (_target.sortingMapScaleType == SortingMapScaleType.Linear || _target.sortingAreas.Count == 0) { _target.originScale = EditorGUILayout.IntField("Start scale (%):", _target.originScale); if (_target.sortingMapScaleType == SortingMapScaleType.AnimationCurve) { EditorGUILayout.HelpBox("The Sorting Map must have at least one area defined to make use of an animation curve.", MessageType.Warning); } } else { if (_target.scalingAnimationCurve == null) { _target.scalingAnimationCurve = AnimationCurve.Linear(0f, 0.1f, 1f, 1f); } _target.scalingAnimationCurve = EditorGUILayout.CurveField("Scaling curve:", _target.scalingAnimationCurve); EditorGUILayout.HelpBox("The curve's values will be read from 0s to 1s only.", MessageType.Info); } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); foreach (SortingArea area in _target.sortingAreas) { int i = _target.sortingAreas.IndexOf(area); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); area.color = EditorGUILayout.ColorField(area.color); EditorGUILayout.LabelField("Position:", GUILayout.Width(50f)); area.z = EditorGUILayout.FloatField(area.z, GUILayout.Width(80f)); if (_target.mapType == SortingMapType.OrderInLayer) { EditorGUILayout.LabelField("Order:", labelWidth); area.order = EditorGUILayout.IntField(area.order); } else if (_target.mapType == SortingMapType.SortingLayer) { EditorGUILayout.LabelField("Layer:", labelWidth); area.layer = EditorGUILayout.TextField(area.layer); } if (GUILayout.Button(insertContent, EditorStyles.miniButtonLeft, buttonWidth)) { Undo.RecordObject(_target, "Add area"); if (i < _target.sortingAreas.Count - 1) { _target.sortingAreas.Insert(i + 1, new SortingArea(area, _target.sortingAreas[i + 1])); } else { _target.sortingAreas.Insert(i + 1, new SortingArea(area)); } break; } if (GUILayout.Button(deleteContent, EditorStyles.miniButtonRight, buttonWidth)) { Undo.RecordObject(_target, "Delete area"); _target.sortingAreas.Remove(area); break; } EditorGUILayout.EndHorizontal(); if (_target.affectScale && _target.sortingMapScaleType == SortingMapScaleType.Linear) { area.scale = EditorGUILayout.IntField("End scale (%):", area.scale); } EditorGUILayout.EndVertical(); } if (GUILayout.Button("Add area")) { Undo.RecordObject(_target, "Add area"); if (_target.sortingAreas.Count > 0) { SortingArea lastArea = _target.sortingAreas [_target.sortingAreas.Count - 1]; _target.sortingAreas.Add(new SortingArea(lastArea)); } else { _target.sortingAreas.Add(new SortingArea(_target.transform.position.z + 1f, 1)); } } EditorGUILayout.Space(); if (SceneSettings.IsTopDown()) { } else if (SceneSettings.IsUnity2D()) { } else { if (GUILayout.Button("Face active camera")) { Undo.RecordObject(_target, "Face active camera"); Vector3 forwardVector = Camera.main.transform.forward; _target.transform.forward = -forwardVector; EditorUtility.SetDirty(_target); } } if (_target.affectScale && _target.sortingAreas.Count > 1 && _target.sortingMapScaleType == SortingMapScaleType.Linear) { if (GUILayout.Button("Interpolate in-between scales")) { Undo.RecordObject(_target, "Interpolate scales"); _target.SetInBetweenScales(); EditorUtility.SetDirty(_target); } } UnityVersionHandler.CustomSetDirty(_target); }
public override void CharSettingsGUI() { #if UNITY_EDITOR EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Standard 3D animations", EditorStyles.boldLabel); if (SceneSettings.IsTopDown()) { character.spriteChild = (Transform)CustomGUILayout.ObjectField <Transform> ("Animation child:", character.spriteChild, true, "", "The child object that contains the Animation component"); } else { character.spriteChild = null; } character.talkingAnimation = (TalkingAnimation)CustomGUILayout.EnumPopup("Talk animation style:", character.talkingAnimation, "", "How talking animations are handled"); character.idleAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Idle:", character.idleAnim, false, "", "The 'Idle' animation"); character.walkAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Walk:", character.walkAnim, false, "", "The 'Walk' animation"); character.runAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Run:", character.runAnim, false, "", "The 'Run' animation"); if (character.talkingAnimation == TalkingAnimation.Standard) { character.talkAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Talk:", character.talkAnim, false, "", "The 'Talk' animation"); } if (AdvGame.GetReferences() && AdvGame.GetReferences().speechManager) { if (AdvGame.GetReferences() && AdvGame.GetReferences().speechManager&& AdvGame.GetReferences().speechManager.lipSyncMode != LipSyncMode.Off && AdvGame.GetReferences().speechManager.lipSyncMode != LipSyncMode.FaceFX) { if (AdvGame.GetReferences().speechManager.lipSyncOutput == LipSyncOutput.PortraitAndGameObject) { if (character.GetShapeable()) { character.lipSyncGroupID = ActionBlendShape.ShapeableGroupGUI("Phoneme shape group:", character.GetShapeable().shapeGroups, character.lipSyncGroupID); } else { EditorGUILayout.HelpBox("Attach a Shapeable script to show phoneme options", MessageType.Info); } } else if (AdvGame.GetReferences().speechManager.lipSyncOutput == LipSyncOutput.GameObjectTexture) { if (character.GetComponent <LipSyncTexture>() == null) { EditorGUILayout.HelpBox("Attach a LipSyncTexture script to allow texture lip-syncing.", MessageType.Info); } } } } character.turnLeftAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Turn left:", character.turnLeftAnim, false, "", "The 'Turn left' animation"); character.turnRightAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Turn right:", character.turnRightAnim, false, "", "The 'Turn right' animation"); character.headLookLeftAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Head look left:", character.headLookLeftAnim, false, "", "The 'Look left' animation"); character.headLookRightAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Head look right:", character.headLookRightAnim, false, "", "The 'Look right' animation"); character.headLookUpAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Head look up:", character.headLookUpAnim, false, "", "The 'Look up' animation"); character.headLookDownAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Head look down:", character.headLookDownAnim, false, "", "The 'Look down' animation"); if (character is Player) { Player player = (Player)character; player.jumpAnim = (AnimationClip)CustomGUILayout.ObjectField <AnimationClip> ("Jump:", player.jumpAnim, false, "", "The 'Jump' animation"); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Bone transforms", EditorStyles.boldLabel); character.upperBodyBone = (Transform)CustomGUILayout.ObjectField <AnimationClip> ("Upper body:", character.upperBodyBone, true, "", "The 'Upper body bone' Transform, used to isolate animations"); character.neckBone = (Transform)CustomGUILayout.ObjectField <AnimationClip> ("Neck bone:", character.neckBone, true, "", "The 'Neck bone' Transform, used to isolate animations"); character.leftArmBone = (Transform)CustomGUILayout.ObjectField <AnimationClip> ("Left arm:", character.leftArmBone, true, "", "The 'Left arm bone' Transform, used to isolate animations"); character.rightArmBone = (Transform)CustomGUILayout.ObjectField <AnimationClip> ("Right arm:", character.rightArmBone, true, "", "The 'Right arm bone' Transform, used to isolate animations"); character.leftHandBone = (Transform)CustomGUILayout.ObjectField <AnimationClip> ("Left hand:", character.leftHandBone, true, "", "The 'Left hand bone' Transform, used to isolate animations"); character.rightHandBone = (Transform)CustomGUILayout.ObjectField <AnimationClip> ("Right hand:", character.rightHandBone, true, "", "The 'Right hand bone' Transform, used to isolate animations"); EditorGUILayout.EndVertical(); if (GUI.changed) { EditorUtility.SetDirty(character); } #endif }
private Vector3 GetLookVector() { Vector3 camForward = Camera.main.transform.forward; camForward = new Vector3(camForward.x, 0f, camForward.z).normalized; if (SceneSettings.IsTopDown()) { camForward = -Camera.main.transform.forward; } else if (SceneSettings.CameraPerspective == CameraPerspective.TwoD) { camForward = Camera.main.transform.up; } Vector3 camRight = new Vector3(Camera.main.transform.right.x, 0f, Camera.main.transform.right.z); // Angle slightly so that left->right rotations face camera if (KickStarter.settingsManager.IsInFirstPerson()) { // No angle tweaking in first-person } else if (SceneSettings.CameraPerspective == CameraPerspective.TwoD) { camRight -= new Vector3(0f, 0f, 0.01f); } else { camRight -= camForward * 0.01f; } if (relativeTo == RelativeTo.Character) { camForward = runtimeCharToMove.TransformForward; camRight = runtimeCharToMove.TransformRight; } Vector3 lookVector = Vector3.zero; switch (direction) { case CharDirection.Down: lookVector = -camForward; break; case CharDirection.Left: lookVector = -camRight; break; case CharDirection.Right: lookVector = camRight; break; case CharDirection.Up: lookVector = camForward; break; case CharDirection.DownLeft: lookVector = (-camForward - camRight).normalized; break; case CharDirection.DownRight: lookVector = (-camForward + camRight).normalized; break; case CharDirection.UpLeft: lookVector = (camForward - camRight).normalized; break; case CharDirection.UpRight: lookVector = (camForward + camRight).normalized; break; } if (SceneSettings.IsTopDown()) { return(lookVector); } if (SceneSettings.CameraPerspective == CameraPerspective.TwoD && relativeTo == RelativeTo.Camera) { return(new Vector3(lookVector.x, 0f, lookVector.y).normalized); } return(lookVector); }
public override void OnInspectorGUI() { SortingMap _target = (SortingMap)target; EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Properties", EditorStyles.boldLabel); _target.mapType = (SortingMapType)CustomGUILayout.EnumPopup("Affect sprite's:", _target.mapType); _target.affectScale = CustomGUILayout.Toggle("Affect Character scale?", _target.affectScale, "", "If True, characters that follow this map should have their scale affected"); if (_target.affectScale) { _target.affectSpeed = CustomGUILayout.Toggle("Affect Character speed?", _target.affectSpeed, "", "If True, characters that follow this map should have their movement speed affected by the scale factor"); _target.sortingMapScaleType = (SortingMapScaleType)CustomGUILayout.EnumPopup("Character scaling mode:", _target.sortingMapScaleType, "", "How scaling values are defined"); if (_target.sortingMapScaleType == SortingMapScaleType.Linear || _target.sortingAreas.Count == 0) { _target.originScale = CustomGUILayout.IntField("Start scale (%):", _target.originScale, "", "The scale (as a percentage) that characters will have at the very top of the map"); if (_target.sortingMapScaleType == SortingMapScaleType.AnimationCurve) { EditorGUILayout.HelpBox("The Sorting Map must have at least one area defined to make use of an animation curve.", MessageType.Warning); } } else { if (_target.scalingAnimationCurve == null) { _target.scalingAnimationCurve = AnimationCurve.Linear(0f, 0.1f, 1f, 1f); } _target.scalingAnimationCurve = CustomGUILayout.CurveField("Scaling curve:", _target.scalingAnimationCurve, "", "The AnimationCurve used to define character scaling, where 0s is the smallest scale, and 1s is the largest"); EditorGUILayout.HelpBox("The curve's values will be read from 0s to 1s only.", MessageType.Info); } if (_target.sortingMapScaleType == SortingMapScaleType.Linear && _target.sortingAreas.Count > 1) { if (GUILayout.Button("Interpolate in-between scales")) { Undo.RecordObject(_target, "Interpolate scales"); _target.SetInBetweenScales(); EditorUtility.SetDirty(_target); } } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Sorting areas", EditorStyles.boldLabel); foreach (SortingArea area in _target.sortingAreas) { int i = _target.sortingAreas.IndexOf(area); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); area.color = EditorGUILayout.ColorField(area.color); EditorGUILayout.LabelField("Position:", GUILayout.Width(50f)); area.z = EditorGUILayout.FloatField(area.z, GUILayout.Width(80f)); if (_target.mapType == SortingMapType.OrderInLayer) { EditorGUILayout.LabelField("Order:", labelWidth); area.order = EditorGUILayout.IntField(area.order); } else if (_target.mapType == SortingMapType.SortingLayer) { EditorGUILayout.LabelField("Layer:", labelWidth); area.layer = EditorGUILayout.TextField(area.layer); } if (GUILayout.Button(insertContent, EditorStyles.miniButtonLeft, buttonWidth)) { Undo.RecordObject(_target, "Add area"); if (i < _target.sortingAreas.Count - 1) { _target.sortingAreas.Insert(i + 1, new SortingArea(area, _target.sortingAreas[i + 1])); } else { _target.sortingAreas.Insert(i + 1, new SortingArea(area)); } break; } if (GUILayout.Button(deleteContent, EditorStyles.miniButtonRight, buttonWidth)) { Undo.RecordObject(_target, "Delete area"); _target.sortingAreas.Remove(area); break; } EditorGUILayout.EndHorizontal(); if (_target.affectScale && _target.sortingMapScaleType == SortingMapScaleType.Linear) { area.scale = CustomGUILayout.IntField("End scale (%):", area.scale, "", "The factor by which characters that use FollowSortingMap will be scaled by when positioned at the bottom boundary of this region"); } EditorGUILayout.EndVertical(); GUILayout.Box(string.Empty, GUILayout.ExpandWidth(true), GUILayout.Height(1)); } if (GUILayout.Button("Add area")) { Undo.RecordObject(_target, "Add area"); if (_target.sortingAreas.Count > 0) { SortingArea lastArea = _target.sortingAreas [_target.sortingAreas.Count - 1]; _target.sortingAreas.Add(new SortingArea(lastArea)); } else { _target.sortingAreas.Add(new SortingArea(_target.transform.position.z + 1f, 1)); } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); if (SceneSettings.IsTopDown()) { } else if (SceneSettings.IsUnity2D()) { } else { if (GUILayout.Button("Face active camera")) { Undo.RecordObject(_target, "Face active camera"); Vector3 forwardVector = Camera.main.transform.forward; _target.transform.forward = -forwardVector; EditorUtility.SetDirty(_target); } } UnityVersionHandler.CustomSetDirty(_target); }
public override void CharSettingsGUI() { #if UNITY_EDITOR EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Mecanim parameters:", EditorStyles.boldLabel); character.moveSpeedParameter = CustomGUILayout.TextField("Move speed float:", character.moveSpeedParameter, "", "The name of the Animator float parameter set to the movement speed"); character.turnParameter = CustomGUILayout.TextField("Turn float:", character.turnParameter, "", "The name of the Animator float parameter set to the turning direction"); character.talkParameter = CustomGUILayout.TextField("Talk bool:", character.talkParameter, "", "The name of the Animator bool parameter set to True while talking"); if (AdvGame.GetReferences() && AdvGame.GetReferences().speechManager&& AdvGame.GetReferences().speechManager.lipSyncMode != LipSyncMode.Off && AdvGame.GetReferences().speechManager.lipSyncMode != LipSyncMode.FaceFX) { if (AdvGame.GetReferences().speechManager.lipSyncOutput == LipSyncOutput.PortraitAndGameObject) { character.phonemeParameter = CustomGUILayout.TextField("Phoneme integer:", character.phonemeParameter, "", "The name of the Animator integer parameter set to the lip-syncing phoneme integer"); if (character.GetShapeable()) { character.lipSyncGroupID = ActionBlendShape.ShapeableGroupGUI("Phoneme shape group:", character.GetShapeable().shapeGroups, character.lipSyncGroupID); } } else if (AdvGame.GetReferences().speechManager.lipSyncOutput == LipSyncOutput.GameObjectTexture) { if (character.GetComponent <LipSyncTexture>() == null) { EditorGUILayout.HelpBox("Attach a LipSyncTexture script to allow texture lip-syncing.", MessageType.Info); } } } if (!character.ikHeadTurning) { character.headYawParameter = CustomGUILayout.TextField("Head yaw float:", character.headYawParameter, "", "The name of the Animator float parameter set to the head yaw"); character.headPitchParameter = CustomGUILayout.TextField("Head pitch float:", character.headPitchParameter, "", "The name of the Animator float parameter set to the head pitch"); } character.verticalMovementParameter = CustomGUILayout.TextField("Vertical movement float:", character.verticalMovementParameter, "", "The name of the Animator float parameter set to the vertical movement speed"); character.isGroundedParameter = CustomGUILayout.TextField("'Is grounded' bool:", character.isGroundedParameter, "", "The name of the Animator boolean parameter set to the 'Is Grounded' check"); if (character is Player) { Player player = (Player)character; player.jumpParameter = CustomGUILayout.TextField("Jump bool:", player.jumpParameter, "", "The name of the Animator boolean parameter to set to 'True' when jumping"); } character.talkingAnimation = TalkingAnimation.Standard; if (character.useExpressions) { character.expressionParameter = CustomGUILayout.TextField("Expression ID integer:", character.expressionParameter, "", "The name of the Animator integer parameter set to the active Expression ID number"); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Mecanim settings:", EditorStyles.boldLabel); if (SceneSettings.IsTopDown()) { character.spriteChild = (Transform)CustomGUILayout.ObjectField <Transform> ("Animator child:", character.spriteChild, true, "", "The Animator, which should be on a child GameObject"); } else { character.spriteChild = null; character.customAnimator = (Animator)CustomGUILayout.ObjectField <Transform> ("Animator (optional):", character.customAnimator, true, "", "The Animator, if not on the root GameObject"); } character.headLayer = CustomGUILayout.IntField("Head layer #:", character.headLayer, "", "The Animator layer used to play head animations while talking"); character.mouthLayer = CustomGUILayout.IntField("Mouth layer #:", character.mouthLayer, "", "The Animator layer used to play mouth animations while talking"); character.ikHeadTurning = CustomGUILayout.Toggle("IK head-turning?", character.ikHeadTurning, "", "If True, then inverse-kinematics will be used to turn the character's head dynamically, rather than playing pre-made animations"); if (character.ikHeadTurning) { #if UNITY_5 || UNITY_2017_1_OR_NEWER || UNITY_PRO_LICENSE EditorGUILayout.HelpBox("'IK Pass' must be enabled for this character's Base layer.", MessageType.Info); #else EditorGUILayout.HelpBox("This features is only available with Unity 5 or Unity Pro.", MessageType.Info); #endif } if (!Application.isPlaying) { character.ResetAnimator(); } Animator charAnimator = character.GetAnimator(); if (charAnimator != null && charAnimator.applyRootMotion) { character.rootTurningFactor = CustomGUILayout.Slider("Root Motion turning:", character.rootTurningFactor, 0f, 1f, "", "The factor by which the job of turning is left to Mecanim root motion"); } character.doWallReduction = CustomGUILayout.Toggle("Slow movement near walls?", character.doWallReduction, "", "If True, then characters will slow down when walking into walls"); if (character.doWallReduction) { character.wallLayer = CustomGUILayout.TextField("Wall collider layer:", character.wallLayer, "", "The layer that walls are expected to be placed on"); character.wallDistance = CustomGUILayout.Slider("Collider distance:", character.wallDistance, 0f, 2f, "", "The distance to keep away from walls"); character.wallReductionOnlyParameter = CustomGUILayout.Toggle("Only affects Mecanim parameter?", character.wallReductionOnlyParameter, "", "If True, then the wall reduction factor will only affect the Animator move speed float parameter, and not character's actual speed"); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Bone transforms:", EditorStyles.boldLabel); character.neckBone = (Transform)CustomGUILayout.ObjectField <Transform> ("Neck bone:", character.neckBone, true, "", "The 'Neck bone' Transform"); character.leftHandBone = (Transform)CustomGUILayout.ObjectField <Transform> ("Left hand:", character.leftHandBone, true, "", "The 'Left hand bone' transform"); character.rightHandBone = (Transform)CustomGUILayout.ObjectField <Transform> ("Right hand:", character.rightHandBone, true, "", "The 'Right hand bone' transform"); EditorGUILayout.EndVertical(); if (GUI.changed) { EditorUtility.SetDirty(character); } #endif }
public override void CharSettingsGUI() { #if UNITY_EDITOR EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Mecanim parameters:", EditorStyles.boldLabel); character.moveSpeedParameter = EditorGUILayout.TextField("Move speed float:", character.moveSpeedParameter); character.turnParameter = EditorGUILayout.TextField("Turn float:", character.turnParameter); character.talkParameter = EditorGUILayout.TextField("Talk bool:", character.talkParameter); if (AdvGame.GetReferences() && AdvGame.GetReferences().speechManager&& AdvGame.GetReferences().speechManager.lipSyncMode != LipSyncMode.Off && AdvGame.GetReferences().speechManager.lipSyncMode != LipSyncMode.FaceFX) { if (AdvGame.GetReferences().speechManager.lipSyncOutput == LipSyncOutput.PortraitAndGameObject) { if (character.GetShapeable()) { character.lipSyncGroupID = ActionBlendShape.ShapeableGroupGUI("Phoneme shape group:", character.GetShapeable().shapeGroups, character.lipSyncGroupID); } else { EditorGUILayout.HelpBox("Attach a Shapeable script to show phoneme options", MessageType.Info); } } else if (AdvGame.GetReferences().speechManager.lipSyncOutput == LipSyncOutput.GameObjectTexture) { if (character.GetComponent <LipSyncTexture>() == null) { EditorGUILayout.HelpBox("Attach a LipSyncTexture script to allow texture lip-syncing.", MessageType.Info); } } } if (!character.ikHeadTurning) { character.headYawParameter = EditorGUILayout.TextField("Head yaw float:", character.headYawParameter); character.headPitchParameter = EditorGUILayout.TextField("Head pitch float:", character.headPitchParameter); } character.headTurnSpeed = EditorGUILayout.Slider("Head turn speed:", character.headTurnSpeed, 0.1f, 20f); character.verticalMovementParameter = EditorGUILayout.TextField("Vertical movement float:", character.verticalMovementParameter); character.isGroundedParameter = EditorGUILayout.TextField("'Is grounded' bool:", character.isGroundedParameter); if (character is Player) { Player player = (Player)character; player.jumpParameter = EditorGUILayout.TextField("Jump bool:", player.jumpParameter); } character.talkingAnimation = TalkingAnimation.Standard; if (character.useExpressions) { character.expressionParameter = EditorGUILayout.TextField("Expression ID integer:", character.expressionParameter); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Mecanim settings:", EditorStyles.boldLabel); if (SceneSettings.IsTopDown()) { character.spriteChild = (Transform)EditorGUILayout.ObjectField("Animator child:", character.spriteChild, typeof(Transform), true); } else { character.spriteChild = null; character.customAnimator = (Animator)EditorGUILayout.ObjectField("Animator (optional):", character.customAnimator, typeof(Animator), true); } character.headLayer = EditorGUILayout.IntField("Head layer #:", character.headLayer); character.mouthLayer = EditorGUILayout.IntField("Mouth layer #:", character.mouthLayer); character.ikHeadTurning = EditorGUILayout.Toggle("IK head-turning?", character.ikHeadTurning); if (character.ikHeadTurning) { #if UNITY_5 || UNITY_2017_1_OR_NEWER || UNITY_PRO_LICENSE EditorGUILayout.HelpBox("'IK Pass' must be enabled for this character's Base layer.", MessageType.Info); #else EditorGUILayout.HelpBox("This features is only available with Unity 5 or Unity Pro.", MessageType.Info); #endif } if (!Application.isPlaying) { character.ResetAnimator(); } Animator charAnimator = character.GetAnimator(); if (charAnimator != null && charAnimator.applyRootMotion) { character.rootTurningFactor = EditorGUILayout.Slider("Root Motion turning:", character.rootTurningFactor, 0f, 1f); } character.doWallReduction = EditorGUILayout.BeginToggleGroup("Slow movement near wall colliders?", character.doWallReduction); character.wallLayer = EditorGUILayout.TextField("Wall collider layer:", character.wallLayer); character.wallDistance = EditorGUILayout.Slider("Collider distance:", character.wallDistance, 0f, 2f); character.wallReductionOnlyParameter = EditorGUILayout.Toggle("Only affects Mecanim parameter?", character.wallReductionOnlyParameter); EditorGUILayout.EndToggleGroup(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Bone transforms:", EditorStyles.boldLabel); character.neckBone = (Transform)EditorGUILayout.ObjectField("Neck bone:", character.neckBone, typeof(Transform), true); character.leftHandBone = (Transform)EditorGUILayout.ObjectField("Left hand:", character.leftHandBone, typeof(Transform), true); character.rightHandBone = (Transform)EditorGUILayout.ObjectField("Right hand:", character.rightHandBone, typeof(Transform), true); EditorGUILayout.EndVertical(); if (GUI.changed) { EditorUtility.SetDirty(character); } #endif }
// Direct-control functions private void DirectControlPlayer(bool isFirstPerson, Vector2 moveKeys) { KickStarter.player.CancelPathfindRecalculations(); if (KickStarter.settingsManager.directMovementType == DirectMovementType.RelativeToCamera) { if (moveKeys != Vector2.zero) { Vector3 moveDirectionInput = Vector3.zero; if (SceneSettings.IsTopDown()) { moveDirectionInput = (moveKeys.y * Vector3.forward) + (moveKeys.x * Vector3.right); } else { if (!isFirstPerson && KickStarter.settingsManager.directMovementPerspective && SceneSettings.CameraPerspective == CameraPerspective.ThreeD) { Vector3 forwardVector = (KickStarter.player.transform.position - Camera.main.transform.position).normalized; Vector3 rightVector = -Vector3.Cross(forwardVector, Camera.main.transform.up); moveDirectionInput = (moveKeys.y * forwardVector) + (moveKeys.x * rightVector); } else { moveDirectionInput = (moveKeys.y * KickStarter.mainCamera.ForwardVector()) + (moveKeys.x * KickStarter.mainCamera.RightVector()); } } KickStarter.player.isRunning = KickStarter.playerInput.IsPlayerControlledRunning(); KickStarter.player.charState = CharState.Move; if (!KickStarter.playerInput.cameraLockSnap) { if (isFirstPerson) { KickStarter.player.SetMoveDirection(moveDirectionInput); } else { KickStarter.player.SetLookDirection(moveDirectionInput, KickStarter.settingsManager.directTurnsInstantly); KickStarter.player.SetMoveDirectionAsForward(); } } } else if (KickStarter.player.charState == CharState.Move && KickStarter.playerInteraction.GetHotspotMovingTo() == null) { KickStarter.player.charState = CharState.Decelerate; //KickStarter.player.StopTurning (); } } else if (KickStarter.settingsManager.directMovementType == DirectMovementType.TankControls) { if (KickStarter.settingsManager.magnitudeAffectsDirect || isFirstPerson) { if (moveKeys.x < 0f) { KickStarter.player.TankTurnLeft(-moveKeys.x); } else if (moveKeys.x > 0f) { KickStarter.player.TankTurnRight(moveKeys.x); } else { KickStarter.player.StopTurning(); } } else { if (moveKeys.x < -0.3f) { KickStarter.player.TankTurnLeft(); } else if (moveKeys.x > 0.3f) { KickStarter.player.TankTurnRight(); } else { KickStarter.player.StopTurning(); } } if (moveKeys.y > 0f) { KickStarter.player.isRunning = KickStarter.playerInput.IsPlayerControlledRunning(); KickStarter.player.charState = CharState.Move; KickStarter.player.SetMoveDirectionAsForward(); } else if (moveKeys.y < 0f) { KickStarter.player.isRunning = KickStarter.playerInput.IsPlayerControlledRunning(); KickStarter.player.charState = CharState.Move; KickStarter.player.SetMoveDirectionAsBackward(); } else if (KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; KickStarter.player.SetMoveDirectionAsForward(); } } }