/// <summary>
        /// Computes camera poses on a cylinder.
        /// </summary>
        /// <param name="cameraCount"></param> The number of cameras on the circular section and on the vertical side of the cylinder.
        /// <param name="setupDirection"></param> The direction of the cylinder setup, inward or outward.
        public void ComputeCylinderPoses(Vector2Int cameraCount, SetupDirection setupDirection)
        {
            // Compute several preliminary values.
            Transform parentTransform = cameraModels[0].transform.parent;
            float     horizontalDegreesPerIteration = 360f / cameraCount.x;
            int       facingDirection              = (setupDirection == SetupDirection.Outwards) ? 1 : -1;
            int       numberOfVerticalIntervals    = cameraCount.y - 1;
            float     verticalIntervalSize         = 1f / Mathf.Max(1, numberOfVerticalIntervals);
            float     distanceToClosestVerticalCam = Mathf.Abs(parentTransform.lossyScale.y) * verticalIntervalSize;

            // Update the camera model of all source cameras.
            for (int j = 0; j < cameraCount.y; j++)
            {
                for (int i = 0; i < cameraCount.x; i++)
                {
                    int         index       = j * cameraCount.x + i;
                    CameraModel cameraModel = cameraModels[index];
                    cameraModel.SetCameraReferenceIndexAndImageName(index + 1, index.ToString("0000") + ".png");
                    cameraModel.transform.localRotation = Quaternion.AngleAxis(i * horizontalDegreesPerIteration, -Vector3.up);
                    cameraModel.transform.localPosition = facingDirection * (cameraModel.transform.localRotation * Vector3.forward) + ((j - 0.5f * numberOfVerticalIntervals) * verticalIntervalSize) * Vector3.up;
                    cameraModel.UpdateDistanceToClosestCam(distanceToClosestVerticalCam);
                    CheckCamDistanceWithOthersInSetup(index, Mathf.Max(0, index - 1), index);
                }
            }
            // Set the initial viewing position so that the viewer will look outwards from within, or inwards from without, based on the specified setup direction.
            initialViewingPosition = (facingDirection == 1) ? parentTransform.position : parentTransform.position - 1.5f * parentTransform.localScale.magnitude * parentTransform.forward;
        }
        /// <summary>
        /// Computes camera poses on a sphere.
        /// </summary>
        /// <param name="cameraCount"></param> The number of cameras on each of the arcs of the sphere.
        /// <param name="setupDirection"></param> The direction of the sphere setup, inward or outward.
        public void ComputeSpherePoses(Vector2Int cameraCount, SetupDirection setupDirection)
        {
            // Compute several preliminary values.
            Transform parentTransform     = cameraModels[0].transform.parent;
            Vector3   lossyScale          = parentTransform.lossyScale;
            Vector2   intervalArcDistance = Vector2.one / cameraCount;
            Vector2   degreesPerIteration = new Vector2(360f, 180f) * intervalArcDistance;
            int       facingDirection     = (setupDirection == SetupDirection.Outwards) ? 1 : -1;

            // Update the camera model of all source cameras.
            for (int j = 0; j < cameraCount.y; j++)
            {
                for (int i = 0; i < cameraCount.x; i++)
                {
                    int         index       = j * cameraCount.x + i;
                    CameraModel cameraModel = cameraModels[index];
                    cameraModel.SetCameraReferenceIndexAndImageName(index + 1, index.ToString("0000") + ".png");
                    cameraModel.transform.localRotation = Quaternion.AngleAxis(i * degreesPerIteration.x, -Vector3.up) * Quaternion.AngleAxis(-90f + (j + 0.5f) * degreesPerIteration.y, -Vector3.right);
                    cameraModel.transform.localPosition = facingDirection * (cameraModel.transform.localRotation * Vector3.forward);
                    CheckCamDistanceWithOthersInSetup(index, Mathf.Max(0, index - cameraCount.x), index);
                }
            }
            // Set the initial viewing position so that the viewer will look outwards from within, or inwards from without, based on the specified setup direction.
            initialViewingPosition = (facingDirection == 1) ? parentTransform.position : parentTransform.position - 1.5f * parentTransform.localScale.magnitude * parentTransform.forward;
        }
        public void StartOperator(SetupDirection direction)
        {
            blockingEnemy.Clear();
            setupDirection = direction;
            string lastAnimation = operatorObject._armature.animation.lastAnimationName;

            DragonBones.AnimationState lastAnimationState = operatorObject._armature.animation.lastAnimationState;
            if (direction == SetupDirection.Bottom)
            {
                operatorObject.armature.flipX = false;

                _underlayObject.transform.localEulerAngles = new Vector3(_underlayObject.transform.localEulerAngles.x, 270f, _underlayObject.transform.localEulerAngles.z);

                DrowRange(SetupDirection.Bottom);
            }
            if (direction == SetupDirection.Top)
            {
                string armatureName = operatorObject.armatureName;

                ChangeArmatureData(operatorObject, armatureName.Replace("_Front", "_Back"), operatorObject.unityData.dataName);

                operatorObject._armature.animation.Play("Idle", 0);

                operatorObject.armature.flipX = false;
                operatorObject.DBUpdate();
                _underlayObject.transform.localEulerAngles = new Vector3(_underlayObject.transform.localEulerAngles.x, 90f, _underlayObject.transform.localEulerAngles.z);

                DrowRange(SetupDirection.Top);
            }
            if (direction == SetupDirection.Left)
            {
                operatorObject.armature.flipX = true;

                _underlayObject.transform.localEulerAngles = new Vector3(_underlayObject.transform.localEulerAngles.x, 0f, _underlayObject.transform.localEulerAngles.z);

                DrowRange(SetupDirection.Left);
            }
            if (direction == SetupDirection.Right)
            {
                operatorObject.armature.flipX = false;

                _underlayObject.transform.localEulerAngles = new Vector3(_underlayObject.transform.localEulerAngles.x, 180f, _underlayObject.transform.localEulerAngles.z);

                DrowRange(SetupDirection.Right);
            }

            StartCoroutine(AnimationStartOperator());
            StartCoroutine(EnemySearch());
            StartCoroutine(AnimationAttack());

            StartCoroutine(_operatorData.skill.SkillPointGenerate(this, _operatorData.skill.initCost));
        }
        /// <summary>
        /// Resets the object's properties.
        /// </summary>
        void Reset()
        {
            // Reset the key child components.
            _cameraSetup          = CameraSetup.CreateOrResetCameraSetup(transform);
            _dataHandler          = DataHandler.CreateOrResetDataHandler(transform);
            _previewCameraManager = PreviewCameraManager.CreateOrResetPreviewCameraManager(transform);
#if UNITY_EDITOR
            // Reset parameters to their default values.
            _cameraPrefab     = null;
            _cameraCount      = new Vector2Int(4, 4);
            _acquireDepthData = false;
            _copyGlobalMesh   = false;
            _setupType        = SetupType.Grid;
            _setupDirection   = SetupDirection.Outwards;
            _lockSetup        = false;
            // Update the acquisition camera poses to reflect the updated setup.
            ComputeAcquisitionCameraPoses();
            // Create a preview camera from the prefab.
            CreatePreviewCameraFromPrefab();
#endif //UNITY_EDITOR
        }
