示例#1
0
        public static void OnEnable()
        {
            weaponID = ScriptableObject.CreateInstance <WeaponID>();
            if (weaponID != null)
            {
                weaponID.SetID(WeaponID.GenerateID());
                weaponID.SetDisplayName("Write weapon name here...");
            }
            Transform player = UEditorInternal.FindPlayer();

            if (player != null)
            {
                inventory = UEditorInternal.FindComponent <AdvancedInventory>(player);
            }

            weaponIDs    = UEditorInternal.FindAssetsByType <WeaponID>();
            toolbarItems = new string[2] {
                "New", "List"
            };
        }
示例#2
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();
        }