public bool AddOneIns(int x, int y, SensorAndAction newOne) { if (IsSensor(newOne)) { if (CanPlaceSensor(x, y, newOne)) { instructions[x, y] = newOne; return(true); } else { return(false); } } else { if (CanPlaceAction(x, y, newOne)) { instructions[x, y] = newOne; return(true); } else { return(false); } } }
public void OnPointerClick(PointerEventData data) { SensorAndAction oppositeOne = GetOpposite(currentType); //not sensor if (oppositeOne == SensorAndAction.None) { return; } SpriteClick.Play(); //is sensor if (isPositive) { receivingImage.color = new Color(receivingImage.color.r, receivingImage.color.g, receivingImage.color.b, 0.5f); } else { receivingImage.color = new Color(receivingImage.color.r, receivingImage.color.g, receivingImage.color.b, 1f); } isPositive = !isPositive; currentType = oppositeOne; InstructionController.AddOneIns(x, y, oppositeOne); }
private bool CanPlaceSensor(int x, int y, SensorAndAction tobechecked) { if (y == 0 || IsSensor(instructions[x, y - 1])) { return(true); } else { return(false); } }
public bool IsSensor(SensorAndAction tobechecked) { if (tobechecked == SensorAndAction.Forward || tobechecked == SensorAndAction.Back || tobechecked == SensorAndAction.Left || tobechecked == SensorAndAction.Right || tobechecked == SensorAndAction.Open) { return(false); } else { return(true); } }
private bool IsConsumeTime(int x, int y, SensorAndAction action) { bool isConsumeTime = false; if (action == SensorAndAction.Forward || action == SensorAndAction.Open) { for (int i = 0; i < y; i++) { if (instructions[x, i] == SensorAndAction.Forward || instructions[x, i] == SensorAndAction.Open) { isConsumeTime = true; } } } return(isConsumeTime); }
private bool CanPlaceAction(int x, int y, SensorAndAction action) { if (y != 0) { if (!IsConsumeTime(x, y, action)) { return(true); } else { return(false); } } else { return(false); } }
private SensorAndAction GetOpposite(SensorAndAction type) { if (type == SensorAndAction.Monster) { return(SensorAndAction._Monster); } if (type == SensorAndAction._Monster) { return(SensorAndAction.Monster); } else if (type == SensorAndAction.Obstacle) { return(SensorAndAction._Obstacle); } else if (type == SensorAndAction._Obstacle) { return(SensorAndAction.Obstacle); } else if (type == SensorAndAction.Route) { return(SensorAndAction._Route); } else if (type == SensorAndAction._Route) { return(SensorAndAction.Route); } else if (type == SensorAndAction.Box) { return(SensorAndAction._Box); } else if (type == SensorAndAction._Box) { return(SensorAndAction.Box); } else { return(SensorAndAction.None); } }
public void OnDrop(PointerEventData data) { if (receivingImage == null) { return; } //get locate var container = this.gameObject.transform.parent; y = getOrder(container); // 0 - 4 var singleInstruction = container.parent; x = getOrder(singleInstruction); //0 - inf //recongize which type Sprite dropSprite = GetDropSprite(data); if (dropSprite != null) { DragRelease.Play(); //record type currentType = GetTypeFromStr(dropSprite.name); bool needEnableDelete = InstructionController.instructions[x, y] == SensorAndAction.None; if (InstructionController.AddOneIns(x, y, currentType)) { isDrop = true; isPositive = true; //active next one & next line if (y < InstructionController.GetLength() - 1) { container.parent.GetChild(y + 1).gameObject.SetActive(true); } if (x < InstructionController.GetHeight() - 1) { singleInstruction.parent.GetChild(x + 1).GetChild(0).gameObject.SetActive(true); } //change png receivingImage.color = new Color(receivingImage.color.r, receivingImage.color.g, receivingImage.color.b, 1f); containerImage.color = new Color(containerImage.color.r, containerImage.color.g, containerImage.color.b, 0f); //receivingImage.overrideSprite = dropSprite; receivingImage.sprite = dropSprite; if (needEnableDelete) { gameObject.GetComponent <DragToDelete>().enabled = true; if (y > 0) { gameObject.transform.parent.parent.transform.GetChild(y - 1).GetChild(0).gameObject .GetComponent <DragToDelete>().enabled = false; } } } } }
private Sprite GetDropSprite(PointerEventData data) { var originalObj = data.pointerDrag; if (originalObj == null) { return(null); } var dragMe = originalObj.GetComponent <DragMe>(); if (dragMe == null) { return(null); } var srcImage = originalObj.GetComponent <Image>(); if (srcImage == null) { return(null); } SensorAndAction type = GetTypeFromStr(srcImage.sprite.name); int childIndex = -1; switch (type) { case SensorAndAction.Forward: childIndex = 0; break; case SensorAndAction.Back: childIndex = 1; break; case SensorAndAction.Left: childIndex = 2; break; case SensorAndAction.Right: childIndex = 3; break; case SensorAndAction.Open: childIndex = 4; break; case SensorAndAction.Route: childIndex = 5; break; case SensorAndAction.Obstacle: childIndex = 6; break; case SensorAndAction.Box: childIndex = 7; break; case SensorAndAction.Monster: childIndex = 8; break; case SensorAndAction.None: childIndex = -1; break; } return(BackUpImage.transform.GetChild(childIndex).gameObject.GetComponent <Image>().sprite); }