protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        HexTile startTile = actor.currentTile;

        if (startTile == null)
        {
            Done();
            return;
        }

        List <HexTile> path = Pathfinder.FindPath(startTile, targetTile, PathFindingMode.None);

        if (path == null)
        {
            Done();
            return;
        }

        Vector3[] line       = NeverdawnUtility.PathAlongTiles(path, 0.1f, 10);
        float     pathLength = NeverdawnUtility.GetPathLength(line);


        GameController.instance.party.PullCharacter(characterToPlace, targetTile.position);

        action = new CharacterMoveAlongPathAction(line, 1000.0f, 1.0f, false);
        action.ActionStart(characterToPlace);
    }
Esempio n. 2
0
    private Topic loadTopicNode(XmlNode node)
    {
        Topic topic = new Topic(XmlUtil.Get(node, "id", string.Empty), XmlUtil.Get(node, "common", false));

        foreach (XmlNode childNode in node.ChildNodes)
        {
            if (childNode.Name == "label")
            {
                topic.label = childNode.InnerText;
            }

            if (childNode.Name == "questions")
            {
                foreach (XmlNode questionNode in childNode.ChildNodes)
                {
                    topic.questions.Add(questionNode.InnerText);
                }
            }

            if (childNode.Name == "default")
            {
                topic.defaultEvent = NeverdawnUtility.LoadEvent(childNode.FirstChild);
            }
        }

        return(topic);
    }
    void Start()
    {
        buttons = new List <UIIconButton>();

        foreach (AbilityBase ability in combatItem.abilities)
        {
            UIAbilityIconButton button = Instantiate(UIFactory.uiAbilityButton);
            button.ability = ability;
            button.menu    = menu;
            button.label   = label;

            buttons.Add(button);
        }

        UIIconButton buttonCancel = Instantiate(UIFactory.uiIconButton);

        buttonCancel.SetIconSprite(iconCancel);
        buttonCancel.onSelect.AddListener(() => label.text = labelCancel);
        buttonCancel.onClick.AddListener(() => menu.GoBack());
        buttons.Add(buttonCancel);

        for (int i = 0; i < buttons.Count; i++)
        {
            buttons[i].transform.SetParent(buttonParent);
            buttons[i].neighborLeft  = buttons[NeverdawnUtility.RepeatIndex(i - 1, buttons.Count)];
            buttons[i].neighborRight = buttons[NeverdawnUtility.RepeatIndex(i + 1, buttons.Count)];
        }
    }
    private void updateView(IQuickMenuInteractionCollection collection)
    {
        interactions = collection.interactions;

        clearIcons();



        if (buttons == null)
        {
            buttons = new List <UITextButton>();
        }

        foreach (QuickMenuInteraction interaction in interactions)
        {
            UITextButton quickMenuIcon = createQuickMenuItem(interaction);
            quickMenuIcon.transform.SetParent(iconParent, false);
            buttons.Add(quickMenuIcon);
        }

        for (int i = 0; i < buttons.Count; i++)
        {
            buttons[i].neighborTop    = buttons[NeverdawnUtility.RepeatIndex(i - 1, buttons.Count)];
            buttons[i].neighborBottom = buttons[NeverdawnUtility.RepeatIndex(i + 1, buttons.Count)];
        }



        icon.sprite          = collection.icon;
        textLabel.text       = collection.label;
        textDescription.text = collection.description;
    }
Esempio n. 5
0
 public CharacterMoveAlongPathAction(Vector3[] corners, float maxDistance, float smoothness = 1.0f, bool run = false)
 {
     this.corners     = corners;
     this.distances   = NeverdawnUtility.CreateDistanceArray(this.corners);
     this.maxDistance = maxDistance;
     this.run         = run;
 }
Esempio n. 6
0
    protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        NavMeshAnimator walker = actor.GetComponentInChildren <NavMeshAnimator>();

        if (walker != null)
        {
            moveSpeed = walker.moveSpeed;
            turnSpeed = walker.turnSpeed;
        }
        else
        {
            moveSpeed = 5.0f;
            turnSpeed = 540.0f;
        }

        if (!run)
        {
            moveSpeed /= 2.0f;
        }

        float distance = Mathf.Min(NeverdawnUtility.GetPathLength(corners), maxDistance);

        distance = 0.0f;
    }
