コード例 #1
0
        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.PopUp)
            {
                //	var.SetValue (intValue);

                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 ((Options.GetLanguageName() == "Arabic" || Options.GetLanguageName() == "Hebrew") && _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);
            }

            if (location == VariableLocation.Global)
            {
                var.Upload();
            }

            KickStarter.actionListManager.VariableChanged();
        }
コード例 #2
0
ファイル: ActionPlayerSwitch.cs プロジェクト: katuokite/TTLY
        override public float Run()
        {
            if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
            {
                if (KickStarter.sceneChanger.GetSubScenes().Length > 0)
                {
                    //	ACDebug.LogWarning ("Cannot switch players while multiple scenes are open!");
                    //	return 0f;
                }

                if (KickStarter.settingsManager.players.Count > 0 && KickStarter.settingsManager.players.Count > playerNumber && playerNumber > -1)
                {
                    if (KickStarter.player != null && KickStarter.player.ID == playerID)
                    {
                        ACDebug.Log("Cannot switch player - already controlling the desired prefab.");
                        return(0f);
                    }

                    if (KickStarter.settingsManager.players[playerNumber].playerOb != null)
                    {
                        KickStarter.saveSystem.SaveCurrentPlayerData();

                        Vector3    oldPlayerPosition = Vector3.zero;
                        Quaternion oldPlayerRotation = new Quaternion();
                        Vector3    oldPlayerScale    = Vector3.one;

                        if (KickStarter.player != null)
                        {
                            oldPlayerPosition = KickStarter.player.transform.position;
                            oldPlayerRotation = KickStarter.player.TransformRotation;
                            oldPlayerScale    = KickStarter.player.transform.localScale;
                        }

                        if (newPlayerPosition != NewPlayerPosition.ReplaceCurrentPlayer)
                        {
                            if (oldPlayer == OldPlayer.ReplaceWithAssociatedNPC && (oldPlayerNPC == null || !oldPlayerNPC.gameObject.activeInHierarchy) && KickStarter.player.associatedNPCPrefab != null)
                            {
                                GameObject newObject = (GameObject)Instantiate(KickStarter.player.associatedNPCPrefab.gameObject);
                                newObject.name = KickStarter.player.associatedNPCPrefab.gameObject.name;
                                oldPlayerNPC   = newObject.GetComponent <NPC>();
                            }

                            if ((oldPlayer == OldPlayer.ReplaceWithNPC || oldPlayer == OldPlayer.ReplaceWithAssociatedNPC) &&
                                oldPlayerNPC != null && oldPlayerNPC.gameObject.activeInHierarchy)
                            {
                                oldPlayerNPC.transform.position   = oldPlayerPosition;
                                oldPlayerNPC.TransformRotation    = oldPlayerRotation;
                                oldPlayerNPC.transform.localScale = oldPlayerScale;

                                // Force the rotation / sprite child to update
                                oldPlayerNPC._Update();
                            }
                        }

                        if (newPlayerNPC == null || newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC)
                        {
                            // Try to find from associated NPC prefab

                            if (KickStarter.settingsManager.players[playerNumber].playerOb.associatedNPCPrefab != null)
                            {
                                ConstantID prefabID = KickStarter.settingsManager.players[playerNumber].playerOb.associatedNPCPrefab.GetComponent <ConstantID>();
                                if (prefabID != null && prefabID.constantID != 0)
                                {
                                    newPlayerNPC_ID = prefabID.constantID;
                                    newPlayerNPC    = AssignFile <NPC> (prefabID.constantID, null);
                                }
                            }
                        }

                        Quaternion newRotation = Quaternion.identity;
                        if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
                        {
                            newRotation = oldPlayerRotation;
                        }
                        else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC && newPlayerNPC)
                        {
                            newRotation = newPlayerNPC.TransformRotation;
                        }
                        else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker && newPlayerMarker)
                        {
                            newRotation = newPlayerMarker.transform.rotation;
                        }

                        KickStarter.ResetPlayer(KickStarter.settingsManager.players[playerNumber].playerOb, playerID, true, newRotation, keepInventory);
                        Player newPlayer = KickStarter.player;
                        PlayerMenus.ResetInventoryBoxes();

                        if (restorePreviousData && KickStarter.saveSystem.DoesPlayerDataExist(playerID, true))
                        {
                            if (newPlayerNPC)
                            {
                                newPlayerNPC.transform.position += new Vector3(100f, -100f, 100f);
                            }

                            int sceneToLoad = KickStarter.saveSystem.GetPlayerScene(playerID);
                            if (sceneToLoad >= 0 && sceneToLoad != UnityVersionHandler.GetCurrentSceneNumber())
                            {
                                KickStarter.saveSystem.loadingGame = LoadingGame.JustSwitchingPlayer;
                                KickStarter.sceneChanger.ChangeScene(new SceneInfo("", sceneToLoad), true, false, newPlayerNPC_ID);
                            }
                            else
                            {
                                string sceneToLoadName = KickStarter.saveSystem.GetPlayerSceneName(playerID);
                                if (sceneToLoadName != "" && sceneToLoadName != UnityVersionHandler.GetCurrentSceneName())
                                {
                                    KickStarter.saveSystem.loadingGame = LoadingGame.JustSwitchingPlayer;
                                    KickStarter.sceneChanger.ChangeScene(new SceneInfo(sceneToLoadName, -1), true, false, newPlayerNPC_ID);
                                }
                            }
                        }
                        else
                        {
                            // No data to restore

                            if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
                            {
                                newPlayer.Teleport(oldPlayerPosition);
                                newPlayer.SetRotation(oldPlayerRotation);
                                newPlayer.transform.localScale = oldPlayerScale;
                            }
                            else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC || newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC)
                            {
                                if (newPlayerNPC)
                                {
                                    newPlayer.Teleport(newPlayerNPC.transform.position);
                                    newPlayer.SetRotation(newPlayerNPC.TransformRotation);
                                    newPlayer.transform.localScale = newPlayerNPC.transform.localScale;

                                    newPlayerNPC.transform.position += new Vector3(100f, -100f, 100f);
                                }
                            }
                            else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker)
                            {
                                if (newPlayerMarker)
                                {
                                    newPlayer.Teleport(newPlayerMarker.transform.position);
                                    newPlayer.SetRotation(newPlayerMarker.transform.rotation);
                                    newPlayer.transform.localScale = newPlayerMarker.transform.localScale;
                                }
                            }
                            else if (newPlayerPosition == NewPlayerPosition.AppearInOtherScene)
                            {
                                if (chooseNewSceneBy == ChooseSceneBy.Name && newPlayerSceneName == UnityVersionHandler.GetCurrentSceneName() ||
                                    (chooseNewSceneBy == ChooseSceneBy.Number && newPlayerScene == UnityVersionHandler.GetCurrentSceneNumber()))
                                {
                                    // Already in correct scene
                                    if (newPlayerNPC && newPlayerNPC.gameObject.activeInHierarchy)
                                    {
                                        newPlayer.Teleport(newPlayerNPC.transform.position);
                                        newPlayer.SetRotation(newPlayerNPC.TransformRotation);
                                        newPlayer.transform.localScale = newPlayerNPC.transform.localScale;

                                        newPlayerNPC.transform.position += new Vector3(100f, -100f, 100f);
                                    }
                                }
                                else
                                {
                                    if (newPlayerNPC && newPlayerNPC.gameObject.activeInHierarchy)
                                    {
                                        newPlayerNPC.transform.position += new Vector3(100f, -100f, 100f);
                                    }

                                    //KickStarter.saveSystem.loadingGame = LoadingGame.JustSwitchingPlayer;
                                    KickStarter.sceneChanger.ChangeScene(new SceneInfo(chooseNewSceneBy, newPlayerSceneName, newPlayerScene), true, false, newPlayerNPC_ID, true);
                                }
                            }
                        }

                        if (KickStarter.mainCamera.attachedCamera)
                        {
                            KickStarter.mainCamera.attachedCamera.MoveCameraInstant();
                        }

                        AssetLoader.UnloadAssets();
                    }
                    else
                    {
                        ACDebug.LogWarning("Cannot switch player - no player prefabs is defined.");
                    }
                }
            }

            return(0f);
        }
