コード例 #1
0
    void Update()
    {
        GameObject obj = GameObject.Find("Player");

        RaycastHit[] hitColliders = null;
        Vector3      playerPos    = new Vector3(
            this.player.transform.position.x,
            this.player.transform.position.y + 1.0f,
            this.player.transform.position.z);
        Vector3 vec = (playerPos - this.transform.position);

        Debug.DrawRay(this.transform.position, vec, Color.red);
        hitColliders = Physics.BoxCastAll(
            this.transform.position,
            new Vector3(0.5f, 0.01f, 0.01f),
            vec.normalized,
            this.transform.rotation,
            vec.magnitude * 0.9f,
            ~LayerMask.GetMask("player"));

        //このフレームの障害物List作成
        List <Obstacle> obstacleList = new List <Obstacle>();

        foreach (var hitCollider in hitColliders)
        {
            if (hitCollider.collider.gameObject.GetComponent <Renderer>() == null)
            {
                continue;
            }

            Obstacle hitObj = this.prevObstacleList.Find(i => i.gameObj == hitCollider.collider.gameObject);

            if (hitObj == null)
            {
                hitObj = new Obstacle(hitCollider.collider.gameObject);
            }

            obstacleList.Add(hitObj);
        }

        //新たに追加された障害物(meshを透過するobj)
        var newObstacleList = obstacleList.Except <Obstacle>(this.prevObstacleList);

        newObstacleList.ToList <Obstacle>().ForEach(i =>
        {
            Material material = i.gameObj.GetComponent <Renderer>().material;
            BlendModeUtils.SetBlendMode(material, BlendModeUtils.Mode.Fade);
            material.SetColor("_Color", new Color(1, 1, 1, 0));
        });

        //障害物じゃなくなったobject
        var exceptList = this.prevObstacleList.Except <Obstacle>(obstacleList);

        exceptList.ToList <Obstacle>().ForEach(i =>
        {
            i.gameObj.GetComponent <Renderer>().material = i.material;
        });

        this.prevObstacleList = obstacleList;
    }
コード例 #2
0
    IEnumerator CreatePhoto(Vector3 vec)
    {
        yield return(new WaitForEndOfFrame());

        int width  = (int)films[this.currentFilmNum].Image.rectTransform.rect.width;
        int height = (int)films[this.currentFilmNum].Image.rectTransform.rect.height;

        // アクティブなレンダーテクスチャをキャッシュしておく
        RenderTexture currentRT = RenderTexture.active;

        RenderTexture renderTexture = new RenderTexture(width, height, 24);

        // アクティブなレンダーテクスチャを一時的にTargetに変更する
        RenderTexture.active = renderTexture;

        photoUICamera.targetTexture = renderTexture;

        photoUICamera.Render();

        Texture2D photo = new Texture2D(width, height);

        photo.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        photo.Apply();

        this.films[this.currentFilmNum].Image.texture = photo;
        this.films[this.currentFilmNum].Image.color   = Color.white;
        Material material = this.films[this.currentFilmNum].Obj.GetComponent <Renderer>().material;

        BlendModeUtils.SetBlendMode(material, BlendModeUtils.Mode.Fade);
        material.SetColor("_Color", new Color(1, 1, 1, alphaValOfSilhouette));
        this.films[this.currentFilmNum].Obj.transform.SetParent(this.player.transform, true);
        this.films[this.currentFilmNum].Axis = Quaternion.Inverse(Quaternion.Euler(this.films[this.currentFilmNum].Obj.transform.eulerAngles)) * vec;
    }
コード例 #3
0
 // マテリアルを非透明化
 void AnTransparent(Material[] materials)
 {
     foreach (Material material in materials)
     {
         float alpha = material.color.a;
         alpha += 0.05f;
         if (alpha > 1.0f)
         {
             alpha = 1.0f;
             BlendModeUtils.SetBlendMode(material, BlendModeUtils.Mode.Opaque);
         }
         material.color = new Color(material.color.r, material.color.g, material.color.b, alpha);
     }
 }
