Beispiel #1
0
        // Load Wall
        public static WallObject LoadWall(StreamReader reader, GameScreen screen)
        {
            WallObject wall = new WallObject();

            wall.screen = screen;

            BoxCollider col = new BoxCollider();

            string line;

            while ((line = GetLine(reader)) != "---")
            {
                switch (line)
                {
                case "X":
                    wall.Position.X = float.Parse(GetLine(reader));
                    break;

                case "Y":
                    wall.Position.Y = float.Parse(GetLine(reader));
                    break;

                case "Width":
                    col.Size.X = float.Parse(GetLine(reader));
                    break;

                case "Height":
                    col.Size.Y = float.Parse(GetLine(reader));
                    break;
                }
            }
            wall.GetComponent <HitBox>().Colliders.Add(col);
            return(wall);
        }
Beispiel #2
0
 public void SetWallObject(Vector2Int pos, WallObject newObject)
 {
     if (IsWallTile(pos))
     {
         Walls[ConvertPositionToWallCoord(pos)] = newObject;
     }
 }
    private IEnumerator ImoveWallsVerticallys() // TODO Set in WallObject.cs
    {
        yield return(new WaitForFixedUpdate());

        int multiplier = 1;

        if (_wallObjects.Count == 0)
        {
            yield break;
        }
        WallObject selectedWallObject = _wallObjects[0];
        float      baseY = Mathf.Infinity;

        foreach (WallObject wallObject in _wallObjects)
        {
            float yPosition = wallObject.GetComponentInChildren <Toggle>().transform.localPosition.y;
            if (yPosition < baseY)
            {
                baseY = yPosition;
            }
        }

        foreach (WallObject wallObject in _wallObjects)
        {
            Toggle selectedToggle = selectedWallObject.GetComponentInChildren <Toggle>();
            Toggle currentToggle  = wallObject.GetComponentInChildren <Toggle>();

            BoxCollider2D selectedCollider = selectedWallObject.GetComponent <BoxCollider2D>();
            BoxCollider2D currentCollider  = wallObject.GetComponent <BoxCollider2D>();
            bool          isTouching       = selectedCollider.IsTouching(currentCollider);

            float height = 20;
            if (isTouching)
            {
                if (_zoom >= WallSuperpositionAtZoomLevel || wallObject.name == selectedWallObject.name)
                {
                    if (multiplier < 4)
                    {
                        multiplier++;
                    }
                }
                else
                {
                    multiplier = 0;
                }

                if (currentToggle.transform.localPosition.y == baseY + height * multiplier)
                {
                    continue;
                }
                currentToggle.transform.localPosition = new Vector3(currentToggle.transform.localPosition.x, baseY + height * multiplier);
            }
            else
            {
                currentToggle.transform.localPosition = new Vector3(currentToggle.transform.localPosition.x, baseY);
                selectedWallObject = wallObject;
                multiplier         = 0;
            }
        }
    }
        private void btnCreateProject_Click(object sender, RoutedEventArgs e)
        {
            if (currentHousePlan != null)
            {
                if (currentHousePlan.GetWalls().Count == 0)
                {
                    HousePlanControl currentHousePlanControl = listViewHousePlans.SelectedItem as HousePlanControl;
                    if (currentHousePlanControl == null)
                    {
                        MessageBox.Show("Select a house plan!");
                        return;
                    }

                    currentHousePlan = currentHousePlanControl.GetCurrentHousePlan();
                }

                if (projectProperties.CheckEmptyFields() == true)
                {
                    MessageBox.Show("Complete mandatory fields!");
                    return;
                }

                if (projectProperties.CheckValidFields() == false)
                {
                    return;
                }

                List <Wall> walls = currentHousePlan.GetWalls();
                Project.UnitOfMeasurement measurementUnit = Project.UnitOfMeasurement.mm;
                float wallsHeight = Convert.ToSingle(projectProperties.textBoxWallsHeight.Text);

                if (projectProperties.comboBoxMeasurementUnits.Text == Project.UnitOfMeasurement.m.ToString())
                {
                    wallsHeight    *= 1000;
                    measurementUnit = Project.UnitOfMeasurement.m;
                }
                if (projectProperties.comboBoxMeasurementUnits.Text == Project.UnitOfMeasurement.cm.ToString())
                {
                    wallsHeight    *= 10;
                    measurementUnit = Project.UnitOfMeasurement.cm;
                }
                Client client = new Client(projectProperties.textBoxClientName.Text, Convert.ToInt64(projectProperties.textBoxTelephoneNumber.Text),
                                           projectProperties.textBoxEmailAddress.Text);
                Decimal budget = Convert.ToDecimal(projectProperties.textBoxBudget.Text);
                String  notes  = projectProperties.textBoxNotes.Text;
                Scene   scene  = new Scene();
                scene.MainCamera.Translate = new Point3d(0, 500, 0);
                scene.MainCamera.Rotate    = new Point3d(-90, 180, 0);
                for (int i = 0; i < walls.Count; i++)
                {
                    WallObject wall = new WallObject(walls[i], wallsHeight);
                    scene.AddWall(wall);
                }
                currentProject = new Project(client, scene, configuration, CurrencyHelper.GetProjectCurrency(), wallsHeight, budget,
                                             notes, measurementUnit);

                this.Close();
            }
        }
