Example #1
0
    public void DropPreview()
    {
        //grab preview object from actioncontroller
        preview = actionController.GetPreview(actionController.currentAction);

        //if the object is grabbed, move it to the mouse coords
        if (preview != null)
        {
            int x = (int)touchCoords.x;
            int y = (int)touchCoords.z;

            preview.transform.position    = new Vector3(x, 0, y);
            preview.transform.eulerAngles = new Vector3(0, actionController.buildingRotation, 0);

            //if action is a strucutre, align it
            Action act = actionController.currentAction;
            if (act.Do == "place")
            {
                StructureData data = StructureDatabase.structureData[act.What];

                int   sizex  = data.Sizex;
                int   sizey  = data.Sizey;
                float alignx = data.Alignx;
                float aligny = data.Aligny;

                //switch size dimensions if building is rotated
                if (actionController.buildingRotation % 180 != 0)
                {
                    int tempszx = sizex;
                    int tempszy = sizey;
                    sizex = tempszy;
                    sizey = tempszx;

                    float tempalignx = alignx;
                    float tempaligny = aligny;
                    alignx = tempaligny;
                    aligny = tempalignx;
                }

                preview.transform.position += new Vector3(alignx, 0, aligny);
            }

            Material m = cannotDo;
            if (actionController.CanDo(act, x, y))
            {
                m = canDo;
            }
            preview.GetComponent <MeshRenderer>().material = m;

            for (int a = 0; a < preview.GetComponent <MeshRenderer>().materials.Length; a++)
            {
                preview.GetComponent <MeshRenderer>().materials[a] = m;
            }
        }
    }
Example #2
0
    void DropPreview()
    {
        //grab preview object from actioncontroller
        preview = actionController.GetPreview(actionController.currentAction);
        Transform prevTrans = preview.transform;

        //if the object is grabbed, move it to the mouse coords
        if (preview != null)
        {
            //set position including elevation
            Vector3 pos = mouseCoords.GetVector3();
            pos.y = worldController.GetObjectFloat((int)pos.x, (int)pos.z);
            prevTrans.position = pos;

            //if action is a strucutre, align it
            Action act = actionController.currentAction;
            if (act.Do == "place")
            {
                StructureData data = StructureDatabase.GetData(act.What);

                int   sizex  = data.sizex;
                int   sizey  = data.sizey;
                float alignx = data.Alignx;
                float aligny = data.Aligny;

                //switch size dimensions if building is rotated
                if (actionController.buildingRotation % 180 != 0)
                {
                    int tempszx = sizex;
                    int tempszy = sizey;
                    sizex = tempszy;
                    sizey = tempszx;

                    float tempalignx = alignx;
                    float tempaligny = aligny;
                    alignx = tempaligny;
                    aligny = tempalignx;
                }

                //BELOW FOR WHEN WE WANT THE CAMERA FACING BUILDINGS
                if (Settings.oldGraphics)
                {
                    if (sizex == sizey && !data.hasRoadTiles && !data.hasWaterTiles)
                    {
                        prevTrans.eulerAngles = cameraController.transform.transform.eulerAngles;
                    }
                    else
                    {
                        prevTrans.eulerAngles = new Vector3(0, actionController.buildingRotation, 0);
                    }
                }
                //FOR NORMAL 3D
                else
                {
                    prevTrans.eulerAngles = new Vector3(0, actionController.buildingRotation, 0);
                }

                prevTrans.position += new Vector3(alignx, 0, aligny);
            }

            Material mat = new Material(canDo);

            //if cannot do, make it red
            if (actionController.CanDo(act, mouseCoords.x, mouseCoords.y))
            {
                mat.color = new Color(1, 1, 1, .5f);
            }
            else
            {
                mat.color = new Color(1, 0, 0, .5f);
            }

            foreach (Transform child in prevTrans)
            {
                Material[] mats = child.GetComponent <MeshRenderer>().materials;
                for (int a = 0; a < mats.Length; a++)
                {
                    mats[a] = mat;
                }
                child.GetComponent <MeshRenderer>().materials = mats;
            }
        }
    }