浏览代码

Added the possibility to make readonly items persistent so they are always displayed.

/Branch_Batching2
Julien Ignace 8 年前
当前提交
adca1f00
共有 6 个文件被更改,包括 182 次插入53 次删除
  1. 9
      Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs
  2. 68
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
  3. 41
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs
  4. 96
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs
  5. 5
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs
  6. 16
      ProjectSettings/InputManager.asset

9
Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs


private static string kDebugPreviousBtn = "Debug Previous";
private static string kDebugNextBtn = "Debug Next";
private static string kValidateBtn = "Debug Validate";
private static string kPersistentBtn = "Debug Persistent";
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2, kDebugPreviousBtn, kDebugNextBtn, kValidateBtn, kDPadVertical, kDPadHorizontal };
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2, kDebugPreviousBtn, kDebugNextBtn, kValidateBtn, kPersistentBtn, kDPadVertical, kDPadHorizontal };
public enum DebugAction

NextDebugMenu,
Validate,
Persistent,
MoveVertical,
MoveHorizontal,
DebugActionCount

validate.repeatMode = DebugActionRepeatMode.Delay;
validate.repeatDelay = 0.25f;
AddAction(DebugAction.Validate, validate);
DebugActionDesc persistent = new DebugActionDesc();
persistent.buttonTriggerList.Add(new[] { kPersistentBtn });
persistent.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.Persistent, persistent);
AddAction(DebugAction.MoveVertical, new DebugActionDesc { axisTrigger = kDPadVertical, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f } );
AddAction(DebugAction.MoveHorizontal, new DebugActionDesc { axisTrigger = kDPadHorizontal, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f } );

68
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs


private List<DebugMenuItem> m_Items = new List<DebugMenuItem>();
private List<DebugMenuItemUI> m_ItemsUI = new List<DebugMenuItemUI>();
private int m_SelectedItem = -1;
private bool m_AllItemsReadOnly = true;
public DebugMenu(string name)
{

if (index >= m_Items.Count || index < 0)
return null;
return m_Items[index];
}
public DebugMenuItem GetSelectedDebugMenuItem()
{
if(m_SelectedItem != -1)
{
return m_Items[m_SelectedItem];
}
return null;
}
public bool HasItem(DebugMenuItem debugItem)
{
foreach(var item in m_Items)
{
if (debugItem == item)
return true;
}
return false;
}
public void RemoveDebugItem(DebugMenuItem debugItem)
{
m_Items.Remove(debugItem);
RebuildGUI();
}
public void AddDebugItem(DebugMenuItem debugItem)
{
m_Items.Add(debugItem);
RebuildGUI();
}
// TODO: Move this to UI classes

menuVLRectTransform.anchorMax = new Vector2(1.0f, 1.0f);
DebugMenuUI.CreateTextElement(string.Format("{0} Title", m_Name), m_Name, 14, TextAnchor.MiddleLeft, m_Root);
RebuildGUI();
m_Root.SetActive(false);
return m_Root;
}
private void RebuildGUI()
{
m_Root.transform.DetachChildren();
foreach(DebugMenuItem menuItem in m_Items)
foreach (DebugMenuItem menuItem in m_Items)
m_Root.SetActive(false);
return m_Root;
if (m_AllItemsReadOnly)
return;
if(m_SelectedItem != -1)
{
m_ItemsUI[m_SelectedItem].SetSelected(false);

void NextItem()
{
if(m_Items.Count != 0 && !m_AllItemsReadOnly)
if(m_Items.Count != 0)
int newSelected = NextItemIndex(m_SelectedItem);
while(m_Items[newSelected].readOnly) // There should always be at least one item that is not readonly because m_AllItemsReadOnly is false.
newSelected = NextItemIndex(newSelected);
int newSelected = (m_SelectedItem + 1) % m_Items.Count;
SetSelectedItem(newSelected);
}
}

void PreviousItem()
{
if(m_Items.Count != 0 && !m_AllItemsReadOnly)
if(m_Items.Count != 0)
int newSelected = PreviousItemIndex(m_SelectedItem);
while (m_Items[newSelected].readOnly) // There should always be at least one item that is not readonly because m_AllItemsReadOnly is false.
newSelected = PreviousItemIndex(newSelected);
int newSelected = m_SelectedItem - 1;
if (newSelected == -1)
newSelected = m_Items.Count - 1;
SetSelectedItem(newSelected);
}
}

DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, dynamicDisplay, drawer);
drawer.SetDebugItem(newItem);
m_Items.Add(newItem);
m_AllItemsReadOnly = m_AllItemsReadOnly && newItem.readOnly;
}
public void Update()

41
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs


DebugMenuManager()
{
LookUpDebugMenuClasses();
m_PersistentDebugMenu = new DebugMenu("Persistent");
m_DebugMenuUI = new DebugMenuUI(this);
}

DebugMenu m_PersistentDebugMenu = null;
DebugMenuUI m_DebugMenuUI = null;
public bool isEnabled { get { return m_Enabled; } }

return m_DebugMenus[index];
else
return null;
}
public DebugMenu GetPersistentDebugMenu()
{
return m_PersistentDebugMenu;
}
void LookUpDebugMenuClasses()

public void ToggleMenu()
{
m_Enabled = !m_Enabled;
m_DebugMenuUI.BuildGUI();
if(m_Enabled)
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
m_DebugMenus[m_ActiveMenuIndex].SetSelected(m_Enabled);
}
public void OnValidate()

public void OnMakePersistent()
{
DebugMenuItem selectedItem = m_DebugMenus[m_ActiveMenuIndex].GetSelectedDebugMenuItem();
if(selectedItem != null && selectedItem.readOnly)
{
if(m_PersistentDebugMenu.HasItem(selectedItem))
{
m_PersistentDebugMenu.RemoveDebugItem(selectedItem);
}
else
{
m_PersistentDebugMenu.AddDebugItem(selectedItem);
}
}
if(m_PersistentDebugMenu.itemCount == 0)
{
m_PersistentDebugMenu.SetSelected(false);
m_DebugMenuUI.EnablePersistentView(false); // Temp, should just need the above. Wait for background UI to be moved to menu itself
}
else
{
m_PersistentDebugMenu.SetSelected(true);
m_DebugMenuUI.EnablePersistentView(true);
}
}
public void OnMoveHorizontal(float value)
{
m_DebugMenus[m_ActiveMenuIndex].OnMoveHorizontal(value);

{
if (m_ActiveMenuIndex != -1)
m_DebugMenus[m_ActiveMenuIndex].Update();
m_PersistentDebugMenu.Update();
}
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemDrawer drawer = null) where DebugMenuType : DebugMenu

96
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs


GameObject m_Root = null;
GameObject[] m_MenuRoots = null;
GameObject m_MainMenuRoot = null;
GameObject m_PersistentMenuRoot = null;
bool m_Enabled = false;
DebugMenuManager m_DebugMenuManager = null;

public void Toggle()
{
m_Enabled = !m_Enabled;
if(!m_Enabled)
{
CleanUpGUI();
}
else
{
BuildGUI();
}
m_MainMenuRoot.SetActive(m_Enabled);
}
public void EnablePersistentView(bool value)
{
m_PersistentMenuRoot.SetActive(value);
}
void CleanUpGUI()

void BuildGUI()
public void BuildGUI()
if (m_Root != null)
return;
float kBorderSize = 5.0f;
m_Root = new GameObject("DebugMenu Root");
Canvas canvas = m_Root.AddComponent<Canvas>();

canvasScaler.referenceResolution = new Vector2(800.0f, 600.0f);
RectTransform canvasRT = canvas.GetComponent<RectTransform>();
//canvasRT.localScale = Vector3.one;
float width = canvasRT.rect.width;
float height = canvasRT.rect.height;
GameObject go = new GameObject("Background");
go.AddComponent<CanvasRenderer>();
var image = go.AddComponent<UI.Image>();
go.transform.SetParent(m_Root.transform, false);
// TODO: Move background an layout to the menu itself.
m_MainMenuRoot = new GameObject("Background");
m_MainMenuRoot.AddComponent<CanvasRenderer>();
var image = m_MainMenuRoot.AddComponent<UI.Image>();
m_MainMenuRoot.transform.SetParent(m_Root.transform, false);
image.rectTransform.anchorMax = new Vector2(1.0f, 1.0f);
image.rectTransform.anchorMax = new Vector2(0.5f, 1.0f);
GameObject goVL = new GameObject("DebugMenu VLayout");
goVL.transform.SetParent(go.transform, false);
UI.VerticalLayoutGroup menuVL = goVL.AddComponent<UI.VerticalLayoutGroup>();
GameObject goVL = DebugMenuUI.CreateVerticalLayoutGroup("DebugMenu VLayout", true, true, true, false, 5.0f, m_MainMenuRoot);
RectTransform menuVLRectTransform = goVL.GetComponent<RectTransform>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = Vector3.zero;

menuVLRectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
menuVLRectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
menuVL.spacing = 5.0f;
menuVL.childControlWidth = true;
menuVL.childControlHeight = true;
menuVL.childForceExpandWidth = true;
menuVL.childForceExpandHeight = false;
// TODO: Move background an layout to the menu itself.
m_PersistentMenuRoot = new GameObject("Background_Persistent");
m_PersistentMenuRoot.AddComponent<CanvasRenderer>();
image = m_PersistentMenuRoot.AddComponent<UI.Image>();
m_PersistentMenuRoot.transform.SetParent(m_Root.transform, false);
image.rectTransform.pivot = new Vector2(0.0f, 0.0f);
image.rectTransform.localPosition = Vector3.zero;
image.rectTransform.localScale = Vector3.one;
image.rectTransform.anchorMin = new Vector2(0.7f, 0.8f);
image.rectTransform.anchorMax = new Vector2(1.0f, 1.0f);
image.rectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
image.rectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
image.color = kBackgroundColor;
GameObject goVL2 = DebugMenuUI.CreateVerticalLayoutGroup("DebugMenu VLayout", true, true, true, false, 5.0f, m_PersistentMenuRoot);
menuVLRectTransform = goVL2.GetComponent<RectTransform>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = Vector3.zero;
menuVLRectTransform.localScale = Vector3.one;
menuVLRectTransform.anchorMin = new Vector2(0.0f, 0.0f);
menuVLRectTransform.anchorMax = new Vector2(1.0f, 1.0f);
menuVLRectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
menuVLRectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
m_PersistentMenuRoot.SetActive(false);
DebugMenuUI.CreateTextElement("DebugMenuTitle", "Debug Menu", 14, TextAnchor.MiddleCenter, goVL);

{
m_MenuRoots[i] = m_DebugMenuManager.GetDebugMenu(i).BuildGUI(goVL);
}
m_DebugMenuManager.GetPersistentDebugMenu().BuildGUI(goVL2);
return CreateVerticalLayoutGroup(name, controlWidth, controlHeight, forceExpandWidth, forceExpandHeight, 0.0f, parent);
}
public static GameObject CreateVerticalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, float spacing, GameObject parent = null )
{
UI.VerticalLayoutGroup horizontalLayout = go.AddComponent<UI.VerticalLayoutGroup>();
horizontalLayout.childControlHeight = controlHeight;
horizontalLayout.childControlWidth = controlWidth;
horizontalLayout.childForceExpandHeight = forceExpandHeight;
horizontalLayout.childForceExpandWidth = forceExpandWidth;
UI.VerticalLayoutGroup verticalLayout = go.AddComponent<UI.VerticalLayoutGroup>();
verticalLayout.childControlHeight = controlHeight;
verticalLayout.childControlWidth = controlWidth;
verticalLayout.childForceExpandHeight = forceExpandHeight;
verticalLayout.childForceExpandWidth = forceExpandWidth;
verticalLayout.spacing = spacing;
return go;
}

return CreateHorizontalLayoutGroup(name, controlWidth, controlHeight, forceExpandWidth, forceExpandHeight, 0.0f, parent);
}
public static GameObject CreateHorizontalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, float spacing = 1.0f, GameObject parent = null)
{
GameObject go = new GameObject(name);
go.transform.SetParent(parent.transform, false);
UI.HorizontalLayoutGroup horizontalLayout = go.AddComponent<UI.HorizontalLayoutGroup>();

horizontalLayout.childForceExpandWidth = forceExpandWidth;
horizontalLayout.spacing = spacing;
return go;
}

5
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs


DebugMenuManager.instance.OnValidate();
}
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.Persistent) != 0.0f)
{
DebugMenuManager.instance.OnMakePersistent();
}
float moveHorizontal = DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.MoveHorizontal);
if (moveHorizontal != 0.0f)
{

16
ProjectSettings/InputManager.asset


type: 0
axis: 6
joyNum: 0
- serializedVersion: 3
m_Name: Debug Persistent
descriptiveName:
descriptiveNegativeName:
negativeButton: right shift
positiveButton:
altNegativeButton: joystick button 2
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 6
joyNum: 0
正在加载...
取消
保存