Beispiel #5
0
 public void SetWallIdVisible(Boolean isVisible)
 {
     foreach (GameObject g in GameObject.FindGameObjectsWithTag("Objects"))
     {
         WallObject wall = g.GetComponent <WallObject>();
         wall.SetIdVisible(isVisible);
     }
 }
 public void OnWallObjectClicked(WallObject wallObject)
 {
     addWallObjectToSelectedList(wallObject, true);
     // _objectsLibraryManager.HideWallEdition(false);
     _objectsLibraryManager.SetPanel(0);
     _objectsLibraryManager.UpdateUIWallTime(wallObject.Time);
     _objectsLibraryManager.SelectWallTab(WallsUtils.GetWallType(wallObject.WallObjectId), wallObject.WallObjectId);
 }
Beispiel #7
0
    public WallObject CreateWallAt(Vector2Int pos, Type type)
    {
        //find model
        TileSet.Piece piece;
        if (!type.IsSubclassOf(typeof(WallObject)))
        {
            return(null);
        }

        if (tileSet != null)
        {
            piece = tileSet.FindPieceFromType(type);
        }
        else
        {
            return(null);
        }

        if (piece == null)
        {
            Debug.LogError("Tileset does not contain type \"" + type.ToString() + '"');
            return(null);
        }

        //instantiate model
        GameObject newWallObject = UnityEditor.PrefabUtility.InstantiatePrefab(piece.Tile) as GameObject;

        //configure gameobject
        newWallObject.name = "Wall (" + pos.x + "," + pos.y + ")";
        newWallObject.transform.SetParent(transform);

        //configure wallobject
        WallObject wallObject = newWallObject.GetComponent <WallObject>();

        if (!wallObject)
        {
            DestroyImmediate(newWallObject);
            Debug.LogError("Wall object prefab does not contain a wall object script");
            return(null);
        }

        if (piece.Tile == null)
        {
            Debug.LogError("Tileset does not contain type \"" + type.ToString() + '"');
            return(null);
        }

        wallObject.TileSetPiece = piece;

        //orient gameObject
        Direction wallDirection = GetWallOrientation(pos);

        newWallObject.transform.position = new Vector3(pos.x, 0, pos.y);
        newWallObject.transform.rotation = Quaternion.Euler(0, (-90 * (int)piece.modelOrientation) + 90 * (int)wallDirection, 0);

        return(wallObject);
    }
