Esempio n. 1
0
    /*
     * void Update ()
     * {
     *  Debug.DrawRay(forwardRay.position, forwardRay.forward * 1.0f, Color.green);
     *
     *  RaycastHit hitObject;
     *
     *  if (Physics.Raycast(forwardRay.position, forwardRay.forward, out hitObject, rayLength))
     *  {
     *      if (hitObject.transform.tag == "Stepping")
     *      {
     *          SteppingController steppingScript = hitObject.transform.GetComponent<SteppingController>();
     *
     *          if (steppingScript.isWarning)
     *          {
     *              ifnotstepping = true;
     *              //Debug.Log("ifnotstepping");
     *          }
     *          else
     *          {
     *              ifnotstepping = false;
     *              //Debug.Log("ifstepping");
     *          }
     *      }
     *      else if (hitObject.transform.tag == "SteppingStone")
     *      {
     *          ifnotstepping = false;
     *      }
     *      else if (hitObject.transform.tag == "Track")
     *      {
     *          TrainController trainScript = hitObject.transform.FindChild("Train").GetComponent<TrainController>();
     *
     *          if (trainScript.isRedlight)
     *          {
     *              ifnotred = false;
     *          }
     *          else
     *          {
     *              ifnotred = true;
     *          }
     *      }
     *  }
     *  else
     *  {
     *      ifnotstepping = true;
     *      ifnotred = true;
     *  }
     *
     * }
     */

    // 명령어 입력 시 명령어 표시창에 선택된 명령어를 표시해준다.
    void DrawButton()
    {
        GameObject btnIns;

        if (scriptList[scriptList.Count - 1].direction == direction.up)
        {
            btnIns = Instantiate(UpBtn, QueuePanel.transform) as GameObject;
        }
        else if (scriptList[scriptList.Count - 1].direction == direction.down)
        {
            btnIns = Instantiate(DownBtn, QueuePanel.transform) as GameObject;
        }
        else if (scriptList[scriptList.Count - 1].direction == direction.left)
        {
            btnIns = Instantiate(LeftBtn, QueuePanel.transform) as GameObject;
        }
        else if (scriptList[scriptList.Count - 1].direction == direction.right)
        {
            btnIns = Instantiate(RightBtn, QueuePanel.transform) as GameObject;
        }
        else// (scriptList[scriptList.Count - 1].direction == direction.stop)
        {
            btnIns = Instantiate(StopBtn, QueuePanel.transform) as GameObject;
        }

        RectTransform rt = btnIns.GetComponent <RectTransform>();

        rt.anchoredPosition = new Vector2((scriptList.Count - 1) * 208 - 416, 0);
        if (scriptList[scriptList.Count - 1].ifType != ifType.None)
        {
            rt.sizeDelta *= 0.9f;
        }

        // 생성된 버튼에 몇번 째 명령어인지 데이터 기록
        UserScriptInfo info = scriptList[scriptList.Count - 1];

        scriptList[info.index].clonedBtn = btnIns;

        // 입력된 Move명령어에 대해 눌렀을 시 삭제되는 터치 이벤트를 붙인다
        btnIns.GetComponent <Button>().onClick.AddListener(() =>
        {
            if (isPlaying)
            {
                return;
            }

            // 현재 이프문 편집 중인데 이프문 바깥의 스크립트 삭제할 경우엔 편집중이던 이프 블록 펑~
            if (curIfMode != ifType.None && info.belongingIfBlock != ifBtnList[ifBtnList.Count - 1])
            {
                int repeatAmount = scriptList.Count;
                for (int k = repeatAmount - 1; k >= 0; k--)
                {
                    if (scriptList[k].belongingIfBlock == ifBtnList[ifBtnList.Count - 1])
                    {
                        Destroy(scriptList[k].clonedBtn);
                        scriptList.Remove(scriptList[k]);
                    }
                }

                Destroy(ifBtnList[ifBtnList.Count - 1]);
                ifBtnList.RemoveAt(ifBtnList.Count - 1);

                curIfMode = ifType.None;
            }

            Destroy(info.clonedBtn);
            //info.clonedBtn = null;

            if (info.ifType != ifType.None)
            {
                ifType tempIfType = info.ifType;
                if (curIfMode == ifType.None &&
                    ((info.index == 0 && scriptList.Count > 1 && scriptList[1].ifType != tempIfType) ||
                     (info.index == 0 && scriptList.Count == 1) ||
                     (info.index != 0 && scriptList[info.index - 1].ifType != tempIfType && info.index == scriptList.Count - 1) ||
                     (info.index != 0 && scriptList[info.index - 1].ifType != tempIfType && scriptList[info.index + 1].ifType != tempIfType)))
                {
                    ifBtnList.Remove(info.belongingIfBlock);
                    Destroy(info.belongingIfBlock);
                    info.belongingIfBlock = null;
                }
                else
                {
                    AdjustIfBlockLength(info.belongingIfBlock.GetComponent <Image>(), true);
                }
            }

            scriptList.RemoveAt(info.index);

            // 중간에 있는 명령어가 없어졌을 경우 뒤에있는 명령어들의 위치를 앞으로 당겨준다
            if (scriptList.Count != info.index)
            {
                GameObject ifBlockTemp = null;

                for (int i = info.index; i < scriptList.Count; i++)
                {
                    RectTransform btnRT    = scriptList[i].clonedBtn.GetComponent <RectTransform>();
                    btnRT.anchoredPosition = new Vector2(i * 208 - 416, 0);

                    scriptList[i].index = i;

                    if (scriptList[i].ifType != ifType.None && scriptList[i].belongingIfBlock != info.belongingIfBlock &&
                        scriptList[i].belongingIfBlock != ifBlockTemp)
                    {
                        ifBlockTemp        = scriptList[i].belongingIfBlock;
                        RectTransform r    = ifBlockTemp.GetComponent <RectTransform>();
                        r.anchoredPosition = new Vector2(r.anchoredPosition.x - 208, 0);
                    }
                }
            }

            // 서로 같은 종류의 다른 이프문 두개 사이에 있는 스크립트가 없어졌을 경우, 이 두 이프문을 하나로 이어준다.
            UserScriptInfo tempInfo = null;
            foreach (UserScriptInfo item in scriptList)
            {
                if (tempInfo == null)
                {
                    tempInfo = item;
                }
                else
                {
                    if (item.ifType != ifType.None && tempInfo.ifType != ifType.None &&
                        item.ifType == tempInfo.ifType && item.belongingIfBlock != tempInfo.belongingIfBlock)
                    {
                        ifBtnList.Remove(item.belongingIfBlock);
                        Destroy(item.belongingIfBlock);
                        item.belongingIfBlock = tempInfo.belongingIfBlock;

                        AdjustIfBlockLength(tempInfo.belongingIfBlock.GetComponent <Image>(), false);
                    }

                    tempInfo = item;
                }
            }
        });

        // ifBtn 그리는 로직
        if (curIfMode != ifType.None && ifBtnList.Count != 0)
        {
            ifBtnList[ifBtnList.Count - 1].GetComponent <Image>().sprite = IfBlockSprite[ifModeCount()];
            scriptList[info.index].belongingIfBlock = ifBtnList[ifBtnList.Count - 1];
        }
    }
