Beispiel #1
0
        public static PlaneMeshBuilder Create(vec2i size, IEnumerable <vec2> points)
        {
            PlaneMeshBuilder mesh = new PlaneMeshBuilder(4, 2);

            int vi = 0;

            uint[] vs = new uint[size.x * size.y];
            foreach (var p in points)
            {
                vs[vi++] = mesh.CreateVertex(p.xzy(0), vec3.up);
            }

            vi = 0;
            for (int i = 0; i < vs.Length - size.x - 1; i++, vi++)
            {
                if (((vi + 1) % size.x) == 0)
                {
                    continue;
                }

                mesh.MakeQuad(vs[vi + 0 + size.x], vs[vi + 1 + size.x], vs[vi + 1], vs[vi + 0]);
            }

            return(mesh);
        }
 public RoleRecord_profile(int race, unitData unit, List <int> careers, List <int> skills, List <int> items, vec2i pos)
 {
     this.race     = race;
     unit_profile  = unit.getProflie();
     this.careers  = careers;
     this.skills   = skills;
     this.items    = items;
     this.location = pos;
 }
Beispiel #3
0
 public RoleRecord(RoleRecord_profile profile)
 {
     race     = profile.race;
     careers  = profile.careers;
     skillNos = profile.skills;
     itemNos  = profile.items;
     data     = new unitData(profile.unit_profile);
     location = profile.location;
 }
Beispiel #4
0
    public void createGroup(List <RoleRecord> units, vec2i matric, Vector2 leftUp, Vector2 rightDown)
    {
        Debug.Log("創建group!!!!!!!!!!!!!!!!");
        GameObject[,] girds = new GameObject[matric.y, matric.x];
        Vector2 startPoint;
        float   width       = rightDown.x - leftUp.x;
        float   height      = leftUp.y - rightDown.y;
        float   gapSize     = 0;
        float   girdSize    = 0;
        float   fieldAspect = width / height;
        float   girdAspect  = (float)matric.x / (float)matric.y; //(float)(girdSize.x) / (float)girdSize.y;
        float   unitPixel   = prafeb[0].GetComponent <SpriteRenderer>().sprite.pixelsPerUnit;
        float   spriteSize  = prafeb[0].GetComponent <SpriteRenderer>().sprite.bounds.size.x;
        //Debug.Log("field aspect:" + fieldAspect +"gird aspect:"+girdAspect);
        //Debug.Log("left up:" + leftUp + "right down:" + rightDown);
        int bigger = matric.x;

        if (matric.y > matric.x)
        {
            bigger = matric.y;
        }
        if (fieldAspect > girdAspect)
        {
            Vector2 boundWidth = new Vector2((width - height) / 2, 0);
            //Debug.Log("bound width:" + boundWidth);
            startPoint = leftUp + boundWidth;
            gapSize    = (height * gapPercentage) / (bigger + 1);
            girdSize   = (height * (1 - gapPercentage) / bigger);
            //Debug.Log("girdSize:"+ girdSize);
        }
        else
        {
            startPoint = leftUp;
            gapSize    = width * gapPercentage / (bigger + 1);
            girdSize   = width * (1 - gapPercentage) / bigger;
        }
        Vector2 gapVec      = new Vector2(gapSize, -gapSize);
        Vector2 halfGridVec = new Vector2(girdSize / 2, -girdSize / 2);
        float   gScale      = girdSize / spriteSize;

        //Debug.Log("girdSize:" + girdSize + " spriteSize:" + spriteSize + "gscale:" + gScale);
        //Debug.Log("start point x:" + startPoint.x + "gap x:"+gapSize +"halfGridVec x:"+girdSize/2);
        for (int y = 0; y < matric.y; y++)
        {
            for (int x = 0; x < matric.x; x++)
            {
                Vector2 pos = startPoint + new Vector2(x * (gapSize + girdSize), -y * (gapSize + girdSize)) + halfGridVec + gapVec;

                GameObject g = createGrid(pos, gScale, new vec2i(x, y), (y * matric.x + x) % prafeb.Count);
                //girds.Add(g);
                girds[y, x] = g;
                //g.name = "gird" + x + "-" + y;
            }
        }
        girdGroups.Add(girds);
    }