Esempio n. 7
0
    private void updatePage()
    {
        List <UIIconButton> buttons = new List <UIIconButton>();

        buttons.Add(centerButton);

        buttonMap = new Dictionary <UISelectable, Character>();

        foreach (Character character in PlacementController.charactersToPlace)
        {
            Character    c          = character;
            UIIconButton iconButton = Instantiate(iconButtonPrefab);
            iconButton.SetIconSprite(character.identity.icon);
            iconButton.transform.SetParent(iconButtonParent);
            iconButton.onClick.AddListener(() => click(c));

            buttons.Add(iconButton);
        }

        for (int i = 0; i < buttons.Count; i++)
        {
            buttons[i].neighborLeft  = buttons[NeverdawnUtility.RepeatIndex(i - 1, buttons.Count)];
            buttons[i].neighborRight = buttons[NeverdawnUtility.RepeatIndex(i + 1, buttons.Count)];
        }

        buttons[0].Select();
    }
    private void selectTop()
    {
        index = NeverdawnUtility.RepeatIndex(index - 1, selectables.Length);


        updateSelection();
    }
    private void updateView()
    {
        foreach (Transform child in slotViewParent)
        {
            Destroy(child.gameObject);
        }

        Mannequin mannequin = avatarController.character.GetComponent <Mannequin>();

        slotViews = new UISlotView[mannequin.combatItemSlots.Length];

        for (int i = 0; i < mannequin.combatItemSlots.Length; i++)
        {
            CombatItemSlot slot = mannequin.combatItemSlots[i];

            int k = i;

            slotViews[i]              = Instantiate(slotViewPrefab);
            slotViews[i].component    = slot.Get();
            slotViews[i].slotName     = slot.slotName;
            slotViews[i].defaultLabel = "None";
            slotViews[i].GetComponent <UIButton>().onClick.AddListener(() => pickItemForSlot(slot, k));

            slotViews[i].transform.SetParent(slotViewParent, false);
        }

        for (int i = 0; i < slotViews.Length; i++)
        {
            int prev = NeverdawnUtility.RepeatIndex(i - 1, slotViews.Length);
            int next = NeverdawnUtility.RepeatIndex(i + 1, slotViews.Length);

            slotViews[i].selectable.neighborBottom = slotViews[next].selectable;
            slotViews[i].selectable.neighborTop    = slotViews[prev].selectable;
        }
    }
Esempio n. 10
0
    public override void Next()
    {
        updateTargets();
        targetIndex = NeverdawnUtility.RepeatIndex(targetIndex - 1, targets.Length);

        updateSelector();
    }
Esempio n. 11
0
    void Start()
    {
        buttons = new List <UIIconButton>();

        if (character.mannequin)
        {
            foreach (CombatItem item in character.mannequin.GetEquippedCombatItems())
            {
                UICombatItemIconButton combatItemButton = Instantiate(UIFactory.uiCombatItemButton);
                combatItemButton.combatItem = item;
                combatItemButton.menu       = menu;
                combatItemButton.label      = label;
                buttons.Add(combatItemButton);
            }
        }

        if (character.unarmed)
        {
            UICombatItemIconButton combatItemButton = Instantiate(UIFactory.uiCombatItemButton);
            combatItemButton.combatItem  = character.unarmed;
            combatItemButton.menu        = menu;
            combatItemButton.label       = label;
            combatItemButton.customLabel = "Self";
            buttons.Add(combatItemButton);
        }

        if (includeWalk)
        {
            AbilityBase walkAbility = Instantiate(CombatController.walkAbility);
            walkAbility.Initialize(character.gameObject);

            UIAbilityIconButton walkButton = Instantiate(UIFactory.uiAbilityButton);
            walkButton.ability = walkAbility;
            walkButton.menu    = menu;
            walkButton.label   = label;
            buttons.Add(walkButton);
        }

        if (includeDoNothing)
        {
            UIIconButton buttonDoNothing = Instantiate(UIFactory.uiIconButton);
            buttonDoNothing.SetIconSprite(iconDoNothing);
            buttonDoNothing.onSelect.AddListener(() => label.text = labelDoNothing);
            buttonDoNothing.onClick.AddListener(() => doNothing());
            buttons.Add(buttonDoNothing);
        }

        for (int i = 0; i < buttons.Count; i++)
        {
            buttons[i].transform.SetParent(buttonParent);
            buttons[i].neighborLeft  = buttons[NeverdawnUtility.RepeatIndex(i - 1, buttons.Count)];
            buttons[i].neighborRight = buttons[NeverdawnUtility.RepeatIndex(i + 1, buttons.Count)];
        }
    }
