コード例 #1
0
 public override void OnGUI(Rect rect)
 {
     GUILayout.BeginArea(rect);
     GUILayout.Box(weaponCategory.ToUpper() + " IK Adjust Selector", skin.GetStyle("WindowBG"), GUILayout.Width(rect.width), GUILayout.Height(30));
     scroll    = GUILayout.BeginScrollView(scroll, false, false, GUILayout.Width(rect.width));
     GUI.color = selected == null ? Color.green : Color.white;
     if (canSelectNull && GUILayout.Button("None", selectorStyle, GUILayout.Height(25), GUILayout.Width(rect.width)))
     {
         selected = null;
         editorWindow.Close();
     }
     for (int i = 0; i < weaponIKAdjusts.Count; i++)
     {
         GUI.color = selected == weaponIKAdjusts[i] ? Color.green : Color.white;
         if (GUILayout.Button(weaponIKAdjusts[i].name, selectorStyle, GUILayout.Height(25), GUILayout.Width(rect.width)))
         {
             selected = weaponIKAdjusts[i];
             EditorGUIUtility.PingObject(weaponIKAdjusts[i]);
             editorWindow.Close();
         }
     }
     GUI.color = Color.white;
     GUILayout.EndScrollView();
     GUILayout.EndArea();
 }
コード例 #2
0
        void DrawIKHandles(vWeaponIKAdjust currentWeaponIK)
        {
            if (leftIK == null || leftIK.iKSolver == null || !leftIK.iKSolver.isValidBones)
            {
                leftIK = new IKSolverEditorHelper(ikController.LeftIK);
            }
            if (rightIK == null || rightIK.iKSolver == null || !rightIK.iKSolver.isValidBones)
            {
                rightIK = new IKSolverEditorHelper(ikController.RightIK);
            }
            if (leftIK == null || rightIK == null)
            {
                return;
            }
            leftIK.DrawIKHandles(ref selected, ref referenceSelected, Color.blue);
            rightIK.DrawIKHandles(ref selected, ref referenceSelected, Color.green);

            if (selected != null)
            {
                if (DrawTransformHandles(selected, referenceSelected))
                {
                    Undo.RecordObject(currentWeaponIK, "Change IK Bone Transform");
                    ApplyOffsets((ikController.IsAiming ? (ikController.IsCrouching ? (ikController.CurrentWeaponIK.crouchingAiming) : ikController.CurrentWeaponIK.standingAiming) :
                                  (ikController.IsCrouching ? ikController.CurrentWeaponIK.crouching : ikController.CurrentWeaponIK.standing)),
                                 ikController.IsLeftWeapon ? ikController.LeftIK : ikController.RightIK,
                                 ikController.IsLeftWeapon ? ikController.RightIK : ikController.LeftIK);
                }
            }
        }
コード例 #3
0
 public virtual void LoadIKAdjust(string category)
 {
     if (weaponIKAdjustList)
     {
         currentWeaponIKAdjust = weaponIKAdjustList.GetWeaponIK(category);
     }
 }
コード例 #4
0
 public void ReplaceWeaponIKAdjust(vWeaponIKAdjust currentIK, vWeaponIKAdjust newIK)
 {
     if (weaponIKAdjusts != null && weaponIKAdjusts.Contains(currentIK))
     {
         int index = IndexOfIK(currentIK);
         weaponIKAdjusts[index] = newIK;
     }
 }
コード例 #5
0
 public int IndexOfIK(vWeaponIKAdjust currentIK)
 {
     if (weaponIKAdjusts != null && weaponIKAdjusts.Contains(currentIK))
     {
         int index = weaponIKAdjusts.IndexOf(currentIK);
         return(index);
     }
     else
     {
         return(-1);
     }
 }
コード例 #6
0
 public vIKAjustSelector(string weaponCategory, UnityEngine.Events.UnityAction <vWeaponIKAdjust> onSelect, GUISkin skin, vWeaponIKAdjust selected = null)
 {
     this.weaponCategory     = weaponCategory;
     this.onSelect           = onSelect;
     this.skin               = skin;
     selectorStyle           = new GUIStyle(skin.button);
     selectorStyle.border    = new RectOffset(1, 1, 1, 1);
     selectorStyle.margin    = new RectOffset(0, 0, 0, 0);
     selectorStyle.padding   = new RectOffset(0, 0, 0, 0);
     selectorStyle.overflow  = new RectOffset(0, 0, 0, 0);
     selectorStyle.alignment = TextAnchor.UpperCenter;
     selectorStyle.fontSize  = 12;
     selectorStyle.clipping  = TextClipping.Clip;
     selectorStyle.wordWrap  = true;
     if (selected != null)
     {
         this.selected = selected;
         canSelectNull = false;
     }
     else
     {
         canSelectNull = true;
     }
 }
