Esempio n. 1
0
    public void AttachObjectTo(GameObject parent, string prefab)
    {
        if (null == _mTagPointRootGameObject)
        {
            return;
        }

        AttachmentSlot attachmentSlot = null;
        bool           isContain      = _mAttachmentSlotList.TryGetValue(parent.GetInstanceID(), out attachmentSlot);

        if (!isContain || attachmentSlot == null)
        {
            attachmentSlot = new AttachmentSlot(parent);
            _mAttachmentSlotList.Add(parent.GetInstanceID(), attachmentSlot);
        }

        Object obj = Resources.Load(prefab);

        if (null == obj)
        {
            //
            return;
        }

        GameObject result = attachmentSlot.AttachObject(obj, Vector3.zero, Quaternion.identity);

        obj = null;
    }
Esempio n. 2
0
 public void DetachLimb(LimbType limb, AttachmentSlot slot)
 {
     int slotIndex = limbSlots.FindIndex(s => s == slot);
     if (slotIndex != -1 && slotIndex < slotTracks.Count)
     {
         SlotTracks tracks = slotTracks[slotIndex];
         tracks.MuteTrack(limb);
     }
 }
Esempio n. 3
0
    public Item Equip(AttachmentSlotId slotId, InventoryItem inventoryItem)
    {
        if (_slotLocks[slotId])
        {
            return(null);
        }

        if (!Inventory.Contains(inventoryItem))
        {
            return(null);
        }

        AttachableContext attachable = (AttachableContext)inventoryItem.context;

        Debug.AssertFormat(attachable, string.Format("Failed to equip: item '{0}' is not attachable", inventoryItem.context.name));

        AttachmentSlot slot = _slots.FirstOrDefault(x => x.SlotId == slotId);

        Debug.AssertFormat(slot != null, string.Format("No slot found with slot id '{0}'", slotId));

        if (_equippedItems[slotId] != null)
        {
            if (!_equippedItems[slotId].GetStateInfo().Depleted)
            {
                // Unequip currently equipped and re-add to the inventory
                AddToInventory(new InventoryItem(
                                   _equippedItems[slotId].GetContext(),
                                   _equippedItems[slotId].GetStateInfo()));
            }
            GameObject.Destroy(_equippedItems[slotId].gameObject);
        }

        // Spawn and equip item from inventory
        Item spawnedItem = GameObject.Instantiate(inventoryItem.context.Prefab);

        _equippedItems[slotId] = spawnedItem;
        if (inventoryItem.stateInfo != null)
        {
            _equippedItems[slotId].InitStateInfo(inventoryItem.stateInfo);
        }

        spawnedItem.transform.SetPositionAndRotation(
            slot.BoneTransform.position,
            slot.BoneTransform.rotation);
        spawnedItem.transform.SetParent(slot.BoneTransform);
        spawnedItem.transform.localPosition = attachable.AttachmentPositionOffset;
        spawnedItem.transform.localRotation = Quaternion.Euler(attachable.AttachmentRotationOffset);

        // Remove inventory item of equiped item
        RemoveFromInventory(inventoryItem);

        OnEquipmentChanged.Invoke(inventoryItem.context);
        return(spawnedItem);
    }
        public TurretComponent Assemble(ObjectModel model, Transform parent, TurretAssembly assembly, AssemblyContext context)
        {
            IContentCachedPrefab component    = GetComponent(model.GetValue <string>("UniqueIdentifier"));
            ValueAssembler       assembler    = new ValueAssembler();
            GameObject           obj          = component.Instantiate();
            TurretComponent      newComponent = obj.GetComponent <TurretComponent>();

            if (parent != null)
            {
                obj.transform.SetParent(parent.transform);
                var position = (Vector2)assembler.Assemble(model.GetObject("LocalPosition"), typeof(Vector2), context);

                obj.transform.localPosition = (Vector3)position + Vector3.back * 0.1f;

                if (model.HasProperty("Angle"))
                {
                    obj.transform.localRotation = Quaternion.Euler(0f, 0f, model.GetValue <float>("Angle"));
                }
                if (model.HasProperty("Flipped"))
                {
                    if (model.GetValue <bool>("Flipped"))
                    {
                        newComponent.Flip();
                    }
                }

                TurretComponent parentComponent = parent.GetComponent <TurretComponent>();
                foreach (var point in newComponent.AttachmentPoints)
                {
                    AttachmentSlot slot = FindSlotForPoint(parentComponent.AttachmentSlots.GetSupportingPoints(point), point, obj.transform, parent.transform);
                    if (slot != null)
                    {
                        slot.Attach(newComponent);
                    }
                }
            }
            else
            {
                obj.transform.SetParent(assembly.transform);
                obj.transform.localPosition = Vector3.zero;
            }

            foreach (ValueModel child in model.GetArray("Children"))
            {
                Assemble(child as ObjectModel, newComponent.transform, assembly, context);
            }

            return(newComponent);
        }
