コード例 #1
0
ファイル: WeaponRackSlot.cs プロジェクト: DevZhav/The-Forest
        private void SpawnNonEquipmentItemView()
        {
            InventoryItemView inventoryItemView  = LocalPlayer.Inventory.InventoryItemViewsCache[this._storedItemId][0];
            InventoryItemView inventoryItemView2 = UnityEngine.Object.Instantiate <InventoryItemView>(inventoryItemView);
            Vector3           position           = base.transform.position;
            Quaternion        rotation           = base.transform.rotation;
            Item          item = ItemDatabase.ItemById(this._storedItemId);
            RackPlacement placementOverride = this.GetPlacementOverride(item);

            if (placementOverride != null)
            {
                Vector3    zero     = Vector3.zero;
                Quaternion identity = Quaternion.identity;
                Vector3    one      = Vector3.one;
                placementOverride.ApplyTo(ref zero, ref identity, ref one);
                inventoryItemView2.transform.localScale     = one;
                inventoryItemView2.transform.parent         = base.transform;
                inventoryItemView2.transform.localPosition  = zero;
                inventoryItemView2.transform.localRotation  = identity;
                inventoryItemView2.transform.localPosition += WeaponRackSlot.GetJitterVector3(this._jitterPosition);
                inventoryItemView2.transform.localRotation  = Quaternion.Euler(WeaponRackSlot.GetJitterVector3(this._jitterRotation)) * inventoryItemView2.transform.localRotation;
            }
            else
            {
                Vector3 position2 = position;
                position2.y += inventoryItemView.transform.position.y - LocalPlayer.Inventory._inventoryGO.transform.position.y;
                inventoryItemView2.transform.localScale = inventoryItemView.transform.lossyScale;
                inventoryItemView2.transform.parent     = base.transform;
                inventoryItemView2.transform.position   = position2;
                inventoryItemView2.transform.rotation   = inventoryItemView.transform.rotation;
            }
            inventoryItemView2.gameObject.layer = base.gameObject.layer;
            inventoryItemView2.gameObject.SetActive(true);
            this._storedItemGO = inventoryItemView2.gameObject;
            UnityEngine.Object.Destroy(inventoryItemView2.GetComponent <Collider>());
            UnityEngine.Object.Destroy(inventoryItemView2);
            VirtualCursorSnapNode component = this._storedItemGO.GetComponent <VirtualCursorSnapNode>();

            if (component)
            {
                UnityEngine.Object.Destroy(component);
            }
            StoreInformation component2 = this._storedItemGO.GetComponent <StoreInformation>();

            if (component2)
            {
                UnityEngine.Object.Destroy(component2);
            }
            if (this.OnItemAdded != null)
            {
                this.OnItemAdded.Invoke(this._storedItemId);
            }
        }
コード例 #2
0
ファイル: WeaponRackSlot.cs プロジェクト: DevZhav/The-Forest
        private void SpawnEquipmentItemView()
        {
            Reparent.Locked = true;
            InventoryItemView inventoryItemView = LocalPlayer.Inventory.InventoryItemViewsCache[this._storedItemId][0];

            if (inventoryItemView._held == null)
            {
                Debug.LogError(string.Concat(new string[]
                {
                    "Attempting to spawn invalid item! No 'held' version of \"",
                    ItemDatabase.ItemById(this._storedItemId)._name,
                    "\" \"",
                    base.gameObject.GetFullName(),
                    "\""
                }));
                return;
            }
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(inventoryItemView._held);
            FakeParent component  = inventoryItemView._held.GetComponent <FakeParent>();

            if (this._applyUpsideDownOffset && inventoryItemView.ItemCache._allowUpsideDownPlacement)
            {
                gameObject.transform.parent        = this._upsideDownBaseOffset;
                gameObject.transform.localPosition = ((!component) ? inventoryItemView._held.transform.localPosition : component.RealLocalPosition) + inventoryItemView.ItemCache._upsideDownOffset;
            }
            else
            {
                gameObject.transform.parent        = base.transform;
                gameObject.transform.localPosition = ((!component) ? inventoryItemView._held.transform.localPosition : component.RealLocalPosition);
            }
            gameObject.transform.localRotation = ((!component) ? inventoryItemView._held.transform.localRotation : component.RealLocalRotation);
            gameObject.transform.parent        = base.transform;
            ItemUtils.FixItemPosition(gameObject, this._storedItemId);
            Item          item = ItemDatabase.ItemById(this._storedItemId);
            RackPlacement placementOverride = this.GetPlacementOverride(item);

            if (placementOverride != null)
            {
                Vector3    zero     = Vector3.zero;
                Quaternion identity = Quaternion.identity;
                Vector3    one      = Vector3.one;
                placementOverride.ApplyTo(ref zero, ref identity, ref one);
                gameObject.transform.localScale     = one;
                gameObject.transform.parent         = base.transform;
                gameObject.transform.localPosition  = zero;
                gameObject.transform.localRotation  = identity;
                gameObject.transform.localPosition += WeaponRackSlot.GetJitterVector3(this._jitterPosition);
                gameObject.transform.localRotation  = Quaternion.Euler(WeaponRackSlot.GetJitterVector3(this._jitterRotation)) * gameObject.transform.localRotation;
            }
            gameObject.layer = base.gameObject.layer;
            Animator animator = gameObject.GetComponent <Animator>() ?? gameObject.transform.GetChild(0).GetComponent <Animator>();

            if (animator)
            {
                UnityEngine.Object.Destroy(animator);
            }
            this.CleanUpComponents(gameObject.transform);
            gameObject.SetActive(true);
            foreach (MonoBehaviour obj in gameObject.GetComponentsInChildren <MonoBehaviour>())
            {
                UnityEngine.Object.Destroy(obj);
            }
            this._storedItemGO = gameObject;
            Reparent.Locked    = false;
            if (this.OnItemAdded != null)
            {
                this.OnItemAdded.Invoke(this._storedItemId);
            }
        }