예제 #1
0
        public MapCollider(IsometricMap map)
        {
            var collidersGroup = map.ObjectGroups["Colliders"];

            Colliders = new PolygonCollider[collidersGroup.Count];

            for (var i = 0; i < collidersGroup.Count; i++)
            {
                var obj = collidersGroup[i];

                var points = new Vector2[4];
                points[0] = new Vector2(obj.Position.X, obj.Position.Y);                          //Topleft
                points[1] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y);              //Topright
                points[2] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y + obj.Height); //BotRight
                points[3] = new Vector2(obj.Position.X, obj.Position.Y + obj.Height);             //BotLeft

                for (var o = 0; o < 4; o++)
                {
                    points[o] = Isometric.WorldToIsometricWorld(points[o], map);
                }

                Colliders[i] = new PolygonCollider(points);

                Colliders[i].SetShouldColliderScaleAndRotateWithTransform(true);
                //entity.addComponent<BoxCollider>(colliders[i]);
            }
        }
예제 #2
0
        public override void Resolve(IsoTransform isoTransform)
        {
            Remove(isoTransform);
            var xyPos = Isometric.IsoToUnitySpace(isoTransform.Position);

            isoTransform.transform.position = new Vector3(xyPos.x, xyPos.y, isoTransform.transform.position.z);

            var index = GetTile(isoTransform);
            int insertIndex;

            if (!_tileDictionary.ContainsKey(index))
            {
                _tileDictionary[index] = new List <IsoTransform>();
                insertIndex            = ~_sortedIndices.BinarySearch(index);
                _sortedIndices.Insert(insertIndex, index);
            }

            insertIndex = _tileDictionary[index].BinarySearch(isoTransform, _yComparer);
            if (insertIndex < 0)
            {
                insertIndex = ~insertIndex;
            }
            _tileDictionary[index].Insert(insertIndex, isoTransform);
            _inverseTileDictionary.Add(isoTransform, index);
        }
