Exemplo n.º 1
0
    public void UnitMode()
    {
        Debug.LogFormat("mode==unit:{0},lastMode==unit:{1}", this.mode == DisplayMode.UNIT, this.lastMode == DisplayMode.UNIT);
        if (this.lastMode != DisplayMode.UNIT)
        {
            Debug.Log("re execute " + grammars[0].name);
            this.lastMode = DisplayMode.UNIT;
            this.mode     = DisplayMode.UNIT;
            grammars[0].Execute();
            Debug.Log("finish reExecute");
            return;
        }

        mode = DisplayMode.UNIT;
        foreach (ShapeObject o in grammars[0].stagedOutputs[grammars[0].stagedOutputs.Count - 1].shapes)
        {
            o.Show(false);
        }
        if (unitSOS == null)
        {
            unitSOS = new List <ShapeObject>();
        }
        //if (unitSOS == null || unitSOS.Count<1) return;
        if (units == null || units.Count < 1)
        {
            return;
        }
        int dif = unitSOS.Count - units[0].Count;

        if (dif > 0)
        {
            SGUtility.RemoveExtraShapeObjects(ref unitSOS, dif);
        }
        for (int i = 0; i < units[0].Count; i++)
        {
            if (i >= unitSOS.Count)
            {
                unitSOS.Add(ShapeObject.CreateBasic());
            }
            Meshable m = (Meshable)units[0][i].Clone();
            SGUtility.ScaleForm(m, new Vector3(0.9f, 0.7f, 1f), Alignment.Center3D);
            unitSOS[i].SetMeshable(m);
            unitSOS[i].Show(true);
        }
    }
Exemplo n.º 2
0
        public override void Execute()
        {
            //Debug.Log("Executing unit, input count="+inputs.shapes.Count);
            //if(sgbuilding!=null && sgbuilding.mode==SGBuilding.DisplayMode.PROGRAM)
            int           counter = -1;
            List <string> names   = new List <string>();
            Dictionary <string, Color> namedColors = new Dictionary <string, Color>();
            string namePrefix = outputs.names[0];

            outMeshables.Clear();
            List <Color> colors = new List <Color>();

            //Dictionary<float, List<Meshable>> sortedContainer = new Dictionary<float, List<Meshable>>();

            foreach (ShapeObject o in inputs.shapes)
            {
                if (o.name == inputs.names[0])
                {
                    Meshable[] units  = SGUtility.DivideFormToLength(o.meshable, 3, 0);
                    float      d      = o.Size[2];
                    string     mbname = namePrefix + d.ToString();
                    if (!namedColors.ContainsKey(mbname))
                    {
                        counter++;
                        int   colorIndex = counter % SchemeColor.ColorSetDefault.Length;
                        Color c          = SchemeColor.ColorSetDefault[colorIndex];
                        namedColors.Add(mbname, c);
                    }
                    foreach (Meshable mb in units)
                    {
                        mb.name = mbname;
                        mb.Scale(new Vector3(0.9f, 0.8f, 1f), mb.bbox.vects, mb.bbox.GetOriginFromAlignment(Alignment.Center), false);
                    }
                    outMeshables.AddRange(units);
                }
                if (inputs.names.Count > 1 && o.name == inputs.names[1])
                {
                    Meshable[] units  = SGUtility.DivideFormToLength(o.meshable, 3, 2);
                    float      d      = o.Size[2];
                    string     mbname = namePrefix + d.ToString();
                    if (!namedColors.ContainsKey(mbname))
                    {
                        counter++;
                        Color c = SchemeColor.ColorSetDefault[counter];
                        namedColors.Add(mbname, c);
                    }
                    foreach (Meshable mb in units)
                    {
                        mb.name = mbname;
                        mb.Scale(new Vector3(1f, 0.8f, 0.9f), mb.bbox.vects, mb.bbox.GetOriginFromAlignment(Alignment.Center), false);
                    }
                    outMeshables.AddRange(units);
                }
            }

            int dif = outputs.shapes.Count - outMeshables.Count;

            SGUtility.RemoveExtraShapeObjects(ref outputs.shapes, dif);
            //Debug.Log("outMeshable count=" + outMeshables.Count);
            for (int i = 0; i < outMeshables.Count; i++)
            {
                if (i >= outputs.shapes.Count)
                {
                    outputs.shapes.Add(ShapeObject.CreateBasic());
                }
                Meshable m = outMeshables[i];
                //Debug.Log("meshable=" + m.ToString());

                outputs.shapes[i].SetMeshable(m);
                outputs.shapes[i].name       = m.name;
                outputs.shapes[i].parentRule = this;
                outputs.shapes[i].GetComponent <MeshRenderer>().material.color = namedColors[m.name];
            }
        }