Esempio n. 5
0
    public void DetachObjectFrom(GameObject parent, GameObject child)
    {
        if (null == _mTagPointRootGameObject)
        {
            return;
        }

        AttachmentSlot attachmentSlot = null;
        bool           isContain      = _mAttachmentSlotList.TryGetValue(parent.GetInstanceID(), out attachmentSlot);

        if (!isContain)
        {
            return;
        }

        attachmentSlot.DetachObject(child);
    }
Esempio n. 6
0
    public void AttachObjectTo(GameObject parent, GameObject child)
    {
        if (null == _mTagPointRootGameObject)
        {
            return;
        }

        AttachmentSlot attachmentSlot = null;
        bool           isContain      = _mAttachmentSlotList.TryGetValue(parent.GetInstanceID(), out attachmentSlot);

        if (!isContain || attachmentSlot == null)
        {
            attachmentSlot = new AttachmentSlot(parent);
            _mAttachmentSlotList.Add(parent.GetInstanceID(), attachmentSlot);
        }

        GameObject result = attachmentSlot.AttachObject(child, Vector3.zero, Quaternion.identity);
    }
Esempio n. 7
0
    public Bone GetBoneForSlot(AttachmentSlot slot)
    {
        switch (slot)
        {
            case AttachmentSlot.Neck:
                return Neck;
            case AttachmentSlot.Spine:
                return Spine;
            case AttachmentSlot.LeftShoulder:
                return LeftShoulder;
            case AttachmentSlot.RightShoulder:
                return RightShoulder;
            case AttachmentSlot.LeftHip:
                return LeftHip;
            case AttachmentSlot.RightHip:
                return RightHip;
        }

        return null;
    }
Esempio n. 8
0
        protected void AddAttachmentSlot(GameObject attachPoint, PlayerInput input = null)
        {
            if (FindAttachmentSlot(attachPoint) != null)
            {
                Debug.LogError("GamePlayer: Trying to add an attachment point that is already assigned to an attachment slot!");
                return;
            }

            if (input != null && IsAttachmentSlotInputAssigned(input))
            {
                Debug.LogError("GamePlayer: Trying to add a a player input that is already assign to an attachment slot!");
                return;
            }


            var attachmentSlot = new AttachmentSlot();

            attachmentSlot.attachPoint = attachPoint;
            attachmentSlot.input       = input;

            _attachmentSlots.Add(attachmentSlot);
        }
Esempio n. 9
0
 protected override void OnEquip(AttachmentSlot slot)
 {
     throw new NotImplementedException();
 }
Esempio n. 10
0
        //public override bool OnSerialize(NetworkWriter writer, bool initialState)
        //{
        //    bool wroteSync = base.OnSerialize(writer, initialState);

        //    writer.Write(synctest);

        //    return wroteSync;
        //}

        //public override void OnDeserialize(NetworkReader reader, bool initialState)
        //{
        //    base.OnDeserialize(reader, initialState);

        //    synctest = reader.ReadInt32();
        //    Debug.Log("Deserialize " + synctest);
        //}


        // todo: these functions don't need to be abstract anymore
        protected virtual void OnEquip(AttachmentSlot slot)
        {
        }
Esempio n. 11
0
 protected int GetSlotIndex(AttachmentSlot slot)
 {
     return(_attachmentSlots.IndexOf(slot));
 }
Esempio n. 12
0
 //public override bool OnSerialize(NetworkWriter writer, bool initialState)
 //{
 //    bool wroteSync = base.OnSerialize(writer, initialState);
 //    writer.Write(synctest);
 //    return wroteSync;
 //}
 //public override void OnDeserialize(NetworkReader reader, bool initialState)
 //{
 //    base.OnDeserialize(reader, initialState);
 //    synctest = reader.ReadInt32();
 //    Debug.Log("Deserialize " + synctest);
 //}
 // todo: these functions don't need to be abstract anymore
 protected virtual void OnEquip(AttachmentSlot slot)
 {
 }
Esempio n. 13
0
 protected int GetSlotIndex(AttachmentSlot slot)
 {
     return _attachmentSlots.IndexOf(slot);
 }
Esempio n. 14
0
 protected override void OnEquip(AttachmentSlot slot)
 {
     _currentlyEquipped = slot.item;
 }
