示例#1
0
        public void FixedUpdate()
        {
            if (State.Locked)
            {
                return;
            }

            if (!worlditem.HasPlayerFocus)
            {
                mShowingHUD = false;
                HidePivotVisualizers();
                WorldItems.ReturnDoppleganger(FocusDoppleganger);
                if (PivotInFocus != null)
                {
                    PivotInFocus.FocusOnOccupant(false);
                }
                ItemToPlace  = null;
                PivotInFocus = null;
                enabled      = false;
                return;
            }
            else if (!Player.Local.ItemPlacement.PlacementModeEnabled)
            {
                //don't let item placement force us to disable
                mShowingHUD = false;
                HidePivotVisualizers();
                WorldItems.ReturnDoppleganger(FocusDoppleganger);
                if (PivotInFocus != null)
                {
                    PivotInFocus.FocusOnOccupant(false);
                }
                ItemToPlace  = null;
                PivotInFocus = null;
                return;
            }

            bool useDoppleganger = false;

            ItemToPlace = null;
            ReceptaclePivot newPivotInFocus = GetClosestPivot(Player.Local.Surroundings.WorldItemFocusHitInfo.point);

            if (PivotInFocus != null && PivotInFocus != newPivotInFocus)
            {
                PivotInFocus.FocusOnOccupant(false);
            }
            PivotInFocus            = newPivotInFocus;
            FocusPlacementPermitted = false;

            if (PivotInFocus.IsOccupied)
            {
                //we want to highlight the item so we can pick it up
                PivotInFocus.FocusOnOccupant(true);
            }
            else
            {
                //if the player is holding something, highlight it for placement
                if (Player.Local.Tool.IsEquipped)
                {
                    ItemToPlace = Player.Local.Tool.worlditem;
                }
                else if (Player.Local.ItemPlacement.IsCarryingSomething)
                {
                    ItemToPlace = Player.Local.ItemPlacement.CarryObject;
                }
                if (ItemToPlace != null)
                {
                    //get where our player is focusing
                    string errorMessage = string.Empty;
                    if (IsObjectPermitted(ItemToPlace, PivotInFocus.Settings) && ItemToPlace.CanBePlacedOn(this.worlditem, PivotInFocus.tr.position, PivotInFocus.tr.up, ref errorMessage))
                    {
                        //create a doppleganger showing what the player could place here if he wanted
                        FocusDoppleganger = WorldItems.GetDoppleganger(ItemToPlace, PivotInFocus.tr, FocusDoppleganger, WIMode.Placing, 1f / PivotInFocus.tr.lossyScale.x);
                        //check to see if the potential occupant will actually fix
                        FocusDoppleganger.transform.parent        = PivotInFocus.tr;
                        FocusDoppleganger.transform.localPosition = Vector3.zero + ItemToPlace.BasePivotOffset;
                        FocusDoppleganger.transform.localRotation = Quaternion.identity;

                        Mats.Get.ItemPlacementOutlineMaterial.SetColor("_OutlineColor", Colors.Get.MessageSuccessColor);
                        Mats.Get.ItemPlacementMaterial.SetColor("_TintColor", Colors.Get.MessageSuccessColor);
                        if (CanOccupantFit(ItemToPlace, PivotInFocus, Pivots))
                        {
                            FocusPlacementPermitted = true;
                        }
                        else
                        {
                            Mats.Get.ItemPlacementOutlineMaterial.SetColor("_OutlineColor", Colors.Get.MessageDangerColor);
                            Mats.Get.ItemPlacementMaterial.SetColor("_TintColor", Colors.Get.MessageDangerColor);
                        }
                        //this will show the place / pick up commands
                        worlditem.RefreshHud();
                        useDoppleganger = true;
                    }
                    else
                    {
                        FocusPlacementPermitted = false;
                    }
                }
            }

            if (ItemToPlace != null)
            {
                ShowPivotVisualizers(PivotInFocus, Pivots, VisualStyle);
            }

            if (!useDoppleganger && FocusDoppleganger != null)
            {
                GameObject.Destroy(FocusDoppleganger);
            }
        }