Beispiel #8
0
    public void ReturnWallT(WallObject wall)
    {
        wall.SetTilePos(new Vec2Int(-1, -1));
        wall.SetMaterial(PrefabAssets.Singleton.wallHologramMat);
        wall.gameObject.transform.parent = this.transform;
        wall.gameObject.SetActive(false);

        m_wallTCache.ReturnObject(wall);
    }
    public IEnumerator Paste(bool flipped = false)
    {
        float initTime = Mathf.Infinity;

        clearListOfSelectedObject();
        List <WallObject> wallObjectsToCreate = new List <WallObject>();

        foreach (WallObject wallObject in _clipboard)
        {
            if (wallObject.Time < initTime)
            {
                initTime = wallObject.Time;
            }
        }

        bool pasteWithoutProblems = canPasteWithoutProblems(initTime);

        if (!pasteWithoutProblems)
        {
            DialogsWindowsManager.Instance.ShowWindow(DialogsWindowsManager.Window.ConfirmPaste);

            while (!FinishPasteDialog)
            {
                yield return(null);
            }

            FinishPasteDialog = false;

            if (!ConfirmPaste)
            {
                yield break;
            }
        }

        foreach (WallObject wallObject in _clipboard)
        {
            float time = _cursorTime + wallObject.Time - initTime;
            if (!pasteWithoutProblems && time > ClipInfo.ClipTimeSize)
            {
                continue;
            }

            // time = time > ClipInfo.ClipTimeSize ? ClipInfo.ClipTimeSize : time;

            string newWallObjectID = flipped == true?WallsUtils.FlipWallObject(wallObject.WallObjectId) : wallObject.WallObjectId;

            WallObject currentWallObject = _songManager.CreateWallObject(newWallObjectID, time, true, this);
            addWallObjectToSelectedList(currentWallObject);
            currentWallObject.GetComponent <Transform>().Find("MarkLine").gameObject.SetActive(_zoom >= WallMarklineVisibleAtZoomLevel);
            currentWallObject.GetComponent <Transform>().Find("Toggle/Wall Id").gameObject.SetActive(_zoom >= WallIdVisibleAtZoomLevel);
        }


        yield break;
    }
        public static void Test()
        {
            List <IMapObject> listOfObjects = new List <IMapObject>();

            MapObject    mapObject    = new MapObject();
            WallObject   wallObject   = new WallObject();
            GroundObject groundObject = new GroundObject();

            listOfObjects.Add(mapObject);
            listOfObjects.Add(wallObject);
        }
Beispiel #11
0
    private void updateWallTime(WallObject wallObject, float time)
    {
        if (wallObject == null)
        {
            return;
        }

        wallObject.ChangeTime(time);
        // _objectsLibraryManager.UpdateUIWallTime(time);
        moveWallsVerticallyInTheNextFrame();
    }
Beispiel #12
0
    private void sortWallObjectListAndSibling()
    {
        _wallObjects.Sort(WallObject.sortWallByName());

        for (int i = 0; i < _wallObjects.Count; i++)
        {
            if (_wallObjects[i].transform.GetSiblingIndex() != i)
            {
                _wallObjects[i].transform.SetSiblingIndex(i);
            }
        }
    }
Beispiel #13
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (_editor.AudioManager.IsPlaying())
     {
         if (other.gameObject.tag != "WallToggle")
         {
             return;
         }
         WallObject wallObject = other.gameObject.GetComponentInParent <WallObject>();
         _editor.OnWallObjectClicked(wallObject);
     }
 }
Beispiel #14
0
 public RuneObject(int x, int y, int z, int type, object mainClass, int bX, int bY, int id, GameObject objects, GameObject animatedObjects)
 {
     localX = x / 128f;
     height = y / 128f;
     localY = z / 128f;
     if (mainClass is InteractiveObject)
     {
         if ((mainClass as InteractiveObject).renderable is Projectile)
         {
             isGfx = true;
         }
     }
     shouldMove = true;
     objectType = type;
     if (type == 1)
     {
         wallObj = (WallObject)mainClass;
     }
     if (type == 2)
     {
         obj2 = (WallDecoration)mainClass;
     }
     if (type == 3)
     {
         obj3 = (GroundDecoration)mainClass;
     }
     if (type == 4)
     {
         obj4 = (Object4)mainClass;
     }
     if (type == 5)
     {
         obj5 = (InteractiveObject)mainClass;
     }
     baseX   = bX;
     baseY   = bY;
     modelId = id;
     if (id > 0)
     {
         def = ObjectDef.forID(id);
         if (def != null)
         {
             if (def.animId != -1)
             {
                 isAnimated = true;
             }
         }
     }
     myRuneMesh               = new RuneMesh();
     this.objectRoot          = objects;
     this.animatedObjectsRoot = animatedObjects;
 }
