Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        Hexagon.Coord v      = new  Hexagon.Coord();
        ushort        height = 0;

        Hexagon.Manager.GetSingleton().Position_Coord(StartPoint.transform.position, ref v, ref height);

        Vector3 vp = Hexagon.Manager.GetSingleton().Coord_Position(v, height);

        StartPointDebug.transform.position = vp;
        fTime += Time.deltaTime * 5.0f;
        int index = (int)fTime;

        if (vPath != null)
        {
            if (vPath.Count > 0)
            {
                int i = index % vPath.Count;
                if (PathDebug != null)
                {
                    PathDebug.transform.position = vPath[i];
                }
            }
        }
    }
Esempio n. 2
0
    // 新建一个调试Hexagon对象aa
    public static GameObject NewElement(Hexagon.Coord v, ushort height, float fWeight, int type)
    {
        if (vertex == null)
        {
            vertex = new Vector3[7];

            float fSize    = Hexagon.Manager.GetSingleton().GetHexagonSize() * 0.95f;
            float halfSize = fSize * 0.5f;

            float fSqrt12 = halfSize * 2.0f * Mathf.Sqrt(1.0f / 12.0f);
            float fHeight = 0.1f;

            vertex[0] = Vector3.zero;
            vertex[1] = new Vector3(halfSize, fHeight, -fSqrt12);
            vertex[2] = new Vector3(halfSize, fHeight, fSqrt12);
            vertex[3] = new Vector3(0, fHeight, 2.0f * fSqrt12);

            vertex[4] = new Vector3(-halfSize, fHeight, fSqrt12);
            vertex[5] = new Vector3(-halfSize, fHeight, -fSqrt12);
            vertex[6] = new Vector3(0, fHeight, -2.0f * fSqrt12);

            face = new int[6 * 3]
            {
                0, 6, 5,
                0, 5, 4,
                0, 4, 3,
                0, 3, 2,
                0, 2, 1,
                0, 1, 6
            };
        }

        if (parent == null)
        {
            parent = new GameObject();
            parent.transform.position = Vector3.zero;
            parent.transform.rotation = Quaternion.identity;
        }

        Vector3    pos = Hexagon.Manager.GetSingleton().Coord_Position(v, height);
        GameObject obj = new GameObject();

        obj.name               = v.x + "_" + v.z + "_" + v.y;
        obj.transform.parent   = parent.transform;
        obj.transform.position = pos;
        obj.transform.rotation = Quaternion.identity;;

        HexagonElement ele = obj.AddComponent <HexagonElement>();

        ele.Build(v, height, fWeight, type);
        return(obj);
    }
Esempio n. 3
0
    // 虚函数(继承自MonoBehaviour)
    void Start()
    {
        mActor = gameObject.GetComponent <sdGameActor>();
        if (mActor == null)
        {
            mActor = gameObject.GetComponent <sdGameMonster>();
        }

        Hexagon.Coord kCoord = new Hexagon.Coord();
        for (int i = 0; i < 37; ++i)
        {
            mElementObjectList.Add(HexagonElement.NewElement(kCoord, 0, 0.0f, 3));
        }
    }
Esempio n. 4
0
    // 虚函数(继承自MonoBehaviour)
    void Update()
    {
        if (mActor == null)
        {
            return;
        }

        List <Hexagon.Coord> kCoordList = new List <Hexagon.Coord>();
        ushort usValue = 0;

        if (showDynamicWeight)
        {
            Hexagon.Coord kCoord = new Hexagon.Coord();
            if (Hexagon.Manager.GetSingleton().Position_Coord(this.transform.position, ref kCoord, ref usValue))
            {
                Hexagon.Manager.GetSingleton().GetNeighbourCoord(kCoord, 0, ref kCoordList);
                Hexagon.Manager.GetSingleton().GetNeighbourCoord(kCoord, 1, ref kCoordList);
                Hexagon.Manager.GetSingleton().GetNeighbourCoord(kCoord, 2, ref kCoordList);
                Hexagon.Manager.GetSingleton().GetNeighbourCoord(kCoord, 3, ref kCoordList);
            }
        }

        if (showDynamicWeight)
        {
            for (int i = 0; i < kCoordList.Count; ++i)
            {
                if (i > mElementObjectList.Count)
                {
                    break;
                }

                Hexagon.Coord kCoord = kCoordList[i]
                ;                               Vector3 kPosition = Hexagon.Manager.GetSingleton().Coord_Position(kCoord, usValue);

                mElementObjectList[i].active             = true;
                mElementObjectList[i].transform.position = kPosition;
                mElementObjectList[i].GetComponent <HexagonElement>().hexagonCoord = kCoord;
            }
        }
        else
        {
            foreach (GameObject kElementObject in mElementObjectList)
            {
                kElementObject.active = false;
            }
        }
    }
Esempio n. 5
0
    // 构建一个调试Hexagonaa
    void Build(Hexagon.Coord v, ushort height, float fWeight, int type)
    {
        hexagonCoord = v;
        mValue       = height;
        mType        = type;

        MeshFilter   mf = gameObject.AddComponent <MeshFilter>();
        MeshRenderer r  = gameObject.AddComponent <MeshRenderer>();

        Shader shader = Shader.Find("SDShader/SelfIllum_Object");

        r.material = new Material(shader);

        int     actor       = (height & Hexagon.Tile.ActorWeightMask) >> Hexagon.Tile.ActorWeightShift;
        int     edge        = (height & Hexagon.Tile.EdgeWeightMask) >> Hexagon.Tile.EdgeWeightShift;
        float   actorweight = actor * 0.1f;
        float   edgweight   = edge * 0.1f;
        Vector4 color       = Vector4.one * fWeight * 0.01f;

        if (type == 0)
        {
            color = new Vector4(actorweight, 0, edgweight);
        }
        else if (type == 1)
        {
            color = new Vector4(0, actorweight + 0.2f, edgweight);
        }
        else if (type == 2)
        {
            color = Vector4.one * (actorweight + 0.5f);
        }
        else
        {
            color = Vector4.one;
        }

        r.material.SetVector("_Color", color);

        mf.mesh.vertices  = vertex;
        mf.mesh.triangles = face;
    }