コード例 #3
0
ファイル: ActionContainerSet.cs プロジェクト: katuokite/TTLY
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            if (AdvGame.GetReferences().inventoryManager)
            {
                inventoryManager = AdvGame.GetReferences().inventoryManager;
            }

            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 (invParameterID == -1)
                {
                    invNumber = -1;
                }

                if (inventoryManager.items.Count > 0)
                {
                    foreach (InvItem _item in inventoryManager.items)
                    {
                        labelList.Add(_item.label);

                        // If a 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!");
                        invNumber = 0;
                        invID     = 0;
                    }

                    useActive = EditorGUILayout.Toggle("Affect active container?", useActive);
                    if (!useActive)
                    {
                        parameterID = Action.ChooseParameterGUI("Container:", parameters, parameterID, ParameterType.GameObject);
                        if (parameterID >= 0)
                        {
                            constantID = 0;
                            container  = null;
                        }
                        else
                        {
                            container = (Container)EditorGUILayout.ObjectField("Container:", container, typeof(Container), true);

                            constantID = FieldToID <Container> (container, constantID);
                            container  = IDToField <Container> (container, constantID, false);
                        }
                    }

                    containerAction = (ContainerAction)EditorGUILayout.EnumPopup("Method:", containerAction);

                    if (containerAction == ContainerAction.RemoveAll)
                    {
                        transferToPlayer = EditorGUILayout.Toggle("Transfer to Player?", transferToPlayer);
                    }
                    else
                    {
                        //
                        invParameterID = Action.ChooseParameterGUI("Inventory item:", parameters, invParameterID, ParameterType.InventoryItem);
                        if (invParameterID >= 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 (containerAction == ContainerAction.Remove)
                        {
                            transferToPlayer = EditorGUILayout.Toggle("Transfer to Player?", transferToPlayer);
                        }

                        if (inventoryManager.items[invNumber].canCarryMultiple)
                        {
                            setAmount = EditorGUILayout.Toggle("Set amount?", setAmount);

                            if (setAmount)
                            {
                                string _label = (containerAction == ContainerAction.Add) ? "Increase count by:" : "Reduce count by:";

                                amountParameterID = Action.ChooseParameterGUI(_label, parameters, amountParameterID, ParameterType.Integer);
                                if (amountParameterID < 0)
                                {
                                    amount = EditorGUILayout.IntField(_label, amount);
                                }
                            }
                        }
                    }

                    AfterRunningOption();
                }

                else
                {
                    EditorGUILayout.LabelField("No inventory items exist!");
                    invID     = -1;
                    invNumber = -1;
                }
            }
        }
