public void Init(SelectableTarget target)
    {
        // Set up a singleton
        radialInstace = this;

        // Cache target
        this.target = target;

        mainCam            = GameController.Instance.mainCamera;
        transform.position = mainCam.WorldToScreenPoint(target.transform.position);

        // Init the buttons
        int buttonCount = buttonPrefabs.Length;

        buttonInstances = new RectTransform[buttonCount];

        float counterOffset = ((buttonCount - 1) * angle) / 2;

        // Spawn, set sprite and begin tracking buttons, lay out in radial menu by angle and count
        for (int i = 0; i < buttonCount; ++i)
        {
            Vector3 v = new Vector3(0, -pixelOffset, 0);
            v = Quaternion.Euler(0, 0, i * angle - counterOffset) * v;

            GameObject newButton = Instantiate(buttonPrefabs[i], transform);
            newButton.transform.localPosition = v;

            buttonInstances[i] = newButton.GetComponent <RectTransform>();
        }
    }
    public void SetTarget(SelectableTarget currentTarget)
    {
        // Disable character target line renderer
        if (this.currentTarget != null)
        {
            // Destroy the old selection world radial menu
            if (WorldUIRadial.Instance != null)
            {
                Destroy(WorldUIRadial.Instance.gameObject);
            }

            switch (this.currentTarget.TargetSelectionProfile.selectionType)
            {
            case SelectionType.Character:
            {
                SelectableCharacter character = (SelectableCharacter)(this.currentTarget);
                character.pathTracer.SetNavPathTrace(false);
                character.inventory.SetOpen(false);
            }
            break;

            case SelectionType.Container:
            {
                SelectableContainer container = (SelectableContainer)(this.currentTarget);
                container.container.SetOpen(false);
            }
            break;
            }

            GameController.Instance.crewTargetDirection.ForceCleanupMenu();
            GameController.Instance.crewTargetDirection.ForceCleanUpInventories();
        }

        // Set the new target
        this.currentTarget = currentTarget;

        // If character, turn on line renderer
        // Disable character target line renderer
        if (this.currentTarget != null)
        {
            WorldUIRadial radialMenu = Instantiate(worldUIMenuPrefab, GameController.Instance.selectionDisplay.transform).GetComponent <WorldUIRadial>();
            radialMenu.Init(currentTarget);

            switch (this.currentTarget.TargetSelectionProfile.selectionType)
            {
            case SelectionType.Character:
            {
                ((SelectableCharacter)(this.currentTarget)).pathTracer.SetNavPathTrace(true);
            }
            break;
            }
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        bool  overBar;
        Panel panelHover = GameController.Instance.panelController.TestOverPanel(out overBar);

        if (panelHover != null)
        {
            panelHover.OnPanelHover();
        }

        // Left click try and select target
        if (Input.GetMouseButtonDown(0))
        {
            // hoverring main panel and clicked, bring to front
            if (panelHover != null)
            {
                GameController.Instance.panelController.BringToFront(panelHover);

                if (overBar) // Clicked a drag bar of panel
                {
                    GameController.Instance.panelController.StartDrag();
                }
                else // Clicked a window of panel
                {
                    panelHover.OnPanelClick();
                }
            }
            else
            {
                Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                if (!GameController.Instance.selectionDisplay.TestSelectionButtons()) // Test if clicked selection buttons
                {
                    // Test if clicked radial menu
                    bool          radialClicked       = false;
                    WorldUIRadial radialMenuCandidate = WorldUIRadial.Instance;
                    if (radialMenuCandidate != null)
                    {
                        radialClicked = radialMenuCandidate.TestWorldClickButtons();
                    }

                    if (!radialClicked)
                    {
                        GameController.Instance.targetSelection.DoTargetSearch(mousePos);
                    }
                }
            }
        }

        if (!Input.GetMouseButton(0))
        {
            GameController.Instance.panelController.ForceStopDrag();
        }

        // Left mouse button UP do release logic on target window
        if (Input.GetMouseButtonUp(0))
        {
            // hoverring main panel and released, bring to front
            if (panelHover != null)
            {
                GameController.Instance.panelController.BringToFront(panelHover);

                if (!overBar) // Released on main window, not bar
                {
                    panelHover.OnPanelReleaseClick();
                }
            }
        }

        // Right click, direct selected character to target location
        if (Input.GetMouseButtonDown(1))
        {
            SelectableTarget currentTarget = GameController.Instance.targetSelection.CurrentTarget;

            if (currentTarget != null)
            {
                switch (currentTarget.TargetSelectionProfile.selectionType)
                {
                case SelectionType.Character:
                {
                    SelectableCharacter character = (SelectableCharacter)currentTarget;

                    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    if (!GameController.Instance.crewTargetDirection.DoTargetSearch(mousePos, character))
                    {
                        character.playerCrewAI.NavToMouse();
                    }
                }
                break;
                }
            }
        }
    }