コード例 #1
0
        public static int init(GameObject game_object = null, PlayerEntity player_entity = null)
        {
            // プレイヤーGameObject取得
            if (game_object != null)
            {
                go = game_object;
            }
            else
            {
                //Debug.Log("PlayerService.init : PlayerFactory.createGameObject()");
                go = PlayerFactory.createGameObject();
            }

            // Entity生成
            if (player_entity != null)
            {
                _entity = player_entity;
                return(_entity.equip.id);
            }
            else
            {
                //Debug.Log("PlayerService.init : PlayerFactory.createEntity()");
                _entity = PlayerFactory.createEntity();
            }

            // Lv 1以上のデータなら next_level更新
            if (1 < _entity.lv)
            {
                nextLevel(_entity.lv - 1);
                nextLevel(_entity.lv);
                nextLevel(_entity.lv + 1);
            }


            EquipEntity equip = _entity.equip;

            if (equip == null)
            {
                // 初期装備
                //Debug.Log("PlayerService.init : EquipFactory.createRandomEntity()");
                equip = EquipFactory.createRandomEntity();
                //Debug.Log("equip.name : " + equip.name);
                ItemEquipController iec = equip.game_object.GetComponentInChildren <ItemEquipController>();
                iec.OnTarget();
            }
            else
            {
                // EquipEntityの通りに武器を作ってIDを再設定
            }

            //nextLevel(1);
            //nextLevel(2);
            return(equip.id);
        }
コード例 #2
0
        public static GameObject createGameObject(EquipEntity entity, Vector3 position)
        {
            Debug.Log("Item.Equip.Factory.createGameObject() : entity.prefab_id : " + entity.prefab_id.ToString());
            Debug.Log("Item.Equip.Factory.createGameObject() : _prefabs.Count : " + _prefabs.Count.ToString());

            var go_base = _prefabs[entity.prefab_id];
            var go      = Object.Instantiate(go_base);

            ItemEquipController iec = go.GetComponentInChildren <ItemEquipController>();

            if (iec != null)
            {
                iec.entity = entity;
            }

            // 出現位置の設定
            go.transform.position = position;
            EquipService.set(go);

            return(go);
        }
コード例 #3
0
        public static void set(GameObject equip)
        {
            ItemEquipController iec = equip.GetComponentInChildren <ItemEquipController>();

            if (iec == null)
            {
                throw new Exception();
            }

            int id = iec.entity.id;

            Debug.Log("EquipService::set() : id : " + id + " : " + iec.entity.name);

            if (equip_item_list.ContainsKey(id))
            {
                equip_item_list[id] = equip;
            }
            else
            {
                equip_item_list.Add(id, equip);
            }
        }
コード例 #4
0
        public static void equipChange(int id, GameObject player_gameobject = null)
        {
            Debug.Log("EquipService::equipChange() : id : " + id);

            if (now_quiped_entity != null && now_quiped_entity.id == id)
            {
                return;
            }

            GameObject go = get(id);

            Rigidbody rb = go.GetComponentInChildren <Rigidbody>();

            rb.isKinematic = true;

            bool exist_eqiuped = true;

            GameObject[] equiped = new GameObject[0];

            try {
                equiped = GameObject.FindGameObjectsWithTag("Equiped");
            } catch (UnityException e) {
                exist_eqiuped = false;
            }

            if (equiped.Length < 1)
            {
                exist_eqiuped = false;
            }

            //Debug.Log("EquipService::equipChange() : equiped.Length : " + equiped.Length);
            //Debug.Log("EquipService::equipChange() : exist_eqiuped : " + exist_eqiuped);

            GameObject player_right_hand;

            if (player_gameobject != null)
            {
                player_right_hand = player_gameobject.transform.Find("_root/center/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_RightShoulder/Character1_RightArm/Character1_RightForeArm/Character1_RightHand").gameObject;
            }
            else
            {
                player_right_hand = GameObject.FindGameObjectWithTag("PlayerRightHand");
                //Debug.Log("player_right_hand.name" + player_right_hand.name);
            }

            //Debug.Log("EquipService::equipChange() : player_right_hand : " + player_right_hand);

            if (player_right_hand == null)
            {
                throw new Exception();
            }

            Debug.Log("EquipService::equipChange() : equiped.Length : " + equiped.Length.ToString());

            if (exist_eqiuped && 0 < equiped.Length)
            {
                foreach (var x in equiped)
                {
                    Debug.Log("EquipService::equipChange() : equiped : x.name : " + x.name.ToString());
                    if (x.layer == 8)
                    {
                        continue;
                    }

                    x.tag = "ItemEquip";

                    foreach (Transform child in x.transform)
                    {
                        child.tag = "ItemEquip";
                    }

                    x.transform.parent = null;
                    //x.transform.SetParent(null);
                    //x.transform.position = player_right_hand.transform.position;

                    ItemEquipController ie = x.GetComponentInChildren <ItemEquipController>();
                    ie.TargetDisable();

                    BoxCollider col = x.GetComponentInChildren <BoxCollider>();
                    col.enabled   = true;
                    col.isTrigger = false;

                    Debug.Log("EquipService.equipChange() : Outline.enabled = true");
                    foreach (var o in x.GetComponentsInChildren <Outline>())
                    {
                        o.enabled = true;
                    }

                    Rigidbody equped_rb = x.GetComponentInChildren <Rigidbody>();

                    if (equped_rb != null)
                    {
                        equped_rb.isKinematic = false;
                        equped_rb.AddRelativeForce(new Vector3(0f, equped_rb.mass * equiped_force, equped_rb.mass * equiped_force), ForceMode.Impulse);
                    }
                }
            }

            //Debug.Log("player_right_hand: " + player_right_hand);
            //Debug.Log("player_right_hand.transform: " + player_right_hand.transform);

            BoxCollider collider = go.GetComponentInChildren <BoxCollider>();

            collider.isTrigger = true;
            //collider.enabled = false;

            go.transform.SetParent(player_right_hand.transform);

            ItemEquipController iec = go.GetComponentInChildren <ItemEquipController>();

            Debug.Log("EquipService.equipChange() : " + iec.entity.name);

            go.transform.position      = Vector3.zero;
            go.transform.rotation      = new Quaternion(0f, 0f, 0f, 0f);
            go.transform.localPosition = iec.entity.equip_position_offset;
            go.transform.localRotation = iec.entity.equip_rotation_offset;

            go.tag = "Equiped";

            foreach (Transform child in go.transform)
            {
                child.tag = "Equiped";
            }

            Debug.Log("EquipService.equipChange() : Outline.enabled = false");
            foreach (var outline in go.GetComponentsInChildren <Outline>())
            {
                outline.enabled = false;
            }

            string    main_body_gameobject_name = iec.entity.main_body_gameobject_name;
            Transform main_body = go.transform.Find(main_body_gameobject_name);

            if (main_body != null)
            {
                main_body.localPosition = Vector3.zero;
                main_body.localRotation = new Quaternion(0f, 0f, 0f, 0f);
            }

            go.SetActive(true);
            now_quiped_entity = iec.entity;

            if (exist_eqiuped)
            {
                MessageBroker.Default.Publish <PlaySe>(new PlaySe {
                    name = "Sword Drop"
                });
            }
        }