Exemplo n.º 5
0
        /// <summary>
        /// Computes camera poses on a sphere.
        /// </summary>
        /// <param name="parentTransform"></param> The parent transform.
        /// <param name="cameraCount"></param> The number of cameras on each of the arcs of the sphere.
        /// <param name="setupDirection"></param> The direction of the sphere setup, inward or outward.
        public void ComputeSpherePoses(Transform parentTransform, Vector2Int cameraCount, SetupDirection setupDirection)
        {
            // Compute several preliminary values.
            Vector2 intervalArcDistance = Vector2.one / cameraCount;
            Vector2 degreesPerIteration = new Vector2(360f, 180f) * intervalArcDistance;
            int     facingDirection     = (setupDirection == SetupDirection.Outwards) ? 1 : -1;
            Vector3 absScale            = new Vector3(Mathf.Abs(parentTransform.lossyScale.x), Mathf.Abs(parentTransform.lossyScale.y), Mathf.Abs(parentTransform.lossyScale.z));

            // Update the camera model of all source cameras.
            for (int j = 0; j < cameraCount.y; j++)
            {
                for (int i = 0; i < cameraCount.x; i++)
                {
                    int         index       = j * cameraCount.x + i;
                    CameraModel cameraModel = cameraModels[index];
                    cameraModel.SetCameraReferenceIndexAndImageName(index, index.ToString("0000") + ".png");
                    cameraModel.transform.rotation = Quaternion.AngleAxis(i * degreesPerIteration.x, -parentTransform.up) * Quaternion.AngleAxis(-90f + (j + 0.5f) * degreesPerIteration.y, -parentTransform.right) * parentTransform.rotation;
                    cameraModel.transform.position = parentTransform.position + Vector3.Scale(cameraModels[index].transform.rotation * Vector3.forward, facingDirection * absScale);
                }
            }
            // Set the initial viewing position so that the viewer will look outwards from within, or inwards from without, based on the specified setup direction.
            initialViewingPosition = (facingDirection == 1) ? parentTransform.position : parentTransform.position - 1.5f * parentTransform.localScale.magnitude * parentTransform.forward;
            // Compute the inter-camera distance factor (here: minimum inter-camera distance).
            float interCamDistanceFactor = 1f;
            int   totalCameraCount       = cameraCount.x * cameraCount.y;

            if (totalCameraCount > 1)
            {
                float xDistance = (cameraModels[1].transform.position - cameraModels[0].transform.position).magnitude;
                if (xDistance > 0)
                {
                    interCamDistanceFactor = xDistance;
                }
                int   halfHeightIndexOne = (Mathf.FloorToInt(cameraCount.y / 2) - 1) * cameraCount.x;
                int   halfHeightIndexTwo = (halfHeightIndexOne + cameraCount.x);
                float yDistance          = (cameraModels[halfHeightIndexOne % totalCameraCount].transform.position - cameraModels[halfHeightIndexTwo % totalCameraCount].transform.position).magnitude;
                if (yDistance > 0)
                {
                    interCamDistanceFactor = Mathf.Min(interCamDistanceFactor, yDistance);
                }
            }
#if UNITY_EDITOR
            // Compute the gizmo size.
            gizmoSize = ComputeGizmoSize(cameraModels, interCamDistanceFactor);
            UpdateGizmosSize();
#endif //UNITY_EDITOR
        }
        public void DrowRange(SetupDirection direction = SetupDirection.Right, bool isActive = false)
        {
            if (rangeTilesParent != null)
            {
                Destroy(rangeTilesParent);
                rangeTiles.Clear();
            }

            Range.RangeOfOperator.Range rangeOfOperator = new Range.RangeOfOperator.Range();

            if (direction == SetupDirection.Right)
            {
                rangeOfOperator = _operatorData.rangeOfOperator.ArrayTransformRightMain();
            }
            if (direction == SetupDirection.Top)
            {
                rangeOfOperator = _operatorData.rangeOfOperator.ArrayTransformTop();
            }
            if (direction == SetupDirection.Bottom)
            {
                rangeOfOperator = _operatorData.rangeOfOperator.ArrayTransformBottom();
            }
            if (direction == SetupDirection.Left)
            {
                rangeOfOperator = _operatorData.rangeOfOperator.ArrayTransformLeft();
            }

            bool[,] range = rangeOfOperator.array;
            int operatorPositionX = rangeOfOperator.x;
            int operatorPositionY = rangeOfOperator.y;

            GameObject rangeTilePrefab = _operatorData.rangeOfOperator.tileRangePrefab;

            rangeTilesParent = new GameObject("Range Tiles");
            rangeTilesParent.transform.SetParent(transform);
            rangeTilesParent.transform.localPosition = new Vector3(-0.5f, 0f, -0.5f);

            for (int x = 0; x < range.GetLength(0); x++)
            {
                for (int y = 0; y < range.GetLength(1); y++)
                {
                    if (range[x, y] == true || (x == operatorPositionX && y == operatorPositionY))
                    {
                        GameObject tileRange = Instantiate(rangeTilePrefab, rangeTilesParent.transform);

                        RangeTile rangeTileComponent = tileRange.GetComponent <RangeTile>();
                        rangeTileComponent.operatorController = this;
                        rangeTiles.Add(rangeTileComponent);

                        Vector3 position = Vector3.zero;
                        if (direction == SetupDirection.Bottom || direction == SetupDirection.Top)
                        {
                            position = new Vector3((operatorPositionY - y) * 1f, 0f, (operatorPositionX - x) * 1f);
                        }
                        if (direction == SetupDirection.Left || direction == SetupDirection.Right)
                        {
                            position = new Vector3((y - operatorPositionY) * 1f, 0f, (x - operatorPositionX) * 1f);
                        }

                        tileRange.GetComponent <BoxCollider>().enabled = isActive;
                        tileRange.transform.localPosition = position;
                    }
                }
            }
            isShowRange = true;
        }