示例#1
0
 void Awake()
 {
     configMenu  = GameObject.Find("Canvas").transform.Find("ConfigMenu").gameObject;
     preview     = GameObject.Find("Canvas").transform.Find("ConfigMenu").Find("PreviewPanel").GetComponent <ActionPreview>();
     canvasUI    = GameObject.Find("Canvas").GetComponent <GraphicRaycaster>();
     eventSystem = EventSystem.current;
     originScale = this.transform.localScale;
 }
示例#2
0
    ActionPreview AddPreview(Card card, CardAction rule)
    {
        ActionPreview preview = previews[curveCount];
        LineRenderer  curve   = curves[curveCount];

        rule.Preview(card, preview);
        ++curveCount;
        return(preview);
    }
示例#3
0
    public void Preview(Card card, ActionPreview preview)
    {
        Player owner     = card.owner;
        Player enemy     = owner.enemy;
        Ship   ownerShip = owner.ship;
        Ship   enemyShip = enemy.ship;
        Map    map       = Map.current;

        int pos1     = ownerShip.position;
        int pos1prev = ownerShip.previousPosition;
        int pos2     = enemyShip.position;
        int pos2prev = enemyShip.previousPosition;

        Vector3 fromPos = map.GetPosition(pos1);

        if (this.ruleType == CardAction.RuleType.attack && this.amount > 0)
        {
            int targetPosition;
            if (ownerShip.direction == 1)
            {
                targetPosition = Mathf.Min(pos2prev, pos1prev + this.range * ownerShip.direction);
            }
            else
            {
                targetPosition = Mathf.Max(pos2prev, pos1prev + this.range * ownerShip.direction);
            }

            if (this.target == CardAction.AttackTarget.All)
            {
                for (int i = 0; i <= 1; ++i)
                {
                    int idx = targetPosition + enemyShip.direction * i;
                    if (idx * ownerShip.direction > pos1 * ownerShip.direction)
                    {
                        Vector3 cell = map.GetPosition(idx);

                        Vector3 toPos    = map.GetPosition(targetPosition + enemyShip.direction * i);
                        int     distance = Mathf.Abs(pos1prev - (targetPosition + enemyShip.direction * i));
                        if (distance <= this.range)
                        {
                            //AddAffected(this.transform.position, toPos, card.rule.color);
                            preview.Set(card, this, fromPos, toPos, this.color);
                            Map.current.tiles[idx].SetHighlight(this.color);
                        }
                        else
                        {
                            preview.Set(card, this, fromPos, toPos, Color.gray);
                            // AddAffected(this.transform.position, toPos, Color.gray);
                        }
                    }
                }
            }
            else if (this.target == CardAction.AttackTarget.Moving)
            {
                int i = 1;
                //for (int i = 1; i < 3; ++i)
                {
                    int idx = targetPosition + enemyShip.direction * i;
                    if (idx * ownerShip.direction > pos1 * ownerShip.direction)
                    {
                        Vector3 cell  = map.GetPosition(idx);
                        Vector3 toPos = map.GetPosition(targetPosition + enemyShip.direction * i);

                        int distance = Mathf.Abs(pos1prev - (targetPosition + enemyShip.direction * i));
                        if (distance <= this.range)
                        {
                            //AddAffected(this.transform.position, toPos, card.rule.color);
                            Map.current.tiles[idx].SetHighlight(this.color);
                            preview.Set(card, this, fromPos, toPos, this.color);
                        }
                        else
                        {
                            //AddAffected(this.transform.position, toPos, Color.gray);
                            preview.Set(card, this, fromPos, toPos, Color.gray);
                        }
                    }
                }
            }
            else if (this.target == CardAction.AttackTarget.notMoving)
            {
                int idx = targetPosition;
                if (idx * ownerShip.direction > pos1 * ownerShip.direction)
                {
                    Vector3 cell  = map.GetPosition(idx);
                    Vector3 toPos = map.GetPosition(targetPosition);

                    int distance = Mathf.Abs(pos1prev - targetPosition);
                    if (distance <= this.range)
                    {
                        //AddAffected(this.transform.position, toPos, card.rule.color);
                        Map.current.tiles[idx].SetHighlight(this.color);
                        preview.Set(card, this, fromPos, toPos, this.color);
                    }
                    else
                    {
                        //AddAffected(this.transform.position, toPos, Color.gray);
                        preview.Set(card, this, fromPos, toPos, Color.gray);
                    }
                }
            }
        }
        if (this.ruleType == CardAction.RuleType.move && this.amount > 0)
        {
            for (int i = 0; i <= this.amount; ++i)
            {
                int     idx  = pos1 + ownerShip.direction * i;
                Vector3 cell = map.GetPosition(idx);
                Map.current.tiles[idx].SetHighlight(this.color);

                Vector3 toPos = map.GetPosition(pos1prev + ownerShip.direction * this.amount);
                preview.Set(card, this, fromPos, toPos, this.color);
                //AddAffected(this.transform.position, toPos, card.rule.color);
            }
        }

        if (this.ruleType == CardAction.RuleType.heal && this.amount > 0)
        {
            int     idx  = pos1;
            Vector3 cell = map.GetPosition(idx);
            Map.current.tiles[idx].SetHighlight(this.color);
            //AddAffected(this.transform.position, cell, card.rule.color);
        }
    }