Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     CoreWrapper.AOutput(Output);
     //GLB.GBK = Encoding.GetEncoding("GB2312");
     //IntPtr o = g_CreateFile(Encoding.Default.GetBytes("ablblabla.bla"));
     UR_Register.Init();
     CoreWrapper.Init();
 }
Exemplo n.º 2
0
 void Start()
 {
     _canny1Bar.onValueChanged.AddListener(Canny1Changed);
     _canny2Bar.onValueChanged.AddListener(Canny2Changed);
     _threshold1Bar.onValueChanged.AddListener(Threshold1Changed);
     _threshold2Bar.onValueChanged.AddListener(Threshold2Changed);
     m_canShow = false;
     core      = CoreWrapper.GetInstance();
     core.InitCore();
     core.OpenVideoStream(0);
     core.GetCameraFrame();
 }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        core     = CoreWrapper.GetInstance();
        cameraOk = core.OpenVideoStream(0);

        if (!cameraOk)
        {
            showPopUp = true;
            return;
        }

        this.frame   = core.GetCameraFrame();
        this.texture = new Texture2D(core.GetFrameWidth(), core.GetFrameHeight(), TextureFormat.BGRA32, false);
        this.transform.localScale = new Vector3(core.GetFrameWidth(), core.GetFrameHeight(), 1);

        //  Camera.main.transform.position = this.transform.position;
        //  Camera.main.transform.Translate(Vector3.back);
        Camera.main.orthographicSize = core.GetFrameHeight() / 2f + 2;
        m_FinishedBuild = false;
    }
Exemplo n.º 4
0
 public static unsafe bool LoadSpr(string filename, ref List <Texture2D> SprResList)
 {
     byte[] filedata;
     if (!OpenFile(filename, out filedata))
     {
         try
         {
             int size = CoreWrapper.GetFileSize(GLB.GBK.GetBytes(filename));
             Debug.Log("Loading " + filename);
             //Debug.Log("Size " + size);
             if (size <= 0)
             {
                 return(false);
             }
             IntPtr read = CoreWrapper.LoadFile(GLB.GBK.GetBytes(filename));
             filedata = new byte[size];
             Marshal.Copy(read, filedata, 0, size);
         }
         catch (Exception e)
         {
             Debug.Log(e);
         }
     }
     if (filedata == null)
     {
         Debug.LogError("Load Image Error: " + filename);
         return(false);
     }
     if (filename.IndexOf(".spr") > 0)
     {
         return(LoadSpr(filename, filedata, ref SprResList));
     }
     else
     {
         //Debug.LogError("Load Image" + filename);
         Texture2D tx = new Texture2D(1, 1);
         tx.LoadImage(filedata);
         SprResList.Add(tx);
         return(true);
     }
 }
Exemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        string file = @"\UImage\第三版\ib系统\ib系统_底图.spr";

        CoreWrapper.InitFile();
        int size = CoreWrapper.GetFileSize(GLB.GBK.GetBytes(file));

        Debug.Log("size = " + size);
        byte[] data = new byte[size];
        //int read = CoreWrapper.LoadFile2(GLB.GBK.GetBytes(file), ref data, size);
        IntPtr read = CoreWrapper.LoadFile(GLB.GBK.GetBytes(file));

        Marshal.Copy(read, data, 0, size);
        Debug.Log(read);

        sr = gameObject.GetComponent <SpriteRenderer>();
        //Sprite sp = sr.sprite;
        //Color32[] colors1 = sp.texture.GetPixels32();
        //Debug.Log(colors1);


        //Color32[] colors = new Color32[100 * 100];
        //for (int i = 0; i < 100 * 100; i++)
        //{
        //    byte c = (byte)i;
        //    colors[i] = new Color32(c, c, c, c);
        //}
        //Texture2D tx = new Texture2D(100, 100);
        //tx.SetPixels32(colors);
        //Sprite newsp = Sprite.Create(tx, new Rect(0f, 0f, 100f, 100f), new Vector2(0.5f, 0.5f));

        Texture2D tx    = SprMgr.GetInstance().LoadSpr(sprPath, 0);
        Sprite    newsp = Sprite.Create(tx, new Rect(0f, 0f, tx.width, tx.height), new Vector2(0f, 1f));

        sr.sprite = newsp;
        sr.flipY  = true;
        //transform.localPosition -= new Vector3(tx.width / 200, tx.height / 200, 0f);
    }
