Ejemplo n.º 1
0
    private void OnTriggerEnter(Collider other)
    {
        var farmSpawn = other.GetComponent <FarmSpawn>();

        if (farmSpawn && !farmSpawn.IsGrown())
        {
            farmSpawn.Grow();
            Destroy(gameObject);
        }
        else
        {
            var greenSpawn = other.GetComponent <GreensSpawn>();
            if (greenSpawn && !greenSpawn.IsGrown())
            {
                greenSpawn.Grow();
                Destroy(gameObject);
            }
            else
            {
                var block = other.GetComponent <Block>();
                if (block && block.IsSand())
                {
                    var grassBlockRoot = BlockFactory.Get().GrassBlock();
                    var grassBlock     = grassBlockRoot.GetComponentInChildren <Block>();
                    WorldPlane.Get().ReplaceBlock(block, grassBlock);

                    Destroy(gameObject);
                }
            }
        }
    }
Ejemplo n.º 2
0
    protected void Start()
    {
        _originalLocalPosition = transform.localPosition;

        _originalScale       = transform.localScale * 1.5f;
        transform.localScale = _originalScale;

        _featureToggles = FeatureToggles.Get();
        _worldPlane     = WorldPlane.Get();

        if (isStartingInteractor)
        {
            GetComponentInParent <BlockInteractionPalette>().Select(this);
            Activate();
        }


        _ghost = Instantiate(BlockFactory.Get().interactableGhostTemplate);
        _ghost.SetActive(false);

        _nonInteractableGhost = Instantiate(BlockFactory.Get().nonInteractableGhostTemplate);
        _nonInteractableGhost.SetActive(false);

        _started = true;
    }
        // -------------------------
        /// Calculate joystick's angle and tilt...
        // -------------------------
        static public float GetJoyAngleAndTilt(Transform camTr, float x, float y, WorldPlane plane, out float tilt)
        {
            Vector2 inputv = new Vector2(x, y);

            if (inputv.sqrMagnitude < 0.000001f)
            {
                tilt = 0;
                return(0);
            }

            Vector2 v = GetWorldVecFromCamera(camTr, x, y, plane);
            float   d = v.magnitude;

            if (d < 0.0001f)
            {
                tilt = 0;
                return(0);
            }

            v /= d;

            tilt = Mathf.Min(d, 1.0f);

            return(Mathf.Rad2Deg * Mathf.Atan2(v.x, v.y));
        }
Ejemplo n.º 4
0
    private void OnTriggerExit(Collider other)
    {
        var delta = Time.fixedTime - _enterTime;

        if (delta > .2f)
        {
            var blockInteractor         = other.GetComponent <BlockInteractor>();
            var isSomeInteractionObject = blockInteractor != null && blockInteractor.IsActivated();
            if (isSomeInteractionObject)
            {
                var realCenterPoint = WorldPlane.Get().GetRealCenterPoint();

                var parentTransform = Camera.main.gameObject.transform.parent.gameObject.transform;

                parentTransform.position = new Vector3(
                    0,
                    parentTransform.position.y,
                    0
                    );
                var diff = Camera.main.transform.position - realCenterPoint;
                diff.y = 0;
                parentTransform.position -= diff;

                var currentPosition = parentTransform.position;
                parentTransform.position = new Vector3(currentPosition.x, .4f, currentPosition.z);

                GetComponent <AudioSource>().PlayOneShot(recenterSound);
            }
        }
    }
        // -------------------
        static public Vector3 RotateVecOnPlane(Vector3 v, float angle, WorldPlane plane)
        {
            angle *= Mathf.Deg2Rad;
            float sinv = Mathf.Sin(angle);
            float cosv = Mathf.Cos(angle);

            switch (plane)
            {
            case WorldPlane.XY:
                return(new Vector3(
                           (v.x * cosv) - (v.y * sinv),
                           (v.x * sinv) + (v.y * cosv),
                           v.z));

            case WorldPlane.XZ:
                return(new Vector3(
                           (v.x * cosv) - (v.z * sinv),
                           v.y,
                           (v.x * sinv) + (v.z * cosv)));

            case WorldPlane.ZY:
            default:
                return(new Vector3(
                           v.x,
                           (v.z * sinv) + (v.y * cosv),
                           (v.z * cosv) - (v.y * sinv)));
            }
        }
