Beispiel #1
0
        protected virtual IEnumerator DropWeaponAnimation()
        {
            WeaponID        currentID        = cacheKeyToID[currentWeaponKey];
            Transform       curTransform     = cacheIDToTransform[currentID];
            DropProperties  dropProperties   = currentID.GetDropProperties();
            IWeaponAnimator currrentAnimator = null;

            if (curTransform != null)
            {
                currrentAnimator = curTransform.GetComponent <IWeaponAnimator>();
            }

            if (currrentAnimator != null)
            {
                currrentAnimator.PutAway();
                yield return(new WaitForSeconds(currrentAnimator.GetPutAwayTime()));
            }

            curTransform.gameObject.SetActive(false);
            Remove(currentID);

            if (dropProperties != DropProperties.Empty)
            {
                Vector3    pos        = _FPCamera.position + (_FPCamera.forward * dropProperties.GetDistance());
                GameObject dropObject = Instantiate(dropProperties.GetDropObject(), pos, Quaternion.Euler(dropProperties.GetRotation()));
                if (dropObject != null)
                {
                    Rigidbody rigidbody = dropObject.GetComponent <Rigidbody>();
                    if (rigidbody != null)
                    {
                        rigidbody.AddForce(_FPCamera.forward * dropProperties.GetForce(), ForceMode.Impulse);
                    }
                }
            }

            currentWeaponKey    = KeyCode.None;
            dropWeaponAnimation = null;
            yield break;
        }