Beispiel #15
0
        private void addElectricalOutletSymbol(WallObject electricalOutlet)
        {
            Circle circle1 = new Circle(
                new Vertex(-1224.53188886458f, -322.498404426762f, 1122.06118324471f),
                new Vertex(-1223.86485851964f, -291.602438283998f, 1138.49268794222f),
                new Vertex(-1223.25055842396f, -263.148867765258f, 1122.06118324471f));

            Circle circle2 = new Circle(
                new Vertex(-1222.20027814054f, -214.501269760972f, 1098.64295046295f),
                new Vertex(-1221.32098761231f, -173.773691779122f, 1137.98228035197f),
                new Vertex(-1220.69855328763f, -144.943354497504f, 1105.95548557759f));

            electricalOutlet.AddSymbol(circle1, sceneControl1.OpenGL);
            electricalOutlet.AddSymbol(circle2, sceneControl1.OpenGL);
        }
Beispiel #16
0
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("trigger");
        if (other.tag == "InstaKill")
        {
            Debug.Log("Rip in kill");
            GameManager.Die(score); // freeze frame w/ instant replay
        }

        WallObject isWallObj = other.GetComponent <WallObject>();

        if (null != isWallObj)
        {
            isWallObj.ApplyToPlayer(this);
        }
    }
Beispiel #17
0
    private void removeWallObjectFromSelectedList(WallObject wallObject)
    {
        _selectedWallObjects.Remove(wallObject);

        // if (_selectedWallObjects.Count == 0) _objectsLibraryManager.HideWallEdition(true);
        if (_selectedWallObjects.Count == 0)
        {
            _objectsLibraryManager.SetPanel(1);
        }
        if (_selectedWallObjects.Count == 1)
        {
            _objectsLibraryManager.SetPanel(0);
        }

        wallObject.GetComponentInChildren <Toggle>().isOn = false;
    }
Beispiel #18
0
    public void OnAddWallObject(float time)
    {
        if (ClipInfo.ClipTimeSize == 0)
        {
            return;
        }

        string wallObjectId = _currentWallObject != null ? _currentWallObject.WallObjectId : "WP.C33CUC";

        _currentWallObject = _songManager.CreateWallObject(wallObjectId, time, true, this);
        _currentWallObject.GetComponent <Transform>().Find("MarkLine").gameObject.SetActive(_zoom >= WallMarklineVisibleAtZoomLevel);
        _currentWallObject.GetComponent <Transform>().Find("Toggle/Wall Id").gameObject.SetActive(_zoom >= WallIdVisibleAtZoomLevel);

        // _objectsLibraryManager.UpdateWallObjectSprite(_currentWallObject.WallObjectId);
        addWallObjectToSelectedList(_currentWallObject);
        OnWallObjectClicked(_currentWallObject);
    }
Beispiel #19
0
    public void ReloadTiles()
    {
        for (int i = -1; i <= Width; i++)
        {
            for (int j = -1; j <= Height; j++)
            {
                Vector2Int pos = new Vector2Int(i, j);
                if (IsCornerTile(pos))
                {
                    int index = ConvertPositionToCornerCoord(pos);
                    if (Corners[index] != null)
                    {
                        DestroyImmediate(Corners[index]);
                    }
                    Corners[index] = CreateCornerAt(pos);
                }
                else if (IsWallTile(pos))
                {
                    int        index   = ConvertPositionToWallCoord(pos);
                    WallObject oldWall = Walls[index];
                    if (Walls[index] != null)
                    {
                        Walls[index] = CreateWallAtFrom(pos, oldWall);
                        DestroyImmediate(oldWall.gameObject);
                    }
                    else
                    {
                        Walls[index] = CreateWallAt(pos);
                    }
                }
                else if (IsWithinBoard(pos))
                {
                    int         index  = ConvertPositionToBoardCoord(pos);
                    BoardObject oldObj = Tiles[index];
                    if (oldObj != null)
                    {
                        Tiles[index] = CreateBoardObjectAtFrom(pos, Tiles[index]);
                        DestroyImmediate(oldObj.gameObject);
                    }
                }
            }
        }

        RemoveExtraObjects();
    }
