/** * Tells the scene's SortingMap to account for this particular instance of FollowSortingMap. */ public void UpdateSortingMap() { if (followSortingMap) { if (KickStarter.sceneSettings != null && KickStarter.sceneSettings.sortingMap != null) { if (KickStarter.sceneSettings.sortingMap != sortingMap) { sortingMap = KickStarter.sceneSettings.sortingMap; SetOriginalDepth(); } } } else { if (customSortingMap != null) { if (sortingMap != customSortingMap) { sortingMap = customSortingMap; SetOriginalDepth(); } } } }
private void OnSceneGUI() { SortingMap _target = (SortingMap)target; for (int i = 0; i < _target.sortingAreas.Count; i++) { Vector3 newPosition = _target.GetAreaPosition(i); newPosition = Handles.PositionHandle(newPosition, Quaternion.identity); _target.sortingAreas [i].z = (newPosition - _target.transform.position).magnitude / _target.transform.forward.magnitude; Vector3 midPoint = _target.transform.position; if (i == 0) { midPoint += _target.transform.forward * _target.sortingAreas [i].z / 2f; } else { midPoint += _target.transform.forward * (_target.sortingAreas [i].z + _target.sortingAreas [i - 1].z) / 2f; } if (_target.mapType == SortingMapType.OrderInLayer) { Handles.Label(midPoint, _target.sortingAreas [i].order.ToString()); } else { Handles.Label(midPoint, _target.sortingAreas [i].layer); } } UnityVersionHandler.CustomSetDirty(_target); }
public override float ActionCharRenderRun(ActionCharRender action) { if (action.renderLock_scale == RenderLock.Set) { action._char.lockScale = true; action._char.spriteScale = (float)action.scale / 100f; } else if (action.renderLock_scale == RenderLock.Release) { action._char.lockScale = false; } if (action.renderLock_direction == RenderLock.Set) { action._char.SetSpriteDirection(action.direction); } else if (action.renderLock_direction == RenderLock.Release) { action._char.lockDirection = false; } if (action.renderLock_sortingMap != RenderLock.NoChange && action._char.GetComponentInChildren <FollowSortingMap>()) { FollowSortingMap[] followSortingMaps = action._char.GetComponentsInChildren <FollowSortingMap>(); SortingMap sortingMap = (action.renderLock_sortingMap == RenderLock.Set) ? action.sortingMap : KickStarter.sceneSettings.sortingMap; foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.SetSortingMap(sortingMap); } } return(0f); }
/** * <summary>Registers a SortingMap, so that it can be updated</summary> * <param name = "_object">The SortingMap to register</param> */ public void Register(SortingMap _object) { if (!sortingMaps.Contains(_object)) { sortingMaps.Add(_object); } }
/** * <summary>Unregisters a SortingMap, so that it is no longer updated</summary> * <param name = "_object">The SortingMap to unregister</param> */ public void Unregister(SortingMap _object) { if (sortingMaps.Contains(_object)) { sortingMaps.Remove(_object); } }
override public void AssignValues(List <ActionParameter> parameters) { if (sceneSetting == SceneSetting.DefaultNavMesh) { if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider && changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles) { hole = AssignFile <PolygonCollider2D> (parameters, parameterID, constantID, hole); } else { newNavMesh = AssignFile <NavigationMesh> (parameters, parameterID, constantID, newNavMesh); } } else if (sceneSetting == SceneSetting.DefaultPlayerStart) { playerStart = AssignFile <PlayerStart> (parameters, parameterID, constantID, playerStart); } else if (sceneSetting == SceneSetting.SortingMap) { sortingMap = AssignFile <SortingMap> (parameters, parameterID, constantID, sortingMap); } else if (sceneSetting == SceneSetting.OnLoadCutscene || sceneSetting == SceneSetting.OnStartCutscene) { cutscene = AssignFile <Cutscene> (parameters, parameterID, constantID, cutscene); } }
private void OnSceneGUI() { SortingMap _target = (SortingMap)target; GUIStyle style = new GUIStyle(); style.normal.textColor = Color.white; style.normal.background = Resource.GreyTexture; for (int i = 0; i < _target.sortingAreas.Count; i++) { Vector3 newPosition = _target.GetAreaPosition(i); newPosition = Handles.PositionHandle(newPosition, Quaternion.identity); _target.sortingAreas [i].z = (newPosition - _target.transform.position).magnitude / _target.transform.forward.magnitude; Vector3 midPoint = _target.transform.position; if (i == 0) { midPoint += _target.transform.forward * _target.sortingAreas [i].z / 2f; } else { midPoint += _target.transform.forward * (_target.sortingAreas [i].z + _target.sortingAreas [i - 1].z) / 2f; } string label = (_target.mapType == SortingMapType.OrderInLayer) ? _target.sortingAreas [i].order.ToString() : _target.sortingAreas [i].layer; Handles.Label(midPoint, label, style); } UnityVersionHandler.CustomSetDirty(_target); }
override public void AssignValues (List<ActionParameter> parameters) { SceneSettings sceneSettings = GameObject.FindWithTag (Tags.gameEngine).GetComponent <SceneSettings>(); if (sceneSetting == SceneSetting.DefaultNavMesh) { if (sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider && changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles) { hole = AssignFile <PolygonCollider2D> (parameters, parameterID, constantID, hole); } else { newNavMesh = AssignFile <NavigationMesh> (parameters, parameterID, constantID, newNavMesh); } } else if (sceneSetting == SceneSetting.DefaultPlayerStart) { playerStart = AssignFile <PlayerStart> (parameters, parameterID, constantID, playerStart); } else if (sceneSetting == SceneSetting.SortingMap) { sortingMap = AssignFile <SortingMap> (parameters, parameterID, constantID, sortingMap); } else if (sceneSetting == SceneSetting.OnLoadCutscene || sceneSetting == SceneSetting.OnStartCutscene) { cutscene = AssignFile <Cutscene> (parameters, parameterID, constantID, cutscene); } }
public override void AssignValues(List<ActionParameter> parameters) { if (sceneSetting == SceneSetting.DefaultNavMesh) { if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider && changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles) { hole = AssignFile <PolygonCollider2D> (parameters, parameterID, constantID, hole); replaceHole = AssignFile <PolygonCollider2D> (parameters, replaceParameterID, replaceConstantID, replaceHole); } else { newNavMesh = AssignFile <NavigationMesh> (parameters, parameterID, constantID, newNavMesh); } } else if (sceneSetting == SceneSetting.DefaultPlayerStart) { playerStart = AssignFile <PlayerStart> (parameters, parameterID, constantID, playerStart); } else if (sceneSetting == SceneSetting.SortingMap) { sortingMap = AssignFile <SortingMap> (parameters, parameterID, constantID, sortingMap); } else if (sceneSetting == SceneSetting.OnLoadCutscene || sceneSetting == SceneSetting.OnStartCutscene) { cutscene = AssignFile <Cutscene> (parameters, parameterID, constantID, cutscene); } }
/** * <summary>Creates a new instance of the 'Scene: Change setting' Action, set to change the current SortingMap</summary> * <param name = "newSortingMap">The new SortingMap</param> * <returns>The generated Action</returns> */ public static ActionNavMesh CreateNew_ChangeSortingMap(SortingMap newSortingMap) { ActionNavMesh newAction = (ActionNavMesh)CreateInstance <ActionNavMesh>(); newAction.sceneSetting = SceneSetting.SortingMap; newAction.sortingMap = newSortingMap; return(newAction); }
private void OnEnable() { if (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.IsUnity2D()) { SortingMap _target = (SortingMap)target; _target.transform.forward = Vector3.down; } }
protected void ApplyRenderData(Char character, NPCData npcData) { character.lockDirection = npcData.lockDirection; character.lockScale = npcData.lockScale; if (character.spriteChild && character.spriteChild.GetComponent <FollowSortingMap>()) { character.spriteChild.GetComponent <FollowSortingMap>().lockSorting = npcData.lockSorting; } else if (character.GetComponent <FollowSortingMap>()) { character.GetComponent <FollowSortingMap>().lockSorting = npcData.lockSorting; } else { character.ReleaseSorting(); } if (npcData.lockDirection) { character.spriteDirection = npcData.spriteDirection; } if (npcData.lockScale) { character.spriteScale = npcData.spriteScale; } if (npcData.lockSorting) { if (character.spriteChild && character.spriteChild.GetComponent <Renderer>()) { character.spriteChild.GetComponent <Renderer>().sortingOrder = npcData.sortingOrder; character.spriteChild.GetComponent <Renderer>().sortingLayerName = npcData.sortingLayer; } else if (character.GetComponent <Renderer>()) { character.GetComponent <Renderer>().sortingOrder = npcData.sortingOrder; character.GetComponent <Renderer>().sortingLayerName = npcData.sortingLayer; } } if (character.GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = character.GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = Serializer.returnComponent <SortingMap> (npcData.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = npcData.followSortingMap; if (!npcData.followSortingMap && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } }
private void UnloadSortingMap(int sortingMapInt, SceneSettings sceneSettings) { SortingMap sortingMap = ConstantID.GetComponent <SortingMap> (sortingMapInt, sceneSettings.gameObject.scene); if (sortingMap) { sceneSettings.sortingMap = sortingMap; KickStarter.sceneSettings.UpdateAllSortingMaps(); } }
private void UnloadSortingMap(int sortingMapInt, SceneSettings sceneSettings) { SortingMap sortingMap = Serializer.returnComponent <SortingMap> (sortingMapInt, sceneSettings.gameObject); if (sortingMap && sceneSettings) { sceneSettings.sortingMap = sortingMap; KickStarter.sceneSettings.UpdateAllSortingMaps(); } }
public override void AssignValues(List <ActionParameter> parameters) { runtimeChar = AssignFile <Char> (parameters, parameterID, constantID, _char); if (isPlayer) { runtimeChar = KickStarter.player; } sortingOrder = AssignInteger(parameters, sortingOrderParameterID, sortingOrder); sortingLayer = AssignString(parameters, sortingLayerParameterID, sortingLayer); runtimeSortingMap = AssignFile <SortingMap> (parameters, sortingMapParameterID, sortingMapConstantID, sortingMap); }
public void UpdateSortingMap() { if (KickStarter.sceneSettings != null && KickStarter.sceneSettings.sortingMap != null) { sortingMap = KickStarter.sceneSettings.sortingMap; SetOriginalDepth(); sortingMap.UpdateSimilarFollowers(this); } else { Debug.Log(this.gameObject.name + " cannot find sorting map to follow!"); } }
/** * Tells the scene's SortingMap to account for this particular instance of FollowSortingMap. */ public void UpdateSortingMap() { if (followSortingMap && KickStarter.sceneSettings != null && KickStarter.sceneSettings.sortingMap != null) { sortingMap = KickStarter.sceneSettings.sortingMap; SetOriginalDepth(); sortingMap.UpdateSimilarFollowers(this); } else if (!followSortingMap && customSortingMap != null) { sortingMap = customSortingMap; SetOriginalDepth(); sortingMap.UpdateSimilarFollowers(this); } }
private void UnloadSortingMap(int sortingMapInt) { SortingMap sortingMap = Serializer.returnComponent <SortingMap> (sortingMapInt); if (sortingMap && KickStarter.sceneSettings) { KickStarter.sceneSettings.sortingMap = sortingMap; // Reset all FollowSortingMap components FollowSortingMap[] followSortingMaps = FindObjectsOfType(typeof(FollowSortingMap)) as FollowSortingMap[]; foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.UpdateSortingMap(); } } }
public void SetSortingMap(SortingMap _sortingMap) { if (_sortingMap == null) { followSortingMap = false; customSortingMap = null; } else if (KickStarter.sceneSettings.sortingMap == _sortingMap) { followSortingMap = true; } else { followSortingMap = false; customSortingMap = _sortingMap; } KickStarter.sceneSettings.UpdateAllSortingMaps(); }
public override void AssignValues(List <ActionParameter> parameters) { if (sceneSettings == null) { return; } switch (sceneSetting) { case SceneSetting.DefaultNavMesh: if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider && changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles) { runtimeHole = AssignFile <PolygonCollider2D> (parameters, parameterID, constantID, hole); runtimeReplaceHole = AssignFile <PolygonCollider2D> (parameters, replaceParameterID, replaceConstantID, replaceHole); runtimeNewNavMesh = null; } else { runtimeHole = null; runtimeReplaceHole = null; runtimeNewNavMesh = AssignFile <NavigationMesh> (parameters, parameterID, constantID, newNavMesh); } break; case SceneSetting.DefaultPlayerStart: runtimePlayerStart = AssignFile <PlayerStart> (parameters, parameterID, constantID, playerStart); break; case SceneSetting.SortingMap: runtimeSortingMap = AssignFile <SortingMap> (parameters, parameterID, constantID, sortingMap); break; case SceneSetting.TintMap: runtimeTintMap = AssignFile <TintMap> (parameters, parameterID, constantID, tintMap); break; case SceneSetting.OnLoadCutscene: case SceneSetting.OnStartCutscene: runtimeCutscene = AssignFile <Cutscene> (parameters, parameterID, constantID, cutscene); break; } }
public override void AssignValues(List <ActionParameter> parameters) { if (isPlayer) { runtimeChar = AssignPlayer(playerID, parameters, parameterID); } else { runtimeChar = AssignFile <Char> (parameters, parameterID, constantID, _char); } sortingOrder = AssignInteger(parameters, sortingOrderParameterID, sortingOrder); sortingLayer = AssignString(parameters, sortingLayerParameterID, sortingLayer); runtimeSortingMap = AssignFile <SortingMap> (parameters, sortingMapParameterID, sortingMapConstantID, sortingMap); scale = AssignInteger(parameters, scaleParameterID, scale); if (directionParameterID >= 0) { int _directionInt = AssignInteger(parameters, directionParameterID, 0); direction = (CharDirection)_directionInt; } }
override public void ShowGUI(List <ActionParameter> parameters) { if (KickStarter.sceneSettings == null) { return; } sceneSetting = (SceneSetting)EditorGUILayout.EnumPopup("Scene setting to change:", sceneSetting); if (sceneSetting == SceneSetting.DefaultNavMesh) { if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.meshCollider || KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider) { if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider) { changeNavMeshMethod = (ChangeNavMeshMethod)EditorGUILayout.EnumPopup("Change NavMesh method:", changeNavMeshMethod); } if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.meshCollider || changeNavMeshMethod == ChangeNavMeshMethod.ChangeNavMesh) { parameterID = Action.ChooseParameterGUI("New NavMesh:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; newNavMesh = null; } else { newNavMesh = (NavigationMesh)EditorGUILayout.ObjectField("New NavMesh:", newNavMesh, typeof(NavigationMesh), true); constantID = FieldToID <NavigationMesh> (newNavMesh, constantID); newNavMesh = IDToField <NavigationMesh> (newNavMesh, constantID, false); } } else if (changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles) { holeAction = (InvAction)EditorGUILayout.EnumPopup("Add or remove hole:", holeAction); string _label = "Hole to add:"; if (holeAction == InvAction.Remove) { _label = "Hole to remove:"; } parameterID = Action.ChooseParameterGUI(_label, parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; hole = null; } else { hole = (PolygonCollider2D)EditorGUILayout.ObjectField(_label, hole, typeof(PolygonCollider2D), true); constantID = FieldToID <PolygonCollider2D> (hole, constantID); hole = IDToField <PolygonCollider2D> (hole, constantID, false); } if (holeAction == InvAction.Replace) { replaceParameterID = Action.ChooseParameterGUI("Hole to remove:", parameters, replaceParameterID, ParameterType.GameObject); if (replaceParameterID >= 0) { replaceConstantID = 0; replaceHole = null; } else { replaceHole = (PolygonCollider2D)EditorGUILayout.ObjectField("Hole to remove:", replaceHole, typeof(PolygonCollider2D), true); replaceConstantID = FieldToID <PolygonCollider2D> (replaceHole, replaceConstantID); replaceHole = IDToField <PolygonCollider2D> (replaceHole, replaceConstantID, false); } } } } else { EditorGUILayout.HelpBox("This action is not compatible with the Unity Navigation pathfinding method, as set in the Scene Manager.", MessageType.Warning); } } else if (sceneSetting == SceneSetting.DefaultPlayerStart) { parameterID = Action.ChooseParameterGUI("New default PlayerStart:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; playerStart = null; } else { playerStart = (PlayerStart)EditorGUILayout.ObjectField("New default PlayerStart:", playerStart, typeof(PlayerStart), true); constantID = FieldToID <PlayerStart> (playerStart, constantID); playerStart = IDToField <PlayerStart> (playerStart, constantID, false); } } else if (sceneSetting == SceneSetting.SortingMap) { parameterID = Action.ChooseParameterGUI("New SortingMap:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; sortingMap = null; } else { sortingMap = (SortingMap)EditorGUILayout.ObjectField("New SortingMap:", sortingMap, typeof(SortingMap), true); constantID = FieldToID <SortingMap> (sortingMap, constantID); sortingMap = IDToField <SortingMap> (sortingMap, constantID, false); } } else if (sceneSetting == SceneSetting.TintMap) { parameterID = Action.ChooseParameterGUI("New TintMap:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; tintMap = null; } else { tintMap = (TintMap)EditorGUILayout.ObjectField("New TintMap:", tintMap, typeof(TintMap), true); constantID = FieldToID <TintMap> (tintMap, constantID); tintMap = IDToField <TintMap> (tintMap, constantID, false); } } else if (sceneSetting == SceneSetting.OnLoadCutscene) { parameterID = Action.ChooseParameterGUI("New OnLoad cutscene:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; cutscene = null; } else { cutscene = (Cutscene)EditorGUILayout.ObjectField("New OnLoad custscne:", cutscene, typeof(Cutscene), true); constantID = FieldToID <Cutscene> (cutscene, constantID); cutscene = IDToField <Cutscene> (cutscene, constantID, false); } } else if (sceneSetting == SceneSetting.OnStartCutscene) { parameterID = Action.ChooseParameterGUI("New OnStart cutscene:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; cutscene = null; } else { cutscene = (Cutscene)EditorGUILayout.ObjectField("New OnStart cutscene:", cutscene, typeof(Cutscene), true); constantID = FieldToID <Cutscene> (cutscene, constantID); cutscene = IDToField <Cutscene> (cutscene, constantID, false); } } AfterRunningOption(); }
/** * <summary>Updates its own variables from a PlayerData class.</summary> * <param name = "playerData">The PlayerData class to load from</param> * <param name = "justAnimationData">If True, then only animation data (and sound) changes will be loaded, as opposed to position, rotaion, etc</param> */ public void LoadPlayerData(PlayerData playerData, bool justAnimationData = false) { if (!justAnimationData) { Teleport(new Vector3(playerData.playerLocX, playerData.playerLocY, playerData.playerLocZ)); SetRotation(playerData.playerRotY); SetMoveDirectionAsForward(); } walkSpeedScale = playerData.playerWalkSpeed; runSpeedScale = playerData.playerRunSpeed; // Animation clips if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity) { idleAnimSprite = playerData.playerIdleAnim; walkAnimSprite = playerData.playerWalkAnim; talkAnimSprite = playerData.playerTalkAnim; runAnimSprite = playerData.playerRunAnim; } else if (animationEngine == AnimationEngine.Legacy) { idleAnim = AssetLoader.RetrieveAsset <AnimationClip> (idleAnim, playerData.playerIdleAnim); walkAnim = AssetLoader.RetrieveAsset <AnimationClip> (walkAnim, playerData.playerWalkAnim); talkAnim = AssetLoader.RetrieveAsset <AnimationClip> (talkAnim, playerData.playerTalkAnim); runAnim = AssetLoader.RetrieveAsset <AnimationClip> (runAnim, playerData.playerRunAnim); } else if (animationEngine == AnimationEngine.Mecanim) { moveSpeedParameter = playerData.playerWalkAnim; talkParameter = playerData.playerTalkAnim; turnParameter = playerData.playerRunAnim; } // Sound walkSound = AssetLoader.RetrieveAsset(walkSound, playerData.playerWalkSound); runSound = AssetLoader.RetrieveAsset(runSound, playerData.playerRunSound); // Portrait graphic portraitIcon.texture = AssetLoader.RetrieveAsset(portraitIcon.texture, playerData.playerPortraitGraphic); // Speech label if (playerData.playerSpeechLabel != "") { SetName(playerData.playerSpeechLabel, playerData.playerDisplayLineID); } speechLabel = playerData.playerSpeechLabel; // Rendering lockDirection = playerData.playerLockDirection; lockScale = playerData.playerLockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting; } else { ReleaseSorting(); } if (playerData.playerLockDirection) { spriteDirection = playerData.playerSpriteDirection; } if (playerData.playerLockScale) { spriteScale = playerData.playerSpriteScale; } if (playerData.playerLockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder; GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer; } } if (!justAnimationData) { // Active path Halt(); ForceIdle(); if (playerData.playerPathData != null && playerData.playerPathData != "" && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, playerData.playerPathData); SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode, playerData.playerPathAffectY); isRunning = playerData.playerIsRunning; lockedPath = false; } else if (playerData.playerActivePath != 0) { Paths savedPath = Serializer.returnComponent <Paths> (playerData.playerActivePath); if (savedPath) { lockedPath = playerData.playerLockedPath; if (lockedPath) { SetLockedPath(savedPath); } else { SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode); } } } // Previous path if (playerData.lastPlayerActivePath != 0) { Paths savedPath = Serializer.returnComponent <Paths> (playerData.lastPlayerActivePath); if (savedPath) { SetLastPath(savedPath, playerData.lastPlayerTargetNode, playerData.lastPlayerPrevNode); } } // Head target lockHotspotHeadTurning = playerData.playerLockHotspotHeadTurning; if (playerData.isHeadTurning) { ConstantID _headTargetID = Serializer.returnComponent <ConstantID> (playerData.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(playerData.headTargetX, playerData.headTargetY, playerData.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } ignoreGravity = playerData.playerIgnoreGravity; if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = Serializer.returnComponent <SortingMap> (playerData.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = playerData.followSortingMap; if (!playerData.followSortingMap) { followSortingMap.SetSortingMap(customSortingMap); } } } } ignoreGravity = playerData.playerIgnoreGravity; }
/** * <summary>Unregisters a SortingMap, so that it is no longer updated</summary> * <param name = "_object">The SortingMap to unregister</param> */ public void Unregister(SortingMap _object) { sortingMaps.Remove(_object); }
/** * <summary>Registers a SortingMap, so that it can be updated</summary> * <param name = "_object">The SortingMap to register</param> */ public void Register(SortingMap _object) { sortingMaps.Add(_object); }
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 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 (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.IsTopDown()) { } else if (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.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); }
/** * <summary>Updates its own variables from a NPCData class.</summary> * <param name = "data">The NPCData class to load from</param> */ public void LoadData(NPCData data) { charState = (data.inCustomCharState) ? CharState.Custom : CharState.Idle; EndPath(); if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity) { idleAnimSprite = data.idleAnim; walkAnimSprite = data.walkAnim; talkAnimSprite = data.talkAnim; runAnimSprite = data.runAnim; } else if (animationEngine == AnimationEngine.Legacy) { idleAnim = AssetLoader.RetrieveAsset(idleAnim, data.idleAnim); walkAnim = AssetLoader.RetrieveAsset(walkAnim, data.walkAnim); runAnim = AssetLoader.RetrieveAsset(runAnim, data.talkAnim); talkAnim = AssetLoader.RetrieveAsset(talkAnim, data.runAnim); } else if (animationEngine == AnimationEngine.Mecanim) { moveSpeedParameter = data.walkAnim; talkParameter = data.talkAnim; turnParameter = data.runAnim;; } walkSound = AssetLoader.RetrieveAsset(walkSound, data.walkSound); runSound = AssetLoader.RetrieveAsset(runSound, data.runSound); if (data.speechLabel != "") { SetName(data.speechLabel, data.displayLineID); } portraitIcon.texture = AssetLoader.RetrieveAsset(portraitIcon.texture, data.portraitGraphic); portraitIcon.ClearSprites(); portraitIcon.ClearCache(); walkSpeedScale = data.walkSpeed; runSpeedScale = data.runSpeed; // Rendering lockDirection = data.lockDirection; lockScale = data.lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else { ReleaseSorting(); } if (data.lockDirection) { spriteDirection = data.spriteDirection; } if (data.lockScale) { spriteScale = data.spriteScale; } if (data.lockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = data.sortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = data.sortingOrder; GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } } AC.Char charToFollow = null; if (data.followTargetID != 0) { RememberNPC followNPC = Serializer.returnComponent <RememberNPC> (data.followTargetID); if (followNPC.GetComponent <AC.Char>()) { charToFollow = followNPC.GetComponent <AC.Char>(); } } if (charToFollow != null || (data.followTargetIsPlayer && KickStarter.player != null)) { FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection); } else { StopFollowing(); } Halt(); if (data.pathData != null && data.pathData != "" && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, data.pathData); SetPath(savedPath, data.targetNode, data.prevNode, data.pathAffectY); isRunning = data.isRunning; } else if (data.pathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.pathID); if (pathObject != null) { SetPath(pathObject, data.targetNode, data.prevNode); } else { ACDebug.LogWarning("Trying to assign a path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } if (data.lastPathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.lastPathID); if (pathObject != null) { SetLastPath(pathObject, data.lastTargetNode, data.lastPrevNode); } else { ACDebug.LogWarning("Trying to assign the previous path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } // Head target if (data.isHeadTurning) { ConstantID _headTargetID = Serializer.returnComponent <ConstantID> (data.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(data.headTargetX, data.headTargetY, data.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = Serializer.returnComponent <SortingMap> (data.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = data.followSortingMap; if (!data.followSortingMap && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } }
/** * <summary>Creates a new instance of the 'Character: Render' Action, set to update a sprite-based character</summary> * <param name = "characterToAffect">The character to affect</param> * <param name = "sortingLock">Whether or not to lock the character's sorting</param> * <param name = "newSortingLayer">The new sorting layer, if locking the character's sorting</param> * <param name = "scaleLock">Whether of not to lock the character's scale</param> * <param name = "newScale">The new scale, as a percentage, if locking the character's scale</param> * <param name = "directionLock">Whether or not to lock the character's facing direction</parm> * <param name = "newDirection">The new direction, if locking the character's facing direction</param> * <param name = "sortingMapLock">Whether or not to lock the character's current SortingMap</parm> * <param name = "newSortingMap">The new SortingMap, if locking the character's facing direction</param> * <returns>The generated Action</returns> */ public static ActionCharRender CreateNew_Sprites(AC.Char characterToAffect, RenderLock sortingLock, string newSortingLayer, RenderLock scaleLock, int newScale, RenderLock directionLock, CharDirection newDirection, RenderLock sortingMapLock, SortingMap newSortingMap) { ActionCharRender newAction = (ActionCharRender)CreateInstance <ActionCharRender>(); newAction._char = characterToAffect; newAction.renderLock_sorting = sortingLock; newAction.mapType = SortingMapType.SortingLayer; newAction.sortingLayer = newSortingLayer; newAction.renderLock_scale = scaleLock; newAction.scale = newScale; newAction.renderLock_direction = directionLock; newAction.direction = newDirection; newAction.renderLock_sortingMap = sortingMapLock; newAction.sortingMap = newSortingMap; return(newAction); }
public void SetSortingMap(SortingMap _sortingMap) { if (_sortingMap == null) { followSortingMap = false; customSortingMap = null; } else if (KickStarter.sceneSettings.sortingMap == _sortingMap) { followSortingMap = true; } else { followSortingMap = false; customSortingMap = _sortingMap; } KickStarter.sceneSettings.UpdateAllSortingMaps (); }
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.originScale = EditorGUILayout.IntField("Start scale (%):", _target.originScale); } 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) { 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 (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.IsTopDown()) { } else if (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.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) { if (GUILayout.Button("Interpolate in-between scales")) { Undo.RecordObject(_target, "Interpolate scales"); _target.SetInBetweenScales(); EditorUtility.SetDirty(_target); } } if (GUI.changed) { EditorUtility.SetDirty(_target); } }
public override void ShowGUI(List<ActionParameter> parameters) { if (KickStarter.sceneSettings == null) { return; } sceneSetting = (SceneSetting) EditorGUILayout.EnumPopup ("Scene setting to change:", sceneSetting); if (sceneSetting == SceneSetting.DefaultNavMesh) { if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.meshCollider || KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider) { if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.PolygonCollider) { changeNavMeshMethod = (ChangeNavMeshMethod) EditorGUILayout.EnumPopup ("Change NavMesh method:", changeNavMeshMethod); } if (KickStarter.sceneSettings.navigationMethod == AC_NavigationMethod.meshCollider || changeNavMeshMethod == ChangeNavMeshMethod.ChangeNavMesh) { parameterID = Action.ChooseParameterGUI ("New NavMesh:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; newNavMesh = null; } else { newNavMesh = (NavigationMesh) EditorGUILayout.ObjectField ("New NavMesh:", newNavMesh, typeof (NavigationMesh), true); constantID = FieldToID <NavigationMesh> (newNavMesh, constantID); newNavMesh = IDToField <NavigationMesh> (newNavMesh, constantID, false); } } else if (changeNavMeshMethod == ChangeNavMeshMethod.ChangeNumberOfHoles) { holeAction = (InvAction) EditorGUILayout.EnumPopup ("Add or remove hole:", holeAction); string _label = "Hole to add:"; if (holeAction == InvAction.Remove) { _label = "Hole to remove:"; } parameterID = Action.ChooseParameterGUI (_label, parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; hole = null; } else { hole = (PolygonCollider2D) EditorGUILayout.ObjectField (_label, hole, typeof (PolygonCollider2D), true); constantID = FieldToID <PolygonCollider2D> (hole, constantID); hole = IDToField <PolygonCollider2D> (hole, constantID, false); } if (holeAction == InvAction.Replace) { replaceParameterID = Action.ChooseParameterGUI ("Hole to remove:", parameters, replaceParameterID, ParameterType.GameObject); if (replaceParameterID >= 0) { replaceConstantID = 0; replaceHole = null; } else { replaceHole = (PolygonCollider2D) EditorGUILayout.ObjectField ("Hole to remove:", replaceHole, typeof (PolygonCollider2D), true); replaceConstantID = FieldToID <PolygonCollider2D> (replaceHole, replaceConstantID); replaceHole = IDToField <PolygonCollider2D> (replaceHole, replaceConstantID, false); } } } } else { EditorGUILayout.HelpBox ("This action is not compatible with the Unity Navigation pathfinding method, as set in the Scene Manager.", MessageType.Warning); } } else if (sceneSetting == SceneSetting.DefaultPlayerStart) { parameterID = Action.ChooseParameterGUI ("New default PlayerStart:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; playerStart = null; } else { playerStart = (PlayerStart) EditorGUILayout.ObjectField ("New default PlayerStart:", playerStart, typeof (PlayerStart), true); constantID = FieldToID <PlayerStart> (playerStart, constantID); playerStart = IDToField <PlayerStart> (playerStart, constantID, false); } } else if (sceneSetting == SceneSetting.SortingMap) { parameterID = Action.ChooseParameterGUI ("New SortingMap:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; sortingMap = null; } else { sortingMap = (SortingMap) EditorGUILayout.ObjectField ("New SortingMap:", sortingMap, typeof (SortingMap), true); constantID = FieldToID <SortingMap> (sortingMap, constantID); sortingMap = IDToField <SortingMap> (sortingMap, constantID, false); } } else if (sceneSetting == SceneSetting.TintMap) { parameterID = Action.ChooseParameterGUI ("New TintMap:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; tintMap = null; } else { tintMap = (TintMap) EditorGUILayout.ObjectField ("New TintMap:", tintMap, typeof (TintMap), true); constantID = FieldToID <TintMap> (tintMap, constantID); tintMap = IDToField <TintMap> (tintMap, constantID, false); } } else if (sceneSetting == SceneSetting.OnLoadCutscene) { parameterID = Action.ChooseParameterGUI ("New OnLoad cutscene:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; cutscene = null; } else { cutscene = (Cutscene) EditorGUILayout.ObjectField ("New OnLoad custscne:", cutscene, typeof (Cutscene), true); constantID = FieldToID <Cutscene> (cutscene, constantID); cutscene = IDToField <Cutscene> (cutscene, constantID, false); } } else if (sceneSetting == SceneSetting.OnStartCutscene) { parameterID = Action.ChooseParameterGUI ("New OnStart cutscene:", parameters, parameterID, ParameterType.GameObject); if (parameterID >= 0) { constantID = 0; cutscene = null; } else { cutscene = (Cutscene) EditorGUILayout.ObjectField ("New OnStart cutscene:", cutscene, typeof (Cutscene), true); constantID = FieldToID <Cutscene> (cutscene, constantID); cutscene = IDToField <Cutscene> (cutscene, constantID, false); } } AfterRunningOption (); }
public void ShowGUI() { GUILayout.Label("Basic structure", EditorStyles.boldLabel); if (GUILayout.Button("Organise room objects")) { InitialiseObjects(); } if (AdvGame.GetReferences().settingsManager == null) { EditorGUILayout.HelpBox("No Settings Manager defined - cannot display full Editor without it!", MessageType.Warning); return; } if (KickStarter.sceneSettings == null) { return; } SettingsManager settingsManager = AdvGame.GetReferences().settingsManager; EditorGUILayout.BeginHorizontal(); newFolderName = EditorGUILayout.TextField(newFolderName); if (GUILayout.Button("Create new folder", buttonWidth)) { if (newFolderName != "") { GameObject newFolder = new GameObject(); if (!newFolderName.StartsWith("_")) { newFolder.name = "_" + newFolderName; } else { newFolder.name = newFolderName; } Undo.RegisterCreatedObjectUndo(newFolder, "Create folder " + newFolder.name); if (Selection.activeGameObject) { newFolder.transform.parent = Selection.activeGameObject.transform; } Selection.activeObject = newFolder; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.Label("Scene settings", EditorStyles.boldLabel); KickStarter.sceneSettings.navigationMethod = (AC_NavigationMethod)EditorGUILayout.EnumPopup("Pathfinding method:", KickStarter.sceneSettings.navigationMethod); KickStarter.navigationManager.ResetEngine(); if (KickStarter.navigationManager.navigationEngine != null) { KickStarter.navigationManager.navigationEngine.SceneSettingsGUI(); } if (settingsManager.IsUnity2D() && KickStarter.sceneSettings.navigationMethod != AC_NavigationMethod.PolygonCollider) { EditorGUILayout.HelpBox("This pathfinding method is not compatible with 'Unity 2D'.", MessageType.Warning); } EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.defaultPlayerStart = (PlayerStart)EditorGUILayout.ObjectField("Default PlayerStart:", KickStarter.sceneSettings.defaultPlayerStart, typeof(PlayerStart), true); if (KickStarter.sceneSettings.defaultPlayerStart == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { PlayerStart newPlayerStart = AddPrefab("Navigation", "PlayerStart", true, false, true).GetComponent <PlayerStart>(); newPlayerStart.gameObject.name = "Default PlayerStart"; KickStarter.sceneSettings.defaultPlayerStart = newPlayerStart; } } EditorGUILayout.EndHorizontal(); if (KickStarter.sceneSettings.defaultPlayerStart) { EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = (_Camera)EditorGUILayout.ObjectField("Default Camera:", KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart, typeof(_Camera), true); if (KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { if (settingsManager == null || settingsManager.cameraPerspective == CameraPerspective.ThreeD) { GameCamera newCamera = AddPrefab("Camera", "GameCamera", true, false, true).GetComponent <GameCamera>(); newCamera.gameObject.name = "NavCam 1"; KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = newCamera; } else if (settingsManager.cameraPerspective == CameraPerspective.TwoD) { GameCamera2D newCamera = AddPrefab("Camera", "GameCamera2D", true, false, true).GetComponent <GameCamera2D>(); newCamera.gameObject.name = "NavCam 1"; KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = newCamera; } else if (settingsManager.cameraPerspective == CameraPerspective.TwoPointFiveD) { GameCamera25D newCamera = AddPrefab("Camera", "GameCamera2.5D", true, false, true).GetComponent <GameCamera25D>(); newCamera.gameObject.name = "NavCam 1"; KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = newCamera; } } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.sortingMap = (SortingMap)EditorGUILayout.ObjectField("Default Sorting map:", KickStarter.sceneSettings.sortingMap, typeof(SortingMap), true); if (KickStarter.sceneSettings.sortingMap == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { SortingMap newSortingMap = AddPrefab("Navigation", "SortingMap", true, false, true).GetComponent <SortingMap>(); newSortingMap.gameObject.name = "Default SortingMap"; KickStarter.sceneSettings.sortingMap = newSortingMap; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.defaultSound = (Sound)EditorGUILayout.ObjectField("Default Sound prefab:", KickStarter.sceneSettings.defaultSound, typeof(Sound), true); if (KickStarter.sceneSettings.defaultSound == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Sound newSound = AddPrefab("Logic", "Sound", true, false, true).GetComponent <Sound>(); newSound.gameObject.name = "Default Sound"; KickStarter.sceneSettings.defaultSound = newSound; newSound.playWhilePaused = true; } } EditorGUILayout.EndHorizontal(); GUILayout.Label("Scene cutscenes", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.cutsceneOnStart = (Cutscene)EditorGUILayout.ObjectField("On start:", KickStarter.sceneSettings.cutsceneOnStart, typeof(Cutscene), true); if (KickStarter.sceneSettings.cutsceneOnStart == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Cutscene newCutscene = AddPrefab("Logic", "Cutscene", true, false, true).GetComponent <Cutscene>(); newCutscene.gameObject.name = "OnStart"; KickStarter.sceneSettings.cutsceneOnStart = newCutscene; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.cutsceneOnLoad = (Cutscene)EditorGUILayout.ObjectField("On load:", KickStarter.sceneSettings.cutsceneOnLoad, typeof(Cutscene), true); if (KickStarter.sceneSettings.cutsceneOnLoad == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Cutscene newCutscene = AddPrefab("Logic", "Cutscene", true, false, true).GetComponent <Cutscene>(); newCutscene.gameObject.name = "OnLoad"; KickStarter.sceneSettings.cutsceneOnLoad = newCutscene; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.cutsceneOnVarChange = (Cutscene)EditorGUILayout.ObjectField("On variable change:", KickStarter.sceneSettings.cutsceneOnVarChange, typeof(Cutscene), true); if (KickStarter.sceneSettings.cutsceneOnVarChange == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Cutscene newCutscene = AddPrefab("Logic", "Cutscene", true, false, true).GetComponent <Cutscene>(); newCutscene.gameObject.name = "OnVarChange"; KickStarter.sceneSettings.cutsceneOnVarChange = newCutscene; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.Label("Visibility", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); GUILayout.Label("Triggers", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { SetTriggerVisibility(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { SetTriggerVisibility(false); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Collision", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { SetCollisionVisiblity(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { SetCollisionVisiblity(false); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Hotspots", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { SetHotspotVisibility(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { SetHotspotVisibility(false); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("NavMesh", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { KickStarter.navigationManager.navigationEngine.SetVisibility(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { KickStarter.navigationManager.navigationEngine.SetVisibility(false); } GUILayout.EndHorizontal(); ListPrefabs(); if (GUI.changed) { EditorUtility.SetDirty(KickStarter.sceneSettings); EditorUtility.SetDirty(KickStarter.playerMovement); if (KickStarter.sceneSettings.defaultPlayerStart) { EditorUtility.SetDirty(KickStarter.sceneSettings.defaultPlayerStart); } } }
/** * Tells the scene's SortingMap to account for this particular instance of FollowSortingMap. */ public void UpdateSortingMap() { if (KickStarter.sceneSettings != null && KickStarter.sceneSettings.sortingMap != null) { sortingMap = KickStarter.sceneSettings.sortingMap; SetOriginalDepth (); sortingMap.UpdateSimilarFollowers (this); } else { Debug.Log (this.gameObject.name + " cannot find Sorting Map to follow!"); } }
/** * <summary>Updates its own variables from a PlayerData class.</summary> * <param name = "playerData">The PlayerData class to load from</param> */ public void LoadData(PlayerData playerData) { upMovementLocked = playerData.playerUpLock; downMovementLocked = playerData.playerDownLock; leftMovementLocked = playerData.playerLeftlock; rightMovementLocked = playerData.playerRightLock; runningLocked = (PlayerMoveLock)playerData.playerRunLock; freeAimLocked = playerData.playerFreeAimLock; charState = (playerData.inCustomCharState) ? CharState.Custom : CharState.Idle; playerData.UpdateFromTempPosition(this); Teleport(new Vector3(playerData.playerLocX, playerData.playerLocY, playerData.playerLocZ)); SetRotation(playerData.playerRotY); SetMoveDirectionAsForward(); walkSpeedScale = playerData.playerWalkSpeed; runSpeedScale = playerData.playerRunSpeed; // Animation clips GetAnimEngine().LoadPlayerData(playerData, this); // Sound walkSound = AssetLoader.RetrieveAsset(walkSound, playerData.playerWalkSound); runSound = AssetLoader.RetrieveAsset(runSound, playerData.playerRunSound); // Portrait graphic portraitIcon.ReplaceTexture(AssetLoader.RetrieveAsset(portraitIcon.texture, playerData.playerPortraitGraphic)); // Speech label SetName(playerData.playerSpeechLabel, playerData.playerDisplayLineID); // Rendering lockDirection = playerData.playerLockDirection; lockScale = playerData.playerLockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting; } else { ReleaseSorting(); } if (playerData.playerLockDirection) { spriteDirection = playerData.playerSpriteDirection; UpdateFrameFlipping(true); } if (playerData.playerLockScale) { spriteScale = playerData.playerSpriteScale; } if (playerData.playerLockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder; GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer; } } // Inactive following AC.Char charToFollow = null; if (playerData.followTargetID != 0) { RememberNPC followNPC = ConstantID.GetComponent <RememberNPC> (playerData.followTargetID); if (followNPC.GetComponent <AC.Char> ()) { charToFollow = followNPC.GetComponent <AC.Char> (); } } if (charToFollow != null || (playerData.followTargetIsPlayer && KickStarter.player != null)) { FollowAssign(charToFollow, playerData.followTargetIsPlayer, playerData.followFrequency, playerData.followDistance, playerData.followDistanceMax, playerData.followFaceWhenIdle, playerData.followRandomDirection); } else { StopFollowing(); } // Active path Halt(); ForceIdle(); if (!string.IsNullOrEmpty(playerData.playerPathData) && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, playerData.playerPathData); SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode, playerData.playerPathAffectY); isRunning = playerData.playerIsRunning; lockedPath = false; } else if (playerData.playerActivePath != 0) { Paths savedPath = ConstantID.GetComponent <Paths> (playerData.playerActivePath); if (savedPath) { lockedPath = playerData.playerLockedPath; if (lockedPath) { SetLockedPath(savedPath); } else { SetPath(savedPath, playerData.playerTargetNode, playerData.playerPrevNode); } } else { Halt(); ForceIdle(); } } else { Halt(); ForceIdle(); } // Previous path if (playerData.lastPlayerActivePath != 0) { Paths savedPath = ConstantID.GetComponent <Paths> (playerData.lastPlayerActivePath); if (savedPath) { SetLastPath(savedPath, playerData.lastPlayerTargetNode, playerData.lastPlayerPrevNode); } } // Head target lockHotspotHeadTurning = playerData.playerLockHotspotHeadTurning; if (playerData.isHeadTurning) { ConstantID _headTargetID = ConstantID.GetComponent <ConstantID> (playerData.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(playerData.headTargetX, playerData.headTargetY, playerData.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } ignoreGravity = playerData.playerIgnoreGravity; if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = ConstantID.GetComponent <SortingMap> (playerData.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = playerData.followSortingMap; if (!playerData.followSortingMap && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } ignoreGravity = playerData.playerIgnoreGravity; if (GetAnimEngine() != null && GetAnimEngine().IKEnabled) { LeftHandIKController.LoadData(playerData.leftHandIKState); RightHandIKController.LoadData(playerData.rightHandIKState); } _spriteDirectionData.LoadData(playerData.spriteDirectionData); // Remember scripts if (!IsLocalPlayer()) { KickStarter.levelStorage.LoadPlayerData(this, playerData); } }