Beispiel #2
0
        public override void BaseGUI()
        {
            BeginBox();
            if (instance.GetWeapon() == null)
            {
                instance.SetWeapon((WeaponID)EditorGUILayout.ObjectField("Weapon ID", instance.GetWeapon(), typeof(WeaponID), false));
                UEditorHelpBoxMessages.Error("Current weapon object not active in Unreal FPS system.", "For create Weapon ID asset press right mouse button on Project window and select Create > Unreal FPS > Weapon > Weapon ID.");
            }
            else
            {
                string weaponName = instance.GetWeapon() != null?instance.GetWeapon().name : "Weapon";

                GUILayout.BeginHorizontal();
                GUILayout.Space(3);
                GUILayout.Label(weaponName, GUILayout.Width(70));
                GUILayout.Space(EditorGUIUtility.labelWidth - 90);
                instance.SetWeapon((WeaponID)EditorGUILayout.ObjectField(instance.GetWeapon(), typeof(WeaponID), false));
                if (GUILayout.Button("", GUI.skin.GetStyle("OL Minus"), GUILayout.Width(20)))
                {
                    instance.SetWeapon(null);
                }
                GUILayout.Space(3);
                GUILayout.EndHorizontal();
                GUILayout.Space(10);

                GUILayout.Label(weaponName + " Properties", UEditorStyles.SectionHeaderLabel);
                GUILayout.Space(5);
                BeginSubBox();
                GUILayout.Space(3);
                IncreaseIndentLevel();
                string weaponDisplayFoldoutName = weaponDisplayFoldout ? "Hide " + weaponName + " Properties" : "Edit " + weaponName + " Properties";
                weaponDisplayFoldout = EditorGUILayout.Foldout(weaponDisplayFoldout, weaponDisplayFoldoutName, true);
                if (weaponDisplayFoldout && instance.GetWeapon() != null)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(17);
                    GUILayout.Label(ContentProperties.ID, GUILayout.Width(100));
                    instance.GetWeapon().SetID(EditorGUILayout.TextField(instance.GetWeapon().GetID()));
                    GUI.SetNextControlName("");
                    if (GenerateIDButton())
                    {
                        string id = System.Guid.NewGuid().ToString().ToUpper();
                        id = id.Replace("-", "");
                        instance.GetWeapon().SetID(id);
                        GUI.FocusControl("");
                    }
                    GUILayout.EndHorizontal();
                    instance.GetWeapon().SetDisplayName(EditorGUILayout.TextField(ContentProperties.DisplayName, instance.GetWeapon().GetDisplayName()));

                    GUILayout.BeginHorizontal();
                    GUILayout.Label(ContentProperties.Description, GUILayout.Width(100));
                    instance.GetWeapon().SetDescription(EditorGUILayout.TextArea(instance.GetWeapon().GetDescription()));
                    GUILayout.EndHorizontal();

                    if (inventory == null)
                    {
                        instance.GetWeapon().SetGroup(EditorGUILayout.TextField(ContentProperties.Group, instance.GetWeapon().GetGroup()));
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        instance.GetWeapon().SetGroup(EditorGUILayout.TextField(ContentProperties.Group, instance.GetWeapon().GetGroup()));
                        GUI.SetNextControlName(ContentProperties.Group.text);
                        if (ListButton())
                        {
                            InventoryGroup[] groups = inventory.GetGroups().ToArray();
                            if (groups != null && groups.Length > 0)
                            {
                                GenericMenu popup = new GenericMenu();
                                for (int i = 0; i < groups.Length; i++)
                                {
                                    popup.AddItem(new GUIContent(groups[i].GetName()), false, (x) => { instance.GetWeapon().SetGroup(x.ToString()); }, groups[i].GetName());
                                }
                                popup.ShowAsContext();
                            }
                            GUI.FocusControl(ContentProperties.Group.text);
                        }
                        GUILayout.EndHorizontal();
                    }
                    instance.GetWeapon().SetImage((Sprite)EditorGUILayout.ObjectField(ContentProperties.Image, instance.GetWeapon().GetImage(), typeof(Sprite), false));

                    IncreaseIndentLevel();
                    BeginSubBox();
                    dropPropertiesFoldout = EditorGUILayout.Foldout(dropPropertiesFoldout, ContentProperties.DropProperties, true);
                    if (dropPropertiesFoldout)
                    {
                        DropProperties dropProperties = instance.GetWeapon().GetDropProperties();
                        dropProperties.SetDropObject(ObjectField <GameObject>(ContentProperties.DropObject, dropProperties.GetDropObject(), false));
                        dropProperties.SetForce(EditorGUILayout.FloatField(ContentProperties.Force, dropProperties.GetForce()));
                        dropProperties.SetSoundEffect(ObjectField <AudioClip>(ContentProperties.SoundEffect, dropProperties.GetSoundEffect(), false));
                        dropProperties.SetDistance(EditorGUILayout.FloatField(ContentProperties.Distance, dropProperties.GetDistance()));
                        dropProperties.SetRotation(EditorGUILayout.Vector3Field(ContentProperties.Rotation, dropProperties.GetRotation()));
                        instance.GetWeapon().SetDropProperties(dropProperties);
                    }
                    EndSubBox();
                    DecreaseIndentLevel();
                }
                GUILayout.Space(3);
                EndSubBox();
                DecreaseIndentLevel();
            }
            EndBox();
        }
        public override void BaseGUI()
        {
            BeginBox();
            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.ID, GUILayout.Width(100));
            instance.SetID(EditorGUILayout.TextField(instance.GetID()));
            GUI.SetNextControlName("");
            if (GenerateIDButton())
            {
                string id = System.Guid.NewGuid().ToString().ToUpper();
                id = id.Replace("-", "");
                instance.SetID(id);
                GUI.FocusControl("");
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.DisplayName, GUILayout.Width(100));
            instance.SetDisplayName(EditorGUILayout.TextField(instance.GetDisplayName()));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.Description, GUILayout.Width(100));
            instance.SetDescription(EditorGUILayout.TextArea(instance.GetDescription()));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.Group, GUILayout.Width(100));
            instance.SetGroup(EditorGUILayout.TextField(instance.GetGroup()));
            if (inventory != null)
            {
                GUI.SetNextControlName(ContentProperties.Group.text);
                if (ListButton())
                {
                    InventoryGroup[] groups = inventory.GetGroups().ToArray();
                    if (groups != null && groups.Length > 0)
                    {
                        GenericMenu popup = new GenericMenu();
                        for (int i = 0; i < groups.Length; i++)
                        {
                            popup.AddItem(new GUIContent(groups[i].GetName()), false, (x) => { instance.SetGroup(x.ToString()); }, groups[i].GetName());
                        }
                        popup.ShowAsContext();
                    }
                    GUI.FocusControl(ContentProperties.Group.text);
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.Image, GUILayout.Width(100));
            instance.SetImage((Sprite)EditorGUILayout.ObjectField(instance.GetImage(), typeof(Sprite), false));
            GUILayout.EndHorizontal();

            GUILayout.Space(3);

            IncreaseIndentLevel();
            BeginSubBox();
            dropPropertiesFoldout = EditorGUILayout.Foldout(dropPropertiesFoldout, ContentProperties.DropProperties, true);
            if (dropPropertiesFoldout)
            {
                DropProperties dropProperties = instance.GetDropProperties();
                dropProperties.SetDropObject(ObjectField <GameObject>(ContentProperties.DropObject, dropProperties.GetDropObject(), false));
                dropProperties.SetForce(EditorGUILayout.FloatField(ContentProperties.Force, dropProperties.GetForce()));
                dropProperties.SetSoundEffect(ObjectField <AudioClip>(ContentProperties.SoundEffect, dropProperties.GetSoundEffect(), false));
                dropProperties.SetDistance(EditorGUILayout.FloatField(ContentProperties.Distance, dropProperties.GetDistance()));
                dropProperties.SetRotation(EditorGUILayout.Vector3Field(ContentProperties.Rotation, dropProperties.GetRotation()));
                instance.SetDropProperties(dropProperties);
            }
            EndSubBox();
            DecreaseIndentLevel();
            EndBox();
        }