예제 #3
0
        private PolygonColliderTrigger[] LoadColliders(IsometricMap map, string groupName)
        {
            var collidersGroup = map.ObjectGroups[groupName];
            var colliders      = new PolygonColliderTrigger[collidersGroup.Count];

            for (var i = 0; i < collidersGroup.Count; i++)
            {
                var obj = collidersGroup[i];

                var points = new Vector2[4];
                points[0] = new Vector2(obj.Position.X, obj.Position.Y);                          //Topleft
                points[1] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y);              //Topright
                points[2] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y + obj.Height); //BotRight
                points[3] = new Vector2(obj.Position.X, obj.Position.Y + obj.Height);             //BotLeft

                for (var o = 0; o < 4; o++)
                {
                    points[o] = Isometric.WorldToIsometricWorld(points[o], map);
                }

                colliders[i] = new PolygonColliderTrigger(points);
                colliders[i].SetShouldColliderScaleAndRotateWithTransform(false);


                //Finally check to see if it has a depth property before adding
                if (obj.Properties.TryGetValue("depth", out var depth))
                {
                    float.TryParse(depth, out var floatValue);
                    colliders[i].Depth = floatValue;
                }

                colliderEntity.AddComponent(colliders[i]);
            }
            return(colliders);
        }
    private void OnDrawGizmos()
    {
        if (!visible && Application.IsPlaying(gameObject))
        {
            return;
        }

        Vector3 boxSize = EffectiveUtility.VectorMultiple(guideSize, Isometric.IsometricTileSize);

        Vector3[] box = new Vector3[]
        {
            transform.parent.position + EffectiveUtility.VectorMultiple(new Vector3(-0.5f, 1f, 0.5f), boxSize),
            transform.parent.position + EffectiveUtility.VectorMultiple(new Vector3(-0.5f, 1f, -0.5f), boxSize),
            transform.parent.position + EffectiveUtility.VectorMultiple(new Vector3(0.5f, 1f, -0.5f), boxSize),
            transform.parent.position + EffectiveUtility.VectorMultiple(new Vector3(0.5f, 1f, 0.5f), boxSize),
            transform.parent.position + EffectiveUtility.VectorMultiple(new Vector3(-0.5f, 0f, -0.5f), boxSize),
            transform.parent.position + EffectiveUtility.VectorMultiple(new Vector3(0.5f, 0f, -0.5f), boxSize),
            transform.parent.position + EffectiveUtility.VectorMultiple(new Vector3(0.5f, 0f, 0.5f), boxSize)
        };

        Gizmos.color = new Color(0.1f, 0.9f, 0.1f);
        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[0]), Isometric.TranslationIsometricToScreen(box[1]));
        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[1]), Isometric.TranslationIsometricToScreen(box[2]));
        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[2]), Isometric.TranslationIsometricToScreen(box[3]));
        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[3]), Isometric.TranslationIsometricToScreen(box[0]));

        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[1]), Isometric.TranslationIsometricToScreen(box[4]));
        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[2]), Isometric.TranslationIsometricToScreen(box[5]));
        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[3]), Isometric.TranslationIsometricToScreen(box[6]));

        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[4]), Isometric.TranslationIsometricToScreen(box[5]));
        Gizmos.DrawLine(Isometric.TranslationIsometricToScreen(box[5]), Isometric.TranslationIsometricToScreen(box[6]));

        Gizmos.color = Color.white;
    }
        public static GameObject BuildPrefab(AvatarData avatarData)
        {
            GameObject go = new GameObject();

            go.name = unitName;
            SpriteRenderer spriteRender = go.AddComponent <SpriteRenderer>();
            Isometric      isometric    = go.AddComponent <Isometric>();

            isometric.faceCamera = true;
            go.AddComponent <SpriteAnimation>();
            SpriteAvatar avatar = go.AddComponent <SpriteAvatar>();

            avatar.avatarData = avatarData;
            avatar.action     = defaultAction;
            avatar.angle      = defaultAngle;
            if (autoDestory)
            {
                go.AddComponent <AutoDestoryOnActionComplete>();
            }

            string path = PrefabPath + "/" + typeName + "/" + unitName + ".prefab";

            CheckPath(path);
            PrefabUtility.CreatePrefab(path, go);
            DestroyImmediate(go);
            return(go);
        }
예제 #6
0
        public override void Draw(double frameTime)
        {
            AEntity    player = WorldModel.Entities.GetPlayerEntity();
            Position3D center = player.Position;

            if ((player as Mobile).IsAlive)
            {
                AEntityView.s_Technique = Techniques.Default;
                m_ShowingDeathEffect    = false;
                if (m_YouAreDead != null)
                {
                    m_YouAreDead.Dispose();
                    m_YouAreDead = null;
                }
            }
            else
            {
                if (!m_ShowingDeathEffect)
                {
                    m_ShowingDeathEffect         = true;
                    m_DeathEffectTime            = 0;
                    m_LightingGlobal             = Isometric.Lighting.OverallLightning;
                    m_LightingPersonal           = Isometric.Lighting.PersonalLightning;
                    m_UI.AddControl(m_YouAreDead = new YouAreDeadGump(), 0, 0);
                }

                double msFade = 2000d;
                double msHold = 1000d;

                if (m_DeathEffectTime < msFade)
                {
                    AEntityView.s_Technique              = Techniques.Default;
                    Isometric.Lighting.OverallLightning  = (int)(m_LightingGlobal + (0x1f - m_LightingGlobal) * ((m_DeathEffectTime / msFade)));
                    Isometric.Lighting.PersonalLightning = (int)(m_LightingPersonal * (1d - (m_DeathEffectTime / msFade)));
                }
                else if (m_DeathEffectTime < msFade + msHold)
                {
                    Isometric.Lighting.OverallLightning  = 0x1f;
                    Isometric.Lighting.PersonalLightning = 0x00;
                }
                else
                {
                    AEntityView.s_Technique              = Techniques.Grayscale;
                    Isometric.Lighting.OverallLightning  = (int)m_LightingGlobal;
                    Isometric.Lighting.PersonalLightning = (int)m_LightingPersonal;
                    if (m_YouAreDead != null)
                    {
                        m_YouAreDead.Dispose();
                        m_YouAreDead = null;
                    }
                }

                m_DeathEffectTime += frameTime;
            }

            Isometric.Update(Model.Map, center, Model.Input.MousePick);
            MiniMap.Update(Model.Map, center);
        }
        void OnEnable()
        {
            Isometric.IsoMatrix = Isometric.GetProjectionMatrix(Projection, XRot, YRot);
#if UNITY_EDITOR
            foreach (var isoTransform in FindObjectsOfType <IsoTransform>())
            {
                Resolve(isoTransform);
            }
#endif
        }
