コード例 #1
0
    private void Start()
    {
        (LoadedEntity.Entity as HumanoidEntity).EquiptmentManager.SetLoadedEquiptmentManager(this);

        HAND_R.GetComponent <LoadedMeleeWeapon>().SetWeaponDetails(LoadedEntity.Entity, null);
        LoadedEntity.Entity.CombatManager.SetLoadedMeleeWeapon(HAND_R.GetComponent <LoadedMeleeWeapon>());
        EquiptStartItems((LoadedEntity.Entity as HumanoidEntity).EquiptmentManager);
    }
コード例 #2
0
    public void SetEquiptmentItem(LoadedEquiptmentPlacement slot, Item item)
    {
        Debug.Log("[LoadedEquiptmentManager] Adding item " + item + " to slot " + slot);

        //Check if an item exists in this slot, if so we destroy it
        GameObject remove;

        EquiptObjects.TryGetValue(slot, out remove);
        if (remove != null)
        {
            DestroyImmediate(remove);
            EquiptObjects.Remove(slot);
            //If the equipt slot required a blendShape, we reset it now
            if (slot == LoadedEquiptmentPlacement.legs)
            {
                SMR.SetBlendShapeWeight(0, 0);
            }
            else if (slot == LoadedEquiptmentPlacement.chest)
            {
                SMR.SetBlendShapeWeight(1, 0);
            }
        }
        //If the item is null, we don't need to add an object
        if (item == null)
        {
            //But if the slot is the hand, we need to activate the unarmed melee attack
            if (slot == LoadedEquiptmentPlacement.weaponHand)
            {
                LoadedEntity.Entity.CombatManager.SetLoadedMeleeWeapon(HAND_R.GetComponent <LoadedMeleeWeapon>());
                //Ensure it is enabled so we can deal unarmed attacks
            }
            else if (slot == LoadedEquiptmentPlacement.legs)
            {
                SMR.SetBlendShapeWeight(0, 0);
            }
            else if (slot == LoadedEquiptmentPlacement.chest)
            {
                SMR.SetBlendShapeWeight(1, 0);
            }



            return;
        }

        //We create the object
        GameObject obj = Instantiate((item as EquiptableItem).GetEquiptItem());
        //Non weapons will have a
        LoadedEquiptment le = obj.GetComponent <LoadedEquiptment>();

        switch (slot)
        {
        case LoadedEquiptmentPlacement.weaponSheath:
            obj.transform.parent = WEAPONSHEATH.transform;
            break;

        case LoadedEquiptmentPlacement.weaponHand:
            obj.transform.parent = HAND_R.transform;
            break;

        case LoadedEquiptmentPlacement.offHand:
            obj.transform.parent = HAND_L.transform;
            break;

        case LoadedEquiptmentPlacement.legs:

            le.transform.parent = SMR.transform;
            le.SMR.bones        = SMR.bones;
            le.SMR.rootBone     = SMR.rootBone;
            Debug.Log("[LoadedEquiptmentManager] Equipting to legs - setting blend shape to 100");
            SMR.SetBlendShapeWeight(0, 100);
            break;

        case LoadedEquiptmentPlacement.chest:
            le.transform.parent = SMR.transform;
            le.SMR.bones        = SMR.bones;
            le.SMR.rootBone     = SMR.rootBone;
            Debug.Log("[LoadedEquiptmentManager] Equipting to chest - setting blend shape to 100");
            SMR.SetBlendShapeWeight(1, 100);
            break;
        }

        if (item.HasMetaData)
        {
            Color c = item.MetaData.Color;
            if (c != null)
            {
                if (le != null)
                {
                    le.SMR.material.SetColor("MainColour", c);
                }
                else if (obj.GetComponent <MeshRenderer>() != null)
                {
                    obj.GetComponent <MeshRenderer>().material.SetColor("MainColour", c);
                }
                else if (obj.GetComponent <SkinnedMeshRenderer>() != null)
                {
                    obj.GetComponent <SkinnedMeshRenderer>().material.SetColor("MainColour", c);
                }
                else if (obj.GetComponentInChildren <MeshRenderer>() != null)
                {
                    obj.GetComponentInChildren <MeshRenderer>().material.SetColor("MainColour", c);
                }
                else if (obj.GetComponentInChildren <SkinnedMeshRenderer>() != null)
                {
                    obj.GetComponentInChildren <SkinnedMeshRenderer>().material.SetColor("MainColour", c);
                }
            }
        }


        if (item is Weapon && !(item is RangeWeapon))
        {
            LoadedMeleeWeapon lmw = obj.GetComponent <LoadedMeleeWeapon>();
            if (lmw == null)
            {
                lmw = obj.GetComponentInChildren <LoadedMeleeWeapon>();
            }
            lmw.SetWeaponDetails(LoadedEntity.Entity, item as Weapon);
            LoadedEntity.Entity.CombatManager.SetLoadedMeleeWeapon(lmw);
        }

        obj.transform.localPosition = Vector3.zero;
        obj.transform.localRotation = Quaternion.identity;
        if (EquiptObjects.ContainsKey(slot))
        {
            EquiptObjects[slot] = obj;
        }
        else
        {
            EquiptObjects.Add(slot, obj);
        }
    }