예제 #1
0
        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);
            }
        }