コード例 #5
0
        public static void onlyEquip(int id, GameObject player_gameobject = null, bool update_service_data = true)
        {
            Debug.Log("EquipService.onlyEquip() : start");
            //if (now_quiped_entity != null && now_quiped_entity.id == id) return;

            GameObject go = get(id);
            Rigidbody  rb = go.GetComponentInChildren <Rigidbody>();

            rb.isKinematic = true;

            GameObject player_right_hand;

            if (player_gameobject != null)
            {
                player_right_hand = player_gameobject.transform.Find("_root/center/Character1_Hips/Character1_Spine/Character1_Spine1/Character1_Spine2/Character1_RightShoulder/Character1_RightArm/Character1_RightForeArm/Character1_RightHand").gameObject;
            }
            else
            {
                player_right_hand = GameObject.FindGameObjectWithTag("PlayerRightHand");
                //Debug.Log("player_right_hand.name" + player_right_hand.name);
            }

            if (player_right_hand == null)
            {
                throw new Exception();
            }

            BoxCollider collider = go.GetComponentInChildren <BoxCollider>();

            //collider.isTrigger = true;
            collider.enabled = false;

            go.transform.SetParent(player_right_hand.transform);

            ItemEquipController iec = go.GetComponentInChildren <ItemEquipController>();

            Debug.Log("EquipService.onlyEquip() : name : " + iec.entity.name);
            Debug.Log("EquipService.onlyEquip() : type : " + iec.entity.type);
            Debug.Log("EquipService.onlyEquip() : prefab : " + iec.entity.prefab_id);
            iec.enabled = false;

            Debug.Log("EquipService.onlyEquip() : before : go.transform.localPosition " + go.transform.localPosition.ToString());
            Debug.Log("EquipService.onlyEquip() : before : go.transform.localRotation " + go.transform.localRotation.ToString());

            go.transform.position      = Vector3.zero;
            go.transform.rotation      = new Quaternion(0f, 0f, 0f, 0f);
            go.transform.localPosition = iec.entity.equip_position_offset;
            go.transform.localRotation = iec.entity.equip_rotation_offset;

            Debug.Log("EquipService.onlyEquip() : after : iec.entity.equip_position_offset " + iec.entity.equip_position_offset.ToString());
            Debug.Log("EquipService.onlyEquip() : after : iec.entity.equip_rotation_offset " + iec.entity.equip_rotation_offset.ToString());

            Debug.Log("EquipService.onlyEquip() : after : go.transform.localPosition " + go.transform.localPosition.ToString());
            Debug.Log("EquipService.onlyEquip() : after : go.transform.localRotation " + go.transform.localRotation.ToString());

            go.tag = "Equiped";

            foreach (Transform child in go.transform)
            {
                child.tag = "Equiped";
            }

            Debug.Log("EquipService.onlyEquip() : Outline.enabled = false");
            foreach (var outline in go.GetComponentsInChildren <Outline>())
            {
                outline.enabled = false;
            }

            string    main_body_gameobject_name = iec.entity.main_body_gameobject_name;
            Transform main_body = go.transform.Find(main_body_gameobject_name);

            if (main_body != null)
            {
                main_body.localPosition = Vector3.zero;
                main_body.localRotation = new Quaternion(0f, 0f, 0f, 0f);
            }

            go.SetActive(true);
            if (update_service_data)
            {
                now_quiped_entity = iec.entity;
            }
        }