private List <RightClickMenuItem> Generate(List <GameObject> objects)
    {
        if (objects == null || objects.Count == 0)
        {
            return(null);
        }
        var result = new List <RightClickMenuItem>();

        foreach (var curObject in objects)
        {
            var subMenus = new List <RightClickMenuItem>();

            //check for any IRightClickable components and gather their options
            var rightClickables      = curObject.GetComponents <IRightClickable>();
            var rightClickableResult = new RightClickableResult();
            if (rightClickables != null)
            {
                foreach (var rightClickable in rightClickables)
                {
                    rightClickableResult.AddElements(rightClickable.GenerateRightClickOptions());
                }
            }
            //add the menu items generated so far
            subMenus.AddRange(rightClickableResult.AsOrderedMenus(rightClickOptionOrder));

            //check for any components that have an attributed method. These are added to the end in whatever order,
            //doesn't matter since it's only for development.
            if (KeyboardInputManager.Instance.CheckKeyAction(KeyAction.ShowAdminOptions, KeyboardInputManager.KeyEventType.Hold))
            {
                foreach (var attributedType in attributedTypes)
                {
                    var components = curObject.GetComponents(attributedType.ComponentType);
                    foreach (var component in components)
                    {
                        //only add the item if the concrete type matches
                        if (component.GetType() == attributedType.ComponentType)
                        {
                            //create menu items for these components
                            subMenus.AddRange(CreateSubMenuOptions(attributedType, component));
                        }
                    }
                }

                if (!string.IsNullOrEmpty(PlayerList.Instance.AdminToken))
                {
                    subMenus.Add(VariableViewerOption.AsMenu(() =>
                    {
                        RequestBookshelfNetMessage.Send(curObject);
                    }));
                }
            }

            if (subMenus.Count > 0)
            {
                result.Add(CreateObjectMenu(curObject, subMenus));
            }
        }

        return(result);
    }
Exemple #2
0
    private List <RightClickMenuItem> Generate(List <GameObject> objects)
    {
        if (objects == null || objects.Count == 0)
        {
            return(null);
        }
        var result = new List <RightClickMenuItem>();

        foreach (var curObject in objects)
        {
            var subMenus = new List <RightClickMenuItem>();

            //check for any IRightClickable components and gather their options
            var rightClickables      = curObject.GetComponents <IRightClickable>();
            var rightClickableResult = new RightClickableResult();
            if (rightClickables != null)
            {
                foreach (var rightClickable in rightClickables)
                {
                    rightClickableResult.AddElements(rightClickable.GenerateRightClickOptions());
                }
            }
            //add the menu items generated so far
            subMenus.AddRange(rightClickableResult.AsOrderedMenus(rightClickOptionOrder));

            //check for any components that have an attributed method. These are added to the end in whatever order,
            //doesn't matter since it's only for development.
            foreach (var attributedType in attributedTypes)
            {
                var components = curObject.GetComponents(attributedType.ComponentType);
                foreach (var component in components)
                {
                    //only add the item if the concrete type matches
                    if (component.GetType() == attributedType.ComponentType)
                    {
                        //create menu items for these components
                        subMenus.AddRange(CreateSubMenuOptions(attributedType, component));
                    }
                }
            }

            if (subMenus.Count > 0)
            {
                result.Add(CreateObjectMenu(curObject, subMenus));
            }
        }

        return(result);
    }