Esempio n. 1
0
 public void RemoveColors(BtnColor btn)
 {
     if (BtnColors.Contains(btn))
     {
         BtnColors.Remove(btn);
     }
 }
Esempio n. 2
0
 private void Start()
 {
     mMapCtrl = this.transform.root.Find("Eniroment").GetComponent <MapCtrl>();
     Shadow   = this.transform.parent.Find("Shadow");
     SetShadowActive();
     btn = this.transform.GetComponent <BtnColor>();
 }
Esempio n. 3
0
 private void SetNeedNoBgActive(BtnColor btn)
 {
     if (btn == null)
     {
         return;
     }
     if (btn.maps.Count == 0)
     {
         return;
     }
     if (btn.BtnPath.Count == 1)
     {
         for (int i = 0; i < btn.maps.Count; i++)
         {
             btn.maps[i].GameOne.transform.Find("Trail").gameObject.SetActive(false);
             btn.maps[i].GameOne.transform.Find("BgMapOne").gameObject.SetActive(false);
         }
         btn.maps.Clear();
     }
     else
     {
         List <MapOne> need = GetNeedToNoActive(btn.maps, btn.BtnPath);
         if (need != null)
         {
             foreach (MapOne map in need)
             {
                 map.GameOne.transform.Find("BgMapOne").gameObject.SetActive(false);
             }
         }
     }
 }
Esempio n. 4
0
    public void GetHasPathToOther(BtnColor btn)
    {
        if (btn == null)
        {
            return;
        }
        BtnColor kes = null;

        for (int i = 0; i < BtnColors.Count; i++)
        {
            if (btn != BtnColors[i] && btn.mTargetBtnColor != BtnColors[i])
            {
                for (int j = 0; j < btn.BtnPath.Count; j++)
                {
                    kes = GetBtnForPath(btn.BtnPath[j], btn);
                    if (kes != null)
                    {
                        int remove = kes.BtnPath.IndexOf(btn.BtnPath[j]);
                        kes.BtnPath.RemoveRange(remove, kes.BtnPath.Count - remove);
                        kes.IsFinished = false;
                        kes.mTargetBtnColor.IsFinished = false;
                    }
                }
            }
        }
    }
Esempio n. 5
0
 public void AddColors(BtnColor btn)
 {
     if (BtnColors.Contains(btn))
     {
         return;
     }
     BtnColors.Add(btn);
 }
Esempio n. 6
0
    private void SetBtnPathToMapone(Vector2 Dir, MapOne go, BtnColor btn)
    {
        GameObject mgo = go.GameOne.transform.Find("Trail").gameObject;

        if (Dir.x == 1)
        {
            mgo.GetComponent <SpriteRenderer>().sprite = levelSys.GetTraillSprite(btn.name);
            mgo.transform.localPosition    = new Vector3(0.5f, 0f, 0);
            mgo.transform.localEulerAngles = new Vector3(0, 0, 0);
            mgo.transform.localScale       = new Vector3(4.45f, 0.7f, 1);
            mgo.SetActive(true);
            if (btn.PathActives.Count == 0)
            {
                btn.AddPathActive(btn.BtnPath[0]);
            }
            btn.AddPathActive(go);
        }
        else if (Dir.x == -1)
        {
            mgo.GetComponent <SpriteRenderer>().sprite = levelSys.GetTraillSprite(btn.name);
            mgo.transform.localPosition    = new Vector3(-0.5f, 0, 0);
            mgo.transform.localScale       = new Vector3(4.45f, 0.7f, 1);
            mgo.transform.localEulerAngles = new Vector3(0, 0, 0);
            mgo.SetActive(true);
            if (btn.PathActives.Count == 0)
            {
                btn.AddPathActive(btn.BtnPath[0]);
            }
            btn.AddPathActive(go);
        }
        else if (Dir.y == 1)
        {
            mgo.GetComponent <SpriteRenderer>().sprite = levelSys.GetTraillSprite(btn.name);
            mgo.transform.localPosition    = new Vector3(0, 0.5f, 0);
            mgo.transform.localScale       = new Vector3(4.45f, 0.7f, 1);
            mgo.transform.localEulerAngles = new Vector3(0, 0, 90);
            mgo.SetActive(true);
            if (btn.PathActives.Count == 0)
            {
                btn.AddPathActive(btn.BtnPath[0]);
            }
            btn.AddPathActive(go);
        }
        else if (Dir.y == -1)
        {
            mgo.GetComponent <SpriteRenderer>().sprite = levelSys.GetTraillSprite(btn.name);
            mgo.transform.localPosition    = new Vector3(0, -0.5f, 0);
            mgo.transform.localScale       = new Vector3(4.45f, 0.7f, 1);
            mgo.transform.localEulerAngles = new Vector3(0, 0, 90);
            mgo.SetActive(true);
            if (btn.PathActives.Count == 0)
            {
                btn.AddPathActive(btn.BtnPath[0]);
            }
            btn.AddPathActive(go);
        }
    }