Esempio n. 15
0
 public AttachmentPoint GetJointForSlot(AttachmentSlot slot)
 {
     return allJoints.FirstOrDefault(j => j.slot == slot);
 }
Esempio n. 16
0
    public void OnLimbAdded(RobotComponent limb, AttachmentSlot slot, AttachmentType type)
    {
        if (type == AttachmentType.Arm)
        {
            currentArms.Add(limb);
            if (activeArm == null)
            {
                NextArmAbility();
            }
        }

        if (type == AttachmentType.Leg)
        {
            currentLegs.Add(limb);
            if (activeLeg == null)
            {
                NextLegAbility();
            }
        }

        allComponents.Add(limb);

        transform.eulerAngles = Vector3.zero;

        AudioSource.PlayClipAtPoint(limbRemoveSound, transform.position);

        switch (slot)
        {
            case AttachmentSlot.LeftHip:
                anim.SetBool("hasLeftLeg", true);
                break;
            case AttachmentSlot.RightHip:
                anim.SetBool("hasRightLeg", true);
                break;
            case AttachmentSlot.Spine:
                if (limb is TorsoComponent)
                {
                    anim.SetBool("hasTorso", true);
                }
                else
                {
                    anim.SetBool("hasLimbAsTorso", true);

                }
                break;
        }

        RefreshInputHints();
    }
Esempio n. 17
0
 protected override void OnEquip(AttachmentSlot slot)
 {
 }
Esempio n. 18
0
    public void OnLimbRemoved(RobotComponent limb, AttachmentSlot slot, AttachmentType type)
    {
        if (type == AttachmentType.Arm)
        {
            if (anim)
            {
                anim.SetBool("aimLeft", false);
                anim.SetBool("aimRight", false);
            }

            currentArms.Remove(limb);
            if (limb == activeArm)
            {
                activeArm = null;
                NextArmAbility();
            }
        }

        if (type == AttachmentType.Leg)
        {
            currentLegs.Remove(limb);
            if (limb == activeLeg)
            {
                activeLeg = null;
                NextLegAbility();
            }
        }

        allComponents.Remove(limb);

        rigidbody2D.fixedAngle = HasLimbs;

        AudioSource.PlayClipAtPoint(limbAttachSound, transform.position);

        switch (slot)
        {
            case AttachmentSlot.LeftHip:
                anim.SetBool("hasLeftLeg", false);
                break;
            case AttachmentSlot.RightHip:
                anim.SetBool("hasRightLeg", false);
                break;
            case AttachmentSlot.Spine:
                if (limb is TorsoComponent)
                {
                    anim.SetBool("hasTorso", false);
                }
                else
                {
                    anim.SetBool("hasLimbAsTorso", false);

                }
                break;
        }

        RefreshInputHints();
    }
Esempio n. 19
0
 protected override void OnEquip(AttachmentSlot slot)
 {            
 }
Esempio n. 20
0
        protected void AddAttachmentSlot(GameObject attachPoint, PlayerInput input = null)
        {
            if (FindAttachmentSlot(attachPoint) != null)
            {
                Debug.LogError("GamePlayer: Trying to add an attachment point that is already assigned to an attachment slot!");
                return;
            }

            if (input != null && IsAttachmentSlotInputAssigned(input))
            {
                Debug.LogError("GamePlayer: Trying to add a a player input that is already assign to an attachment slot!");
                return;
            }

            var attachmentSlot = new AttachmentSlot();
            attachmentSlot.attachPoint = attachPoint;
            attachmentSlot.input = input;

            _attachmentSlots.Add(attachmentSlot);
        }
Esempio n. 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttachmentIdentifier"/> struct.
 /// </summary>
 /// <param name="name">The name of the attachment.</param>
 /// <param name="slot">The slot of the attachment.</param>
 public AttachmentIdentifier(AttachmentName name, AttachmentSlot slot)
 {
     Code = 0;
     Name = name;
     Slot = slot;
 }
Esempio n. 22
0
 protected override void OnEquip(AttachmentSlot slot)
 {
     _currentlyEquipped = slot.item;
 }
Esempio n. 23
0
 public void OnLimbRemoved(RobotComponent limb, AttachmentSlot slot, AttachmentType type)
 {
     if (LimbRemoved != null)
     {
         LimbRemoved(limb, slot, type);
     }
 }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttachmentIdentifier"/> struct.
 /// </summary>
 /// <param name="code">The code of the attachment.</param>
 /// <param name="name">The name of the attachment.</param>
 /// <param name="slot">The slot of the attachment.</param>
 internal AttachmentIdentifier(uint code, AttachmentName name, AttachmentSlot slot)
 {
     Code = code;
     Name = name;
     Slot = slot;
 }