예제 #8
0
        public IsoRaycastHit gethit()
        {
            var           isoRay = Isometric.MouseToIsoRay();
            IsoRaycastHit isoRaycasthit;

            if (IsoPhysics.Raycast(isoRay, out isoRaycasthit))
            {
                return(isoRaycasthit);
            }
            return(isoRaycasthit);
        }
예제 #9
0
        private void UpdateOnMouseCallbacks()
        {
            //raycast
            IsoRaycastHit hit;

            if (IsoPhysics.Raycast(Isometric.MouseToIsoRay(), out hit))
            {
                if (_mouseOverIsoTransform != null)
                {
                    if (hit.IsoTransform != _mouseOverIsoTransform)
                    {
                        _mouseOverIsoTransform.SendMessage("OnMouseExit", SendMessageOptions.DontRequireReceiver);
                        hit.IsoTransform.SendMessage("OnMouseEnter", SendMessageOptions.DontRequireReceiver);
                    }
                    else
                    {
                        _mouseOverIsoTransform.SendMessage("OnMouseOver", SendMessageOptions.DontRequireReceiver);
                    }
                }
                else
                {
                    hit.IsoTransform.SendMessage("OnMouseEnter", SendMessageOptions.DontRequireReceiver);
                }

                _mouseOverIsoTransform = hit.IsoTransform;
                if (Input.GetMouseButtonDown(0))
                {
                    _mouseOverIsoTransform.SendMessage("OnMouseDown", SendMessageOptions.DontRequireReceiver);
                }

                if (Input.GetMouseButtonUp(0))
                {
                    _mouseOverIsoTransform.SendMessage("OnMouseUp", SendMessageOptions.DontRequireReceiver);
                }
            }
            else
            {
                if (_mouseOverIsoTransform != null)
                {
                    _mouseOverIsoTransform.SendMessage("OnMouseExit", SendMessageOptions.DontRequireReceiver);
                    if (Input.GetMouseButtonDown(0))
                    {
                        _mouseOverIsoTransform.SendMessage("OnMouseDown", SendMessageOptions.DontRequireReceiver);
                    }

                    if (Input.GetMouseButtonUp(0))
                    {
                        _mouseOverIsoTransform.SendMessage("OnMouseUp", SendMessageOptions.DontRequireReceiver);
                    }
                }

                _mouseOverIsoTransform = null;
            }
        }
            public Hexagon(IsoTransform isoTransform)
            {
                var isoMin = isoTransform.Position - isoTransform.Size / 2;
                var isoMax = isoTransform.Position + isoTransform.Size / 2;

                _min = new Vector2(isoMin.x + isoMin.y, isoMin.z + isoMin.y);
                _max = new Vector2(isoMax.x + isoMax.y, isoMax.z + isoMax.y);
                var left  = Isometric.IsoToUnitySpace(isoTransform.Position + new Vector3(-isoTransform.Size.x / 2, -isoTransform.Size.y / 2, isoTransform.Size.z / 2)).x;
                var right = Isometric.IsoToUnitySpace(isoTransform.Position + new Vector3(isoTransform.Size.x / 2, -isoTransform.Size.y / 2, -isoTransform.Size.z / 2)).x;

                _h = new Vector2(left, right);
            }