Esempio n. 7
0
 private void OnMouseUp()
 {
     if (btnColor == null)
     {
         return;
     }
     btnColor.GetComponent <BtnColorDrag>().SetShadowActive();
     shadow   = null;
     btnColor = null;
 }
Esempio n. 8
0
 public BtnColor GetBtnForPath(MapOne mapOne, BtnColor Btn)
 {
     foreach (BtnColor btn in BtnColors)
     {
         if (btn.BtnPath.Contains(mapOne) && Btn != btn && Btn.mTargetBtnColor != btn)
         {
             return(btn);
         }
     }
     return(null);
 }
Esempio n. 9
0
    private void SetBgPathToMaps(BtnColor btn)
    {
        Color col = btn.mColorGame.transform.parent.Find("Shadow").GetComponent <SpriteRenderer>().color;

        foreach (MapOne map in btn.BtnPath)
        {
            GameObject go = map.GameOne.transform.Find("BgMapOne").gameObject;
            go.SetActive(true);
            go.GetComponent <SpriteRenderer>().color = col;
            btn.AddMapPath(map);
        }
    }
Esempio n. 10
0
 public void SetAllNOActives(BtnColor btn)
 {
     for (int i = 0; i < btn.PathActives.Count; i++)
     {
         btn.PathActives[i].GameOne.transform.Find("Trail").gameObject.SetActive(false);
         btn.PathActives[i].GameOne.transform.Find("BgMapOne").gameObject.SetActive(false);
     }
     btn.PathActives.Clear();
     for (int i = 0; i < btn.maps.Count; i++)
     {
         btn.maps[i].GameOne.transform.Find("Trail").gameObject.SetActive(false);
         btn.maps[i].GameOne.transform.Find("BgMapOne").gameObject.SetActive(false);
     }
     btn.maps.Clear();
 }
