Exemplo n.º 1
0
    public void CreateByCell(MoveImpl move)
    {
        foreach (GameObject marker in route)
        {
            Destroy(marker);
        }
        route.Clear();

        CFG.Animation route_animation = MoveAnimator.CreateAnimation(move);

        if (route_animation == null)
        {
            return;
        }

        double  cur_length = 0;
        double  angle;
        Vector2 cur_pos = new Vector2();

        while (route_animation.GetPosition(cur_length, out cur_pos, out angle))
        {
            //ToDo change GetPosition to return Vector3 and rotate board to be xy instead of xz
            Vector3    offset            = new Vector3((float)cur_pos.x, 0.1f, (float)cur_pos.y);
            GameObject route_marker_inst = Instantiate(route_marker, offset, transform.rotation) as GameObject;
            route.Add(route_marker_inst);

            cur_length += 0.5;//ToDo this is not good
        }
    }
Exemplo n.º 2
0
    public void PlayRunAnimation(MoveImpl move)
    {
        if (gameObject.tag != "Dude")
        {
            ResetAnimations(false, false);
        }

        if (unit.isTeleport)
        {
            //ToDo change GetPosition to return Vector3 and rotate board to be xy instead of xz
            Vector2 cur_pos = GameBoard.instance.FindTargetCellPlace(move);
            Vector3 offset  = new Vector3((float)cur_pos.x, 0.1f, (float)cur_pos.y);
            gameObject.transform.position = offset;
        }
        else
        {
            GetComponent <Animator> ().SetTrigger("walk");

            cur_animation = CFG.MoveAnimator.CreateAnimation(move);
        }
    }
Exemplo n.º 3
0
    //[RequireComponent(typeof(Animator))]//ToDo and so one

    // Use this for initialization
    void Start()
    {
        //m_Animator = GetComponent<Animator>(); //ToDo and so one

        gameObject.AddComponent <AudioSource> ();

        if (unit != null)
        {
            gameObject.AddComponent <ToolTip> ().SetToolTip(new CardImpl(unit));
        }

        /*var mesh_coll = gameObject.GetComponentInChildren<MeshCollider> ();
         * if (mesh_coll != null)
         *      mesh_coll.enabled = false;
         *
         * var cap_coll = gameObject.GetComponentInChildren<CapsuleCollider> ();
         * if (cap_coll != null)
         *      cap_coll.enabled = false;*/

        animation_by_type = new Dictionary <AnimationInfo.EType, List <AnimationInfo> >();
        foreach (var anim in animations)
        {
            List <AnimationInfo> list = null;
            if (!animation_by_type.TryGetValue(anim.type, out list))
            {
                list = new List <AnimationInfo>();
                animation_by_type.Add(anim.type, list);
            }

            list.Add(anim);
        }

        if (animation_by_type [AnimationInfo.EType.idle].Count > 1)
        {
            List <AnimationInfo> idles = null;
            if (!animation_by_type.TryGetValue(AnimationInfo.EType.idle_action, out idles))
            {
                idles = new List <AnimationInfo> ();
                animation_by_type.Add(AnimationInfo.EType.idle_action, idles);
            }

            idles.AddRange(animation_by_type [AnimationInfo.EType.idle]);
        }

        if (animation_by_type.ContainsKey(AnimationInfo.EType.idle_action))
        {
            time_to_action = DateTime.Now.AddMinutes(GetTimeDilta());
        }

        if (gameObject.tag != "Dude")
        {
            cur_idle = animation_by_type [AnimationInfo.EType.idle] [0].animation;
            Animator animator = GetComponent <Animator> ();
            myController = animator.runtimeAnimatorController;

            ResetAnimations(false, false);
        }

        if (unit != null && unit.oriented_cell.cell != null)
        {
            unit.SetNotificator(this);

            Quaternion rotation = Quaternion.identity;
            //rotation.eulerAngles = new Vector3 (0, unit.command_idx == 0 ? 90 : -90, 0);
            rotation.SetFromToRotation(orientation, unit.command_idx == 0 ? Vector3.right : Vector3.left);

            Vector2 cur_pos = GameBoard.instance.FindCellPlace(unit.oriented_cell);
            transform.rotation = rotation;
            if (unit.isTeleport)
            {
                transform.position = new Vector3(cur_pos.x, 0.1f, cur_pos.y);
            }
            else
            {
                GetComponent <Animator> ().SetTrigger("walk");

                float   shadow   = 10.0f;
                Vector2 from_pos = new Vector2(unit.command_idx == 0 ? -shadow : shadow, cur_pos.y);
                transform.position = new Vector3(from_pos.x, 0.1f, from_pos.y);
                cur_animation      = CFG.MoveAnimator.CreateAnimation(from_pos, cur_pos);
            }

            UnityEngine.Object properties = Resources.Load("Properties", typeof(GameObject));
            GameObject         prop_clone = Instantiate(properties) as GameObject;
            prop_clone.GetComponent <Properties>().dude = this;

            foreach (var render in gameObject.GetComponentsInChildren <Renderer> ())
            {
                foreach (var mat in render.materials)
                {
                    if (Array.Find(colored_textures, obj => mat.mainTexture == obj) != null)
                    {
                        Color col = (unit.command_idx == 0 ? Color.red : Color.green);

                        if (mat.HasProperty("_EmissionMap") && mat.GetTexture("_EmissionMap") != null)
                        {
                            mat.SetColor("_EmissionColor", Color.Lerp(Color.black, col, color_intensity));
                        }
                        else
                        {
                            mat.color = Color.Lerp(Color.white, col, color_intensity);
                        };
                    }
                }
            }

            if (unit.isVampire)
            {
                UnityEngine.Object dark_circle       = Resources.Load("Effects/DarkCircle", typeof(GameObject));
                GameObject         dark_circle_clone = Instantiate(dark_circle) as GameObject;

                dark_circle_clone.transform.SetParent(transform);
                dark_circle_clone.transform.position = transform.position;
            }

            if (unit.armor > 0)
            {
                UnityEngine.Object shield       = Resources.Load("Effects/Shield", typeof(GameObject));
                GameObject         shield_clone = Instantiate(shield) as GameObject;

                shield_clone.transform.SetParent(transform);
                shield_clone.transform.position = transform.position;
            }
        }
    }