private void OnMouseOver()
 {
     if (arrowObject == null)
     {
         if (eventType == EventTypes.ATTACK)
         {
             CharacterScript character = cell.GetComponentInChildren <CharacterScript>();
             if (character != null)
             {
                 arrowObject = cell.addDecoration(cell.transform.position + new Vector3(0, cell.WalkingHeight, 0), 0, false, true, arrow);
             }
         }
         else if (eventType == EventTypes.MOVE)
         {
             arrowObject = cell.addDecoration(cell.transform.position + new Vector3(0, cell.WalkingHeight, 0), 0, false, true, arrow);
         }
         else if (eventType == EventTypes.SKILL)
         {
             arrowObject = cell.addDecoration(cell.transform.position + new Vector3(0, cell.WalkingHeight, 0), 0, false, true, arrow);
             if (callback != null)
             {
                 callback(cell);
             }
         }
     }
 }
    // Async method for IA Move
    private IEnumerator IAMoveAsync(CharacterScript character, Cell destiny, MoveCharacterToCallBack callback)
    {
        Entity entity = character.transform.GetComponent(typeof(Entity)) as Entity;

        IsoUnity.Cell characterCurrentCell = character.transform.parent.transform.GetComponent(typeof(IsoUnity.Cell)) as IsoUnity.Cell;
        IsoUnity.Cell destinyCell          = SearchCellInMap(destiny);

        try
        {
            entity.mover.maxJumpSize = character.character.attributesWithFormulas.Find(x => x.attribute.id == moveHeight.id).value;
        }
        catch (NullReferenceException e)
        {
            Debug.Log("Character '" + character.character.name + "' doesn't have attribute '" + moveHeight.name + "'");
        }

        try
        {
            CalculateDistanceArea(entity, characterCurrentCell, EventTypes.IA_MOVE, character.character.attributesWithFormulas.Find(x => x.attribute.id == moveRange.id).value, character.character.attributesWithFormulas.Find(x => x.attribute.id == moveHeight.id).value);
        }
        catch (NullReferenceException e)
        {
            Debug.Log("Character '" + character.character.name + "' doesn't have some or any of this attributes: '" + moveHeight.name + "', '" + moveRange.name + "', '" + attackHeight.name + "', '" + attackRange.name + "'");
        }

        yield return(new WaitForSeconds(1f));

        GameObject arrowObject = destinyCell.addDecoration(destinyCell.transform.position + new Vector3(0, destinyCell.WalkingHeight, 0), 0, false, true, arrow);

        yield return(new WaitForSeconds(1f));

        GameObject.Destroy(arrowObject);
        cleanCells();
        yield return(MoveCharacterToAsync(character, destiny, callback));
    }
Exemple #3
0
        public void OnSceneGUI(SceneView scene)
        {
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            RaycastHit info = new RaycastHit();

            GameObject selected = null;
            Ray        ray      = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            if (Physics.Raycast(ray, out info /*, LayerMask.NameToLayer("Cells Layer")*/)) //TODO Arreglar esto porque al parecer la distancia no funciona correctamente
            {
                if (info.collider.transform.IsChildOf(this.map.transform))
                {
                    selected = info.collider.gameObject;
                }
            }

            /**
             * Mouse Events of painting mode
             */

            bool decorateLater = false;

            if (Event.current.isMouse && Event.current.button == 0 && selected != null && Event.current.type == EventType.MouseUp)
            {
                decorateLater = true;
            }

            /**
             * Working zone
             */

            if (selected != null)
            {
                Cell cs = selected.GetComponent <Cell>();
                if (cs != null)
                {
                    FaceNoSC f = (cs != null) ? cs.getFaceByPoint(info.point) : null;
                    if (f != null)
                    {
                        Vector3 position = selected.transform.position;
                        if (cs != null)
                        {
                            position.y = cs.Height;
                        }

                        Vector3[] vertex  = f.SharedVertex;
                        int[]     indexes = f.VertexIndex;

                        Vector3[] puntos = new Vector3[5];
                        for (int i = 0; i < indexes.Length; i++)
                        {
                            puntos[i] = cs.transform.TransformPoint(vertex[indexes[i]]);
                        }
                        if (indexes.Length == 3)//Triangular faces
                        {
                            puntos[3] = cs.transform.TransformPoint(vertex[indexes[2]]);
                        }
                        puntos[puntos.Length - 1] = puntos[0]; // Closes the line
                        Handles.DrawPolyLine(puntos);

                        Vector2 directions = new Vector2(puntos[1].x - puntos[0].x, puntos[2].y - puntos[1].y);
                        int     ang        = 0;
                        if (directions.x == 0f)
                        {
                            if (directions.y == 0f)
                            {
                                ang = 0;
                            }
                            else
                            {
                                ang = 2;
                            }
                        }
                        else
                        {
                            ang = 1;
                        }

                        if (paintingIsoDecoration != null)
                        {
                            if (decorateLater)
                            {
                                GameObject tmpdec = cs.addDecoration(info.point, ang, parallelDecoration, (Event.current.shift) ? false : true, paintingIsoDecoration);

                                if (autoanimate)
                                {
                                    AutoAnimator tmpautoanim = tmpdec.AddComponent <AutoAnimator>() as AutoAnimator;

                                    tmpautoanim.FrameSecuence = this.FrameSecuence;
                                    tmpautoanim.FrameRate     = this.FrameRate;
                                }

                                cs.refresh();
                            }
                            else
                            {
                                map.ghostDecoration(cs, info.point, ang, parallelDecoration, (Event.current.shift) ? false : true, paintingIsoDecoration, 0.5f);
                            }
                        }
                    }
                }
            }
        }