Beispiel #4
0
 public void SetDropProperties(DropProperties value)
 {
     dropProperties = value;
 }
Beispiel #5
0
        protected virtual IEnumerator ReplaceWeaponAnimation(WeaponID targetWeaponID)
        {
            if (currentWeaponKey != KeyCode.None)
            {
                WeaponID        currentID        = cacheKeyToID[currentWeaponKey];
                Transform       currentTransform = cacheIDToTransform[currentID];
                DropProperties  dropProperties   = currentID.GetDropProperties();
                IWeaponAnimator currrentAnimator = null;
                if (currentTransform != null)
                {
                    currrentAnimator = currentTransform.GetComponent <IWeaponAnimator>();
                }
                else
                {
                    switchWeaponAnimation = null;
                    yield break;
                }

                if (currrentAnimator != null)
                {
                    currrentAnimator.PutAway();
                    yield return(new WaitForSeconds(currrentAnimator.GetPutAwayTime()));
                }

                if (dropProperties != DropProperties.Empty)
                {
                    Vector3    pos        = _FPCamera.position + (_FPCamera.forward * dropProperties.GetDistance());
                    GameObject dropObject = Instantiate(dropProperties.GetDropObject(), pos, Quaternion.Euler(dropProperties.GetRotation()));
                    if (dropObject != null)
                    {
                        Rigidbody rigidbody = dropObject.GetComponent <Rigidbody>();
                        if (rigidbody != null)
                        {
                            rigidbody.AddForce(_FPCamera.forward * dropProperties.GetForce(), ForceMode.Impulse);
                        }
                    }
                }

                currentTransform.gameObject.SetActive(false);
                currentWeaponKey = KeyCode.None;
            }

            Transform       targetTransform = cacheIDToTransform[targetWeaponID];
            IWeaponAnimator targetAnimator  = null;

            if (targetTransform != null)
            {
                targetAnimator = targetTransform.GetComponent <IWeaponAnimator>();
            }
            else
            {
                switchWeaponAnimation = null;
                yield break;
            }

            targetTransform.gameObject.SetActive(true);

            if (targetAnimator != null)
            {
                yield return(new WaitForSeconds(targetAnimator.GetTakeTime()));
            }

            List <InventorySlot> slots = cacheGroupToSlots[targetWeaponID.GetGroup()];

            for (int i = 0, length = slots.Count; i < length; i++)
            {
                InventorySlot slot = slots[i];
                if (slot.GetWeapon() == targetWeaponID)
                {
                    currentWeaponKey = slot.GetKey();
                    break;
                }
            }
            switchWeaponAnimation = null;
            yield break;
        }