Esempio n. 12
0
    protected override void OnQuickMenuPageEnabled()
    {
        Character character = avatarController.character;

        selectedIndex = NeverdawnUtility.RepeatIndex(selectedIndex, buttons.Count);

        if (buttons.Count > 0)
        {
            buttons[selectedIndex].Select();
        }
    }
Esempio n. 13
0
    private static Vector3 shift(Vector3[] lineStrip, int p, float thickness)
    {
        int     prev           = NeverdawnUtility.RepeatIndex(p - 1, lineStrip.Length);
        int     next           = NeverdawnUtility.RepeatIndex(p + 1, lineStrip.Length);
        Vector3 shiftDirection = lineStrip[next] - lineStrip[prev];

        shiftDirection.y = 0.0f;
        shiftDirection.Normalize();
        shiftDirection = Quaternion.Euler(0.0f, 90.0f, 0.0f) * shiftDirection;

        return(lineStrip[p] + thickness * shiftDirection);
    }
    /// <summary>
    /// Updates the cursor with joystick info
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="intensity"></param>
    public override void UpdateValues(Vector3 direction, float intensity)
    {
        if (targets.Length == 0)
        {
            return;
        }

        // Check if current target is still valid
        if (Vector3.Distance(character.transform.position, targets[targetIndex].position) > maxRange)
        {
            targetIndex = NeverdawnUtility.RepeatIndex(targetIndex, targets.Length);
        }
    }
Esempio n. 15
0
    private void updateCurrentControllers()
    {
        currentTurnControllers.Clear();

        Character character = currentCombatGroup[turnIndex];

        // find the next living character
        while (!character.isAlive)
        {
            turnIndex = NeverdawnUtility.RepeatIndex(turnIndex + 1, currentCombatGroup.Count);
            character = currentCombatGroup[turnIndex];
        }

        // fetch all characters in the party in the following sequence
        if (character.IsInPlayerParty)
        {
            while (character.IsInPlayerParty)
            {
                // find the current controller or an auxiliary controller
                NeverdawnCharacterController controller = character.controller;

                if (!controller)
                {
                    controller = findControllerForCharacter(character);
                }

                // collect the controllers and try to add more characters
                if (!currentTurnControllers.Contains(controller))
                {
                    controller.character = character;

                    currentTurnControllers.Add(controller);

                    turnIndex = NeverdawnUtility.RepeatIndex(turnIndex + 1, currentCombatGroup.Count);
                    character = currentCombatGroup[turnIndex];
                }
                else
                {
                    break;
                }
            }
        }
        else
        {
            currentTurnControllers.Add(character.controller);
            turnIndex = NeverdawnUtility.RepeatIndex(turnIndex + 1, currentCombatGroup.Count);
        }

        NeverdawnCamera.Clear();
        currentTurnControllers.ForEach(c => NeverdawnCamera.AddTargetLerped(c.character.cachedTransform));
    }
Esempio n. 16
0
    private NeverdawnCharacterController findControllerForCharacter(Character character)
    {
        AvatarController preferredController = _controllers.FirstOrDefault(c => c.preferredCharacterId == character.id);

        if (preferredController)
        {
            return(preferredController);
        }
        else
        {
            NeverdawnCharacterController auxiliaryController = _controllers[auxiliaryControllerIndex];
            auxiliaryControllerIndex = NeverdawnUtility.RepeatIndex(auxiliaryControllerIndex + 1, _controllers.Count);
            return(auxiliaryController);
        }
    }