Ejemplo n.º 6
0
 private void Start()
 {
     _sandSpreadController = SandSpreadController.Get();
     _worldPlane           = WorldPlane.Get();
     _block          = GetComponentInChildren <Block>();
     _featureToggles = FeatureToggles.Get();
 }
Ejemplo n.º 7
0
 public Layout(WorldPlane plane, Orientation orientation, Vector3 size, Vector3 origin)
 {
     Plane       = plane;
     Orientation = orientation;
     Size        = size;
     Origin      = origin;
 }
Ejemplo n.º 8
0
        public void Use(Block block)
        {
            var water      = Instantiate(waterBlockTemplate);
            var waterBlock = water.GetComponentInChildren <Block>();

            WorldPlane.Get().AddBlockOnTopOf(waterBlock, water, block);
            waterBlock.ShortFreeze();
        }
Ejemplo n.º 9
0
    public static void Highlight(List <Block> blocks)
    {
        var worldPlane = WorldPlane.Get();

        foreach (var block in blocks)
        {
            worldPlane.RemoveAndDestroyBlock(block);
        }
    }
Ejemplo n.º 10
0
    void Start()
    {
        _worldPlane           = GetComponent <WorldPlane>();
        _lastPlacedHouse      = Time.fixedTime - 10;
        _sandSpreadController = SandSpreadController.Get();
        _featureToggles       = FeatureToggles.Get();

        _workQueue = WorkQueue.Get();
    }
Ejemplo n.º 11
0
    void Start()
    {
        _life         = Time.fixedTime;
        _block        = GetComponentInChildren <Block>();
        _worldPlane   = GameObject.FindWithTag("WorldPlane").GetComponent <WorldPlane>();
        _workQueue    = WorkQueue.Get();
        _blockFactory = BlockFactory.Get();

        _block.SetAsUnstable();
    }
Ejemplo n.º 12
0
        private Vector3 coordForPlane(WorldPlane plane, float x, float y)
        {
            switch (plane)
            {
            case WorldPlane.XY: return(new Vector3(x, y, 0));

            case WorldPlane.XZ: return(new Vector3(x, 0, y));
            }

            return(Vector3.zero);
        }
        // ----------------------
        static public float GetAngleFromDir(Vector3 dir, WorldPlane plane, float fallbackAngle)
        {
            Vector2 v = ((plane == WorldPlane.XY) ? new Vector2(dir.x, dir.y) : (plane == WorldPlane.XZ) ? new Vector2(dir.x, dir.z) : new Vector2(dir.z, dir.y));

            if (v.sqrMagnitude < 0.000001f)
            {
                return(fallbackAngle);
            }

            v.Normalize();

            return(Mathf.Rad2Deg * Mathf.Atan2(v.x, v.y));
        }
Ejemplo n.º 14
0
    void Start()
    {
        _worldPlane      = WorldPlane.Get();
        _block           = GetComponent <BlockRelative>().block;
        _audioSource     = GetComponent <AudioSource>();
        _cityWoodcutters = CityWoodcutters.Get();

        var rotation = new Vector3(0, Random.value * 360, 0);

        var woodcutterTemplate = woodcutterTemplates[Random.Range(0, woodcutterTemplates.Length)];
        var woodcutter         = Instantiate(woodcutterTemplate);

        woodcutter.transform.SetParent(transform, false);
        woodcutter.transform.Rotate(rotation);
    }
        // -----------------
        static public Vector3 AngleToWorldVec(float angle, WorldPlane plane)
        {
            angle *= Mathf.Deg2Rad;
            float sinv = Mathf.Sin(angle);
            float cosv = Mathf.Cos(angle);

            switch (plane)
            {
            case WorldPlane.XY:
                return(new Vector3(sinv, cosv, 0));

            case WorldPlane.XZ:
                return(new Vector3(sinv, 0, cosv));

            case WorldPlane.ZY:
            default:
                return(new Vector3(0, cosv, sinv));
            }
        }