예제 #11
0
    /// <summary>
    /// creates a handle in left axis. return the delta movement on the isometric wEst axis.
    /// </summary>
    /// <param name="isoPosition"></param> the isometric position of our object. Pass the transform.position component
    /// <returns></returns>
    float handleY(Vector3 pos)
    {
        GUI.SetNextControlName("y");
        Handles.color = new Color(1.0f, 1.0f, 1.0f, 0.75f);
        var dir   = Isometric.isoProjection(Isometric.vectorToIsoDirection(IsoDirection.West));
        var delta = Handles.Slider(pos, dir);
        var d     = delta - pos;

        var res = d.magnitude * ((Math.Sign(d.x) == Math.Sign(dir.x)) ? 1 : -1);

        return(res);
    }
예제 #12
0
    /// <summary>
    /// creates a handle in Up axis. return the delta movement on the isometric up axis.
    /// </summary>
    /// <param name="isoPosition"></param> the isometric position of our object
    /// <returns></returns>
    float handleZ(Vector3 isoPosition)
    {
        GUI.SetNextControlName("z");
        Handles.color = new Color(1.0f, 0.0f, 0.0f, 0.75f);
        var dir   = Isometric.isoProjection(Isometric.vectorToIsoDirection(IsoDirection.Up));
        var delta = Handles.Slider(isoPosition, dir);
        var d     = delta - isoPosition;

        var res = d.magnitude * ((Math.Sign(d.y) == Math.Sign(dir.y)) ? 1 : -1);

        return(res);
    }
예제 #13
0
        void OnMouseDrag()
        {
            if (!Input.GetMouseButton(0))
            {
                return;
            }
            //Press delete or backspace, then delete
            if (Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace))
            {
                Destroy(gameObject);
            }

            var mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            //avoids raycasting to ourself
            disableColldiers();

            var hit = Physics2D.Raycast(mouseWorldPos, Vector2.zero);

            if (hit.collider != null)
            {
                //did we hit a IsoObject
                var hitIsoObject = hit.collider.GetComponent <IsoTransform>();
                if (hitIsoObject != null)
                {
                    //calc the new height were we want to put our object at
                    var newHeight = hitIsoObject.Position.y + hitIsoObject.Size.y / 2f + isoObject.Size.y / 2f;

                    //calc the final position
                    var pos = Isometric.CreateXYZfromY(Input.mousePosition, newHeight);
                    if (pos != null)
                    {
                        //pos = Ceil(pos);
                        if (FindObjectsOfType <IsoTransform>().All(c => c.Position != pos))
                        {
                            isoObject.Position = pos.Value;
                        }
                    }
                }
            }
            else
            {
                //we didn't hit anything, keep the current height
                var pos = Isometric.CreateXYZfromY(Input.mousePosition, isoObject.Position.y + isoObject.Size.y / 2f);
                //pos = Ceil(pos);
                if (pos != null)
                {
                    isoObject.Position = pos.Value;
                }
            }
            //turn colliders back on
            enableColldiers();
        }
 void forward()
 {
     if (canMoveForward())
     {
         inAction = true;
         var newPos = this.isoObj.Position + Isometric.vectorToIsoDirection(currentForwardDirection);
         positionInMap += Isometric.vectorToIsoDirection(currentForwardDirection);
         moveTo(newPos, (x) => EasingFunctions.QuadEaseOut(x, 0, 1, forwardSpeed), () => {
             inAction = false;
         }, 0, forwardSpeed);
     }
 }
