Close ups

新建Hotspot,命名为Hotspot_Panel,移动缩放使它与场景中的panel重合

image-20211105142332384

新建SimpleCamera,命名为PanelCam,将它对齐置Panel旁边

image-20211105155411477

点击Hotspot:Panel,新建Walk to Marker,将坐标设置为X 2.635,Y 0,Z -1.198,Label为“控制板”,新建Use Interaction,Cursor为Use,Player action为Walk to Marker,勾选Face after moving,编辑它的Interaction

  1. Camera:Switch——New Camera-PanelCam
  2. Player:Constrain——Up movement-disable——Down movement-disable——Left movement-disable——Right movement-disable
  3. Hotspot:Enable or disable——Hotspot to affect-Hotspot_Panel——Change to make-disable

新建Hotspot,命名为Hotspot_Joystick,将其设置如下

image-20211105170736304

选中Hotspot_Joystic,Ctrl+D复制一个,命名为Hotspot_Buttons,向右移动并缩放覆盖到面板右侧的按钮上,Label改为“按钮”,这两个使用相同的interaction(手柄:USE)

注意的是,Hotspot_Joystick和Hotspot_Button的边界都要被Hotspot_Panel包含在里面,这样的话鼠标悬停在上面会先和最外面的Hotspot_panel互动

在Settings manager,Hotspot settings里面,Display Hotspot icon是Only When Highlighting,这就说明每一个Hotspot的Texture要显示的话,必须要有一个Object to highlight 对象,但是,我们不必每一个游戏资产都要添加hightlight组件

选中Hotspot_Panel,直接在里面添加Highlight组件,并且将组件放到Object to highlight里面,并且关闭Auto brighten materials when enabled,这样的话并不需要特定的高亮游戏内的一些对象了,直接显示Hotspot的icon。我们把Hotspot_Joystick和Hotspot_Buttons也这样做

回到Hotspots settings,勾选Hide icons behind Colliders,这样的话在Hotspot_Panel内部的Hotspot_Joystick 和 Hotspot_Buttons就不会在Hotspot_Panel处在激活的状态时显示了。

双击My 3D Game —— PlayerController,将Tutorial Files——EvilLair——EL_TinPot下的PressButton、SlamPanel、TakeBook全都拉取进动画状态树里面,并将这三个动画片段都做一个到Locomotion的过度,在过度条件内全都把exit time设为1,Transition Duration设为0

编辑 手柄:USE 这个interaction,

  1. Character:animate——Is Player-true——Method - Play Custom——Clip name-rRobot|Robot_PressButton——Wait until finish-true
  2. Camera:Switch——New camera-RevealCam
  3. Object:Animate——Animation engine:Mecanim——Animator-LaserGun——Parameter to affect-State——Parameter type:int——Set as value-1
  4. Engine:Wait——Wait time-0.25
  5. Character:animate——Character-EL_Brain——Parameter to affect-DodgeLaser——Parameter type-Trigger
  6. Engine:Wait——Wait time-1
  7. Camera:Switch——Return to last gameplay-true

Creating a new menu

和上一步的Close up交互后,我们制作一个退出菜单来退出Close up交互场景

点击进入Menu Settings,点击Create new menu,Menu Name命名为CloseUp,Source改为Adventure Creator,使用这个source可以快速方便地制作UI原型。在Game界面可以很方便的看到制作的原型样式

Element type选择Button,点击Add new。Element name输入Button_CloseUp、Button text输入Exit,Font选为creatinin-pro、Text size设为3,Text effect选为outline、Effect size选择为2、Text colour(Highlight)设为绿色

在上面的CloseUp properties里面勾选Strat game locked off、Appear type选择During Gameplay、Position选择Aligned、Alignment选择Lower Right

点击进入Hotspot_Panel:Use,在最后添加节点

  1. Menu:Change state——Change type-Unlock menu——Menu to unlock-CloseUp

然后右键——Select All——再右键——Copy Selected

回到Menu manager在Button_CloseUp properties当中点击生成ActionList to run,这个Actionlist会放在Asset文件夹里,双击打开

然后右键——Paste Copied Actions——将第一个engine:wait删除

  1. Camera:Switch——New Camera-NavCam1
  2. Player:Constrain——Up movement-enable——Down movement-enable——Left movement-enable——Right movement-enable
  3. Hotspot:Enable or disable——Hotspot to affect-Hotspot_Panel——Change to make-enable
  4. Menu:Change state——Change type-Lock menu——Menu to unlock-CloseUp

注意这里的Actionlist中引用的对象都自动生成一个ConstantID,因为作为CloseUp menu逻辑的actionlist是创建在asset文件夹中的,这保证了CloseUp menu在多场景中的复用,而且随用随取,通过添加ConstantID可以快速定位在不同场景中引用的对象

接下来,我们将制作好的menu原型转换为Unity UI in prefab,第一步就是进入Menu manager,选中Close up菜单,然后将Source菜单改为Unity UI Prefab

在hierarchy窗口新建UI——Button,将Canvas改名为CloseUpUI

进入2D视图模式,点击Button,聚焦上后,将其移动到Canvas的右下角,并稍微调整一下大小,选中Button,删掉其中的Image Component,并将其子级中的text脱拖拽到Button组件的Target Graphic里面,将Highlighted Color改为绿色

选中Text,将Color改为白色,添加Outline组件,将Font改为creatinin-Pro,并将size改为30。点击Button,重命名为btnCloseUp

将CloseUpUI放进My 3D Game——UI文件夹中,然后进入Menu manager,选中Close up菜单,将CloseUpUI放进Linked Canvas prefab里面,RectTransform Boundary是用来当使用Mouse Over方式的时候判断交互边界用的。然后在Button_CloseUp properties里面,在Linked Button中,将hierarchy敞口中的btnCloseUp拖拽进来。

最后Override一下CloseUpUI,将其从hierarchy窗口中删掉就可以了

Active Inputs

我们已经制作了一个CloseUp菜单,但是我们也需要一个按键映射到Exit按钮上,我们可以根据Project settings——Input Manager里面命名的按键来直接映射

只需要在Menu manager——CloseUp——Button_CloseUp属性中的Alternative Input button输入键名就可以了,这里我们输入Fire1,这样按一下左Ctrl键就能退出CloseUp

实际游戏中,一个按键可能有多个功能,比如Esc键可以打开菜单,也可以退出窗口,我们可以使用菜单Adventure Creator——Editors——Active Inputs Editors来设定按键激活的条件,或者使用这个Active Inputs Editor来设定按键用来激活特定的菜单或功能(注意这里不要使用Fire1,会出现Bug)

image-20211108133909232

回到Menu manager——CloseUp properties,点击新建ActionList when turn on和ActionList when turn off。

ActionList when turn on

  1. Input:Toggle active——Active Input-InputBtn_CloseUp——New state-true

ActionList when turn off

  1. Input:Toggle active——Active Input-InputBtn_CloseUp——New state-false

删掉之前Alternative Input button输入的键名就可以了