Beispiel #6
0
        private static void NewWeaponGUI()
        {
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(5);
            GUILayout.Label(ContentProperties.BaseOptions, UEditorStyles.SectionHeaderLabel);
            GUILayout.Space(7);
            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.ID, GUILayout.Width(100));
            weaponID.SetID(EditorGUILayout.TextField(weaponID.GetID()));
            GUI.SetNextControlName("");
            if (UEditor.GenerateIDButton())
            {
                string id = System.Guid.NewGuid().ToString().ToUpper();
                id = id.Replace("-", "");
                weaponID.SetID(id);
                GUI.FocusControl("");
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.DisplayName, GUILayout.Width(100));
            weaponID.SetDisplayName(EditorGUILayout.TextField(weaponID.GetDisplayName()));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.Description, GUILayout.Width(100));
            weaponID.SetDescription(EditorGUILayout.TextArea(weaponID.GetDescription()));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.Group, GUILayout.Width(100));
            weaponID.SetGroup(EditorGUILayout.TextField(weaponID.GetGroup()));
            if (inventory != null)
            {
                GUI.SetNextControlName(ContentProperties.Group.text);
                if (UEditor.ListButton())
                {
                    InventoryGroup[] groups = inventory.GetGroups().ToArray();
                    if (groups != null && groups.Length > 0)
                    {
                        GenericMenu popup = new GenericMenu();
                        for (int i = 0; i < groups.Length; i++)
                        {
                            popup.AddItem(new GUIContent(groups[i].GetName()), false, (x) => { weaponID.SetGroup(x.ToString()); }, groups[i].GetName());
                        }
                        popup.ShowAsContext();
                    }
                    GUI.FocusControl(ContentProperties.Group.text);
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.Image, GUILayout.Width(100));
            weaponID.SetImage((Sprite)EditorGUILayout.ObjectField(weaponID.GetImage(), typeof(Sprite), false));
            GUILayout.EndHorizontal();

            GUILayout.Space(10);
            GUILayout.Label(ContentProperties.DropProperties, UEditorStyles.SectionHeaderLabel);
            GUILayout.Space(7);
            DropProperties dropProperties = weaponID.GetDropProperties();

            dropProperties.SetDropObject(UEditor.ObjectField <GameObject>(ContentProperties.DropObject, dropProperties.GetDropObject(), false));
            dropProperties.SetForce(EditorGUILayout.FloatField(ContentProperties.Force, dropProperties.GetForce()));
            dropProperties.SetSoundEffect(UEditor.ObjectField <AudioClip>(ContentProperties.SoundEffect, dropProperties.GetSoundEffect(), false));
            dropProperties.SetDistance(EditorGUILayout.FloatField(ContentProperties.Distance, dropProperties.GetDistance()));
            GUILayout.BeginHorizontal();
            GUILayout.Label(ContentProperties.Rotation, GUILayout.Width(145));
            dropProperties.SetRotation(EditorGUILayout.Vector3Field(GUIContent.none, dropProperties.GetRotation()));
            GUILayout.EndHorizontal();

            weaponID.SetDropProperties(dropProperties);

            GUILayout.Space(5);
            UEditor.HorizontalLine();
            GUILayout.Space(5);

            if (UEditor.Button("Create", "Right", GUILayout.Width(70)))
            {
                string path = EditorUtility.SaveFilePanelInProject("Create new Property", weaponID.GetDisplayName(), "", "");
                if (!string.IsNullOrEmpty(path))
                {
                    string name = System.IO.Path.GetFileName(path);
                    path = path.Replace(name, "");
                    ScriptableObjectUtility.CreateAsset(weaponID, path, name);
                    OnEnable();
                }
            }
            GUILayout.Space(5);
            GUILayout.EndVertical();
        }