Esempio n. 2
0
    IEnumerator MoveInput()
    {
        ffBtn.interactable   = true;
        undoBtn.interactable = false;

        for (int r = 0; r < repeatCount; r++)
        {
            playBtn.sprite = RepeatSprite[repeatCount - r - 1];

            RaycastHit hit;

            for (int t = 0; t < trainControllerList.Count; t++)
            {
                trainControllerList[t].isTrain = false;
            }

            if (r > 0)
            {
                foreach (var script in scriptList)
                {
                    script.clonedBtn.GetComponent <Image>().material = null;
                }
            }

            bool satisfyCondition = true;

            for (int i = 0; i < scriptList.Count; i++)
            {
                var       originalDir = scriptList[i].direction;
                Transform dir;

                if (originalDir == direction.up)
                {
                    dir = upRay;
                }
                else if (originalDir == direction.left)
                {
                    dir = leftRay;
                }
                else if (originalDir == direction.right)
                {
                    dir = rightRay;
                }
                else
                {
                    dir = downRay;
                }

                if (i > 0 && scriptList[i].ifType != ifType.None && scriptList[i].ifType != scriptList[i - 1].ifType)
                {
                    satisfyCondition = true;
                }

                //if 조건문에 해당하는 경우 검사
                if (scriptList[i].ifType == ifType.None)
                {
                    ; // do nothing
                }
                else if (i > 0 && scriptList[i].ifType == scriptList[i - 1].ifType && !satisfyCondition)
                {
                    continue;
                }
                else if (scriptList[i].ifType == ifType.ifArrow && !bounceScript.isArrowAlertOn)
                {
                    satisfyCondition = false;

                    scriptList[i].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                    for (int k = i + 1; k < scriptList.Count; k++)
                    {
                        if (scriptList[k].belongingIfBlock == scriptList[i].belongingIfBlock)
                        {
                            scriptList[k].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                        }
                    }

                    yield return(new WaitForSeconds(moveInterval));

                    continue;
                }
                else if (scriptList[i].ifType == ifType.ifNotArrow && bounceScript.isArrowAlertOn)
                {
                    satisfyCondition = false;

                    scriptList[i].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                    for (int k = i + 1; k < scriptList.Count; k++)
                    {
                        if (scriptList[k].belongingIfBlock == scriptList[i].belongingIfBlock)
                        {
                            scriptList[k].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                        }
                    }

                    yield return(new WaitForSeconds(moveInterval));

                    continue;
                }
                else if (scriptList[i].ifType == ifType.ifGasi && !bounceScript.isGasiAlertOn)
                {
                    satisfyCondition = false;

                    scriptList[i].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                    for (int k = i + 1; k < scriptList.Count; k++)
                    {
                        if (scriptList[k].belongingIfBlock == scriptList[i].belongingIfBlock)
                        {
                            scriptList[k].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                        }
                    }

                    yield return(new WaitForSeconds(moveInterval));

                    continue;
                }
                else if (scriptList[i].ifType == ifType.ifNotGasi && bounceScript.isGasiAlertOn)
                {
                    satisfyCondition = false;

                    scriptList[i].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                    for (int k = i + 1; k < scriptList.Count; k++)
                    {
                        if (scriptList[k].belongingIfBlock == scriptList[i].belongingIfBlock)
                        {
                            scriptList[k].clonedBtn.GetComponent <Image>().material = UIGrayscaleMat;
                        }
                    }

                    yield return(new WaitForSeconds(moveInterval));

                    continue;
                }

                HighlightButton(scriptList[i].clonedBtn);

                if (scriptList[i].direction == direction.up)
                {
                    if (Physics.Raycast(upRay.position, upRay.forward, out hit, rayLength) && hit.collider.tag != "LeftCar" && hit.collider.tag != "RightCar" && hit.collider.tag != "Bead" && hit.collider.tag != "Water" && hit.collider.tag != "Gasi" && hit.collider.tag != "ArrowGun")
                    {
                        bounceScript.UpCollideInput();
                    }
                    else
                    {
                        bounceScript.UpInput();
                    }
                }
                else if (scriptList[i].direction == direction.down)
                {
                    if (Physics.Raycast(downRay.position, downRay.forward, out hit, rayLength) && hit.collider.tag != "LeftCar" && hit.collider.tag != "RightCar" && hit.collider.tag != "Bead" && hit.collider.tag != "Water" && hit.collider.tag != "Gasi" && hit.collider.tag != "ArrowGun")
                    {
                        bounceScript.DownCollideInput();
                    }
                    else
                    {
                        bounceScript.DownInput();
                    }
                }
                else if (scriptList[i].direction == direction.left)
                {
                    if (Physics.Raycast(leftRay.position, leftRay.forward, out hit, rayLength) && hit.collider.tag != "LeftCar" && hit.collider.tag != "RightCar" && hit.collider.tag != "Bead" && hit.collider.tag != "Water" && hit.collider.tag != "Gasi" && hit.collider.tag != "ArrowGun")
                    {
                        bounceScript.LeftCollideInput();
                    }
                    else
                    {
                        bounceScript.LeftInput();
                    }
                }
                else if (scriptList[i].direction == direction.right)
                {
                    if (Physics.Raycast(rightRay.position, rightRay.forward, out hit, rayLength) && hit.collider.tag != "LeftCar" && hit.collider.tag != "RightCar" && hit.collider.tag != "Bead" && hit.collider.tag != "Water" && hit.collider.tag != "Gasi" && hit.collider.tag != "ArrowGun")
                    {
                        bounceScript.RightCollideInput();
                    }
                    else
                    {
                        bounceScript.RightInput();
                    }
                }
                else if (scriptList[i].direction == direction.stop)
                {
                    // do nothing
                }

                scriptList[i].SetDirection(originalDir);

                for (int j = 0; j < carControllerList.Count; j++)
                {
                    carControllerList[j].CarInput();
                }

                for (int j = 0; j < steppingControllerList.Count; j++)
                {
                    steppingControllerList[j].SteppingInput();
                }

                for (int j = 0; j < trainControllerList.Count; j++)
                {
                    trainControllerList[j].TrainInput();
                }

                for (int j = 0; j < arrowGunControllerList.Count; j++)
                {
                    arrowGunControllerList[j].ArrowInput();
                }

                for (int j = 0; j < gasiControllerList.Count; j++)
                {
                    gasiControllerList[j].GasiInput();
                }

                yield return(new WaitForSeconds(moveInterval));
            }
        }

        Time.timeScale = 1f;

        ClearButton();
        scriptList.Clear();
        ifBtnList.Clear();
        curIfMode            = ifType.None;
        isPlaying            = false;
        ffBtn.interactable   = false;
        undoBtn.interactable = true;
        repeatCount          = 1;
        playBtn.sprite       = RepeatSprite[0];
    }