Esempio n. 17
0
    public override void ActionUpdate(float timekey)
    {
        Vector2 fwdTurn = NeverdawnUtility.InputToForwardTurn(character.transform, direction, 1.0f);

        Vector3 forward = character.transform.forward;

        character.transform.forward = Vector3.RotateTowards(forward, direction, timekey * Mathf.PI * 2.0f * (turnSpeed / 360.0f), 0.0f);

        distance += fwdTurn.x * timekey * moveSpeed;
        character.transform.position += direction * fwdTurn.x * timekey * moveSpeed;

        if (distance >= maxDistance)
        {
            Done();
        }
    }
Esempio n. 18
0
    internal Character GetNextCharacter(AvatarController controller = null)
    {
        if (Count == 0)
        {
            return(null);
        }
        else
        {
            int index = 0;

            Vector3    position = GameController.playerSpawnPosition;
            Quaternion rotation = Quaternion.identity;
            Vector3    forward  = Vector3.right;

            if (controller != null && controller.character != null)
            {
                index = characters.IndexOf(controller.character) + 1;

                position = controller.character.transform.position;
                rotation = controller.character.transform.rotation;
                forward  = controller.character.transform.forward;
                PutCharacter(controller.character);
            }

            for (int i = 0; i < characters.Count; i++)
            {
                int currentIndex = NeverdawnUtility.RepeatIndex(index + i, characters.Count);

                Character character = characters[currentIndex];

                if (!character.controller)
                {
                    character.solid.Show();
                    character.transform.position = position;
                    character.transform.forward  = forward;
                    character.GetComponentInChildren <NavMeshAnimator>().Reset();


                    _activeCharacters.Add(character);
                    _hiddenCharacters.Remove(character);
                    return(character);
                }
            }
        }

        return(null);
    }
Esempio n. 19
0
    /// <summary>
    /// Updates the cursor
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="intensity"></param>
    public override void UpdateValues(Vector3 direction, float intensity)
    {
        // TODO: HIDE SELECTOR AND DO THIS PROPERLY
        if (targets.Count == 0)
        {
            return;
        }

        // Check if current target is still valid
        if (Vector3.Distance(character.transform.position, targets[targetIndex].position) > maxRange)
        {
            fetchTargets();
            targetIndex = NeverdawnUtility.RepeatIndex(targetIndex, targets.Count);
        }

        updateSelector();
    }
Esempio n. 20
0
    protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        HexTile startTile = HexTerrain.GetClosestTile(character.position);

        if (startTile == null)
        {
            Done();
            return;
        }

        List <HexTile> path = Pathfinder.FindPath(startTile, targetTile, ignoreTarget ? PathFindingMode.ExcludeTarget : PathFindingMode.None);

        if (path == null)
        {
            Done();
            return;
        }

        if (actor.remainingSteps == 0)
        {
            Done();
            return;
        }

        if (!includeLast)
        {
            path.Remove(targetTile);
        }


        while (path.Count > actor.remainingSteps + 1)
        {
            path.RemoveAt(path.Count - 1);
        }

        targetTile            = path[path.Count - 1];
        actor.remainingSteps -= path.Count - 1;

        Vector3[] line       = NeverdawnUtility.PathAlongTiles(path, 0.1f, 10);
        float     pathLength = NeverdawnUtility.GetPathLength(line);

        action = new CharacterMoveAlongPathAction(line, 1000.0f, 1.0f, run);
        action.ActionStart(actor);
    }
    protected override void OnQuickMenuPageEnabled()
    {
        Character character = avatarController.character;

        selectedIndex = NeverdawnUtility.RepeatIndex(selectedIndex, buttons.Count);

        foreach (KeyValuePair <SkillType, UISkillView> entry in skillViewMap)
        {
            entry.Value.value = character.GetSkillLevel(entry.Key, true).ToString();
        }

        foreach (KeyValuePair <AttributeType, UISkillView> entry in attributeViewMap)
        {
            entry.Value.value = character.GetAttributeLevel(entry.Key, true).ToString();
        }

        buttons[selectedIndex].Select();
    }