Beispiel #20
0
    private void BoardSetup(int level)
    {
        Destroy(GameObject.Find("Board"));
        SetBoardSize(level);

        boardHolder = new GameObject("Board").transform;
        int levelType = Random.Range(0, 2);

        for (int x = -1; x < columns + 1; x++)
        {
            for (int y = -1; y < rows + 1; y++)
            {
                WallObject wallTilesByLevel = wallTiles[levelType];
                GameObject toInstantiate    = wallTilesByLevel.floorTile;

                if (x == -1 || x == columns || y == -1 || y == rows)
                {
                    GameObject[] wall = wallTilesByLevel.wallTiles;
                    toInstantiate = wall[Random.Range(0, wall.Length)];
                }

                if (y == rows)
                {
                    if (x == columns - 3)
                    {
                        toInstantiate = leftGateTile;
                    }
                    if (x == columns - 2)
                    {
                        toInstantiate = centerGateTile;
                    }
                    if (x == columns - 1)
                    {
                        toInstantiate = rightGateTile;
                    }
                }

                GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0f), Quaternion.identity);
                instance.transform.SetParent(boardHolder);
            }
        }

        CreateTracksTiles();
        CreateCarTiles();
    }
Beispiel #21
0
    public WallObject CreateWallObject(string objName, float time, bool isOn, OhShapeEditor editor)
    {
        time = Mathf.Round(time * 100);
        time = time * 0.01f;

        //Create SongObject basic.
        GameObject go = Instantiate(WallPrefab);

        go.name = string.Format("{0:0000.00}", time);
        go.SetActive(true);
        go.transform.SetParent(wallsParent);

        WallObject wall = go.GetComponent <WallObject>();

        wall.Init(objName, time, isOn, editor);
        editor.addWallObjectToListOfObjects(wall);

        return(wall);
    }
        //public IMapObject[,] level1 = new IMapObject[28,112];


        public static IMapObject[,] LoadMapWithObjects(Level level)
        {
            IMapObject[,] objectRenderedMap = new IMapObject[28, 112];

            for (int y = 0; y < level.LevelAsCharArray.GetLength(1); y++)
            {
                for (int x = 0; x < level.LevelAsCharArray.GetLength(0); x++)
                {
                    PositionOnMap currentPosition = new PositionOnMap {
                        X = x, Y = y
                    };
                    char symbol = level.LevelAsCharArray[x, y];

                    switch (symbol)
                    {
                    case '|':
                        objectRenderedMap[x, y] = new WallObject(symbol, currentPosition);
                        break;

                    case '@':
                        objectRenderedMap[x, y] = new PlayerObject(symbol, currentPosition);
                        break;

                    case 'T':
                        objectRenderedMap[x, y] = new GroundObject(symbol, currentPosition);
                        break;

                    case ' ':
                        objectRenderedMap[x, y] = new MapObject(symbol, currentPosition);
                        break;

                    case '_':
                        objectRenderedMap[x, y] = new RoofObject(symbol, currentPosition);
                        break;

                    default:
                        break;
                    }
                }
            }
            return(objectRenderedMap);
        }
Beispiel #23
0
    private void ReplaceWall(Vector2Int pos, Type type)
    {
        WallObject obj    = level.board.GetWallObject(pos);
        WallObject newObj = null;

        if (type != null)
        {
            newObj = level.board.CreateWallAt(pos, type);
        }
        if (obj && (newObj != null || type == null))
        {
            DestroyImmediate(obj.gameObject);
        }
        if (type != null && newObj == null)
        {
            return;
        }
        level.board.SetWallObject(pos, newObj);
        SetSceneDirty();
    }
Beispiel #24
0
    /*public void OnDeleteWallObjectDialog()
     * {
     *  DialogsWindowsManager.Instance.ShowWindow(DialogsWindowsManager.Window.DeleteObject);
     * }
     */

    public void OnDeleteWallObject()
    {
        /*
         * _wallObjects.Remove(_currentWallObject);
         * removeWallObjectFromSelectedList(_currentWallObject);
         * _currentWallObject = null; // TODO I don't know if this is valid
         * Destroy(_currentWallObject.gameObject);
         * // Destroy(_objectsLibraryManager.gameObject);
         */

        foreach (WallObject wallObject in _selectedWallObjects)
        {
            _wallObjects.Remove(wallObject);
            Destroy(wallObject.gameObject);
        }
        _selectedWallObjects.Clear(); // Set outside of the iteration because it will throw an error
        _objectsLibraryManager.SetPanel(1);
        _currentWallObject = null;    // TODO I don't know if this is valid
        moveWallsVerticallyInTheNextFrame();
    }