コード例 #7
0
        void OnGUI()
        {
            GUILayout.BeginVertical(skin.GetStyle("WindowBG"));

            if (!Application.isPlaying)
            {
                DrawMessageInfo("Go to <color=green>PlayMode</color> to edit the IK Adjust List", "PlayModeIcon");
                ikController = null;
                return;
            }
            if (ikController == null)
            {
                DrawMessageInfo("Select a <color=green>Shooter Controller</color>", "ShooterControllerIcon");
                return;
            }

            if (!ikController.CurrentActiveWeapon)
            {
                DrawMessageInfo("Shooter Controller Doesn't have a <color=green>Active Weapon</color>", "WeaponIcon");
                return;
            }

            if (skin == null)
            {
                skin = Resources.Load("vSkin") as GUISkin;
            }

            scroll = EditorGUILayout.BeginScrollView(scroll);
            {
                {
                    if (ikController.WeaponIKAdjustList)
                    {
                        if (ikList == null || ikList.targetObject != ikController.WeaponIKAdjustList)
                        {
                            ikList = new SerializedObject(ikController.WeaponIKAdjustList);
                        }
                        if (ikList != null)
                        {
                            ikList.UpdateIfRequiredOrScript();
                        }

                        var weaponIKAdjustList = ikController.WeaponIKAdjustList;
                        EditorGUI.BeginChangeCheck();
                        weaponIKAdjustList = (vWeaponIKAdjustList)EditorGUILayout.ObjectField(weaponIKAdjustList, typeof(vWeaponIKAdjustList), false);

                        if (EditorGUI.EndChangeCheck())
                        {
                            ikController.WeaponIKAdjustList = weaponIKAdjustList;
                            ikController.SetIKAdjust(weaponIKAdjustList.GetWeaponIK(ikController.CurrentActiveWeapon.weaponCategory));
                            return;
                        }

                        EditorGUI.BeginChangeCheck();
                        string stateTag = ikController.IsCrouching ? "Crouching " : "Standing ";
                        if (ikController.IsAiming)
                        {
                            stateTag += "Aiming";
                        }
                        GUILayout.Box("State : " + stateTag + " / " + ikController.CurrentActiveWeapon.weaponCategory + " Category", skin.box, GUILayout.ExpandWidth(true));

                        if (GUILayout.Button(ikController.LockAiming ? "Unlock Aim" : "Lock Aim", EditorStyles.miniButton))
                        {
                            ikController.LockAiming = !ikController.LockAiming;
                        }

                        if (GUILayout.Button(ikController.IsCrouching ? "Unlock Crouch" : "Lock Crouch", EditorStyles.miniButton))
                        {
                            ikController.IsCrouching = !ikController.IsCrouching;
                        }

                        if (useLockCamera && GUILayout.Button(LockCamera ? "Unlock Camera" : "Lock Camera", EditorStyles.miniButton))
                        {
                            LockCamera = !LockCamera;
                        }

                        if (ikController.CurrentWeaponIK)
                        {
                            if (ik == null || ik.targetObject != ikController.CurrentWeaponIK)
                            {
                                ik = new SerializedObject(ikController.CurrentWeaponIK);
                            }
                            ik.Update();
                            try
                            {
                                GUILayout.Space(20);
                                DrawWeaponIKSettings(ikController.CurrentWeaponIK);
                                GUILayout.Space(20);
                                DrawLeftIKOffsets();
                                GUILayout.Space(20);
                            }
                            catch { }
                        }
                        else
                        {
                            EditorStyles.helpBox.richText = true;
                            EditorGUILayout.HelpBox("This weapon doesn't have a IKAdjust for the '" + ikController.CurrentActiveWeapon.weaponCategory + "' category,  click in the button below to create one.", MessageType.Info);
                            if (GUILayout.Button("Create New IK Adjust", skin.button))
                            {
                                vWeaponIKAdjust ikAdjust = ScriptableObject.CreateInstance <vWeaponIKAdjust>();
                                AssetDatabase.CreateAsset(ikAdjust, "Assets/" + ikController.gameObject.name + "@" + ikController.CurrentActiveWeapon.weaponCategory + ".asset");
                                ikAdjust.weaponCategories = new List <string>()
                                {
                                    ikController.CurrentActiveWeapon.weaponCategory
                                };

                                ikController.WeaponIKAdjustList.weaponIKAdjusts.Add(ikAdjust);
                                ikController.SetIKAdjust(ikAdjust);

                                SerializedObject scriptableIK = new SerializedObject(ikAdjust);
                                scriptableIK.ApplyModifiedProperties();
                                ikList.ApplyModifiedProperties();
                                EditorUtility.SetDirty(ikList.targetObject);
                                AssetDatabase.SaveAssets();
                                EditorUtility.SetDirty(scriptableIK.targetObject);
                            }
                            if (GUILayout.Button("Choose IK Adjust", skin.button))
                            {
                                var action = new UnityEngine.Events.UnityAction <vWeaponIKAdjust>((ikAdjust) =>
                                {
                                    ikController.WeaponIKAdjustList.weaponIKAdjusts.Add(ikAdjust);
                                    ikController.SetIKAdjust(ikAdjust);

                                    ikList.ApplyModifiedProperties();
                                    EditorUtility.SetDirty(ikList.targetObject);
                                });

                                PopupWindow.Show(selectorRect, new vIKAjustSelector(ikController.CurrentActiveWeapon.weaponCategory, action, skin));
                            }
                            if (Event.current.type == EventType.Repaint)
                            {
                                selectorRect = GUILayoutUtility.GetLastRect();
                            }
                            ikController.LoadIKAdjust(ikController.CurrentActiveWeapon.weaponCategory);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (ikList != null)
                            {
                                ikList.ApplyModifiedProperties();
                                EditorUtility.SetDirty(ikList.targetObject);
                            }
                        }
                    }
                    else
                    {
                        GUILayout.FlexibleSpace();
                        GUILayout.Label("You need to assign a <color=green>IK Adjust List</color> in the ShooterManager First!", skin.GetStyle("SuperTitle"));
                    }
                }
                GUILayout.Space(20);
            }

            EditorGUILayout.EndScrollView();
            GUILayout.FlexibleSpace(); GUILayout.EndVertical();
        }
