Пример #1
0
        ///<summary> ChipUIオブジェクトをドラッグ状態にする。 </summary>
        private void SetDrag(ChipUI chip)
        {
            if (chip == null)
            {
                return;
            }

            // ドラッグモードに変更
            chip.ActivateChase();
            now_drag = chip;
            chip.SetScale(ChipUI.STANDARD_DRAG_SCALE);

            if (onDrag != null)
            {
                onDrag(chip);
            }

            RemoveChipUI(chip);

            HideChipConfig();
        }
Пример #2
0
        ///<summary> チップを離した時の処理 </summary>
        private void DropChip(Vector3 pos)
        {
            // サイズを固定用に変更して、固定モードにする。
            now_drag.SetScale(ChipUI.STANDARD_SCALE);

            // ドロップした座標を設定
            now_drag.SetPosition3D(pos);

            // 最も近いチップを参照する。
            ChipUI nearest = FindNearestChipUI(now_drag);

            // 最も近いチップが接続できないなら、終了
            if (nearest == null || (!nearest.IsConnectable))
            {
                DisactiveChipUI(now_drag);

                // なんであれドラッグ状態は解除する。
                now_drag = null;
                return;
            }

            // 接触したチップが存在しないなら、終了
            if (nearest == null)
            {
                DisactiveChipUI(now_drag);

                // なんであれドラッグ状態は解除する。
                now_drag = null;
                return;
            }

            // 最も適した設置方向を計算する。
            Vector3 set_pos = CalcSettingPos(
                now_drag.transform.position,
                nearest.transform.position
                );

            // 内部でドラッグ状態が解除されているなら、終了
            if (now_drag == null)
            {
                return;
            }

            now_drag.SetPosition3D(set_pos);

            // UI範囲を超えているなら、非アクティブにして終了。
            if (CheckLimitOver(now_drag))
            {
                // 画面外なので非アクティブ
                DisactiveChipUI(now_drag);

                // なんであれドラッグ状態は解除する。
                now_drag = null;
                return;
            }

            // 全く同じ場所にチップが既にあるなら終了
            foreach (ChipUI use in useChips)
            {
                if (Vector3.Equals(use.transform.position, now_drag.transform.position))
                {
                    // 画面外なので非アクティブ
                    DisactiveChipUI(now_drag);

                    // なんであれドラッグ状態は解除する。
                    now_drag = null;
                    return;
                }
            }

            // 再接続の可能性を考慮
            if (now_drag.parent != null)
            {
                now_drag.parent.Disconnect(now_drag.connect_index);
                RemoveAll(now_drag);
                now_drag.Init();
            }

            // 位置を固定
            now_drag.FreezePos();

            // 使用中チップ配列に登録
            useChips.Add(now_drag);

            // 接続UIを表示
            Vector3[] linked_info = CalcLinkedUIPos(now_drag, nearest);


            // ChipUIを内部的に接続状態にする
            int index = 0;

            if (nearest.isCPU)
            {
                Vector3 direction = now_drag.transform.position - nearest.transform.position;
                if (direction.x == 0)
                {
                    if (direction.y < 0)
                    {
                        index = 2;
                    }
                    else
                    {
                        index = 0;
                    }
                }
                else if (direction.y == 0)
                {
                    if (direction.x < 0)
                    {
                        index = 3;
                    }
                    else
                    {
                        index = 1;
                    }
                }
            }

            // 接続に失敗したら終了
            if (!nearest.Connect(now_drag, index))
            {
                DisactiveChipUI(now_drag);

                // なんであれドラッグ状態は解除する。
                now_drag = null;
                return;
            }

            ShowLinked(now_drag, linked_info);

            if (now_drag.Name == Lobot.ChipName.GAIN)
            {
                num_gain_chip++;
            }

            now_drag = null;
        }