Beispiel #25
0
    public void Paste()
    {
        // TODO what happens if time + songTime?
        // TODO set as not active
        float initTime = Mathf.Infinity;

        clearListOfSelectedObject();
        foreach (WallObject wallObject in _clipboard)
        {
            if (wallObject.Time < initTime)
            {
                initTime = wallObject.Time;
            }
        }
        foreach (WallObject wallObject in _clipboard)
        {
            float time = _cursorTime + wallObject.Time - initTime;
            time = time > ClipInfo.ClipTimeSize ? ClipInfo.ClipTimeSize : time;
            WallObject currentWallObject = _songManager.CreateWallObject(wallObject.WallObjectId, time, true, this);
            addWallObjectToSelectedList(currentWallObject);
            currentWallObject.GetComponent <Transform>().Find("MarkLine").gameObject.SetActive(_zoom >= WallMarklineVisibleAtZoomLevel);
            currentWallObject.GetComponent <Transform>().Find("Toggle/Wall Id").gameObject.SetActive(_zoom >= WallIdVisibleAtZoomLevel);
        }
    }
Beispiel #26
0
    private void addWallObjectToSelectedList(WallObject wallObject, bool clear = false)
    {
        if (clear)
        {
            clearListOfSelectedObject();
        }
        if (_selectedWallObjects.IndexOf(wallObject) >= 0)
        {
            return;                                                // Works like a Set. Not duplicate elements
        }
        _selectedWallObjects.Add(wallObject);
        if (_selectedWallObjects.Count == 1)
        {
            _currentWallObject = wallObject; // Change above of the if?
            // _objectsLibraryManager.HideWallEdition(false);
            _objectsLibraryManager.SetPanel(0);
        }
        if (_selectedWallObjects.Count > 1)
        {
            _objectsLibraryManager.SetPanel(2);
        }

        wallObject.GetComponentInChildren <Toggle>().isOn = true;
    }
