Exemple #1
0
    void FixedUpdate()
    {
        if (null == unitplaceSubject && "BattleStage" == Application.loadedLevelName)
        {
            // バトルフィールドシーン時においてInUnitPlaceのためにSubjectコンポを取得
            unitplaceSubject = GameObject.Find("Canvas_TimerInUnitPlace").GetComponent<UnitPlaceSubject>();
        }

        // Rayを作成
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, (Vector2)ray.direction);
        if (hit.collider != null)
        {
            // Rayがヒットしたオブジェクトがチップ / ユニット / ステータスウィンドウの場合
            if (("Tip" == hit.collider.gameObject.tag) ||
                ("UnitGO" == hit.collider.gameObject.tag) ||
                ("StatusWindow" == hit.collider.gameObject.tag))
            {
                // ヒットしたオブジェクトが持つRay検出クラスの基底クラス側メソッドをコール
                var dRayCast = hit.collider.GetComponent<DetectRayBase>();
                dRayCast.DetectRayHit();
            }

            // InUnitPlace時の処理
            if ("Tip" == hit.collider.gameObject.tag)
            {
                // アンダーライン内のユニットアイコンが既にクリックされているかを判定
                if (1 == unitplaceSubject.status)
                {
                    // ユニットがクリックされている状態でチップにRayがヒットした場合
                    // Subjectのフィールドに格納されている、現在クリックされているユニットIDを読みだして
                    // そのユニットIDのユニットGOを生成し、チップに配置する。
                    int unitId = unitplaceSubject.NowClickUnitID;

                    // クラス種別を読み出し、クラスに対応したGOをインスタンス化する
                    Sprite classSprite = null;
                    GameObject classGO = null;
                    GameObject unitGO = null;
                    Vector3 tipPosition = hit.collider.gameObject.transform.position;
                    switch (gameManager.unitStateList[unitId].classType)
                    {
                        case Defines.SOLDLER: // ソルジャー
                            classGO = Resources.Load<GameObject>("UnitSprite_Battle/SOLDLER");
                            unitGO = Instantiate(classGO, tipPosition, Quaternion.identity) as GameObject;
                            break;
                        case Defines.WIZARD:  // ウィザード
                            classGO = Resources.Load<GameObject>("UnitSprite_Battle/WIZARD");
                            unitGO = Instantiate(classGO, tipPosition, Quaternion.identity) as GameObject;
                            break;
                        default:             // 例外
                            // 処理なし
                            break;
                    }
                }
            }
        }
    }
    void Start()
    {
        // ユニットアイコンSubjectコンポを取得
        unitplaceSubject = this.gameObject.GetComponent<UnitPlaceSubject>();
        
        // バトル参加中ユニット管理クラスを取得
        battleUnitList = GameObject.Find("Canvas").GetComponent<BattleUnitList>();

        // ユニットインスタンス作成クラスを取得
        unitCreate = this.gameObject.GetComponent<InstantiateUnitOnTip>();

        // サブジェクトコンポを取得し、オブサーバリストに自身を追加
        subjectCompo = GameObject.Find("Canvas_TimerInUnitPlace").GetComponent<UnitPlaceSubject>();
    }
	void Start ()
    {
        // サブジェクトコンポを取得し、オブサーバリストに自身を追加
        subjectCompo = GameObject.Find("Canvas_TimerInUnitPlace").GetComponent<UnitPlaceSubject>();
        subjectCompo.Attach(this);

        // 自身のImageコンポを取得
        thisImageCompo = this.gameObject.GetComponent<Image>();

        // バトル参加中ユニットリスト管理クラスを取得
        unitListInBattle = GameObject.Find("Canvas").GetComponent<BattleUnitList>();

        // 初期配置完了クラスを取得
        compJudRPC = subjectCompo.GetComponent<UnitPlaceCompJudRPC>();

        // オーディオコンポを取得
        audioCompo = GameObject.Find("PlayersParent").transform.FindChild("SEPlayer").gameObject.GetComponent<AudioSource>();
        // TODO 本当はリクワイヤードコンポ属性を使うべき。上手く動いてくれなかったのでとりあえず
        if (null == audioCompo) audioCompo = GameObject.Find("PlayersParent").transform.FindChild("SEPlayer").gameObject.GetComponent<AudioSource>();
	}