示例#1
0
    void instantiateListValue(int list, int index, int value)
    {
        GameObject a = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        a.transform.SetParent(lists [list].transform);
        a.transform.localPosition = new Vector3(10f, 0f, (index + 1) * (5 / 6f));
        a.name = index.ToString();
        a.AddComponent <variable> ();
        a.GetComponent <variable>().value = value;

        GameObject c = new GameObject();

        c.name = "Canvas";
        c.AddComponent <Canvas> ();
        c.AddComponent <RectTransform> ();
        c.AddComponent <CanvasScaler> ();
        c.AddComponent <GraphicRaycaster> ();

        c.GetComponent <Canvas> ().renderMode = RenderMode.WorldSpace;
        c.transform.SetParent(a.transform);
        c.GetComponent <RectTransform> ().transform.localPosition = new Vector3(0f, 1f, 0f);
        c.GetComponent <RectTransform> ().transform.Rotate(new Vector3(0, -90, 0));

        c.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 1);
        c.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 1);
        //c.GetComponent<RectTransform> ().localScale = new Vector3 (1f, 1f, 1f);
        c.GetComponent <RectTransform> ().anchorMax = new Vector2(.5f, .5f);
        c.GetComponent <RectTransform> ().anchorMin = new Vector2(.5f, .5f);


        GameObject t = new GameObject();

        t.AddComponent <Text> ();
        t.GetComponent <Text>().text = value.ToString();
        t.name = "Text";
        t.GetComponent <Text>().fontSize  = 30;
        t.GetComponent <Text>().alignment = TextAnchor.LowerCenter;
        t.GetComponent <Text>().font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
        t.AddComponent <RectTransform> ();
        t.AddComponent <CanvasRenderer> ();

        t.transform.SetParent(c.transform);
        t.GetComponent <RectTransform> ().transform.localPosition = new Vector3(0f, 0f, 0f);
        t.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 300);
        t.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100);
        t.GetComponent <RectTransform> ().anchorMax = new Vector2(.5f, .5f);
        t.GetComponent <RectTransform> ().anchorMin = new Vector2(.5f, .5f);
        t.GetComponent <RectTransform> ().transform.localRotation = Quaternion.identity;
        t.GetComponent <RectTransform> ().localScale = new Vector3(0.01f, 0.01f, 0.01f);

        nodes.Add(a);

        variable z = (variable)a.GetComponent(typeof(variable));

        z.Move(new Vector3(-10f, 0f, 0f));
    }
示例#2
0
    void incrementArrayValueByArrayIndex(int list, int index, int otherindex)
    {
        GameObject a = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        a.transform.SetParent(lists [list].transform);
        a.transform.position = lists [list].transform.position + new Vector3(0f, 0f, (index + 1) * (5 / 6f));
        a.name = otherindex.ToString();
        a.AddComponent <variable> ();
        foreach (GameObject geo in nodes)
        {
            if (geo.name == index.ToString() && geo.transform.parent == lists[list].transform)
            {
                a.GetComponent <variable>().value = geo.GetComponent <variable>().value;
                break;
            }
        }


        GameObject c = new GameObject();

        c.name = "Canvas";
        c.AddComponent <Canvas> ();
        c.AddComponent <RectTransform> ();
        c.AddComponent <CanvasScaler> ();
        c.AddComponent <GraphicRaycaster> ();

        c.GetComponent <Canvas> ().renderMode = RenderMode.WorldSpace;
        c.transform.SetParent(a.transform);
        c.GetComponent <RectTransform> ().transform.localPosition = new Vector3(0f, 1f, 0f);
        c.GetComponent <RectTransform> ().transform.Rotate(new Vector3(0, -90, 0));

        c.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 1);
        c.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 1);
        //c.GetComponent<RectTransform> ().localScale = new Vector3 (1f, 1f, 1f);
        c.GetComponent <RectTransform> ().anchorMax = new Vector2(.5f, .5f);
        c.GetComponent <RectTransform> ().anchorMin = new Vector2(.5f, .5f);


        GameObject t = new GameObject();

        t.AddComponent <Text> ();
        t.GetComponent <Text>().text = a.GetComponent <variable>().value.ToString();
        t.name = "Text";
        t.GetComponent <Text>().fontSize  = 30;
        t.GetComponent <Text>().alignment = TextAnchor.LowerCenter;
        t.GetComponent <Text>().font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
        t.AddComponent <RectTransform> ();
        t.AddComponent <CanvasRenderer> ();

        t.transform.SetParent(c.transform);
        t.GetComponent <RectTransform> ().transform.localPosition = new Vector3(0f, 0f, 0f);
        t.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 300);
        t.GetComponent <RectTransform> ().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100);
        t.GetComponent <RectTransform> ().anchorMax = new Vector2(.5f, .5f);
        t.GetComponent <RectTransform> ().anchorMin = new Vector2(.5f, .5f);
        t.GetComponent <RectTransform> ().transform.localRotation = Quaternion.identity;
        t.GetComponent <RectTransform> ().localScale = new Vector3(0.01f, 0.01f, 0.01f);

        variable z = (variable)a.GetComponent(typeof(variable));

        z.Move(new Vector3(0f, 0f, (otherindex - index) * (5 / 6f)));
        foreach (GameObject geo in nodes)
        {
            if (geo.name == otherindex.ToString() && geo.transform.parent == lists[list].transform)
            {
                a.GetComponent <variable>().value += geo.GetComponent <variable>().value;
                break;
            }
        }

        updateArrayValue(list, otherindex, a.GetComponent <variable> ().value);

        //a.SetActive (false);
    }