Beispiel #5
0
    /*public void init(List<RoleRecord> units, vec2i size)
     * {
     *  this.units = units;
     *  Vector2 startPoint;
     *  float gapSize = 0;
     *  float girdSize = 0;
     *  float fieldAspect = Camera.main.pixelWidth / (0.5f * Camera.main.pixelHeight);
     *  float girdAspect = (float)size.x / (float)size.y;
     *  float unitPixel = girds[0].GetComponent<SpriteRenderer>().sprite.pixelsPerUnit;
     *  float spriteSize = girds[0].GetComponent<SpriteRenderer>().sprite.bounds.size.x;
     *  float cameraHeight_half = Camera.main.orthographicSize;
     *  float cameraWidth_half = Camera.main.orthographicSize * Camera.main.aspect;
     *  Debug.Log("field Asp:" + fieldAspect);
     *  Debug.Log("gird Asp" + girdAspect);
     *  Debug.Log("cameraWidth_half:" + cameraWidth_half);
     *  Debug.Log("cameraHeight_half:" + cameraHeight_half);
     *  if (fieldAspect > girdAspect)
     *  {
     *
     *      int boundWidth = (int)(Camera.main.pixelWidth - 0.5f * Camera.main.pixelHeight);
     *
     *      startPoint = Camera.main.ScreenToWorldPoint(new Vector2(0,Camera.main.pixelHeight*0.5f));
     *      Debug.Log("boundWidth:" + boundWidth + " screen space start position:" + new Vector2(boundWidth, Camera.main.pixelHeight * 0.5f) + " world space start position:" + startPoint);
     *      gapSize = (cameraHeight_half * gapPercentage / (size.y + 1));
     *      Debug.Log("gapSize:" + gapSize);
     *      girdSize = (cameraHeight_half *  (1-gapPercentage) / size.y);
     *      Debug.Log("girdSize:" + girdSize);
     *  }
     *  else
     *  {
     *      startPoint = Camera.main.ScreenToWorldPoint(new Vector2(0, Camera.main.pixelHeight * 0.5f));
     *      Debug.Log("start point:"+startPoint+"camera width half:"+cameraWidth_half*2);
     *      gapSize = cameraWidth_half *2* gapPercentage / (size.x + 1);
     *
     *      girdSize = cameraWidth_half *2* (1 - gapPercentage) / size.x;
     *      Debug.Log("gapsize before:" + cameraWidth_half * 2 * gapPercentage);
     *  }
     *  //widthPercentage = (1-gapPercentage)/
     *  Vector2 gapVec = new Vector2(gapSize, -gapSize);
     *  Vector2 halfGridVec = new Vector2(girdSize / 2,-girdSize / 2);
     *  float gScale = girdSize / spriteSize;
     *  Debug.Log("girdSize:" + girdSize + " spriteSize:" + spriteSize + "gscale:" + gScale);
     *  for (int y = 0; y < size.y; y++)
     *  {
     *      for(int x = 0; x < size.x; x++)
     *      {
     *          Vector2 pos = startPoint + new Vector2(x * (gapSize + girdSize), -y * (gapSize + girdSize))+halfGridVec+gapVec;
     *
     *          GameObject g= createGrid(pos, gScale,new vec2i(x,y));
     *          g.name = "gird" + x + "-" + y;
     *      }
     *  }
     * }
     */
    public GameObject createGrid(Vector2 pos, float scale, vec2i index, int girdNo)
    {
        int girdIdx = index.y * index.x + index.x;
        //Debug.Log("gird x:" + index.x + " y:" + index.y + " girdIdx:" + girdIdx);
        GameObject gird = Instantiate(prafeb[girdNo], pos, Quaternion.Euler(0, 0, 0));

        gird.transform.localScale    = new Vector2(scale, scale);
        gird.GetComponent <gird>().x = index.x;
        gird.GetComponent <gird>().y = index.y;
        return(gird);
    }