Ejemplo n.º 16
0
 private float CalculateCellFadeZoom(Camera camera)
 {
     return(WorldPlane.GetAbsDistanceToPoint(camera.transform.position));
 }
Ejemplo n.º 17
0
 void Start()
 {
     _worldPlane = WorldPlane.Get();
     _block      = GetComponent <BlockRelative>().block;
 }
Ejemplo n.º 18
0
 void Start()
 {
     _rigidbody  = GetComponent <Rigidbody>();
     _worldPlane = WorldPlane.Get();
 }
        // ----------------------
        // Transform 2d vector from camera space onto world plane...
        // -----------------------
        static public Vector3 GetWorldVecFromCamera(Transform camTr, float x, float y, WorldPlane plane)
        {
            Vector3 xDir;
            Vector3 yDir;

            switch (plane)
            {
            case WorldPlane.XZ:
                xDir   = camTr.right;
                yDir   = camTr.forward;
                xDir.y = xDir.z;
                yDir.y = yDir.z;
                break;

            case WorldPlane.XY:
                xDir   = camTr.right;
                yDir   = camTr.up;
                xDir.z = 0;
                yDir.z = 0;
                break;

            case WorldPlane.ZY:
            default:
                xDir   = camTr.forward;
                yDir   = camTr.up;
                xDir.x = xDir.z;
                yDir.x = yDir.z;
                //xDir.x = 0;
                //yDir.x = 0;
                break;
            }

            xDir.z = 0;
            yDir.z = 0;

            xDir.Normalize();
            yDir.Normalize();


            return((xDir * x) + (yDir * y));
        }
