Esempio n. 1
0
        /// <summary>
        /// Builds a new Third Person Controller Item.
        /// </summary>
        public static void BuildItem(GameObject item, ItemType itemType, string itemName, ItemTypes baseObjectType, HandAssignment handAssignment)
        {
            m_Base           = item;
            m_ItemType       = itemType;
            m_ItemName       = itemName;
            m_Type           = baseObjectType;
            m_HandAssignment = handAssignment;

            BuildItem();
        }
Esempio n. 2
0
        /// <summary>
        /// Draws the custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            var item = target as Item;

            if (item == null || serializedObject == null)
            {
                return; // How'd this happen?
            }
            base.OnInspectorGUI();

            // Show all of the fields.
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();

            // Allow the user to assign the item if it isn't already assigned
            if (item.transform.parent == null)
            {
                m_AssignTo = EditorGUILayout.ObjectField("Assign To", m_AssignTo, typeof(GameObject), true) as GameObject;
                var enableGUI = m_AssignTo != null && m_AssignTo.GetComponent <Animator>() != null;
                if (enableGUI)
                {
                    if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(m_AssignTo)))
                    {
                        EditorGUILayout.HelpBox("The character must be located within the scene.", MessageType.Error);
                        enableGUI = false;
                    }
                    else
                    {
                        if (m_AssignTo.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand) == null)
                        {
                            // The ItemPlacement component must be specified for generic models.
                            m_ItemPlacement = EditorGUILayout.ObjectField("Item Placement", m_ItemPlacement, typeof(ItemPlacement), true) as ItemPlacement;
                            if (m_ItemPlacement == null)
                            {
                                EditorGUILayout.HelpBox("The ItemPlacement GameObject must be specified for Generic models.", MessageType.Error);
                                enableGUI = false;
                            }
                        }
                        else
                        {
                            m_HandAssignment = (HandAssignment)EditorGUILayout.EnumPopup("Hand", m_HandAssignment);
                        }
                    }
                }

                GUI.enabled = enableGUI;
                if (GUILayout.Button("Assign"))
                {
                    Transform itemPlacement = null;
                    if (m_AssignTo.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand) == null)
                    {
                        itemPlacement = m_ItemPlacement.transform;
                    }
                    else
                    {
                        var handTransform = m_AssignTo.GetComponent <Animator>().GetBoneTransform(m_HandAssignment == HandAssignment.Left ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);
                        itemPlacement = handTransform.GetComponentInChildren <ItemPlacement>().transform;
                    }
                    AssignItem(item.gameObject, itemPlacement);
                }
                GUI.enabled = true;
            }

            var itemTypeProperty = PropertyFromName(serializedObject, "m_ItemType");

            EditorGUILayout.PropertyField(itemTypeProperty);
            if (itemTypeProperty.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("This field is required. The Inventory uses the Item Type to determine the type of item.", MessageType.Error);
            }

            var itemName = PropertyFromName(serializedObject, "m_ItemName");

            EditorGUILayout.PropertyField(itemName);
            if (string.IsNullOrEmpty(itemName.stringValue))
            {
                EditorGUILayout.HelpBox("The Item Name specifies the name of the Animator substate machine. It should not be empty unless you only have one item type.", MessageType.Warning);
            }

            if ((m_CharacterAnimatorFoldout = EditorGUILayout.Foldout(m_CharacterAnimatorFoldout, "Character Animator Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                var canAim = PropertyFromName(serializedObject, "m_CanAim");
                EditorGUILayout.PropertyField(canAim);
                if (canAim.boolValue)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RequireAim"));
                }
                DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_DefaultStates"));
                if (canAim.boolValue)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_AimStates"));
                }
                if (target is IUseableItem)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_UseStates"));
                }
                if (target is IReloadableItem)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_ReloadStates"));
                }
                if (target is MeleeWeapon || target is Shield)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_RecoilStates"));
                }
                DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_EquipStates"));
                DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_UnequipStates"));
                EditorGUI.indentLevel--;
            }

            if ((m_UIFoldout = EditorGUILayout.Foldout(m_UIFoldout, "UI Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemSprite"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RightItemSprite"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CrosshairsSprite"), true);
                EditorGUI.indentLevel--;
            }

            if ((m_InputFoldout = EditorGUILayout.Foldout(m_InputFoldout, "Input Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                if (item is IUseableItem)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_UseInputName"));
                    if (serializedObject.FindProperty("m_DualWieldUseInputName") != null)
                    {
                        EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DualWieldUseInputName"));
                    }
                }
                if (item is IReloadableItem)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ReloadInputName"));
                }
                if (item is IFlashlightUseable)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ToggleFlashlightInputName"));
                }
                if (item is ILaserSightUseable)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ToggleLaserSightInputName"));
                }
                EditorGUI.indentLevel--;
            }

            if ((m_GeneralFoldout = EditorGUILayout.Foldout(m_GeneralFoldout, "General Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TwoHandedItem"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_NonDominantHandPosition"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HolsterTarget"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemPickup"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AimCameraState"));
                EditorGUI.indentLevel--;
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(item, "Inspector");
                serializedObject.ApplyModifiedProperties();
                InspectorUtility.SetObjectDirty(item);
            }
        }