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

(196评价)
价格: 4069.00元
暗黑之光第46课背包系统物品拖拽功能
Oneart发起了问答2018-01-28
3
回复
578
浏览
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条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!