private void Finish() { if (!references) { GetReferences(); } if (!references) { return; } string managerPath = gameName + "/Managers"; try { System.IO.Directory.CreateDirectory(Application.dataPath + "/" + managerPath); } catch (System.Exception e) { ACDebug.LogError("Wizard aborted - Could not create directory: " + Application.dataPath + "/" + managerPath + ". Please make sure the Assets direcrory is writeable, and that the intended game name contains no special characters."); Debug.LogException(e, this); pageNumber--; return; } try { ScriptableObject t = CustomAssetUtility.CreateAsset <SceneManager> ("SceneManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/SceneManager.asset", gameName + "_SceneManager"); references.sceneManager = (SceneManager)t; t = CustomAssetUtility.CreateAsset <SettingsManager> ("SettingsManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/SettingsManager.asset", gameName + "_SettingsManager"); references.settingsManager = (SettingsManager)t; references.settingsManager.saveFileName = gameName; references.settingsManager.cameraPerspective = cameraPerspective; references.settingsManager.movingTurning = movingTurning; references.settingsManager.movementMethod = movementMethod; references.settingsManager.inputMethod = inputMethod; references.settingsManager.interactionMethod = interactionMethod; references.settingsManager.hotspotDetection = hotspotDetection; if (cameraPerspective == CameraPerspective.TwoPointFiveD) { references.settingsManager.forceAspectRatio = true; } t = CustomAssetUtility.CreateAsset <ActionsManager> ("ActionsManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/ActionsManager.asset", gameName + "_ActionsManager"); references.actionsManager = (ActionsManager)t; AdventureCreator.RefreshActions(); ActionsManager defaultActionsManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_ActionsManager.asset", typeof(ActionsManager)) as ActionsManager; if (defaultActionsManager != null) { references.actionsManager.defaultClass = defaultActionsManager.defaultClass; references.actionsManager.defaultClassName = defaultActionsManager.defaultClassName; } t = CustomAssetUtility.CreateAsset <VariablesManager> ("VariablesManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/VariablesManager.asset", gameName + "_VariablesManager"); references.variablesManager = (VariablesManager)t; t = CustomAssetUtility.CreateAsset <InventoryManager> ("InventoryManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/InventoryManager.asset", gameName + "_InventoryManager"); references.inventoryManager = (InventoryManager)t; t = CustomAssetUtility.CreateAsset <SpeechManager> ("SpeechManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/SpeechManager.asset", gameName + "_SpeechManager"); references.speechManager = (SpeechManager)t; references.speechManager.ClearLanguages(); t = CustomAssetUtility.CreateAsset <CursorManager> ("CursorManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/CursorManager.asset", gameName + "_CursorManager"); references.cursorManager = (CursorManager)t; t = CustomAssetUtility.CreateAsset <MenuManager> ("MenuManager", managerPath); AssetDatabase.RenameAsset("Assets/" + managerPath + "/MenuManager.asset", gameName + "_MenuManager"); references.menuManager = (MenuManager)t; CursorManager defaultCursorManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_CursorManager.asset", typeof(CursorManager)) as CursorManager; if (wizardMenu == WizardMenu.Blank) { if (defaultCursorManager != null) { CursorIcon useIcon = new CursorIcon(); useIcon.Copy(defaultCursorManager.cursorIcons[0]); references.cursorManager.cursorIcons.Add(useIcon); EditorUtility.SetDirty(references.cursorManager); } } else { if (defaultCursorManager != null) { foreach (CursorIcon defaultIcon in defaultCursorManager.cursorIcons) { CursorIcon newIcon = new CursorIcon(); newIcon.Copy(defaultIcon); references.cursorManager.cursorIcons.Add(newIcon); } CursorIconBase pointerIcon = new CursorIconBase(); pointerIcon.Copy(defaultCursorManager.pointerIcon); references.cursorManager.pointerIcon = pointerIcon; } else { ACDebug.LogWarning("Cannot find Default_CursorManager asset to copy from!"); } references.cursorManager.allowMainCursor = true; EditorUtility.SetDirty(references.cursorManager); MenuManager defaultMenuManager = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/Default/Default_MenuManager.asset", typeof(MenuManager)) as MenuManager; if (defaultMenuManager != null) { #if UNITY_EDITOR references.menuManager.drawOutlines = defaultMenuManager.drawOutlines; references.menuManager.drawInEditor = defaultMenuManager.drawInEditor; #endif references.menuManager.pauseTexture = defaultMenuManager.pauseTexture; if (wizardMenu != WizardMenu.Blank) { System.IO.Directory.CreateDirectory(Application.dataPath + "/" + gameName + "/UI"); } foreach (Menu defaultMenu in defaultMenuManager.menus) { Menu newMenu = ScriptableObject.CreateInstance <Menu>(); newMenu.Copy(defaultMenu, true, true); newMenu.Recalculate(); if (wizardMenu == WizardMenu.DefaultAC) { newMenu.menuSource = MenuSource.AdventureCreator; } else if (wizardMenu == WizardMenu.DefaultUnityUI) { newMenu.menuSource = MenuSource.UnityUiPrefab; } if (defaultMenu.canvas) { string newCanvasPath = "Assets/" + gameName + "/UI/" + defaultMenu.canvas.name + ".prefab"; GameObject canvasObInScene = (GameObject)PrefabUtility.InstantiatePrefab(defaultMenu.canvas.gameObject); PrefabUtility.DisconnectPrefabInstance(canvasObInScene); GameObject canvasObNewPrefab = PrefabUtility.CreatePrefab(newCanvasPath, canvasObInScene); newMenu.canvas = canvasObNewPrefab.GetComponent <Canvas>(); DestroyImmediate(canvasObInScene); newMenu.rectTransform = null; } foreach (MenuElement newElement in newMenu.elements) { AssetDatabase.AddObjectToAsset(newElement, references.menuManager); newElement.hideFlags = HideFlags.HideInHierarchy; } AssetDatabase.AddObjectToAsset(newMenu, references.menuManager); newMenu.hideFlags = HideFlags.HideInHierarchy; references.menuManager.menus.Add(newMenu); } EditorUtility.SetDirty(references.menuManager); } else { ACDebug.LogWarning("Cannot find Default_MenuManager asset to copy from!"); } } CreateManagerPackage(gameName); AssetDatabase.SaveAssets(); if (GameObject.FindObjectOfType <KickStarter>() == null) { bool initScene = EditorUtility.DisplayDialog("Organise scene?", "Process complete. Would you like to organise the scene objects to begin working? This can be done at any time within the Scene Manager.", "Yes", "No"); if (initScene) { references.sceneManager.InitialiseObjects(); } } } catch (System.Exception e) { ACDebug.LogWarning("Could not create Manager. Does the subdirectory " + managerPath + " exist?"); Debug.LogException(e, this); pageNumber--; } }
public override Vector3[] GetPointsArray(Vector3 _originPos, Vector3 _targetPos, AC.Char _char = null) { if (KickStarter.sceneSettings == null || KickStarter.sceneSettings.navMesh == null) { return(base.GetPointsArray(_originPos, _targetPos, _char)); } PolygonCollider2D[] polys = KickStarter.sceneSettings.navMesh.transform.GetComponents <PolygonCollider2D>(); if (polys == null || polys.Length == 0) { return(base.GetPointsArray(_originPos, _targetPos, _char)); } CalcSearchRadius(KickStarter.sceneSettings.navMesh); AddCharHoles(polys, _char, KickStarter.sceneSettings.navMesh); List <Vector3> pointsList3D = new List <Vector3> (); if (IsLineClear(_originPos, _targetPos)) { pointsList3D.Add(_targetPos); return(pointsList3D.ToArray()); } // Iterate through polys, find originPos neareset to _originPos int nearestOriginIndex = -1; float minDist = 0f; Vector2 originPos = Vector2.zero; Vector2 originPos2D = new Vector2(_originPos.x, _originPos.y); for (int i = 0; i < polys.Length; i++) { Vector2 testOriginPos = GetNearestToMesh(_originPos, polys[i], (polys.Length > 1)); float dist = (originPos2D - testOriginPos).sqrMagnitude; if (nearestOriginIndex < 0 || dist < minDist) { minDist = dist; originPos = testOriginPos; nearestOriginIndex = i; } } if (nearestOriginIndex < 0) { nearestOriginIndex = 0; } Vector2 targetPos = GetNearestToMesh(_targetPos, polys[nearestOriginIndex], (polys.Length > 1)); Vector2[] pointsList = allVertexData[nearestOriginIndex]; pointsList = AddEndsToList(pointsList, originPos, targetPos); bool useCache = (KickStarter.sceneSettings.navMesh.characterEvasion == CharacterEvasion.None) ? true : false; float[,] weight = pointsToWeight(pointsList, useCache, nearestOriginIndex); int[] precede = buildSpanningTree(0, 1, weight); if (precede == null) { ACDebug.LogWarning("Pathfinding error - cannot build spanning tree from " + originPos + " to " + targetPos); pointsList3D.Add(_targetPos); return(pointsList3D.ToArray()); } int[] _path = getShortestPath(0, 1, precede); foreach (int i in _path) { if (i < pointsList.Length) { Vector3 vertex = new Vector3(pointsList[i].x, pointsList[i].y, _originPos.z); pointsList3D.Insert(0, vertex); } } if (pointsList3D.Count > 1) { if (pointsList3D[0] == _originPos || (Mathf.Approximately(pointsList3D[0].x, originPos.x) && Mathf.Approximately(pointsList3D[0].y, originPos.y))) { pointsList3D.RemoveAt(0); // Remove origin point from start } } else if (pointsList3D.Count == 0) { ACDebug.LogError("Error attempting to pathfind to point " + _targetPos + " corrected = " + targetPos); pointsList3D.Add(originPos); } return(pointsList3D.ToArray()); }
override public float Run() { UpgradeSelf(); if (movePath && movePath.GetComponent <Char>()) { ACDebug.LogWarning("Can't follow a Path attached to a Character!"); return(0f); } if (!isRunning) { isRunning = true; if (charToMove) { if (charToMove is NPC) { NPC npcToMove = (NPC)charToMove; npcToMove.StopFollowing(); } if (movePathMethod == MovePathMethod.StopMoving) { charToMove.EndPath(); if (charToMove is Player && KickStarter.playerInteraction.GetHotspotMovingTo() != null) { KickStarter.playerInteraction.StopMovingToHotspot(); } if (stopInstantly) { charToMove.Halt(); } } else if (movePathMethod == MovePathMethod.MoveOnNewPath) { if (movePath) { if (doTeleport) { charToMove.Teleport(movePath.transform.position); // Set rotation if there is more than one node if (movePath.nodes.Count > 1) { charToMove.SetLookDirection(movePath.nodes[1] - movePath.nodes[0], true); } } if (willWait && movePath.pathType != AC_PathType.ForwardOnly) { willWait = false; ACDebug.LogWarning("Cannot pause while character moves along a non-forward only path, as this will create an indefinite cutscene."); } charToMove.SetPath(movePath); if (willWait) { return(defaultPauseTime); } } } else if (movePathMethod == MovePathMethod.ResumeLastSetPath) { charToMove.ResumeLastPath(); } } return(0f); } else { if (charToMove.GetPath() != movePath) { isRunning = false; return(0f); } else { return(defaultPauseTime); } } }
private void MoveCamera() { if (target == null) { return; } SetDesired(); if (!lockXLocAxis || !lockYLocAxis || !lockZLocAxis) { transform.position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * dampSpeed); } if (!lockFOV) { if (_camera.orthographic) { _camera.orthographicSize = Mathf.Lerp(_camera.orthographicSize, desiredFOV, Time.deltaTime * dampSpeed); } else { _camera.fieldOfView = Mathf.Lerp(_camera.fieldOfView, desiredFOV, Time.deltaTime * dampSpeed); } } float newPitch = transform.eulerAngles.x; if (!lockXRotAxis) { float t = transform.eulerAngles.x; if (t > 180f) { t -= 360f; } newPitch = Mathf.Lerp(t, desiredPitch, Time.deltaTime * dampSpeed); } if (!lockYRotAxis) { if (yRotConstrainType == CameraRotConstrainType.LookAtTarget) { if (!lockXRotAxis) { ACDebug.LogWarning(gameObject.name + " cannot obey Pitch rotation, since Spin rotation's 'Look At Target' is overriding."); } if (target) { Vector3 lookAtPos = target.position; lookAtPos.y += targetHeight; lookAtPos.x += targetXOffset; lookAtPos.z += targetZOffset; // Look at and dampen the rotation Vector3 lookDir = lookAtPos - transform.position; if (directionInfluence != 0f) { lookDir += target.forward * directionInfluence; } Quaternion rotation = Quaternion.LookRotation(lookDir); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * dampSpeed); } else if (!targetIsPlayer) { ACDebug.LogWarning(this.name + " has no target"); } } else { float thisSpin = transform.eulerAngles.y; if (desiredSpin > (thisSpin + 180f)) { desiredSpin -= 360f; } else if (thisSpin > (desiredSpin + 180f)) { thisSpin -= 360f; } float newSpin = Mathf.Lerp(thisSpin, desiredSpin, Time.deltaTime * dampSpeed); transform.eulerAngles = new Vector3(newPitch, newSpin, transform.eulerAngles.z); } } else { transform.eulerAngles = new Vector3(newPitch, transform.eulerAngles.y, transform.eulerAngles.z); } SetFocalPoint(); }
/** * <summary>Updates its own variables from a NPCData class.</summary> * <param name = "data">The NPCData class to load from</param> */ public void LoadData(NPCData data) { charState = (data.inCustomCharState) ? CharState.Custom : CharState.Idle; EndPath(); GetAnimEngine().LoadNPCData(data, this); walkSound = AssetLoader.RetrieveAsset(walkSound, data.walkSound); runSound = AssetLoader.RetrieveAsset(runSound, data.runSound); if (!string.IsNullOrEmpty(data.speechLabel)) { SetName(data.speechLabel, data.displayLineID); } portraitIcon.ReplaceTexture(AssetLoader.RetrieveAsset(portraitIcon.texture, data.portraitGraphic)); walkSpeedScale = data.walkSpeed; runSpeedScale = data.runSpeed; // Rendering lockDirection = data.lockDirection; lockScale = data.lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else { ReleaseSorting(); } if (data.lockDirection) { spriteDirection = data.spriteDirection; } if (data.lockScale) { spriteScale = data.spriteScale; } if (data.lockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = data.sortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = data.sortingOrder; GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } } AC.Char charToFollow = null; if (data.followTargetID != 0) { RememberNPC followNPC = Serializer.returnComponent <RememberNPC> (data.followTargetID); if (followNPC.GetComponent <AC.Char>()) { charToFollow = followNPC.GetComponent <AC.Char>(); } } if (charToFollow != null || (data.followTargetIsPlayer && KickStarter.player != null)) { FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection); } else { StopFollowing(); } Halt(); if (!string.IsNullOrEmpty(data.pathData) && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, data.pathData); SetPath(savedPath, data.targetNode, data.prevNode, data.pathAffectY); isRunning = data.isRunning; } else if (data.pathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.pathID); if (pathObject != null) { SetPath(pathObject, data.targetNode, data.prevNode); } else { ACDebug.LogWarning("Trying to assign a path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } if (data.lastPathID != 0) { Paths pathObject = Serializer.returnComponent <Paths> (data.lastPathID); if (pathObject != null) { SetLastPath(pathObject, data.lastTargetNode, data.lastPrevNode); } else { ACDebug.LogWarning("Trying to assign the previous path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } // Head target if (data.isHeadTurning) { ConstantID _headTargetID = Serializer.returnComponent <ConstantID> (data.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(data.headTargetX, data.headTargetY, data.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = Serializer.returnComponent <SortingMap> (data.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = data.followSortingMap; if (!data.followSortingMap && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } }
private void UnloadTransformData(List <TransformData> _transforms, SubScene subScene) { // Delete any objects (if told to) RememberTransform[] currentTransforms = UnityVersionHandler.GetOwnSceneComponents <RememberTransform> ((subScene != null) ? subScene.gameObject : null); foreach (RememberTransform transformOb in currentTransforms) { if (transformOb.saveScenePresence) { // Was object not saved? bool found = false; foreach (TransformData _transform in _transforms) { if (_transform.objectID == transformOb.constantID) { found = !_transform.savePrevented; } } if (!found) { // Can't find: delete KickStarter.sceneChanger.ScheduleForDeletion(transformOb.gameObject); } } } Object[] prefabAssets = Resources.LoadAll("SaveableData/Prefabs", typeof(GameObject)); if (prefabAssets == null || prefabAssets.Length == 0) { prefabAssets = Resources.LoadAll(string.Empty, typeof(GameObject)); } foreach (TransformData _transform in _transforms) { RememberTransform saveObject = Serializer.returnComponent <RememberTransform> (_transform.objectID, (subScene != null) ? subScene.gameObject : null); if (saveObject == null) { // Restore any deleted objects (if told to) if (_transform.bringBack && !_transform.savePrevented) { bool foundObject = false; foreach (Object prefabAsset in prefabAssets) { if (prefabAsset is GameObject) { GameObject prefabGameObject = (GameObject)prefabAsset; if (prefabGameObject.GetComponent <RememberTransform>()) { int prefabID = prefabGameObject.GetComponent <ConstantID>().constantID; if ((_transform.linkedPrefabID != 0 && prefabID == _transform.linkedPrefabID) || (_transform.linkedPrefabID == 0 && prefabID == _transform.objectID)) { GameObject newObject = (GameObject)Instantiate(prefabGameObject); newObject.name = prefabGameObject.name; saveObject = newObject.GetComponent <RememberTransform>(); foundObject = true; if (_transform.linkedPrefabID != 0 && prefabID == _transform.linkedPrefabID) { // Spawned object has wrong ID, re-assign it ConstantID[] idScripts = saveObject.GetComponents <ConstantID>(); foreach (ConstantID idScript in idScripts) { idScript.constantID = _transform.objectID; } } break; } } } } if (!foundObject) { ACDebug.LogWarning("Could not find Resources prefab with ID " + _transform.objectID + " - is it placed in a Resources folder?"); } } } if (saveObject != null) { saveObject.LoadTransformData(_transform); } } Resources.UnloadUnusedAssets(); KickStarter.stateHandler.IgnoreNavMeshCollisions(); }
private void UseInteractionGUI() { if (settingsManager && settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive) { if (_target.UpgradeSelf()) { UnityVersionHandler.CustomSetDirty(_target); } } EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Use interactions", EditorStyles.boldLabel); if (GUILayout.Button(addContent, EditorStyles.miniButtonRight, buttonWidth)) { Undo.RecordObject(_target, "Create use interaction"); _target.useButtons.Add(new Button()); _target.provideUseInteraction = true; } EditorGUILayout.EndHorizontal(); if (_target.provideUseInteraction) { if (cursorManager) { // Create a string List of the field's names (for the PopUp box) List <string> labelList = new List <string>(); int iconNumber; if (cursorManager.cursorIcons.Count > 0) { foreach (CursorIcon _icon in cursorManager.cursorIcons) { labelList.Add(_icon.label); } foreach (Button useButton in _target.useButtons) { iconNumber = -1; int j = 0; foreach (CursorIcon _icon in cursorManager.cursorIcons) { // If an item has been removed, make sure selected variable is still valid if (_icon.id == useButton.iconID) { iconNumber = j; break; } j++; } if (iconNumber == -1) { // Wasn't found (item was deleted?), so revert to zero iconNumber = 0; useButton.iconID = 0; } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); iconNumber = EditorGUILayout.Popup("Cursor / icon:", iconNumber, labelList.ToArray()); // Re-assign variableID based on PopUp selection useButton.iconID = cursorManager.cursorIcons[iconNumber].id; string iconLabel = cursorManager.cursorIcons[iconNumber].label; if (GUILayout.Button(Resource.CogIcon, EditorStyles.miniButtonRight, buttonWidth)) { SideMenu("Use", _target.useButtons.Count, _target.useButtons.IndexOf(useButton)); } EditorGUILayout.EndHorizontal(); ButtonGUI(useButton, iconLabel, _target.interactionSource); GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); } } else { EditorGUILayout.LabelField("No cursor icons exist!"); iconNumber = -1; for (int i = 0; i < _target.useButtons.Count; i++) { _target.useButtons[i].iconID = -1; } } } else { ACDebug.LogWarning("A CursorManager is required to run the game properly - please open the Adventure Creator wizard and set one."); } } EditorGUILayout.EndVertical(); }
override public ActionEnd End(List <AC.Action> actions) { int actualNumber = 0; if (saveCheck == SaveCheck.NumberOfSaveGames) { actualNumber = KickStarter.saveSystem.GetNumSaves(includeAutoSaves); } else if (saveCheck == SaveCheck.NumberOfProfiles) { actualNumber = KickStarter.options.GetNumProfiles(); } else if (saveCheck == SaveCheck.IsSlotEmpty) { return(ProcessResult(!SaveSystem.DoesSaveExist(intValue, intValue, !checkByElementIndex), actions)); } else if (saveCheck == SaveCheck.DoesProfileExist) { if (checkByElementIndex) { int i = Mathf.Max(0, intValue); bool includeActive = true; if (menuName != "" && elementName != "") { MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName); if (menuElement != null && menuElement is MenuProfilesList) { MenuProfilesList menuProfilesList = (MenuProfilesList)menuElement; if (menuProfilesList.fixedOption) { ACDebug.LogWarning("Cannot refer to ProfilesLst " + elementName + " in Menu " + menuName + ", as it lists a fixed profile ID only!"); return(ProcessResult(false, actions)); } i += menuProfilesList.GetOffset(); includeActive = menuProfilesList.showActive; } else { ACDebug.LogWarning("Cannot find ProfilesList element '" + elementName + "' in Menu '" + menuName + "'."); } } else { ACDebug.LogWarning("No ProfilesList element referenced when trying to delete profile slot " + i.ToString()); } bool result = KickStarter.options.DoesProfileExist(i, includeActive); return(ProcessResult(result, actions)); } else { // intValue is the profile ID bool result = Options.DoesProfileIDExist(intValue); return(ProcessResult(result, actions)); } } else if (saveCheck == SaveCheck.IsSavingPossible) { return(ProcessResult(!PlayerMenus.IsSavingLocked(this), actions)); } return(ProcessResult(CheckCondition(actualNumber), actions)); }
override public void ShowGUI(List <ActionParameter> parameters) { isPlayer = EditorGUILayout.Toggle("Is Player?", isPlayer); if (!isPlayer) { intCharParameterID = Action.ChooseParameterGUI("Character:", parameters, intCharParameterID, ParameterType.GameObject); if (intCharParameterID >= 0) { intCharConstantID = 0; interactionCharacter = null; } else { interactionCharacter = (Char)EditorGUILayout.ObjectField("Character:", interactionCharacter, typeof(Char), true); intCharConstantID = FieldToID(interactionCharacter, intCharConstantID); interactionCharacter = IDToField(interactionCharacter, intCharConstantID, false); } } handsUsed = (HandsUsed)EditorGUILayout.EnumPopup("Which hand(s) to send to interaction", handsUsed); objectType = (ObjectType)EditorGUILayout.EnumPopup("Object Type:", objectType); if (objectType == ObjectType.SceneObject) { objectParameterID = Action.ChooseParameterGUI("Interaction Object:", parameters, objectParameterID, ParameterType.GameObject); if (objectParameterID >= 0) { objectConstantID = 0; interactionObject = null; } else { interactionObject = (SimpleInteractionObject)EditorGUILayout.ObjectField("Interaction Object:", interactionObject, typeof(SimpleInteractionObject), true); objectConstantID = FieldToID(interactionObject, objectConstantID); interactionObject = IDToField(interactionObject, objectConstantID, false); } } else if (objectType == ObjectType.InventoryObject) { if (inventoryManager == null && AdvGame.GetReferences().inventoryManager) { inventoryManager = AdvGame.GetReferences().inventoryManager; } if (settingsManager == null && AdvGame.GetReferences().settingsManager) { settingsManager = AdvGame.GetReferences().settingsManager; } if (inventoryManager) { // Create a string List of the field's names (for the PopUp box) List <string> labelList = new List <string>(); int i = 0; if (parameterID == -1) { invNumber = -1; } if (inventoryManager.items.Count > 0) { foreach (InvItem _item in inventoryManager.items) { labelList.Add(_item.label); // If an item has been removed, make sure selected variable is still valid if (_item.id == invID) { invNumber = i; } i++; } if (invNumber == -1) { // Wasn't found (item was possibly deleted), so revert to zero ACDebug.LogWarning("Previously chosen item no longer exists!"); invNumber = 0; invID = 0; } // parameterID = Action.ChooseParameterGUI("Inventory item:", parameters, parameterID, ParameterType.InventoryItem); if (parameterID >= 0) { invNumber = Mathf.Min(invNumber, inventoryManager.items.Count - 1); invID = -1; } else { invNumber = EditorGUILayout.Popup("Inventory item:", invNumber, labelList.ToArray()); invID = inventoryManager.items[invNumber].id; } // } } } AfterRunningOption(); }
protected void AddCharHoles(PolygonCollider2D[] navPolys, AC.Char charToExclude, NavigationMesh navigationMesh) { if (navigationMesh.characterEvasion == CharacterEvasion.None) { return; } ResetHoles(KickStarter.sceneSettings.navMesh, false); for (int p = 0; p < navPolys.Length; p++) { if (p > 0) { return; } if (navPolys[p].transform.lossyScale != Vector3.one) { ACDebug.LogWarning("Cannot create evasion Polygons inside NavMesh '" + navPolys[p].gameObject.name + "' because it has a non-unit scale."); continue; } Vector2 navPosition = navPolys[p].transform.position; for (int c = 0; c < KickStarter.stateHandler.Characters.Count; c++) { AC.Char character = KickStarter.stateHandler.Characters[c]; CircleCollider2D circleCollider2D = character.GetComponent <CircleCollider2D>(); if (circleCollider2D != null && (character.charState == CharState.Idle || navigationMesh.characterEvasion == CharacterEvasion.AllCharacters) && (charToExclude == null || character != charToExclude) && Perform2DOverlapPoint(character.transform.position, NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0) { if (character.IsPlayer && KickStarter.settingsManager.movementMethod == MovementMethod.Direct) { // In this particular case, do not set Is Trigger } else { circleCollider2D.isTrigger = true; } List <Vector2> newPoints3D = new List <Vector2>(); Vector2 centrePoint = character.transform.TransformPoint(circleCollider2D.offset); float radius = circleCollider2D.radius * character.transform.localScale.x; float yScaler = navigationMesh.characterEvasionYScale; switch (navigationMesh.characterEvasionPoints) { case CharacterEvasionPoints.Four: newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler)); break; case CharacterEvasionPoints.Eight: newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler)); break; case CharacterEvasionPoints.Sixteen: newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nne.x * radius, dir_nne.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nee.x * radius, dir_nee.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_see.x * radius, dir_see.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sse.x * radius, dir_sse.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_ssw.x * radius, dir_ssw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sww.x * radius, dir_sww.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nww.x * radius, dir_nww.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nnw.x * radius, dir_nnw.y * radius * yScaler)); break; } navPolys[p].pathCount++; List <Vector2> newPoints = new List <Vector2>(); for (int i = 0; i < newPoints3D.Count; i++) { // Only add a point if it is on the NavMesh if (Perform2DOverlapPoint(newPoints3D[i], NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0) { newPoints.Add(newPoints3D[i] - navPosition); } else { Vector2 altPoint = GetLineIntersect(newPoints3D[i], centrePoint); if (altPoint != Vector2.zero) { newPoints.Add(altPoint - navPosition); } } } if (newPoints.Count > 1) { navPolys[p].SetPath(navPolys[p].pathCount - 1, newPoints.ToArray()); } } } RebuildVertexArray(navPolys[p].transform, navPolys[p], p); } }
/** * <summary>Transfers values from one list of parameters to another</summary> * <param name = "externalParameters">The parameters to update</param> * <param name = "fromParameters">The parameters to get the new values from</param> * <param name = "sendingToAsset">If True, the parameters to update are part of an asset file</param> * <param name = "_isAssetFile">If True, the parameters to get the new values from are part of an asset file</param> */ public static void BulkAssignParameterValues(List <ActionParameter> externalParameters, List <ActionParameter> fromParameters, bool sendingToAsset, bool _isAssetFile) { for (int i = 0; i < externalParameters.Count; i++) { if (fromParameters.Count > i) { switch (externalParameters[i].parameterType) { case ParameterType.String: externalParameters[i].SetValue(fromParameters[i].stringValue); break; case ParameterType.Float: externalParameters[i].SetValue(fromParameters[i].floatValue); break; case ParameterType.UnityObject: externalParameters[i].SetValue(fromParameters[i].objectValue); break; case ParameterType.Vector3: externalParameters[i].SetValue(fromParameters[i].vector3Value); break; case ParameterType.ComponentVariable: externalParameters[i].SetValue(fromParameters[i].variables, fromParameters[i].intValue); break; case ParameterType.GameObject: externalParameters[i].gameObjectParameterReferences = fromParameters[i].gameObjectParameterReferences; if (sendingToAsset) { if (_isAssetFile) { if (fromParameters[i].gameObject) { // Referencing a prefab if (fromParameters[i].gameObjectParameterReferences == GameObjectParameterReferences.ReferencePrefab) { externalParameters[i].SetValue(fromParameters[i].gameObject); } else if (fromParameters[i].gameObjectParameterReferences == GameObjectParameterReferences.ReferenceSceneInstance) { int idToSend = 0; if (fromParameters[i].gameObject && fromParameters[i].gameObject.GetComponent <ConstantID>()) { idToSend = fromParameters[i].gameObject.GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning(fromParameters[i].gameObject.name + " requires a ConstantID script component!", fromParameters[i].gameObject); } externalParameters[i].SetValue(fromParameters[i].gameObject, idToSend); } } else { externalParameters[i].SetValue(fromParameters[i].intValue); } } else if (fromParameters[i].gameObject) { int idToSend = 0; if (fromParameters[i].gameObject && fromParameters[i].gameObject.GetComponent <ConstantID>()) { idToSend = fromParameters[i].gameObject.GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning(fromParameters[i].gameObject.name + " requires a ConstantID script component!", fromParameters[i].gameObject); } externalParameters[i].SetValue(fromParameters[i].gameObject, idToSend); } else { externalParameters[i].SetValue(fromParameters[i].intValue); } } else if (fromParameters[i].gameObject) { externalParameters[i].SetValue(fromParameters[i].gameObject); } else { externalParameters[i].SetValue(fromParameters[i].intValue); } break; default: externalParameters[i].SetValue(fromParameters[i].intValue); break; } } } }
protected void DrawSharedElements(ActionList _target) { if (IsActionListPrefab(_target)) { EditorGUILayout.HelpBox("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info); return; } int numActions = 0; if (_target.source != ActionListSource.AssetFile) { numActions = _target.actions.Count; if (numActions < 1) { numActions = 1; AddAction(ActionsManager.GetDefaultAction(), -1, _target); } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (_target.source == ActionListSource.AssetFile) { GUI.enabled = false; } if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft)) { Undo.RecordObject(_target, "Expand actions"); foreach (AC.Action action in _target.actions) { action.isDisplayed = true; } } if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid)) { Undo.RecordObject(_target, "Collapse actions"); foreach (AC.Action action in _target.actions) { action.isDisplayed = false; } } GUI.enabled = true; if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid)) { if (_target.source == ActionListSource.AssetFile) { if (_target.assetFile != null) { ActionListEditorWindow.Init(_target.assetFile); } } else { ActionListEditorWindow.Init(_target); } } if (!Application.isPlaying) { GUI.enabled = false; } if (GUILayout.Button("Run now", EditorStyles.miniButtonRight)) { _target.Interact(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_target.source == ActionListSource.AssetFile) { return; } ActionListEditor.ResetList(_target); actionsManager = AdvGame.GetReferences().actionsManager; if (actionsManager == null) { EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning); OnEnable(); return; } if (!actionsManager.displayActionsInInspector) { EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info); return; } for (int i = 0; i < _target.actions.Count; i++) { if (_target.actions[i] == null) { ACDebug.LogWarning("An empty Action was found, and was deleted"); _target.actions.RemoveAt(i); numActions--; continue; } _target.actions[i].AssignParentList(_target); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); int typeIndex = actionsManager.GetActionTypeIndex(_target.actions[i]); string actionLabel = " (" + i.ToString() + ") " + actionsManager.GetActionTypeLabel(_target.actions[i], true); actionLabel = actionLabel.Replace("\r\n", ""); actionLabel = actionLabel.Replace("\n", ""); actionLabel = actionLabel.Replace("\r", ""); if (actionLabel.Length > 40) { actionLabel = actionLabel.Substring(0, 40) + "..)"; } _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel); if (!_target.actions[i].isEnabled) { EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f)); } if (GUILayout.Button("", CustomStyles.IconCog)) { ActionSideMenu(i); } _target.actions[i].isAssetFile = false; EditorGUILayout.EndHorizontal(); if (_target.actions[i].isBreakPoint) { EditorGUILayout.HelpBox("Break point", MessageType.None); } if (_target.actions[i].isDisplayed) { GUI.enabled = _target.actions[i].isEnabled; if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString())) { EditorGUILayout.HelpBox("This Action type is not listed in the Actions Manager", MessageType.Warning); } else { int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex); if (newTypeIndex >= 0) { // Rebuild constructor if Subclass and type string do not match ActionEnd _end = new ActionEnd(); _end.resultAction = _target.actions[i].endAction; _end.skipAction = _target.actions[i].skipAction; _end.linkedAsset = _target.actions[i].linkedAsset; _end.linkedCutscene = _target.actions[i].linkedCutscene; Undo.RecordObject(_target, "Change Action type"); _target.actions[i] = RebuildAction(_target.actions[i], newTypeIndex, _target, -1, _end); } if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0) { _target.actions[i].ShowGUI(_target.parameters); } else { _target.actions[i].ShowGUI(null); } } } if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel) { _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed); } GUI.enabled = true; EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } if (GUILayout.Button("Add new action")) { Undo.RecordObject(_target, "Create action"); numActions += 1; } _target = ActionListEditor.ResizeList(_target, numActions); }
private void ShowVarGUI (List<GVar> vars, List<ActionParameter> parameters, ParameterType parameterType) { // Create a string List of the field's names (for the PopUp box) List<string> labelList = new List<string>(); int i = 0; if (parameterID == -1) { variableNumber = -1; } if (vars.Count > 0) { foreach (GVar _var in vars) { labelList.Add (_var.label); // If a GlobalVar variable has been removed, make sure selected variable is still valid if (_var.id == variableID) { variableNumber = i; } i ++; } if (variableNumber == -1 && (parameters == null || parameters.Count == 0 || parameterID == -1)) { // Wasn't found (variable was deleted?), so revert to zero ACDebug.LogWarning ("Previously chosen variable no longer exists!"); variableNumber = 0; variableID = 0; } parameterID = Action.ChooseParameterGUI ("Variable:", parameters, parameterID, parameterType); if (parameterID >= 0) { //variableNumber = 0; variableNumber = Mathf.Min (variableNumber, vars.Count-1); variableID = -1; } else { variableNumber = EditorGUILayout.Popup ("Variable:", variableNumber, labelList.ToArray()); variableID = vars [variableNumber].id; } string label = "Statement: "; if (vars [variableNumber].type == VariableType.Boolean) { setVarMethodIntBool = (SetVarMethodIntBool) EditorGUILayout.EnumPopup ("New value is:", setVarMethodIntBool); label += "="; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.Boolean); if (setParameterID < 0) { boolValue = (BoolValue) EditorGUILayout.EnumPopup (label, boolValue); } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { ShowMecanimGUI (); } } if (vars [variableNumber].type == VariableType.PopUp) { setVarMethod = (SetVarMethod) EditorGUILayout.EnumPopup ("Method:", setVarMethod); if (setVarMethod == SetVarMethod.Formula) { label += "="; setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.String); if (setParameterID < 0) { formula = EditorGUILayout.TextField (label, formula); } #if UNITY_WP8 EditorGUILayout.HelpBox ("This feature is not available for Windows Phone 8.", MessageType.Warning); #endif } else if (setVarMethod == SetVarMethod.IncreaseByValue || setVarMethod == SetVarMethod.SetValue) { if (setVarMethod == SetVarMethod.IncreaseByValue) { label += "+="; } else if (setVarMethod == SetVarMethod.SetValue) { label += "="; } setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.Integer); if (setParameterID < 0) { if (setVarMethod == SetVarMethod.SetValue) { intValue = EditorGUILayout.Popup (label, intValue, vars[variableNumber].popUps); } else { intValue = EditorGUILayout.IntField (label, intValue); } if (setVarMethod == SetVarMethod.SetAsRandom && intValue < 0) { intValue = 0; } } } } else if (vars [variableNumber].type == VariableType.Integer) { setVarMethodIntBool = (SetVarMethodIntBool) EditorGUILayout.EnumPopup ("New value is:", setVarMethodIntBool); if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { setVarMethod = (SetVarMethod) EditorGUILayout.EnumPopup ("Method:", setVarMethod); if (setVarMethod == SetVarMethod.Formula) { label += "="; setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.String); if (setParameterID < 0) { formula = EditorGUILayout.TextField (label, formula); } #if UNITY_WP8 EditorGUILayout.HelpBox ("This feature is not available for Windows Phone 8.", MessageType.Warning); #endif } else { if (setVarMethod == SetVarMethod.IncreaseByValue) { label += "+="; } else if (setVarMethod == SetVarMethod.SetValue) { label += "="; } else if (setVarMethod == SetVarMethod.SetAsRandom) { label += ("= 0 to"); } setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.Integer); if (setParameterID < 0) { intValue = EditorGUILayout.IntField (label, intValue); if (setVarMethod == SetVarMethod.SetAsRandom && intValue < 0) { intValue = 0; } } } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { ShowMecanimGUI (); } } else if (vars [variableNumber].type == VariableType.Float) { setVarMethodIntBool = (SetVarMethodIntBool) EditorGUILayout.EnumPopup ("New value is:", setVarMethodIntBool); if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { setVarMethod = (SetVarMethod) EditorGUILayout.EnumPopup ("Method:", setVarMethod); if (setVarMethod == SetVarMethod.Formula) { label += "="; setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.String); if (setParameterID < 0) { formula = EditorGUILayout.TextField (label, formula); } #if UNITY_WP8 EditorGUILayout.HelpBox ("This feature is not available for Windows Phone 8.", MessageType.Warning); #endif } else { if (setVarMethod == SetVarMethod.IncreaseByValue) { label += "+="; } else if (setVarMethod == SetVarMethod.SetValue) { label += "="; } else if (setVarMethod == SetVarMethod.SetAsRandom) { label += "= 0 to"; } setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.Float); if (setParameterID < 0) { floatValue = EditorGUILayout.FloatField (label, floatValue); if (setVarMethod == SetVarMethod.SetAsRandom && floatValue < 0f) { floatValue = 0f; } } } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { ShowMecanimGUI (); } } else if (vars [variableNumber].type == VariableType.String) { setVarMethodString = (SetVarMethodString) EditorGUILayout.EnumPopup ("New value is:", setVarMethodString); label += "="; if (setVarMethodString == SetVarMethodString.EnteredHere) { setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.String); if (setParameterID < 0) { stringValue = EditorGUILayout.TextField (label, stringValue); } } else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText) { menuName = EditorGUILayout.TextField ("Menu name:", menuName); elementName = EditorGUILayout.TextField ("Element name:", elementName); slotNumberParameterID = Action.ChooseParameterGUI ("Slot # (optional):", parameters, slotNumberParameterID, ParameterType.Integer); if (slotNumberParameterID < 0) { slotNumber = EditorGUILayout.IntField ("Slot # (optional):", slotNumber); } } } else if (vars [variableNumber].type == VariableType.Vector3) { setVarMethodVector = (SetVarMethodVector) EditorGUILayout.EnumPopup ("Method:", setVarMethodVector); if (setVarMethodVector == SetVarMethodVector.IncreaseByValue) { label += "+="; } else if (setVarMethodVector == SetVarMethodVector.SetValue) { label += "="; } setParameterID = Action.ChooseParameterGUI (label, parameters, setParameterID, ParameterType.Vector3); if (setParameterID < 0) { vector3Value = EditorGUILayout.Vector3Field (label, vector3Value); } } AfterRunningOption (); } else { EditorGUILayout.HelpBox ("No variables exist!", MessageType.Info); variableID = -1; variableNumber = -1; } }
private void SetVariable (GVar var, VariableLocation location, bool doSkip) { if (var == null) { return; } if (location == VariableLocation.Global) { var.Download (); } if (var.type == VariableType.Integer) { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (int) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula, Options.GetLanguage (), localVariables)); } else { _value = intValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { _value = animator.GetInteger (parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue (); } var.SetValue (_value, setVarMethod); if (doSkip) { var.BackupValue (); } } if (var.type == VariableType.Float) { float _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (float) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula, Options.GetLanguage (), localVariables)); } else { _value = floatValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { _value = animator.GetFloat (parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue (); } var.SetFloatValue (_value, setVarMethod); if (doSkip) { var.BackupValue (); } } else if (var.type == VariableType.Boolean) { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { _value = (int) boolValue; } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && parameterName != "") { if (animator.GetBool (parameterName)) { _value = 1; } } } var.SetValue (_value, SetVarMethod.SetValue); } else if (var.type == VariableType.Vector3) { Vector3 newValue = vector3Value; if (setVarMethodVector == SetVarMethodVector.IncreaseByValue) { newValue += var.vector3Val; } var.SetVector3Value (newValue); } else if (var.type == VariableType.PopUp) { int _value = 0; if (setVarMethod == SetVarMethod.Formula) { _value = (int) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula, Options.GetLanguage (), localVariables)); } else if (setVarMethod == SetVarMethod.SetAsRandom) { if (var.popUps != null) { _value = var.popUps.Length; } } else { _value = intValue; } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue (); } var.SetValue (_value, setVarMethod); if (doSkip) { var.BackupValue (); } } else if (var.type == VariableType.String) { string _value = ""; if (setVarMethodString == SetVarMethodString.EnteredHere) { _value = AdvGame.ConvertTokens (stringValue, Options.GetLanguage (), localVariables); } else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText) { MenuElement menuElement = PlayerMenus.GetElementWithName (menuName, elementName); if (menuElement != null) { if (menuElement is MenuInput) { MenuInput menuInput = (MenuInput) menuElement; _value = menuInput.GetContents (); if (KickStarter.runtimeLanguages.LanguageReadsRightToLeft (Options.GetLanguage ()) && _value.Length > 0) { // Invert char[] charArray = _value.ToCharArray (); _value = ""; for (int i = charArray.Length-1; i >= 0; i --) { _value += charArray[i]; } } } else { PlayerMenus.GetMenuWithName (menuName).Recalculate (); menuElement.PreDisplay (slotNumber, Options.GetLanguage (), false); _value = menuElement.GetLabel (slotNumber, Options.GetLanguage ()); } } else { ACDebug.LogWarning ("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'"); } } var.SetStringValue (_value, lineID); } if (location == VariableLocation.Global) { var.Upload (); } KickStarter.actionListManager.VariableChanged (); }
public static void ModifyAction(ActionListAsset _target, AC.Action _action, string callback) { ActionsManager actionsManager = AdvGame.GetReferences().actionsManager; if (actionsManager == null) { return; } int i = -1; if (_action != null && _target.actions.IndexOf(_action) > -1) { i = _target.actions.IndexOf(_action); } switch (callback) { case "Enable": Undo.RecordObject(_target, "Enable action"); _target.actions [i].isEnabled = true; break; case "Disable": Undo.RecordObject(_target, "Disable action"); _target.actions [i].isEnabled = false; break; case "Cut": Undo.RecordObject(_target, "Cut action"); List <AC.Action> cutList = new List <AC.Action>(); AC.Action cutAction = Object.Instantiate(_action) as AC.Action; cutList.Add(cutAction); AdvGame.copiedActions = cutList; _target.actions.Remove(_action); Undo.DestroyObjectImmediate(_action); //UnityEngine.Object.DestroyImmediate (_action, true); AssetDatabase.SaveAssets(); break; case "Copy": List <AC.Action> copyList = new List <AC.Action>(); AC.Action copyAction = Object.Instantiate(_action) as AC.Action; copyAction.ClearIDs(); copyAction.name = copyAction.name.Replace("(Clone)", ""); copyList.Add(copyAction); AdvGame.copiedActions = copyList; break; case "Paste after": Undo.RecordObject(_target, "Paste actions"); List <AC.Action> pasteList = AdvGame.copiedActions; int j = i + 1; foreach (AC.Action action in pasteList) { if (action == null) { ACDebug.LogWarning("Error when pasting Action - cannot find original. Did you change scene before pasting? If you need to transfer Actions between scenes, copy them to an ActionList asset first."); continue; } AC.Action pastedAction = Object.Instantiate(action) as AC.Action; pastedAction.name = pastedAction.name.Replace("(Clone)", ""); pastedAction.hideFlags = HideFlags.HideInHierarchy; _target.actions.Insert(j, pastedAction); j++; AssetDatabase.AddObjectToAsset(pastedAction, _target); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(pastedAction)); } AssetDatabase.SaveAssets(); break; case "Insert after": Undo.RecordObject(_target, "Create action"); ActionListAssetEditor.AddAction(actionsManager.GetDefaultAction(), i + 1, _target); break; case "Delete": Undo.RecordObject(_target, "Delete action"); _target.actions.Remove(_action); Undo.DestroyObjectImmediate(_action); //UnityEngine.Object.DestroyImmediate (_action, true); AssetDatabase.SaveAssets(); break; case "Move to top": Undo.RecordObject(_target, "Move action to top"); _target.actions.Remove(_action); _target.actions.Insert(0, _action); break; case "Move up": Undo.RecordObject(_target, "Move action up"); _target.actions.Remove(_action); _target.actions.Insert(i - 1, _action); break; case "Move to bottom": Undo.RecordObject(_target, "Move action to bottom"); _target.actions.Remove(_action); _target.actions.Insert(_target.actions.Count, _action); break; case "Move down": Undo.RecordObject(_target, "Move action down"); _target.actions.Remove(_action); _target.actions.Insert(i + 1, _action); break; } }
/** * <summary>Updates a PlayerData class with its own variables that need saving.</summary> * <param name = "playerData">The original PlayerData class</param> * <returns>The updated PlayerData class</returns> */ public PlayerData SavePlayerData(PlayerData playerData) { playerData.playerID = ID; playerData.playerLocX = transform.position.x; playerData.playerLocY = transform.position.y; playerData.playerLocZ = transform.position.z; playerData.playerRotY = TransformRotation.eulerAngles.y; playerData.playerWalkSpeed = walkSpeedScale; playerData.playerRunSpeed = runSpeedScale; // Animation clips if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity) { playerData.playerIdleAnim = idleAnimSprite; playerData.playerWalkAnim = walkAnimSprite; playerData.playerRunAnim = runAnimSprite; playerData.playerTalkAnim = talkAnimSprite; } else if (animationEngine == AnimationEngine.Legacy) { playerData.playerIdleAnim = AssetLoader.GetAssetInstanceID(idleAnim); playerData.playerWalkAnim = AssetLoader.GetAssetInstanceID(walkAnim); playerData.playerRunAnim = AssetLoader.GetAssetInstanceID(runAnim); playerData.playerTalkAnim = AssetLoader.GetAssetInstanceID(talkAnim); } else if (animationEngine == AnimationEngine.Mecanim) { playerData.playerWalkAnim = moveSpeedParameter; playerData.playerTalkAnim = talkParameter; playerData.playerRunAnim = turnParameter; } // Sound playerData.playerWalkSound = AssetLoader.GetAssetInstanceID(walkSound); playerData.playerRunSound = AssetLoader.GetAssetInstanceID(runSound); // Portrait graphic playerData.playerPortraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture); // Speech label playerData.playerSpeechLabel = GetName(); playerData.playerDisplayLineID = displayLineID; // Rendering playerData.playerLockDirection = lockDirection; playerData.playerLockScale = lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting; } else if (GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = GetComponent <FollowSortingMap>().lockSorting; } else { playerData.playerLockSorting = false; } playerData.playerSpriteDirection = spriteDirection; playerData.playerSpriteScale = spriteScale; if (spriteChild && spriteChild.GetComponent <Renderer>()) { playerData.playerSortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName; } else if (GetComponent <Renderer>()) { playerData.playerSortingOrder = GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = GetComponent <Renderer>().sortingLayerName; } playerData.playerActivePath = 0; playerData.lastPlayerActivePath = 0; if (GetPath()) { playerData.playerTargetNode = GetTargetNode(); playerData.playerPrevNode = GetPreviousNode(); playerData.playerIsRunning = isRunning; playerData.playerPathAffectY = activePath.affectY; if (GetComponent <Paths>() && GetPath() == GetComponent <Paths>()) { playerData.playerPathData = Serializer.CreatePathData(GetComponent <Paths>()); playerData.playerLockedPath = false; } else { playerData.playerPathData = ""; playerData.playerActivePath = Serializer.GetConstantID(GetPath().gameObject); playerData.playerLockedPath = lockedPath; } } if (GetLastPath()) { playerData.lastPlayerTargetNode = GetLastTargetNode(); playerData.lastPlayerPrevNode = GetLastPrevNode(); playerData.lastPlayerActivePath = Serializer.GetConstantID(GetLastPath().gameObject); } playerData.playerIgnoreGravity = ignoreGravity; // Head target playerData.playerLockHotspotHeadTurning = lockHotspotHeadTurning; if (headFacing == HeadFacing.Manual && headTurnTarget != null) { playerData.isHeadTurning = true; playerData.headTargetID = Serializer.GetConstantID(headTurnTarget); if (playerData.headTargetID == 0) { ACDebug.LogWarning("The Player's head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID", gameObject); } playerData.headTargetX = headTurnTargetOffset.x; playerData.headTargetY = headTurnTargetOffset.y; playerData.headTargetZ = headTurnTargetOffset.z; } else { playerData.isHeadTurning = false; playerData.headTargetID = 0; playerData.headTargetX = 0f; playerData.headTargetY = 0f; playerData.headTargetZ = 0f; } if (GetComponentInChildren <FollowSortingMap>() != null) { FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>(); playerData.followSortingMap = followSortingMap.followSortingMap; if (!playerData.followSortingMap && followSortingMap.GetSortingMap() != null) { if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null) { playerData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("The Player's SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID", gameObject); playerData.customSortingMapID = 0; } } else { playerData.customSortingMapID = 0; } } else { playerData.followSortingMap = false; playerData.customSortingMapID = 0; } return(playerData); }
public void ShowGUI() { try { CustomGUILayout.MultiLineLabelGUI("Player ID:", playerID.ToString()); EditorGUILayout.LabelField("Scene info:"); CustomGUILayout.MultiLineLabelGUI(" Current scene:", currentScene.ToString()); CustomGUILayout.MultiLineLabelGUI(" Previous scene:", previousScene.ToString()); CustomGUILayout.MultiLineLabelGUI(" Sub-scenes:", openSubScenes); if (tempPlayerStart != 0) { CustomGUILayout.MultiLineLabelGUI(" PlayerStart ID:", tempPlayerStart.ToString()); CustomGUILayout.MultiLineLabelGUI(" PlayerStart method:", tempTeleportPlayerStartMethod.ToString()); } EditorGUILayout.LabelField("Movement:"); CustomGUILayout.MultiLineLabelGUI(" Position:", "(" + playerLocX.ToString() + ", " + playerLocY.ToString() + ", " + playerLocZ.ToString() + ")"); CustomGUILayout.MultiLineLabelGUI(" Rotation:", playerRotY.ToString()); CustomGUILayout.MultiLineLabelGUI(" Walk speed:", playerWalkSpeed.ToString()); CustomGUILayout.MultiLineLabelGUI(" Run speed:", playerRunSpeed.ToString()); CustomGUILayout.MultiLineLabelGUI(" Is running?", playerIsRunning.ToString()); CustomGUILayout.MultiLineLabelGUI(" Up locked?", playerUpLock.ToString()); CustomGUILayout.MultiLineLabelGUI(" Down locked?", playerDownLock.ToString()); CustomGUILayout.MultiLineLabelGUI(" Left locked?", playerLeftlock.ToString()); CustomGUILayout.MultiLineLabelGUI(" Right locked?", playerRightLock.ToString()); CustomGUILayout.MultiLineLabelGUI(" Run locked?", playerRunLock.ToString()); CustomGUILayout.MultiLineLabelGUI(" Free-aim locked?", playerFreeAimLock.ToString()); CustomGUILayout.MultiLineLabelGUI(" Ignore gravity?", playerIgnoreGravity.ToString()); EditorGUILayout.LabelField("Animation:"); CustomGUILayout.MultiLineLabelGUI(" Idle animation:", playerIdleAnim); CustomGUILayout.MultiLineLabelGUI(" Walk animation:", playerWalkAnim); CustomGUILayout.MultiLineLabelGUI(" Talk animation:", playerTalkAnim); CustomGUILayout.MultiLineLabelGUI(" Run animation:", playerRunAnim); CustomGUILayout.MultiLineLabelGUI(" In custom state?", inCustomCharState.ToString()); CustomGUILayout.MultiLineLabelGUI(" Left hand IK:", leftHandIKState); CustomGUILayout.MultiLineLabelGUI(" Right hand IK:", rightHandIKState); EditorGUILayout.LabelField("Sound:"); CustomGUILayout.MultiLineLabelGUI(" Walk sound:", playerWalkSound); CustomGUILayout.MultiLineLabelGUI(" Run sound:", playerRunSound); EditorGUILayout.LabelField("Speech:"); CustomGUILayout.MultiLineLabelGUI(" Portrait graphic:", playerPortraitGraphic); CustomGUILayout.MultiLineLabelGUI(" Speech label:", playerSpeechLabel); CustomGUILayout.MultiLineLabelGUI(" Speech label ID:", playerDisplayLineID.ToString()); EditorGUILayout.LabelField("Pathfinding:"); CustomGUILayout.MultiLineLabelGUI(" Target node:", playerTargetNode.ToString()); CustomGUILayout.MultiLineLabelGUI(" Previous node:", playerPrevNode.ToString()); CustomGUILayout.MultiLineLabelGUI(" Path data:", playerPathData); CustomGUILayout.MultiLineLabelGUI(" Locked to path?", playerLockedPath.ToString()); CustomGUILayout.MultiLineLabelGUI(" Active path:", playerActivePath.ToString()); CustomGUILayout.MultiLineLabelGUI(" Path affects Y?", playerPathAffectY.ToString()); CustomGUILayout.MultiLineLabelGUI(" Last target node:", lastPlayerTargetNode.ToString()); CustomGUILayout.MultiLineLabelGUI(" Last previous node:", lastPlayerPrevNode.ToString()); CustomGUILayout.MultiLineLabelGUI(" Last active path:", lastPlayerActivePath.ToString()); EditorGUILayout.LabelField("Sprites:"); CustomGUILayout.MultiLineLabelGUI(" Lock direction?", playerLockDirection.ToString()); CustomGUILayout.MultiLineLabelGUI(" Sprite direction:", playerSpriteDirection); CustomGUILayout.MultiLineLabelGUI(" Scale locked?", playerLockScale.ToString()); CustomGUILayout.MultiLineLabelGUI(" Sprite scale:", playerSpriteScale.ToString()); CustomGUILayout.MultiLineLabelGUI(" Lock sorting?", playerLockSorting.ToString()); CustomGUILayout.MultiLineLabelGUI(" Sorting order:", playerSortingOrder.ToString()); CustomGUILayout.MultiLineLabelGUI(" Sorting layer:", playerSortingLayer); CustomGUILayout.MultiLineLabelGUI(" Follow default Sorting Map?", followSortingMap.ToString()); if (!followSortingMap) { CustomGUILayout.MultiLineLabelGUI(" Sorting map?", customSortingMapID.ToString()); } CustomGUILayout.MultiLineLabelGUI("Inventory:", inventoryData); CustomGUILayout.MultiLineLabelGUI(" Active Document:", activeDocumentID.ToString()); CustomGUILayout.MultiLineLabelGUI(" Collected Documents:", collectedDocumentData.ToString()); CustomGUILayout.MultiLineLabelGUI(" Last-open Document pages", lastOpenDocumentPagesData.ToString()); CustomGUILayout.MultiLineLabelGUI(" Objectives:", playerObjectivesData.ToString()); EditorGUILayout.LabelField("Head-turning:"); CustomGUILayout.MultiLineLabelGUI(" Head facing Hotspot?", playerLockHotspotHeadTurning.ToString()); CustomGUILayout.MultiLineLabelGUI(" Head turning?", isHeadTurning.ToString()); CustomGUILayout.MultiLineLabelGUI(" Head target:", headTargetID.ToString()); CustomGUILayout.MultiLineLabelGUI(" Head target position:", "(" + headTargetX + ", " + headTargetY + ", " + headTargetZ + ")"); EditorGUILayout.LabelField("Camera:"); CustomGUILayout.MultiLineLabelGUI(" Camera:", gameCamera.ToString()); CustomGUILayout.MultiLineLabelGUI(" Last nav cam:", lastNavCamera.ToString()); CustomGUILayout.MultiLineLabelGUI(" Last nav cam 2:", lastNavCamera2.ToString()); CustomGUILayout.MultiLineLabelGUI(" Camera position:", "(" + mainCameraLocX + ", " + mainCameraLocY + ", " + mainCameraLocZ + ")"); CustomGUILayout.MultiLineLabelGUI(" Camera rotation:", "(" + mainCameraRotX + ", " + mainCameraRotY + ", " + mainCameraRotZ + ")"); CustomGUILayout.MultiLineLabelGUI(" Split-screen?", isSplitScreen.ToString()); if (isSplitScreen) { CustomGUILayout.MultiLineLabelGUI(" Top-left split?", isTopLeftSplit.ToString()); CustomGUILayout.MultiLineLabelGUI(" Vertical split?", splitIsVertical.ToString()); CustomGUILayout.MultiLineLabelGUI(" Split camera:", splitCameraID.ToString()); CustomGUILayout.MultiLineLabelGUI(" Split amount main:", splitAmountMain.ToString()); CustomGUILayout.MultiLineLabelGUI(" Split amount other:", splitAmountOther.ToString()); CustomGUILayout.MultiLineLabelGUI(" Overlay rect:", "(" + overlayRectX + ", " + overlayRectY + ", " + overlayRectWidth + ", " + overlayRectHeight + ")"); } CustomGUILayout.MultiLineLabelGUI(" Shake intensity:", shakeIntensity.ToString()); if (shakeIntensity > 0f) { CustomGUILayout.MultiLineLabelGUI(" Shake duration", shakeDuration.ToString()); CustomGUILayout.MultiLineLabelGUI(" Shake effect:", ((CameraShakeEffect)shakeEffect).ToString()); } if (playerScriptData != null && playerScriptData.Count > 0) { EditorGUILayout.LabelField("Remember data:"); foreach (ScriptData scriptData in playerScriptData) { RememberData rememberData = SaveSystem.FileFormatHandler.DeserializeObject <RememberData> (scriptData.data); if (rememberData != null) { CustomGUILayout.MultiLineLabelGUI(" " + rememberData.GetType().ToString() + ":", EditorJsonUtility.ToJson(rememberData, true)); } } } } catch (Exception e) { ACDebug.LogWarning("Error displaying player data. Exception: " + e); } }
private void RunInstant(AC.Menu _menu) { if (changeType == MenuChangeType.HideMenuElement || changeType == MenuChangeType.ShowMenuElement) { MenuElement _element = PlayerMenus.GetElementWithName(menuToChange, elementToChange); if (_element != null) { if (changeType == MenuChangeType.HideMenuElement) { _element.IsVisible = false; KickStarter.playerMenus.DeselectInputBox(_element); } else { _element.IsVisible = true; } _menu.ResetVisibleElements(); _menu.Recalculate(); KickStarter.playerMenus.FindFirstSelectedElement(); } else { ACDebug.LogWarning("Could not find element of name '" + elementToChange + "' on menu '" + menuToChange + "'"); } } else if (changeType == MenuChangeType.UnlockMenu) { _menu.isLocked = false; } else if (changeType == MenuChangeType.AddJournalPage) { MenuElement _element = PlayerMenus.GetElementWithName(menuToChange, elementToChange); if (_element != null) { if (journalText != "") { if (_element is MenuJournal) { MenuJournal journal = (MenuJournal)_element; JournalPage newPage = new JournalPage(lineID, journalText); journal.AddPage(newPage, onlyAddNewJournal, journalPageIndex); if (lineID == -1) { ACDebug.LogWarning("The new Journal page has no ID number, and will not be included in save game files - this can be corrected by clicking 'Gather text' in the Speech Manager"); } } else { ACDebug.LogWarning(_element.title + " is not a journal!"); } } else { ACDebug.LogWarning("No journal text to add!"); } } else { ACDebug.LogWarning("Could not find menu element of name '" + elementToChange + "' inside '" + menuToChange + "'"); } _menu.Recalculate(); } else if (changeType == MenuChangeType.RemoveJournalPage) { MenuElement _element = PlayerMenus.GetElementWithName(menuToChange, elementToChange); if (_element != null) { if (_element is MenuJournal) { MenuJournal journal = (MenuJournal)_element; if (removeJournalPageMethod == RemoveJournalPageMethod.RemoveAllPages) { journal.RemoveAllPages(); } else if (removeJournalPageMethod == RemoveJournalPageMethod.RemoveSinglePage) { journal.RemovePage(journalPageIndex); } } else { ACDebug.LogWarning(_element.title + " is not a journal!"); } } else { ACDebug.LogWarning("Could not find menu element of name '" + elementToChange + "' inside '" + menuToChange + "'"); } _menu.Recalculate(); } }
/** * <summary>Serialises appropriate GameObject values into a string.</summary> * <returns>The data, serialised as a string</returns> */ public TransformData SaveTransformData() { TransformData transformData = new TransformData(); transformData.objectID = constantID; transformData.LocX = transform.position.x; transformData.LocY = transform.position.y; transformData.LocZ = transform.position.z; transformData.RotX = transform.eulerAngles.x; transformData.RotY = transform.eulerAngles.y; transformData.RotZ = transform.eulerAngles.z; transformData.ScaleX = transform.localScale.x; transformData.ScaleY = transform.localScale.y; transformData.ScaleZ = transform.localScale.z; transformData.bringBack = saveScenePresence; if (saveParent) { // Attempt to find the "hand" bone of a character Transform t = transform.parent; if (t == null) { transformData.parentID = 0; return(transformData); } while (t.parent != null) { t = t.parent; if (t.GetComponent <AC.Char>()) { AC.Char parentCharacter = t.GetComponent <AC.Char>(); if (parentCharacter is Player || (parentCharacter.GetComponent <ConstantID>() && parentCharacter.GetComponent <ConstantID>().constantID != 0)) { if (transform.parent == parentCharacter.leftHandBone || transform.parent == parentCharacter.rightHandBone) { if (parentCharacter is Player) { transformData.parentIsPlayer = true; transformData.parentIsNPC = false; transformData.parentID = 0; } else { transformData.parentIsPlayer = false; transformData.parentIsNPC = true; transformData.parentID = parentCharacter.GetComponent <ConstantID>().constantID; } if (transform.parent == parentCharacter.leftHandBone) { transformData.heldHand = Hand.Left; } else { transformData.heldHand = Hand.Right; } return(transformData); } } break; } } if (transform.parent.GetComponent <ConstantID>() && transform.parent.GetComponent <ConstantID>().constantID != 0) { transformData.parentID = transform.parent.GetComponent <ConstantID>().constantID; } else { transformData.parentID = 0; ACDebug.LogWarning("Could not save " + this.name + "'s parent since it has no Constant ID"); } } return(transformData); }
override public float Run() { if (!isRunning) { isRunning = true; AC.Menu _menu = PlayerMenus.GetMenuWithName(menuToChange); if (_menu != null) { if (changeType == MenuChangeType.TurnOnMenu) { if (_menu.IsManualControlled()) { if (!_menu.TurnOn(doFade)) { // Menu is already on isRunning = false; return(0f); } if (doFade && willWait) { return(_menu.fadeSpeed); } } else { ACDebug.LogWarning("Can only turn on Menus with an Appear Type of Manual, OnInputKey or OnContainer - did you mean 'Unlock Menu'?"); } } else if (changeType == MenuChangeType.TurnOffMenu) { if (_menu.IsManualControlled() || _menu.appearType == AppearType.OnInteraction) { if (!_menu.TurnOff(doFade)) { // Menu is already off isRunning = false; return(0f); } if (doFade && willWait) { return(_menu.fadeSpeed); } } else { ACDebug.LogWarning("Can only turn off Menus with an Appear Type of Manual, OnInputKey or OnContainer - did you mean 'Lock Menu'?"); } } else if (changeType == MenuChangeType.LockMenu) { if (doFade) { _menu.TurnOff(true); } else { _menu.ForceOff(); } _menu.isLocked = true; if (doFade && willWait) { return(_menu.fadeSpeed); } } else { RunInstant(_menu); } } else if (menuToChange != "") { ACDebug.LogWarning("Could not find menu of name '" + menuToChange + "'"); } } else { isRunning = false; return(0f); } return(0f); }
private void InvInteractionGUI() { EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Inventory interactions", EditorStyles.boldLabel); if (GUILayout.Button(addContent, EditorStyles.miniButtonRight, buttonWidth)) { Undo.RecordObject(_target, "Create inventory interaction"); _target.invButtons.Add(new Button()); _target.provideInvInteraction = true; } EditorGUILayout.EndHorizontal(); if (_target.provideInvInteraction) { if (inventoryManager) { // Create a string List of the field's names (for the PopUp box) List <string> labelList = new List <string>(); int invNumber; if (inventoryManager.items.Count > 0) { foreach (InvItem _item in inventoryManager.items) { labelList.Add(_item.label); } foreach (Button invButton in _target.invButtons) { invNumber = -1; int j = 0; string invName = ""; foreach (InvItem _item in inventoryManager.items) { // If an item has been removed, make sure selected variable is still valid if (_item.id == invButton.invID) { invNumber = j; invName = _item.label; break; } j++; } if (invNumber == -1) { // Wasn't found (item was deleted?), so revert to zero ACDebug.Log("Previously chosen item no longer exists!"); invNumber = 0; invButton.invID = 0; } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); invNumber = EditorGUILayout.Popup("Inventory item:", invNumber, labelList.ToArray()); // Re-assign variableID based on PopUp selection invButton.invID = inventoryManager.items[invNumber].id; if (settingsManager != null && settingsManager.CanGiveItems()) { if (_target.GetComponent <Char>() != null || _target.GetComponentInParent <Char>() != null) { invButton.selectItemMode = (SelectItemMode)EditorGUILayout.EnumPopup(invButton.selectItemMode, GUILayout.Width(70f)); } } if (GUILayout.Button(Resource.CogIcon, EditorStyles.miniButtonRight, buttonWidth)) { SideMenu("Inv", _target.invButtons.Count, _target.invButtons.IndexOf(invButton)); } EditorGUILayout.EndHorizontal(); if (invName != "") { string label = invName; if (_target.GetComponent <Char>() && settingsManager != null && settingsManager.CanGiveItems()) { label = invButton.selectItemMode.ToString() + " " + label; } ButtonGUI(invButton, label, _target.interactionSource, true); } else { ButtonGUI(invButton, "Inventory", _target.interactionSource, true); } GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); } } else { EditorGUILayout.LabelField("No inventory items exist!"); for (int i = 0; i < _target.invButtons.Count; i++) { _target.invButtons[i].invID = -1; } } } else { ACDebug.LogWarning("An InventoryManager is required to run the game properly - please open the Adventure Creator wizard and set one."); } } EditorGUILayout.EndVertical(); }
public override void ShowGUI(List <ActionParameter> parameters) { Upgrade(); if (inventoryManager == null) { inventoryManager = AdvGame.GetReferences().inventoryManager; } selectedCheckMethod = (SelectedCheckMethod)EditorGUILayout.EnumPopup("Check selected item is:", selectedCheckMethod); if (inventoryManager != null) { if (selectedCheckMethod == SelectedCheckMethod.InSpecificCategory) { // Create a string List of the field's names (for the PopUp box) List <string> labelList = new List <string>(); int i = 0; int binNumber = 0; if (parameterID == -1) { binNumber = -1; } if (inventoryManager.bins != null && inventoryManager.bins.Count > 0) { foreach (InvBin _bin in inventoryManager.bins) { labelList.Add(_bin.id.ToString() + ": " + _bin.label); // If a category has been removed, make sure selected is still valid if (_bin.id == binID) { binNumber = i; } i++; } if (binNumber == -1) { ACDebug.LogWarning("Previously chosen category no longer exists!"); binNumber = 0; } binNumber = EditorGUILayout.Popup("Inventory category:", binNumber, labelList.ToArray()); binID = inventoryManager.bins[binNumber].id; includeLast = EditorGUILayout.Toggle("Include last-selected?", includeLast); } else { EditorGUILayout.HelpBox("No inventory categories exist!", MessageType.Info); binID = -1; } } else if (selectedCheckMethod == SelectedCheckMethod.SpecificItem) { // Create a string List of the field's names (for the PopUp box) List <string> labelList = new List <string>(); int i = 0; int invNumber = 0; if (parameterID == -1) { invNumber = -1; } if (inventoryManager.items.Count > 0) { foreach (InvItem _item in inventoryManager.items) { labelList.Add(_item.label); // If an item has been removed, make sure selected variable is still valid if (_item.id == invID) { invNumber = i; } i++; } if (invNumber == -1) { ACDebug.LogWarning("Previously chosen item no longer exists!"); invID = 0; } parameterID = Action.ChooseParameterGUI("Inventory item:", parameters, parameterID, ParameterType.InventoryItem); if (parameterID >= 0) { invNumber = Mathf.Min(invNumber, inventoryManager.items.Count - 1); invID = -1; } else { invNumber = EditorGUILayout.Popup("Inventory item:", invNumber, labelList.ToArray()); invID = inventoryManager.items[invNumber].id; } includeLast = EditorGUILayout.Toggle("Include last-selected?", includeLast); } else { EditorGUILayout.HelpBox("No inventory items exist!", MessageType.Info); invID = -1; } } } }
/** * <summary>Updates a NPCData class with its own variables that need saving.</summary> * <param name = "npcData">The original NPCData class</param> * <returns>The updated NPCData class</returns> */ public NPCData SaveData(NPCData npcData) { npcData.RotX = TransformRotation.eulerAngles.x; npcData.RotY = TransformRotation.eulerAngles.y; npcData.RotZ = TransformRotation.eulerAngles.z; npcData.inCustomCharState = (charState == CharState.Custom && GetAnimator() != null && GetAnimator().GetComponent <RememberAnimator>()); // Animation npcData = GetAnimEngine().SaveNPCData(npcData, this); npcData.walkSound = AssetLoader.GetAssetInstanceID(walkSound); npcData.runSound = AssetLoader.GetAssetInstanceID(runSound); npcData.speechLabel = GetName(); npcData.displayLineID = displayLineID; npcData.portraitGraphic = AssetLoader.GetAssetInstanceID(portraitIcon.texture); npcData.walkSpeed = walkSpeedScale; npcData.runSpeed = runSpeedScale; // Rendering npcData.lockDirection = lockDirection; npcData.lockScale = lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { npcData.lockSorting = spriteChild.GetComponent <FollowSortingMap>().lockSorting; } else if (GetComponent <FollowSortingMap>()) { npcData.lockSorting = GetComponent <FollowSortingMap>().lockSorting; } else { npcData.lockSorting = false; } npcData.spriteDirection = spriteDirection; npcData.spriteScale = spriteScale; if (spriteChild && spriteChild.GetComponent <Renderer>()) { npcData.sortingOrder = spriteChild.GetComponent <Renderer>().sortingOrder; npcData.sortingLayer = spriteChild.GetComponent <Renderer>().sortingLayerName; } else if (GetComponent <Renderer>()) { npcData.sortingOrder = GetComponent <Renderer>().sortingOrder; npcData.sortingLayer = GetComponent <Renderer>().sortingLayerName; } npcData.pathID = 0; npcData.lastPathID = 0; if (GetPath()) { npcData.targetNode = GetTargetNode(); npcData.prevNode = GetPreviousNode(); npcData.isRunning = isRunning; npcData.pathAffectY = GetPath().affectY; if (GetPath() == GetComponent <Paths>()) { npcData.pathData = Serializer.CreatePathData(GetComponent <Paths>()); } else { if (GetPath().GetComponent <ConstantID>()) { npcData.pathID = GetPath().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("Want to save path data for " + name + " but path has no ID!", gameObject); } } } if (GetLastPath()) { npcData.lastTargetNode = GetLastTargetNode(); npcData.lastPrevNode = GetLastPrevNode(); if (GetLastPath().GetComponent <ConstantID>()) { npcData.lastPathID = GetLastPath().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("Want to save previous path data for " + name + " but path has no ID!", gameObject); } } if (followTarget) { if (!followTargetIsPlayer) { if (followTarget.GetComponent <ConstantID>()) { npcData.followTargetID = followTarget.GetComponent <ConstantID>().constantID; npcData.followTargetIsPlayer = followTargetIsPlayer; npcData.followFrequency = followFrequency; npcData.followDistance = followDistance; npcData.followDistanceMax = followDistanceMax; npcData.followFaceWhenIdle = followFaceWhenIdle; npcData.followRandomDirection = followRandomDirection; } else { ACDebug.LogWarning("Want to save follow data for " + name + " but " + followTarget.name + " has no ID!", gameObject); } } else { npcData.followTargetID = 0; npcData.followTargetIsPlayer = followTargetIsPlayer; npcData.followFrequency = followFrequency; npcData.followDistance = followDistance; npcData.followDistanceMax = followDistanceMax; //followFaceWhenIdle = false; npcData.followFaceWhenIdle = followFaceWhenIdle; npcData.followRandomDirection = followRandomDirection; } } else { npcData.followTargetID = 0; npcData.followTargetIsPlayer = false; npcData.followFrequency = 0f; npcData.followDistance = 0f; npcData.followDistanceMax = 0f; npcData.followFaceWhenIdle = false; npcData.followRandomDirection = false; } if (headFacing == HeadFacing.Manual && headTurnTarget != null) { npcData.isHeadTurning = true; npcData.headTargetID = Serializer.GetConstantID(headTurnTarget); if (npcData.headTargetID == 0) { ACDebug.LogWarning("The NPC " + gameObject.name + "'s head-turning target Transform, " + headTurnTarget + ", was not saved because it has no Constant ID", gameObject); } npcData.headTargetX = headTurnTargetOffset.x; npcData.headTargetY = headTurnTargetOffset.y; npcData.headTargetZ = headTurnTargetOffset.z; } else { npcData.isHeadTurning = false; npcData.headTargetID = 0; npcData.headTargetX = 0f; npcData.headTargetY = 0f; npcData.headTargetZ = 0f; } if (GetComponentInChildren <FollowSortingMap>() != null) { FollowSortingMap followSortingMap = GetComponentInChildren <FollowSortingMap>(); npcData.followSortingMap = followSortingMap.followSortingMap; if (!npcData.followSortingMap && followSortingMap.GetSortingMap() != null) { if (followSortingMap.GetSortingMap().GetComponent <ConstantID>() != null) { npcData.customSortingMapID = followSortingMap.GetSortingMap().GetComponent <ConstantID>().constantID; } else { ACDebug.LogWarning("The NPC " + gameObject.name + "'s SortingMap, " + followSortingMap.GetSortingMap().name + ", was not saved because it has no Constant ID"); npcData.customSortingMapID = 0; } } else { npcData.customSortingMapID = 0; } } else { npcData.followSortingMap = false; npcData.customSortingMapID = 0; } return(npcData); }
public override void ShowGUI(List <ActionParameter> parameters) { if (inventoryManager == null && AdvGame.GetReferences().inventoryManager) { inventoryManager = AdvGame.GetReferences().inventoryManager; } if (settingsManager == null && AdvGame.GetReferences().settingsManager) { settingsManager = AdvGame.GetReferences().settingsManager; } invCheckType = (InvCheckType)EditorGUILayout.EnumPopup("Check to make:", invCheckType); if (invCheckType == InvCheckType.NumberOfItemsCarrying) { intCondition = (IntCondition)EditorGUILayout.EnumPopup("Count is:", intCondition); intValueParameterID = Action.ChooseParameterGUI(intCondition.ToString() + ":", parameters, intValueParameterID, ParameterType.Integer); if (intValueParameterID < 0) { intValue = EditorGUILayout.IntField(intCondition.ToString() + ":", intValue); } if (inventoryManager != null && inventoryManager.bins != null && inventoryManager.bins.Count > 0) { checkNumberInCategory = EditorGUILayout.Toggle("Check specific category?", checkNumberInCategory); if (checkNumberInCategory) { int categoryIndex = 0; string[] popupList = new string[inventoryManager.bins.Count]; for (int i = 0; i < inventoryManager.bins.Count; i++) { popupList[i] = inventoryManager.bins[i].label; if (inventoryManager.bins[i].id == categoryIDToCheck) { categoryIndex = i; } } categoryIndex = EditorGUILayout.Popup("Limit to category:", categoryIndex, popupList); categoryIDToCheck = inventoryManager.bins[categoryIndex].id; } } SetPlayerGUI(); return; } if (inventoryManager) { // Create a string List of the field's names (for the PopUp box) List <string> labelList = new List <string>(); int i = 0; if (parameterID == -1) { invNumber = -1; } if (inventoryManager.items.Count > 0) { foreach (InvItem _item in inventoryManager.items) { labelList.Add(_item.label); // If an item has been removed, make sure selected variable is still valid if (_item.id == invID) { invNumber = i; } i++; } if (invNumber == -1) { // Wasn't found (item was possibly deleted), so revert to zero ACDebug.LogWarning("Previously chosen item no longer exists!"); invNumber = 0; invID = 0; } // parameterID = Action.ChooseParameterGUI("Inventory item:", parameters, parameterID, ParameterType.InventoryItem); if (parameterID >= 0) { invNumber = Mathf.Min(invNumber, inventoryManager.items.Count - 1); invID = -1; } else { invNumber = EditorGUILayout.Popup("Inventory item:", invNumber, labelList.ToArray()); invID = inventoryManager.items[invNumber].id; } // if (inventoryManager.items[invNumber].canCarryMultiple) { doCount = EditorGUILayout.Toggle("Query count?", doCount); if (doCount) { intCondition = (IntCondition)EditorGUILayout.EnumPopup("Count is:", intCondition); intValueParameterID = Action.ChooseParameterGUI(intCondition.ToString() + ":", parameters, intValueParameterID, ParameterType.Integer); if (intValueParameterID < 0) { intValue = EditorGUILayout.IntField(intCondition.ToString() + ":", intValue); if (intValue < 1) { intValue = 1; } } } } else { doCount = false; } SetPlayerGUI(); } else { EditorGUILayout.LabelField("No inventory items exist!"); invID = -1; invNumber = -1; } } else { EditorGUILayout.HelpBox("An Inventory Manager must be assigned for this Action to work", MessageType.Warning); } }
/** * <summary>Performs what should happen when the element is clicked on.</summary> * <param name = "_menu">The element's parent Menu</param> * <param name = "_slot">Ignored by this subclass</param> * <param name = "_mouseState">The state of the mouse button</param> */ public override void ProcessClick(AC.Menu _menu, int _slot, MouseState _mouseState) { if (!_menu.IsClickable()) { return; } ShowClick(); if (buttonClickType == AC_ButtonClickType.TurnOffMenu) { _menu.TurnOff(doFade); } else if (buttonClickType == AC_ButtonClickType.Crossfade) { AC.Menu menuToSwitchTo = PlayerMenus.GetMenuWithName(switchMenuTitle); if (menuToSwitchTo != null) { KickStarter.playerMenus.CrossFade(menuToSwitchTo); } else { ACDebug.LogWarning("Cannot find any menu of name '" + switchMenuTitle + "'"); } } else if (buttonClickType == AC_ButtonClickType.OffsetElementSlot) { if (elementToShift != null) { elementToShift.Shift(shiftInventory, shiftAmount); elementToShift.RecalculateSize(_menu.menuSource); _menu.Recalculate(); } else { ACDebug.LogWarning("Cannot find '" + inventoryBoxTitle + "' inside '" + _menu.title + "'"); } } else if (buttonClickType == AC_ButtonClickType.OffsetJournal) { MenuJournal journalToShift = (MenuJournal)PlayerMenus.GetElementWithName(_menu.title, inventoryBoxTitle); if (journalToShift != null) { journalToShift.Shift(shiftInventory, loopJournal, shiftAmount); journalToShift.RecalculateSize(_menu.menuSource); _menu.Recalculate(); } else { ACDebug.LogWarning("Cannot find '" + inventoryBoxTitle + "' inside '" + _menu.title + "'"); } } else if (buttonClickType == AC_ButtonClickType.RunActionList) { if (actionList) { if (!actionList.canRunMultipleInstances) { KickStarter.actionListAssetManager.EndAssetList(actionList); } AdvGame.RunActionListAsset(actionList, parameterID, parameterValue); } } else if (buttonClickType == AC_ButtonClickType.CustomScript) { MenuSystem.OnElementClick(_menu, this, _slot, (int)_mouseState); } else if (buttonClickType == AC_ButtonClickType.SimulateInput) { KickStarter.playerInput.SimulateInput(simulateInput, inputAxis, simulateValue); } base.ProcessClick(_menu, _slot, _mouseState); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (!Application.isPlaying) { return; } character = playerData as AC.Char; if (character == null) { GameObject characterObject = playerData as GameObject; if (characterObject) { character = characterObject.GetComponent <AC.Char>(); } } if (character) { if (character.GetAnimEngine() == null) { ACDebug.LogWarning("The 2D character animation track requires that " + character + "'s has an animation engine."); return; } if (!character.GetAnimEngine().isSpriteBased) { ACDebug.LogWarning("The 2D character animation track requires that " + character + "'s animation is sprite-based."); return; } if (character.turn2DCharactersIn3DSpace) { ACDebug.LogWarning("For the 2D character animation track to work, " + character + "'s 'Turn root object in 3D?' must be unchecked."); return; } if (forceDirection) { Vector3 lookVector = AdvGame.GetCharLookVector(charDirection); character.SetLookDirection(lookVector, turnInstantly); } if (lastFramePosition != Vector3.zero) { Vector3 deltaPosition = character.Transform.position - lastFramePosition; deltaPosition *= Time.deltaTime * 1000f; if (Mathf.Approximately(deltaPosition.sqrMagnitude, 0f)) { if (character.isTalking && (character.talkingAnimation == TalkingAnimation.Standard || character.animationEngine == AnimationEngine.Custom)) { character.GetAnimEngine().PlayTalk(); } else { character.GetAnimEngine().PlayIdle(); } SetOverrideState(false); } else { SetOverrideState(true); switch (moveSpeed) { case PathSpeed.Walk: character.GetAnimEngine().PlayWalk(); break; case PathSpeed.Run: character.GetAnimEngine().PlayRun(); break; default: break; } if (!forceDirection) { Vector3 lookVector = new Vector3(deltaPosition.x, 0f, deltaPosition.y); character.SetLookDirection(lookVector, turnInstantly); } } } lastFramePosition = character.Transform.position; } }
private void AddCharHoles(PolygonCollider2D[] navPolys, AC.Char charToExclude, NavigationMesh navigationMesh) { if (navigationMesh.characterEvasion == CharacterEvasion.None) { return; } ResetHoles(KickStarter.sceneSettings.navMesh, false); for (int p = 0; p < navPolys.Length; p++) { if (p > 0) { return; } if (navPolys[p].transform.lossyScale != Vector3.one) { ACDebug.LogWarning("Cannot create evasion Polygons inside NavMesh '" + navPolys[p].gameObject.name + "' because it has a non-unit scale."); continue; } Vector2 navPosition = navPolys[p].transform.position; foreach (AC.Char character in KickStarter.stateHandler.Characters) { CircleCollider2D circleCollider2D = character.GetComponent <CircleCollider2D>(); if (circleCollider2D != null && (character.charState == CharState.Idle || navigationMesh.characterEvasion == CharacterEvasion.AllCharacters) && (charToExclude == null || character != charToExclude) && UnityVersionHandler.Perform2DOverlapPoint(character.transform.position, NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0) { circleCollider2D.isTrigger = true; List <Vector2> newPoints3D = new List <Vector2>(); #if UNITY_5 || UNITY_2017_1_OR_NEWER Vector2 centrePoint = character.transform.TransformPoint(circleCollider2D.offset); #else Vector2 centrePoint = character.transform.TransformPoint(circleCollider2D.center); #endif float radius = circleCollider2D.radius * character.transform.localScale.x; float yScaler = navigationMesh.characterEvasionYScale; if (navigationMesh.characterEvasionPoints == CharacterEvasionPoints.Four) { newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler)); } else if (navigationMesh.characterEvasionPoints == CharacterEvasionPoints.Eight) { newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler)); } else if (navigationMesh.characterEvasionPoints == CharacterEvasionPoints.Sixteen) { newPoints3D.Add(centrePoint + new Vector2(dir_n.x * radius, dir_n.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nne.x * radius, dir_nne.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_ne.x * radius, dir_ne.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nee.x * radius, dir_nee.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_e.x * radius, dir_e.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_see.x * radius, dir_see.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_se.x * radius, dir_se.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sse.x * radius, dir_sse.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_s.x * radius, dir_s.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_ssw.x * radius, dir_ssw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sw.x * radius, dir_sw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_sww.x * radius, dir_sww.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_w.x * radius, dir_w.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nww.x * radius, dir_nww.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nw.x * radius, dir_nw.y * radius * yScaler)); newPoints3D.Add(centrePoint + new Vector2(dir_nnw.x * radius, dir_nnw.y * radius * yScaler)); } navPolys[p].pathCount++; List <Vector2> newPoints = new List <Vector2>(); for (int i = 0; i < newPoints3D.Count; i++) { // Only add a point if it is on the NavMesh if (UnityVersionHandler.Perform2DOverlapPoint(newPoints3D[i], NavigationEngine_PolygonCollider.results, 1 << KickStarter.sceneSettings.navMesh.gameObject.layer) != 0) { newPoints.Add(newPoints3D[i] - navPosition); } else { Vector2 altPoint = GetLineIntersect(newPoints3D[i], centrePoint); if (altPoint != Vector2.zero) { newPoints.Add(altPoint - navPosition); } } } if (newPoints.Count > 1) { navPolys[p].SetPath(navPolys[p].pathCount - 1, newPoints.ToArray()); } } } RebuildVertexArray(navPolys[p].transform, navPolys[p], p); } }
override public float Run() { if (!isRunning) { isRunning = true; if (charToMove && marker) { Paths path = charToMove.GetComponent <Paths>(); if (path == null) { ACDebug.LogWarning("Cannot move a character with no Paths component"); } else { if (charToMove is NPC) { NPC npcToMove = (NPC)charToMove; npcToMove.StopFollowing(); } path.pathType = AC_PathType.ForwardOnly; path.pathSpeed = speed; path.affectY = true; Vector3[] pointArray; Vector3 targetPosition = marker.transform.position; if (KickStarter.settingsManager.ActInScreenSpace()) { targetPosition = AdvGame.GetScreenNavMesh(targetPosition); } if (pathFind && KickStarter.navigationManager) { pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(charToMove.transform.position, targetPosition, charToMove); } else { List <Vector3> pointList = new List <Vector3>(); pointList.Add(targetPosition); pointArray = pointList.ToArray(); } if (speed == PathSpeed.Walk) { charToMove.MoveAlongPoints(pointArray, false); } else { charToMove.MoveAlongPoints(pointArray, true); } if (charToMove.GetPath()) { if (!pathFind && doFloat) { charToMove.GetPath().affectY = true; } else { charToMove.GetPath().affectY = false; } } if (willWait) { return(defaultPauseTime); } } } return(0f); } else { if (charToMove.GetPath() == null) { isRunning = false; return(0f); } else { return(defaultPauseTime); } } }
override public float Run() { #if UNITY_WEBGL return(0f); #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 if (!isRunning && filePath != "") { isRunning = true; if (canSkip) { Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.CancelOnInput); } else { Handheld.PlayFullScreenMovie(filePath, Color.black, FullScreenMovieControlMode.Full); } return(defaultPauseTime); } else { isRunning = false; return(0f); } #elif UNITY_5 || UNITY_PRO_LICENSE if (movieClip == null) { ACDebug.LogWarning("Cannot play movie - no movie clip set!"); return(0f); } if (movieClipType == MovieClipType.OnMaterial && material == null) { ACDebug.LogWarning("Cannot play movie - no material has been assigned. A movie clip can only be played as a material's texture, so a material must be assigned."); return(0f); } if (includeAudio && sound == null) { ACDebug.LogWarning("Cannot play movie audio - no Sound object has been assigned."); } if (!isRunning) { isRunning = true; guiTexture = null; KickStarter.playerInput.skipMovieKey = ""; if (movieClipType == MovieClipType.FullScreen) { CreateFullScreenMovie(); } else if (movieClipType == MovieClipType.OnMaterial) { material.mainTexture = movieClip; } movieClip.Play(); if (includeAudio) { sound.GetComponent <AudioSource>().clip = movieClip.audioClip; sound.Play(false); } if (movieClipType == MovieClipType.FullScreen || willWait) { if (canSkip && skipKey != "") { KickStarter.playerInput.skipMovieKey = skipKey; } return(defaultPauseTime); } return(0f); } else { if (movieClip.isPlaying) { if (!canSkip || KickStarter.playerInput.skipMovieKey != "") { return(defaultPauseTime); } } if (includeAudio) { sound.Stop(); } movieClip.Stop(); KickStarter.playerInput.skipMovieKey = ""; if (movieClipType == MovieClipType.FullScreen) { EndFullScreenMovie(); } isRunning = false; return(0f); } #else ACDebug.LogWarning("On non-mobile platforms, this Action is only available in Unity 5 or Unity Pro."); return(0f); #endif }
public override void OnInspectorGUI() { ActionListAsset _target = (ActionListAsset)target; ActionListAssetEditor.ShowPropertiesGUI(_target); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft)) { Undo.RecordObject(_target, "Expand actions"); foreach (AC.Action action in _target.actions) { action.isDisplayed = true; } } if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid)) { Undo.RecordObject(_target, "Collapse actions"); foreach (AC.Action action in _target.actions) { action.isDisplayed = false; } } if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid)) { ActionListEditorWindow.Init(_target); } if (!Application.isPlaying) { GUI.enabled = false; } if (GUILayout.Button("Run now", EditorStyles.miniButtonRight)) { if (KickStarter.actionListAssetManager != null) { if (!_target.canRunMultipleInstances) { int numRemoved = KickStarter.actionListAssetManager.EndAssetList(_target); if (numRemoved > 0) { ACDebug.Log("Removed 1 instance of ActionList asset '" + _target.name + "' because it is set to only run one at a time.", _target); } } AdvGame.RunActionListAsset(_target); } else { ACDebug.LogWarning("An AC PersistentEngine object must be present in the scene for ActionList assets to run.", _target); } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (actionsManager == null) { EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning); OnEnable(); return; } if (!actionsManager.displayActionsInInspector) { EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info); return; } for (int i = 0; i < _target.actions.Count; i++) { int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]); if (_target.actions[i] == null) { _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], typeIndex, _target)); } _target.actions[i].isAssetFile = true; EditorGUILayout.BeginVertical("Button"); string actionLabel = " (" + i + ") " + actionsManager.GetActionTypeLabel(_target.actions[i], true); actionLabel = actionLabel.Replace("\r\n", ""); actionLabel = actionLabel.Replace("\n", ""); actionLabel = actionLabel.Replace("\r", ""); if (actionLabel.Length > 40) { actionLabel = actionLabel.Substring(0, 40) + "..)"; } EditorGUILayout.BeginHorizontal(); _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel); if (!_target.actions[i].isEnabled) { EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.Width(100f)); } if (GUILayout.Button("", CustomStyles.IconCog)) { ActionSideMenu(_target.actions[i]); } EditorGUILayout.EndHorizontal(); if (_target.actions[i].isDisplayed) { if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString())) { EditorGUILayout.HelpBox("This Action type is not listed in the Actions Manager", MessageType.Warning); } else { int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex); if (newTypeIndex >= 0) { // Rebuild constructor if Subclass and type string do not match ActionEnd _end = new ActionEnd(); _end.resultAction = _target.actions[i].endAction; _end.skipAction = _target.actions[i].skipAction; _end.linkedAsset = _target.actions[i].linkedAsset; _end.linkedCutscene = _target.actions[i].linkedCutscene; Undo.RecordObject(_target, "Change Action type"); _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], newTypeIndex, _target, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene)); } EditorGUILayout.Space(); GUI.enabled = _target.actions[i].isEnabled; if (_target.useParameters) { if (Application.isPlaying) { _target.actions[i].AssignValues(_target.parameters); } _target.actions[i].ShowGUI(_target.parameters); } else { if (Application.isPlaying) { _target.actions[i].AssignValues(null); } _target.actions[i].ShowGUI(null); } } GUI.enabled = true; } if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel) { _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } if (GUILayout.Button("Add new Action")) { Undo.RecordObject(_target, "Create action"); AddAction(actionsManager.GetDefaultAction(), _target.actions.Count, _target); } if (GUI.changed) { EditorUtility.SetDirty(_target); } }