コード例 #8
0
        void DrawWeaponIKSettings(vWeaponIKAdjust currentWeaponIK)
        {
            GUILayout.BeginHorizontal();

            GUILayout.Label(" ", skin.GetStyle("PopUpArrow"));

            if (GUILayout.Button(currentWeaponIK.name, skin.GetStyle("PopUp")))
            {
                var index  = ikController.WeaponIKAdjustList.IndexOfIK(currentWeaponIK);
                var action = new UnityEngine.Events.UnityAction <vWeaponIKAdjust>((ikAdjust) =>
                {
                    ikController.WeaponIKAdjustList.weaponIKAdjusts[index] = (ikAdjust);
                    ikController.SetIKAdjust(ikAdjust);

                    ikList.ApplyModifiedProperties();
                    EditorUtility.SetDirty(ikList.targetObject);
                });

                PopupWindow.Show(selectorRect, new vIKAjustSelector(ikController.CurrentActiveWeapon.weaponCategory, action, skin, currentWeaponIK));
            }

            if (Event.current.type == EventType.Repaint)
            {
                selectorRect = GUILayoutUtility.GetLastRect();
            }
            if (GUILayout.Button(new GUIContent("Create Copy", "Create and Apply a copy of this IK Adjust to the current Weapon category"), skin.button))
            {
                if (EditorUtility.DisplayDialog("Create Copy", "Create a copy of this IK Adjust? ", "Confirm"))
                {
                    string assetPath = AssetDatabase.GetAssetPath(currentWeaponIK);

                    var newAssetPath = assetPath.Replace(".asset", "_Copy.asset");
                    if (AssetDatabase.CopyAsset(assetPath, newAssetPath))
                    {
                        vWeaponIKAdjust newIK = (vWeaponIKAdjust)AssetDatabase.LoadAssetAtPath(newAssetPath, typeof(vWeaponIKAdjust));
                        ikController.WeaponIKAdjustList.ReplaceWeaponIKAdjust(currentWeaponIK, newIK);
                        ikController.SetIKAdjust(newIK);
                        ProjectWindowUtil.ShowCreatedAsset(newIK);

                        return;
                    }
                }
            }

            GUILayout.EndHorizontal();
            if (ikController.LeftIK == null || ikController.RightIK == null || !ikController.LeftIK.isValidBones || !ikController.RightIK.isValidBones)
            {
                return;
            }
            GUILayout.BeginHorizontal();

            GUI.enabled = selected != ikController.LeftIK.endBoneOffset;
            if (GUILayout.Button("Left Hand", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(true)))
            {
                referenceSelected = ikController.LeftIK.endBone;
                selected          = ikController.LeftIK.endBoneOffset;
            }
            GUI.enabled = selected != ikController.LeftIK.middleBoneOffset;
            if (GUILayout.Button("Left Hint", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(true)))
            {
                referenceSelected = ikController.LeftIK.middleBone;
                selected          = ikController.LeftIK.middleBoneOffset;
            }
            GUILayout.Space(20);
            GUI.enabled = selected != ikController.RightIK.endBoneOffset;
            if (GUILayout.Button("Right Hand", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(true)))
            {
                referenceSelected = ikController.RightIK.endBone;
                selected          = ikController.RightIK.endBoneOffset;
            }
            GUI.enabled = selected != ikController.RightIK.middleBoneOffset;
            if (GUILayout.Button("Right Hint", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(true)))
            {
                referenceSelected = ikController.RightIK.middleBone;
                selected          = ikController.RightIK.middleBoneOffset;
            }
            GUI.enabled = true;


            GUILayout.EndHorizontal();
            GUILayout.Space(10);

            if (selected != null)
            {
                GUILayout.Label(selected.name, EditorStyles.whiteBoldLabel);
                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Reset Position", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(true)))
                {
                    Undo.RecordObject(selected, "Reset Position");
                    selected.localPosition = Vector3.zero;
                    ApplyOffsets((ikController.IsAiming ? (ikController.IsCrouching ? (ikController.CurrentWeaponIK.crouchingAiming) : ikController.CurrentWeaponIK.standingAiming) :
                                  (ikController.IsCrouching ? ikController.CurrentWeaponIK.crouching : ikController.CurrentWeaponIK.standing)),
                                 ikController.IsLeftWeapon ? ikController.LeftIK : ikController.RightIK,
                                 ikController.IsLeftWeapon ? ikController.RightIK : ikController.LeftIK);
                }
                if (GUILayout.Button("Reset", EditorStyles.miniButtonMid, GUILayout.ExpandWidth(true)))
                {
                    Undo.RecordObject(selected, "Reset ALL");
                    selected.localPosition    = Vector3.zero;
                    selected.localEulerAngles = Vector3.zero;
                    ApplyOffsets((ikController.IsAiming ? (ikController.IsCrouching ? (ikController.CurrentWeaponIK.crouchingAiming) : ikController.CurrentWeaponIK.standingAiming) :
                                  (ikController.IsCrouching ? ikController.CurrentWeaponIK.crouching : ikController.CurrentWeaponIK.standing)),
                                 ikController.IsLeftWeapon ? ikController.LeftIK : ikController.RightIK,
                                 ikController.IsLeftWeapon ? ikController.RightIK : ikController.LeftIK);
                }
                if (GUILayout.Button("Reset Rotation", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(true)))
                {
                    Undo.RecordObject(selected, "Reset Rotation");
                    selected.localEulerAngles = Vector3.zero;
                    ApplyOffsets((ikController.IsAiming ? (ikController.IsCrouching ? (ikController.CurrentWeaponIK.crouchingAiming) : ikController.CurrentWeaponIK.standingAiming) :
                                  (ikController.IsCrouching ? ikController.CurrentWeaponIK.crouching : ikController.CurrentWeaponIK.standing)),
                                 ikController.IsLeftWeapon ? ikController.LeftIK : ikController.RightIK,
                                 ikController.IsLeftWeapon ? ikController.RightIK : ikController.LeftIK);
                }
                GUILayout.EndHorizontal();
            }
            if (ikController.IsAiming)
            {
                DrawHeadTrackSliders(ikController.IsCrouching ? currentWeaponIK.crouchingAiming.spineOffset : currentWeaponIK.standingAiming.spineOffset);
            }
            else
            {
                DrawHeadTrackSliders(ikController.IsCrouching ? currentWeaponIK.crouching.spineOffset : currentWeaponIK.standing.spineOffset);
            }
        }
コード例 #9
0
 public virtual void SetIKAdjust(vWeaponIKAdjust iKAdjust)
 {
     currentWeaponIKAdjust = iKAdjust;
 }