Esempio n. 3
0
    private void InitIfMode(ifType ifModeType)
    {
        source.PlayOneShot(selectSound2, audioVolume);

        if (!isPlaying && curIfMode == ifType.None && scriptList.Count < 5)
        {
            curIfMode = ifModeType;

            // 새로운 ifMode에 들어갈 때에만 ifblock을 그려준다
            // 05.02 기획 변경으로 이프문 종료 후 동일한 종류의 이프문 바로 시작해도 새로운 ifBlock으로 그려주려고 했으나 사이드이펙트가 커서 나중에 수정할 예정
            if (scriptList.Count == 0 || scriptList[scriptList.Count - 1].ifType != curIfMode)
            {
                var ifBlock = Instantiate(IfBtn, QueuePanel.transform) as GameObject;
                ifBtnList.Add(ifBlock);

                RectTransform rt = ifBlock.GetComponent <RectTransform>();
                rt.anchoredPosition = new Vector2((scriptList.Count) * 208 - 522, 0);
                rt.localScale       = Vector3.one;

                // Set ifBtn image that is on the ifBlock
                ifBtn = ifBlock.transform.Find("Button");
                if (ifBtn != null)
                {
                    switch (curIfMode)
                    {
                    case ifType.ifGasi:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_gasi;
                        break;

                    case ifType.ifArrow:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_arrow;
                        break;

                    case ifType.ifNotGasi:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_notGasi;
                        break;

                    case ifType.ifNotArrow:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_notArrow;
                        break;
                    }

                    ifBtn.GetComponent <Button>().onClick.AddListener(() =>
                    {
                        if (scriptList.Count == 0 || (scriptList[scriptList.Count - 1].ifType != curIfMode && curIfMode != ifType.None))
                        {
                            if (ifBtnList.Count != 0)
                            {
                                var latestIfBtn = ifBtnList[ifBtnList.Count - 1];
                                ifBtnList.RemoveAt(ifBtnList.Count - 1);
                                Destroy(latestIfBtn);
                            }
                        }
                        curIfMode = ifType.None;
                        buttonScript.stopBlinkAnim();
                        //이프문 종료 후 다시 해당 이프문 편집으로 진입하고 싶은 경우 때문에 밑줄 주석 처리했다가...
                        //05.02 그냥 이프문을 삭제하고 다시 만드는 걸로 UX를 변경함에 따라 주석 해제 하려다가.... 사이드이펙트가 커서 나중에하기로
                        //ifBtn.GetComponent<Button>().onClick.RemoveAllListeners();
                    });
                } // end of Set ifBtn image that is on the ifBlock
            }
            else  // 새 블록이 아니라 기존거에 연결되는거일 때, 애니메이션을 다시 켜준다
            {
                if (buttonScript != null)
                {
                    buttonScript.blinkAnim();
                }
            }

            buttonScript = ifBtn.GetComponent <ButtonHighlightController>();
        }
    }
    public void Initialize(List <UserScriptInfo> scriptList, int repeatCount, int lineNumber, ButtonEvent buttonEvent)
    {
        GameObject btnIns;
        GameObject ifBlock      = null;
        int        ifModeLength = 0;

        Transform scriptBox = transform.Find("ScriptBox");

        Transform[] scripts = scriptBox.GetComponentsInChildren <Transform>();
        for (int i = 1; i < scripts.Length; i++) //자기자신 제외하고 [1]부터 시작
        {
            Destroy(scripts[i].gameObject);
        }

        ifType prevIfMode = ifType.None;

        this.lineNumber.text = lineNumber.ToString();

        for (int i = 0; i < scriptList.Count; i++)
        {
            if (scriptList[i].ifType != ifType.None && scriptList[i].ifType != prevIfMode)
            {
                ifBlock = Instantiate(IfBtn, scriptBox) as GameObject;

                RectTransform ifBlcokRT = ifBlock.GetComponent <RectTransform>();
                ifBlcokRT.anchoredPosition = new Vector2(i * 135 - 336f, 0);
                //ifBlcokRT.localScale = new Vector3(0.65f, 0.65f, 0.65f);

                Transform ifBtn = ifBlock.transform.Find("Button");
                if (ifBtn != null)
                {
                    ifBtn.GetComponent <Button>().enabled = false;

                    switch (scriptList[i].ifType)
                    {
                    case ifType.ifGasi:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_gasi;
                        break;

                    case ifType.ifArrow:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_arrow;
                        break;

                    case ifType.ifNotGasi:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_notGasi;
                        break;

                    case ifType.ifNotArrow:
                        ifBtn.GetComponent <Image>().sprite = ifBtn_notArrow;
                        break;
                    }
                }
                ifModeLength++;
            }
            else if (scriptList[i].ifType != ifType.None)
            {
                if (ifBlock != null)
                {
                    ifBlock.GetComponent <Image>().sprite = IfBlockSprite[ifModeLength];
                }
            }
            else
            {
                ifBlock      = null;
                ifModeLength = 0;
            }

            if (scriptList[i].direction == direction.up)
            {
                btnIns = Instantiate(UpBtn, scriptBox) as GameObject;
            }
            else if (scriptList[i].direction == direction.down)
            {
                btnIns = Instantiate(DownBtn, scriptBox) as GameObject;
            }
            else if (scriptList[i].direction == direction.left)
            {
                btnIns = Instantiate(LeftBtn, scriptBox) as GameObject;
            }
            else if (scriptList[i].direction == direction.right)
            {
                btnIns = Instantiate(RightBtn, scriptBox) as GameObject;
            }
            else// (scriptList[i].direction == direction.stop)
            {
                btnIns = Instantiate(StopBtn, scriptBox) as GameObject;
            }

            RectTransform rt = btnIns.GetComponent <RectTransform>();
            rt.anchoredPosition = new Vector2(i * 135 - 270f, 0);
            rt.localScale       = new Vector3(0.65f, 0.65f, 0.65f);

            prevIfMode = scriptList[i].ifType;
        } // End of forloop

        repeatImgComp.sprite = RepeatSprites[repeatCount - 1];
    }
Esempio n. 5
0
 public UserScriptInfo(direction dir, ifType ifType, bool endIf, int n, GameObject obj = null, GameObject belongingIfBlock = null) : base(dir, ifType, endIf, obj)
 {
     index = n;
     this.belongingIfBlock = belongingIfBlock;
 }
Esempio n. 6
0
 public void SetIfType(ifType type)
 {
     ifType = type;
 }
Esempio n. 7
0
 void SetInfo(direction dir, ifType ifType, GameObject obj = null)
 {
     clonedBtn   = obj;
     direction   = dir;
     this.ifType = ifType;
 }