Exemplo n.º 6
0
    private void initializeMaze()
    {
        Debug.Log("Initgo");


        GameObject prefabObstacle = ((GameObject)Resources.Load("Prefabs/" + Const.OBSTACLE_PREFAB_NAME, typeof(GameObject)));

        GameObject o         = Instantiate(prefabObstacle, Vector3.zero, Quaternion.Euler(90.0f, 0.0f, 0.0f));
        Vector3    mazeScale = this.GetMazeScale();

        o.transform.localScale = mazeScale;
        o.transform.parent     = GameObject.Find(Const.MAZE_GAMEOBJECT_NAME).transform;
        Renderer rend = o.GetComponent <Renderer>();

        rend.material.SetTextureScale("_MainTex", new Vector2(mazeScale.x, mazeScale.y));


        GameObject arrivalPrefab = ((GameObject)Resources.Load("Prefabs/" + Const.POINT_OF_ARRIVAL_PREFAB_NAME, typeof(GameObject)));

        double[] end = CoreWrapper.GetInstance().GetEndCenter();
        //GameObject arrivalObject = Instantiate(arrivalPrefab, MazeData.MAZE_POINT_OF_ARRIVAL, Quaternion.Euler(-90.0f, 0.0f, 0.0f));
        float      x_scale_arrivee = -Const.HAUTEUR_MAZE / 2f + Const.HAUTEUR_MAZE * (float)end[0];
        float      y_scale_arrivee = -Const.LARGEUR_MAZE / 2f + Const.LARGEUR_MAZE * (float)end[1];
        GameObject arrivalObject   = Instantiate(arrivalPrefab, new Vector3(x_scale_arrivee, 1.0f, y_scale_arrivee), Quaternion.Euler(-90.0f, 0.0f, 0.0f));

        arrivalObject.transform.parent     = GameObject.Find(Const.MAZE_GAMEOBJECT_NAME).transform;
        arrivalObject.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);

        ParticleSystem arrivalPs = arrivalObject.GetComponent <ParticleSystem>();

        ParticleSystem.MainModule arrivalMain = arrivalPs.main;

        arrivalPs.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
        ParticleSystemRenderer arrivalPsr = arrivalObject.GetComponent <ParticleSystemRenderer>();

        arrivalPsr.renderMode = ParticleSystemRenderMode.Billboard;
        Debug.Log(arrivalMain.simulationSpace);
        arrivalMain.simulationSpace = ParticleSystemSimulationSpace.Local;


        /* for (int i = 0; i < MazeData.ARRAY_DATAS_TEST.Length / 2; ++i)
         * {
         *   MazeObstacle.Create(MazeData.ARRAY_DATAS_TEST[i, 0], MazeData.ARRAY_DATAS_TEST[i, 1]);
         * }*/
        List <double[, ]> walls = CoreWrapper.GetInstance().GetWall();

        foreach (double[,] wall in walls)
        {
            // Debug.Log("(" + -10f / 2f + 10f * (float)wall[0, 0] + " , " + -10f / 2f + 10f * (float)wall[0, 1] + "); (" + -10f / 2f + 10f * (float)wall[1, 0] + " , " + -10f / 2f + 10f * (float)wall[1, 1] + ")");

            float x_scale_wall_start = -Const.HAUTEUR_MAZE / 2f + Const.HAUTEUR_MAZE * (float)wall[0, 0];
            float y_scale_wall_start = -Const.LARGEUR_MAZE / 2f + Const.LARGEUR_MAZE * (float)wall[0, 1];
            float x_scale_wall_end   = -Const.HAUTEUR_MAZE / 2f + Const.HAUTEUR_MAZE * (float)wall[1, 0];
            float y_scale_wall_end   = -Const.LARGEUR_MAZE / 2f + Const.LARGEUR_MAZE * (float)wall[1, 1];
            Debug.Log("(" + x_scale_wall_start + " , " + y_scale_wall_start + "); (" + x_scale_wall_end + " , " + y_scale_wall_end + ")");

            MazeObstacle.Create(new Vector3(x_scale_wall_start, 1f, y_scale_wall_start), new Vector3(x_scale_wall_end, 1f, y_scale_wall_end));
        }

        GameObject mazeObject = GameObject.Find(Const.MAZE_GAMEOBJECT_NAME);

        mazeObject.transform.position   = new Vector3(0.8f, 394.74f, -10.15f);
        mazeObject.transform.localScale = new Vector3(1.4f, 1.0f, 1.0f);
    }
