Пример #1
0
 private void OnExecuteCommand(ExecuteCommandEvent evt)
 {
     if (evt.commandName == "ObjectSelectorClosed" && addItemField != null)
     {
         UnityEngine.Object addItem = addItemField.value;
         if (addItem != null)
         {
             if (CanBeAdded?.Invoke(addItem) ?? true)
             {
                 if (AddItemAction != null)
                 {
                     AddItemAction(addItem);
                     serializedProperty.serializedObject.Update();
                     UpdateListViewSize();
                 }
                 else
                 {
                     Undo.RecordObject(serializedProperty.serializedObject.targetObject, "Remove item");
                     int newItemIndex = serializedProperty.arraySize;
                     serializedProperty.InsertArrayElementAtIndex(newItemIndex);
                     SerializedProperty itemProperty = serializedProperty.GetArrayElementAtIndex(newItemIndex);
                     itemProperty.objectReferenceValue = addItemField.value;
                     serializedProperty.serializedObject.Update();
                     UpdateListViewSize();
                 }
             }
             addItemField.value = null;
         }
     }
 }
Пример #2
0
        private void EnterNewShip()
        {
            Ship   localShip = new Ship();
            double draft;
            string cargo;
            bool   toUpdate = false;

            localShip.Name = InputName();
            if (CheckIfAlreadyInCue(localShip.Name))
            {
                AlreadyInCueError(localShip);
                return;
            }
            if ((GlobalVar.ShipList.Any(ship => ship.Name == localShip.Name)))
            {
                toUpdate = true;
                Ship ship = GetShipInfo(localShip.Name);
                localShip.Length = ship.Length;
                draft            = InputDraft();
                if (IsDraftTooDeep(draft, localShip.Name))
                {
                    return;
                }
            }
            else
            {
                localShip.Length = InputLength();
            }
            localShip.IsUpstream = InputDirection();
            if (IsSluiceFull(localShip.IsUpstream))
            {
                return;
            }
            cargo = InputCargo(localShip);
            CanBeAdded canBeAdded = CheckLength(localShip);

            switch (canBeAdded)
            {
            case CanBeAdded.Yes:
                if (toUpdate)
                {
                    UpdateShip(localShip, cargo);
                }
                else
                {
                    AddShip(localShip, cargo);
                }
                break;

            case CanBeAdded.NoNotCurrently:
                CantBeAddedAtThisTime(localShip);
                break;
            }
        }