Esempio n. 1
0
    static Vector3 index_to_position(int i, Texture2D aTex)
    {
        int x = i % aTex.width - aTex.width / 2;
        int y = i / aTex.width - aTex.height / 2;

        return(new Vector3(-BodyManager.convert_units(x), BodyManager.convert_units(y)));
    }
Esempio n. 2
0
    public static void resize_camera(Camera aCam, Vector2 aSize, float aDistance = 1)
    {
        //TODO what if camera is not orthographic
        float texRatio = aSize.x / (float)aSize.y;
        float camRatio = aCam.aspect;

        if (camRatio > texRatio) //match width
        {
            aCam.orthographicSize = BodyManager.convert_units(aSize.x / camRatio) / 2.0f;
        }
        else
        {
            aCam.orthographicSize = BodyManager.convert_units(aSize.y) / 2.0f;
        }
    }
Esempio n. 3
0
    GameObject create_object(ZgJointId aId, Texture2D aTex, Vector2 aDim, List <Vector3> aAttach)
    {
        GameObject parent = new GameObject("genParent" + aId.ToString());
        //GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        //sphere.transform.localScale = Vector3.one * 0.2f;
        //sphere.transform.parent = parent.transform;
        GameObject kid = (GameObject)GameObject.Instantiate(ManagerManager.Manager.mReferences.mPlanePrefab);

        //GameObject kid = (GameObject)GameObject.CreatePrimitive(PrimitiveType.Plane); //TODO use prefab instead
        kid.GetComponent <Renderer>().material             = new Material(ManagerManager.Manager.mReferences.mDefaultCharacterShader);
        kid.GetComponent <Renderer>().material.mainTexture = aTex;
        kid.transform.rotation = Quaternion.AngleAxis(90, Vector3.right) * kid.transform.rotation;

        kid.transform.localScale = new Vector3(BodyManager.convert_units(aDim.x) / 10.0f, 1, BodyManager.convert_units(aDim.y) / 10.0f) * GameConstants.SCALE;
        kid.transform.position   = -aAttach[0] * GameConstants.SCALE;
        kid.transform.parent     = parent.transform;

        mParts[aId] = parent;
        return(parent);
    }
    public void focus_camera_on_element(FlatElementBase aElement)
    {
        Rect focus = aElement.BoundingBox;
        //TODO what if camera is not orthographic
        float texRatio = focus.width / (float)focus.height;
        float camRatio = this.Camera.aspect;

        if (camRatio > texRatio) //match width
        {
            Interpolator.TargetOrthographicHeight = BodyManager.convert_units(focus.width / camRatio) / 2.0f;
        }
        else
        {
            Interpolator.TargetOrthographicHeight = BodyManager.convert_units(focus.height) / 2.0f;
        }
        Vector3 position = aElement.HardPosition;

        position.z = Center.z + Distance;
        Interpolator.TargetSpatialPosition = new SpatialPosition(position, Camera.transform.rotation);
    }