Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(207评价)
优惠后 ¥1899.00优惠前 ¥2499.00 双十一全年最大力度限时优惠
1对1 答疑即时回复7天无理由退款30天价保提问必答

服务保障

1对1 答疑

提供专属的一对一在线答疑,快速答疑解惑。

即时回复

及时响应学习咨询,帮助解决问题。

7天无理由退款

购买后7天内可申请无理由退款。

30天价保

购买后30天内如遇降价,可申请价保。

提问必答

对于提问做到有问必答,帮您扫清学习过程中的种种障碍

暗黑之光第46课背包系统物品拖拽功能
Oneart发起了问答2018-01-28
3
回复
777
浏览
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InventoryItem : UIDragDropItem {

    
    private UISprite sprite;

    protected override void Awake() {
        base.Awake();
        sprite = this.GetComponent<UISprite>();
        
    }

    protected override void OnDragDropRelease(GameObject surface)
    {//当我们拖拽结束的时候鼠标下的物体 根据鼠标碰撞监测 碰撞到的第一个物体就是 surface
        base.OnDragDropRelease(surface);
        
        if (surface != null)
        {
            if (surface.tag == Tags.inventory_item_grid)//当拖放到一个空的格子里面的时候
            {
                if (surface == this.transform.parent.gameObject)//拖放到自己的格子里面
                {
                    
                    ResetPosition();
                }else
                {
                    Debug.Log("aaa");
                    InventoryItemGrid oldParent = this.transform.parent.GetComponent<InventoryItemGrid>();
                    Debug.Log(oldParent.name);
                    this.transform.parent = surface.transform;
                    ResetPosition();
                    InventoryItemGrid newParent = surface.GetComponent<InventoryItemGrid>();
                    newParent.SetId(oldParent.id, oldParent.num);
                    Debug.Log(newParent.transform.position);
                    oldParent.ClearInfo();//清空当前父亲的信息
                }
            }
            else if (surface.tag == Tags.inventory_Item)//当拖放到一个有物品的格子里面的时候
            {

            }
            else {
                ResetPosition();
            }

        }
        else {
            ResetPosition();
        }

    }

    void ResetPosition() {//重置位置
        transform.localPosition = Vector3.zero;
    }

    public void SetId(int id) {
        ObjectInfo info = ObjectsInfo._instance.GetObjectInfoById(id);
        sprite.spriteName = info.icon_name;
    }

    public void SetIconName(string icon_name) {
        sprite.spriteName = icon_name;
    }
}

Debug.Log("aaa");这一段以下的代码 没有反应 就是拖拽到另一个物体放置的时候 没有效果也没用任何报错 应该怎么解决 我用的是NGUI 3.11.4  unity2017.3 版本

所有回复
  • 缘分 • 2018-01-28

    建议用unity3d的亲儿子UGUI代码比NGUI简单多了!

    还有-4条回复,点击查看
    你还没有登录,请先登录或注册!
  • 老师_Trigger • 2018-01-28

    同学你好,同学要把NGUI与Unity的版本对应起来,比如这个案例是unity4.6开发的,所以之前的NGUI版本是没有问题的,但是同学如果使用最新的Unity版本,一定要去NGUI看看官网的更新日志,以及下载导入最新的NGUI插件,因为这些东西都是在不断更新的,包括对应的文件以及API

    还有-5条回复,点击查看
    你还没有登录,请先登录或注册!
发表回复
你还没有登录,请先 登录或 注册!