Example #1
0
 /// <summary>
 /// Borra el objeto que este seleccionado.
 /// </summary>
 /// <param name="Selected">Selected.</param>
 static void DeleteSelectedObject(GameObject Selected)
 {
     if (Selected.tag == "MainCamera")
     {
         return;
     }
     MapUI.DestroyImmediate(Selected, true);
 }
Example #2
0
    /// <summary>
    /// Borra los objeto seleccionados.
    /// </summary>
    static void DeleteObject()
    {
        GameObject MapObj = GameObject.Find("Map");

        foreach (GameObject i in Selection.gameObjects)
        {
            if (i == null)
            {
                continue;
            }
            if (i.name.Contains("Main Camera"))
            {
                var camera = i;
                GameObject.Instantiate(camera);
                continue;
            }

            SpriteRenderer si = i.GetComponent <SpriteRenderer>();
            if (si.sortingLayerName == Constant.LAYER_TILE)
            {
                GameObject temp = new GameObject();
                if ((i.transform.position.x + i.transform.position.y) % 2 == 0)
                {
                    temp = (GameObject)DarkFloor;
                }
                else
                {
                    temp = (GameObject)LightFloor;
                }
                Sprite aux = temp.GetComponent <SpriteRenderer>().sprite;
                temp.transform.position   = i.transform.position;
                temp.transform.localScale = new Vector3(ProjectSettings.pixelPerUnit / aux.rect.width, ProjectSettings.pixelPerUnit / aux.rect.height);
                var ins = MapUI.Instantiate(temp, temp.transform.position, Quaternion.identity) as GameObject;
                ins.transform.parent = MapObj.transform;
                MapUI.DestroyImmediate(GameObject.Find("New Game Object"), true);
            }
            MapUI.DestroyImmediate(i, true);
        }
    }
Example #3
0
    /// <summary>
    /// Pinta el objeto seleccionado en la scene.
    /// </summary>
    static void DropObject()
    {
        GameObject     temp         = RPGInspectorUI.ObjectBrowser;
        SpriteRenderer selectSprite = temp.GetComponent <SpriteRenderer>();

        foreach (GameObject i in Selection.gameObjects)
        {
            if (i == null)
            {
                continue;
            }
            SpriteRenderer iSprite = i.GetComponent <SpriteRenderer>();
            if (i.name == "Main Camera" || iSprite.sprite.name == selectSprite.sprite.name || i.name == "Map")
            {
                continue;
            }
            if (selectSprite.sortingLayerName == Constant.LAYER_TILE)
            {
                if (i.transform.parent.name == "Map" && i.tag != "RPG-PLAYER")
                {
                    temp.transform.position = i.transform.position;
                }
                else if (i.tag != "RPG-PLAYER")
                {
                    temp.transform.position = i.transform.parent.gameObject.transform.position;
                }
                temp.transform.localScale = new Vector3(ProjectSettings.pixelPerUnit / selectSprite.sprite.rect.width, ProjectSettings.pixelPerUnit / selectSprite.sprite.rect.height);
                GameObject son = MapUI.Instantiate(temp, temp.transform.position, Quaternion.identity) as GameObject;
                son.transform.parent = i.transform.parent;
                MapUI.DestroyImmediate(i, true);
            }
            else if (temp.tag == "RPG-PLAYER")
            {
                if (GameObject.Find("PLAYER(Clone)") != null)
                {
                    continue;
                }

                temp.name = "PLAYER";
                temp.transform.position   = i.transform.position;
                temp.transform.localScale = new Vector3(ProjectSettings.pixelPerUnit / selectSprite.sprite.rect.width, ProjectSettings.pixelPerUnit / selectSprite.sprite.rect.height);
                var son = MapUI.Instantiate(temp, temp.transform.position, Quaternion.identity) as GameObject;
            }
            else
            {
                GameObject aux = null;
                if (i.transform.parent.gameObject.transform.parent != null && i.transform.parent.childCount != 0)
                {
                    if (i.transform.parent.gameObject.transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().sprite.name == selectSprite.sprite.name)
                    {
                        continue;
                    }

                    aux = i.transform.parent.gameObject;
                    MapUI.DestroyImmediate(i.transform.parent.gameObject.transform.GetChild(0).gameObject);
                }
                else if (i.transform.parent.gameObject.transform.parent != null)
                {
                    aux = i.transform.parent.gameObject.transform.parent.gameObject;
                    MapUI.DestroyImmediate(i);
                }
                else
                {
                    aux = i;
                }
                var inst = MapUI.Instantiate(temp, new Vector3(0, 0), Quaternion.identity);
                temp = inst as GameObject;
                temp.transform.parent        = aux.transform;
                temp.transform.localPosition = new Vector3(0, 0);
                var sprite  = aux.GetComponent <SpriteRenderer>().sprite;
                var sprite2 = temp.GetComponent <SpriteRenderer>().sprite;
                temp.transform.localScale = new Vector3(sprite.rect.width / sprite2.rect.width, sprite.rect.height / sprite2.rect.height);
            }

            MapUI.DestroyImmediate(GameObject.Find("New Game Object"), true);
        }
        Selection.activeGameObject = null;
    }