예제 #15
0
        private void Raycast()
        {
            if (ReflectionUIManager.instance.is_ui_open)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                //カメラ位置からマウス方向への光線
                var           isoRay = Isometric.MouseToIsoRay();
                IsoRaycastHit isoRaycastHit;
                if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
                {
                    try
                    {
                        isoRaycastHit.IsoTransform.gameObject.GetComponent <AbstractBuildingBehavior>().ClickAction();
                    }
                    catch
                    {
                    }
                }
                if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
                {
                    Vector2 select_vec = ConvertVector.instance.Vec3ToIndexIsoXZ(isoRaycastHit.Point);
                    StartCoroutine(Blink(isoRaycastHit.IsoTransform.GetComponent <SpriteRenderer>(), Color.red));
                    BuildingControl.instance.Building(select_vec);
                }

                if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
                {
                    Debug.Log("Moving to " + isoRaycastHit.Point);
                    Debug.Log("Isotransform: " + isoRaycastHit.IsoTransform.Position);
                    AstarAgent.MoveTo(isoRaycastHit.Point);
                }

                //Destroy(isoRaycastHit.IsoTransform.gameObject);

                //MapManager.instance.MapDown(isoRaycastHit.IsoTransform);
            }
            if (Input.GetMouseButtonDown(1))
            {
                //カメラ位置からマウス方向への光線
                var           isoRay = Isometric.MouseToIsoRay();
                IsoRaycastHit isoRaycastHit;
                if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
                {
                    Vector2 select_vec = ConvertVector.instance.Vec3ToIndexIsoXZ(isoRaycastHit.Point);
                    Destroy(isoRaycastHit.IsoTransform.gameObject);
                }
            }
        }
    private void jumpUp()
    {
        var finalNewPos = posInMapToWorldPos(positionInMap + Isometric.vectorToIsoDirection(currentForwardDirection) + Isometric.vectorToIsoDirection(IsoDirection.Up));
        var tempNewPos  = posInMapToWorldPos(positionInMap + Isometric.vectorToIsoDirection(currentForwardDirection) * 2 / 3f + Isometric.vectorToIsoDirection(IsoDirection.Up) * 4 / 3f);

        inAction = true;
        moveTo(tempNewPos, (x) => EasingFunctions.Linear(x, 0, 1, forwardSpeed * 2 / 3f), () => {
            moveTo(finalNewPos, (x) => EasingFunctions.Linear(x, 0, 1, forwardSpeed * 1 / 3f), () => {
                positionInMap = positionInMap + Isometric.vectorToIsoDirection(currentForwardDirection) + Isometric.vectorToIsoDirection(IsoDirection.Up);
                inAction      = false;
            }, 0, forwardSpeed * 1 / 3f);
        }, 0, forwardSpeed * 2 / 3f);
    }
예제 #17
0
        private void ZAxisHandle()
        {
            Handles.color = Handles.zAxisColor;
            var screenHandlePos = Isometric.IsoToUnitySpace(_isoHandlePos);
            var deltaMovement   = Handles.Slider(screenHandlePos, Isometric.IsoToUnitySpace(Vector3.forward)) - screenHandlePos;

            if (!(Mathf.Abs(deltaMovement.y) > Mathf.Epsilon))
            {
                return;
            }
            ApplyZAxisChanges(deltaMovement.y);
            _isoHandlePos = _selectedObjects.Aggregate(Vector3.zero, (runningSum, t) => runningSum + t.Position) / _selectedObjects.Count;
        }
예제 #18
0
 // Update is called once per frame
 void Update()
 {
     //raycast when mouse clicked
     if (Input.GetMouseButtonDown(0))
     {
         var           isoRay = Isometric.MouseToIsoRay();
         IsoRaycastHit isoRaycastHit;
         if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
         {
             Debug.Log("Moving to " + isoRaycastHit.Point);
             AstarAgent.MoveTo(isoRaycastHit.Point);
         }
     }
 }
예제 #19
0
    /// <summary>
    /// Updates the instance, occurs after Update(). Used for depth sorting.
    /// </summary>
    private void LateUpdate()
    {
        // Depth sorting

        // Check if the object is static
        if (Static && _staticDone)
        {
            return;
        }

        Isometric.DepthSort(gameObject, Offset);

        // Set _staticDone
        _staticDone = true;
    }