Esempio n. 22
0
    // Update is called once per frame
    void Update()
    {
        if (inputModule != null)
        {
            float horizontal = inputModule.GetAxis(NeverdawnInputAxis.HorizontalLeft);
            float vertical   = inputModule.GetAxis(NeverdawnInputAxis.VerticalLeft);

            Vector3 input = inputModule.normalizedDirection;

            if (input.sqrMagnitude < 0.1f)
            {
                if (center != null)
                {
                    center.Select();
                }
                else if (selected != null)
                {
                    selected.Deselect();
                }

                selected = null;
            }

            if (input.sqrMagnitude > 0.1f)
            {
                float inputAngle = Vector3.SignedAngle(Vector3.forward, input, Vector3.up);

                if (inputAngle < 0.0f)
                {
                    inputAngle = 360.0f + inputAngle;
                }

                inputAngle += angle / 2.0f;

                int index = NeverdawnUtility.RepeatIndex((int)(inputAngle / angle), peripherals.Length);

                selected = peripherals[index];
                peripherals[index].Select();
            }

            previousInput = input;
        }
    }
    private List <Vector3> sampleSurroundings(int count, float radius)
    {
        List <Vector3> result = new List <Vector3>();

        float stepWidth = (radius * 2.0f) / (float)count;
        int   count2    = count / 2;

        for (int i = -count2; i < count2; i++)
        {
            for (int j = -count2; j < count2; j++)
            {
                Vector3 position = character.position;
                position.x += stepWidth * i;
                position.z += stepWidth * j;

                NavMeshHit hit;

                if (NavMesh.SamplePosition(position, out hit, 1.0f, NavMesh.AllAreas))
                {
                    position = hit.position;

                    if (Vector3.Distance(position, character.position) <= character.remainingSteps)
                    {
                        NavMeshPath path = new NavMeshPath();

                        if (NavMesh.CalculatePath(character.position, position, NavMesh.AllAreas, path))
                        {
                            if (NeverdawnUtility.GetPathLength(path) <= character.remainingSteps)
                            {
                                result.Add(position);
                            }
                        }
                    }
                }
            }
        }

        return(result);
    }
Esempio n. 24
0
    private void loadEvents()
    {
        events = new Dictionary <string, NeverdawnEventBase>();

        XmlDocument doc = NeverdawnScene.sceneEventsXml;

        XmlNodeList list = doc.GetElementsByTagName("events");

        if (list != null)
        {
            XmlNode eventsNode = list[0];

            if (eventsNode != null)
            {
                foreach (XmlNode node in eventsNode.ChildNodes)
                {
                    NeverdawnEventBase eventBase = NeverdawnUtility.LoadEvent(node);
                    events.Add(eventBase.id, eventBase);
                }
            }
        }
    }
Esempio n. 25
0
    public override void ActionUpdate(float timekey)
    {
        Vector3 position;

        float preferredDistance = distance + timekey * moveSpeed;

        if (!NeverdawnUtility.SamplePath(corners, distances, preferredDistance, out position) || preferredDistance > maxDistance)
        {
            Done();
            return;
        }

        Vector3 dir = (position - transform.position);

        dir.y = 0.0f;
        dir.Normalize();

        Vector2 fwdTurn = NeverdawnUtility.InputToForwardTurn(character.transform, dir, 1.0f);

        Vector3 forward = character.transform.forward;

        character.transform.forward = Vector3.RotateTowards(forward, dir, timekey * Mathf.PI * 2.0f * (turnSpeed / 360.0f), 0.0f);

        distance = distance + fwdTurn.x * timekey * moveSpeed;

        NeverdawnUtility.SamplePath(corners, distances, distance, out position);

        character.transform.position = position;

        RaycastHit rayHit;

        // experimental: stick to ground
        if (Physics.Raycast(character.transform.position + Vector3.up, Vector3.down, out rayHit, 3f, 1 << 9))
        {
            character.transform.position = rayHit.point;
        }
    }
