public BehaviorBase(GameObject owner)
 {
     _owner = owner;
     _selectedBehavior = _owner.GetComponent<SelectedBehavior>();
     _visual = _owner.GetComponent<Visual>();
     _behaviors = _owner.GetComponent<Behaviors>();
 }
Exemple #2
0
        private void SetSelectedGameObjectFromBehavior(SelectedBehavior behavior)
        {
            switch (behavior)
            {
            case SelectedBehavior.Restore:
                EventSystem.current.SetSelectedGameObject(_cachedSelection);
                break;

            case SelectedBehavior.SetDefault:
                EventSystem.current.SetSelectedGameObject(DefaultSelectedGameObject);
                break;

            case SelectedBehavior.None:
            default:
                break;
            }
        }
    public void OnDrag(PointerEventData eventData)
    {
        if (!DraggingEnabled())
        {
            return;
        }
        if (!gameObject == itemBeingDragged)
        {
            return;
        }

        transform.position = Input.mousePosition;

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
        {
            if (!hit.transform.gameObject.GetComponent<Behaviors>().GetBehavior(gameObject.name).Available)
            {
                return;
            }

            var selection = hit.transform.gameObject.GetComponent<SelectedBehavior>();
            if (selection != null && selectedBehavior != selection)
            {
                RemoveTempSelection();
                selection.SetPreview(gameObject.name);
                FindObjectOfType<Mirror>().SetMirrorPreview(selection.gameObject, gameObject.name);
                selectedBehavior = selection;
            }
        }
        else if (selectedBehavior != null)
        {
            RemoveTempSelection();
        }
    }
    private void SetPrevious(SelectedBehavior previousSelectedBehavior, Direction currentDirection, string direction)
    {
        if (previousSelectedBehavior.GetPreview() == "BridgeUpDown")
        {
            return;
        }

        if (chain.Any() && previousSelectedBehavior.gameObject != chain.First().gameObject)
        {
            SetPrevew(previousSelectedBehavior, direction);
        }
        else
        {
            switch (currentDirection)
            {
                case Direction.Up:
                    if (previousSelectedBehavior.IsNameSelected("Left"))
                    {
                        SetPrevew(previousSelectedBehavior, "DownLeft");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Right"))
                    {
                        SetPrevew(previousSelectedBehavior, "RightDown");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Up"))
                    {
                        SetPrevew(previousSelectedBehavior, "UpDown");
                    }
                    else
                    {
                        SetPrevew(previousSelectedBehavior, "Down");
                    }
                    break;
                case Direction.Down:
                    if (previousSelectedBehavior.IsNameSelected("Left"))
                    {
                        SetPrevew(previousSelectedBehavior, "LeftUp");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Right"))
                    {
                        SetPrevew(previousSelectedBehavior, "UpRight");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Down"))
                    {
                        SetPrevew(previousSelectedBehavior, "UpDown");
                    }
                    else
                    {
                        SetPrevew(previousSelectedBehavior, "Up");
                    }
                    break;
                case Direction.Right:
                    if (previousSelectedBehavior.IsNameSelected("Right"))
                    {
                        SetPrevew(previousSelectedBehavior, "LeftRight");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Up"))
                    {
                        SetPrevew(previousSelectedBehavior, "LeftUp");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Down"))
                    {
                        SetPrevew(previousSelectedBehavior, "DownLeft");
                    }
                    else
                    {
                        SetPrevew(previousSelectedBehavior, "Left");
                    }
                    break;
                case Direction.Left:
                    if (previousSelectedBehavior.IsNameSelected("Left"))
                    {
                        SetPrevew(previousSelectedBehavior, "LeftRight");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Up"))
                    {
                        SetPrevew(previousSelectedBehavior, "UpRight");
                    }
                    else if (previousSelectedBehavior.IsNameSelected("Down"))
                    {
                        SetPrevew(previousSelectedBehavior, "RightDown");
                    }
                    else
                    {
                        SetPrevew(previousSelectedBehavior, "Right");
                    }
                    break;
                default:
                    break;
            }
        }
    }
 private void SetPrevew(SelectedBehavior currentSelectedBehavior, string name)
 {
     var behavior = currentSelectedBehavior.GetComponent<Behaviors>().GetBehavior(name);
     if (behavior.Available)
     {
         FindObjectOfType<Mirror>().SetMirrorPreview(currentSelectedBehavior.gameObject, name);
         currentSelectedBehavior.SetPreview(name);
     }
 }
 private void SetCurrent(SelectedBehavior currentSelectedBehavior, string name)
 {
     if (IsInStack(currentSelectedBehavior.gameObject))
     {
         SetPrevew(currentSelectedBehavior, "BridgeUpDown");
     }
     else
     {
         SetPrevew(currentSelectedBehavior, name);
     }
 }
    private void RemoveTempSelection()
    {
        if (selectedBehavior != null)
        {
            FindObjectOfType<Mirror>().ClearMirrorPreview(selectedBehavior.gameObject);
            selectedBehavior.ClearPreview();
        }

        selectedBehavior = null;
    }
 void Start()
 {
     _behaviors = GetComponent<Behaviors>();
     _selectedBehavior = GetComponent<SelectedBehavior>();
 }
 private void ToggleSingleSelection(SelectedBehavior selectedBehavior, bool removeSelection)
 {
     if (removeSelection)
     {
         FindObjectOfType<Mirror>().RemoveSelection(selectedBehavior.gameObject, name);
         selectedBehavior.RemoveSelection(this.gameObject.name);
     }
     else
     {
         FindObjectOfType<Mirror>().SetMirror(selectedBehavior.gameObject, name);
         selectedBehavior.SelectBehavior(this.gameObject.name);
     }
 }