Beispiel #6
0
        public uint[] AddPlane(IEnumerator <Tuple <vec3, vec3> > vertices, vec2i step, bool revert = false)
        {
            int cn = step.x + 1;
            int rn = step.y + 1;
            int vn = cn * rn;
            int tn = step.x * step.y * 2;

            uint[] result = new uint[vn];

            Grow(vn, tn);

            int ri = 0;
            int i  = 0;
            int j  = 0;

            while (vertices.MoveNext())
            {
                var v = vertices.Current;
                result[ri++] = CreateVertex(v.Item1, v.Item2);

                j++;
                if (j == rn)
                {
                    i++;
                    j = 0;
                    if (i == cn)
                    {
                        break;
                    }
                }
            }

            int vi = 0;

            for (i = 0; i < tn / 2; i++, vi++)
            {
                if (((vi + 1) % rn) == 0)
                {
                    vi++;
                }

                if (!revert)
                {
                    MakeQuad(result[vi + 0], result[vi + 1], result[vi + 1 + rn], result[vi + 0 + rn]);
                }
                else
                {
                    MakeQuad(result[vi + 1 + rn], result[vi + 1], result[vi + 0], result[vi + 0 + rn]);
                }
            }

            return(result);
        }
Beispiel #7
0
        public aabb2i Extend(vec2i p)
        {
            if (isEmpty)
            {
                return(new aabb2i(p, p));
            }

            var min = vec2i.Min(a, p);
            var max = vec2i.Max(b, p);

            return(new aabb2i(min, max));
        }
Beispiel #8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            vec2i obj = (vec2i)fieldInfo.GetValue(property.serializedObject.targetObject);

            Rect contentPosition = EditorGUI.PrefixLabel(position, label);

            contentPosition.width      *= .25f;
            EditorGUIUtility.labelWidth = 14f;
            EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("x"), new GUIContent("X"));
            contentPosition.x          += contentPosition.width;
            EditorGUIUtility.labelWidth = 14f;
            EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("y"), new GUIContent("Y"));
            contentPosition.x += contentPosition.width;
            //EditorGUIUtility.labelWidth = 14f;
            //EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("z"), new GUIContent("Z"));
            contentPosition.x += contentPosition.width;

            EditorGUI.SelectableLabel(contentPosition, "l: " + obj.length.ToString());
        }
Beispiel #9
0
        public uint[] AddPlane(plane p, vec3 origin, vec2 size, vec2i step, vec3 forward)
        {
            var  n     = MathEx.Convert.ToVec3(p.normal);
            vec3 right = vec3.Cross(n, forward);
            int  cn    = step.x + 1;
            int  rn    = step.y + 1;
            int  vn    = cn * rn;
            int  tn    = step.x * step.y * 2;
            vec2 dv    = size.Div(step);

            uint[] result = new uint[vn];

            Grow(vn, tn);

            int  ri = 0;
            vec3 v;

            for (int i = 0; i < cn; i++)
            {
                v = origin + i * right * dv.x;
                for (int j = 0; j < rn; j++, v += forward * dv.y)
                {
                    result[ri++] = CreateVertex(v, n);
                }
            }

            int vi = 0;

            for (int i = 0; i < tn / 2; i++, vi++)
            {
                if (((vi + 1) % rn) == 0)
                {
                    vi++;
                }

                MakeQuad(result[vi + 0], result[vi + 1], result[vi + 1 + rn], result[vi + 0 + rn]);
            }

            return(result);
        }
Beispiel #10
0
 public uint[] AddPlane(plane p, vec3 origin, vec2 size, vec2i step)
 {
     return(AddPlane(p, origin, size, step, vec3.forward));
 }
Beispiel #11
0
 public aabb2i(vec2i a, vec2i b)
 {
     this.a = a;
     this.b = b;
 }