コード例 #4
0
        override public float Run()
        {
            if (!isRunning)
            {
                isRunning = true;

                MainCamera mainCam = KickStarter.mainCamera;

                if (mainCam)
                {
                    _Camera cam = linkedCamera;

                    if (returnToLast)
                    {
                        cam = mainCam.GetLastGameplayCamera();
                    }

                    if (cam)
                    {
                        if (mainCam.attachedCamera != cam)
                        {
                            if (cam is GameCameraThirdPerson)
                            {
                                GameCameraThirdPerson tpCam = (GameCameraThirdPerson)cam;
                                tpCam.ResetRotation();
                            }
                            else if (cam is GameCameraAnimated)
                            {
                                GameCameraAnimated animCam = (GameCameraAnimated)cam;
                                animCam.PlayClip();
                            }

                            if (transitionTime > 0f && linkedCamera is GameCamera25D)
                            {
                                mainCam.SetGameCamera(cam, 0f);
                                ACDebug.LogWarning("Switching to a 2.5D camera (" + linkedCamera.name + ") must be instantaneous.");
                            }
                            else
                            {
                                mainCam.SetGameCamera(cam, transitionTime, moveMethod, timeCurve, retainPreviousSpeed);

                                if (willWait)
                                {
                                    if (transitionTime > 0f)
                                    {
                                        return(transitionTime);
                                    }
                                    else if (linkedCamera is GameCameraAnimated)
                                    {
                                        return(defaultPauseTime);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (linkedCamera is GameCameraAnimated && willWait)
                {
                    GameCameraAnimated animatedCamera = (GameCameraAnimated)linkedCamera;
                    if (animatedCamera.isPlaying())
                    {
                        return(defaultPauseTime);
                    }
                    else
                    {
                        isRunning = false;
                        return(0f);
                    }
                }
                else
                {
                    isRunning = false;
                    return(0f);
                }
            }

            return(0f);
        }
コード例 #5
0
        private void SendParameters(List <ActionParameter> externalParameters, bool sendingToAsset)
        {
            if (!setParameters)
            {
                return;
            }

            for (int i = 0; i < externalParameters.Count; i++)
            {
                if (localParameters.Count > i)
                {
                    if (externalParameters[i].parameterType == ParameterType.String)
                    {
                        externalParameters[i].SetValue(localParameters[i].stringValue);
                    }
                    else if (externalParameters[i].parameterType == ParameterType.Float)
                    {
                        externalParameters[i].SetValue(localParameters[i].floatValue);
                    }
                    else if (externalParameters[i].parameterType == ParameterType.UnityObject)
                    {
                        externalParameters[i].SetValue(localParameters[i].objectValue);
                    }
                    else if (externalParameters[i].parameterType != ParameterType.GameObject)
                    {
                        externalParameters[i].SetValue(localParameters[i].intValue);
                    }
                    else
                    {
                        if (sendingToAsset)
                        {
                            if (isAssetFile)
                            {
                                //externalParameters[i].SetValue (localParameters[i].intValue);

                                if (localParameters[i].gameObject != null)
                                {
                                    externalParameters[i].SetValue(localParameters[i].gameObject);
                                }
                                else
                                {
                                    externalParameters[i].SetValue(localParameters[i].intValue);
                                }
                            }
                            else if (localParameters[i].gameObject != null)
                            {
                                int idToSend = 0;
                                if (localParameters[i].gameObject && localParameters[i].gameObject.GetComponent <ConstantID>())
                                {
                                    idToSend = localParameters[i].gameObject.GetComponent <ConstantID>().constantID;
                                }
                                else
                                {
                                    ACDebug.LogWarning(localParameters[i].gameObject.name + " requires a ConstantID script component!");
                                }
                                externalParameters[i].SetValue(localParameters[i].gameObject, idToSend);
                            }
                            else
                            {
                                externalParameters[i].SetValue(localParameters[i].intValue);
                            }
                        }
                        else if (localParameters[i].gameObject != null)
                        {
                            externalParameters[i].SetValue(localParameters[i].gameObject);
                        }
                        else
                        {
                            externalParameters[i].SetValue(localParameters[i].intValue);
                        }
                    }
                }
            }
        }
コード例 #6
0
 public override void TurnOn(NavigationMesh navMesh)
 {
     ACDebug.LogWarning("Cannot enable NavMesh " + navMesh.gameObject.name + " as this scene's Navigation Method is Unity Navigation.");
 }
コード例 #7
0
        override public float Run()
        {
            if (_gameObject == null)
            {
                return(0f);
            }

            if (invAction == InvAction.Add)
            {
                // Instantiate

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (_gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    ACDebug.Log(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                    return(0f);
                }

                Vector3    position = _gameObject.transform.position;
                Quaternion rotation = _gameObject.transform.rotation;

                if (positionRelativeTo != PositionRelativeTo.Nothing)
                {
                    float forward = _gameObject.transform.position.z;
                    float right   = _gameObject.transform.position.x;
                    float up      = _gameObject.transform.position.y;

                    if (positionRelativeTo == PositionRelativeTo.RelativeToActiveCamera)
                    {
                        Transform mainCam = KickStarter.mainCamera.transform;
                        position              = mainCam.position + (mainCam.forward * forward) + (mainCam.right * right) + (mainCam.up * up);
                        rotation.eulerAngles += mainCam.transform.rotation.eulerAngles;
                    }
                    else if (positionRelativeTo == PositionRelativeTo.RelativeToPlayer)
                    {
                        if (KickStarter.player)
                        {
                            Transform playerTranform = KickStarter.player.transform;
                            position              = playerTranform.position + (playerTranform.forward * forward) + (playerTranform.right * right) + (playerTranform.up * up);
                            rotation.eulerAngles += playerTranform.rotation.eulerAngles;
                        }
                    }
                }

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;
                KickStarter.stateHandler.GatherObjects();
            }
            else if (invAction == InvAction.Remove)
            {
                // Delete
                KickStarter.sceneSettings.ScheduleForDeletion(_gameObject);
            }
            else if (invAction == InvAction.Replace)
            {
                if (replaceGameObject == null)
                {
                    ACDebug.LogWarning("Cannot perform swap because the object to remove was not found in the scene.");
                    return(0f);
                }

                Vector3    position = replaceGameObject.transform.position;
                Quaternion rotation = replaceGameObject.transform.rotation;

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    ACDebug.Log(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                    return(0f);
                }

                KickStarter.sceneSettings.ScheduleForDeletion(replaceGameObject);

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;
                KickStarter.stateHandler.GatherObjects();
            }

            return(0f);
        }
コード例 #8
0
        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
                                if (invButton.invID > 0)
                                {
                                    ACDebug.Log("Previously chosen item no longer exists!");
                                }
                                invNumber       = 0;
                                invButton.invID = 0;
                            }

                            EditorGUILayout.Space();
                            EditorGUILayout.BeginHorizontal();

                            invNumber = CustomGUILayout.Popup("Inventory item:", invNumber, labelList.ToArray(), "", "The inventory item associated with the interaction");

                            // 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(string.Empty, CustomStyles.IconCog))
                            {
                                SideMenu("Inv", _target.invButtons.Count, _target.invButtons.IndexOf(invButton));
                            }


                            EditorGUILayout.EndHorizontal();
                            if (!string.IsNullOrEmpty(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(string.Empty, 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();
        }
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            if (KickStarter.settingsManager != null)
            {
                if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.DoNotAllow)
                {
                    EditorGUILayout.HelpBox("This Action requires Player Switching to be allowed, as set in the Settings Manager.", MessageType.Info);
                    return;
                }

                if (KickStarter.settingsManager.players.Count == 0)
                {
                    EditorGUILayout.HelpBox("No players are defined in the Settings Manager.", MessageType.Warning);
                    return;
                }

                playerIDParameterID = Action.ChooseParameterGUI("New Player ID:", parameters, playerIDParameterID, ParameterType.Integer);
                if (playerIDParameterID == -1)
                {
                    // Create a string List of the field's names (for the PopUp box)
                    List <string> labelList = new List <string>();

                    int i            = 0;
                    int playerNumber = -1;

                    foreach (PlayerPrefab playerPrefab in KickStarter.settingsManager.players)
                    {
                        if (playerPrefab.playerOb != null)
                        {
                            labelList.Add(playerPrefab.playerOb.name);
                        }
                        else
                        {
                            labelList.Add("(Undefined prefab)");
                        }

                        // If a player has been removed, make sure selected player is still valid
                        if (playerPrefab.ID == playerID)
                        {
                            playerNumber = i;
                        }

                        i++;
                    }

                    if (playerNumber == -1)
                    {
                        // Wasn't found (item was possibly deleted), so revert to zero
                        ACDebug.LogWarning("Previously chosen Player no longer exists!");

                        playerNumber = 0;
                        playerID     = 0;
                    }

                    playerNumber = EditorGUILayout.Popup("New Player:", playerNumber, labelList.ToArray());
                    playerID     = KickStarter.settingsManager.players[playerNumber].ID;
                }

                newTransformParameterID = Action.ChooseParameterGUI("New Transform:", parameters, newTransformParameterID, ParameterType.GameObject);
                if (newTransformParameterID >= 0)
                {
                    newTransformConstantID = 0;
                    newTransform           = null;
                }
                else
                {
                    newTransform = (Transform)EditorGUILayout.ObjectField("New Transform:", newTransform, typeof(Transform), true);

                    newTransformConstantID = FieldToID(newTransform, newTransformConstantID);
                    newTransform           = IDToField(newTransform, newTransformConstantID, true);
                }

                associatedCameraParameterID = Action.ChooseParameterGUI("Camera (optional):", parameters, associatedCameraParameterID, ParameterType.GameObject);
                if (associatedCameraParameterID >= 0)
                {
                    associatedCameraConstantID = 0;
                    associatedCamera           = null;
                }
                else
                {
                    associatedCamera = (_Camera)EditorGUILayout.ObjectField("Camera (optional):", associatedCamera, typeof(_Camera), true);

                    associatedCameraConstantID = FieldToID(associatedCamera, associatedCameraConstantID);
                    associatedCamera           = IDToField(associatedCamera, associatedCameraConstantID, true);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("No Settings Manager assigned!", MessageType.Warning);
            }

            AfterRunningOption();
        }
コード例 #10
0
        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.id.ToString() + ": " + _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 = CustomGUILayout.Popup("Cursor / icon:", iconNumber, labelList.ToArray(), "", "The cursor/icon associated with the interaction");

                            // Re-assign variableID based on PopUp selection
                            useButton.iconID = cursorManager.cursorIcons[iconNumber].id;
                            string iconLabel = cursorManager.cursorIcons[iconNumber].label;

                            if (GUILayout.Button("", CustomStyles.IconCog))
                            {
                                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();
        }
コード例 #11
0
        public override void OnInspectorGUI()
        {
            if (AdvGame.GetReferences() == null)
            {
                ACDebug.LogError("A References file is required - please use the Adventure Creator window to create one.");
                EditorGUILayout.LabelField("No References file found!");
            }
            else
            {
                if (AdvGame.GetReferences().inventoryManager)
                {
                    inventoryManager = AdvGame.GetReferences().inventoryManager;
                }
                if (AdvGame.GetReferences().cursorManager)
                {
                    cursorManager = AdvGame.GetReferences().cursorManager;
                }
                if (AdvGame.GetReferences().settingsManager)
                {
                    settingsManager = AdvGame.GetReferences().settingsManager;
                }

                if (Application.isPlaying)
                {
                    if (_target.gameObject.layer != LayerMask.NameToLayer(settingsManager.hotspotLayer))
                    {
                        EditorGUILayout.HelpBox("Current state: OFF", MessageType.Info);
                    }
                }

                if (_target.lineID > -1)
                {
                    EditorGUILayout.LabelField("Speech Manager ID:", _target.lineID.ToString());
                }

                _target.interactionSource = (AC.InteractionSource)CustomGUILayout.EnumPopup("Interaction source:", _target.interactionSource, "", "The source of the commands that are run when an option is chosen");
                _target.hotspotName       = CustomGUILayout.TextField("Label (if not name):", _target.hotspotName, "", "The display name, if not the GameObject's name");
                _target.highlight         = (Highlight)CustomGUILayout.ObjectField <Highlight> ("Object to highlight:", _target.highlight, true, "", "The Highlight component that controls any highlighting effects associated with the Hotspot");

                if (AdvGame.GetReferences().settingsManager != null && AdvGame.GetReferences().settingsManager.hotspotDrawing == ScreenWorld.WorldSpace)
                {
                    _target.iconSortingLayer = CustomGUILayout.TextField("Icon sorting layer:", _target.iconSortingLayer, "", "The 'Sorting Layer' of the icon's SpriteRenderer");
                    _target.iconSortingOrder = CustomGUILayout.IntField("Icon sprite order:", _target.iconSortingOrder, "", "The 'Order in Layer' of the icon's SpriteRenderer");
                }

                EditorGUILayout.BeginHorizontal();
                _target.centrePoint = (Transform)CustomGUILayout.ObjectField <Transform> ("Centre point (override):", _target.centrePoint, true, "", "A Transform that represents the centre of the Hotspot, if it is not physically at the same point as the Hotspot's GameObject itself");

                if (_target.centrePoint == null)
                {
                    if (GUILayout.Button("Create", autoWidth))
                    {
                        string     prefabName = "Hotspot centre: " + _target.gameObject.name;
                        GameObject go         = SceneManager.AddPrefab("Navigation", "HotspotCentre", true, false, false);
                        go.name = prefabName;
                        go.transform.position = _target.transform.position;
                        _target.centrePoint   = go.transform;
                        go.transform.parent   = _target.transform;
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                _target.walkToMarker = (Marker)CustomGUILayout.ObjectField <Marker> ("Walk-to Marker:", _target.walkToMarker, true, "", "The Marker that the player can optionally automatically walk to before an Interaction runs");
                if (_target.walkToMarker == null)
                {
                    if (GUILayout.Button("Create", autoWidth))
                    {
                        string prefabName = "Marker";
                        if (SceneSettings.IsUnity2D())
                        {
                            prefabName += "2D";
                        }
                        Marker newMarker = SceneManager.AddPrefab("Navigation", prefabName, true, false, true).GetComponent <Marker>();
                        newMarker.gameObject.name   += (": " + _target.gameObject.name);
                        newMarker.transform.position = _target.transform.position;
                        _target.walkToMarker         = newMarker;
                    }
                }
                EditorGUILayout.EndHorizontal();

                _target.limitToCamera = (_Camera)CustomGUILayout.ObjectField <_Camera> ("Limit to camera:", _target.limitToCamera, true, "", "If assigned, then the Hotspot will only be interactive when the assigned _Camera is active");

                EditorGUILayout.BeginHorizontal();
                _target.interactiveBoundary = (InteractiveBoundary)CustomGUILayout.ObjectField <InteractiveBoundary> ("Interactive boundary:", _target.interactiveBoundary, true, "", "If assigned, then the Hotspot will only be interactive when the player is within this Trigger Collider's boundary");
                if (_target.interactiveBoundary == null)
                {
                    if (GUILayout.Button("Create", autoWidth))
                    {
                        string prefabName = "InteractiveBoundary";
                        if (SceneSettings.IsUnity2D())
                        {
                            prefabName += "2D";
                        }
                        InteractiveBoundary newInteractiveBoundary = SceneManager.AddPrefab("Logic", prefabName, true, false, true).GetComponent <InteractiveBoundary>();
                        newInteractiveBoundary.gameObject.name   += (": " + _target.gameObject.name);
                        newInteractiveBoundary.transform.position = _target.transform.position;
                        _target.interactiveBoundary = newInteractiveBoundary;

                        UnityVersionHandler.PutInFolder(newInteractiveBoundary.gameObject, "_Hotspots");
                    }
                }
                EditorGUILayout.EndHorizontal();

                _target.drawGizmos = CustomGUILayout.Toggle("Draw yellow cube?", _target.drawGizmos, "", "If True, then a Gizmo may be drawn in the Scene window at the Hotspots's position");

                if (settingsManager != null && (settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction || settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot || settingsManager.interactionMethod == AC_InteractionMethod.CustomScript))
                {
                    _target.oneClick = CustomGUILayout.Toggle("Single 'Use' Interaction?", _target.oneClick, "", "If True, then clicking the Hotspot will run the Hotspot's first interaction in useButtons, regardless of the Settings Manager's Interaction method");

                    if (_target.oneClick && settingsManager.interactionMethod == AC_InteractionMethod.CustomScript)
                    {
                        EditorGUILayout.HelpBox("The above property can be accessed by reading the Hotspot script's IsSingleInteraction() method.", MessageType.Info);
                    }
                }
                if (_target.oneClick || (settingsManager != null && settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive))
                {
                    if (settingsManager != null && settingsManager.interactionMethod == AC_InteractionMethod.CustomScript)
                    {
                    }
                    else
                    {
                        _target.doubleClickingHotspot = (DoubleClickingHotspot)CustomGUILayout.EnumPopup("Double-clicking:", _target.doubleClickingHotspot, "", "The effect that double-clicking on the Hotspot has");
                    }
                }
                if (settingsManager != null && settingsManager.playerFacesHotspots)
                {
                    _target.playerTurnsHead = CustomGUILayout.Toggle("Players turn heads when active?", _target.playerTurnsHead, "", "If True, then the player will turn their head when the Hotspot is selected");
                }

                EditorGUILayout.Space();

                UseInteractionGUI();

                if (settingsManager == null || settingsManager.interactionMethod == AC_InteractionMethod.ContextSensitive || settingsManager.interactionMethod == AC_InteractionMethod.CustomScript)
                {
                    EditorGUILayout.Space();
                    LookInteractionGUI();
                }

                EditorGUILayout.Space();
                InvInteractionGUI();

                if (KickStarter.cursorManager != null && KickStarter.cursorManager.AllowUnhandledIcons())
                {
                    EditorGUILayout.Space();
                    UnhandledUseInteractionGUI();
                }

                EditorGUILayout.Space();
                UnhandledInvInteractionGUI();
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }
コード例 #12
0
        public static void FindGlobalReferences(MenuCommand command)
        {
            ConstantID _constantID = (ConstantID)command.context;

            if (_constantID)
            {
                if (_constantID.constantID == 0)
                {
                    ACDebug.LogWarning("Cannot find references for " + _constantID.name + " because it's ConstantID value is zero!", _constantID);
                    return;
                }

                if (EditorUtility.DisplayDialog("Search '" + _constantID.gameObject.name + "' references?", "The Editor will search assets, and active scenes listed in the Build Settings, for references to this GameObject.  The current scene will need to be saved and listed to be included in the search process. Continue?", "OK", "Cancel"))
                {
                    if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                    {
                        // Menus
                        if (KickStarter.menuManager)
                        {
                            foreach (Menu menu in KickStarter.menuManager.menus)
                            {
                                if (menu.IsUnityUI())
                                {
                                    if (menu.ReferencesObjectOrID(_constantID.gameObject, _constantID.constantID))
                                    {
                                        Debug.Log("'" + _constantID.gameObject.name + "' is referenced by Menu '" + menu.title + "'");
                                    }

                                    foreach (MenuElement element in menu.elements)
                                    {
                                        if (element != null && element.ReferencesObjectOrID(_constantID.gameObject, _constantID.constantID))
                                        {
                                            Debug.Log("'" + _constantID.gameObject.name + "' is referenced by Menu Element '" + element.title + "' in Menu '" + menu.title + "'");
                                        }
                                    }
                                }
                            }
                        }

                        // ActionList assets
                        if (AdvGame.GetReferences().speechManager)
                        {
                            ActionListAsset[] allActionListAssets = AdvGame.GetReferences().speechManager.GetAllActionListAssets();
                            foreach (ActionListAsset actionListAsset in allActionListAssets)
                            {
                                SearchActionListAssetForReferences(_constantID, actionListAsset);
                            }
                        }

                        // Scenes
                        string   originalScene = UnityVersionHandler.GetCurrentSceneFilepath();
                        string[] sceneFiles    = AdvGame.GetSceneFiles();

                        foreach (string sceneFile in sceneFiles)
                        {
                            UnityVersionHandler.OpenScene(sceneFile);

                            string suffix = " in scene '" + sceneFile + "'";
                            SearchSceneForReferences(_constantID, suffix);
                        }

                        UnityVersionHandler.OpenScene(originalScene);
                    }
                }
            }
        }
コード例 #13
0
        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();

            if (_target.source == ActionListSource.InScene)
            {
                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 || _target.source == ActionListSource.AssetFile)
            {
                if (Application.isPlaying)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Edit Actions", GUILayout.Height(40f)))
                    {
                        ActionListEditorWindow.OpenForActionList(_target);
                    }

                    bool isRunning = false;
                    if (Application.isPlaying)
                    {
                        if (KickStarter.actionListManager != null)
                        {
                            isRunning = KickStarter.actionListManager.IsListRunning(_target);
                        }
                    }

                    if (isRunning)
                    {
                        if (GUILayout.Button("Stop", GUILayout.Height(40f)))
                        {
                            _target.Kill();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Run now", GUILayout.Height(40f)))
                        {
                            _target.Interact();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    if (GUILayout.Button("Edit Actions", GUILayout.Height(40f)))
                    {
                        ActionListEditorWindow.OpenForActionList(_target);
                    }
                }
                return;
            }
            else
            {
                EditorGUILayout.BeginHorizontal();

                GUI.enabled = (_target.source == ActionListSource.InScene);

                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))
                {
                    ActionListEditorWindow.OpenForActionList(_target);
                }
                GUI.enabled = Application.isPlaying;
                if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
                {
                    _target.Interact();
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            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);
                    _target.actions.RemoveAt(i);
                    numActions--;
                    continue;
                }

                _target.actions[i].AssignParentList(_target);

                CustomGUILayout.BeginVertical();
                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.NumParameters > 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;

                CustomGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new action"))
            {
                Undo.RecordObject(_target, "Create action");
                numActions += 1;
            }

            _target = ActionListEditor.ResizeList(_target, numActions);
        }
コード例 #14
0
        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);
                        }
                    }
                }

                AfterRunningOption();
            }
            else
            {
                EditorGUILayout.HelpBox("No variables exist!", MessageType.Info);
                variableID     = -1;
                variableNumber = -1;
            }
        }
コード例 #15
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            if (AdvGame.GetReferences().inventoryManager)
            {
                inventoryManager = AdvGame.GetReferences().inventoryManager;
            }

            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 (invParameterID == -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;
                    }

                    useActive = EditorGUILayout.Toggle("Affect active container?", useActive);
                    if (!useActive)
                    {
                        parameterID = Action.ChooseParameterGUI("Container:", parameters, parameterID, ParameterType.GameObject);
                        if (parameterID >= 0)
                        {
                            constantID = 0;
                            container  = null;
                        }
                        else
                        {
                            container = (Container)EditorGUILayout.ObjectField("Container:", container, typeof(Container), true);

                            constantID = FieldToID <Container> (container, constantID);
                            container  = IDToField <Container> (container, constantID, false);
                        }
                    }

                    //
                    invParameterID = Action.ChooseParameterGUI("Item to check:", parameters, invParameterID, ParameterType.InventoryItem);
                    if (invParameterID >= 0)
                    {
                        invNumber = Mathf.Min(invNumber, inventoryManager.items.Count - 1);
                        invID     = -1;
                    }
                    else
                    {
                        invNumber = EditorGUILayout.Popup("Item to check:", invNumber, labelList.ToArray());
                        invID     = inventoryManager.items[invNumber].id;
                    }
                    //

                    if (inventoryManager.items[invNumber].canCarryMultiple)
                    {
                        doCount = EditorGUILayout.Toggle("Query count?", doCount);

                        if (doCount)
                        {
                            EditorGUILayout.BeginHorizontal("");
                            EditorGUILayout.LabelField("Count is:", GUILayout.MaxWidth(70));
                            intCondition = (IntCondition)EditorGUILayout.EnumPopup(intCondition);
                            intValue     = EditorGUILayout.IntField(intValue);

                            if (intValue < 1)
                            {
                                intValue = 1;
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    else
                    {
                        doCount = false;
                    }
                }

                else
                {
                    EditorGUILayout.LabelField("No inventory items exist!");
                    invID     = -1;
                    invNumber = -1;
                }
            }
        }
コード例 #16
0
        /**
         * <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 = transform.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    = GetPrevNode();
                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");
                }
                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");
                        playerData.customSortingMapID = 0;
                    }
                }
                else
                {
                    playerData.customSortingMapID = 0;
                }
            }
            else
            {
                playerData.followSortingMap   = false;
                playerData.customSortingMapID = 0;
            }

            return(playerData);
        }
コード例 #17
0
        private void UpdateValue()
        {
            if (uiSlider == null)
            {
                visualAmount = Mathf.Clamp(visualAmount, 0f, 1f);

                // Limit by steps
                if (numberOfSteps > 0)
                {
                    visualAmount = Mathf.Round(visualAmount * numberOfSteps) / numberOfSteps;
                }

                amount = (visualAmount * (maxValue - minValue)) + minValue;
            }
            else
            {
                amount = visualAmount;
            }

            if (sliderType == AC_SliderType.Speech || sliderType == AC_SliderType.SFX || sliderType == AC_SliderType.Music)
            {
                if (Options.optionsData != null)
                {
                    if (sliderType == AC_SliderType.Speech)
                    {
                        Options.optionsData.speechVolume = amount;
                        KickStarter.options.SetVolume(SoundType.SFX);
                    }
                    else if (sliderType == AC_SliderType.Music)
                    {
                        Options.optionsData.musicVolume = amount;
                        KickStarter.options.SetVolume(SoundType.Music);
                    }
                    else if (sliderType == AC_SliderType.SFX)
                    {
                        Options.optionsData.sfxVolume = amount;
                        KickStarter.options.SetVolume(SoundType.SFX);
                    }

                                        #if UNITY_5
                    if (sliderType == AC_SliderType.Speech)
                    {
                        AdvGame.SetMixerVolume(KickStarter.settingsManager.speechMixerGroup, KickStarter.settingsManager.speechAttentuationParameter, amount);
                    }
                    else if (sliderType == AC_SliderType.Music)
                    {
                        AdvGame.SetMixerVolume(KickStarter.settingsManager.musicMixerGroup, KickStarter.settingsManager.musicAttentuationParameter, amount);
                    }
                    else if (sliderType == AC_SliderType.SFX)
                    {
                        AdvGame.SetMixerVolume(KickStarter.settingsManager.sfxMixerGroup, KickStarter.settingsManager.sfxAttentuationParameter, amount);
                    }
                                        #endif

                    Options.SavePrefs();
                }
                else
                {
                    ACDebug.LogWarning("Could not find Options data!");
                }
            }
            else if (sliderType == AC_SliderType.FloatVariable)
            {
                if (varID >= 0)
                {
                    GVar var = GlobalVariables.GetVariable(varID);
                    if (var.type == VariableType.Float)
                    {
                        var.SetFloatValue(amount);
                    }
                }
            }

            if (!KickStarter.actionListAssetManager.IsListRunning(actionListOnChange))
            {
                AdvGame.RunActionListAsset(actionListOnChange);
            }
        }
コード例 #18
0
        override public 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);
            }
        }
コード例 #19
0
        private void ProcessActionEnd(ActionEnd actionEnd, int i, bool doStackOverflowDelay = false)
        {
            if (isSkipping && skipIteractions > (actions.Count * 3))
            {
                // StackOverFlow
                ACDebug.LogWarning("Looping ActionList '" + gameObject.name + "' detected while skipping - ending prematurely to avoid a StackOverflow exception.");
                CheckEndCutscene();
                return;
            }

            if (pauseWhenActionFinishes)
            {
                resumeIndices.Add(i);
                if (!AreActionsRunning())
                {
                    FinishPause();
                }
                return;
            }

            if (actionEnd.resultAction == ResultAction.RunCutscene)
            {
                if (actionEnd.linkedAsset != null)
                {
                    if (isSkipping)
                    {
                        AdvGame.SkipActionListAsset(actionEnd.linkedAsset);
                    }
                    else
                    {
                        AdvGame.RunActionListAsset(actionEnd.linkedAsset, 0, !IsSkippable());
                    }
                    CheckEndCutscene();
                }
                else if (actionEnd.linkedCutscene != null)
                {
                    if (actionEnd.linkedCutscene != this)
                    {
                        if (isSkipping)
                        {
                            actionEnd.linkedCutscene.Skip();
                        }
                        else
                        {
                            actionEnd.linkedCutscene.Interact(0, !IsSkippable());
                        }
                        CheckEndCutscene();
                    }
                    else
                    {
                        if (triggerTime > 0f)
                        {
                            Kill();
                            StartCoroutine("PauseUntilStart", !IsSkippable());
                        }
                        else
                        {
                            ProcessAction(0);
                        }
                    }
                }
                else
                {
                    CheckEndCutscene();
                }
            }
            else if (actionEnd.resultAction == ResultAction.Stop)
            {
                CheckEndCutscene();
            }
            else if (actionEnd.resultAction == ResultAction.Skip)
            {
                if (doStackOverflowDelay)
                {
                    StartCoroutine(DelayProcessAction(actionEnd.skipAction));
                }
                else
                {
                    ProcessAction(actionEnd.skipAction);
                }
            }
            else if (actionEnd.resultAction == ResultAction.Continue)
            {
                ProcessAction(i + 1);
            }

            pauseWhenActionFinishes = false;
        }
コード例 #20
0
        override public 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;
                    }
                }
            }
        }
コード例 #21
0
        private bool CheckCondition(GVar _var, GVar _compareVar)
        {
            if (_var == null)
            {
                ACDebug.LogWarning("Cannot check state of variable since it cannot be found!");
                return(false);
            }

            if (_compareVar != null && _var != null && _compareVar.type != _var.type)
            {
                ACDebug.LogWarning("Cannot compare " + _var.label + " and " + _compareVar.label + " as they are not the same type!");
                return(false);
            }

            if (_var.type == VariableType.Boolean)
            {
                int fieldValue   = _var.val;
                int compareValue = (int)boolValue;
                if (_compareVar != null)
                {
                    compareValue = _compareVar.val;
                }

                if (boolCondition == BoolCondition.EqualTo)
                {
                    if (fieldValue == compareValue)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (fieldValue != compareValue)
                    {
                        return(true);
                    }
                }
            }

            else if (_var.type == VariableType.Integer || _var.type == VariableType.PopUp)
            {
                int fieldValue   = _var.val;
                int compareValue = intValue;
                if (_compareVar != null)
                {
                    compareValue = _compareVar.val;
                }

                if (intCondition == IntCondition.EqualTo)
                {
                    if (fieldValue == compareValue)
                    {
                        return(true);
                    }
                }
                else if (intCondition == IntCondition.NotEqualTo)
                {
                    if (fieldValue != compareValue)
                    {
                        return(true);
                    }
                }
                else if (intCondition == IntCondition.LessThan)
                {
                    if (fieldValue < compareValue)
                    {
                        return(true);
                    }
                }
                else if (intCondition == IntCondition.MoreThan)
                {
                    if (fieldValue > compareValue)
                    {
                        return(true);
                    }
                }
            }

            else if (_var.type == VariableType.Float)
            {
                float fieldValue   = _var.floatVal;
                float compareValue = floatValue;
                if (_compareVar != null)
                {
                    compareValue = _compareVar.floatVal;
                }

                if (intCondition == IntCondition.EqualTo)
                {
                    if (fieldValue == compareValue)
                    {
                        return(true);
                    }
                }
                else if (intCondition == IntCondition.NotEqualTo)
                {
                    if (fieldValue != compareValue)
                    {
                        return(true);
                    }
                }
                else if (intCondition == IntCondition.LessThan)
                {
                    if (fieldValue < compareValue)
                    {
                        return(true);
                    }
                }
                else if (intCondition == IntCondition.MoreThan)
                {
                    if (fieldValue > compareValue)
                    {
                        return(true);
                    }
                }
            }

            else if (_var.type == VariableType.String)
            {
                string fieldValue   = _var.textVal;
                string compareValue = AdvGame.ConvertTokens(stringValue);
                if (_compareVar != null)
                {
                    compareValue = _compareVar.textVal;
                }

                if (!checkCase)
                {
                    fieldValue   = fieldValue.ToLower();
                    compareValue = compareValue.ToLower();
                }

                if (boolCondition == BoolCondition.EqualTo)
                {
                    if (fieldValue == compareValue)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (fieldValue != compareValue)
                    {
                        return(true);
                    }
                }
            }

            else if (_var.type == VariableType.Vector3)
            {
                if (vectorCondition == VectorCondition.EqualTo)
                {
                    return(_var.vector3Val == vector3Value);
                }
                else if (vectorCondition == VectorCondition.MagnitudeGreaterThan)
                {
                    return(_var.vector3Val.magnitude > floatValue);
                }
            }

            return(false);
        }
コード例 #22
0
        private float HandlePlay(int trackID, bool loop, bool isQueued, float fadeTime, bool isCrossfade, bool resumeIfPlayedBefore, int newTrackTimeSamples = 0, bool crossfadeWhenLooping = false)
        {
            if (crossfade)
            {
                crossfade.Stop();
            }

            MusicStorage musicStorage = GetSoundtrack(trackID);

            if (musicStorage == null || musicStorage.audioClip == null)
            {
                ACDebug.LogWarning("Cannot play " + name + " - no AudioClip assigned to track " + trackID + "!");
                return(0f);
            }

            isPlaying = true;

            if (isQueued && queuedSoundtrack.Count > 0)
            {
                queuedSoundtrack.Add(new QueuedSoundtrack(trackID, loop, fadeTime, isCrossfade, resumeIfPlayedBefore, newTrackTimeSamples, crossfadeWhenLooping));
                return(0f);
            }
            else
            {
                if (queuedSoundtrack.Count > 0 && queuedSoundtrack[0].trackID == trackID)
                {
                    // Already playing, ignore
                    return(0f);
                }

                // End other objects
                EndOthers();

                bool alreadyPlaying = (queuedSoundtrack.Count > 0) ? true : false;
                if (alreadyPlaying)
                {
                    StoreSoundtrackSampleByIndex(0);
                }

                if (resumeIfPlayedBefore)
                {
                    newTrackTimeSamples = GetSoundtrackSample(trackID);
                }

                queuedSoundtrack.Clear();

                if (crossfadeWhenLooping && loop && fadeTime > 0f)
                {
                    queuedSoundtrack.Add(new QueuedSoundtrack(trackID, loop, fadeTime, false, false, 0, true));
                }
                else
                {
                    queuedSoundtrack.Add(new QueuedSoundtrack(trackID, loop));
                }

                KickStarter.eventManager.Call_OnPlaySoundtrack(trackID, IsMusic, loop, fadeTime, newTrackTimeSamples);

                if (alreadyPlaying)
                {
                    if (fadeTime > 0f)
                    {
                        if (isCrossfade)
                        {
                            if (crossfade)
                            {
                                crossfade.FadeOut(audioSource, fadeTime);
                            }

                            SetRelativeVolume(musicStorage.relativeVolume);
                            audioSource.clip = musicStorage.audioClip;
                            HandleFadeIn(fadeTime, loop, newTrackTimeSamples);

                            return(fadeTime);
                        }
                        else
                        {
                            FadeOutThenIn(musicStorage, fadeTime, loop, resumeIfPlayedBefore, newTrackTimeSamples);
                            return(fadeTime * 2f);
                        }
                    }
                    else
                    {
                        Stop();
                        SetRelativeVolume(musicStorage.relativeVolume);
                        Play(musicStorage.audioClip, loop, newTrackTimeSamples);
                        return(0f);
                    }
                }
                else
                {
                    SetRelativeVolume(musicStorage.relativeVolume);

                    if (fadeTime <= 0f && KickStarter.stateHandler.gameState != GameState.Paused)
                    {
                        // Prevents volume not correct in first frame of play
                        fadeTime = 0.001f;
                    }

                    if (fadeTime > 0f)
                    {
                        audioSource.clip = musicStorage.audioClip;
                        HandleFadeIn(fadeTime, loop, newTrackTimeSamples);
                        return(fadeTime);
                    }
                    else
                    {
                        Play(musicStorage.audioClip, loop, newTrackTimeSamples);
                        return(0f);
                    }
                }
            }
        }
コード例 #23
0
        private void Export()
        {
                        #if UNITY_WEBPLAYER
            ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again.");
                        #else
            if (speechManager == null || exportColumns == null || exportColumns.Count == 0 || speechManager.lines == null || speechManager.lines.Count == 0)
            {
                return;
            }

            string suggestedFilename = string.Empty;
            if (AdvGame.GetReferences().settingsManager)
            {
                suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - ";
            }
            suggestedFilename += "GameText.csv";

            string fileName = EditorUtility.SaveFilePanel("Export game text", "Assets", suggestedFilename, "csv");
            if (fileName.Length == 0)
            {
                return;
            }

            List <SpeechLine> exportLines = new List <SpeechLine>();
            foreach (SpeechLine line in speechManager.lines)
            {
                if (filterByType)
                {
                    if (!IsTextTypeFiltered(line.textType))
                    {
                        continue;
                    }
                }
                if (filterByScene)
                {
                    if (sceneNames != null && sceneNames.Length > sceneFilter)
                    {
                        string selectedScene      = sceneNames[sceneFilter] + ".unity";
                        string scenePlusExtension = (string.IsNullOrEmpty(line.scene)) ? string.Empty : (line.scene + ".unity");

                        if ((string.IsNullOrEmpty(line.scene) && sceneFilter == 0) ||
                            sceneFilter == 1 ||
                            (!string.IsNullOrEmpty(line.scene) && sceneFilter > 1 && line.scene.EndsWith(selectedScene)) ||
                            (!string.IsNullOrEmpty(line.scene) && sceneFilter > 1 && scenePlusExtension.EndsWith(selectedScene)))
                        {
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                if (filterByText)
                {
                    if (!line.Matches(textFilter, filterSpeechLine))
                    {
                        continue;
                    }
                }
                if (filterByTag)
                {
                    if (tagFilter == -1 ||
                        (tagFilter < speechManager.speechTags.Count && line.tagID == speechManager.speechTags[tagFilter].ID))
                    {
                    }
                    else
                    {
                        continue;
                    }
                }

                exportLines.Add(new SpeechLine(line));
            }

            if (doRowSorting)
            {
                switch (rowSorting)
                {
                case RowSorting.ByID:
                    exportLines.Sort((a, b) => a.lineID.CompareTo(b.lineID));
                    break;

                case RowSorting.ByDescription:
                    exportLines.Sort((a, b) => string.Compare(a.description, b.description, System.StringComparison.Ordinal));
                    break;

                case RowSorting.ByType:
                    exportLines.Sort((a, b) => string.Compare(a.textType.ToString(), b.textType.ToString(), System.StringComparison.Ordinal));
                    break;

                case RowSorting.ByAssociatedObject:
                    exportLines.Sort((a, b) => string.Compare(a.owner, b.owner, System.StringComparison.Ordinal));
                    break;

                case RowSorting.ByScene:
                    exportLines.Sort((a, b) => string.Compare(a.scene, b.scene, System.StringComparison.Ordinal));
                    break;

                default:
                    break;
                }
            }

            List <string[]> output = new List <string[]>();

            string[]      languagesArray = speechManager.languages.ToArray();
            List <string> headerList     = new List <string>();
            headerList.Add("ID");
            foreach (ExportColumn exportColumn in exportColumns)
            {
                headerList.Add(exportColumn.GetHeader(languagesArray));
            }
            output.Add(headerList.ToArray());

            foreach (SpeechLine line in exportLines)
            {
                List <string> rowList = new List <string>();
                rowList.Add(line.lineID.ToString());
                foreach (ExportColumn exportColumn in exportColumns)
                {
                    string cellText = exportColumn.GetCellText(line);
                    rowList.Add(cellText);
                }
                output.Add(rowList.ToArray());
            }

            string fileContents = CSVReader.CreateCSVGrid(output);
            if (!string.IsNullOrEmpty(fileContents) && Serializer.SaveFile(fileName, fileContents))
            {
                int numLines = exportLines.Count;
                ACDebug.Log(numLines.ToString() + " line" + ((numLines != 1) ? "s" : string.Empty) + " exported.");
            }
                        #endif
        }
コード例 #24
0
        override public float Run()
        {
            UpgradeSelf();

            if (runtimeMovePath && runtimeMovePath.GetComponent <Char>())
            {
                ACDebug.LogWarning("Can't follow a Path attached to a Character!", runtimeMovePath);
                return(0f);
            }

            if (!isRunning)
            {
                isRunning = true;

                if (runtimeChar)
                {
                    if (runtimeChar is NPC)
                    {
                        NPC npcToMove = (NPC)runtimeChar;
                        npcToMove.StopFollowing();
                    }

                    if (movePathMethod == MovePathMethod.StopMoving)
                    {
                        runtimeChar.EndPath();
                        if (runtimeChar.IsPlayer && KickStarter.playerInteraction.GetHotspotMovingTo() != null)
                        {
                            KickStarter.playerInteraction.StopMovingToHotspot();
                        }

                        if (stopInstantly)
                        {
                            runtimeChar.Halt();
                        }
                    }
                    else if (movePathMethod == MovePathMethod.MoveOnNewPath)
                    {
                        if (runtimeMovePath)
                        {
                            int randomIndex = -1;
                            if (runtimeMovePath.pathType == AC_PathType.IsRandom && startRandom)
                            {
                                if (runtimeMovePath.nodes.Count > 1)
                                {
                                    randomIndex = Random.Range(0, runtimeMovePath.nodes.Count);
                                }
                            }

                            PrepareCharacter(randomIndex);

                            if (willWait && runtimeMovePath.pathType != AC_PathType.ForwardOnly && runtimeMovePath.pathType != AC_PathType.ReverseOnly)
                            {
                                willWait = false;
                                ACDebug.LogWarning("Cannot pause while character moves along a linear path, as this will create an indefinite cutscene.");
                            }

                            if (randomIndex >= 0)
                            {
                                runtimeChar.SetPath(runtimeMovePath, randomIndex, 0);
                            }
                            else
                            {
                                runtimeChar.SetPath(runtimeMovePath);
                            }

                            if (willWait)
                            {
                                return(defaultPauseTime);
                            }
                        }
                    }
                    else if (movePathMethod == MovePathMethod.ResumeLastSetPath)
                    {
                        runtimeChar.ResumeLastPath();
                    }
                }

                return(0f);
            }
            else
            {
                if (runtimeChar.GetPath() != runtimeMovePath)
                {
                    isRunning = false;
                    return(0f);
                }
                else
                {
                    return(defaultPauseTime);
                }
            }
        }
コード例 #25
0
        private void PerformSaveOrLoad()
        {
            ClearAllEvents();

            if (saveHandling == SaveHandling.ContinueFromLastSave || saveHandling == SaveHandling.LoadGame)
            {
                EventManager.OnFinishLoading += OnFinishLoading;
                EventManager.OnFailLoading   += OnFail;
            }
            else if (saveHandling == SaveHandling.OverwriteExistingSave || saveHandling == SaveHandling.SaveNewGame)
            {
                EventManager.OnFinishSaving += OnFinishSaving;
                EventManager.OnFailSaving   += OnFail;
            }

            if ((saveHandling == SaveHandling.LoadGame || saveHandling == SaveHandling.ContinueFromLastSave) && doSelectiveLoad)
            {
                KickStarter.saveSystem.SetSelectiveLoadOptions(selectiveLoad);
            }

            string newSaveLabel = "";

            if (customLabel && ((updateLabel && saveHandling == SaveHandling.OverwriteExistingSave) || saveHandling == AC.SaveHandling.SaveNewGame))
            {
                if (selectSaveType != SelectSaveType.Autosave)
                {
                    GVar gVar = GlobalVariables.GetVariable(varID);
                    if (gVar != null)
                    {
                        newSaveLabel = gVar.GetValue(Options.GetLanguage());
                    }
                    else
                    {
                        ACDebug.LogWarning("Could not " + saveHandling.ToString() + " - no variable found.");
                        return;
                    }
                }
            }

            int i = Mathf.Max(0, saveIndex);

            if (saveHandling == SaveHandling.ContinueFromLastSave)
            {
                SaveSystem.ContinueGame();
                return;
            }

            if (saveHandling == SaveHandling.LoadGame || saveHandling == SaveHandling.OverwriteExistingSave)
            {
                if (selectSaveType == SelectSaveType.Autosave)
                {
                    if (saveHandling == SaveHandling.LoadGame)
                    {
                        SaveSystem.LoadAutoSave();
                        return;
                    }
                    else
                    {
                        if (PlayerMenus.IsSavingLocked(this))
                        {
                            ACDebug.LogWarning("Cannot save at this time - either blocking ActionLists, a Conversation is active, or saving has been manually locked.");
                            OnComplete();
                        }
                        else
                        {
                            SaveSystem.SaveAutoSave();
                        }
                        return;
                    }
                }
                else if (selectSaveType == SelectSaveType.SlotIndexFromVariable)
                {
                    GVar gVar = GlobalVariables.GetVariable(slotVarID);
                    if (gVar != null)
                    {
                        i = gVar.val;
                    }
                    else
                    {
                        ACDebug.LogWarning("Could not get save slot index - no variable found.");
                        return;
                    }
                }
            }

            if (menuName != "" && elementName != "")
            {
                MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName);
                if (menuElement != null && menuElement is MenuSavesList)
                {
                    MenuSavesList menuSavesList = (MenuSavesList)menuElement;
                    i += menuSavesList.GetOffset();
                }
                else
                {
                    ACDebug.LogWarning("Cannot find ProfilesList element '" + elementName + "' in Menu '" + menuName + "'.");
                }
            }
            else
            {
                ACDebug.LogWarning("No SavesList element referenced when trying to find slot slot " + i.ToString());
            }

            if (saveHandling == SaveHandling.LoadGame)
            {
                SaveSystem.LoadGame(i, -1, false);
            }
            else if (saveHandling == SaveHandling.OverwriteExistingSave || saveHandling == SaveHandling.SaveNewGame)
            {
                if (PlayerMenus.IsSavingLocked(this))
                {
                    ACDebug.LogWarning("Cannot save at this time - either blocking ActionLists, a Conversation is active, or saving has been manually locked.");
                    OnComplete();
                }
                else
                {
                    if (saveHandling == SaveHandling.OverwriteExistingSave)
                    {
                        SaveSystem.SaveGame(i, -1, false, updateLabel, newSaveLabel);
                    }
                    else if (saveHandling == SaveHandling.SaveNewGame)
                    {
                        SaveSystem.SaveNewGame(updateLabel, newSaveLabel);
                    }
                }
            }
        }
コード例 #26
0
        private void CleanUpAsset()
        {
            string assetPath = AssetDatabase.GetAssetPath(this);

            Object[] objects = AssetDatabase.LoadAllAssetsAtPath(assetPath);

            foreach (Object _object in objects)
            {
                if (_object is Menu)
                {
                    AC.Menu _menu = (Menu)_object;

                    bool found = false;
                    foreach (AC.Menu menu in menus)
                    {
                        if (menu == _menu)
                        {
                            _object.hideFlags = HideFlags.HideInHierarchy;
                            found             = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        ACDebug.Log("Deleted unset menu: " + _menu.title);
                        DestroyImmediate(_object, true);
                    }

                    for (int i = 0; i < _menu.elements.Count; i++)
                    {
                        if (_menu.elements[i] == null)
                        {
                            _menu.elements.RemoveAt(i);
                            i = 0;
                        }
                    }
                }
            }

            foreach (Object _object in objects)
            {
                if (_object is MenuElement)
                {
                    MenuElement _element = (MenuElement)_object;

                    bool found = false;
                    foreach (AC.Menu menu in menus)
                    {
                        foreach (MenuElement element in menu.elements)
                        {
                            if (element == _element)
                            {
                                _object.hideFlags = HideFlags.HideInHierarchy;
                                found             = true;
                                break;
                            }
                        }
                    }

                    if (!found)
                    {
                        ACDebug.Log("Deleted unset element: " + _element.title);
                        DestroyImmediate(_object, true);
                    }
                }
            }

            AssetDatabase.SaveAssets();
        }
コード例 #27
0
        private void Export()
        {
                        #if UNITY_WEBPLAYER
            ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again.");
                        #else
            if (speechManager == null || exportColumns == null || exportColumns.Count == 0 || speechManager.lines == null || speechManager.lines.Count == 0)
            {
                return;
            }

            string suggestedFilename = "";
            if (AdvGame.GetReferences().settingsManager)
            {
                suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - ";
            }
            suggestedFilename += "GameText.csv";

            string fileName = EditorUtility.SaveFilePanel("Export game text", "Assets", suggestedFilename, "csv");
            if (fileName.Length == 0)
            {
                return;
            }

            string[]          sceneNames  = speechManager.GetSceneNames();
            List <SpeechLine> exportLines = new List <SpeechLine>();
            foreach (SpeechLine line in speechManager.lines)
            {
                if (filterByType)
                {
                    if (line.textType != typeFilter)
                    {
                        continue;
                    }
                }
                if (filterByScene)
                {
                    if (sceneNames != null && sceneNames.Length > sceneFilter)
                    {
                        string selectedScene      = sceneNames[sceneFilter] + ".unity";
                        string scenePlusExtension = (line.scene != "") ? (line.scene + ".unity") : "";

                        if ((line.scene == "" && sceneFilter == 0) ||
                            sceneFilter == 1 ||
                            (line.scene != "" && sceneFilter > 1 && line.scene.EndsWith(selectedScene)) ||
                            (line.scene != "" && sceneFilter > 1 && scenePlusExtension.EndsWith(selectedScene)))
                        {
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                if (filterByText)
                {
                    if (!line.Matches(textFilter, filterSpeechLine))
                    {
                        continue;
                    }
                }
                if (filterByTag)
                {
                    if (tagFilter == -1 ||
                        (tagFilter < speechManager.speechTags.Count && line.tagID == speechManager.speechTags[tagFilter].ID))
                    {
                    }
                    else
                    {
                        continue;
                    }
                }

                exportLines.Add(new SpeechLine(line));
            }

            if (doRowSorting)
            {
                if (rowSorting == RowSorting.ByID)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.lineID.CompareTo(b.lineID)); });
                }
                else if (rowSorting == RowSorting.ByDescription)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.description.CompareTo(b.description)); });
                }
                else if (rowSorting == RowSorting.ByType)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.textType.ToString().CompareTo(b.textType.ToString())); });
                }
                else if (rowSorting == RowSorting.ByAssociatedObject)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.owner.CompareTo(b.owner)); });
                }
                else if (rowSorting == RowSorting.ByScene)
                {
                    exportLines.Sort(delegate(SpeechLine a, SpeechLine b) { return(a.scene.CompareTo(b.owner)); });
                }
            }

            bool            fail   = false;
            List <string[]> output = new List <string[]>();

            string[]      languagesArray = speechManager.languages.ToArray();
            List <string> headerList     = new List <string>();
            headerList.Add("ID");
            foreach (ExportColumn exportColumn in exportColumns)
            {
                headerList.Add(exportColumn.GetHeader(languagesArray));
            }
            output.Add(headerList.ToArray());

            foreach (SpeechLine line in exportLines)
            {
                List <string> rowList = new List <string>();
                rowList.Add(line.lineID.ToString());
                foreach (ExportColumn exportColumn in exportColumns)
                {
                    string cellText = exportColumn.GetCellText(line);
                    rowList.Add(cellText);

                    if (cellText.Contains(CSVReader.csvDelimiter))
                    {
                        fail = true;
                        ACDebug.LogError("Cannot export translation since line " + line.lineID.ToString() + " (" + line.text + ") contains the character '" + CSVReader.csvDelimiter + "'.");
                    }
                }
                output.Add(rowList.ToArray());
            }

            if (!fail)
            {
                int length = output.Count;

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int j = 0; j < length; j++)
                {
                    sb.AppendLine(string.Join(CSVReader.csvDelimiter, output[j]));
                }

                if (Serializer.SaveFile(fileName, sb.ToString()))
                {
                    int numLines = exportLines.Count;
                    ACDebug.Log(numLines.ToString() + " line" + ((numLines != 1) ? "s" : "") + " exported.");
                }
            }

            //this.Close ();
                        #endif
        }
コード例 #28
0
        override public float Run()
        {
            if (_gameObject == null)
            {
                return(0f);
            }

            if (invAction == InvAction.Add)
            {
                // Instantiate

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (_gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    RememberTransform rememberTransform = oldOb.GetComponent <RememberTransform>();

                    if (rememberTransform != null && rememberTransform.saveScenePresence && rememberTransform.linkedPrefabID != 0)
                    {
                        // Bypass this check
                    }
                    else
                    {
                        ACDebug.LogWarning(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                        return(0f);
                    }
                }

                Vector3    position = _gameObject.transform.position;
                Quaternion rotation = _gameObject.transform.rotation;

                if (positionRelativeTo != PositionRelativeTo.Nothing)
                {
                    float forward = _gameObject.transform.position.z;
                    float right   = _gameObject.transform.position.x;
                    float up      = _gameObject.transform.position.y;

                    if (positionRelativeTo == PositionRelativeTo.RelativeToActiveCamera)
                    {
                        Transform mainCam = KickStarter.mainCamera.transform;
                        position              = mainCam.position + (mainCam.forward * forward) + (mainCam.right * right) + (mainCam.up * up);
                        rotation.eulerAngles += mainCam.transform.rotation.eulerAngles;
                    }
                    else if (positionRelativeTo == PositionRelativeTo.RelativeToPlayer)
                    {
                        if (KickStarter.player)
                        {
                            Transform playerTranform = KickStarter.player.transform;
                            position              = playerTranform.position + (playerTranform.forward * forward) + (playerTranform.right * right) + (playerTranform.up * up);
                            rotation.eulerAngles += playerTranform.rotation.eulerAngles;
                        }
                    }
                    else if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject)
                    {
                        if (relativeGameObject != null)
                        {
                            Transform relativeTransform = relativeGameObject.transform;
                            position              = relativeTransform.position + (relativeTransform.forward * forward) + (relativeTransform.right * right) + (relativeTransform.up * up);
                            rotation.eulerAngles += relativeTransform.rotation.eulerAngles;
                        }
                    }
                    else if (positionRelativeTo == PositionRelativeTo.EnteredValue)
                    {
                        position += relativeVector;
                    }
                    else if (positionRelativeTo == PositionRelativeTo.VectorVariable)
                    {
                        if (variableLocation == VariableLocation.Global)
                        {
                            position += GlobalVariables.GetVector3Value(vectorVarID);
                        }
                        else if (variableLocation == VariableLocation.Local && !isAssetFile)
                        {
                            position += LocalVariables.GetVector3Value(vectorVarID);
                        }
                    }
                }

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;

                if (newObject.GetComponent <RememberTransform>())
                {
                    newObject.GetComponent <RememberTransform>().OnSpawn();
                }

                KickStarter.stateHandler.IgnoreNavMeshCollisions();
            }
            else if (invAction == InvAction.Remove)
            {
                // Delete
                KickStarter.sceneChanger.ScheduleForDeletion(_gameObject);
            }
            else if (invAction == InvAction.Replace)
            {
                if (replaceGameObject == null)
                {
                    ACDebug.LogWarning("Cannot perform swap because the object to remove was not found in the scene.");
                    return(0f);
                }

                Vector3    position = replaceGameObject.transform.position;
                Quaternion rotation = replaceGameObject.transform.rotation;

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    ACDebug.Log(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                    return(0f);
                }

                KickStarter.sceneChanger.ScheduleForDeletion(replaceGameObject);

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;
                KickStarter.stateHandler.IgnoreNavMeshCollisions();
            }

            return(0f);
        }
コード例 #29
0
        override public void ShowGUI()
        {
            if (!settingsManager)
            {
                settingsManager = AdvGame.GetReferences().settingsManager;
            }

            if (!settingsManager)
            {
                return;
            }

            if (settingsManager.playerSwitching == PlayerSwitching.DoNotAllow)
            {
                EditorGUILayout.HelpBox("This Action requires Player Switching to be allowed, as set in the Settings Manager.", MessageType.Info);
                return;
            }

            // Create a string List of the field's names (for the PopUp box)
            List <string> labelList = new List <string>();

            int i = 0;

            playerNumber = -1;

            if (settingsManager.players.Count > 0)
            {
                foreach (PlayerPrefab playerPrefab in settingsManager.players)
                {
                    if (playerPrefab.playerOb != null)
                    {
                        labelList.Add(playerPrefab.playerOb.name);
                    }
                    else
                    {
                        labelList.Add("(Undefined prefab)");
                    }

                    // If a player has been removed, make sure selected player is still valid
                    if (playerPrefab.ID == playerID)
                    {
                        playerNumber = i;
                    }

                    i++;
                }

                if (playerNumber == -1)
                {
                    // Wasn't found (item was possibly deleted), so revert to zero
                    ACDebug.LogWarning("Previously chosen Player no longer exists!");

                    playerNumber = 0;
                    playerID     = 0;
                }

                playerNumber = EditorGUILayout.Popup("New Player:", playerNumber, labelList.ToArray());
                playerID     = settingsManager.players[playerNumber].ID;

                if (AdvGame.GetReferences().settingsManager == null || !AdvGame.GetReferences().settingsManager.shareInventory)
                {
                    keepInventory = EditorGUILayout.Toggle("Transfer inventory?", keepInventory);
                }
                restorePreviousData = EditorGUILayout.Toggle("Restore position?", restorePreviousData);
                if (restorePreviousData)
                {
                    EditorGUILayout.LabelField("If first time in game:", EditorStyles.boldLabel);
                }

                newPlayerPosition = (NewPlayerPosition)EditorGUILayout.EnumPopup("New Player position:", newPlayerPosition);

                if (newPlayerPosition == NewPlayerPosition.ReplaceNPC)
                {
                    newPlayerNPC = (NPC)EditorGUILayout.ObjectField("NPC to be replaced:", newPlayerNPC, typeof(NPC), true);

                    newPlayerNPC_ID = FieldToID <NPC> (newPlayerNPC, newPlayerNPC_ID);
                    newPlayerNPC    = IDToField <NPC> (newPlayerNPC, newPlayerNPC_ID, false);
                }
                else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker)
                {
                    newPlayerMarker = (Marker)EditorGUILayout.ObjectField("Marker to appear at:", newPlayerMarker, typeof(Marker), true);

                    newPlayerMarker_ID = FieldToID <Marker> (newPlayerMarker, newPlayerMarker_ID);
                    newPlayerMarker    = IDToField <Marker> (newPlayerMarker, newPlayerMarker_ID, false);
                }
                else if (newPlayerPosition == NewPlayerPosition.AppearInOtherScene)
                {
                    chooseNewSceneBy = (ChooseSceneBy)EditorGUILayout.EnumPopup("Choose scene by:", chooseNewSceneBy);
                    if (chooseNewSceneBy == ChooseSceneBy.Name)
                    {
                        newPlayerSceneName = EditorGUILayout.TextField("Scene to appear in:", newPlayerSceneName);
                    }
                    else
                    {
                        newPlayerScene = EditorGUILayout.IntField("Scene to appear in:", newPlayerScene);
                    }
                }

                if (newPlayerPosition == NewPlayerPosition.ReplaceNPC || newPlayerPosition == NewPlayerPosition.AppearAtMarker)
                {
                    EditorGUILayout.Space();
                    oldPlayer = (OldPlayer)EditorGUILayout.EnumPopup("Old Player", oldPlayer);

                    if (oldPlayer == OldPlayer.ReplaceWithNPC)
                    {
                        oldPlayerNPC = (NPC)EditorGUILayout.ObjectField("NPC to replace old Player:", oldPlayerNPC, typeof(NPC), true);

                        oldPlayerNPC_ID = FieldToID <NPC> (oldPlayerNPC, oldPlayerNPC_ID);
                        oldPlayerNPC    = IDToField <NPC> (oldPlayerNPC, oldPlayerNPC_ID, false);
                    }
                }
            }

            else
            {
                EditorGUILayout.LabelField("No players exist!");
                playerID     = -1;
                playerNumber = -1;
            }

            EditorGUILayout.Space();

            AfterRunningOption();
        }
コード例 #30
0
        override public void AssignValues(List <ActionParameter> parameters)
        {
            if (isPlayer)
            {
                if (KickStarter.player != null)
                {
                    runtimeLinkedProp = KickStarter.player.GetComponent <Moveable>();

                    if (runtimeLinkedProp == null)
                    {
                        ACDebug.LogWarning("The player " + KickStarter.player + " requires a Moveable component to be moved with the 'Object: Transform' Action.", KickStarter.player);
                    }
                }
                else
                {
                    runtimeLinkedProp = null;
                }
            }
            else
            {
                runtimeLinkedProp = AssignFile <Moveable> (parameters, parameterID, constantID, linkedProp);
            }

            runtimeMarker  = AssignFile <Marker> (parameters, markerParameterID, markerID, marker);
            transitionTime = AssignFloat(parameters, transitionTimeParameterID, transitionTime);
            newVector      = AssignVector3(parameters, newVectorParameterID, newVector);

            if (!(transformType == TransformType.CopyMarker ||
                  (transformType == TransformType.Translate && toBy == ToBy.To) ||
                  (transformType == TransformType.Rotate && toBy == ToBy.To)))
            {
                inWorldSpace = false;
            }

            runtimeVariable = null;
            if (transformType != TransformType.CopyMarker && setVectorMethod == SetVectorMethod.FromVector3Variable)
            {
                switch (variableLocation)
                {
                case VariableLocation.Global:
                    vectorVarID     = AssignVariableID(parameters, vectorVarParameterID, vectorVarID);
                    runtimeVariable = GlobalVariables.GetVariable(vectorVarID, true);
                    break;

                case VariableLocation.Local:
                    if (!isAssetFile)
                    {
                        vectorVarID     = AssignVariableID(parameters, vectorVarParameterID, vectorVarID);
                        runtimeVariable = LocalVariables.GetVariable(vectorVarID, localVariables);
                    }
                    break;

                case VariableLocation.Component:
                    Variables runtimeVariables = AssignFile <Variables> (variablesConstantID, variables);
                    if (runtimeVariables != null)
                    {
                        runtimeVariable = runtimeVariables.GetVariable(vectorVarID);
                    }
                    runtimeVariable = AssignVariable(parameters, vectorVarParameterID, runtimeVariable);
                    break;
                }
            }
        }