Пример #1
0
    private GameObject GetBlockUnderMouse()
    {
        Camera camera = CameraExtensions.FindCameraUnderMouse();

        if (camera == null)
        {
            return(null);
        }

        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (!Physics.Raycast(ray, out hitInfo))
        {
            return(null);
        }

        GameObject gameObject = RootGameObject.GetRoot(hitInfo.collider.gameObject);

        if (Tags.PALETTE_BLOCK.HasTag(gameObject))
        {
            return(gameObject);
        }

        return(null);
    }
Пример #2
0
    protected void Initialise(GameObject feedbackBlock, GameObject collisionChecker)
    {
        this.feedbackBlock      = feedbackBlock;
        this.dragCollisionBlock = collisionChecker;

        feedbackBlock.Destroy <FeedbackEditorBlock>();
        feedbackOutline         = feedbackBlock.GetComponent <Outline>();
        feedbackOutline.enabled = true;

        feedbackColliders = feedbackBlock.GetComponentsInChildren <BlockCollider>();
        foreach (GameObject go in feedbackBlock.Children(true))
        {
            if (Tags.EDITOR_PIP.HasTag(go))
            {
                go.tag = Tags.TEMPLATE_PIP.TagName();
            }
            else if (Tags.EDITOR_BLOCK.HasTag(go))
            {
                go.tag = Tags.TEMPLATE_BLOCK.TagName();
            }
        }
        if (Tags.EDITOR_BLOCK.HasTag(feedbackBlock))
        {
            feedbackBlock.tag = Tags.TEMPLATE_BLOCK.TagName();
        }

        pipColliders    = dragCollisionBlock.GetComponentsInChildren <PipCollider>();
        currentRotation = dragCollisionBlock.transform.rotation;
        dragCollisionBlock.DestroyInChildren <Renderer>();
        dragCollisionBlock.DestroyInChildren <Outline>();
        foreach (GameObject go in dragCollisionBlock.Children(true))
        {
            if (Tags.EDITOR_PIP.HasTag(go))
            {
                go.tag = Tags.TEMPLATE_PIP.TagName();
            }
            else if (Tags.EDITOR_BLOCK.HasTag(go))
            {
                go.tag = Tags.TEMPLATE_BLOCK.TagName();
            }
        }
        if (Tags.EDITOR_BLOCK.HasTag(dragCollisionBlock))
        {
            dragCollisionBlock.tag = Tags.TEMPLATE_BLOCK.TagName();
        }

        Camera currentCamera = CameraExtensions.FindCameraUnderMouse();

        if (currentCamera != null)
        {
            UpdateCurrentBlock(currentCamera);
        }
    }
Пример #3
0
    // Should be called during Update. If it returns true, then
    // the caller should exit the Update method
    public void DoUpdate()
    {
        if (feedbackBlock != null)
        {
            Camera currentCamera = CameraExtensions.FindCameraUnderMouse();
            if (currentCamera == null)
            {
                return;
            }

            ShowBlocks();
            UpdateRotation(currentCamera);
            UpdateCurrentBlock(currentCamera);

            AnimateRotation();
        }
    }
Пример #4
0
    protected override Collider GetColliderForDrag()
    {
        Camera     camera = CameraExtensions.FindCameraUnderMouse();
        Ray        ray    = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        // Ignore pips when raycasting
        if (Physics.Raycast(ray, out hitInfo))
        {
            GameObject root = RootGameObject.GetRoot(hitInfo.collider.gameObject);
            if (Tags.EDITOR_BLOCK.HasTag(root) && root.transform.parent != null)
            {
                return(hitInfo.collider);
            }
        }

        return(null);
    }
Пример #5
0
    // Update is called once per frame
    public bool CanActivate()
    {
        if (!Input.GetButton(DragButtonName) || EventSystem.current.IsPointerOverGameObject())
        {
            return(false);
        }

        Camera     camera = CameraExtensions.FindCameraUnderMouse();
        Ray        ray    = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo) && Tags.EDITOR_BLOCK.HasTag(hitInfo.collider))
        {
            return(RootGameObject.GetRoot(hitInfo.collider.gameObject).transform.parent == null);
        }
        else
        {
            return(false);
        }
    }
Пример #6
0
    public bool CanActivate()
    {
        // Note, we never return true, but do stuff anyway...
        if (Input.GetButtonDown(SelectionButton) && !EventSystem.current.IsPointerOverGameObject())
        {
            Camera     camera = CameraExtensions.FindCameraUnderMouse();
            Ray        ray    = camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            if (!Physics.Raycast(ray, out hitInfo))
            {
                return(false);
            }

            GameObject newSelection = RootGameObject.GetRoot(hitInfo.collider.gameObject);
            if (Tags.EDITOR_BLOCK.HasTag(newSelection))
            {
                SelectionManager.Selection = newSelection;
            }
        }

        return(false);
    }