Esempio n. 26
0
    protected override void OnCharacterActionStart(Character actor)
    {
        transform = actor.transform;

        NavMeshPath path = new NavMeshPath();

        if (NavMesh.CalculatePath(transform.position, target, NavMesh.AllAreas, path))
        {
            Vector3[] line       = NeverdawnUtility.RelaxPath(NeverdawnUtility.RefinePath(path.corners, 0.1f), 10);
            float     pathLength = NeverdawnUtility.GetPathLength(line);

            if (pathLength - stoppingDistance < walkDistance)
            {
                walkDistance = pathLength - stoppingDistance;
            }

            action = new CharacterMoveAlongPathAction(line, walkDistance, 1.0f, run);
            action.ActionStart(actor);
        }
        else
        {
            Done();
        }
    }
Esempio n. 27
0
    private void createPath()
    {
        if (NavMesh.CalculatePath(root, targetTransform.position, NavMesh.AllAreas, navMeshPath))
        {
            if (navMeshPath.status != NavMeshPathStatus.PathInvalid)
            {
                float pathLength = NeverdawnUtility.GetPathLength(navMeshPath);

                path = NeverdawnUtility.RelaxPath(NeverdawnUtility.RefinePath(navMeshPath.corners, 0.2f), 10);

                for (int i = 0; i < path.Length; i++)
                {
                    RaycastHit rayHit;

                    // experimental: stick to ground
                    if (Physics.Raycast(path[i] + 2 * Vector3.up, Vector3.down, out rayHit, 4f, 1 << 9))
                    {
                        path[i] = rayHit.point + 0.05f * Vector3.up;
                    }
                }

                if (path.Length > 1)
                {
                    List <Vector3> vertices     = new List <Vector3>();
                    List <int>     triangles    = new List <int>();
                    List <Color>   vertexColors = new List <Color>();

                    Vector3 dir = (path[1] - path[0]);
                    dir.y = 0.0f;
                    dir.Normalize();

                    Vector3 side = Vector3.Cross(dir, Vector3.up).normalized;

                    targetDirection = dir;

                    int colorIndex = 0;

                    vertices.Add(path[0] + width * side);
                    vertices.Add(path[0] - width * side);
                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);

                    int index = 0;

                    for (int i = 1; i < path.Length - 1; i++)
                    {
                        dir  = ((path[i] - path[i - 1]).normalized + (path[i + 1] - path[i]).normalized) / 2.0f;
                        side = Vector3.Cross(dir, Vector3.up).normalized;

                        float distance = NeverdawnUtility.GetPathLength(path, i);

                        colorIndex = distance > maxDistance ? 1 : 0;
                        // colorIndex = NeverdawnUtility.RepeatIndex((int)(distance / walkAbility.maxDistance), colors.Length);

                        vertices.Add(path[i] + width * side);
                        vertices.Add(path[i] - width * side);

                        vertexColors.Add(colors[colorIndex]);
                        vertexColors.Add(colors[colorIndex]);

                        triangles.Add(index + 0);
                        triangles.Add(index + 2);
                        triangles.Add(index + 3);

                        triangles.Add(index + 1);
                        triangles.Add(index + 0);
                        triangles.Add(index + 3);

                        index += 2;

                        //if(distance < walkAbility.maxDistance && NeverdawnUtility.GetPathLength(line, i + 1) > walkAbility.maxDistance)
                        //{
                        //    Vector3 maxPos = Vector3.zero;

                        //    NeverdawnUtility.SamplePath(line, walkAbility.maxDistance, out maxPos);


                        //}
                    }

                    dir  = path[path.Length - 1] - path[path.Length - 2];
                    side = Vector3.Cross(dir, Vector3.up).normalized;

                    vertices.Add(path[path.Length - 1] + width * side);
                    vertices.Add(path[path.Length - 1] - width * side);

                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);

                    triangles.Add(index + 0);
                    triangles.Add(index + 2);
                    triangles.Add(index + 3);

                    triangles.Add(index + 1);
                    triangles.Add(index + 0);
                    triangles.Add(index + 3);

                    vertices.Add(path[path.Length - 1] + 1.5f * width * side);
                    vertices.Add(path[path.Length - 1] - 1.5f * width * side);
                    vertices.Add(path[path.Length - 1] + 0.3f * dir.normalized);

                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);
                    vertexColors.Add(colors[colorIndex]);

                    triangles.Add(vertices.Count - 1);
                    triangles.Add(vertices.Count - 2);
                    triangles.Add(vertices.Count - 3);



                    Mesh mesh = new Mesh();
                    mesh.vertices  = vertices.ToArray();
                    mesh.triangles = triangles.ToArray();
                    mesh.colors    = vertexColors.ToArray();

                    meshFilter.sharedMesh = mesh;
                }
            }
        }
    }
