// Clear the slot public void ClearSlot() { item = null; icon.sprite = null; icon.enabled = false; }
FixItem item; // Current item in the slot // Add item to the slot public void AddItem(FixItem newItem) { item = newItem; icon.sprite = item.icon; icon.enabled = true; }
void Update() { if (theItem == null) { theItem = FindObjectOfType <FixItem>(); } }
private void FixAxis(FixItem fix) { //Quaternion.AngleAxis:軸を決めて回転させる //Quaternion * Vector3: 指定方向に回転させたVector3が返ってくる Quaternion targetRotation = fix.Target.rotation; Quaternion twistOffset = Quaternion.AngleAxis(0, targetRotation * fix.TwistAxis); targetRotation = twistOffset * targetRotation; // 親(肩)と子(手首)のワールド座標の緩和軸を求める Vector3 relaxedAxisParent = twistOffset * fix.Parent.rotation * fix.AxisRelativeToParentDefault; Vector3 relaxedAxisChild = twistOffset * fix.Child.rotation * fix.AxisRelativeToChildDefault; // 親(肩)と子(手首)の中間の回転角度を計算する Vector3 relaxedAxis = Vector3.Slerp(relaxedAxisParent, relaxedAxisChild, fix.GetFixWeight()); // relaxedAxisを(axis、twistAxis)空間で変換して、ねじれ角を計算できます Quaternion r = Quaternion.LookRotation(targetRotation * fix.Axis, targetRotation * fix.TwistAxis); relaxedAxis = Quaternion.Inverse(r) * relaxedAxis; // ねじれ軸を中心にこのTransformを回転させるために必要な角度を計算します float angle = Mathf.Atan2(relaxedAxis.x, relaxedAxis.z) * Mathf.Rad2Deg; //Debug.Log($"Angle{angle}"); // 子(手首)の回転を取っておいて、対象(ひじ)を回転させた後戻せるようにしておく Quaternion childRotation = fix.Child.rotation; // 対象(ひじ)を回転させる fix.Target.rotation = Quaternion.AngleAxis(angle, targetRotation * fix.TwistAxis) * targetRotation; // 対象(ひじ)で動いてしまった子(手首)の回転を元に戻す fix.Child.rotation = childRotation; }
// Remove an item public void Remove(FixItem item) { items.Remove(item); if (onItemChangedCallback != null) { onItemChangedCallback.Invoke(); } }
public float UpperArmFixWeight = 0.2f; //0.5では強すぎて肩がねじれる場合がある public void SetVRIK(VRIK setIK) { if (ik != null) { ik.GetIKSolver().OnPostUpdate -= OnPostUpdate; } ik = setIK; LeftElbowFixItem = new FixItem(ik.references.leftUpperArm, ik.references.leftForearm, ik.references.leftHand, () => ElbowFixWeight); LeftUpperArmFixItem = new FixItem(ik.references.leftShoulder, ik.references.leftUpperArm, ik.references.leftForearm, () => UpperArmFixWeight); RightElbowFixItem = new FixItem(ik.references.rightUpperArm, ik.references.rightForearm, ik.references.rightHand, () => ElbowFixWeight); RightUpperArmFixItem = new FixItem(ik.references.rightShoulder, ik.references.rightUpperArm, ik.references.rightForearm, () => UpperArmFixWeight); if (ik != null) { ik.GetIKSolver().OnPostUpdate += OnPostUpdate; } }
// Add a new item if enough room public bool Add(FixItem item) { if (item.showInInventory) { if (items.Count >= space) { Debug.Log("Not enough room."); return(false); } items.Add(item); if (onItemChangedCallback != null) { onItemChangedCallback.Invoke(); } } return(true); }
private void AddFixActionItemToListView(FixItem fi) { var item = new ListViewItem(string.Empty); item.Tag = fi; item.Checked = fi.DefaultChecked; var subItem = new ListViewItem.ListViewSubItem(item, fi.Name); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, fi.Example); item.SubItems.Add(subItem); listView1.Items.Add(item); }
private void AddFixActionItemToListView(FixItem fi) { var item = new ListViewItem(string.Empty) { Tag = fi, Checked = fi.DefaultChecked }; item.SubItems.Add(fi.Name); item.SubItems.Add(fi.Example); listView1.Items.Add(item); }