예제 #20
0
    public static MeshObject GetStaticMesh(LightTilemapCollider.Base tilemap)
    {
        switch (tilemap.TilemapType())
        {
        case MapType.UnityRectangle:
            return(Rectangle.GetStaticMesh());

        case MapType.UnityIsometric:
            return(Isometric.GetStaticMesh());

        case MapType.UnityHexagon:
            return(Hexagon.GetStaticMesh());
        }

        return(null);
    }
예제 #21
0
        public static IsoHexSpriteTile IsoHexSpriteTileAt(Vector3Int _coordinate)
        {
            GameObject prefab = TurnBasedGameKit.DemoIsoTilemap.ResourcesLoader.m_IsoSquareSpriteTilePrefab;

            GameObject hex = Object.Instantiate(prefab) as GameObject;

            hex.transform.SetParent(m_Parent, false);

            Vector2 converted = Isometric.TwoDToIso(_coordinate.x, _coordinate.y);
            Vector3 pos       = new Vector3(converted.x, converted.y, 0f);

            hex.transform.localPosition = pos;
            IsoHexSpriteTile tile = hex.GetComponent <IsoHexSpriteTile>();

            tile.m_Property.m_Coordinate = _coordinate;
            return(tile);
        }
예제 #22
0
    void Update()
    {
        if (!selected && Input.GetKeyDown(KeyCode.Alpha1))
        {
            select();
        }

        if (selected && Input.GetMouseButtonDown(0) && Input.mousePosition.y >= 150)
        {
            Vector3 pos = (Vector3)Isometric.CreateXYZfromY(Input.mousePosition, 0);
            if (GridManager.get().cut((int)(Math.Round(pos.x)) - 1, (int)(Math.Round(pos.z)) - 1))
            {
                if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
                {
                    leaveSelection();
                }
            }
        }
    }