Esempio n. 28
0
    public void UpdateExplorationControls()
    {
        if (character != null)
        {
            if (currentAbility != null)
            {
                updateAbility();
                return;
            }

            if (inputModule.GetAxisUp(NeverdawnInputAxis.Trigger, NeverdawnInputAxisDirection.Positive))
            {
                if (quickSlotsPage != null)
                {
                    quickSlotsPage = null;
                    characterMenu.Close();
                }
            }



            if (inputModule.GetAxisDown(NeverdawnInputAxis.Trigger, NeverdawnInputAxisDirection.Positive))
            {
                if (character.isIdle)
                {
                    quickSlotsPage           = Instantiate(UIFactory.uiQuickMenuQuickSlotsPrefab);
                    quickSlotsPage.abilities = character.quickCastAbilities;

                    characterMenu.Open(quickSlotsPage);
                }
            }

            if (characterMenu.isOpen)
            {
                if (inputModule.GetButtonDown(NeverdawnInputButton.Cancel))
                {
                    characterMenu.GoBack();
                }

                return;
            }

            // DEBUG LVL UP
            if (inputModule.GetButtonDown(NeverdawnInputButton.Info))
            {
                character.LevelUp();
            }

            // Start pressed
            if (inputModule.GetButtonDown(NeverdawnInputButton.Start))
            {
                if (character.isIdle)
                {
                    characterMenu.NavigateInto(Instantiate(UIFactory.uiQuickMenuStartPrefab));
                }
            }

            //Select pressed
            if (inputModule.GetButtonDown(NeverdawnInputButton.Settings))
            {
                if (character.isIdle)
                {
                    GameController.instance.PauseGame();
                }
            }

            // Confirm pressed
            if (inputModule.GetButtonDown(NeverdawnInputButton.Confirm))
            {
                if (character.isIdle)
                {
                    if (currentInteractable != null)
                    {
                        UIQuickMenuInteractable page = Instantiate(UIFactory.uiQuickMenuInteractionCollectionPrefab);
                        page.SetInteractionCollection(currentInteractable);

                        characterMenu.NavigateInto(page);
                    }
                }
                else
                {
                    character.currentAction.ActionConfirm();
                }
            }

            // Cancel pressed
            if (inputModule.GetButtonDown(NeverdawnInputButton.Cancel))
            {
                if (!character.isIdle)
                {
                    character.currentAction.ActionCancel();
                }
                else
                {
                    characterMenu.NavigateInto(Instantiate(UIFactory.uiQuickMenuStartPrefab));
                }
            }

            // Switch character pressed
            if (inputModule.GetButtonDown(NeverdawnInputButton.SwitchCharacter))
            {
                if (character.isIdle)
                {
                    NeverdawnCamera.RemoveTargetLerped(characterTransform);

                    Character nextCharacter = GameController.instance.party.GetNextCharacter(this);

                    if (nextCharacter != null)
                    {
                        character            = nextCharacter;
                        preferredCharacterId = nextCharacter.id;
                    }


                    NeverdawnCamera.AddTargetLerped(characterTransform);

                    // UINeverdawnParty.UpdateView();

                    characterMenu = UICharacterMenus.GetMenu(character);
                }
            }

            // Movement
            if (character.isIdle)
            {
                Vector3 input = inputModule.normalizedDirection;
                smoothedInput = Vector3.RotateTowards(smoothedInput, input, Time.deltaTime * _inputSmoothing, 1.0f);

                // Get player input
                Vector2 fwdTurn = NeverdawnUtility.InputToForwardTurn(characterTransform, smoothedInput, 2.0f);

                // Rotate the player
                characterTransform.Rotate(Vector3.up, fwdTurn.y * Time.deltaTime * characterNavMeshAnimator.turnSpeed);

                // Find target position
                Vector3 targetPosition = characterTransform.position + characterNavMeshAnimator.moveSpeed * fwdTurn.x * characterTransform.forward * Time.deltaTime;

                NavMeshHit hit;

                // Check for valid position
                if (!NavMesh.Raycast(characterTransform.position, targetPosition, out hit, NavMesh.AllAreas))
                {
                    characterTransform.position = hit.position;
                }
                else
                {
                    if (NavMesh.SamplePosition(targetPosition, out hit, 0.1f, NavMesh.AllAreas))
                    {
                        characterTransform.position = hit.position;
                    }
                }

                RaycastHit rayHit;

                // experimental: stick to ground
                if (Physics.Raycast(characterTransform.position, Vector3.down, out rayHit, 0.5f, 1 << 9))
                {
                    characterTransform.position = rayHit.point;
                }
            }

            // Find closest interaction
            Collider[] colliders = Physics.OverlapSphere(character.transform.position, 1.0f, 1 << 10);

            float        minDistance   = float.MaxValue;
            Interactable closestHandle = null;

            for (int i = 0; i < colliders.Length; i++)
            {
                float        distance = Vector3.Distance(colliders[i].transform.position, character.transform.position);
                Interactable handle   = colliders[i].GetComponentInParent <Interactable>();

                if (distance < minDistance && handle != null && handle.enabled)
                {
                    closestHandle = handle;
                    minDistance   = distance;
                }
            }

            if (closestHandle != null)
            {
                updateInteraction(closestHandle);
            }
            else
            {
                updateInteraction(null);
            }
        }
    }
 internal void Select(int selectionIndex)
 {
     index = NeverdawnUtility.RepeatIndex(selectionIndex, selectables.Length);
     updateSelection();
 }
