Improved Context Menus
Context menus now support dropdown options Context menus can now be created for UI elements with new dedicated cancellation click catcher Game manager creates context menus based on the object being clicked, no need for duplicate code in every context that object appears
This commit is contained in:
parent
36f0e4b364
commit
0ae4a388f5
14 changed files with 1062 additions and 226 deletions
|
|
@ -1753,12 +1753,14 @@
|
|||
<e p="ClickCatcher.cs" t="Include" />
|
||||
<e p="ClickRaycaster.cs" t="Include" />
|
||||
<e p="ContextMenu.cs" t="Include" />
|
||||
<e p="ContextMenuOption.cs" t="Include" />
|
||||
<e p="CorporationMenuItem.cs" t="Include" />
|
||||
<e p="DragHandler.cs" t="Include" />
|
||||
<e p="FlatButton.cs" t="Include" />
|
||||
<e p="GalaxyZone.cs" t="Include" />
|
||||
<e p="Icons.cs" t="Include" />
|
||||
<e p="LoginScreen.cs" t="Include" />
|
||||
<e p="MouseHover.cs" t="Include" />
|
||||
<e p="PropertiesPanel.cs" t="Include" />
|
||||
<e p="PropertyLabel.cs" t="Include" />
|
||||
<e p="ReadOnlyPropertiesPanel.cs" t="Include" />
|
||||
|
|
|
|||
|
|
@ -874,12 +874,14 @@
|
|||
<Compile Include="Assets\Scripts\UI\ClickCatcher.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ClickRaycaster.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ContextMenu.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ContextMenuOption.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\CorporationMenuItem.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\DragHandler.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\FlatButton.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\GalaxyZone.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\Icons.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\LoginScreen.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\MouseHover.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\PropertiesPanel.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\PropertyLabel.cs" />
|
||||
<Compile Include="Assets\Scripts\UI\ReadOnlyPropertiesPanel.cs" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &4271092340480064605
|
||||
--- !u!1 &2147126713262799487
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
|
|
@ -8,30 +8,33 @@ GameObject:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 4271092340480064602}
|
||||
- component: {fileID: 4271092340480064598}
|
||||
- component: {fileID: 4271092340480064601}
|
||||
- component: {fileID: 4271092340480064600}
|
||||
- component: {fileID: 4271092340480064603}
|
||||
- component: {fileID: 2147126713262799480}
|
||||
- component: {fileID: 2147126713262799476}
|
||||
- component: {fileID: 2147126713262799483}
|
||||
- component: {fileID: 2147126713262799482}
|
||||
- component: {fileID: 2147126713262799481}
|
||||
- component: {fileID: 3523328438153607920}
|
||||
- component: {fileID: 1963641399357161325}
|
||||
m_Layer: 5
|
||||
m_Name: Button 1
|
||||
m_Name: Context Menu Option
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &4271092340480064602
|
||||
--- !u!224 &2147126713262799480
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092340480064605}
|
||||
m_GameObject: {fileID: 2147126713262799487}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 4271092341023254464}
|
||||
- {fileID: 2147126713793274338}
|
||||
- {fileID: 1944744018361081348}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
|
@ -40,21 +43,21 @@ RectTransform:
|
|||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &4271092340480064598
|
||||
--- !u!222 &2147126713262799476
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092340480064605}
|
||||
m_GameObject: {fileID: 2147126713262799487}
|
||||
m_CullTransparentMesh: 0
|
||||
--- !u!114 &4271092340480064601
|
||||
--- !u!114 &2147126713262799483
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092340480064605}
|
||||
m_GameObject: {fileID: 2147126713262799487}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
|
|
@ -75,13 +78,13 @@ MonoBehaviour:
|
|||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
--- !u!114 &4271092340480064600
|
||||
--- !u!114 &2147126713262799482
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092340480064605}
|
||||
m_GameObject: {fileID: 2147126713262799487}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
|
|
@ -111,17 +114,17 @@ MonoBehaviour:
|
|||
m_PressedTrigger: Pressed
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 4271092340480064601}
|
||||
m_TargetGraphic: {fileID: 2147126713262799483}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
--- !u!114 &4271092340480064603
|
||||
--- !u!114 &2147126713262799481
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092340480064605}
|
||||
m_GameObject: {fileID: 2147126713262799487}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
|
|
@ -135,7 +138,35 @@ MonoBehaviour:
|
|||
m_FlexibleWidth: -1
|
||||
m_FlexibleHeight: -1
|
||||
m_LayoutPriority: 1
|
||||
--- !u!1 &4271092341023254467
|
||||
--- !u!114 &3523328438153607920
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2147126713262799487}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 741dca7ca8716dd438516c4f8bafd441, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Label: {fileID: 2147126713793274364}
|
||||
Arrow: {fileID: 1628239746935905733}
|
||||
Button: {fileID: 2147126713262799482}
|
||||
Hover: {fileID: 1963641399357161325}
|
||||
--- !u!114 &1963641399357161325
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2147126713262799487}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6435d6126b6f8694292cb94466cf1df4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &2147126713793274337
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
|
|
@ -143,10 +174,10 @@ GameObject:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 4271092341023254464}
|
||||
- component: {fileID: 4271092341023254495}
|
||||
- component: {fileID: 4271092341023254494}
|
||||
- component: {fileID: 4271092341023254465}
|
||||
- component: {fileID: 2147126713793274338}
|
||||
- component: {fileID: 2147126713793274365}
|
||||
- component: {fileID: 2147126713793274364}
|
||||
- component: {fileID: 2147126713793274339}
|
||||
m_Layer: 5
|
||||
m_Name: Text (TMP)
|
||||
m_TagString: Untagged
|
||||
|
|
@ -154,18 +185,18 @@ GameObject:
|
|||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &4271092341023254464
|
||||
--- !u!224 &2147126713793274338
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092341023254467}
|
||||
m_GameObject: {fileID: 2147126713793274337}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 4271092340480064602}
|
||||
m_Father: {fileID: 2147126713262799480}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
|
|
@ -173,21 +204,21 @@ RectTransform:
|
|||
m_AnchoredPosition: {x: 4, y: 0}
|
||||
m_SizeDelta: {x: -24, y: -8}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &4271092341023254495
|
||||
--- !u!222 &2147126713793274365
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092341023254467}
|
||||
m_GameObject: {fileID: 2147126713793274337}
|
||||
m_CullTransparentMesh: 0
|
||||
--- !u!114 &4271092341023254494
|
||||
--- !u!114 &2147126713793274364
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092341023254467}
|
||||
m_GameObject: {fileID: 2147126713793274337}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||
|
|
@ -268,7 +299,7 @@ MonoBehaviour:
|
|||
m_pageToDisplay: 1
|
||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_textInfo:
|
||||
textComponent: {fileID: 4271092341023254494}
|
||||
textComponent: {fileID: 2147126713793274364}
|
||||
characterCount: 14
|
||||
spriteCount: 0
|
||||
spaceCount: 1
|
||||
|
|
@ -292,13 +323,13 @@ MonoBehaviour:
|
|||
- {fileID: 0}
|
||||
m_baseMaterial: {fileID: 0}
|
||||
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
||||
--- !u!114 &4271092341023254465
|
||||
--- !u!114 &2147126713793274339
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4271092341023254467}
|
||||
m_GameObject: {fileID: 2147126713793274337}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
|
|
@ -312,3 +343,75 @@ MonoBehaviour:
|
|||
m_FlexibleWidth: -1
|
||||
m_FlexibleHeight: -1
|
||||
m_LayoutPriority: 1
|
||||
--- !u!1 &7016173882347324599
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1944744018361081348}
|
||||
- component: {fileID: 1986380382041583511}
|
||||
- component: {fileID: 1628239746935905733}
|
||||
m_Layer: 5
|
||||
m_Name: Image
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1944744018361081348
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7016173882347324599}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2147126713262799480}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 1, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: -2, y: 0}
|
||||
m_SizeDelta: {x: 24, y: -8}
|
||||
m_Pivot: {x: 1, y: 0.5}
|
||||
--- !u!222 &1986380382041583511
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7016173882347324599}
|
||||
m_CullTransparentMesh: 0
|
||||
--- !u!114 &1628239746935905733
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7016173882347324599}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 21300000, guid: ef87bbaa6e6f6824fa1b758cc93393d5, type: 3}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
|
|
|
|||
364
Assets/Prefabs/Context Menu.prefab
Normal file
364
Assets/Prefabs/Context Menu.prefab
Normal file
|
|
@ -0,0 +1,364 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &3452408986865468161
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3452408986865468174}
|
||||
- component: {fileID: 3452408986865468172}
|
||||
- component: {fileID: 3452408986865468175}
|
||||
- component: {fileID: 3452408986865468173}
|
||||
m_Layer: 5
|
||||
m_Name: Context Menu
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &3452408986865468174
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408986865468161}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 3452408988660256314}
|
||||
- {fileID: 3452408986885472817}
|
||||
- {fileID: 3452408987762814048}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 0, y: -35.87}
|
||||
m_SizeDelta: {x: 250, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &3452408986865468172
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408986865468161}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1741964061, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_HorizontalFit: 0
|
||||
m_VerticalFit: 2
|
||||
--- !u!114 &3452408986865468175
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408986865468161}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1297475563, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Padding:
|
||||
m_Left: 2
|
||||
m_Right: 2
|
||||
m_Top: 2
|
||||
m_Bottom: 2
|
||||
m_ChildAlignment: 0
|
||||
m_Spacing: 0
|
||||
m_ChildForceExpandWidth: 1
|
||||
m_ChildForceExpandHeight: 1
|
||||
m_ChildControlWidth: 1
|
||||
m_ChildControlHeight: 1
|
||||
--- !u!114 &3452408986865468173
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408986865468161}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f50aaf220f9a82a4a817fa3164bcd62b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Canvas: {fileID: 0}
|
||||
Root: {fileID: 0}
|
||||
CancelClickCatcher: {fileID: 0}
|
||||
OptionPrefab: {fileID: 3523328438153607920, guid: 8cabdd9c2f8e4be45b917debb4762707,
|
||||
type: 3}
|
||||
DropMenuPrefab: {fileID: 3452408986865468173}
|
||||
IsDropdown: 0
|
||||
ForceDirectionRight: 0
|
||||
ForcePosition: {x: 0, y: 0, z: 0}
|
||||
ContentRoot: {fileID: 3452408986885472817}
|
||||
OptionHeight: 34
|
||||
PaddingHeight: 16
|
||||
--- !u!1 &3452408986885472816
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3452408986885472817}
|
||||
- component: {fileID: 3452408986885472831}
|
||||
- component: {fileID: 3452408986885472830}
|
||||
m_Layer: 5
|
||||
m_Name: Content
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &3452408986885472817
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408986885472816}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3452408986865468174}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &3452408986885472831
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408986885472816}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1297475563, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Padding:
|
||||
m_Left: 0
|
||||
m_Right: 0
|
||||
m_Top: 3
|
||||
m_Bottom: 3
|
||||
m_ChildAlignment: 0
|
||||
m_Spacing: 1
|
||||
m_ChildForceExpandWidth: 1
|
||||
m_ChildForceExpandHeight: 1
|
||||
m_ChildControlWidth: 1
|
||||
m_ChildControlHeight: 1
|
||||
--- !u!114 &3452408986885472830
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408986885472816}
|
||||
m_Enabled: 0
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1741964061, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_HorizontalFit: 0
|
||||
m_VerticalFit: 1
|
||||
--- !u!1 &3452408987762814051
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3452408987762814048}
|
||||
- component: {fileID: 3452408987762814063}
|
||||
- component: {fileID: 3452408987762814062}
|
||||
- component: {fileID: 3452408987762814049}
|
||||
m_Layer: 5
|
||||
m_Name: Outline
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &3452408987762814048
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408987762814051}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3452408986865468174}
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &3452408987762814063
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408987762814051}
|
||||
m_CullTransparentMesh: 0
|
||||
--- !u!114 &3452408987762814062
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408987762814051}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 0.8, g: 0.9333333, b: 1, a: 1}
|
||||
m_RaycastTarget: 0
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 21300000, guid: f86ca8785ddc5524d9f125ad626ffcf8, type: 3}
|
||||
m_Type: 1
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 0
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
--- !u!114 &3452408987762814049
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408987762814051}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_IgnoreLayout: 1
|
||||
m_MinWidth: -1
|
||||
m_MinHeight: -1
|
||||
m_PreferredWidth: -1
|
||||
m_PreferredHeight: -1
|
||||
m_FlexibleWidth: -1
|
||||
m_FlexibleHeight: -1
|
||||
m_LayoutPriority: 1
|
||||
--- !u!1 &3452408988660256317
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3452408988660256314}
|
||||
- component: {fileID: 3452408988660256313}
|
||||
- component: {fileID: 3452408988660256312}
|
||||
- component: {fileID: 3452408988660256315}
|
||||
m_Layer: 5
|
||||
m_Name: Fill
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &3452408988660256314
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408988660256317}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3452408986865468174}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &3452408988660256313
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408988660256317}
|
||||
m_CullTransparentMesh: 0
|
||||
--- !u!114 &3452408988660256312
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408988660256317}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 0, g: 0.041666675, b: 0.1, a: 0.79607844}
|
||||
m_RaycastTarget: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 21300000, guid: d43f9691259ed984fa09c853c5cda7f0, type: 3}
|
||||
m_Type: 1
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
--- !u!114 &3452408988660256315
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3452408988660256317}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_IgnoreLayout: 1
|
||||
m_MinWidth: -1
|
||||
m_MinHeight: -1
|
||||
m_PreferredWidth: -1
|
||||
m_PreferredHeight: -1
|
||||
m_FlexibleWidth: -1
|
||||
m_FlexibleHeight: -1
|
||||
m_LayoutPriority: 1
|
||||
7
Assets/Prefabs/Context Menu.prefab.meta
Normal file
7
Assets/Prefabs/Context Menu.prefab.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 75d78a753ab7e4e41995db4f59fd74b7
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Resources/Sprites/Icons/rightArrow.png
(Stored with Git LFS)
Normal file
BIN
Assets/Resources/Sprites/Icons/rightArrow.png
(Stored with Git LFS)
Normal file
Binary file not shown.
110
Assets/Resources/Sprites/Icons/rightArrow.png.meta
Normal file
110
Assets/Resources/Sprites/Icons/rightArrow.png.meta
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ef87bbaa6e6f6824fa1b758cc93393d5
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 9
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 64
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- serializedVersion: 2
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 64
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- serializedVersion: 2
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 64
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 29e18919e5ea9284a9e1964ab5ce7934
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -266,7 +266,6 @@ public class StrategyGameManager : MonoBehaviour
|
|||
|
||||
ClickRaycaster.OnClickMiss += () =>
|
||||
{
|
||||
ContextMenu.gameObject.SetActive(false);
|
||||
if (_currentTab == GalaxyTabButton) PopulateGalaxyProperties();
|
||||
else if (_currentTab == ZoneTabButton) PopulateZoneProperties(_populatedZone);
|
||||
else if (_currentTab == TechTabButton) PopulateTechProperties();
|
||||
|
|
@ -345,6 +344,25 @@ public class StrategyGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
void ShowContextMenu(object clickTarget)
|
||||
{
|
||||
ContextMenu.gameObject.SetActive(true);
|
||||
ContextMenu.Clear();
|
||||
if (clickTarget is PlanetData planet)
|
||||
{
|
||||
ContextMenu.AddOption("Test Option 1", () => Debug.Log("Test Option 1 Selected"));
|
||||
ContextMenu.AddOption("Test Option 2", () => Debug.Log("Test Option 2 Selected"));
|
||||
ContextMenu.AddDropdown("Test Dropdown", new []
|
||||
{
|
||||
("Dropdown Option 1", (Action) (() => Debug.Log("Dropdown Option 1 Selected"))),
|
||||
("Dropdown Option 2", (Action) (() => Debug.Log("Dropdown Option 2 Selected"))),
|
||||
("Dropdown Option 3", (Action) (() => Debug.Log("Dropdown Option 3 Selected")))
|
||||
});
|
||||
ContextMenu.AddOption("Test Option 3", () => Debug.Log("Test Option 3 Selected"));
|
||||
}
|
||||
ContextMenu.Show();
|
||||
}
|
||||
|
||||
void PopulateGalaxy()
|
||||
{
|
||||
_galaxyPopulated = true;
|
||||
|
|
@ -507,11 +525,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
}
|
||||
else if (data.button == PointerEventData.InputButton.Right)
|
||||
{
|
||||
ContextMenu.gameObject.SetActive(true);
|
||||
ContextMenu.SetOptions(new []
|
||||
{
|
||||
("Test Option", (Action) (() => Debug.Log("Test Option Selected")))
|
||||
});
|
||||
ShowContextMenu(planetData);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -537,7 +551,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
}
|
||||
else if (data.button == PointerEventData.InputButton.Right)
|
||||
{
|
||||
|
||||
ShowContextMenu(planetData);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,13 @@ using UnityEngine.UI;
|
|||
public class ContextMenu : MonoBehaviour
|
||||
{
|
||||
public Canvas Canvas;
|
||||
public RectTransform OptionPrefab;
|
||||
public RectTransform Root;
|
||||
public ClickCatcher CancelClickCatcher;
|
||||
public ContextMenuOption OptionPrefab;
|
||||
public ContextMenu DropMenuPrefab;
|
||||
public ContextMenu Parent;
|
||||
public bool ForceDirectionRight;
|
||||
public Vector3 ForcePosition;
|
||||
|
||||
public RectTransform ContentRoot;
|
||||
|
||||
|
|
@ -17,31 +23,100 @@ public class ContextMenu : MonoBehaviour
|
|||
public float PaddingHeight;
|
||||
|
||||
private List<GameObject> _options = new List<GameObject>();
|
||||
private bool _hasDropdown;
|
||||
private bool _dropdownRight;
|
||||
private GameObject _dropdown;
|
||||
private ContextMenuOption _currentDropdown;
|
||||
|
||||
public void SetOptions(IEnumerable<(string text, Action action)> options)
|
||||
private void Start()
|
||||
{
|
||||
if (CancelClickCatcher != null)
|
||||
CancelClickCatcher.OnClick += data =>
|
||||
{
|
||||
End();
|
||||
};
|
||||
}
|
||||
|
||||
private void End()
|
||||
{
|
||||
if (_dropdown != null)
|
||||
Destroy(_dropdown);
|
||||
CancelClickCatcher.gameObject.SetActive(false);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
var rect = transform as RectTransform;
|
||||
var pivot = rect.pivot;
|
||||
pivot.x = Input.mousePosition.x > Screen.width - rect.sizeDelta.x * Canvas.scaleFactor ? 1 : 0;
|
||||
pivot.y = Input.mousePosition.y < (PaddingHeight + options.Count() * OptionHeight) * Canvas.scaleFactor ? 0 : 1;
|
||||
rect.pivot = pivot;
|
||||
rect.position = Input.mousePosition;
|
||||
|
||||
// Destroy previous options
|
||||
foreach(var option in _options)
|
||||
Destroy(option);
|
||||
_options.Clear();
|
||||
|
||||
foreach (var option in options)
|
||||
_hasDropdown = false;
|
||||
}
|
||||
|
||||
public void AddOption(string text, Action action)
|
||||
{
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
optionButton.Label.text = text;
|
||||
optionButton.Button.onClick.AddListener(() =>
|
||||
{
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
optionButton.GetComponentInChildren<TextMeshProUGUI>().text = option.text;
|
||||
optionButton.GetComponent<Button>().onClick.AddListener(() =>
|
||||
action();
|
||||
if(Parent!=null)
|
||||
Parent.End();
|
||||
else
|
||||
End();
|
||||
});
|
||||
optionButton.Hover.OnEnter += data =>
|
||||
{
|
||||
if (_dropdown != null)
|
||||
Destroy(_dropdown);
|
||||
};
|
||||
optionButton.Arrow.gameObject.SetActive(false);
|
||||
_options.Add(optionButton.gameObject);
|
||||
}
|
||||
|
||||
public void AddDropdown(string text, IEnumerable<(string text, Action action)> options)
|
||||
{
|
||||
_hasDropdown = true;
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
optionButton.Label.text = text;
|
||||
optionButton.Hover.OnEnter += data =>
|
||||
{
|
||||
if (_currentDropdown != optionButton)
|
||||
{
|
||||
option.action();
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
_options.Add(optionButton.gameObject);
|
||||
}
|
||||
if(_dropdown!=null)
|
||||
Destroy(_dropdown);
|
||||
var drop = Instantiate(DropMenuPrefab, Root);
|
||||
_dropdown = drop.gameObject;
|
||||
foreach (var option in options)
|
||||
drop.AddOption(option.text, option.action);
|
||||
drop.Parent = this;
|
||||
drop.ForceDirectionRight = _dropdownRight;
|
||||
Vector3[] corners = new Vector3[4];
|
||||
((RectTransform) optionButton.transform).GetWorldCorners(corners);
|
||||
drop.ForcePosition = corners[_dropdownRight ? 2 : 1];
|
||||
drop.Show();
|
||||
}
|
||||
};
|
||||
_options.Add(optionButton.gameObject);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
var rect = transform as RectTransform;
|
||||
var pivot = rect.pivot;
|
||||
var canvas = Parent != null ? Parent.Canvas : Canvas;
|
||||
if (Parent!=null)
|
||||
pivot.x = ForceDirectionRight ? 0 : 1;
|
||||
else
|
||||
pivot.x = Input.mousePosition.x > Screen.width - rect.sizeDelta.x * canvas.scaleFactor ? 1 : 0;
|
||||
var scaleFactor = canvas.scaleFactor;
|
||||
_dropdownRight = Input.mousePosition.x < Screen.width - rect.sizeDelta.x * scaleFactor * 2;
|
||||
var pivotTop = (Parent==null ? Input.mousePosition.y : ForcePosition.y) > (PaddingHeight + _options.Count * OptionHeight) * scaleFactor;
|
||||
pivot.y = pivotTop ? 1 : 0;
|
||||
rect.pivot = pivot;
|
||||
rect.position = Parent!=null ? ForcePosition - (pivotTop ? Vector3.zero : Vector3.up * (OptionHeight * scaleFactor)) : Input.mousePosition;
|
||||
if (Parent==null)
|
||||
CancelClickCatcher.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
Assets/Scripts/UI/ContextMenuOption.cs
Normal file
13
Assets/Scripts/UI/ContextMenuOption.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ContextMenuOption : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Image Arrow;
|
||||
public Button Button;
|
||||
public MouseHover Hover;
|
||||
}
|
||||
11
Assets/Scripts/UI/ContextMenuOption.cs.meta
Normal file
11
Assets/Scripts/UI/ContextMenuOption.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 741dca7ca8716dd438516c4f8bafd441
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/Scripts/UI/MouseHover.cs
Normal file
27
Assets/Scripts/UI/MouseHover.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MouseHover : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public event Action<PointerEventData> OnEnter;
|
||||
public event Action<PointerEventData> OnExit;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
OnEnter?.Invoke(eventData);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
OnExit?.Invoke(eventData);
|
||||
}
|
||||
|
||||
public void ClearListeners()
|
||||
{
|
||||
OnEnter = null;
|
||||
OnExit = null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/MouseHover.cs.meta
Normal file
11
Assets/Scripts/UI/MouseHover.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6435d6126b6f8694292cb94466cf1df4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue