public EditPartyViewModel(Unit[] units, UserParty party = null)
        {
            m_UnitsCollection      = new ObservableCollection <Unit>(units);
            UnitList               = m_UnitsCollection.ToReadOnlyReactiveCollection(x => new UnitViewModel(x));
            m_PartyUnitsCollection = new ObservableCollection <UserUnit>();
            PartyUnits             = m_PartyUnitsCollection.ToReadOnlyReactiveCollection(x => new UserUnitViewModel(x, () => UnselectUserUnit(x)));

            OnCancel.Subscribe(x => CloseWindow((Window)x));
            OnSubmit.Subscribe(x => SaveParty((Window)x));

            OnSearchTextChanged.Subscribe(() => { SearchUnit(SearchText.Value); });

            ShowUnitType.Subscribe(OnChangeShowUnitType);
            OnChangeSelected.Subscribe(OnChangeSelectedUnit);

            OnAddTag.Subscribe(() =>
            {
                var window = new AddTagWindow(tag =>
                {
                    Tags.Add(new TagViewModel(tag, OnRemoveTag));
                });
                window.ShowDialog();
            });

            if (party != null)
            {
                m_Party     = party;
                m_PartUnits = party.UserUnits.ToList();
                foreach (var unitViewModel in UnitList)
                {
                    if (m_PartUnits.Any(x => x.UnitId == unitViewModel.Unit.Id))
                    {
                        unitViewModel.SetSelect(true);
                    }
                }
                m_PartyUnitsCollection.Clear();
                foreach (var unit in m_PartUnits)
                {
                    m_PartyUnitsCollection.Add(unit);
                }

                IsFullParty.Value       = true;
                IsVisibleSelected.Value = Visibility.Visible;
                PartyComment.Value      = party.Comment;
                EstimateDamage.Value    = party.EstimateDamage;

                Tags.Clear();
                if (party.Tags?.Length > 0)
                {
                    var vms = party.Tags
                              .Select(x => Database.I.Tags.SingleOrDefault(db => db.Id == x))
                              .Select(x => new TagViewModel(x, OnRemoveTag));
                    Tags.AddRange(vms);
                }
            }
        }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        var ray = mainCamera.ScreenPointToRay(Input.mousePosition);

        Debug.DrawRay(ray.origin, ray.direction * 100f, Color.red, 1f);

        if (Physics.Raycast(ray, out var hitInfo))
        {
            if (Instance.isAnySelected == false)
            {
                if (Input.GetButtonDown("Fire1"))
                {
                    var newEntity = hitInfo.collider.GetComponent <Instance>();
                    if (currentInstance != newEntity)
                    {
                        currentInstance = newEntity;
                        currentInstance.OnSelect();
                        OnChangeSelected?.Invoke(newEntity);
                    }
                }
                else
                {
                    var newEntity = hitInfo.collider.GetComponent <Instance>();
                    if (highlitedInstance != newEntity)
                    {
                        highlitedInstance = newEntity;

                        highlitedInstance.OnHover();
                        OnChangeHighlited?.Invoke(newEntity);
                    }
                }
            }
        }
        else
        {
            if (Input.GetButtonDown("Fire1"))
            {
                if (currentInstance != null)
                {
                    currentInstance.OnDeselected();
                    currentInstance = null;
                    OnChangeSelected?.Invoke(null);
                }
            }
            else
            {
                if (highlitedInstance != null && Instance.isAnySelected == false)
                {
                    highlitedInstance.OnHoverOut();
                    highlitedInstance = null;
                    OnChangeHighlited?.Invoke(null);
                }
            }
        }
    }