コード例 #1
0
        //プレハブ作成
        private GameObject CreatePrefab(Scene scene)
        {
            //キャラクターの親オブジェ登録
            GameObject parantCharacter = (GameObject)Resources.Load(ConstantsEditor.CHARACTER_PARANT_RESOURCES_PATH);

            parantCharacter = PrefabUtility.InstantiatePrefab(parantCharacter, scene) as GameObject;
            GameObject obj = PrefabUtility.InstantiatePrefab(modelObj, scene) as GameObject;

            obj.transform.parent        = parantCharacter.transform;
            obj.transform.localPosition = Vector3.zero;
            parantCharacter.name        = charaName;
            tempObject = parantCharacter;
            //子オブジェのレイヤーを変更
            List <Transform> children = SubTransform.ChildClass(parantCharacter.transform);//子オブジェを全て読みこみ

            foreach (Transform child in children)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Character");
            }
            parantCharacter.layer = LayerMask.NameToLayer("Character");

            //オブジェクトの位置移動
            parantCharacter.transform.position = new Vector3(ConstantsEditor.CHARACTER_VIEW_PLACE, 0, 0);

            CharacterView.characterPrefab = parantCharacter;

            //プレハブのセーブ
            return(PrefabUtility.SaveAsPrefabAsset(parantCharacter, "Assets/Character/" + charaName + "/" + charaName + ".prefab"));
        }
コード例 #2
0
        private void Update()
        {
            _orthographicSize = _camera.orthographicSize;

            var oldPosition = MainTransform.position;

            // Looper code. Horizontal teleportation.
            if (oldPosition.x < _orthographicSize * _camera.aspect - Bounds.max.x * 0.75)
            {
                // RIGHT
                SubTransform.localPosition = Vector2.right;
                _handOver = true;
            }
            else if (oldPosition.x > Bounds.max.x * 0.75 - _orthographicSize * _camera.aspect)
            {
                // LEFT
                SubTransform.localPosition = Vector2.left;
                _handOver = true;
            }

            if (_handOver && math.abs(oldPosition.x) > Bounds.max.x * 2)
            {
                // Switch main and sub maps.
                var oldMain = MainTransform;
                MainTransform = SubTransform;
                SubTransform  = oldMain;

                MainTransform.SetParent(null);
                SubTransform.SetParent(MainTransform);

                _handOver = false;

                oldPosition = MainTransform.position;
            }

            // Movement code.
            if (_dragLock)
            {
                _delta = _dragOrigin - _camera.ScreenToWorldPoint(Input.mousePosition);
            }

            if (_orthoChanged)
            {
                _movement /= _orthographicSize;
                _camera.orthographicSize = TerrainCam.orthographicSize = OceanCam.orthographicSize =
                    _orthographicSize    = math.clamp(_scrollDirection + _orthographicSize, 0.2f, 5f);
                _movement *= _orthographicSize;

                _orthoChanged = false;
            }

            MainTransform.position = new Vector3
                                     (
                // Subtract as the map is moving, not the camera.
                oldPosition.x - (_dragLock ? _delta.x : _movement.x),
                math.clamp(oldPosition.y - (_dragLock ? _delta.y : _movement.y),
                           _orthographicSize - Bounds.max.y, Bounds.max.y - _orthographicSize)
                                     );

            if (_dragLock)
            {
                _dragOrigin = _camera.ScreenToWorldPoint(Input.mousePosition);
            }
        }