Ejemplo n.º 1
0
    public O_ClassDoodad _getDoodFromPoint(float posX, float posY, string doodName = "Any")
    {
        O_ClassDoodad retDood = O_Globals.I.doodads [0];

        foreach (O_ClassDoodad dood in O_Globals.I.doodads)
        {
            if (dood.posX == posX && dood.posY == posY)
            {
                if (dood.type == doodName || doodName == "Any" || (doodName == "Corner" && dood.isCorner))
                {
                    retDood = dood;
                }
                break;
            }
        }
        return(retDood);
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (!editorMode)
        {
            return;
        }
        try{
            Vector3 gamePoint = O_ControlCamera.I._getGamePoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y));
            int     actPosX = (int)gamePoint.x, actPosY = (int)gamePoint.y;

            // Doodad and tail rotation
            float zRotation = 0;
            if (rotateDood)
            {
                float.TryParse(doodRotation, out zRotation);
            }

            #region "Mouse Click"
            if (Input.GetMouseButton(0))
            {
                #region "Terrain Brush"
                if (brushMode == "Terrain")
                {
                    O_ClassTerrain targetTile = O_GetTerrain.I._getTerrain(actPosX, actPosY);
                    targetTile._changeTerrain(O_DB_Terrain.I._getSprite(terType), terType);
                    targetTile.sprite.name = targetTile.sprite.name.Replace("(Clone)", "");
                    targetTile.sprite.transform.SetParent(GameObject.Find("_O_TERRAIN").transform);
                }
                #endregion
                #region "Unit Brush"
                else if (brushMode == "Unit")
                {
                    // Remove existing unit if present
                    bool hasUnit = O_GetUnit.I._pointHasUnit(actPosX, actPosY);
                    if (hasUnit)
                    {
                        O_ControlUnit.I._addToDestroyList(O_GetUnit.I._getUnitFromPoint(actPosX, actPosY));
                    }

                    // Create Unit
                    O_ControlUnit.I._createUnit(unitType, actPosX, actPosY);

                    // Specials
                    O_ClassUnit createdUnit = O_GetUnit.I._getLastCreatedUnit();
                    switch (createdUnit.type)
                    {
                    case "pathBlocker":
                        // Switch pathBlocker sprite
                        createdUnit._changeSprite("pathBlocker_Editor");
                        createdUnit.sprite.transform.SetParent(GameObject.Find("_O_UNITS").transform);
                        break;
                    }

                    // Finalize creation
                    createdUnit.sprite.name = createdUnit.sprite.name.Replace("(Clone)", "");
                    createdUnit.sprite.transform.SetParent(GameObject.Find("_O_UNITS").transform);
                }
                #endregion
                #region "Doodad Brush (Per Tile)"
                else if (brushMode == "Doodad")
                {
                    // Remove existing doodad if present
                    bool hasDood = O_GetDoodad.I._pointHasDood(actPosX, actPosY);
                    if (hasDood)
                    {
                        O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX, actPosY));
                    }

                    // Create Doodad
                    if (rotateDood)
                    {
                        O_ControlDoodad.I._createDoodad(doodType, actPosX, actPosY, zRotation);
                    }
                    else
                    {
                        O_ControlDoodad.I._createDoodad(doodType, actPosX, actPosY);
                    }

                    // Specials
                    O_ClassDoodad createdDood = O_GetDoodad.I._getLastCreatedDood();
                    /*Create tail*/ if (createTail)
                    {
                        O_ControlDoodad.I._createTails(createdDood, isTailTree, zRotation);
                    }

                    // Finalize creation
                    createdDood.sprite.name = createdDood.sprite.name.Replace("(Clone)", "");
                    createdDood.sprite.transform.SetParent(GameObject.Find("_O_DOODADS").transform);
                }
                #endregion
                #region "Corner Brush"
                else if (brushMode == "Corner")
                {
                    // Remove existing corner if present
                    bool hasDood = O_GetDoodad.I._pointHasDood(actPosX, actPosY, "Corner");
                    if (hasDood)
                    {
                        O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX, actPosY, "Corner"));
                    }

                    // Create Doodad
                    string cornerType_orig = cornerType;

                    if (cornerBase == "Line")
                    {
                    }
                    else
                    {
                        if (cornerBase == "Outward")
                        {
                            cornerType += "Corner3";
                        }
                        else if (cornerBase == "Inward")
                        {
                            cornerType += "Corner2";
                        }

                        float zRot = 0;
                        float.TryParse(cornerLine, out zRot);
                        O_ControlDoodad.I._createDoodad(cornerType, actPosX, actPosY, zRot);
                    }

                    // Specials
                    O_ClassDoodad createdDood = O_GetDoodad.I._getLastCreatedDood();
                    /*Return original cornerBase*/ cornerType = cornerType_orig;

                    // Finalize creation
                    createdDood.sprite.name = createdDood.sprite.name.Replace("(Clone)", "");
                    createdDood.sprite.transform.SetParent(GameObject.Find("_O_DOODADS").transform);
                }
                #endregion
                #region "Unit Eraser"
                else if (brushMode == "Unit Eraser")
                {
                    // Remove existing unit if present
                    bool hasUnit = O_GetUnit.I._pointHasUnit(actPosX, actPosY);
                    if (hasUnit)
                    {
                        O_ControlUnit.I._addToDestroyList(O_GetUnit.I._getUnitFromPoint(actPosX, actPosY));
                        Debug.Log("Unit erased!");
                    }
                }
                #endregion
                #region "Doodad Eraser"
                else if (brushMode == "Doodad Eraser")
                {
                    // Remove existing unit if present
                    bool hasDood = O_GetDoodad.I._pointHasDood(actPosX, actPosY);
                    if (hasDood)
                    {
                        O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX, actPosY));
                        Debug.Log("Doodad erased!");

                        // Remove tails
                        for (float x = -0.5f; x < 1; x += 0.25f)
                        {
                            for (float y = -0.5f; y < 1; y += 0.25f)
                            {
                                hasDood = O_GetDoodad.I._pointHasDood(actPosX + x, actPosY + y);
                                if (hasDood)
                                {
                                    O_ControlDoodad.I._addToDestroyList(O_GetDoodad.I._getDoodFromPoint(actPosX + x, actPosY + y));
                                }
                            }
                        }
                    }
                }
                #endregion
            }
            #endregion

            #region "Keyboard Keys"
            if (Input.GetKey(KeyCode.E) && !telePressed)
            {
                O_ControlHero.I._instantMove(actPosX, actPosY);
                Debug.Log("Teleported to " + actPosX + ", " + actPosY + ", " + telePressed);

                telePressed = true;
            }
            else if (!Input.GetKey(KeyCode.E) && telePressed)
            {
                telePressed = false;
            }
            #endregion

            #region "Bursh control"
            brush.transform.position = new Vector3(actPosX, actPosY, 0);
            #endregion
        }catch (Exception ex) {
            Debug.Log("Turning off editor mode. Reason: " + ex.Message);
            _turnOffEditor(true);
        }
    }
Ejemplo n.º 3
0
    // Tail Creator
    //	- Gets a newly created doodad via editor
    #region "MISC - Tail Creator"
    public void _createTails(O_ClassDoodad createdDood, bool isTree, float zRotation)
    {
        float doodX = createdDood.posX, doodY = createdDood.posY;

        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                // Skip created doodad and diagonal corners
                if (x == 0 && y == 0)
                {
                    continue;
                }
                if (x != 0 && y != 0)
                {
                    continue;
                }

                // Check if doodad node exists
                if (!O_GetDoodad.I._pointHasDood(doodX + x, doodY + y))
                {
                    continue;
                }
                O_ClassDoodad nodeDood = O_GetDoodad.I._getDoodFromPoint(doodX + x, doodY + y);

                // Created doodad should be the same with the node doodad
                if (createdDood.type != nodeDood.type)
                {
                    continue;
                }

                bool isXAlign = (createdDood.posX != nodeDood.posX) ? true : false;

                // Non-trees
                if (!isTree)
                {
                    if (isXAlign)
                    {
                        if (createdDood.posX > nodeDood.posX)
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.5f, createdDood.posY - 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.5f, createdDood.posY + 0.5f, zRotation);
                        }
                        else
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.5f, createdDood.posY - 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.5f, createdDood.posY + 0.5f, zRotation);
                        }
                    }
                    else
                    {
                        if (createdDood.posY > nodeDood.posY)
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.5f, createdDood.posY - 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.5f, createdDood.posY - 0.5f, zRotation);
                        }
                        else
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.5f, createdDood.posY + 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.5f, createdDood.posY + 0.5f, zRotation);
                        }
                    }
                }

                // Trees
                else
                {
                    if (isXAlign)
                    {
                        if (createdDood.posX > nodeDood.posX)
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.25f, createdDood.posY - 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.25f, createdDood.posY + 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.75f, createdDood.posY - 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.75f, createdDood.posY + 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.5f, createdDood.posY, zRotation);
                        }
                        else
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.25f, createdDood.posY - 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.25f, createdDood.posY + 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.75f, createdDood.posY - 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.75f, createdDood.posY + 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.5f, createdDood.posY, zRotation);
                        }
                    }
                    else
                    {
                        if (createdDood.posY > nodeDood.posY)
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.25f, createdDood.posY - 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.25f, createdDood.posY - 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX, createdDood.posY - 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.5f, createdDood.posY - 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.5f, createdDood.posY - 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.25f, createdDood.posY - 0.75f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.25f, createdDood.posY - 0.75f, zRotation);
                        }
                        else
                        {
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.25f, createdDood.posY + 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.25f, createdDood.posY + 0.25f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX, createdDood.posY + 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.5f, createdDood.posY + 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.5f, createdDood.posY + 0.5f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX - 0.25f, createdDood.posY + 0.75f, zRotation);
                            _createTailOnPos(createdDood.type, createdDood.posX + 0.25f, createdDood.posY + 0.75f, zRotation);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
 public void _addToDestroyList(O_ClassDoodad targetDood)
 {
     toDestroy.Add(targetDood.id);
 }