Пример #7
0
    private void UpdateLaser()
    {
        Camera camera = CameraExtensions.FindCameraUnderMouse();

        if (camera == null)
        {
            return;
        }

        Vector3 mousePosition = Input.mousePosition;

        mousePosition.z = 50;

        Vector3 target = camera.ScreenToWorldPoint(mousePosition);
        Vector3 delta  = target - laser.transform.position;

        if (delta.magnitude > 30)
        {
            delta  = delta.normalized * 30.0f;
            target = laser.transform.position + delta;
        }

        // First check if the mouse pointer is over a mesh
        Ray           ray = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit    hitInfo;
        bool          hit           = false;
        VoxelRenderer voxelRenderer = null;

        if (Physics.Raycast(ray, out hitInfo, 50.0f))
        {
            target        = hitInfo.point;
            voxelRenderer = hitInfo.collider.gameObject.GetComponentInParent <VoxelRenderer>();

            // Protect a second ray to see if the point we are aiming at would collide first
            ray = new Ray(laser.transform.position, target - laser.transform.position);
            if (Physics.Raycast(ray, out hitInfo, 50.0f))
            {
                target        = hitInfo.point;
                voxelRenderer = hitInfo.collider.gameObject.GetComponentInParent <VoxelRenderer>();
            }

            hit = true;
        }

        if (!hit)
        {
            // If not protect a ray from the origin to the target
            ray = new Ray(laser.transform.position, delta);
            if (Physics.Raycast(ray, out hitInfo, delta.magnitude))
            {
                target        = hitInfo.point;
                voxelRenderer = hitInfo.collider.gameObject.GetComponentInParent <VoxelRenderer>();

                hit = true;
            }
        }

        if (hit && voxelRenderer != null)
        {
            VoxelMap voxelMap      = voxelRenderer.VoxelMap;
            Vector3  localPosition = target - voxelRenderer.gameObject.transform.position;

            Vector3 point;
            point.x = localPosition.x / voxelMap.Scale - voxelMap.Offset.x;
            point.y = localPosition.y / voxelMap.Scale - voxelMap.Offset.y;
            point.z = localPosition.z / voxelMap.Scale - voxelMap.Offset.z;

            // Clamp to the bounds of the map
            int x = Mathf.Clamp(Mathf.RoundToInt(point.x), 0, voxelMap.Columns);
            int y = Mathf.Clamp(Mathf.RoundToInt(point.y), 0, voxelMap.Rows);
            int z = Mathf.Clamp(Mathf.RoundToInt(point.z), 0, voxelMap.Pages);

            IntVector3 nearestVoxel;
            if (voxelMap.FindNearestVoxel(localPosition, out nearestVoxel))
            {
                if (!lastVoxel.Equals(nearestVoxel))
                {
                    lastVoxel      = nearestVoxel;
                    lastVoxelTimer = 0;
                }
                else
                {
                    lastVoxelTimer += Time.deltaTime;
                    if (lastVoxelTimer > 0.1)
                    {
                        Vector3 position = nearestVoxel;
                        position *= voxelMap.Scale;
                        position += voxelMap.Offset;
                        position += voxelRenderer.gameObject.transform.position;

                        DebugUI.DrawCubeCentred(position, new Vector3(voxelMap.Scale, voxelMap.Scale, voxelMap.Scale), voxelRenderer.gameObject.transform.rotation, Color.red);

                        voxelRenderer.RemoveVoxel(nearestVoxel);
                        lastVoxel = IntVector3.UNDEFINED;
                    }
                }
            }
            else
            {
                lastVoxel = IntVector3.UNDEFINED;
            }
        }
        else
        {
            lastVoxel = IntVector3.UNDEFINED;
        }

        delta = target - laser.transform.position;
        Vector3 scale = laser.transform.localScale;

        scale.z = delta.magnitude;

        laser.transform.localScale = scale;
        laser.transform.LookAt(target);

        delta = delta.normalized * (delta.magnitude - 0.1f);

        collision.transform.position = laser.transform.position + delta;
        ParticleSystem[] particles = collision.GetComponentsInChildren <ParticleSystem>();
        foreach (var ps in particles)
        {
            var emission = ps.emission;
            emission.enabled = hit;
        }
    }
Пример #8
0
 protected bool CheckValidPosition()
 {
     return(!feedbackColliders.Any(collider => (collider.GetOtherBlock() != null)) &&
            !Tags.PALETTE_CAMERA.HasTag(CameraExtensions.FindCameraUnderMouse()));
 }