void Start() { // Create data m_State = ESTATE.NONE; m_NumberCluesFound = 0; m_UI.HideAll(); // Check internet if (Application.internetReachability == NetworkReachability.NotReachable) { Debug.Log("No Internet"); m_UI.PopupButtons.ShowPopup("", "Please connect to internet and restart Treasur Hunt to download the data.", "Restart App", OkPopup, string.Empty, null, string.Empty, null); } else { //m_UI.Progress.Title = "Wait Downloading data..."; m_UI.Progress.SetProgress("Downloading\n0%", 0); m_UI.Progress.Show(); StartCoroutine(Init()); } }
public void OnMessageTap() { m_UI.MessageUI.DisableButton(); switch (m_State) { case ESTATE.INTRO: m_MessageID++; if (m_MessageID < m_FileManager.Data.Intro.Count) { m_UI.MessageUI.SetMessage("Instructions", m_FileManager.Data.Intro[m_MessageID], 0.3f); } else { // Show first clue m_MessageID = 0; m_State = ESTATE.GAME; m_UI.MessageUI.SetMessage("Look for all the clues!", m_FileManager.Data.Clues[m_MessageID], 0.3f); } break; case ESTATE.GAME: break; case ESTATE.END: break; } }
protected void FSM() { switch (eState) { case ESTATE.eNormal: break; case ESTATE.eWalk: { Vector2 CurPos = this.transform.position; float step = fSpeed * Time.deltaTime; transform.position = Vector2.MoveTowards(CurPos, vTargetPos, step); fLength -= fSpeed * Time.deltaTime; if (fLength <= 0.0f) { eState = ESTATE.eNormal; ImgChange((int)eState); fLength = 0.0f; vTargetPos = this.transform.position; } } break; } }
private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { mState = ESTATE.Hidding; } }
public void OnMarkerFound(string id, int markerID) { // Avoid scan when no Game state if (m_State != ESTATE.GAME) { return; } // Find clue if ((markerID >= 0) && (markerID < m_FileManager.Data.Clues.Count)) { //m_FileManager.Data.Clues[markerID] m_NumberCluesFound++; if (m_NumberCluesFound < m_FileManager.Data.Clues.Count) { // Instance egg and set new message InstanceObject(); m_UI.MessageUI.SetMessage("Clue " + id, m_FileManager.Data.Clues[markerID], 0.3f); } else { // End clues m_MessageID = 0; m_State = ESTATE.END; m_UI.MessageUI.SetMessage("Game over", m_FileManager.Data.EndOfGame[m_MessageID], 0.3f); } } }
private IEnumerator Init() { // Request files yield return(m_FileManager.RequestFiles()); m_UI.Progress.SetProgress("Downloading\n100%", 100); //m_UI.Progress.SetProgress(100); yield return(new WaitForSeconds(1.0f)); // m_UI.Progress.Title = "Completed! Ready to play =)"; m_UI.Progress.SetProgress("Ready to play =)", 100); yield return(new WaitForSeconds(1.0f)); m_UI.Progress.Hide(); // Intro m_MessageID = 0; m_State = ESTATE.INTRO; m_UI.MessageUI.Show(); m_UI.MessageUI.DisableButton(); m_UI.MessageUI.SetMessage("Instructions", m_FileManager.Data.Intro[m_MessageID], 0.3f); m_UI.MessageUI.OnMessageEnd += OnEndOfMessage; }
public void OnBecameVisible() { e = ESTATE.VISIBLE; if (e == ESTATE.VISIBLE) { print("Should be shooting"); //Instantiate(BulletB, firepos.transform.position, Quaternion.identity); coroutine = WaitAndShoot(1.0f); StartCoroutine(coroutine); } }
public void Show() { if (mState == ESTATE.Hidden) { mState = ESTATE.Showing; activeColorPicker = this; dt = 0; OriginalColor = GetColor(); NotifyColor(OriginalColor); } }
/** * Draw Color Picker */ private void DrawColorPicker() { Rect rect = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr); Event e = Event.current; Vector2 mousePos = e.mousePosition; bool isLeftMBtnClicked = e.type == EventType.MouseUp; bool isLeftMBtnDragging = e.type == EventType.MouseDrag; bool isLeftMBtnMoving = e.type == EventType.MouseMove; bool openCondition = rect.Contains(mousePos) && ((isLeftMBtnClicked || isLeftMBtnDragging || isLeftMBtnMoving) && e.isMouse); bool closeCondition = isLeftMBtnClicked || (!rect.Contains(mousePos)) && (e.isMouse && isLeftMBtnMoving || e.type == EventType.MouseDown); if (openCondition && (activeColorPicker == null || activeColorPicker.mState == ESTATE.Hidden) && mState == ESTATE.Hidden) { mState = ESTATE.Showing; activeColorPicker = this; delta = 0; } if (closeCondition && mState == ESTATE.Showed) { if (isLeftMBtnClicked) { ApplyColor(); } else { SetColor(SelectedColor); } mState = ESTATE.Hidding; delta = 0; } if (mState == ESTATE.Showed) { if (rect.Contains(mousePos)) { float coeffX = colorSpace.width / sizeCurr; float coeffY = colorSpace.height / sizeCurr; Vector2 localImagePos = (mousePos - startPos); Color res = colorSpace.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y) - 1); SetColor(res); if (isLeftMBtnDragging) { ApplyColor(); } } else { SetColor(SelectedColor); } } }
private void consoleRead() { StrConsole = ""; float pc = 30.0f; DateTime _pre = DateTime.Now; while (_avrdude.HasExited == false) { int c = 0; do { //StrConsole += (char)c; StrConsole += (char)c; c = _avrdude.StandardError.Read(); //Console.Write((char)c); if (c < 0) { System.Threading.Thread.Sleep(1); } else { if ((char)c == '#') { pc = pc + _udPercent; } //Console.WriteLine(pc); raiseEvent(_udloading, (int)pc); TimeSpan sp = DateTime.Now - _pre; if (OnConsoleReceived != null && sp.TotalMilliseconds >= 10) { EventArgs_ConsoleRead ea = new EventArgs_ConsoleRead(); ea.DataRead = StrConsole; StrConsole = ""; OnConsoleReceived(this, ea); } } } while (c >= 0); } raiseEvent("done", 100, "h"); State = ESTATE.COMPLETE; if (OnFirmwareDownloadComplete != null) { OnFirmwareDownloadComplete(this, null); } }
/** * Update scaling states */ private void UpdateScaleState() { if (mState == ESTATE.Showing) { sizeCurr = Mathf.Lerp(sizeHidden, sizeFull, delta / animTime); if (delta / animTime > 1.0f) { mState = ESTATE.Showed; } delta += Time.deltaTime; } if (mState == ESTATE.Hidding) { sizeCurr = Mathf.Lerp(sizeFull, sizeHidden, delta / animTime); if (delta / animTime > 1.0f) { mState = ESTATE.Hidden; } delta += Time.deltaTime; } }
// Update is called once per frame public void _DrawGUI() { if (titleStyle == null) { titleStyle = new GUIStyle (GUI.skin.label); titleStyle.normal.textColor = textColor; } Rect rectColorEdit = new Rect(startPos.x + sizeCurr + 10, startPos.y + 30, 40, 140); Rect rectColorSlider = new Rect(startPos.x + sizeCurr + 50, startPos.y + 30, 60, 140); //GUI.Label(new Rect(startPos.x + sizeCurr + 60, startPos.y, 200, 30), Title, titleStyle); GUI.DrawTexture(new Rect(startPos.x + sizeCurr + 10, startPos.y, 40, 20), txColorDisplay); if(GUI.Button(new Rect(startPos.x + sizeCurr + 10, startPos.y + sizeCurr, 60, 20), "Apply")) { if (ftlGatherer.ActiveNotes != null && ftlGatherer.ActiveNotes.Count > 0) { GameObject activeNote = ftlGatherer.ActiveNotes[0]; if (activeNote.GetComponent<StickyScript>() != null) { activeNote.GetComponent<StickyScript>().noteColor = TempColor; } else if (activeNote.GetComponent<LineScript>() != null) activeNote.GetComponent<LineScript>().LineColor = TempColor; } TempColor = new Color (1f, 1f, 1f, 1f); SelectedColor = TempColor; HideColorPicker = true; } //update scaling states if(mState == ESTATE.Showing) { sizeCurr = Mathf.Lerp(sizeHidden, sizeFull, dt/animTime); if(dt/animTime > 1.0f) { mState = ESTATE.Showed; } dt += Time.deltaTime; } if(mState == ESTATE.Hidding) { sizeCurr = Mathf.Lerp(sizeFull, sizeHidden, dt/animTime); if(dt/animTime > 1.0f) { mState = ESTATE.Hidden; } dt += Time.deltaTime; } //draw color picker Rect rect = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr); GUI.DrawTexture(rect, colorSpace); float alphaGradHeight = alphaGradientHeight * (sizeCurr/sizeFull); Vector2 startPosAlpha = startPos + new Vector2(0, sizeCurr); Rect rectAlpha = new Rect(startPosAlpha.x, startPosAlpha.y, sizeCurr, alphaGradHeight); GUI.DrawTexture(rectAlpha, alphaGradient); Rect rectFullSize = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr + alphaGradHeight); Vector2 mousePos = Event.current.mousePosition; Event e = Event.current; bool isLeftMBtnClicked = e.type == EventType.mouseUp; bool isLeftMBtnDragging = e.type == EventType.MouseDrag; bool openCondition = (rectFullSize.Contains(e.mousePosition) && (((e.type == EventType.MouseUp || e.type == EventType.mouseDrag || e.type == EventType.MouseMove) && e.isMouse))); bool closeCondition = isLeftMBtnClicked || (!rectFullSize.Contains(e.mousePosition)) && (e.isMouse && (e.type == EventType.MouseMove || e.type == EventType.MouseDown)); if(openCondition && (activeColorPicker == null || activeColorPicker.mState == ESTATE.Hidden)) { if(mState == ESTATE.Hidden) { mState = ESTATE.Showing; activeColorPicker = this; dt = 0; } } if(closeCondition) { if(mState == ESTATE.Showed) { if(isLeftMBtnClicked) { ApplyColor(); } else { SetColor(SelectedColor); } mState = ESTATE.Hidding; dt = 0; } } if(mState == ESTATE.Showed) { if(rect.Contains(e.mousePosition)) { float coeffX = colorSpace.width / sizeCurr; float coeffY = colorSpace.height / sizeCurr; Vector2 localImagePos = (mousePos - startPos); Color res = colorSpace.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y)-1); SetColor(res); if(isLeftMBtnDragging ) { ApplyColor(); } UpdateColorEditFields(false); UpdateColorSliders(false); } else if(rectAlpha.Contains(e.mousePosition)) { float coeffX = alphaGradient.width / sizeCurr; float coeffY = alphaGradient.height / sizeCurr; Vector2 localImagePos = (mousePos - startPosAlpha); Color res = alphaGradient.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y)-1); Color curr = GetColor(); curr.a = res.r; SetColor(curr); if(isLeftMBtnDragging) { ApplyColor(); } UpdateColorEditFields(false); UpdateColorSliders(false); } else if(rectColorEdit.Contains(e.mousePosition)) { UpdateColorEditFields(true); UpdateColorSliders(false); } else if(rectColorSlider.Contains(e.mousePosition)) { UpdateColorEditFields(false); UpdateColorSliders(true); } else { SetColor(SelectedColor); } } }
// Update is called once per frame public void _DrawGUI () { if (titleStyle == null) { titleStyle = new GUIStyle (GUI.skin.label); titleStyle.normal.textColor = textColor; } Rect rectColorEdit = new Rect(startPos.x + sizeCurr + 10, startPos.y + 30, 40, 140); Rect rectColorSlider = new Rect(startPos.x + sizeCurr + 50, startPos.y + 30, 60, 140); GUI.Label(new Rect(startPos.x + sizeCurr + 60, startPos.y, 200, 30), Title, titleStyle); GUI.DrawTexture(new Rect(startPos.x + sizeCurr + 10, startPos.y, 40, 20), txColorDisplay); if(mState == ESTATE.Showed) { txtR = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 30, 40, 20), txtR, 3); txtG = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 60, 40, 20), txtG, 3); txtB = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 90, 40, 20), txtB, 3); txtA = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 120, 40, 20), txtA, 3); valR = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 35, 60, 20), valR, 0.0f, 1.0f); valG = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 65, 60, 20), valG, 0.0f, 1.0f); valB = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 95, 60, 20), valB, 0.0f, 1.0f); valA = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 125, 60, 20), valA, 0.0f, 1.0f); if(GUI.Button(new Rect(startPos.x + sizeCurr + 10, startPos.y + 150, 60, 20), "Apply")) { ApplyColor(); SelectedColor = TempColor; if(receiver) { receiver.SendMessage(colorSetFunctionName, SelectedColor, SendMessageOptions.DontRequireReceiver); } } GUIStyle labelStyleRGBA = new GUIStyle(GUI.skin.label); labelStyleRGBA.normal.textColor = Color.white; GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 30, 20, 20), "R", labelStyleRGBA); GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 60, 20, 20), "G", labelStyleRGBA); GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 90, 20, 20), "B", labelStyleRGBA); GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 120, 20, 20), "A", labelStyleRGBA); } //update scaling states if(mState == ESTATE.Showing) { sizeCurr = Mathf.Lerp(sizeHidden, sizeFull, dt/animTime); if(dt/animTime > 1.0f) { mState = ESTATE.Showed; } dt += Time.deltaTime; } if(mState == ESTATE.Hidding) { sizeCurr = Mathf.Lerp(sizeFull, sizeHidden, dt/animTime); if(dt/animTime > 1.0f) { mState = ESTATE.Hidden; } dt += Time.deltaTime; } //draw color picker Rect rect = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr); GUI.DrawTexture(rect, colorSpace); float alphaGradHeight = alphaGradientHeight * (sizeCurr/sizeFull); Vector2 startPosAlpha = startPos + new Vector2(0, sizeCurr); Rect rectAlpha = new Rect(startPosAlpha.x, startPosAlpha.y, sizeCurr, alphaGradHeight); GUI.DrawTexture(rectAlpha, alphaGradient); Rect rectFullSize = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr + alphaGradHeight); Vector2 mousePos = Event.current.mousePosition; Event e = Event.current; bool isLeftMBtnClicked = e.type == EventType.mouseUp; bool isLeftMBtnDragging = e.type == EventType.MouseDrag; bool openCondition = (rectFullSize.Contains(e.mousePosition) && (((e.type == EventType.MouseUp || e.type == EventType.mouseDrag || e.type == EventType.MouseMove) && e.isMouse))); bool closeCondition = isLeftMBtnClicked || (!rectFullSize.Contains(e.mousePosition)) && (e.isMouse && (e.type == EventType.MouseMove || e.type == EventType.MouseDown)); if(openCondition && (activeColorPicker == null || activeColorPicker.mState == ESTATE.Hidden)) { if(mState == ESTATE.Hidden) { mState = ESTATE.Showing; activeColorPicker = this; dt = 0; } } if(closeCondition) { if(mState == ESTATE.Showed) { if(isLeftMBtnClicked) { ApplyColor(); } else { SetColor(SelectedColor); } mState = ESTATE.Hidding; dt = 0; } } if(mState == ESTATE.Showed) { if(rect.Contains(e.mousePosition)) { float coeffX = colorSpace.width / sizeCurr; float coeffY = colorSpace.height / sizeCurr; Vector2 localImagePos = (mousePos - startPos); Color res = colorSpace.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y)-1); SetColor(res); if(isLeftMBtnDragging ) { ApplyColor(); } UpdateColorEditFields(false); UpdateColorSliders(false); } else if(rectAlpha.Contains(e.mousePosition)) { float coeffX = alphaGradient.width / sizeCurr; float coeffY = alphaGradient.height / sizeCurr; Vector2 localImagePos = (mousePos - startPosAlpha); Color res = alphaGradient.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y)-1); Color curr = GetColor(); curr.a = res.r; SetColor(curr); if(isLeftMBtnDragging) { ApplyColor(); } UpdateColorEditFields(false); UpdateColorSliders(false); } else if(rectColorEdit.Contains(e.mousePosition)) { UpdateColorEditFields(true); UpdateColorSliders(false); } else if(rectColorSlider.Contains(e.mousePosition)) { UpdateColorEditFields(false); UpdateColorSliders(true); } else { SetColor(SelectedColor); } } }
ESTATE_STATUS ProcessState() { ESTATE_STATUS CurrStateStatus = ESTATE_STATUS.RUNNING; if (OldState != State) { Debug.Log("State is " + State); OldState = State; } switch (State) { case ESTATE.BEGIN_THROW_PROJECTILES: case ESTATE.BEGIN_CHASE: { PauseWaypoints(); NavAgent.SetDestination(PlayerPosition.position); NavAgent.Resume(); //sws pause() will pause the nav agent, so it needs to be resumed CurrStateStatus = ESTATE_STATUS.COMPLETED; ResetPlayerHiddenTimer(); ResetTimeBetweenProjectilesTimer(); } break; case ESTATE.BEGIN_PATROL: { ResumeWaypoints(); CurrStateStatus = ESTATE_STATUS.COMPLETED; } break; case ESTATE.BEGIN_STRIKE: { NavAgent.Stop(); StrikePlayer(); StrikeAnimFinished = false; CurrStateStatus = ESTATE_STATUS.COMPLETED; } break; case ESTATE.STRIKING: { if (StrikeAnimFinished == false) { if (CallBackFunctionCalledOnce == false) { CallBackFunctionCalledOnce = true; CallBackAfterWait(StrikeAnimDuration, () => { //theres a delay between the anim is playing and the projectile is thrown StrikeAnimFinished = true; }); } } if (StrikeAnimFinished == true) { NavAgent.SetDestination(PlayerPosition.position); if (DistanceToPlayer <= (RangeForStrike + ReachForStrike)) //check we are still in range for damage { GameLogicScript.PlayerDamaged(DamageForStrike); } CurrStateStatus = ESTATE_STATUS.COMPLETED; CallBackFunctionCalledOnce = false; StrikeAnimFinished = false; } else { CurrStateStatus = ESTATE_STATUS.RUNNING; } } break; case ESTATE.CHASING: { NavAgent.SetDestination(PlayerPosition.position); CurrStateStatus = ESTATE_STATUS.RUNNING; } break; case ESTATE.PATROLLING: { //let the waypoint manager do it's thing CurrStateStatus = ESTATE_STATUS.RUNNING; } break; case ESTATE.THROWING_PROJECTILES: { NavAgent.SetDestination(PlayerPosition.position); bool PlayerVisable = CanSeePlayer(); CurrStateStatus = ESTATE_STATUS.RUNNING; if (PlayerVisable == true) { if (MinimumTimeBetweenProjectilesReached()) { StartCoroutine(PlayOneShotAnimation(ANIM_STATES.THROW_PROJECTILE_ANIM_VALE)); CallBackAfterWait(DelayProjectileThrownAnim, () => { //theres a delay between the anim is playing and the projectile is thrown FireProjectile(); }); ResetTimeBetweenProjectilesTimer(); } ResetPlayerHiddenTimer(); } else if (CantSeePlayerSeconds > TimePersuePlayerForProjectileWhenHidden) { CurrStateStatus = ESTATE_STATUS.COMPLETED; //leave this state } } break; } return(CurrStateStatus); }
void SetState(ESTATE NewState) { OldState = State; State = NewState; StateStatus = ESTATE_STATUS.RUNNING; }
void Awake() { bDirection = true; fLength = 0.0f; eState = ESTATE.eNormal; }
// Update is called once per frame public void _DrawGUI() { if (activeColorPicker != this) { return; } if (titleStyle == null) { titleStyle = new GUIStyle(GUI.skin.label); titleStyle.normal.textColor = textColor; titleStyle.fontSize = 18; } //update scaling states if (mState == ESTATE.Showing) { sizeCurr = Mathf.Lerp(sizeHidden, sizeFull, dt / animTime); if (dt / animTime > 1.0f) { mState = ESTATE.Showed; } dt += Time.deltaTime; } if (mState == ESTATE.Hidding) { sizeCurr = Mathf.Lerp(sizeFull, sizeHidden, dt / animTime); if (dt / animTime > 1.0f) { mState = ESTATE.Hidden; } dt += Time.deltaTime; } float currentScale = sizeCurr / sizeFull; startPos = new Vector2(originPos.x - sizeFull * currentScale * anchorPos.x, originPos.y - sizeFull * currentScale * anchorPos.y); Rect rectColorEdit = new Rect(startPos.x + sizeCurr + 10, startPos.y + 30, 40, 140); Rect rectColorSlider = new Rect(startPos.x + sizeCurr + 50, startPos.y + 30, 60, 140); if (mState == ESTATE.Showed) { float startXSidePanel = startPos.x + sizeCurr; GUI.DrawTexture(new Rect(startXSidePanel, startPos.y, widthSidePanel, sizeFull), txDialogBG); // Dialog background rectangle GUI.Label(new Rect(startPos.x + sizeCurr + 10, startPos.y, 200, 30), Title, titleStyle); //GUI.DrawTexture(new Rect(startPos.x + sizeCurr + 10, startPos.y, 40, 20), txColorDisplay); string txtOldR = txtR; string txtOldG = txtG; string txtOldB = txtB; string txtOldA = txtA; float startXTextVals = startPos.x + sizeCurr + 10; float widthTextVals = 40; txtR = GUI.TextField(new Rect(startXTextVals, startPos.y + 30, widthTextVals, 20), txtR, 3); txtG = GUI.TextField(new Rect(startXTextVals, startPos.y + 60, widthTextVals, 20), txtG, 3); txtB = GUI.TextField(new Rect(startXTextVals, startPos.y + 90, widthTextVals, 20), txtB, 3); if (showAlpha) { txtA = GUI.TextField(new Rect(startXTextVals, startPos.y + 120, widthTextVals, 20), txtA, 3); } float startXSliders = startXTextVals + widthTextVals + 8; // startPos.x + sizeCurr + 50; float widthSliders = startXSidePanel + widthSidePanel - startXSliders - 28; valR = GUI.HorizontalSlider(new Rect(startXSliders, startPos.y + 35, widthSliders, 20), valR, 0.0f, 1.0f); valG = GUI.HorizontalSlider(new Rect(startXSliders, startPos.y + 65, widthSliders, 20), valG, 0.0f, 1.0f); valB = GUI.HorizontalSlider(new Rect(startXSliders, startPos.y + 95, widthSliders, 20), valB, 0.0f, 1.0f); if (showAlpha) { valA = GUI.HorizontalSlider(new Rect(startXSliders, startPos.y + 125, widthSliders, 20), valA, 0.0f, 1.0f); } if (txtOldR != txtR || txtOldG != txtG || txtOldB != txtB || txtOldA != txtA) { UpdateColorEditFields(true); UpdateColorSliders(false); SetColor(new Color(valR, valG, valB, valA)); ApplyColor(); } if (GUI.Button(new Rect(startPos.x + sizeCurr + widthSidePanel - 10 - 60, startPos.y + sizeFull - 20 - 8, 60, 20), "OK")) { ApplyColor(); SelectedColor = TempColor; if (receiver) { receiver.SendMessage(colorSetFunctionName, SelectedColor, SendMessageOptions.DontRequireReceiver); } mState = ESTATE.Hidding; } if (GUI.Button(new Rect(startPos.x + sizeCurr + 10, startPos.y + sizeFull - 20 - 8, 60, 20), "Cancel")) { SetColor(OriginalColor); if (receiver) { receiver.SendMessage(colorSetFunctionName, OriginalColor, SendMessageOptions.DontRequireReceiver); } mState = ESTATE.Hidding; } if (GUI.Button(new Rect(startPos.x + sizeCurr + 10, startPos.y + sizeFull + (-20 - 8) * 2, 60, 20), "Default")) { if (receiver) { receiver.SendMessage(colorGetDefaultFunctionName, this, SendMessageOptions.DontRequireReceiver); receiver.SendMessage(colorSetFunctionName, SelectedColor, SendMessageOptions.DontRequireReceiver); } } if (GUI.Button(new Rect(startPos.x + sizeCurr + 10, startPos.y + sizeFull + (-20 - 8) * 3, 60, 20), "White")) { if (receiver) { NotifyColor(Color.white); receiver.SendMessage(colorSetFunctionName, SelectedColor, SendMessageOptions.DontRequireReceiver); } } if (GUI.Button(new Rect(startPos.x + sizeCurr + 10, startPos.y + sizeFull + (-20 - 8) * 4, 60, 20), "Black")) { if (receiver) { NotifyColor(Color.black); receiver.SendMessage(colorSetFunctionName, SelectedColor, SendMessageOptions.DontRequireReceiver); } } GUIStyle labelStyleRGBA = new GUIStyle(GUI.skin.label); labelStyleRGBA.normal.textColor = Color.white; float startXValLetters = startXSliders + widthSliders + 8; GUI.Label(new Rect(startXValLetters, startPos.y + 30, 20, 20), "R", labelStyleRGBA); GUI.Label(new Rect(startXValLetters, startPos.y + 60, 20, 20), "G", labelStyleRGBA); GUI.Label(new Rect(startXValLetters, startPos.y + 90, 20, 20), "B", labelStyleRGBA); if (showAlpha) { GUI.Label(new Rect(startXValLetters, startPos.y + 120, 20, 20), "A", labelStyleRGBA); } } //draw color picker Rect rect = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr); GUI.DrawTexture(rect, colorSpace); Rect rectGray = new Rect(startPos.x - widthGrayScale * currentScale, startPos.y, widthGrayScale * currentScale, sizeCurr); GUI.DrawTexture(rectGray, txGrayScale); // Rect rectFullSize = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr); float alphaGradHeight = alphaGradientHeight * (sizeCurr / sizeFull); Vector2 startPosAlpha = startPos + new Vector2(0, sizeCurr); Rect rectAlpha = new Rect(startPosAlpha.x, startPosAlpha.y, sizeCurr, alphaGradHeight); if (showAlpha) { if (mState != ESTATE.Hidden) // jma { GUI.DrawTexture(rectAlpha, alphaGradient); } // rectFullSize = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr + alphaGradHeight); } Vector2 mousePos = Event.current.mousePosition; Event e = Event.current; bool isLeftMBtnClicked = e.type == EventType.mouseUp; bool isLeftMBtnDragging = e.type == EventType.MouseDrag; #if false bool openCondition = (rectFullSize.Contains(e.mousePosition) && (((e.type == EventType.MouseUp || e.type == EventType.mouseDrag || e.type == EventType.MouseMove) && e.isMouse))); // bool closeCondition = isLeftMBtnClicked || (!rectFullSize.Contains(e.mousePosition)) && (e.isMouse && (e.type == EventType.MouseMove || e.type == EventType.MouseDown)); if (openCondition && (activeColorPicker == null || activeColorPicker.mState == ESTATE.Hidden)) { if (mState == ESTATE.Hidden) { mState = ESTATE.Showing; activeColorPicker = this; dt = 0; OriginalColor = GetColor(); } } if (closeCondition) { if (mState == ESTATE.Showed) { if (isLeftMBtnClicked) { ApplyColor(); } else { SetColor(SelectedColor); } mState = ESTATE.Hidding; dt = 0; } } #endif if (mState == ESTATE.Showed) { if (rect.Contains(e.mousePosition) && (isLeftMBtnClicked || isLeftMBtnDragging)) { float coeffX = colorSpace.width / sizeCurr; float coeffY = colorSpace.height / sizeCurr; Vector2 localImagePos = (mousePos - startPos); Color res = colorSpace.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y) - 1); SetColor(res); ApplyColor(); UpdateColorEditFields(false); UpdateColorSliders(false); } else if (rectGray.Contains(e.mousePosition) && (isLeftMBtnClicked || isLeftMBtnDragging)) { float localImageY = (mousePos.y - startPos.y); float grayVal = localImageY / (float)(txGrayScale.height - 1); grayVal = Mathf.Clamp(grayVal, 0.0f, 1.0f); Color grayColor = new Color(grayVal, grayVal, grayVal); SetColor(grayColor); ApplyColor(); UpdateColorEditFields(false); UpdateColorSliders(false); } else if (showAlpha && rectAlpha.Contains(e.mousePosition)) { float coeffX = alphaGradient.width / sizeCurr; float coeffY = alphaGradient.height / sizeCurr; Vector2 localImagePos = (mousePos - startPosAlpha); Color res = alphaGradient.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y) - 1); Color curr = GetColor(); curr.a = res.r; SetColor(curr); if (isLeftMBtnDragging) { ApplyColor(); } UpdateColorEditFields(false); UpdateColorSliders(false); } else if (rectColorEdit.Contains(e.mousePosition)) { UpdateColorEditFields(true); UpdateColorSliders(false); } else if (rectColorSlider.Contains(e.mousePosition)) { UpdateColorEditFields(false); UpdateColorSliders(true); } else { SetColor(SelectedColor); } } }
// thread start private void Thread_StartBootloader() { //Thread.Sleep(1000); raiseEvent("port scan", 5, "a"); DateTime sTime = DateTime.Now; // 현재 포트 리스트 작성 List <COMPortInfo> prePorts = update_ports(); List <COMPortInfo> ports; //Thread.Sleep(1000); raiseEvent("reboot", 10, "b"); _sp.Close(); _sp.Open(); //System.Threading.Thread.Sleep(100); //_sp.Close(); bool isExist = false; DateTime stime = DateTime.Now; TimeSpan ts; bool isNull = true; // 기존 포트 있을 동안 대기하기 do { System.Threading.Thread.Sleep(200); ts = DateTime.Now - stime; if (ts.TotalSeconds >= 10) { State = ESTATE.COMPLETE; EventArgs_StateChanged e = new EventArgs_StateChanged(); e.message = "Port not found."; Thread.Sleep(100); OnError(this, e); return; } isExist = false; foreach (COMPortInfo com in update_ports()) { isNull = false; //Console.WriteLine(com.Name); if (com.Name == _sp.PortName) { isExist = true; } } } while (isExist || isNull); //Thread.Sleep(1000); raiseEvent("reboot", 15, "d"); // 새로운 포트 찾기 do { System.Threading.Thread.Sleep(10); ports = update_ports(); _percent++; } while (ports.Count < prePorts.Count); //Thread.Sleep(1000); raiseEvent("finding", 20, "e"); foreach (COMPortInfo com in ports) { _percent++; bool found = false; foreach (COMPortInfo preCom in prePorts) { if (com.Name == preCom.Name) { found = true; break; } } // 추정 포트 찾음 if (found == false) { startAvrdude(com.Name); return; } } }
// Use this for initialization void Start() { // rb = GetComponent<Rigidbody>(); rb.AddForce(new Vector3(0, -2, 0), ForceMode.VelocityChange); e = ESTATE.INVISIBLE; }
// Update is called once per frame public void _DrawGUI() { if (titleStyle == null) { titleStyle = new GUIStyle(GUI.skin.label); titleStyle.normal.textColor = textColor; } Rect rectColorEdit = new Rect(startPos.x + sizeCurr + 10, startPos.y + 30, 40, 140); Rect rectColorSlider = new Rect(startPos.x + sizeCurr + 50, startPos.y + 30, 60, 140); GUI.Label(new Rect(startPos.x + sizeCurr + 60, startPos.y, 200, 30), Title, titleStyle); GUI.DrawTexture(new Rect(startPos.x + sizeCurr + 10, startPos.y, 40, 20), txColorDisplay); if (mState == ESTATE.Showed) { txtR = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 30, 40, 20), txtR, 3, textfield_sm); txtG = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 60, 40, 20), txtG, 3, textfield_sm); txtB = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 90, 40, 20), txtB, 3, textfield_sm); txtA = GUI.TextField(new Rect(startPos.x + sizeCurr + 10, startPos.y + 120, 40, 20), txtA, 3, textfield_sm); valR = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 35, 60, 20), valR, 0.0f, 1.0f); valG = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 65, 60, 20), valG, 0.0f, 1.0f); valB = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 95, 60, 20), valB, 0.0f, 1.0f); valA = GUI.HorizontalSlider(new Rect(startPos.x + sizeCurr + 50, startPos.y + 125, 60, 20), valA, 0.0f, 1.0f); if (GUI.Button(new Rect(startPos.x + sizeCurr + 10, startPos.y + 150, 60, 20), "Apply")) { ApplyColor(); SelectedColor = TempColor; if (receiver) { receiver.SendMessage(colorSetFunctionName, SelectedColor, SendMessageOptions.DontRequireReceiver); } } GUIStyle labelStyleRGBA = new GUIStyle(GUI.skin.label); labelStyleRGBA.normal.textColor = Color.white; GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 30, 20, 20), "R", labelStyleRGBA); GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 60, 20, 20), "G", labelStyleRGBA); GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 90, 20, 20), "B", labelStyleRGBA); GUI.Label(new Rect(startPos.x + sizeCurr + 110, startPos.y + 120, 20, 20), "A", labelStyleRGBA); } //update scaling states if (mState == ESTATE.Showing) { sizeCurr = Mathf.Lerp(sizeHidden, sizeFull, dt / animTime); if (dt / animTime > 1.0f) { mState = ESTATE.Showed; } dt += Time.deltaTime; } if (mState == ESTATE.Hidding) { sizeCurr = Mathf.Lerp(sizeFull, sizeHidden, dt / animTime); if (dt / animTime > 1.0f) { mState = ESTATE.Hidden; } dt += Time.deltaTime; } //draw color picker Rect rect = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr); GUI.DrawTexture(rect, colorSpace); float alphaGradHeight = alphaGradientHeight * (sizeCurr / sizeFull); Vector2 startPosAlpha = startPos + new Vector2(0, sizeCurr); Rect rectAlpha = new Rect(startPosAlpha.x, startPosAlpha.y, sizeCurr, alphaGradHeight); GUI.DrawTexture(rectAlpha, alphaGradient); Rect rectFullSize = new Rect(startPos.x, startPos.y, sizeCurr, sizeCurr + alphaGradHeight); Vector2 mousePos = Event.current.mousePosition; Event e = Event.current; bool isLeftMBtnClicked = e.type == EventType.mouseUp; bool isLeftMBtnDragging = e.type == EventType.MouseDrag; bool openCondition = (rectFullSize.Contains(e.mousePosition) && (((e.type == EventType.MouseUp || e.type == EventType.mouseDrag || e.type == EventType.MouseMove) && e.isMouse))); bool closeCondition = isLeftMBtnClicked || (!rectFullSize.Contains(e.mousePosition)) && (e.isMouse && (e.type == EventType.MouseMove || e.type == EventType.MouseDown)); if (openCondition && (activeColorPicker == null || activeColorPicker.mState == ESTATE.Hidden)) { if (mState == ESTATE.Hidden) { mState = ESTATE.Showing; activeColorPicker = this; dt = 0; } } if (closeCondition) { if (mState == ESTATE.Showed) { if (isLeftMBtnClicked) { ApplyColor(); } else { SetColor(SelectedColor); } mState = ESTATE.Hidding; dt = 0; } } if (mState == ESTATE.Showed) { if (rect.Contains(e.mousePosition)) { float coeffX = colorSpace.width / sizeCurr; float coeffY = colorSpace.height / sizeCurr; Vector2 localImagePos = (mousePos - startPos); Color res = colorSpace.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y) - 1); SetColor(res); if (isLeftMBtnDragging) { ApplyColor(); } UpdateColorEditFields(false); UpdateColorSliders(false); } else if (rectAlpha.Contains(e.mousePosition)) { float coeffX = alphaGradient.width / sizeCurr; float coeffY = alphaGradient.height / sizeCurr; Vector2 localImagePos = (mousePos - startPosAlpha); Color res = alphaGradient.GetPixel((int)(coeffX * localImagePos.x), colorSpace.height - (int)(coeffY * localImagePos.y) - 1); Color curr = GetColor(); curr.a = res.r; SetColor(curr); if (isLeftMBtnDragging) { ApplyColor(); } UpdateColorEditFields(false); UpdateColorSliders(false); } else if (rectColorEdit.Contains(e.mousePosition)) { UpdateColorEditFields(true); UpdateColorSliders(false); } else if (rectColorSlider.Contains(e.mousePosition)) { UpdateColorEditFields(false); UpdateColorSliders(true); } else { SetColor(SelectedColor); } } }
public void SetState(ESTATE estate) { eState = estate; }