public override void SceneSettingsGUI() { #if UNITY_EDITOR EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.navMesh = (NavigationMesh)EditorGUILayout.ObjectField("Default NavMesh:", KickStarter.sceneSettings.navMesh, typeof(NavigationMesh), true); if (!SceneSettings.IsUnity2D()) { EditorGUILayout.EndHorizontal(); EditorGUILayout.HelpBox("This pathfinding method is only compatible with 'Unity 2D' mode.", MessageType.Warning); EditorGUILayout.BeginHorizontal(); } else if (KickStarter.sceneSettings.navMesh == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { NavigationMesh newNavMesh = null; newNavMesh = SceneManager.AddPrefab("Navigation", "NavMesh2D", true, false, true).GetComponent <NavigationMesh>(); newNavMesh.gameObject.name = "Default NavMesh"; KickStarter.sceneSettings.navMesh = newNavMesh; EditorGUIUtility.PingObject(newNavMesh.gameObject); } } EditorGUILayout.EndHorizontal(); #endif }
public override void SceneSettingsGUI() { #if UNITY_EDITOR if (SceneSettings.IsUnity2D()) { EditorGUILayout.HelpBox("This method is not compatible with 'Unity 2D' mode.", MessageType.Warning); } #endif }
public override void SceneSettingsGUI() { #if UNITY_EDITOR KickStarter.sceneSettings.navMesh = (NavigationMesh)EditorGUILayout.ObjectField("Default NavMesh:", KickStarter.sceneSettings.navMesh, typeof(NavigationMesh), true); if (SceneSettings.IsUnity2D()) { EditorGUILayout.HelpBox("This method is not compatible with 'Unity 2D' mode.", MessageType.Warning); } #endif }
protected void Awake() { if (GetComponent <Renderer>()) { GetComponent <Renderer>().enabled = false; } if (SceneSettings.IsUnity2D()) { transform.RotateAround(transform.position, Vector3.right, 90f); transform.RotateAround(transform.position, transform.right, -90f); } }
protected override void Awake() { isDragControlled = true; targetIsPlayer = false; SetOriginalPosition(); if (KickStarter.settingsManager) { _is2D = SceneSettings.IsUnity2D(); } base.Awake(); }
/** * 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(); }
/** * 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); }
/** * <summary>Rebuilds the nodes List from an array of points. The first point on the new path will be the GameObject's current position.</summary> * <param name = "pointData">An array of position vectors that dictate the new path</param> */ public void BuildNavPath(Vector3[] pointData) { if (pointData != null && pointData.Length > 0) { pathType = AC_PathType.ForwardOnly; affectY = false; nodePause = 0; List <Vector3> newNodes = new List <Vector3>(); newNodes.Clear(); newNodes.Add(this.transform.position); nodeCommands.Clear(); for (int i = 0; i < pointData.Length; i++) { if (i == 0) { // If first point, ignore if same as position if (SceneSettings.IsUnity2D()) { Vector2 testPoint = new Vector2(transform.position.x, transform.position.y); Vector2 testPoint2 = new Vector2(pointData[0].x, pointData[0].y); if ((testPoint - testPoint2).magnitude < 0.001f) { continue; } } else { Vector3 testPoint = new Vector3(transform.position.x, pointData[0].y, transform.position.z); if ((testPoint - pointData[0]).magnitude < 0.001f) { continue; } } } newNodes.Add(pointData[i]); } nodes = newNodes; } }
/** * <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(); }
public override void OnInspectorGUI() { if (_target == null) { return; } if (SceneSettings.IsUnity2D()) { if (_target.GetComponent <Collider2D>() == null) { EditorGUILayout.HelpBox("A 2D Collider component must be placed on this object.", MessageType.Warning); } else if (_target.GetComponent <Collider2D>() != null && !_target.GetComponent <Collider2D>().isTrigger) { EditorGUILayout.HelpBox("This object's 2D Collider component must have 'Is Trigger?' set.", MessageType.Warning); } if (_target.GetComponent <Rigidbody2D>() == null && _target.GetComponentInParent <Rigidbody2D>() == null) { EditorGUILayout.HelpBox("A 2D Rigidbody component must be placed on this object.", MessageType.Warning); } } else { if (_target.GetComponent <Collider>() == null) { EditorGUILayout.HelpBox("A Collider component must be placed on this object.", MessageType.Warning); } else if (_target.GetComponent <Collider>() != null && !_target.GetComponent <Collider>().isTrigger) { EditorGUILayout.HelpBox("This object's Collider component must have 'Is Trigger?' set.", MessageType.Warning); } if (_target.GetComponent <Rigidbody>() == null && _target.GetComponentInParent <Rigidbody>() == null) { EditorGUILayout.HelpBox("A Rigidbody component must be placed on this object.", MessageType.Warning); } } }
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); }
private static bool IsUnity2D() { return(SceneSettings.IsUnity2D()); }
public override void OnInspectorGUI() { if (AdvGame.GetReferences() == null) { ACDebug.LogError("A References file is required - please use the Adventure Creator window to create one."); EditorGUILayout.LabelField("No References file found!"); } else { if (AdvGame.GetReferences().inventoryManager) { inventoryManager = AdvGame.GetReferences().inventoryManager; } if (AdvGame.GetReferences().cursorManager) { cursorManager = AdvGame.GetReferences().cursorManager; } if (AdvGame.GetReferences().settingsManager) { settingsManager = AdvGame.GetReferences().settingsManager; } if (Application.isPlaying) { if (_target.gameObject.layer != LayerMask.NameToLayer(settingsManager.hotspotLayer)) { EditorGUILayout.HelpBox("Current state: OFF", MessageType.Info); } } if (_target.lineID > -1) { EditorGUILayout.LabelField("Speech Manager ID:", _target.lineID.ToString()); } _target.interactionSource = (AC.InteractionSource)CustomGUILayout.EnumPopup("Interaction source:", _target.interactionSource, "", "The source of the commands that are run when an option is chosen"); _target.hotspotName = CustomGUILayout.TextField("Label (if not name):", _target.hotspotName, "", "The display name, if not the GameObject's name"); _target.highlight = (Highlight)CustomGUILayout.ObjectField <Highlight> ("Object to highlight:", _target.highlight, true, "", "The Highlight component that controls any highlighting effects associated with the Hotspot"); if (AdvGame.GetReferences().settingsManager != null && AdvGame.GetReferences().settingsManager.hotspotDrawing == ScreenWorld.WorldSpace) { _target.iconSortingLayer = CustomGUILayout.TextField("Icon sorting layer:", _target.iconSortingLayer, "", "The 'Sorting Layer' of the icon's SpriteRenderer"); _target.iconSortingOrder = CustomGUILayout.IntField("Icon sprite order:", _target.iconSortingOrder, "", "The 'Order in Layer' of the icon's SpriteRenderer"); } EditorGUILayout.BeginHorizontal(); _target.centrePoint = (Transform)CustomGUILayout.ObjectField <Transform> ("Centre point (override):", _target.centrePoint, true, "", "A Transform that represents the centre of the Hotspot, if it is not physically at the same point as the Hotspot's GameObject itself"); if (_target.centrePoint == null) { if (GUILayout.Button("Create", autoWidth)) { string prefabName = "Hotspot centre: " + _target.gameObject.name; GameObject go = SceneManager.AddPrefab("Navigation", "HotspotCentre", true, false, false); go.name = prefabName; go.transform.position = _target.transform.position; _target.centrePoint = go.transform; go.transform.parent = _target.transform; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); _target.walkToMarker = (Marker)CustomGUILayout.ObjectField <Marker> ("Walk-to Marker:", _target.walkToMarker, true, "", "The Marker that the player can optionally automatically walk to before an Interaction runs"); if (_target.walkToMarker == null) { if (GUILayout.Button("Create", autoWidth)) { string prefabName = "Marker"; if (SceneSettings.IsUnity2D()) { prefabName += "2D"; } Marker newMarker = SceneManager.AddPrefab("Navigation", prefabName, true, false, true).GetComponent <Marker>(); newMarker.gameObject.name += (": " + _target.gameObject.name); newMarker.transform.position = _target.transform.position; _target.walkToMarker = newMarker; } } EditorGUILayout.EndHorizontal(); _target.limitToCamera = (_Camera)CustomGUILayout.ObjectField <_Camera> ("Limit to camera:", _target.limitToCamera, true, "", "If assigned, then the Hotspot will only be interactive when the assigned _Camera is active"); EditorGUILayout.BeginHorizontal(); _target.interactiveBoundary = (InteractiveBoundary)CustomGUILayout.ObjectField <InteractiveBoundary> ("Interactive boundary:", _target.interactiveBoundary, true, "", "If assigned, then the Hotspot will only be interactive when the player is within this Trigger Collider's boundary"); if (_target.interactiveBoundary == null) { if (GUILayout.Button("Create", autoWidth)) { string prefabName = "InteractiveBoundary"; if (SceneSettings.IsUnity2D()) { prefabName += "2D"; } InteractiveBoundary newInteractiveBoundary = SceneManager.AddPrefab("Logic", prefabName, true, false, true).GetComponent <InteractiveBoundary>(); newInteractiveBoundary.gameObject.name += (": " + _target.gameObject.name); newInteractiveBoundary.transform.position = _target.transform.position; _target.interactiveBoundary = newInteractiveBoundary; UnityVersionHandler.PutInFolder(newInteractiveBoundary.gameObject, "_Hotspots"); } } EditorGUILayout.EndHorizontal(); _target.drawGizmos = CustomGUILayout.Toggle("Draw yellow cube?", _target.drawGizmos, "", "If True, then a Gizmo may be drawn in the Scene window at the Hotspots's position"); if (settingsManager != null && (settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction || settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot || settingsManager.interactionMethod == AC_InteractionMethod.CustomScript)) { _target.oneClick = CustomGUILayout.Toggle("Single 'Use' Interaction?", _target.oneClick, "", "If True, then clicking the Hotspot will run the Hotspot's first interaction in useButtons, regardless of the Settings Manager's Interaction method"); if (_target.oneClick && settingsManager.interactionMethod == AC_InteractionMethod.CustomScript) { EditorGUILayout.HelpBox("The above property can be accessed by reading the Hotspot script's IsSingleInteraction() method.", MessageType.Info); } } if (_target.oneClick || (settingsManager != null && settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive)) { if (settingsManager != null && settingsManager.interactionMethod == AC_InteractionMethod.CustomScript) { } else { _target.doubleClickingHotspot = (DoubleClickingHotspot)CustomGUILayout.EnumPopup("Double-clicking:", _target.doubleClickingHotspot, "", "The effect that double-clicking on the Hotspot has"); } } if (settingsManager != null && settingsManager.playerFacesHotspots) { _target.playerTurnsHead = CustomGUILayout.Toggle("Players turn heads when active?", _target.playerTurnsHead, "", "If True, then the player will turn their head when the Hotspot is selected"); } EditorGUILayout.Space(); UseInteractionGUI(); if (settingsManager == null || settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive || settingsManager.interactionMethod == AC_InteractionMethod.CustomScript) { EditorGUILayout.Space(); LookInteractionGUI(); } EditorGUILayout.Space(); InvInteractionGUI(); EditorGUILayout.Space(); UnhandledInvInteractionGUI(); } UnityVersionHandler.CustomSetDirty(_target); }
protected void SharedGUI (DragBase _target, bool isOnHinge) { CustomGUILayout.BeginVertical (); EditorGUILayout.LabelField ("Collision settings:", EditorStyles.boldLabel); _target.ignorePlayerCollider = CustomGUILayout.ToggleLeft ("Ignore Player's collider?", _target.ignorePlayerCollider, "", "If True, then the Physics system will ignore collisions between this object and the player"); _target.ignoreMoveableRigidbodies = CustomGUILayout.ToggleLeft ("Ignore Moveable Rigidbodies?", _target.ignoreMoveableRigidbodies, "", " If True, then the Physics system will ignore collisions between this object and the bounday colliders of any DragTrack that this is not locked to"); _target.childrenShareLayer = CustomGUILayout.ToggleLeft ("Place children on same layer?", _target.childrenShareLayer, "", "If True, then this object's children will be placed on the same layer"); EditorGUILayout.BeginHorizontal (); _target.interactiveBoundary = (InteractiveBoundary) CustomGUILayout.ObjectField <InteractiveBoundary> ("Interactive boundary:", _target.interactiveBoundary, true, "", "If assigned, then the draggable will only be interactive when the player is within this Trigger Collider's boundary"); if (_target.interactiveBoundary == null) { if (GUILayout.Button ("Create", GUILayout.MaxWidth (90f))) { string prefabName = "InteractiveBoundary"; if (SceneSettings.IsUnity2D ()) { prefabName += "2D"; } InteractiveBoundary newInteractiveBoundary = SceneManager.AddPrefab ("Logic", prefabName, true, false, true).GetComponent <InteractiveBoundary>(); newInteractiveBoundary.gameObject.name += (": " + _target.gameObject.name); newInteractiveBoundary.transform.position = _target.transform.position; _target.interactiveBoundary = newInteractiveBoundary; UnityVersionHandler.PutInFolder (newInteractiveBoundary.gameObject, "_Hotspots"); } } EditorGUILayout.EndHorizontal (); _target.limitToCamera = (_Camera) CustomGUILayout.ObjectField <_Camera> ("Limit to camera:", _target.limitToCamera, true, "", "If assigned, then the draggable will only be interactive when the assigned _Camera is active"); CustomGUILayout.EndVertical (); CustomGUILayout.BeginVertical (); EditorGUILayout.LabelField ("Icon settings:", EditorStyles.boldLabel); _target.showIcon = CustomGUILayout.Toggle ("Icon at contact point?", _target.showIcon, "", "If True, then an icon will be displayed at the 'grab point' when the object is held"); if (_target.showIcon) { if (cursorManager && cursorManager.cursorIcons.Count > 0) { int cursorInt = cursorManager.GetIntFromID (_target.iconID); cursorInt = CustomGUILayout.Popup ("Cursor icon:", cursorInt, cursorManager.GetLabelsArray (), "", "The cursor that gets shown when held"); _target.iconID = cursorManager.cursorIcons [cursorInt].id; } else { _target.iconID = -1; } } CustomGUILayout.EndVertical (); CustomGUILayout.BeginVertical (); EditorGUILayout.LabelField ("Sound settings:", EditorStyles.boldLabel); _target.moveSoundClip = (AudioClip) CustomGUILayout.ObjectField <AudioClip> ("Move sound:", _target.moveSoundClip, false, "", "The sound to play when the object is moved"); _target.slideSoundThreshold = CustomGUILayout.FloatField ("Min. move speed:", _target.slideSoundThreshold, "", "The minimum speed that the object must be moving by for sound to play"); _target.slidePitchFactor = CustomGUILayout.FloatField ("Pitch factor:", _target.slidePitchFactor, "", "The factor by which the movement sound's pitch is adjusted in relation to speed"); _target.collideSoundClip = (AudioClip) CustomGUILayout.ObjectField <AudioClip> ("Collide sound:", _target.collideSoundClip, false, "", "The sound to play when the object has a collision"); if (isOnHinge) { _target.onlyPlayLowerCollisionSound = CustomGUILayout.Toggle ("Only on lower boundary?", _target.onlyPlayLowerCollisionSound, "", "If True, then the collision sound will only play when the object collides with its lower boundary collider"); } CustomGUILayout.EndVertical (); }
public override void OnInspectorGUI() { if (AdvGame.GetReferences() == null) { ACDebug.LogError("A References file is required - please use the Adventure Creator window to create one."); EditorGUILayout.LabelField("No References file found!"); } else { if (AdvGame.GetReferences().inventoryManager) { inventoryManager = AdvGame.GetReferences().inventoryManager; } if (AdvGame.GetReferences().cursorManager) { cursorManager = AdvGame.GetReferences().cursorManager; } if (AdvGame.GetReferences().settingsManager) { settingsManager = AdvGame.GetReferences().settingsManager; } if (Application.isPlaying) { if (_target.gameObject.layer != LayerMask.NameToLayer(settingsManager.hotspotLayer)) { EditorGUILayout.HelpBox("Current state: OFF", MessageType.Info); } } if (_target.lineID > -1) { EditorGUILayout.LabelField("Speech Manager ID:", _target.lineID.ToString()); } _target.interactionSource = (AC.InteractionSource)EditorGUILayout.EnumPopup("Interaction source:", _target.interactionSource); _target.hotspotName = EditorGUILayout.TextField("Label (if not name):", _target.hotspotName); _target.highlight = (Highlight)EditorGUILayout.ObjectField("Object to highlight:", _target.highlight, typeof(Highlight), true); if (AdvGame.GetReferences().settingsManager != null && AdvGame.GetReferences().settingsManager.hotspotDrawing == ScreenWorld.WorldSpace) { _target.iconSortingLayer = EditorGUILayout.TextField("Icon sorting layer:", _target.iconSortingLayer); _target.iconSortingOrder = EditorGUILayout.IntField("Icon sprite order:", _target.iconSortingOrder); } EditorGUILayout.BeginHorizontal(); _target.centrePoint = (Transform)EditorGUILayout.ObjectField("Centre point (override):", _target.centrePoint, typeof(Transform), true); if (_target.centrePoint == null) { if (GUILayout.Button("Create", autoWidth)) { string prefabName = "Hotspot centre: " + _target.gameObject.name; GameObject go = SceneManager.AddPrefab("Navigation", "HotspotCentre", true, false, false); go.name = prefabName; go.transform.position = _target.transform.position; _target.centrePoint = go.transform; if (GameObject.Find("_Markers")) { go.transform.parent = GameObject.Find("_Markers").transform; } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); _target.walkToMarker = (Marker)EditorGUILayout.ObjectField("Walk-to Marker:", _target.walkToMarker, typeof(Marker), true); if (_target.walkToMarker == null) { if (GUILayout.Button("Create", autoWidth)) { string prefabName = "Marker"; if (SceneSettings.IsUnity2D()) { prefabName += "2D"; } Marker newMarker = SceneManager.AddPrefab("Navigation", prefabName, true, false, true).GetComponent <Marker>(); newMarker.gameObject.name += (": " + _target.gameObject.name); newMarker.transform.position = _target.transform.position; _target.walkToMarker = newMarker; } } EditorGUILayout.EndHorizontal(); _target.limitToCamera = (_Camera)EditorGUILayout.ObjectField("Limit to camera:", _target.limitToCamera, typeof(_Camera), true); EditorGUILayout.BeginHorizontal(); _target.interactiveBoundary = (InteractiveBoundary)EditorGUILayout.ObjectField("Interactive boundary:", _target.interactiveBoundary, typeof(InteractiveBoundary), true); if (_target.interactiveBoundary == null) { if (GUILayout.Button("Create", autoWidth)) { string prefabName = "InteractiveBoundary"; if (SceneSettings.IsUnity2D()) { prefabName += "2D"; } InteractiveBoundary newInteractiveBoundary = SceneManager.AddPrefab("Logic", prefabName, true, false, true).GetComponent <InteractiveBoundary>(); newInteractiveBoundary.gameObject.name += (": " + _target.gameObject.name); newInteractiveBoundary.transform.position = _target.transform.position; _target.interactiveBoundary = newInteractiveBoundary; UnityVersionHandler.PutInFolder(newInteractiveBoundary.gameObject, "_Hotspots"); } } EditorGUILayout.EndHorizontal(); _target.drawGizmos = EditorGUILayout.Toggle("Draw yellow cube?", _target.drawGizmos); if (settingsManager != null && (settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction || settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot)) { _target.oneClick = EditorGUILayout.Toggle("Single 'Use' Interaction?", _target.oneClick); } if (_target.oneClick || (settingsManager != null && settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive)) { _target.doubleClickingHotspot = (DoubleClickingHotspot)EditorGUILayout.EnumPopup("Double-clicking:", _target.doubleClickingHotspot); } if (settingsManager != null && settingsManager.playerFacesHotspots) { _target.playerTurnsHead = EditorGUILayout.Toggle("Turn head active?", _target.playerTurnsHead); } EditorGUILayout.Space(); UseInteractionGUI(); if (settingsManager == null || settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive || settingsManager.interactionMethod == AC_InteractionMethod.CustomScript) { EditorGUILayout.Space(); LookInteractionGUI(); } EditorGUILayout.Space(); InvInteractionGUI(); EditorGUILayout.Space(); UnhandledInvInteractionGUI(); } UnityVersionHandler.CustomSetDirty(_target); }
private void MoveStraightToCursor() { if (KickStarter.playerInput.AllDirectionsLocked()) { if (KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; } return; } if (KickStarter.playerInput.GetDragState() == DragState.None) { KickStarter.playerInput.ResetDragMovement(); if (KickStarter.player.charState == CharState.Move && KickStarter.player.GetPath() == null) { KickStarter.player.charState = CharState.Decelerate; } } if (KickStarter.playerInput.GetMouseState() == MouseState.SingleClick && KickStarter.settingsManager.singleTapStraight) { movingFromHold = false; if (KickStarter.settingsManager.singleTapStraightPathfind) { PointControlPlayer(); return; } //Vector3 clickPoint = ClickPoint (KickStarter.playerInput.GetMousePosition ()); Vector3 clickPoint = GetStraightToCursorClickPoint(); Vector3 moveDirection = clickPoint - KickStarter.player.transform.position; if (clickPoint != Vector3.zero) { if (moveDirection.magnitude > KickStarter.settingsManager.destinationAccuracy) { if (SceneSettings.IsUnity2D()) { moveDirection = new Vector3(moveDirection.x, 0f, moveDirection.y); } bool run = false; if (moveDirection.magnitude > KickStarter.settingsManager.dragRunThreshold) { run = true; } if (KickStarter.playerInput.runLock == PlayerMoveLock.AlwaysRun) { run = true; } else if (KickStarter.playerInput.runLock == PlayerMoveLock.AlwaysWalk) { run = false; } List <Vector3> pointArray = new List <Vector3>(); pointArray.Add(clickPoint); KickStarter.player.MoveAlongPoints(pointArray.ToArray(), run); } else { if (KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; } } } } else if (KickStarter.playerInput.GetDragState() == DragState.Player && moveStraightToCursorHoldTime == 0f && (!KickStarter.settingsManager.singleTapStraight || KickStarter.playerInput.CanClick())) { //Vector3 clickPoint = ClickPoint (KickStarter.playerInput.GetMousePosition ()); Vector3 clickPoint = GetStraightToCursorClickPoint(); Vector3 moveDirection = clickPoint - KickStarter.player.transform.position; if (clickPoint != Vector3.zero) { if (moveDirection.magnitude > KickStarter.settingsManager.destinationAccuracy) { if (SceneSettings.IsUnity2D()) { moveDirection = new Vector3(moveDirection.x, 0f, moveDirection.y); } bool run = false; if (moveDirection.magnitude > KickStarter.settingsManager.dragRunThreshold) { run = true; } if (KickStarter.playerInput.runLock == PlayerMoveLock.AlwaysRun) { run = true; } else if (KickStarter.playerInput.runLock == PlayerMoveLock.AlwaysWalk) { run = false; } if (KickStarter.settingsManager.pathfindUpdateFrequency > 0f && moveStraightToCursorUpdateTime == 0f) { if (movingFromHold && KickStarter.player.IsPathfinding() && (clickPoint - KickStarter.player.GetTargetPosition(true)).magnitude < KickStarter.settingsManager.destinationAccuracy) { // Too close, don't update } else { Vector3[] pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(KickStarter.player.transform.position, clickPoint, KickStarter.player); KickStarter.player.MoveAlongPoints(pointArray, run); moveStraightToCursorUpdateTime = KickStarter.settingsManager.pathfindUpdateFrequency; movingFromHold = true; } } else { KickStarter.player.isRunning = run; KickStarter.player.charState = CharState.Move; KickStarter.player.SetLookDirection(moveDirection, false); KickStarter.player.SetMoveDirectionAsForward(); movingFromHold = true; } } else { if (KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; movingFromHold = false; } } if (KickStarter.player.GetPath() && (KickStarter.settingsManager.pathfindUpdateFrequency <= 0f || KickStarter.playerInput.GetMouseState() != MouseState.HeldDown)) { KickStarter.player.EndPath(); movingFromHold = false; } } else { if (KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; movingFromHold = false; } if (KickStarter.player.GetPath()) { KickStarter.player.EndPath(); movingFromHold = false; } } } else { if (KickStarter.player.charState == CharState.Move || KickStarter.player.IsPathfinding()) { if (movingFromHold && moveStraightToCursorHoldTime > 0f) { if (KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; } if (KickStarter.player.GetPath()) { KickStarter.player.EndPath(); } } } else { movingFromHold = false; } } }
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); }
// Point/click functions private void PointControlPlayer() { if (KickStarter.playerInput.IsCursorLocked()) { return; } if (!KickStarter.mainCamera.IsPointInCamera(KickStarter.playerInput.GetMousePosition())) { return; } if (KickStarter.playerInput.AllDirectionsLocked()) { if (KickStarter.player.GetPath() == null && KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; } return; } if ((KickStarter.playerInput.GetMouseState() == MouseState.SingleClick || KickStarter.playerInput.GetMouseState() == MouseState.DoubleClick) && !KickStarter.playerMenus.IsInteractionMenuOn() && !KickStarter.playerMenus.IsMouseOverMenu() && !KickStarter.playerInteraction.IsMouseOverHotspot() && KickStarter.playerCursor) { if (KickStarter.playerCursor.GetSelectedCursor() < 0) { if (KickStarter.settingsManager.doubleClickMovement == DoubleClickMovement.RequiredToWalk && KickStarter.playerInput.GetMouseState() == MouseState.SingleClick) { return; } if (KickStarter.playerInput.GetDragState() == DragState.Moveable) { return; } if (KickStarter.runtimeInventory.SelectedItem != null && !KickStarter.settingsManager.canMoveWhenActive && KickStarter.settingsManager.movementMethod == MovementMethod.PointAndClick && !KickStarter.settingsManager.inventoryDisableLeft) { return; } bool doubleClick = false; if (KickStarter.playerInput.GetMouseState() == MouseState.DoubleClick && KickStarter.settingsManager.doubleClickMovement == DoubleClickMovement.MakesPlayerRun) { doubleClick = true; } if (KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction && KickStarter.playerMenus != null) { KickStarter.playerMenus.CloseInteractionMenus(); } Vector3 simulatedMouse = KickStarter.playerInput.GetMousePosition(); // In Unity 5.6+, 'Ignore Raycast' layers are included in raycast checks so we need to specify the layer if in 2D if ( (SceneSettings.IsUnity2D() && !SearchForNavMesh2D(simulatedMouse, Vector2.zero, doubleClick)) || (!SceneSettings.IsUnity2D() && !RaycastNavMesh(simulatedMouse, doubleClick)) ) { // Move Ray down screen until we hit something if (KickStarter.settingsManager.walkableClickRange > 0f && ((int)Screen.height * KickStarter.settingsManager.walkableClickRange) > 1) { float maxIterations = 100f; float stepSize = Screen.height / maxIterations; // was fixed at 4f if (KickStarter.settingsManager.navMeshSearchDirection == NavMeshSearchDirection.StraightDownFromCursor) { if (SceneSettings.IsUnity2D()) { // Down if (SearchForNavMesh2D(simulatedMouse, -Vector2.up, doubleClick)) { return; } } else { for (float i = 1f; i < Screen.height * KickStarter.settingsManager.walkableClickRange; i += stepSize) { // Down if (RaycastNavMesh(new Vector2(simulatedMouse.x, simulatedMouse.y - i), doubleClick)) { return; } } } } for (float i = 1f; i < Screen.height * KickStarter.settingsManager.walkableClickRange; i += stepSize) { // Up if (RaycastNavMesh(new Vector2(simulatedMouse.x, simulatedMouse.y + i), doubleClick)) { return; } if (KickStarter.settingsManager.navMeshSearchDirection == NavMeshSearchDirection.RadiallyOutwardsFromCursor) { // Down if (RaycastNavMesh(new Vector2(simulatedMouse.x, simulatedMouse.y - i), doubleClick)) { return; } } // Left if (RaycastNavMesh(new Vector2(simulatedMouse.x - i, simulatedMouse.y), doubleClick)) { return; } // Right if (RaycastNavMesh(new Vector2(simulatedMouse.x + i, simulatedMouse.y), doubleClick)) { return; } // DownLeft if (RaycastNavMesh(new Vector2(simulatedMouse.x - i, simulatedMouse.y - i), doubleClick)) { return; } // DownRight if (RaycastNavMesh(new Vector2(simulatedMouse.x + i, simulatedMouse.y - i), doubleClick)) { return; } // UpLeft if (RaycastNavMesh(new Vector2(simulatedMouse.x - i, simulatedMouse.y + i), doubleClick)) { return; } // UpRight if (RaycastNavMesh(new Vector2(simulatedMouse.x + i, simulatedMouse.y + i), doubleClick)) { return; } } } } } else if (KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot && KickStarter.settingsManager.autoCycleWhenInteract) { KickStarter.playerCursor.ResetSelectedCursor(); } } else if (KickStarter.player.GetPath() == null && KickStarter.player.charState == CharState.Move) { KickStarter.player.charState = CharState.Decelerate; } }