Exemplo n.º 1
0
 void LateUpdate()
 {
     if (flag)
     {
         if (Input.GetMouseButtonDown(1))
         {
             item_dis.instance.gameObject.SetActive(false);  
             EquipAndBag_Grid now = transform.parent.gameObject.GetComponent <EquipAndBag_Grid> ();
             if (now.id >= 1001 && now.id <= 1003)
             {
                 if (id == 0)
                 {
                     return;
                 }
                 objectInfo info = ObjectsInfo.instance.FindObjecInfoById(now.id);
                 int        hp   = info.hp;
                 int        mp   = info.mp;
                 ps.GetDrug(hp, mp);
                 transform.parent.GetComponent <EquipAndBag_Grid> ().MinsNumber();
             }
             else if (now.id >= 2001 && now.id <= 2023)
             {
                 bool success = Equip.instance.Dress(now.id);
                 if (success)
                 {
                     transform.parent.GetComponent <EquipAndBag_Grid> ().MinsNumber();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
    public objectInfo FindObjecInfoById(int id)
    {
        objectInfo info = null;

        objectInfoDic.TryGetValue(id, out info);
        return(info);
    }
Exemplo n.º 3
0
    void MinProperty(int id)
    {
        objectInfo info = ObjectsInfo.instance.FindObjecInfoById(id);

        this.attack -= info.attack;
        this.def    -= info.def;
        this.speed  -= info.speed;
    }
Exemplo n.º 4
0
    void plusProperty(int id)
    {
        objectInfo info = ObjectsInfo.instance.FindObjecInfoById(id);

        this.attack += info.attack;
        this.def    += info.def;
        this.speed  += info.speed;
    }
Exemplo n.º 5
0
    /// <summary>
    /// Start is called on the frame when a script is enabled just before
    /// any of the Update methods is called the first time.
    /// </summary>
    // void Start()
    // {
    //  spawn(Vector3.zero, Vector3Int.zero, -1);
    //  spawn(Vector3.up*5, Vector3Int.zero, -1);
    // }
    void sculptObjects()
    {
        if (Cursor.lockState == CursorLockMode.None)
        {
            return;
        }
        if ((Input.GetButton("Fire1")) /*  && (Sthread == null || !Sthread.IsAlive)*/)
        {
            int        multi = 1;
            RaycastHit hit;
            Ray        ray = new Ray(cam.transform.position, cam.transform.forward);    //cam.ScreenPointToRay(new Vector2(Screen.width/2,Screen.height/2));

            if (Physics.Raycast(ray, out hit, 30f))
            {
                objectInfo objInfo = hit.transform.GetComponent <objectInfo>();
                if (objInfo != null && objInfo.enabled)
                {
                    Vector3 pos = hit.transform.InverseTransformPoint(hit.point) - hit.normal * multi;
                    //Vector3 playerPos = Player.localPosition;

                    MeshCollider collider = hit.collider as MeshCollider;
                    // Remember to handle case where collider is null because you hit a non-mesh primitive...

                    Mesh mesh  = collider.sharedMesh;
                    int  limit = hit.triangleIndex * 3;

                    //int submesh = 0;
                    // if(multi == -1){
                    //     for(submesh = 0; submesh < mesh.subMeshCount; submesh++)
                    //     {
                    //         int numIndices = mesh.GetTriangles(submesh).Length;
                    //         if(numIndices > limit)
                    //             break;

                    //         limit -= numIndices;
                    //     }
                    //     Material material = collider.GetComponent<MeshRenderer>().sharedMaterials[submesh];
                    //     submesh = m_materials.IndexOf(material);
                    // }
                    //Debug.Log(hit.transform.InverseTransformPoint(pos));
                    VoxelObj vObj = objDict[objInfo.chunk][objInfo.index];
                    Voxel[]  v    = vObj.voxels;
                    sculptingObj.sculpt(ref v, pos, 1, vObj.vSize);
                    objDict[objInfo.chunk][objInfo.index] = new VoxelObj(vObj.vSize, v);
                    spawn(hit.transform.localPosition, objInfo.chunk, objInfo.index);
                    objInfo.enabled = false;
                    // if(objDict[objInfo.chunk][objInfo.index].voxels == objects[0].voxels){
                    //  Debug.Log("fail");
                    // }

                    /* Sthread = new Thread(() => GTL(sculp.sculpt(ref voxels,multi,pos,playerPos,submesh)));
                     *
                     * Sthread.Start();*/
                }
            }
        }
    }
Exemplo n.º 6
0
    public void OnEndDrag(PointerEventData eventData)               //
    {
        GameObject go = eventData.pointerCurrentRaycast.gameObject; //获取到鼠标终点位置下 可能的物体


        if (go != null)
        {
            Debug.Log(go.name);
            if (go.tag.Equals("Grid"))            //鼠标终点位置下是: 空格子(所以直接放进去)
            {
                SetParentAndPosition(transform, go.transform);
                go.GetComponent <EquipAndBag_Grid>().id  = this.id;
                go.GetComponent <EquipAndBag_Grid>().num = this.count;
                //ChangeParentId (transform.parent,go.transform);
                ChangeCount(transform.parent, go.transform);
            }
            else if (go.tag.Equals("PlayerPetItem")) //鼠标终点位置下是: 也是一个物体(所以需要交换位置)
            {                                        //交换位置要注意可能需要把物品下的子物体的Raycast Target关掉(不去掉可能无法交换)
                //ChangeParentId (transform.parent,go.transform.parent);
                go.transform.parent.GetComponent <EquipAndBag_Grid>().id  = this.id;
                go.transform.parent.GetComponent <EquipAndBag_Grid>().num = this.count;
                transform.parent.GetComponent <EquipAndBag_Grid>().id     = go.GetComponent <Drag2>().id;
                transform.parent.GetComponent <EquipAndBag_Grid>().num    = go.GetComponent <Drag2>().count;
                //ChangeIdandCount(transform.parent,go.transform.parent);
                SetParentAndPosition(transform, go.transform.parent); //将被拖拽的物体1放到鼠标终点下的格子2里面
                SetParentAndPosition(go.transform, nowParent);        //将鼠标终点格子2里面物体2 放到 原来物体1的格子1里面
                ChangeCount(transform.parent, go.transform.parent);


                if (transform.position == go.transform.position)
                {
                    Debug.Log("error");
                }
            }
            else if (go.tag.Equals("shortcutdrug"))
            {
                go.GetComponent <ShortCutItem> ().setDrag2(id, count);
                Destroy(gameObject);
            }
            else if (go.tag.Equals("shopweapon"))
            {
                objectInfo info = ObjectsInfo.instance.FindObjecInfoById(id);

                EquipAndBag.instance.GetMoney(info.price_sell * count);
                Destroy(gameObject);
            }
            else            //鼠标终点是:无效位置(所以物体放回原来的位置)
            {
                SetParentAndPosition(transform, nowParent);
            }
        }
        else        //
        {
            SetParentAndPosition(transform, nowParent);
        }
        isRaycastLocationValid = true;        //ui事件穿透:置为不能穿透
    }
Exemplo n.º 7
0
 void PlusProperty(EquipItem item)
 {
     if (item != null)
     {
         objectInfo info = ObjectsInfo.instance.FindObjecInfoById(item.id);
         this.attack += info.attack;
         this.def    += info.def;
         this.speed  += info.speed;
     }
 }
Exemplo n.º 8
0
    public void AllBuyBtn(int id)
    {
        objectInfo info    = ObjectsInfo.instance.FindObjecInfoById(id);
        int        price   = info.price_buy;
        bool       success = EquipAndBag.instance.getCoin(price);

        if (success)
        {
            EquipAndBag.instance.getId(id);
        }
    }
Exemplo n.º 9
0
    public void setId(int id, int num = 1)
    {
        this.id = id;
        info    = ObjectsInfo.instance.FindObjecInfoById(id);
        Drag2 item = this.GetComponentInChildren <Drag2> ();

        item.setIconname(info.icon_name);
        itemcount.SetActive(true);
        this.num = num;
        itemcount.GetComponent <Text> ().text = num.ToString();
    }
Exemplo n.º 10
0
 public void setDrag2(int id, int count)
 {
     count_text      = transform.parent.Find("shortcutcount").GetComponent <Text> ();
     this.id         = id;
     this.count      = count;
     count_text.text = count.ToString();
     count_text.gameObject.SetActive(true);
     this.obinfo        = ObjectsInfo.instance.FindObjecInfoById(id);
     img                = this.GetComponent <Image> ();
     img.overrideSprite = Resources.Load("Icon/" + obinfo.icon_name, typeof(Sprite)) as Sprite;
     type               = ShortCutType.Drug;
 }
Exemplo n.º 11
0
    public bool Dress_load(int id)
    {
        objectInfo info   = ObjectsInfo.instance.FindObjecInfoById(id);
        GameObject parent = null;

        switch (info.dressType)
        {
        case DressType.Headgear:
            parent = headgear;
            break;

        case DressType.Armor:
            parent = armor;
            break;

        case DressType.LeftHand:
            parent = lefthand;
            break;

        case DressType.RightHand:
            parent = righthand;
            break;

        case DressType.Shoe:
            parent = shoe;
            break;

        case DressType.Accessory:
            parent = accessory;
            break;
        }

        EquipItem item = parent.GetComponentInChildren <EquipItem>();

        if (item != null)
        {
            EquipAndBag.instance.getId(item.id);//装备卸下,放回
            MinProperty(item.id);
            item.SetInfo(info);
            plusProperty(info.id);
        }
        else
        {
            GameObject itemGo = Instantiate(equip_item);
            itemGo.transform.SetParent(parent.transform);
            itemGo.transform.position = parent.transform.position;
            itemGo.GetComponent <EquipItem>().SetInfo(info);
            plusProperty(id);
        }

        //UpdateProperty ();
        return(true);
    }
Exemplo n.º 12
0
    string GetDrugDis(int id)
    {
        objectInfo info = ObjectsInfo.instance.FindObjecInfoById(id);
        string     str  = "";

        str += "name:" + info.name + "\n";
        str += "HP:" + info.hp + "\n";
        str += "MP:" + info.mp + "\n";
        str += "出售价:" + info.price_sell + "\n";
        str += "购买价:" + info.price_buy + "\n";

        return(str);
    }
Exemplo n.º 13
0
    public void okbtn()
    {
        int        count       = int.Parse(buy_num.text);
        objectInfo info        = ObjectsInfo.instance.FindObjecInfoById(buy_id);
        int        price       = info.price_buy;
        int        price_total = price * count;
        bool       success     = EquipAndBag.instance.getCoin(price_total);

        if (success)
        {
            if (count > 0)
            {
                EquipAndBag.instance.getId(buy_id, count);
            }
        }
    }
Exemplo n.º 14
0
    public void showDis(int id)
    {
        this.gameObject.SetActive(true);
        objectInfo info = ObjectsInfo.instance.FindObjecInfoById(id);
        string     des  = "";

        switch (info.type)
        {
        case objectType.Drug:
            des = GetDrugDis(id);
            break;

        case objectType.Equip:
            des = GetEquipDis(id);
            break;
        }
        this.GetComponent <Text> ().text = des;
    }
Exemplo n.º 15
0
 public void setId(int id)
 {
     setProperty();
     this.id = id;
     info    = ObjectsInfo.instance.FindObjecInfoById(id);
     iconname_sprite.sprite = Resources.Load("Icon/" + info.icon_name, typeof(Sprite)) as Sprite;
     name_text.text         = info.name;
     if (info.attack > 0)
     {
         effect_text.text = "+伤害" + info.attack;
     }
     else if (info.def > 0)
     {
         effect_text.text = "+防御" + info.def;
     }
     else if (info.speed > 0)
     {
         effect_text.text = "+速度" + info.speed;
     }
     price_text.text = info.price_buy.ToString();
 }
Exemplo n.º 16
0
    private IEnumerator delay()
    {
        float timer = resetTimer;

        while (timer > 0)
        {
            timer -= Time.deltaTime;
            yield return(null);
        }
        for (int i = 0; i < spawnAmount; i++)
        {
            isMovingUp = 0;
            GameObject instance = Spawn(returnRandomPos(mainX), returnRandomPos(mainZ)
                                        , isMovingUp, returnRandomObject(powerUps));
            objectInfo prop = instance.AddComponent <objectInfo>();
            instance        = null;
            prop.isMovingUp = isMovingUp;
            prop.speed      = powerUpSpeed;
            prop            = null;
        }

        Loop();
    }
Exemplo n.º 17
0
    public void UseDrug()
    {
        if (id == 0)
        {
            return;
        }
        int hp = obinfo.hp;
        int mp = obinfo.mp;

        ps.GetDrug(hp, mp);
        count--;
        if (count <= 0)
        {
            count_text.gameObject.SetActive(false);
            this.id            = 0;
            this.obinfo        = null;
            img.overrideSprite = null;
            type = ShortCutType.None;
        }
        else
        {
            count_text.text = count.ToString();
        }
    }
Exemplo n.º 18
0
    public void read()
    {
        string text = objectInfoList.text;

        string[] str = text.Split('\n');
        foreach (string array in str)
        {
            objectInfo info      = new objectInfo();
            string[]   s         = array.Split(',');
            int        id        = int.Parse(s[0]);
            string     name      = s [1];
            string     icon_name = s [2];
            string     str_type  = s [3];
            objectType type      = objectType.Drug;
            switch (str_type)
            {
            case "Drug":
                type = objectType.Drug;
                break;

            case "Equip":
                type = objectType.Equip;
                break;

            case "Mat":
                type = objectType.Mat;
                break;
            }

            info.id        = id;
            info.name      = name;
            info.icon_name = icon_name;
            info.type      = type;

            if (type == objectType.Drug)
            {
                int hp         = int.Parse(s [4]);
                int mp         = int.Parse(s [5]);
                int price_sell = int.Parse(s [6]);
                int price_buy  = int.Parse(s [7]);

                info.hp         = hp;
                info.mp         = mp;
                info.price_sell = price_sell;
                info.price_buy  = price_buy;
            }
            else if (type == objectType.Equip)
            {
                info.attack     = int.Parse(s[4]);
                info.def        = int.Parse(s[5]);
                info.speed      = int.Parse(s[6]);
                info.price_sell = int.Parse(s[9]);
                info.price_buy  = int.Parse(s[10]);
                string str_dresstype = s[7];
                switch (str_dresstype)
                {
                case "Headgear":
                    info.dressType = DressType.Headgear;
                    break;

                case "Armor":
                    info.dressType = DressType.Armor;
                    break;

                case "LeftHand":
                    info.dressType = DressType.LeftHand;
                    break;

                case "RightHand":
                    info.dressType = DressType.RightHand;
                    break;

                case "Shoe":
                    info.dressType = DressType.Shoe;
                    break;

                case "Accessory":
                    info.dressType = DressType.Accessory;
                    break;
                }
                string str_apptype = s[8];
                switch (str_apptype)
                {
                case "Swordman":
                    info.applicationType = ApplicationType.Swordman;
                    break;

                case "Magician":
                    info.applicationType = ApplicationType.Magician;
                    break;

                case "Common":
                    info.applicationType = ApplicationType.Common;
                    break;
                }
            }
            objectInfoDic.Add(id, info);
        }
    }
Exemplo n.º 19
0
 public void SetInfo(objectInfo info)
 {
     this.id            = info.id;
     img                = this.GetComponent <Image> ();
     img.overrideSprite = Resources.Load("Icon/" + info.icon_name, typeof(Sprite)) as Sprite;
 }
Exemplo n.º 20
0
 public void SetId(int id)
 {
     this.id = id;
     objectInfo info = ObjectsInfo.instance.FindObjecInfoById(id);
 }
Exemplo n.º 21
0
    public void spawn(Vector3 position, Vector3Int chunk, int index)
    {
        VoxelObj obj;

        Debug.Log("hello");
        if (index >= 0)
        {
            obj = objDict[chunk][index];
        }
        else
        {
            //System.Random random = new System.Random();
            VoxelObj temp = objects[0];
            //Debug.Log(UnityEngine.Random.Range(0,objects.Count));

            obj = new VoxelObj(temp.vSize, (Voxel[])temp.voxels.Clone());
            //obj.voxels = temp.voxels;
            //obj.vSize = temp.vSize;
        }

        Marching marching = new MarchingCubes();

        marching.Surface = 0;
        float[] vox = new float[obj.voxels.Length];
        for (int i = 0; i < obj.voxels.Length; i++)
        {
            vox[i] = obj.voxels[i].value;
        }
        int ind;

        if (objDict.ContainsKey(chunk))
        {
            if (objDict[chunk].Count > index && index >= 0)
            {
                objDict[chunk][index] = obj;
                ind = index;
            }
            else
            {
                objDict[chunk].Add(obj);
                ind = objDict[chunk].Count - 1;
            }
        }
        else
        {
            objDict.Add(chunk, new List <VoxelObj>());
            objDict[chunk].Add(obj);
            ind = objDict[chunk].Count - 1;
        }

        List <Vector3> verts   = new List <Vector3>();
        List <int>     indices = new List <int>();

        marching.Generate(vox, obj.vSize.x, obj.vSize.y, obj.vSize.z, verts, indices);
        //Debug.Log(obj.voxels.Length);
        List <List <int> > subIndices = new List <List <int> >()
        {
            indices
        };
        Action action = () => {
            GameObject g  = meshGeneration.genMesh(verts, subIndices, materials, transform);
            objectInfo oI = g.AddComponent <objectInfo>();
            oI.index = ind;
            oI.chunk = chunk;

            g.transform.localPosition = position;
            if (!meshes.ContainsKey(chunk))
            {
                meshes.Add(chunk, new List <GameObject>());
            }
            if (meshes[chunk].Count > ind)
            {
                Destroy(meshes[chunk][ind]);
                meshes[chunk][ind] = g;
            }
            else
            {
                meshes[chunk].Add(g);
            }
            //Debug.Log("hello");
        };

        actions.Add(action);
    }
Exemplo n.º 22
0
    string GetEquipDis(int id)
    {
        objectInfo info = ObjectsInfo.instance.FindObjecInfoById(id);
        string     str  = "";

        str += "name:" + info.name + "\n";
        switch (info.dressType)
        {
        case DressType.Headgear:
            str += "穿戴类型:头盔\n";
            break;

        case DressType.Armor:
            str += "穿戴类型:盔甲\n";
            break;
            break;

        case DressType.LeftHand:
            str += "穿戴类型:左手\n";
            break;
            break;

        case DressType.RightHand:
            str += "穿戴类型:右手\n";
            break;
            break;

        case DressType.Shoe:
            str += "穿戴类型:鞋\n";
            break;
            break;

        case DressType.Accessory:
            str += "穿戴类型:饰品\n";
            break;
        }

        switch (info.applicationType)
        {
        case ApplicationType.Swordman:
            str += "适用类型:剑士\n";
            break;

        case ApplicationType.Magician:
            str += "适用类型:魔法师\n";
            break;

        case ApplicationType.Common:
            str += "适用类型:通用\n";
            break;
        }

        str += "伤害值:" + info.attack + "\n";
        str += "防御值:" + info.def + "\n";
        str += "速度值:" + info.speed + "\n";


        str += "出售价:" + info.price_sell + "\n";
        str += "购买价:" + info.price_buy + "\n";

        return(str);
    }