Esempio n. 30
0
    void Update()
    {
        bool containsCharacter = false;


        foreach (Character character in GameController.instance.party.Where(c => c.controller))
        {
            foreach (BoxCollider collider in colliders)
            {
                if (NeverdawnUtility.PointInOABB(character.position, collider))
                {
                    containsCharacter = true;
                }
            }
        }

        if (prevContainsCharacter != containsCharacter)
        {
            solidRenderer.ForEach(r => r.enabled = !containsCharacter);

            //targetAlpha = containsCharacter ? minAlpha : 1.0f;
            //currentAlpha = materials[0].color.a;

            //foreach (Material material in materials)
            //{
            //    if (containsCharacter)
            //    {
            //        material.renderQueue = 3001;
            //    }
            //    else
            //    {

            //        material.renderQueue = 3000;
            //    }

            //}


            lerp = 0.0f;
        }

        //if (lerp <= 1.0f)
        //{
        //    lerp += Time.deltaTime * fadeSpeed;

        //    foreach (Material material in materials)
        //    {
        //        Color color = material.color;
        //        color.a = Mathf.Lerp(currentAlpha, targetAlpha, lerp);

        //        if(color.a >= 0.99f)
        //        {
        //            shadowRenderer.ForEach(r => r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On);
        //            solidRenderer.ForEach(r => r.enabled = false);
        //        }
        //        else
        //        {
        //            shadowRenderer.ForEach(r => r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly);
        //            solidRenderer.ForEach(r => r.enabled = true);
        //        }

        //        //material.SetInt("_ZWrite", color.a < 0.5f ? 0 : 1);

        //        material.color = color;
        //    }

        //}

        prevContainsCharacter = containsCharacter;
    }