Esempio n. 1
0
    private void SetPath(MoveComponent move)
    {
        float       time = 0;
        VoxelBlocks map  = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();
        float       oa   = move.transform.rotation.eulerAngles.y * 3.1415f / 180;

        for (int i = 1; i < move.pathList.Count; i++)
        {
            Vector3 pos;
            pos = map.LogToWorld(move.pathList [i]) - map.LogToWorld(move.pathList [i - 1]);
            int     n    = 1;
            Vector3 cPos = pos;
            while (i < move.pathList.Count - 1)
            {
                if (cPos != (map.LogToWorld(move.pathList[i + 1]) - map.LogToWorld(move.pathList[i])))
                {
                    break;
                }
                pos += cPos;
                i++;
                n++;
            }
            ;

            Hashtable args  = new Hashtable();
            float     angle = GetAngle(pos);
            if (Mathf.Abs(angle - oa) > 0.1)
            {
                iTween.RotateTo(move.gameObject, iTween.Hash("rotation", new Vector3(0, angle * 180 / 3.1415f, 0), "time", 0.25f, "easeType", "easeInOutBack", "loopType", "none", "delay", time));
                time += 0.25f;
                //获取转向后的前进坐标
                oa = angle;
            }
            pos = RotatePos(pos, -oa);
            args.Add("easeType", iTween.EaseType.linear);
            //移动的整体时间。如果与speed共存那么优先speed
            args.Add("time", move.moveSpeed * n);
            args.Add("loopType", "none");
            args.Add("delay", time);
            time += move.moveSpeed * n;
            // x y z 标示移动的位置。
            args.Add("x", pos.x);
            args.Add("z", pos.z);
            args.Add("onstart", "MoveStart");
            args.Add("onstartparams", move.pathList[i]);
            args.Add("onstarttarget", move.gameObject);

            if (move.pathList.Count - 1 == i)
            {
                int ap = (i - 1) / move.SPD + 1;
                move.GetComponent <StateComponent>().m_actionPoint -= ap;
                move.GetComponent <StateComponent>().Invoke("AnimationEnd", time);
                args.Add("oncomplete", "MoveEnd");

                args.Add("oncompleteparams", move.pathList[i]);
                args.Add("oncompletetarget", move.gameObject);
            }
            iTween.MoveBy(move.gameObject, args);
        }
    }
Esempio n. 2
0
    public void ShowUI(List <Vector3> list, int Type)
    {
        Type--;
        Transform   t    = transform.GetChild(Type);
        string      name = "Prefabs/UI/Simple/" + t.name;
        VoxelBlocks map  = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>();

        List <GameObject> childList = new List <GameObject>();
        int childCount = t.transform.childCount;

        for (int i = 0; i < childCount; i++)
        {
            GameObject child = t.transform.GetChild(i).gameObject;
            childList.Add(child);
        }
        for (int i = 0; i < childCount; i++)
        {
            DestroyImmediate(childList[i]);
        }

        if (list == null)
        {
            return;
        }
        foreach (var pos in list)
        {
            GameObject obj = (GameObject)Resources.Load(name);
            obj = Instantiate(obj);
            obj.transform.parent   = t;
            obj.transform.position = map.LogToWorld(pos);
        }
    }
Esempio n. 3
0
    public void ShowWornArea(BasicEntity entity)
    {
        List <Vector3> list = entity.GetComponent <MonitorComponent>().m_view;

        string      name = "Prefabs/UI/Simple/red";
        VoxelBlocks map  = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>();

        List <GameObject> childList = new List <GameObject>();
        int childCount = entity.transform.childCount;

        for (int i = 0; i < childCount; i++)
        {
            GameObject child = entity.transform.GetChild(i).gameObject;
            childList.Add(child);
        }
        for (int i = 0; i < childCount; i++)
        {
            DestroyImmediate(childList[i]);
        }

        if (list == null)
        {
            return;
        }
        foreach (var pos in list)
        {
            GameObject obj = (GameObject)Resources.Load(name);
            obj = Instantiate(obj);
            obj.transform.parent   = entity.transform;
            obj.transform.position = map.LogToWorld(pos);
        }
    }