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; }
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); } }
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); }
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); }
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); }
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; }
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); }
protected override void OnEquip(AttachmentSlot slot) { throw new NotImplementedException(); }
//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) { }
protected int GetSlotIndex(AttachmentSlot slot) { return(_attachmentSlots.IndexOf(slot)); }
protected int GetSlotIndex(AttachmentSlot slot) { return _attachmentSlots.IndexOf(slot); }
protected override void OnEquip(AttachmentSlot slot) { _currentlyEquipped = slot.item; }
public AttachmentPoint GetJointForSlot(AttachmentSlot slot) { return allJoints.FirstOrDefault(j => j.slot == slot); }
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(); }
protected override void OnEquip(AttachmentSlot slot) { }
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(); }
/// <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; }
public void OnLimbRemoved(RobotComponent limb, AttachmentSlot slot, AttachmentType type) { if (LimbRemoved != null) { LimbRemoved(limb, slot, type); } }
/// <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; }