コード例 #4
0
 // マテリアルを透明化
 void Transparent(Material[] materials)
 {
     foreach (Material material in materials)
     {
         BlendModeUtils.SetBlendMode(material, BlendModeUtils.Mode.Fade);
         float alpha = material.color.a;
         alpha -= 0.05f;
         if (alpha < 0.2f)
         {
             alpha = 0.2f;
         }
         material.color = new Color(material.color.r, material.color.g, material.color.b, alpha);
     }
 }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        if (isTransparent)
        {
            foreach (Material material in this.gameObject.GetComponent <Renderer>().materials)
            {
                BlendModeUtils.SetBlendMode(material, BlendModeUtils.Mode.Fade);
                // 色を透明にする

                float alpha = material.color.a;
                if (alpha > ALPHA_MIN)
                {
                    alpha -= ALPHA_SPEED;
                }
                else
                {
                    alpha = ALPHA_MIN;
                }
                material.color = new Color(material.color.r, material.color.g, material.color.b, alpha);
            }
        }
        else
        {
            foreach (Material material in this.gameObject.GetComponent <Renderer>().materials)
            {
                // 色を元に戻す

                float alpha = material.color.a;
                if (alpha < 1.0f)
                {
                    alpha += ALPHA_SPEED;
                }
                else
                {
                    alpha          = 1.0f;
                    material.color = new Color(material.color.r, material.color.g, material.color.b, alpha);
                    BlendModeUtils.SetBlendMode(material, BlendModeUtils.Mode.Opaque);
                }
                material.color = new Color(material.color.r, material.color.g, material.color.b, alpha);
            }
        }
        isTransparent = false;
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (isCursorLocked)
        {
            Cursor.lockState = CursorLockMode.Locked;
        }

        ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.0f));

        bool isRayHit = Physics.Raycast(ray, out hitInfo, reachableDistance);


        Debug.DrawRay(ray.origin, ray.direction * reachableDistance, Color.red, 0.0f, false);

        // Show gray block
        //rayがgameobjectに当たったとき
        if (isRayHit)
        {
            //もしrayが当たったgameobjectがTerrain(Tagはステージ)なら
            if (hitInfo.collider.tag == "Stage")
            {
                //blockGray.SetActive(true); //仮想のgameobjectをアクティブ化
                BlendModeUtils.SetBlendMode(blockGray.transform.GetChild(0).gameObject.GetComponent <Renderer>().material, BlendModeUtils.Mode.Transparent);
                blockGray.transform.GetChild(0).GetComponent <Renderer>().enabled = true;
                blockGray.transform.GetChild(0).gameObject.GetComponent <Renderer>().material.color = color; //仮想とわかるよう色を黒めに
                hitObjPos = hitInfo.point;
                blockGray.transform.position = hitObjPos + hitInfo.normal * 0.001f;                          //rayが当たったその場に仮想のgameObjectを生成(おそらくここが原因)
            }
            //もし障害物にrayが当たれば
            else if (hitInfo.collider.tag == "WallwithHP")
            {
                print("hit");
                hitInfo.collider.gameObject.transform.GetChild(0).GetComponent <BrockScript>().select_flag = true; //その障害物を選択状態にする
                //blockGray.SetActive(false); //仮想のgameobjectは生成しない
                blockGray.transform.GetChild(0).GetComponent <Renderer>().enabled = false;
            }
            //それ以外のところにrayが当たれば
            else
            {
                //blockGray.SetActive(false); //仮想のgameobjectは生成しない
                blockGray.transform.GetChild(0).GetComponent <Renderer>().enabled = false;
            }
        }
        //rayが当たらなければ
        else
        {
            //blockGray.SetActive(false); //仮想のgameobjectは生成しない
            blockGray.transform.GetChild(0).GetComponent <Renderer>().enabled = false;
        }


        // Put blocks
        //rayがTerrain上に当たれば障害物を置くことが可能
        if (isRayHit && Input.GetMouseButtonDown(0) && hitInfo.collider.tag == "Stage")
        {
            hitObjPos = hitInfo.point;
            BlendModeUtils.SetBlendMode(blockPrefab.transform.GetChild(0).gameObject.GetComponent <Renderer>().material, BlendModeUtils.Mode.Opaque);
            childobj = Instantiate(blockPrefab, hitObjPos, Quaternion.identity); //あらかじめ用意していた変数に生成したgameobjectを格納
            childobj.transform.parent = parentobj.transform;                     //生成したgameobjectを設定した親オブジェクトの子として設定
            audioSource.clip          = putSound;
            audioSource.Play();
        }



        // Destoroy blocks
        //rayが障害物に当たれば
        if (isRayHit && Input.GetMouseButtonDown(1) && hitInfo.collider.tag == "WallwithHP")
        {
            Destroy(hitInfo.transform.gameObject);
            audioSource.clip = destroySound;
            audioSource.Play();
        }

        // Select blocks
        //右矢印キーを押したとき
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            blockGray.SetActive(false);           //選択中のgameobject(仮想)を非アクティブ化
            block_counter++;
            if (block_counter >= Obstacle.Length) //カウンタが配列の要素数を超えないよう最初に戻す
            {
                block_counter = 0;
            }
            blockGray    = Obstacle_gray[block_counter]; //選択中のgameobject(仮想)を変える
            blockPrefab  = Obstacle[block_counter];      //選択中のgameobjectを変える
            image.sprite = sprite[block_counter];        //選択中のgameobjectの画像を変える
            blockGray.SetActive(true);                   //アクティブ化
        }
    }