Esempio n. 11
0
 public bool isHas(List <MapOne> maps, BtnColor btn)
 {
     foreach (MapOne one in maps)
     {
         if (one == maps[maps.Count - 1] || one == maps[0])
         {
             continue;
         }
         if (btn.BtnPath.Contains(one))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 12
0
    public BtnColor SetBtnInfo(int x1, int y1, string a)
    {
        GameObject go  = Resources.Load <GameObject>(@"Prefabs\BtnColor\" + a.ToString());
        Transform  go1 = transform.GetChild(x1).GetChild(y1);

        go1.GetComponent <SpriteRenderer>().DOFade(0, 0.01f);
        mapCtrl.GetMapOne(x1, y1).IsObstacle = true;
        GameObject go3 = Instantiate(go);

        SetParentInit(go1, go3.transform);
        BtnColor BtnCol1 = go3.transform.GetChild(0).GetComponent <BtnColor>();

        BtnCol1.AddBtnPath(mapCtrl.GetMapOne((int)go1.position.x, (int)go1.position.y));
        BtnCol1.mColor = BtnCol1.GetComponent <SpriteRenderer>().color;
        mapCtrl.AddColors(BtnCol1);
        return(BtnCol1);
    }
Esempio n. 13
0
 public void SetColorPos()
 {
     mapCtrl.mBtnColors.Clear();
     foreach (string a in BtnInfo.Keys)
     {
         int      x1      = BtnInfo[a][0][0];
         int      y1      = BtnInfo[a][0][1];
         int      x2      = BtnInfo[a][1][0];
         int      y2      = BtnInfo[a][1][1];
         BtnColor BtnCol1 = SetBtnInfo(x1, y1, a);
         BtnColor BtnCol2 = SetBtnInfo(x2, y2, a);
         BtnCol1.mTargetBtnColor = BtnCol2;
         BtnCol2.mTargetBtnColor = BtnCol1;
         for (int i = 0; i < BtnInfo[a].Count; i++)
         {
             BtnCol1.AddHelpPath(mapCtrl.GetMapOne(BtnInfo[a][i][0], BtnInfo[a][i][1]));
         }
     }
 }
Esempio n. 14
0
    public void OnClickChange()
    {
        if (!GPUInstancingAnchor.gameObject.activeSelf)
        {
            isGPUInstancing = true;
            GPUInstancingAnchor.gameObject.SetActive(true);
            NormalAnchor.gameObject.SetActive(false);
        }
        else
        {
            isGPUInstancing = false;
            GPUInstancingAnchor.gameObject.SetActive(false);
            NormalAnchor.gameObject.SetActive(true);
        }

        RefreshStateTip();

        BtnAction.SetActive(isGPUInstancing);
        BtnColor.SetActive(isGPUInstancing);
    }
Esempio n. 15
0
    public int IndexMin(List <MapOne> maps, BtnColor btn)
    {
        int temp = 50;

        foreach (MapOne one in maps)
        {
            if (one == maps[maps.Count - 1])
            {
                break;
            }
            if (btn.BtnPath.Contains(one))
            {
                if (temp > btn.BtnPath.IndexOf(one))
                {
                    temp = btn.BtnPath.IndexOf(one);
                }
            }
        }
        return(temp);
    }
Esempio n. 16
0
 private void OnMouseDown()
 {
     if (btnColor == null)
     {
         foreach (BtnColor btn in mapCtrl.mBtnColors)
         {
             if (btn.BtnPath.Contains(Own))
             {
                 btnColor = btn;
             }
         }
     }
     if (btnColor != null)
     {
         shadow = btnColor.transform.parent.Find("Shadow").GetComponent <ShadowDrag>();
         Vector3 ShadowCurrentPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.touches[0].position.x,
                                                                               Input.touches[0].position.y, -Camera.main.transform.position.z));
         shadow.transform.position = ShadowCurrentPos;
         btnColor.GetComponent <BtnColorDrag>().SetShadowActive(true);
     }
 }
Esempio n. 17
0
 private void SetNeedNoActives(BtnColor btn)
 {
     if (btn == null)
     {
         return;
     }
     if (btn.PathActives.Count == 0)
     {
         return;
     }
     if (btn.BtnPath.Count == 1)
     {
         for (int i = 0; i < btn.PathActives.Count; i++)
         {
             btn.PathActives[i].GameOne.transform.Find("Trail").gameObject.SetActive(false);
             btn.PathActives[i].GameOne.transform.Find("BgMapOne").gameObject.SetActive(false);
         }
         btn.PathActives.Clear();
     }
     if ((btn.BtnPath.Count - 1) != btn.PathActives.Count)
     {
         for (int i = 0; i < btn.PathActives.Count; i++)
         {
             if (!btn.BtnPath.Contains(btn.PathActives[i]))
             {
                 btn.PathActives[i].GameOne.transform.Find("Trail").gameObject.SetActive(false);
             }
         }
         int order = btn.PathActives.IndexOf(btn.BtnPath[btn.BtnPath.Count - 2]);
         if (order != btn.PathActives.Count - 1)
         {
             for (int i = order + 1; i < btn.PathActives.Count; i++)
             {
                 btn.PathActives[i].GameOne.transform.Find("Trail").gameObject.SetActive(false);
             }
             btn.PathActives.RemoveRange(order + 1, btn.PathActives.Count - order - 1);
         }
     }
 }
Esempio n. 18
0
    public void SetTipPaht()
    {
        if (GoldSystem.Instance.GetGoldMount(0) < 5)
        {
            return;
        }
        GoldSystem.Instance.GetGoldMount(-5);
        View.Instance.GameUI.SetGoldCount();
        View.Instance.PlayUI.SetGoldCount();
        int rodom = UnityEngine.Random.Range(0, ks.Count);

        if (ks.Count == 0)
        {
            return;
        }
        BtnColor btn = BtnColors[ks[rodom]];

        ks.Remove(ks[rodom]);
        MapOne mapOne2 = btn.HelpPos[1];

        btn.HelpPos.RemoveAt(1);
        btn.AddHelpPath(mapOne2);
        if (btn.IsFinished)
        {
            bool          b      = true;
            List <MapOne> isTrue = new List <MapOne>();
            isTrue.Add(GetMapOne((int)btn.mPosition.x, (int)btn.mPosition.y));
            for (int i = 0; i < btn.HelpPos.Count - 1; i++)
            {
                Vector2 Path = btn.HelpPos[i + 1].mPosition - btn.HelpPos[i].mPosition;
                MapOne  one  = new MapOne();
                one.XPosition = -1;
                one.YPosition = -1;
                if (Path.x != 0)
                {
                    int d = (int)btn.HelpPos[i].XPosition;
                    while (one.XPosition != btn.HelpPos[i + 1].XPosition)
                    {
                        d  += (int)(Path.x / Mathf.Abs(Path.x));
                        one = GetMapOne(d, (int)btn.HelpPos[i].YPosition);
                        isTrue.Add(one);
                    }
                }
                else
                {
                    int c = (int)btn.HelpPos[i].YPosition;
                    while (one.YPosition != btn.HelpPos[i + 1].YPosition)
                    {
                        c  += (int)(Path.y / Mathf.Abs(Path.y));
                        one = GetMapOne((int)btn.HelpPos[i].XPosition, c);
                        isTrue.Add(one);
                    }
                }
            }
            if (isTrue.Count == btn.BtnPath.Count || isTrue.Count == btn.mTargetBtnColor.BtnPath.Count)
            {
                if (isTrue.Count == btn.BtnPath.Count)
                {
                    for (int i = 0; i < isTrue.Count; i++)
                    {
                        b = b && btn.BtnPath.Contains(isTrue[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < isTrue.Count; i++)
                    {
                        b = b && btn.mTargetBtnColor.BtnPath.Contains(isTrue[i]);
                    }
                }
            }
            else
            {
                b = false;
            }
            if (b)
            {
                isTrue.Clear();
                SetTipPaht();
                return;
            }
            b = true;
        }
        btn.PathActives.Clear();
        SetAllNOActives(btn);
        if (btn.BtnPath.Count != 1)
        {
            btn.BtnPath.RemoveRange(1, btn.BtnPath.Count - 1);
        }
        if (btn.mTargetBtnColor.BtnPath.Count != 1)
        {
            btn.mTargetBtnColor.BtnPath.RemoveRange(1, btn.mTargetBtnColor.BtnPath.Count - 1);
        }
        for (int i = 0; i < btn.HelpPos.Count - 1; i++)
        {
            Vector2 Path      = btn.HelpPos[i + 1].mPosition - btn.HelpPos[i].mPosition;
            float   XPosition = -1;
            float   YPosition = -1;
            if (Path.x != 0)
            {
                int d = (int)btn.HelpPos[i].XPosition;
                while (XPosition != btn.HelpPos[i + 1].XPosition)
                {
                    d        += (int)(Path.x / Mathf.Abs(Path.x));
                    XPosition = GetMapOne(d, (int)btn.HelpPos[i].YPosition).XPosition;
                    btn.AddBtnPath(GetMapOne(d, (int)btn.HelpPos[i].YPosition));
                }
            }
            else
            {
                int c = (int)btn.HelpPos[i].YPosition;
                while (YPosition != btn.HelpPos[i + 1].YPosition)
                {
                    c        += (int)(Path.y / Mathf.Abs(Path.y));
                    YPosition = GetMapOne((int)btn.HelpPos[i].XPosition, c).YPosition;
                    btn.AddBtnPath(GetMapOne((int)btn.HelpPos[i].XPosition, c));
                }
            }
        }
        btn.GetComponent <BoxCollider2D>().enabled = false;
        btn.mTargetBtnColor.GetComponent <BoxCollider2D>().enabled = false;
        GetHasPathToOther(btn);
        btn.IsFinished = true;
        btn.transform.Find("HelpUI").gameObject.SetActive(true);
        btn.mTargetBtnColor.IsFinished = true;
        btn.mTargetBtnColor.transform.Find("HelpUI").gameObject.SetActive(true);
        btn.maps = btn.BtnPath;
        foreach (MapOne one in btn.BtnPath)
        {
            one.GameOne.transform.Find("TrailDrag").GetComponent <BoxCollider2D>().enabled = false;
            one.IsObstacle = true;
            if (btn.BtnPath[btn.BtnPath.Count - 1] != one)
            {
                btn.AddPathActive(one);
            }
        }
        source.clip = AutoLine;
        source.Play();
        View.Instance.GameUI.SetFootCountTxt();
    }
Esempio n. 19
0
    private void Update()
    {
        int x  = (int)Math.Round(this.transform.position.x);
        int y  = (int)Math.Round(this.transform.position.y);
        int x1 = (int)Math.Round(this.transform.position.x) - (int)transform.parent.parent.position.x;
        int y1 = (int)Math.Round(this.transform.position.y) - (int)transform.parent.parent.position.y;

        if (Mathf.Abs(x1) >= 0 || Mathf.Abs(y1) >= 0)
        {
            MapOne   TargetOne  = mapCtrl.GetMapOne(x, y);
            BtnColor currentBtn = this.transform.parent.GetChild(0).GetComponent <BtnColor>();
            if (x >= LevelCreateSys.Col || y >= LevelCreateSys.Row || x < 0 || y < 0)
            {
                return;
            }
            if (TargetOne.IsObstacle == false || currentBtn.mTargetBtnColor.mPosition == new Vector2(x, y) || TargetOne.mPosition == currentBtn.mPosition)
            {
                if (TargetOne == currentBtn.BtnPath[currentBtn.BtnPath.Count - 1])
                {
                    return;
                }
                else
                {
                    if (!currentBtn.IsFinished && !(kk == x1 && xx == y1))
                    {
                        mapCtrl.source.clip = mapCtrl.mButton;
                        mapCtrl.source.Play();
                        kk = x1;
                        xx = y1;
                    }
                }

                BtnColor TragetBtn = mapCtrl.GetBtnForPath(TargetOne, currentBtn);
                if (TragetBtn != null)
                {
                    TragetBtn.IsFinished = false;
                    TragetBtn.mTargetBtnColor.IsFinished = false;
                    int remove = TragetBtn.BtnPath.IndexOf(TargetOne);
                    TragetBtn.BtnPath.RemoveRange(remove, TragetBtn.BtnPath.Count - remove);
                }
                else
                {
                    mapCtrl.GetHasPathToOther(currentBtn);
                }
                //判断是否可以继续运动,如果按钮的状态没有完成则无法运动
                if (currentBtn.IsFinished)
                {
                    if (!currentBtn.BtnPath.Contains(TargetOne))
                    {
                        return;
                    }
                    else
                    {
                        currentBtn.IsFinished = false;
                    }
                    currentBtn.mTargetBtnColor.IsFinished = false;
                }
                //判断 当前路线是否重合,重合整理路线
                if (currentBtn.BtnPath.Contains(TargetOne))
                {
                    if (currentBtn.BtnPath.Count != 1)
                    {
                        int remove = currentBtn.BtnPath.IndexOf(TargetOne);
                        currentBtn.BtnPath.RemoveRange(remove + 1, currentBtn.BtnPath.Count - remove - 1);
                    }
                }
                else
                {
                    currentBtn.AddBtnPath(TargetOne);
                    int   Count = currentBtn.BtnPath.Count;
                    float xoff  = Math.Abs(currentBtn.BtnPath[Count - 1].XPosition - currentBtn.BtnPath[Count - 2].XPosition);
                    float yoff  = Math.Abs(currentBtn.BtnPath[Count - 1].YPosition - currentBtn.BtnPath[Count - 2].YPosition);
                    //判断当前运动的位置是否发生大规模运动
                    if (xoff + yoff != 1)
                    {
                        //ToDo 高速度的响应解决方案  --->
                        currentBtn.BtnPath[currentBtn.BtnPath.Count - 2].GameOne.transform.GetChild(2).gameObject.SetActive(false);
                        List <MapOne> a1 = new List <MapOne>();
                        if (currentBtn.mTargetBtnColor.mPosition == TargetOne.mPosition)
                        {
                            TargetOne.IsObstacle = false;
                            mapCtrl.GetMapOne((int)currentBtn.mPosition.x, (int)currentBtn.mPosition.y).IsObstacle = false;
                            a1 = AStart.GetInstance.GetPath
                                     (mapCtrl.GetMapOne((int)currentBtn.BtnPath[Count - 2].XPosition, (int)currentBtn.BtnPath[Count - 2].YPosition),
                                     TargetOne);
                            TargetOne.IsObstacle = true;
                        }
                        else
                        {
                            mapCtrl.GetMapOne((int)currentBtn.mPosition.x, (int)currentBtn.mPosition.y).IsObstacle = false;
                            a1 = AStart.GetInstance.GetPath
                                     (mapCtrl.GetMapOne((int)currentBtn.BtnPath[Count - 2].XPosition, (int)currentBtn.BtnPath[Count - 2].YPosition),
                                     TargetOne);
                        }
                        mapCtrl.GetMapOne((int)currentBtn.mPosition.x, (int)currentBtn.mPosition.y).IsObstacle = true;
                        if (a1 == null || a1.Count == 0)
                        {
                            currentBtn.BtnPath.Remove(TargetOne); return;
                        }
                        else
                        {
                            if (isHas(a1, currentBtn))
                            {
                                int index = IndexMin(a1, currentBtn);
                                currentBtn.BtnPath.RemoveRange(index + 1, currentBtn.BtnPath.Count - index - 1);
                                foreach (MapOne cc in a1)
                                {
                                    int cx     = a1.IndexOf(cc);
                                    int insert = a1.IndexOf(currentBtn.BtnPath[index]);
                                    if (cx == 0 || cx == a1.Count - 1)
                                    {
                                        continue;
                                    }
                                    if (a1.IndexOf(cc) <= insert)
                                    {
                                        int Inde = insert - cx;
                                        currentBtn.BtnPath.Add(a1[Inde]);
                                    }
                                }
                            }
                            else
                            {
                                foreach (MapOne c in a1)
                                {
                                    if (c == a1[a1.Count - 1] || c == a1[0])
                                    {
                                        continue;
                                    }
                                    if (c == a1[a1.Count - 1] && c == a1[0])
                                    {
                                        continue;
                                    }
                                    int index = a1.Count - a1.IndexOf(c) - 1;
                                    currentBtn.BtnPath.Insert(currentBtn.BtnPath.Count - 1, a1[index]);
                                }
                            }
                        }
                        mapCtrl.GetHasPathToOther(currentBtn);
                    }
                }
                if (currentBtn.mTargetBtnColor.mPosition == new Vector2(x, y))
                {
                    View.Instance.GameUI.SetFootCountTxt();
                    currentBtn.IsFinished = true;
                    currentBtn.mTargetBtnColor.IsFinished = true;
                    if (currentBtn.mColorGame.transform.Find("HelpUI").gameObject.activeSelf == false)
                    {
                        mapCtrl.source.clip = mapCtrl.Winline;
                        mapCtrl.source.Play();
                    }
                }
                if (currentBtn.BtnPath.Count >= 2)
                {
                    MapOne one;
                    for (int i = 0; i < currentBtn.BtnPath.Count - 1; i++)
                    {
                        Vector2 ks = currentBtn.BtnPath[i + 1].mPosition - currentBtn.BtnPath[i].mPosition;
                        if (ks.x + ks.y > 1)
                        {
                            one = currentBtn.BtnPath[i + 1];
                            currentBtn.BtnPath.RemoveRange(i + 1, currentBtn.BtnPath.Count - i - 1);
                        }
                    }
                }
            }
        }
    }