Exemplo n.º 7
0
 void OnDestroy()
 {
     Debug.Log("Destroyed");
     CoreWrapper.GameEnd();
 }
Exemplo n.º 8
0
 // Update is called once per frame
 void FixedUpdate()
 {
     CoreWrapper.GameLoop();
 }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        if (paused)
        {
            return;
        }

        if (!cameraOk)
        {
            return;
        }

        this.frame = core.GetCameraFrame();
        this.texture.LoadRawTextureData(this.frame);
        this.texture.Apply();
        this.GetComponent <Renderer>().material.SetTexture("_MainTex", this.texture);

        /*
         *
         * if(!m_calibrated && !m_config_exists)
         * {
         *
         *  accTime += Time.deltaTime;
         *  if( accTime >= 1)
         *  {
         *      accTime -= 1;
         *      Debug.Log("mdr");
         *      StartCoroutine(AsycnFindPattern());
         *      //core.AddPatternToCalibrator();
         *
         *      if(core.CheckCalibrator())
         *      {
         *          m_calibrated = true;
         *          core.Calibrate();
         *      }
         *
         *  }
         *  return;
         *
         * }
         *
         */

        //this.camera.Video();
        if (!m_FinishedBuild)
        {
            core.Build();

            if (core.CheckBuid())
            {
                m_FinishedBuild = true;

                core.InitTransformDefault();

                Debug.Log("Built");
                double[]   start      = CoreWrapper.GetInstance().GetBeginCenter();
                GameObject prefabBall = ((GameObject)Resources.Load("Prefabs/" + Const.BALL_PREFAB_NAME, typeof(GameObject)));
                float      x_unity    = -Const.HAUTEUR_MAZE / 2 + Const.HAUTEUR_MAZE * (float)start[0];
                float      y_unity    = (-Const.LARGEUR_MAZE / 2 + Const.LARGEUR_MAZE * (float)start[1]) - 10.15f;

                Vector3    spawnPosition = new Vector3(x_unity, 400.0f, y_unity);
                GameObject objetBall     = Instantiate(prefabBall, spawnPosition, Quaternion.Euler(90.0f, 0.0f, 0.0f));
                objetBall.GetComponent <Ball>().spawnPosition = spawnPosition;

                GameObject o = ((GameObject)Resources.Load("Prefabs/" + Const.MAZE_PREFAB_NAME, typeof(GameObject)));
                maze = Instantiate(o, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.Euler(0.0f, 0.0f, 0.0f));

                GameObject Init = ((GameObject)Resources.Load("Prefabs/" + Const.GAMEINITIALIZER_PREFAB_NAME, typeof(GameObject)));
                GameObject o2   = Instantiate(Init, Vector3.zero, Quaternion.Euler(0.0f, 0.0f, 0.0f));

                double[] rot = core.GetInitRot();

                rotLab = new Vector3(-(float)(rot[0]) + rotOffsetX,
                                     -(float)(rot[2]) + rotOffsetY,
                                     -(float)(rot[1]) + rotOffsetZ);

                inGameController.StartTimer();
            }
        }
        else
        {
            core.Tracking();
            core.UpdateTranform();

            double[] rot = core.GetDeltaRot();
            rotLab += new Vector3(-(float)rot[0], -(float)(rot[2]), -(float)(rot[1]));

            // correction

            /*
             * float rotZ = rotLab[2];
             * if(rotZ > 0)
             *  rotZ -= 35.50f;
             * else
             *  rotZ += 35.5f;
             */

            Quaternion previousRotation = maze.transform.rotation;
            Quaternion nextRotation     = Quaternion.Euler(rotLab);
            maze.transform.rotation = Quaternion.Lerp(previousRotation, nextRotation, Time.deltaTime * 15.0f);
        }
    }