Пример #1
0
    // read in the functions, assign shapes and do the layout
    public static void doInit(string fname)
    {
        int levelStart = 10;

        if (functions != null)
        {
            for (int i = 0; i < functionList.Count; i++)
            {
                functions[functionList[i]].clear();
                Destroy(functions[functionList[i]].go);
            }
            functions.Clear();
            functionList.Clear();
        }
        functions    = new Dictionary <uint, functionItem>();
        functionList = new List <uint>();
        StreamReader reader = null;

        // read the functionList and assign verticle levels
        try{
            reader = new StreamReader(fname);
        }catch (FileNotFoundException e) {
            startup.errorString = e.ToString();
            //Debug.Break();
            return;
        }
        string     line;
        int        lastLevel    = -1;
        int        curx         = -1;
        int        maxX         = -1;
        bool       first        = true;
        List <int> funsPerLevel = new List <int>();
        int        levelCount   = 0;
        int        val;

        using (reader)
        {
            while ((line = reader.ReadLine()) != null)
            {
                functionItem fi = new functionItem(line);
                functionList.Add(fi.address);
                if (fi.level > lastLevel && !first)
                {
                    if (curx > maxX)
                    {
                        maxX = curx;
                    }
                    if (curx >= 0)
                    {
                        val = curx + 1;
                        //Debug.Log ("adding funcsPerlevel "+val+" entry "+levelCount);
                        funsPerLevel.Add(val);
                    }
                    else
                    {
                        Debug.Log("New level, but curx is zero??");
                        funsPerLevel.Add(0);
                    }
                    levelCount++;
                    curx = -1;
                }
                else
                {
                    curx++;
                }
                first     = false;
                lastLevel = fi.level;
                fi.x      = curx;
                functions.Add(fi.address, fi);
                //Debug.Log ("line: " + line);
            }
            val = curx + 1;
            //Debug.Log ("adding funcsPerlevel "+val+" entry "+levelCount);
            funsPerLevel.Add(curx + 1);
            //for(int i=0; i < funsPerLevel.Count; i++){
            //	Debug.Log ("level "+i+" has "+funsPerLevel[i]+" functions ");
            //}
        }
        // Adjust the function height per their levels
        Debug.Log("len of funsPerLevel is " + funsPerLevel.Count + " numlevels is " + lastLevel);
        top = lastLevel + levelStart;
        //float currentZ = 0.5F;
        for (int i = 0; i < functionList.Count; i++)
        {
            functionItem fi = functions[functionList[i]];
            fi.y = top - fi.level;
            //fi.z = currentZ;
            //Debug.Log ("look at level "+ fi.level);
            int tmp = (maxX - funsPerLevel[fi.level - 1]) / 2;
            fi.x = fi.x + tmp;
            //currentZ = currentZ * -1.0F;
        }
        assignObjects();
    }
Пример #2
0
    // pick a shape based on quantity of vertices & # of basic blocks
    private static void assignObjects()
    {
        for (int i = 0; i < length(); i++)
        {
            uint         address  = getFunctionAddress(i);
            functionItem fi       = getFunction(address);
            string       polyType = "stellatedPrefab";
            if (fi.num_blocks <= 5)
            {
                polyType = "pyramidPrefab";
            }
            else if (fi.num_blocks <= 6)
            {
                polyType = "octoPrefab";
            }
            else if (fi.num_blocks <= 8)
            {
                polyType = "cubePrefab";
            }
            else if (fi.num_blocks <= 10)
            {
                polyType = "isoPrefab";
            }
            else if (fi.num_blocks <= 20)
            {
                polyType = "decoPrefab";
            }
            else if (fi.num_blocks <= 26)
            {
                polyType   = "thirtysixPrefab";
                fi.subtype = 1;
                fi.xOff    = 0.3f;
                fi.yOff    = -0.2f;
                fi.zOff    = -0.3f;
            }
            else if (fi.num_blocks <= 60)
            {
                polyType = "soccerPrefab";
            }
            else if (fi.num_blocks <= 70)
            {
                polyType   = "buckyPrefab";
                fi.xOff    = -0.3f;
                fi.subtype = 1;

                //}else if (fi.num_blocks <= 74){
                //	polyType = "rhombicPrefab";

                //}else if (fi.num_blocks <= 127){
                //	polyType = "ditriPrefab";
                //	fi.subtype = 1;
            }
            else if (fi.num_blocks <= 80)
            {
                polyType   = "conjecturePrefab";
                fi.subtype = 1;
            }
            else if (fi.num_blocks <= 90)
            {
                polyType = "pentakisPrefab";
                fi.yOff  = -0.32f;
            }
            else if (fi.num_blocks <= 110)
            {
                polyType   = "romanPrefab";
                fi.subtype = 1;
            }
            else if (fi.num_blocks <= 200)
            {
                polyType   = "stellarPrefab";
                fi.subtype = 1;
                fi.xOff    = 0.6f;
                fi.yOff    = 0.1f;
                fi.zOff    = -0.073f;
            }
            else               //stellatedPrefab
            {
                polyType = "stellatedPrefab";
                fi.xOff  = 0.2f;
                fi.yOff  = 0.25f;
                fi.zOff  = -0.17f;
            }
            fi.setType(polyType);
            GameObject go;
            //go = (GameObject) Instantiate(isoPrefab, pt, Quaternion.identity) as GameObject;
            go = (GameObject)Instantiate(Resources.Load(polyType)) as GameObject;
            functionBehaive fb = (functionBehaive)go.GetComponent(typeof(functionBehaive));
            fb.setFunction(fi);
            SphereCollider sc = go.AddComponent <SphereCollider>();

            Vector3 center = new Vector3(fi.xOff / go.transform.localScale.x, fi.yOff / go.transform.localScale.y, fi.zOff / go.transform.localScale.z);
            //sc.radius = 0.6f/go.transform.localScale.x;
            sc.radius = 0.6f / go.transform.localScale.x;
            if (polyType == "stellarPrefab")
            {
                //Debug.Log ("obect "+go.name+" radius is "+sc.radius+" sizex is "+sc.bounds.size.x+" "+sc.bounds.size.y+" "+sc.center.x+" "+sc.center.y);
                //sc.center = Vector3.zero;
                center.y -= 1.0f / go.transform.localScale.y;
                center.x -= 0.5f / go.transform.localScale.x;
            }
            sc.center = center;
            Vector3 pt = new Vector3(fi.x - fi.xOff, fi.y - fi.yOff, fi.z - fi.zOff);
            go.transform.position = pt;
            fi.go = go;
            fi.setShader(startup.shader2);
            fi.setColor(startup.color2);
            fi.setScript(fb);
        }
    }