背包系统(2)

显示物品的描述信息

用一个单例存放信息

usingUnityEngine;

usingSystem.Collections;

publicclassUIManager:MonoBehaviour{

public Gameobject  panel;

private UIManager( ) {  }

private static UIManager  instance;

public static UIManager Instance{

get{

if(instance==null){

instance =new UIManager ( );

instance.panel =Gameobject.Find("Canvas").transform.FindChild("panel").gameobject;

}

return instance;

}

}

}

显示panel(//挂在预设体item上)

usingUnityEngine;

usingSystem.Collections;

usingUnityEngine.UI;

usingUnityEngine.EventSystems;

publicclassItemDescriptionScript:MonoBehaviour,IPointerEnterHandler,IPointerExitHandler{

//private Gameobject  panel;

public BaseScript goods;

voidStart( ){

//       panel = transform.root.FindChild ("Panel").gameObject ;//item最底层的父物体(Canvas)和panel的父物体相同

}

voidUpdate( ){

}

#regionIPointerEnterHandlerimplementation

publicvoidOnPointerEnter(PointerEventDataeventData)

{

if(!UIManager.Instance.panel.activeSelf){

UIManager.Instance.panel.SetActive(true);

UIManager.Instance.panel.GetComponent<ShowDetalScript>.Goods=goods;

}

}

#endregion

#regionIPointerExitHandlerimplementation

publicvoidOnPointerExit(PointerEventDataeventData)

{

if(UIManager.Instance.panel.activeSelf){

UIManager.Instance.panel.SetActive(false);

}

}

#endregion

}

将物品加载到panel上(//描述,挂在Panel上)

usingUnityEngine;

usingSystem.Collections;

usingUnityEngine.UI;

public classShowDetalScript:MonoBehaviour{

private BaseScript goods;

public BaseScript Goods{

get{

returngoods;

}

set{

goods=value;

headImage.overrideSprite=Resources.Load("Texture/"+goods.iconName);

goodsName.text=goods.name;

description.text=goods.description;

}

}

private  Image  headImage;

private  Text   goodsName;

private  Text    description;

voidAwake( ){

headImage=transform.GetChild(0).gameObject.GetComponent<Image>( );

description=transform.GetChild(1).gameObject.GetComponent<Text>( );

goodsName=transform.GetChild(2).gameObject.GetComponent<Text>( );

}

voidUpdate( ){

}

}

翻页(挂载在Canvas上)

usingUnityEngine;

usingSystem.Collections;

publicclassNextPageScript:MonoBehaviour{

publicGameObjectcontent;

voidStart(){

}

voidUpdate(){

}

publicvoidButtonPressed( ){

content.transform.localPosition=newVector3(content.transform.localPosition.x,content.transform.localPosition.y+400f,0);

}

publicvoidButtonPressed_1( ){

content.transform.localPosition=newVector3(content.transform.localPosition.x,content.transform.localPosition.y-400f,0);

}

}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 基类脚本 usingUnityEngine; usingSystem.Collections; publiccla...
    胤醚貔貅阅读 4,064评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,390评论 19 139
  • 没有牵挂,没有心思 没有压抑,也没有克制 我的心如野草向光而生,永不回头
    须荌阅读 1,430评论 1 0
  • 前诗:前生身份终有别,一场车祸至古代。重生一见定此生,多少悲欢离别叹。只愿与你共进退,不遂我愿遇他人,从此陌路一生...
    司官耀耀阅读 3,218评论 1 3
  • 我本不是一个懦弱的人。 寒假已经接近尾声,这大概是我最后一次在家持续混吃等死的悠长假期。 没有履行放假前期做好的旅...
    竹Danica阅读 3,655评论 0 0