Beispiel #27
0
    void OnCollisionStay2D(Collision2D coll)
    {
        OnCollisionStayCounter += 1;
        UpInTheAir_Counter      = 0;

        //This is making sure that when Ninja is colliding with something it is always registered.
        if (IsGrounded == false && WallTouch == false)
        {
            FixStateTimer += 1;
            if (FixStateTimer > 4)
            {
                foreach (ContactPoint2D contact in coll.contacts)
                {
                    if (0.1f > contact.normal.y && ((contact.normal.x * contact.normal.x) < (0.85f * 0.85f)))
                    {
                        JumpForceCount = 0f;
                    }
                    else if (contact.normal.x >= Ground_X_MIN && contact.normal.x <= Ground_X_MAX && contact.normal.y >= Ground_Y_MIN && contact.normal.y <= Ground_Y_MAX)
                    {
                        FixStateTimer = 0;
                        DJ_available  = false;
                        GroundedToObjectsList.Add(contact.collider.gameObject);
                        IsGrounded = true;
                    }
                    else
                    {
                        if (this.GetComponent <Rigidbody2D>().velocity.y < 0f)
                        {
                            FixStateTimer = 0;
                            DJ_available  = false;
                            WalledToObjectsList.Add(contact.collider.gameObject);
                            WallTouch = true;

                            this.transform.parent = null;
                            NinjaPlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                            NinjaPlatformRoot.RootedTo           = contact.collider.gameObject;
                            this.transform.parent = NinjaPlatformRoot.transform;

                            if (contact.normal.x > 0)
                            {
                                PlayerLooksRight = true;
                                MySpriteOBJ.transform.localScale = MySpriteOriginalScale;
                            }
                            else
                            {
                                PlayerLooksRight = false;
                                MySpriteOBJ.transform.localScale = new Vector3(-MySpriteOriginalScale.x, MySpriteOriginalScale.y, MySpriteOriginalScale.z);
                            }

                            //Start emiting smoke particles when touching the wall
                            WallGripParticles.emissionRate = WallGripEmissionRate;
                        }
                    }
                }
            }
        }


        //OnStay Ground Events:
        else if (IsGrounded == true)
        {
            Vector2 NinjaStandDirection = Vector2.zero;
            foreach (ContactPoint2D contact in coll.contacts)
            {
                int CountHappenings = 0;
                foreach (GameObject GroundedObject in GroundedToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == GroundedObject.GetInstanceID())
                    {
                        NinjaStandDirection += contact.normal;
                        CountHappenings     += 1;
                    }
                }
                if (CountHappenings > 0)
                {
                    NinjaStandDirection = NinjaStandDirection / CountHappenings;
                    //This makes sure that Ninja doesn't walk on the walls.
                    if ((NinjaStandDirection.x > Ground_X_MAX || NinjaStandDirection.x < Ground_X_MIN) && (NinjaStandDirection.y > Ground_Y_MAX || NinjaStandDirection.y < Ground_Y_MIN))
                    {
                        this.GetComponent <Rigidbody2D>().AddForce(NinjaStandDirection * 100f);
                    }
                    else
                    {
                        //this Rotates the Ninja to allign with platform.
                        Vector2 RealDirectionV2 = new Vector2(this.transform.up.x, this.transform.up.y);
                        float   TorqueTo        = Vector2.Angle(NinjaStandDirection, RealDirectionV2);
                        if (NinjaStandDirection.normalized.x > RealDirectionV2.normalized.x)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        if (-NinjaStandDirection.normalized.y > RealDirectionV2.normalized.y)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        this.GetComponent <Rigidbody2D>().AddTorque(TorqueTo * 1000f * Time.deltaTime);

                        this.GetComponent <Rigidbody2D>().AddForce(NinjaStandDirection * (-300f));
                    }
                }
            }


            //OnStay Wall Events:
        }
        else if (WallTouch == true)
        {
            foreach (ContactPoint2D contact in coll.contacts)
            {
                Vector2 NinjaWallDirection = Vector2.zero;
                int     CountHappenings    = 0;
                foreach (GameObject WallObject in WalledToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == WallObject.GetInstanceID())
                    {
                        NinjaWallDirection += contact.normal;
                        CountHappenings    += 1;
                    }
                }

                if (CountHappenings > 0)
                {
                    NinjaWallDirection = NinjaWallDirection / CountHappenings;
                    if ((NinjaWallDirection.x > Ground_X_MAX || NinjaWallDirection.x < Ground_X_MIN) && (NinjaWallDirection.y > Ground_Y_MAX || NinjaWallDirection.y < Ground_Y_MIN))
                    {
                        if ((Btn_Left_bool == false && PlayerLooksRight == false) || (Btn_Right_bool == false && PlayerLooksRight == true))
                        {
                            this.GetComponent <Rigidbody2D>().AddForce(NinjaWallDirection * -100f);
                        }
                        //this Rotates the Ninja to allign with the wall.
                        Vector2 RealDirectionV2 = new Vector2(this.transform.up.x, this.transform.up.y);

                        if (PlayerLooksRight == false)
                        {
                            RealDirectionV2 = RotateThisVector(RealDirectionV2, 1.35f);
                        }
                        else
                        {
                            RealDirectionV2 = RotateThisVector(RealDirectionV2, -1.35f);
                        }

                        float TorqueTo = Vector2.Angle(NinjaWallDirection, RealDirectionV2);
                        if (contact.normal.x > RealDirectionV2.normalized.x)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        if (-contact.normal.y > RealDirectionV2.normalized.y)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        this.GetComponent <Rigidbody2D>().AddTorque(TorqueTo * 450f * Time.deltaTime);
                    }
                    else
                    {
                        if ((Btn_Left_bool == false && PlayerLooksRight == false) || (Btn_Right_bool == false && PlayerLooksRight == true))
                        {
                            this.GetComponent <Rigidbody2D>().AddForce(NinjaWallDirection * 100f);
                        }
                    }
                }
            }
        }
    }