Ejemplo n.º 20
0
        public void Render_SystemCall()
        {
            if (!Settings.IsVisible)
            {
                return;
            }

            Camera camera = Camera.current;

            if (IsRenderIgnoreCamera(camera))
            {
                return;
            }

            AABB camViewVolumeAABB = camera.CalculateVolumeAABB();

            Vector3 gridPlanePos   = WorldPlane.ProjectPoint(camViewVolumeAABB.Center);
            Vector3 gridPlaneScale = camViewVolumeAABB.Size * 2.0f;

            gridPlaneScale.y = 1.0f;
            Matrix4x4 transformMatrix = Matrix4x4.TRS(gridPlanePos, Rotation, gridPlaneScale);

            // Continue based on whether cell fading is used
            if (LookAndFeel.UseCellFading)
            {
                // We will need to render the grid twice to simulate the grid effect which exists in Unity.
                // When zooming out, it appears that smaller cells fade away while newer and bigger ones
                // appear instead. We can do this by rendering the grid twice with different cell sizes and
                // alpha values. The first step is to calculate the camera zoom (abs y position) and then
                // count the number of digits in this value.
                float cameraZoom = CalculateCellFadeZoom(camera);
                int   numDigits  = MathEx.GetNumDigits((int)cameraZoom);

                // The number of digits inside the camera zoom can be used to calculate two power of 10 values.
                // These values will be used to calculate 2 cell sizes: the small size which is fading out and
                // the bigger size which is fading in.
                // Example (assume XZ cell size of 1 and camera Y pos of 10.5)
                //      Zoom = 10 => NumDigits = 2;
                //      Power0 = 1; Power1 = 2;
                //      SmallCellSize = baseSize * 10 ^ Power0 = 10;
                //      BigCellSize = baseSize * 10 ^ Power1 = 100;
                // So the cell size increases in powers of 10.
                int csPower0 = numDigits - 1;
                int csPower1 = csPower0 + 1;

                // Calculate the cell size scale value based on the calculated powers of 10
                float csScale0 = Mathf.Pow(10.0f, csPower0);
                float csScale1 = Mathf.Pow(10.0f, csPower1);

                // Calculate the alpha scale values. The first alpha scale value is used to fade out the small cells.
                // The second alpha is used to fade in the bigger ones.
                Color color  = LookAndFeel.LineColor;
                float alpha0 = (csScale1 - cameraZoom) / (csScale1 - csScale0);
                float alpha1 = 1.0f - alpha0;

                // Set material properties
                Material material = MaterialPool.Get.XZGrid_Plane;
                material.SetFloat("_CamFarPlaneDist", camera.farClipPlane);
                material.SetVector("_CamWorldPos", camera.transform.position);
                material.SetVector("_GridOrigin", Vector3.zero);
                material.SetVector("_GridRight", Right);
                material.SetVector("_GridLook", Look);
                material.SetMatrix("_TransformMatrix", transformMatrix);

                // Render in 2 passes to achieve the cell fade effect
                color.a = LookAndFeel.LineColor.a * alpha0;
                if (color.a != 0.0f)
                {
                    // Set material properties for this pass
                    material.SetFloat("_CellSizeX", Settings.CellSizeX * csScale0);
                    material.SetFloat("_CellSizeZ", Settings.CellSizeZ * csScale0);
                    material.SetColor("_LineColor", color);
                    material.SetPass(0);

                    // Render
                    Graphics.DrawMeshNow(MeshPool.Get.UnitQuadXZ, transformMatrix);
                }
                color.a = LookAndFeel.LineColor.a * alpha1;
                if (color.a != 0.0f)
                {
                    // Set material properties for this pass
                    material.SetFloat("_CellSizeX", Settings.CellSizeX * csScale1);
                    material.SetFloat("_CellSizeZ", Settings.CellSizeZ * csScale1);
                    material.SetColor("_LineColor", color);
                    material.SetPass(0);

                    // Render
                    Graphics.DrawMeshNow(MeshPool.Get.UnitQuadXZ, transformMatrix);
                }
            }
            else
            {
                // Just render the grid once with the chosen cell size
                Material material = MaterialPool.Get.XZGrid_Plane;
                material.SetFloat("_CamFarPlaneDist", camera.farClipPlane);
                material.SetVector("_CamWorldPos", camera.transform.position);
                material.SetMatrix("_TransformMatrix", transformMatrix);
                material.SetFloat("_CellSizeX", Settings.CellSizeX);
                material.SetFloat("_CellSizeZ", Settings.CellSizeZ);
                material.SetColor("_LineColor", LookAndFeel.LineColor);
                material.SetVector("_GridOrigin", Vector3.zero);
                material.SetVector("_GridRight", Right);
                material.SetVector("_GridLook", Look);
                material.SetPass(0);
                Graphics.DrawMeshNow(MeshPool.Get.UnitQuadXZ, transformMatrix);
            }
        }
Ejemplo n.º 21
0
 public bool Raycast(Ray ray, out float t)
 {
     return(WorldPlane.Raycast(ray, out t));
 }
Ejemplo n.º 22
0
 private void Start()
 {
     _worldPlane = WorldPlane.Get();
 }
Ejemplo n.º 23
0
 void Start()
 {
     _worldPlane     = WorldPlane.Get();
     _workQueue      = WorkQueue.Get();
     _featureToggles = FeatureToggles.Get();
 }
Ejemplo n.º 24
0
 void Start()
 {
     _worldPlane = WorldPlane.Get();
     _workQueue  = WorkQueue.Get();
 }
Ejemplo n.º 25
0
 private void Awake()
 {
     _worldPlaneInstance    = this;
     _topLeftPointTransform = TopLeftPoint.transform;
 }
Ejemplo n.º 26
0
 void Start()
 {
     _worldPlane = GetComponent <WorldPlane>();
 }
Ejemplo n.º 27
0
 private void Awake() // FarmController is only created during the game, and is used right after being created. Therefore we must store static instances in the Awake method instead of Start.
 {
     _worldPlane     = WorldPlane.Get();
     _featureToggles = FeatureToggles.Get();
 }