예제 #23
0
    public static void DrawWireCube(Vector3 position, Vector3 size)
    {
        var half = size / 2;

        // draw front
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(-half.x, -half.y, half.z)), Isometric.isoProjection(position + new Vector3(half.x, -half.y, half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(-half.x, -half.y, half.z)), Isometric.isoProjection(position + new Vector3(-half.x, half.y, half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(half.x, half.y, half.z)), Isometric.isoProjection(position + new Vector3(half.x, -half.y, half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(half.x, half.y, half.z)), Isometric.isoProjection(position + new Vector3(-half.x, half.y, half.z)));
        // draw back
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(-half.x, -half.y, -half.z)), Isometric.isoProjection(position + new Vector3(half.x, -half.y, -half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(-half.x, -half.y, -half.z)), Isometric.isoProjection(position + new Vector3(-half.x, half.y, -half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(half.x, half.y, -half.z)), Isometric.isoProjection(position + new Vector3(half.x, -half.y, -half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(half.x, half.y, -half.z)), Isometric.isoProjection(position + new Vector3(-half.x, half.y, -half.z)));
        // draw corners
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(-half.x, -half.y, -half.z)), Isometric.isoProjection(position + new Vector3(-half.x, -half.y, half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(half.x, -half.y, -half.z)), Isometric.isoProjection(position + new Vector3(half.x, -half.y, half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(-half.x, half.y, -half.z)), Isometric.isoProjection(position + new Vector3(-half.x, half.y, half.z)));
        Handles.DrawLine(Isometric.isoProjection(position + new Vector3(half.x, half.y, -half.z)), Isometric.isoProjection(position + new Vector3(half.x, half.y, half.z)));
    }
예제 #24
0
        public override void Render(Graphics graphics, Camera camera)
        {
            for (var y = 1; y <= map.Height; y++)
            {
                for (var x = 1; x <= map.Width; x++)
                {
                    var index   = Indices[x - 1, y - 1];                           //-1 because indices are zero indexed.
                    var tileset = Tileset.TilesetForPosition(index, map.Tilesets); //Tileset the index belongs to.

                    var subTexturePosition =
                        index - tileset.FirstGid; //Resets position to start at 0 for the subtexture positioning.
                    if (subTexturePosition <= -1)
                    {
                        continue;                       //Don't render empty tiles.
                    }
                    var worldpos =
                        Isometric.IsometricToWorld(new Point(x - 1, y - 1), map); //Isometric Projection to world coords.

                    //Culling
                    if (worldpos.X > camera.Bounds.X + camera.Bounds.Width ||   //Right side
                        worldpos.Y > camera.Bounds.Y + camera.Bounds.Height ||  //Bottom
                        worldpos.X < camera.Bounds.X - map.LargestTileSize.X || //Left
                        worldpos.Y < camera.Bounds.Y - map.LargestTileSize.Y)   //Top
                    {
                        continue;                                               //Don't draw l
                    }
                    var columnRounding = subTexturePosition % tileset.Columns;
                    var sourceRect     = new RectangleF //Subposition in texture.
                    {
                        X = (columnRounding * tileset.TileWidth),
                        Y = (subTexturePosition / tileset.Columns) *
                            tileset.TileHeight,    //Y needs rounding.
                        Width  = tileset.TileWidth,
                        Height = tileset.TileHeight
                    };

                    //Finally draw.
                    graphics.Batcher.Draw(tileset.Texture, worldpos, sourceRect, Color.White, 0, new Vector2(0, 0), 1, SpriteEffects.None, 0);
                }
            }
        }
예제 #25
0
        public override void Resolve(IsoTransform isoTransform)
        {
            if (isoTransform == null)
            {
                return;
            }

            //apply xy screen position
            var posXY = Isometric.IsoToUnitySpace(isoTransform.Position);

            isoTransform.transform.position = new Vector3(posXY.x, posXY.y, isoTransform.transform.position.z);

            //add if not exists
            SortingState sortingState;

            if (!_isoTransformToSortingState.TryGetValue(isoTransform, out sortingState))
            {
                sortingState = new SortingState(isoTransform);
                _nodes.Add(sortingState);
                _isoTransformToSortingState.Add(isoTransform, sortingState);
            }

            //remove from parent dependencies
            for (int i = 0; i < sortingState.ParentDependencies.Count; i++)
            {
                sortingState.ParentDependencies[i].ChildDependencies.Remove(sortingState);
            }

            sortingState.ParentDependencies.Clear();

            //remove from child dependencies
            for (int i = 0; i < sortingState.ChildDependencies.Count; i++)
            {
                var childDependency = sortingState.ChildDependencies[i];
                childDependency.ParentDependencies.Remove(sortingState);
            }

            sortingState.ChildDependencies.Clear();
            sortingState.Hexagon = new Hexagon(isoTransform);
            CalculateDependencies(sortingState);
        }
예제 #26
0
    void OnGUI()
    {
        GUILayout.Label("Base Settings", EditorStyles.boldLabel);

        GUILayout.Label("TileSize_X : " + Isometric.IsometricTileSize.x);
        GUILayout.Label("TileSize_Y : " + Isometric.IsometricTileSize.y);
        GUILayout.Label("TileSize_Z : " + Isometric.IsometricTileSize.z);

        float x = EditorGUILayout.FloatField("RenderSize_X", Isometric.IsometricRenderSize.x);
        float y = EditorGUILayout.FloatField("RenderSize_Y", Isometric.IsometricRenderSize.y);

        Isometric.IsometricRenderSize = new Vector2(x, y);

        if (GUILayout.Button("Calc Isometric Rotation"))
        {
            float tileSize = Isometric.IsometricRenderSize.x / Mathf.Sqrt(2);
            Isometric.IsometricTileSize = Vector3.one * tileSize;
            Isometric.SaveConfig();
            Isometric.CalcIsometricRotation(Isometric.IsometricRenderSize);
        }
    }
예제 #27
0
        public void CalculateTileProperties()
        {
            //Set tile properties to the same size as the map.
            TileProperties = new DenseArray <TileProperties>(Width, Height);

            //For each item
            var properties = ObjectGroups["TileProperties"];

            foreach (var tiledObject in properties)
            {
                //Create a new item.
                var tileProperties = new TileProperties();

                //Parse properties
                tileProperties = tiledObject.Properties
                                 .Aggregate(tileProperties, (current, tiledObjectProperty) =>
                                            TilePropertyMap[tiledObjectProperty.Key].Invoke(tiledObjectProperty.Value, current));

                //find prositon and store.
                var pos = Isometric.WorldToIsometric(tiledObject.WorldPosition, this);
                TileProperties[(int)pos.X, (int)pos.Y] = tileProperties;
            }
        }
예제 #28
0
        // Update is called once per frame
        void Update()
        {
            //mouse ray in unity's coordinate system (used for debug purposes only)
            var ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
            var color = Input.GetMouseButton(0) ? Color.red : Color.white;

            Debug.DrawRay(ray.origin, ray.direction * 1000, color);

            //mouse ray in isometric coordinate system
            var isoRay = Isometric.MouseToIsoRay();

            //do an isometric raycast on left mouse click
            if (Input.GetMouseButtonDown(0))
            {
                IsoRaycastHit isoRaycastHit;
                if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
                {
                    Debug.Log("we clicked on " + isoRaycastHit.Collider.name + " at " + isoRaycastHit.Point);
                    SpawnFlower(isoRaycastHit.Point);
                    StartCoroutine(Blink(isoRaycastHit.IsoTransform.GetComponent <SpriteRenderer>(), Color.red));
                }
            }
        }
예제 #29
0
        public void Update()
        {
            // Handle mouse movement
            if (Input.GetMouseButtonDown(0) && !mouseDebounce && trackMouse)
            {
                trackMouse = false;

                var isoRay = Isometric.MouseToIsoRay();

                //do an isometric raycast on left mouse click
                if (Input.GetMouseButtonDown(0))
                {
                    IsoRaycastHit isoRaycastHit;

                    if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
                    {
                        selectedObj = isoRaycastHit.IsoTransform;

                        // Update instruction text
                        component2 =
                            new InstructionComponent("X: " + selectedObj.Position.x + " Z: " + selectedObj.Position.z)
                        {
                            OnComponentClicked = onClicked
                        };
                        targetPos = new Vector3(selectedObj.Position.x, 1, selectedObj.Position.z);
                        instructionRenderer.Render();
                    }
                }

                if (instructionRenderer != null)
                {
                    instructionRenderer.BackgroundColor = instructionRenderer.DefaultBackgroundColor;
                }
            }

            mouseDebounce = false;
        }
예제 #30
0
    public void init()
    {
        float x = transform.position.x;
        float y = transform.position.y;

        Camera  camera = GetComponent <Camera>();
        Vector3 p      = camera.ScreenToWorldPoint(new Vector3(0, 0, camera.nearClipPlane));
        Vector3 b      = camera.ScreenToWorldPoint(new Vector3(0, 150, camera.nearClipPlane));

        Vector3 left = (Vector3)Isometric.IsoToScreen(new Vector3(0, 0, GridManager.get().size + 1));

        xmin = left.x + x - p.x;
        Vector3 right = (Vector3)Isometric.IsoToScreen(new Vector3(GridManager.get().size + 1, 0, 0));

        xmax = right.x - x + p.x;
        Vector3 bottom = (Vector3)Isometric.IsoToScreen(new Vector3(0, 0, 0));

        ymin = bottom.y + b.y - p.y;
        Vector3 top = (Vector3)Isometric.IsoToScreen(new Vector3(GridManager.get().size + 2, 0, GridManager.get().size + 2));

        ymax = top.y - y + p.y;

        lastFrame = (float)Time.time;
    }