Beispiel #28
0
    public static void RefreshObjects()
    {
        foreach (Character character in Location.characters)
        {
            if (DisplayedEntities.Contains(character))
            {
                continue;
            }

            CharacterObject characterObject = Object.Instantiate(PrefabManager.characterObjectPrefab, character.WorldPosition, Quaternion.identity);
            characterObject.SetCharacter(character);
            if (character.isPlayer)
            {
                playerCharacterObject = characterObject;
            }
            DisplayedEntities.Add(character);
        }

        foreach (Item item in Location.items)
        {
            if (DisplayedEntities.Contains(item))
            {
                continue;
            }

            if (item.container == null)
            {
                ItemObject itemObject = Object.Instantiate(PrefabManager.itemObjectPrefab, item.WorldPosition, Quaternion.identity);
                itemObject.item = item;
                DisplayedEntities.Add(item);
            }
        }

        foreach (Wall wall in Location.walls.Values)
        {
            if (DisplayedEntities.Contains(wall))
            {
                continue;
            }

            Doorway doorway = wall as Doorway;
            if (doorway != null)
            {
                DoorwayObject doorwayObject = Object.Instantiate(PrefabManager.doorObjectPrefab, doorway.WorldPosition, Quaternion.identity, TerrainParent);
                doorwayObject.doorway = doorway;
                doorwayObject.GetComponentInChildren <DoorObject>().door = doorway.door;
                doorwayObject.transform.up = doorway.direction;
            }
            else
            {
                WallObject wallObject = Object.Instantiate(PrefabManager.GetWallObject(wall.wallType), wall.WorldPosition, Quaternion.identity, TerrainParent);
                wallObject.Wall         = wall;
                wallObject.transform.up = wall.direction;
            }

            DisplayedEntities.Add(wall);
        }

        foreach (EntityObject entityObject in EntityObjects)
        {
            if (entityObject != null)
            {
                entityObject.UpdateDisplay();
            }
        }
    }
Beispiel #29
0
 public void addWallObjectToListOfObjects(WallObject wallObject)
 {
     _wallObjects.Add(wallObject);
     sortWallObjectListAndSibling();
     moveWallsVerticallyInTheNextFrame();
 }
Beispiel #30
0
    public void OnWallObjectDrag(WallObject wallObject)
    {
        // if (!Input.GetMouseButton(0)) return; // if Mouse button is not right
        if (Input.GetMouseButton(0))
        {
            if (_selectedWallObjects.IndexOf(wallObject) < 0)
            {
                OnWallObjectClicked(wallObject);
            }
            Vector2 worldPosition;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponentInParent <RectTransform>(), Input.mousePosition, GetComponentInParent <Canvas>().worldCamera, out worldPosition);

            float draggedWallTime = PixelToSec(Input.mousePosition.x / _mainCanvas.scaleFactor);

            if (Mathf.Abs(_cursorTime - draggedWallTime) < 2f / _zoom)
            {
                draggedWallTime = _cursorTime;
            }
            else
            {
                if (_timeGridManager.Snap)
                {
                    foreach (RectTransform gridLine in _timeGridManager.GridLines)
                    {
                        if (Mathf.Abs(float.Parse(gridLine.name) - draggedWallTime) < 2f / _zoom)
                        {
                            draggedWallTime = float.Parse(gridLine.name);
                            break;
                        }
                    }
                }
            }

            float diffTime = draggedWallTime - wallObject.Time;

            foreach (WallObject selectedWallObject in _selectedWallObjects)
            {
                float wallTime = selectedWallObject.Time + diffTime;
                if (wallTime >= ClipInfo.ClipTimeSize - 0.01f)
                {
                    wallTime = ClipInfo.ClipTimeSize - 0.01f;
                }
                if (wallTime < 0)
                {
                    wallTime = 0f;
                }

                updateWallTime(selectedWallObject, wallTime);
            }
        }

        /*OnWallObjectClicked(wallObject);
         * Vector2 worldPosition;
         * RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponentInParent<RectTransform>(), Input.mousePosition, GetComponentInParent<Canvas>().worldCamera, out worldPosition);
         *
         * float wallTime = PixelToSec(Input.mousePosition.x / _mainCanvas.scaleFactor);
         *
         * if (Mathf.Abs(_cursorTime - wallTime) < 2f / _zoom)
         * {
         *  wallTime = _cursorTime;
         * }
         * updateWallTime(wallTime);*/
    }