示例#1
0
 public void settrap(string str)
 {
     string[] arr1 = str.Split('t');
     trapList = new List <TrapVo>(arr1.Length);
     for (int i = 0; i < arr1.Length; i++)
     {
         string[] arr = arr1[i].Split('=');
         if (arr[0] == "1")
         {
             TrapDoor trap = new TrapDoor();
             trap.type = 1;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "2")
         {
             MonsterRefreshVo trap = new MonsterRefreshVo();
             trap.type = 2;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "3")
         {
             AtkOffice trap = new AtkOffice();
             trap.type = 3;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "4")
         {
             CubeTrap trap = new CubeTrap();
             trap.type = 4;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "5")
         {
             Transfer trap = new Transfer();
             trap.type = 5;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "6")
         {
             TrapLandmine trap = new TrapLandmine();
             trap.type = 6;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "7")
         {
             TrapSpring trap = new TrapSpring();
             trap.type = 7;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
     }
 }
示例#2
0
    public void deleteMonster(GameObject g)
    {
        MonsterRefreshVo trapvo = trapDataObject[g] as MonsterRefreshVo;

        trapvo.curLiveEnemy--;
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        foreach (GameObject trapobj in trapDataObject.Keys)
        {
            TrapVo trap = trapDataObject[trapobj];
            if (trap.type == 2)
            {
                MonsterRefreshVo trapvo = trap as MonsterRefreshVo;
                if (trapvo.curLiveEnemy < trapvo.maxLiveEnemy)
                {
                    trapvo.currefreshindex++;
                    if (trapvo.currefreshindex >= trapvo.refreshCD * 5)
                    {
                        trapvo.curLiveEnemy++;
                        Notice.EnemyCreat.broadcast("", trapObject[trap.id]);
                        trapvo.currefreshindex = 0;
                    }
                }
            }
            else if (trap.type == 3)
            {
                AtkOffice trapvo = trap as AtkOffice;
                trapvo.curcd++;
                if (trapvo.curcd >= trapvo.atkCD)
                {
                    trapvo.curcd = 0;

                    GameObject obj = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/ShootCollisoon 1"), trapObject[trap.id].transform.position, trapObject[trap.id].transform.rotation);
                    obj.tag = "trap";
                    obj.GetComponent <ShootCollisoon>().initdata(trapvo.rang / trapvo.speed);
                    obj.transform.Translate(new Vector3(0, 0.5f, 0));
                    obj.GetComponent <Rigidbody>().AddForce(obj.transform.forward * 1000);
                    obj.transform.SetParent(trapObject[trap.id].transform);
                }
            }
            else if (trap.type == 7)
            {
                TrapSpring trapvo = trap as TrapSpring;
                if (trapvo.isshrink)
                {
                    //Debug.Log(trapvo.curRange);
                    trapvo.curRange -= 0.5f;
                    if (trapvo.curRange <= 0)
                    {
                        foreach (Transform child in trapobj.transform)
                        {
                            if (child.GetComponent <TrapCollisoon>())
                            {
                                if (child.GetComponent <TrapCollisoon>().use == "trigger")
                                {
                                    // Destroy(child.gameObject);
                                }
                                else
                                {
                                    trapvo.isshrink = false;
                                    trapvo.curRange = -1;
                                    Destroy(child.gameObject);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (Transform child in trapobj.transform)
                        {
                            if (child.GetComponent <TrapCollisoon>())
                            {
                                if (child.GetComponent <TrapCollisoon>().use == "trigger")
                                {
                                    // Destroy(child.gameObject);
                                }
                                else
                                {
                                    child.transform.localScale = new Vector3(trapvo.curRange, 0.1f, 1);
                                    child.transform.Translate(new Vector3(0.25f, 0, 0));
                                }
                            }
                        }
                    }
                }
                else if (trapvo.curRange != -1)
                {
                    if (trapvo.curRange < trapvo.range)
                    {
                        trapvo.curRange += 0.5f;
                        foreach (Transform child in trapobj.transform)
                        {
                            if (child.GetComponent <TrapCollisoon>())
                            {
                                if (child.GetComponent <TrapCollisoon>().use == "trigger")
                                {
                                    // Destroy(child.gameObject);
                                }
                                else
                                {
                                    child.transform.localScale = new Vector3(trapvo.curRange, 0.1f, 1);
                                    child.transform.Translate(new Vector3(-0.25f, 0, 0));
                                }
                            }
                        }
                    }
                    else
                    {
                        trapvo.isshrink = true;
                    }
                }
            }
        }
    }
示例#4
0
    public void inittrap(List <TrapVo> list)
    {
        for (int i = 0; i < list.Count; i++)
        {
            list[i].id = nextTrapId;
            nextTrapId++;
            if (list[i].type == 1)
            {
                TrapDoor trap = list[i] as TrapDoor;
                trap.curLiveEnemy = 0;
                GameObject obj = GameObject.Instantiate(trapListPre[0], trap.v3, trapListPre[0].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
                if (trap.triggerPList.Count > 0)
                {
                    obj.transform.Translate(new Vector3(0, -50, 0));
                }

                for (int j = 0; j < trap.triggerPList.Count; j++)
                {
                    GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.triggerPList[j], placeGameObject.transform.rotation);
                    obj1.transform.localScale = trap.triggerRList[j];
                    obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                    obj1.GetComponent <TrapCollisoon>().type = 1;
                    obj1.GetComponent <TrapCollisoon>().use  = "trigger";
                    obj1.transform.SetParent(obj.transform);
                }

                for (int j = 0; j < trap.clearPList.Count; j++)
                {
                    GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.clearPList[j], placeGameObject.transform.rotation);
                    obj1.transform.localScale = trap.clearRList[j];
                    obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                    obj1.GetComponent <TrapCollisoon>().type = 1;
                    obj1.GetComponent <TrapCollisoon>().use  = "clear";
                    obj1.transform.SetParent(obj.transform);
                }
                updataTrap(nextTrapId - 1);
            }
            else if (list[i].type == 2)
            {
                MonsterRefreshVo trap = list[i] as MonsterRefreshVo;
                trap.curLiveEnemy    = 0;
                trap.currefreshindex = 0;
                GameObject obj = GameObject.Instantiate(trapListPre[1], trap.v3, trapListPre[1].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
            }
            else if (list[i].type == 3)
            {
                AtkOffice  trap = list[i] as AtkOffice;
                GameObject obj  = GameObject.Instantiate(trapListPre[2], trap.v3, trapListPre[1].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
            }
            else if (list[i].type == 4)
            {
                CubeTrap   trap = list[i] as CubeTrap;
                GameObject obj  = GameObject.Instantiate(placeGameObject, trap.v3, trapListPre[1].transform.rotation);
                obj.transform.localScale = trap.sv3;
                obj.GetComponent <TrapCollisoon>().id   = list[i].id;
                obj.GetComponent <TrapCollisoon>().type = 4;
                obj.GetComponent <TrapCollisoon>().use  = "atk" + trap.AtkType;
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
            }
            else if (list[i].type == 5)
            {
                Transfer   trap = list[i] as Transfer;
                GameObject obj  = GameObject.Instantiate(trapListPre[3], trap.v3, trapListPre[3].transform.rotation);
                obj.AddComponent <TrapCollisoon>().id   = list[i].id;
                obj.GetComponent <TrapCollisoon>().type = 5;
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);

                GameObject obj1 = GameObject.Instantiate(trapListPre[3], trap.tv3, trapListPre[3].transform.rotation);
                obj1.AddComponent <TrapCollisoon>().id   = list[i].id;
                obj1.GetComponent <TrapCollisoon>().type = 5;
                obj1.transform.SetParent(obj.transform);
            }
            else if (list[i].type == 6)
            {
                TrapLandmine trap = list[i] as TrapLandmine;
                trap.curLiveEnemy = 0;
                GameObject obj = GameObject.Instantiate(trapListPre[5], trap.v3, trapListPre[0].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);


                for (int j = 0; j < trap.triggerPList.Count; j++)
                {
                    GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.triggerPList[j], placeGameObject.transform.rotation);
                    obj1.transform.localScale = trap.triggerRList[j];
                    obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                    obj1.GetComponent <TrapCollisoon>().type = 6;
                    obj1.GetComponent <TrapCollisoon>().use  = "trigger";
                    obj1.transform.SetParent(obj.transform);
                }


                // updataTrap(nextTrapId - 1);
            }
            else if (list[i].type == 7)
            {
                TrapSpring trap = list[i] as TrapSpring;
                GameObject obj  = GameObject.Instantiate(trapListPre[5], trap.v3, trapListPre[0].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);

                GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.v3, placeGameObject.transform.rotation);
                obj1.transform.localScale = new Vector3(trap.range, 0.1f, 1);
                obj1.transform.Translate(new Vector3(-trap.range / 2 + .5f, 0, 0));
                obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                obj1.GetComponent <TrapCollisoon>().type = 7;
                obj1.GetComponent <TrapCollisoon>().use  = "trigger";
                obj1.transform.SetParent(obj.transform);

                obj.transform.Rotate(0, trap.rotiony, 0);


                Debug.Log(trap.rotiony);
            }
        }
        //Timer time = new Timer(13, () => { Debug.Log("alwaysDo");
        // }, () => { Debug.Log("stopTimer1")};
    }