コード例 #1
0
    protected override void OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
    {
        Fixture other = (fixtureA.Body == b2Body) ? fixtureB : fixtureA;

        //UnityEngine.Debug.Log("伤害体碰撞 On");
        MapCollider collider = other.Body.UserData as MapCollider;

        if (collider != null)
        {
            //UnityEngine.Debug.Log("  OnCollision  collider  ");
            // 如果是Destroy类型的则应该设置速度为0,并发送回调(立即销毁/延迟销毁)
            // 如果是Bound类型的则应该根据速度,反弹,发送回调(原方向/法线对称)
            // 如果是Cross类型则应该已经在OnBeforeCollision中处理了
            if (false == collider.m_isSensor)
            {
                damageBody.OnColliderCollision(collider.m_strHandle);
            }
            // 场景物体受击 TODO
        }

        // 能执行到OnCollision说明角色可受击
        MapRole role = other.Body.UserData as MapRole;

        if (role != null)
        {
            //UnityEngine.Debug.Log("  OnCollision  MapRole  ");
            damageBody.AddDamageRole(role.m_strHandle);
        }

        //base.OnCollision(fixtureA, fixtureB, contact);
    }
コード例 #2
0
        public virtual void Start()
        {
            hitBox.localPosition = new Vector3(0, 0, 0);

            StartCoroutine("animateSprite");

            //Check current map
            RaycastHit[] hitRays = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down);
            int          closestIndex;
            float        closestDistance;

            CheckHitRaycastDistance(hitRays, out closestIndex, out closestDistance);

            if (closestIndex >= 0)
            {
                currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
            }
            else
            {
                //if no map found
                //Check for map in front of character's direction
                hitRays = Physics.RaycastAll(transform.position + Vector3.up + getForwardVectorRaw(), Vector3.down);

                CheckHitRaycastDistance(hitRays, out closestIndex, out closestDistance);

                if (closestIndex >= 0)
                {
                    currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
                }
            }
        }
コード例 #3
0
    protected override void OnSeparation(Fixture fixtureA, Fixture fixtureB, Contact contact)
    {
        if (null == b2Body)
        {
            return;
        }
        Fixture other = (fixtureA.Body == b2Body) ? fixtureB : fixtureA;

        //UnityEngine.Debug.Log("伤害体碰撞 Separation");
        MapCollider collider = other.Body.UserData as MapCollider;

        if (collider != null)
        {
            //UnityEngine.Debug.Log("  OnSeparation  collider  ");
        }
        // 分离受击
        MapRole role = other.Body.UserData as MapRole;

        if (role != null)
        {
            //UnityEngine.Debug.Log("  OnSeparation  MapRole  ");
            damageBody.RemoveDamageRole(role.m_strHandle);
        }

        //base.OnSeparation(fixtureA, fixtureB, contact);
    }
コード例 #4
0
        public override void Update()
        {
            Position     += velocity;
            traveledDist += velocity.Length();

            //List<GameObject> objects = new List<GameObject>();
            //foreach (Enemy e in Game1.enemies) objects.Add((GameObject)e);

            foreach (GameObject g in SceneManager.gameScene.objects)
            {
                if (g.ObstructsBullets)
                {
                    if (MapCollider.Intersects(g.BulletCollider))
                    {
                        g.Health -= Properties.Damage * (traveledDist / Properties.MaxRange);
                        this.Dead = true;
                    }
                }
            }
            foreach (Tile t in CloseSolidTiles)
            {
                if (t.Properties.ObstructsBullets)
                {
                    if (MapCollider.Intersects(t.Hitbox))
                    {
                        this.Dead = true;
                    }
                }
            }
            if (!Camera.AreaIsVisible(MapCollider))
            {
                Dead = true;
            }
        }
コード例 #5
0
    public void CheckMapCollision()
    {
        foreach (MapCollider mapCol in MapManager.instance.mapColliders)
        {
            mapCol.tilemapObject.SetActive(false);
        }
        MapManager.instance.mapColliders.Clear();
        RaycastHit2D[] hitColliders;
        for (int i = 0; i < 5; i++)
        {
            Vector2 dir     = i == 0 ? Vector2.up : i == 1 ? Vector2.down : i == 2 ? Vector2.left : i == 3 ? Vector2.right : Vector2.zero;
            float   rayDist = dir.y != 0 ? 5 : 6;

            // Debug.DrawLine(transform.position, transform.position + (Vector3)(dir * rayDist),Color.red,6f);
            hitColliders = Physics2D.BoxCastAll((Vector2)transform.position + new Vector2(0.5f, 0), new Vector2(11, 9), 0, Vector2.zero);
            foreach (RaycastHit2D ray in hitColliders)
            {
                if (ray.collider.tag == "MapCollider")
                {
                    MapCollider mapCollider = ray.collider.GetComponent <MapCollider>();
                    if (!MapManager.instance.mapColliders.Contains(mapCollider))
                    {
                        MapManager.instance.mapColliders.Add(mapCollider);
                        mapCollider.tilemapObject.SetActive(true);
                    }
                }
            }
        }
    }
コード例 #6
0
    /// <summary>
    /// 创建单个Collider,Collider不会移动,一定会发生碰撞,如果不发生碰撞则创建特殊的碰撞体
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public MapCollider CreateCollider(ColliderDataNode data)
    {
        if (data == null)
        {
            return(null);
        }
        MapCollider col = new MapCollider();

        col.InitData(data);
        col.m_strHandle = data.name; // GetColliderStrHandle(data.name);
        if (data.bodyCreateType == (int)eBodyCreateType.Rectangle)
        {
            col.InitB2Rectangle(this, data.sizeX, data.sizeY, 0.0f, data.position, 0, (BodyType)data.bodyType, 0, data.isActive);
        }
        else if (data.bodyCreateType == (int)eBodyCreateType.Circle)
        {
            col.InitB2Circle(this, data.radius, 0.0f, data.position, (BodyType)data.bodyType, 0, data.isActive);
        }
        else if (data.bodyCreateType == (int)eBodyCreateType.Polygon)
        {
            col.InitB2Polygon(this, data.vertices, 0.0f, data.position, 0, (BodyType)data.bodyType, 0, data.isActive);
        }
        else if (data.bodyCreateType == (int)eBodyCreateType.Edge)
        {
            col.InitB2Edge(this, data.startPos, data.endPos, 0, data.isActive);
        }
        col.m_isSensor = data.isSensor;

        return(col);
    }
コード例 #7
0
        public override void OnCreate()
        {
            base.OnCreate();

            entity.AddTag("Map");

            cells = new Array2D <int>(128, 128);

            mapCollider = entity.AddComponent <MapCollider>();
            mapCollider.cell2CollisionValue              = new int[Cell.COUNT];
            mapCollider.cell2CollisionValue[Cell.VOID]   = 1;
            mapCollider.cell2CollisionValue[Cell.GROUND] = 0;
            mapCollider.cell2CollisionValue[Cell.WALL]   = 1;
            mapCollider.cell2CollisionValue[Cell.TRUNK]  = 1;

            mapRenderer = entity.AddComponent <MapRenderer>();
            mapRenderer
            .SetTexture("terrain", RenderMode.BASE)
            .SetTexture("terrain_light_filter", RenderMode.LIGHT_FILTER)
            .SetTexture("black", RenderMode.LIGHT_MAP)
            .SetLayer(ViewLayers.TERRAIN);

            Tiler tiler = mapRenderer.tiler;

            tiler.AddPattern(new TilerPattern(Cell.GROUND, 0));
            tiler.AddPattern(new TilerPattern(Cell.WALL, 1));
            tiler.AddPattern(new TilerPattern(Cell.TRUNK, 2));
        }
コード例 #8
0
    public virtual bool Init(MapDataNode mapData)
    {
        if (mapData == null)
        {
            return(false);
        }

        this.mapData = mapData;

        b2World = new World(new Vector2(0f, 0f)); // 2.5D 不需要重力

        b2World.JointRemoved                += OnB2JointRemoved;
        b2World.ContactManager.PreSolve     += OnB2PreSolve;
        b2World.ContactManager.PostSolve    += OnB2PostSolve;
        b2World.ContactManager.BeginContact += OnB2BeginContact;
        b2World.ContactManager.EndContact   += OnB2EndContact;

        baseCollision = new MapCollider();
        baseCollision.InitB2Body(this, 0, 0, 1, 1);
        MapFunctions.SetCollisionGroup(baseCollision.m_body, 0, VelcroPhysics.Collision.Filtering.Category.None, VelcroPhysics.Collision.Filtering.Category.None); // 不与任何碰撞

        colliderDic.Clear();
        speColliderDic.Clear();

        return(true);
    }
コード例 #9
0
ファイル: MapRole.cs プロジェクト: kylinzlkz/RPGTest
    protected override bool OnBeforeCollision(Fixture fixtureA, Fixture fixtureB)
    {
        if (null == b2Body)
        {
            return(false);
        }
        if (!m_isActive)
        {
            return(false);
        }
        Fixture other = (fixtureA.Body == b2Body) ? fixtureB : fixtureA;
        MapObj  obj   = other.Body.UserData as MapObj;

        if (obj == null)
        {
            return(false);
        }

        //UnityEngine.Debug.Log("人物碰撞 Before");
        MapCollider collider = other.Body.UserData as MapCollider;

        // 是单向通过
        if (collider != null && collider.isOneWay)
        {
            float vDot = Vector2.Dot(m_linearVelocity, collider.oneWayDir);
            if (vDot > 0.5f)
            {
                return(false); // 移动方向和可通行方向相同 可通过
            }
        }

        return(true);
    }
コード例 #10
0
 public override void Update()
 {
     if (MapCollider.Intersects(SceneManager.gameScene.player.MapCollider))
     {
         if (Sprite.Alpha == 1)
         {
             SoundManager.door.Play();
         }
         if (Sprite.Alpha > .4f)
         {
             Sprite.Alpha -= .05f;
         }
     }
     else
     {
         if (Sprite.Alpha <= .4f)
         {
             SoundManager.door.Play();
         }
         if (Sprite.Alpha < 1)
         {
             Sprite.Alpha += .05f;
         }
     }
 }
コード例 #11
0
    void Start()
    {
        hitBox.localPosition = new Vector3(0, 0, 0);
        sight.localPosition  = new Vector3(0, 0, 0);

        exclaim.SetActive(false);

        StartCoroutine("animateSprite");


        //Check current map
        RaycastHit[] hitRays         = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down);
        int          closestIndex    = -1;
        float        closestDistance = float.PositiveInfinity;

        if (hitRays.Length > 0)
        {
            for (int i = 0; i < hitRays.Length; i++)
            {
                if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                {
                    if (hitRays[i].distance < closestDistance)
                    {
                        closestDistance = hitRays[i].distance;
                        closestIndex    = i;
                    }
                }
            }
        }
        if (closestIndex != -1)
        {
            currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
        }
        else
        {
            Debug.Log("no map found for: " + gameObject.name);
        }

        if (trainerBehaviour == TrainerBehaviour.Turn)
        {
            StartCoroutine("turnAtRandom");
        }
        else
        {
            turnableDirections[0] = false;
            turnableDirections[1] = false;
            turnableDirections[2] = false;
            turnableDirections[3] = false;
            if (trainerBehaviour == TrainerBehaviour.Patrol)
            {
                StartCoroutine("patrolAround");
            }
        }

        updateDirection(direction);
        StartCoroutine(refireSightColliders());
    }
コード例 #12
0
    void Start()
    {
        initialPosition = hitBox.position;

        hitBox.localPosition = new Vector3(0, 0, 0);

        exclaim.SetActive(false);

        StartCoroutine("animateSprite");


        //Check current map
        RaycastHit[] hitRays         = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down);
        int          closestIndex    = -1;
        float        closestDistance = float.PositiveInfinity;

        if (hitRays.Length > 0)
        {
            for (int i = 0; i < hitRays.Length; i++)
            {
                if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                {
                    if (hitRays[i].distance < closestDistance)
                    {
                        closestDistance = hitRays[i].distance;
                        closestIndex    = i;
                    }
                }
            }
        }
        if (closestIndex != -1)
        {
            currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
        }
        else
        {
            Debug.Log("no map found for: " + gameObject.name);
        }



        if (npcBehaviour == NPCBehaviour.Walk)
        {
            StartCoroutine("walkAtRandom");
        }
        else if (npcBehaviour == NPCBehaviour.Patrol)
        {
            StartCoroutine("patrolAround");
        }
    }
コード例 #13
0
 /// <summary>
 /// 读取数据生成配置的Colliders
 /// </summary>
 /// <param name="mapData"></param>
 public void CreateColliders(List <ColliderDataNode> mapData)
 {
     if (mapData == null)
     {
         return;
     }
     for (int i = 0; i < mapData.Count; i++)
     {
         MapCollider col = CreateCollider(mapData[i]);
         if (col != null)
         {
             colliderDic.Add(col.m_strHandle, col);
         }
     }
 }
コード例 #14
0
    public void Initialize(Map map, int chunkX, int chunkY)
    {
        // chunk data
        this.map       = map;
        chunkPos       = new Vector2Int(chunkX, chunkY);
        topLeftNodePos = chunkPos * Map.chunkTileSize;
        topLeftPos     = map.NodePosToWorldPos(topLeftNodePos);

        // references
        // map components
        mapRenderer = GetComponent <MapRenderer>();
        mapCollider = GetComponent <MapCollider>();
        mapRenderer.Initialize(this);
        mapCollider.Initialize(this);
    }
コード例 #15
0
        public override void Initialize()
        {
            ClearColor = Color.CornflowerBlue;
            var renderer = new RenderLayerExcludeRenderer(1, UIComponent.UIRenderLayer);

            AddRenderer(renderer);


            //           var map = content.Load<TmxMap>("Map/untitled");
            var tiledEntity = CreateEntity("mapEntity");

            Benchmark.Go(() =>
            {
                map = Content.Load("/Map/untitled.tmx");

                isometricMapComponent = new IsometricMapComponent(map);
                tiledEntity.AddComponent(isometricMapComponent);
            });

            NetworkSingleton.Instance.OnInitialized     += OnNetworkInitialized;
            NetworkSingleton.Instance.OnClientConnected += OnClientConnected;

            var txt2D = Content.Load <Texture2D>("player");

            players = new PlayerFactory(this, 10, txt2D);


            colliderEntity = CreateEntity("collider");
            var collider = new MapCollider(map);

            foreach (var t in collider.Colliders)
            {
                colliderEntity.AddComponent(t);
            }

            var spawnObject = map.ObjectGroups["Objects"].GetTiledObject("spawn");

            Camera.SetPosition(spawnObject.WorldPosition);
            //camera.transform.setPosition(spawn.x+camera.bounds.width/4, spawn.y-camera.bounds.height/1.5f);

            UISetUp();
        }
コード例 #16
0
    // 当伤害体碰撞到Collider时:
    // 如果是Destroy类型的则应该设置速度为0,并发送回调(立即销毁/延迟销毁)
    // 如果是Bound类型的则应该根据速度,反弹,发送回调(原方向/法线对称)
    // 如果是Cross类型则应该已经在OnBeforeCollision中处理了

    protected override bool OnBeforeCollision(Fixture fixtureA, Fixture fixtureB)
    {
        if (null == b2Body)
        {
            return(false);
        }
        if (!m_isActive)
        {
            return(false);
        }
        Fixture other = (fixtureA.Body == b2Body) ? fixtureB : fixtureA;

        //UnityEngine.Debug.Log("伤害体碰撞 Before");
        MapCollider collider = other.Body.UserData as MapCollider;

        if (collider != null)
        {
            //UnityEngine.Debug.Log("  OnBeforeCollision  collider  ");
            if (boundType == eDamageBoundType.Cross)
            {
                return(false); // Cross类型直接通过
            }
            if (collider.m_isSensor == true)
            {
                return(false);
            }
        }

        MapRole role = other.Body.UserData as MapRole;

        if (role != null)
        {
            if (role == hostMapRole)
            {
                return(false);                    // 是主人放出来的 不发生碰撞
            }
            return(role.OnCanDamage(damageBody)); // 角色是否可以受击
        }
        // 场景物体是否可以受击 TODO
        return(true);
        //return base.OnBeforeCollision(fixtureA, fixtureB);
    }
コード例 #17
0
        public override void Update()
        {
            foreach (Item item in SceneManager.gameScene.objects.Where(item => item is Item && item.BulletCollider.Intersects(BulletCollider))) //yo dawg, i heard you like items..
            {
                if (item.Properties == Items.properties[9])
                {
                    SceneManager.gameScene.RemoveObject(item);
                    fuel++;
                    Debug.WriteLine("boat got fuel, level: " + fuel);
                }
            }

            if (Velocity.Length() > 0)
            {
                Camera.Follow(Center);
                time++;
                if (time > 120)
                {
                    SceneManager.CurrentScene = SceneManager.winScene;
                }
                SceneManager.gameScene.player.Position = Position + new Vector2(0, -50);
            }


            if (fuel >= REQUIRED_FUEL && MapCollider.Intersects(SceneManager.gameScene.player.MapCollider))
            {
                //end the game
                Velocity = new Vector2(10, 5);
                //SceneManager.gameScene.RemoveObject(SceneManager.gameScene.player);
                Sprite.Frame = 0;
                SceneManager.CurrentScene.RemoveObject(SceneManager.gameScene.player);
                SceneManager.gameScene.player.Sprite.AnimationSpeed = 0;
                SceneManager.gameScene.player.inventoryVisible      = false;
            }

            Position += Velocity;


            base.Update();
        }
コード例 #18
0
    void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
        SerializedObject serializedThis = new SerializedObject(this);

        selectedMap  = Selection.activeGameObject;
        selectedTile = Selection.activeGameObject;
        EditorGUILayout.LabelField("Map Editor:", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(serializedThis.FindProperty("setupTiles"), new GUIContent("Setup Tiles"), true);
        if (GUILayout.Button("Toggle Grid"))
        {
            if (GameObject.Find("TempMapEditorGrid") != null)
            {
                DestroyImmediate(GameObject.Find("TempMapEditorGrid"));
            }
            else
            {
                HierarchyProperty prop    = new HierarchyProperty(HierarchyType.GameObjects);
                GameObject        gridObj = Instantiate(gridPrefab, new Vector3(0, 0, 0), Quaternion.Euler(90, 0, 0));
                gridObj.name = "TempMapEditorGrid";
            }
        }
        if (selectedTile != null)
        {
            if (Selection.activeGameObject.scene.name != null)
            {
                if (Selection.gameObjects.Length == 1)
                {
                    if (selectedTile.GetComponent <Renderer>() != null)
                    {
                        if (selectedTile.GetComponent <MeshFilter>() != null)
                        {
                            EditorGUILayout.Separator();
                            EditorGUILayout.LabelField("Tile Editor:", EditorStyles.boldLabel);
                            MeshFilter meshFilter = selectedTile.GetComponent <MeshFilter>();
                            Renderer   renderer   = selectedTile.GetComponent <Renderer>();
                            Material[] mat        = renderer.sharedMaterials;
                            if (meshFilter.sharedMesh.name.Contains("cliff") && mat.Length == 2)
                            {
                                mat[0] = (Material)EditorGUILayout.ObjectField("Cliff Mat", renderer.sharedMaterials[0], typeof(Material), false);
                            }
                            else if (meshFilter.sharedMesh.name.Contains("stair"))
                            {
                                mat[0] = (Material)EditorGUILayout.ObjectField("Stair Mat", renderer.sharedMaterials[0], typeof(Material), false);
                            }
                            bool found = false;
                            if (mat.Length > 0)
                            {
                                for (int i = 0; i < mat.Length; i++)
                                {
                                    if (found)
                                    {
                                        break;
                                    }
                                    for (int e = 0; e < castedPresets.Length; e++)
                                    {
                                        if (mat[i] != null)
                                        {
                                            if (mat[i].name == castedPresets[e])
                                            {
                                                found  = true;
                                                matInt = i;
                                                if (firstRun)
                                                {
                                                    preset = (PresetTiles)e;
                                                }
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            found = true;
                                            if (firstRun)
                                            {
                                                preset = PresetTiles.None;
                                            }
                                        }
                                    }
                                    if (!found)
                                    {
                                        if (firstRun)
                                        {
                                            preset = PresetTiles.None;
                                        }
                                    }
                                }
                            }
                            if (preset == PresetTiles.None)
                            {
                                if (meshFilter.sharedMesh.name == "tile" && mat.Length == 1)
                                {
                                    mat[0] = (Material)EditorGUILayout.ObjectField("Tile Mat", renderer.sharedMaterials[0], typeof(Material), false);
                                }
                                else if (meshFilter.sharedMesh.name.Contains("cliff") && mat.Length == 2)
                                {
                                    mat[1] = (Material)EditorGUILayout.ObjectField("Overlay Mat", renderer.sharedMaterials[1], typeof(Material), false);
                                }
                                else if (meshFilter.sharedMesh.name == "stairDirt" && mat.Length == 2)
                                {
                                    mat[1] = (Material)EditorGUILayout.ObjectField("Side Mat", renderer.sharedMaterials[1], typeof(Material), false);
                                }
                            }
                            if (matInt < mat.Length && matInt >= 0)
                            {
                                if (!firstRun)
                                {
                                    mat[matInt] = (Material)AssetDatabase.LoadAssetAtPath("Assets/MapCreation/Materials/" + castedPresets[(int)preset] + ".mat", typeof(Material));
                                }
                            }
                            if ((matInt < 0 || matInt >= mat.Length) || preset == PresetTiles.None)
                            {
                                matInt = EditorGUILayout.IntField("Mat Element", matInt);
                            }
                            firstRun = true;
                            PresetTiles oldpreset = preset;
                            if (meshFilter.sharedMesh.name != "stairRail")
                            {
                                preset = (PresetTiles)EditorGUILayout.EnumPopup("Tile Preset", preset);
                            }
                            if (oldpreset != preset)
                            {
                                firstRun = false;
                            }
                            if (selTile1 != null && mat != null)
                            {
                                if (selTile1.materials != null)
                                {
                                    for (int i = mat.Length - 1; i < selTile1.materials.Length; i++)
                                    {
                                        mat[i] = selTile1.materials[i];
                                    }
                                }
                                selTile1 = null;
                            }
                            if (setupTiles != null)
                            {
                                if (setupTiles.Length > 0)
                                {
                                    if (GUILayout.Button("Select Setups"))
                                    {
                                        GenericMenu menu = new GenericMenu();
                                        foreach (Tile tile in setupTiles)
                                        {
                                            AddTileItem1(menu, tile.name, tile);
                                        }
                                        menu.ShowAsContext();
                                    }
                                }
                            }
                            renderer.sharedMaterials = mat;
                        }
                    }
                    else if (selectedTile.GetComponent <Footstep>() != null)
                    {
                        if (selTile2 != null)
                        {
                            if (selTile2.footstepSound == null)
                            {
                                selTile2 = null;
                            }
                        }
                        Footstep         footstep         = selectedTile.GetComponent <Footstep>();
                        SerializedObject serializedObject = new SerializedObject(footstep);
                        EditorGUILayout.Separator();
                        EditorGUILayout.LabelField("Footstep Editor:", EditorStyles.boldLabel);
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("walkClip"), new GUIContent("Footstep"), true);
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("gizmoColor"), new GUIContent("Gizmo Color"), true);
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("stepOnAnyObject"), new GUIContent("Any Object?"), true);
                        if (selTile2 != null)
                        {
                            if (selTile2.footstepSound != null)
                            {
                                serializedObject.FindProperty("walkClip").objectReferenceValue = selTile2.footstepSound;
                            }
                            if (selTile2.footstepGizmo != null)
                            {
                                serializedObject.FindProperty("gizmoColor").colorValue = selTile2.footstepGizmo;
                            }
                            serializedObject.FindProperty("stepOnAnyObject").boolValue = selTile2.footstepAnyObject;
                        }
                        selTile2 = null;
                        if (setupTiles != null)
                        {
                            if (setupTiles.Length > 0)
                            {
                                if (GUILayout.Button("Select Setups"))
                                {
                                    GenericMenu menu = new GenericMenu();
                                    foreach (Tile tile in setupTiles)
                                    {
                                        AddTileItem2(menu, tile.name, tile);
                                    }
                                    menu.ShowAsContext();
                                }
                            }
                        }
                        serializedObject.ApplyModifiedProperties();
                    }
                    EditorGUILayout.Separator();
                    if (selectedMap != null)
                    {
                        if (selectedMap.transform.parent != null)
                        {
                            selectedMap = selectedMap.transform.parent.gameObject;
                        }
                        EditorGUILayout.Separator();
                        if (selectedMap.GetComponent <MapCollider>() != null)
                        {
                            EditorGUILayout.LabelField("Map Collision:", EditorStyles.boldLabel);
                            MapCollider mapCollider = selectedMap.GetComponent <MapCollider>();
                            if (GUILayout.Button("Generate Collision Mesh"))
                            {
                                mapCollider.shorthandCollisionMap = "0x4";
                                mapCollider.width  = 2;
                                mapCollider.length = 2;
                                MapCompiler.Compile(selectedMap);
                            }
                            mapCollider.drawWireframe  = EditorGUILayout.Toggle("Wireframe Gizmo", mapCollider.drawWireframe);
                            mapCollider.wireframeColor = EditorGUILayout.ColorField("Wireframe Color", mapCollider.wireframeColor);
                        }
                        EditorGUILayout.Separator();
                        if (selectedMap.GetComponent <MapSettings>() != null)
                        {
                            EditorGUILayout.LabelField("Map Settings:", EditorStyles.boldLabel);
                            MapSettings mapSettings = selectedMap.GetComponent <MapSettings>();
                            mapSettings.mapName                     = EditorGUILayout.TextField(new GUIContent("Map Name"), mapSettings.mapName);
                            mapSettings.mapNameBoxTexture           = (Sprite)EditorGUILayout.ObjectField("Map Name Box Sprite", mapSettings.mapNameBoxTexture, typeof(Sprite), false);
                            mapSettings.mapNameColor                = EditorGUILayout.ColorField("Map Name Color", mapSettings.mapNameColor);
                            mapSettings.mapBGMClip                  = (AudioClip)EditorGUILayout.ObjectField("Map BGM", mapSettings.mapBGMClip, typeof(AudioClip), false);
                            mapSettings.mapBGMNightClip             = (AudioClip)EditorGUILayout.ObjectField("Map BGM 2", mapSettings.mapBGMNightClip, typeof(AudioClip), false);
                            mapSettings.mapBGMLoopStartSamples      = EditorGUILayout.IntField("Map BGM Loop Samples", mapSettings.mapBGMLoopStartSamples);
                            mapSettings.mapBGMNightLoopStartSamples = EditorGUILayout.IntField("Map BGM 2 Loop Samples", mapSettings.mapBGMNightLoopStartSamples);
                            EditorGUILayout.Space();
                            mapSettings.environment   = (MapSettings.Environment)EditorGUILayout.EnumPopup("Map Environment", mapSettings.environment);
                            mapSettings.environment2  = (MapSettings.Environment)EditorGUILayout.EnumPopup("Map Environment 2", mapSettings.environment2);
                            mapSettings.pokemonRarity = (MapSettings.PokemonRarity)EditorGUILayout.EnumPopup("Pokémon Rarity", mapSettings.pokemonRarity);
                            SerializedObject serializedObject = new SerializedObject(mapSettings);
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("encounters"), new GUIContent("Map Encounters"), true);
                            serializedObject.ApplyModifiedProperties();
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Cannot process multiple selections!", EditorStyles.boldLabel);
                }
            }
            else
            {
                EditorGUILayout.LabelField("Cannot process non-scene objects!", EditorStyles.boldLabel);
            }
        }
        else
        {
            EditorGUILayout.LabelField("No tile selected!", EditorStyles.boldLabel);
        }
        serializedThis.ApplyModifiedProperties();
        EditorGUILayout.EndScrollView();
    }
コード例 #19
0
    private bool checkDestination(Vector3 movement)
    {
        startPosition        = transform.position;
        destinationPosition1 = startPosition + movement;

        int direction = 0;

        //GlobalVariables.global.debug("move: "+movement.x +" "+movement.z);
        if (Mathf.RoundToInt(movement.x) != 0)
        {
            // moving right or left
            direction            = 1;
            destinationPosition2 = destinationPosition1 + new Vector3(0, 0, 1);
        }
        else if (Mathf.RoundToInt(movement.z) != 0)
        {
            //moving up or down
            destinationPosition2 = destinationPosition1 + new Vector3(1, 0, 0);
        }

        //GlobalVariables.global.debug("s: "+startPosition +" d1: "+destinationPosition1+" d2: "+destinationPosition2);

        //return a list of every collision at xyz position with a spherical radius of 0.4f
        hitColliders =
            Physics.OverlapSphere(new Vector3(transform.position.x, transform.position.y, transform.position.z), 0.4f);

        //Check current map
        RaycastHit[] hitRays =
            Physics.RaycastAll(transform.position + Vector3.up + Player.getForwardVectorRaw(direction), Vector3.down, 3f);
        int   closestIndex    = -1;
        float closestDistance = float.PositiveInfinity;

        if (hitRays.Length > 0)
        {
            for (int i = 0; i < hitRays.Length; i++)
            {
                if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                {
                    if (hitRays[i].distance < closestDistance)
                    {
                        closestDistance = hitRays[i].distance;
                        closestIndex    = i;
                    }
                }
            }
        }
        if (closestIndex != -1)
        {
            currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();

            //Check destiantion map
            hitRays = Physics.RaycastAll(transform.position + Vector3.up + Player.getForwardVectorRaw(direction),
                                         Vector3.down, 3f);
            closestIndex    = -1;
            closestDistance = float.PositiveInfinity;
            if (hitRays.Length > 0)
            {
                for (int i = 0; i < hitRays.Length; i++)
                {
                    if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                    {
                        if (hitRays[i].distance < closestDistance)
                        {
                            closestDistance = hitRays[i].distance;
                            closestIndex    = i;
                        }
                    }
                }
            }
            if (closestIndex != -1)
            {
                destinationMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
            }
            else
            {
                destinationMap = currentMap;
            }


            //check destination for objects
            currentObjectCollider = null; //empty currentOBJC
            hitColliders          = Physics.OverlapSphere(destinationPosition1, 0.25f);
            if (hitColliders.Length > 0)
            {
                for (int i = 0; i < hitColliders.Length; i++)
                {
                    if (hitColliders[i].name.ToLowerInvariant().Contains("object"))
                    {
                        //if hits object
                        currentObjectCollider = hitColliders[i];
                    }
                }
            }
            if (currentObjectCollider == null)
            {
                hitColliders = Physics.OverlapSphere(destinationPosition2, 0.25f);
                if (hitColliders.Length > 0)
                {
                    for (int i = 0; i < hitColliders.Length; i++)
                    {
                        if (hitColliders[i].name.ToLowerInvariant().Contains("object"))
                        {
                            //if hits object
                            currentObjectCollider = hitColliders[i];
                        }
                    }
                }
            }
            if (currentObjectCollider == null)
            {
                //if both positions are free
                //ensure the slopes of the destination are both 0
                float slope1 = MapCollider.getSlopeOfPosition(destinationPosition1, direction);
                float slope2 = MapCollider.getSlopeOfPosition(destinationPosition2, direction);

                //Make sure that destination Position is at most a single square away from start.
                //this way we can ensure that the movement of the object will be one square at most
                movement = new Vector3(Mathf.Clamp(movement.x, -1, 1), Mathf.Clamp(movement.y, -1, 1),
                                       Mathf.Clamp(movement.z, -1, 1));
                destinationPosition1 = startPosition + movement;

                if (slope1 == 0 && slope2 == 0)
                {
                    //if both squares in the destination are not impassable tiles
                    //Debug.Log (destinationPosition1);
                    if (destinationMap.getTileTag(destinationPosition1) != 1 &&
                        destinationMap.getTileTag(destinationPosition1) != 2 &&
                        destinationMap.getTileTag(destinationPosition2) != 1 &&
                        destinationMap.getTileTag(destinationPosition2) != 2)
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
コード例 #20
0
    ///Make the player move one space in the direction they are facing
    private IEnumerator moveForward()
    {
        Vector3 movement = getForwardVector();

        bool ableToMove = false;

        //without any movement, able to move should stay false
        if (movement != Vector3.zero)
        {
            //check destination for objects/transparents
            Collider   objectCollider      = null;
            Collider   transparentCollider = null;
            Collider[] hitColliders        = Physics.OverlapSphere(transform.position + movement + new Vector3(0, 0.5f, 0),
                                                                   0.4f);
            if (hitColliders.Length > 0)
            {
                for (int i = 0; i < hitColliders.Length; i++)
                {
                    if (hitColliders[i].name.ToLowerInvariant().Contains("_object"))
                    {
                        objectCollider = hitColliders[i];
                    }
                    else if (hitColliders[i].name.ToLowerInvariant().Contains("_transparent"))
                    {
                        transparentCollider = hitColliders[i];
                    }
                }
            }

            if (objectCollider != null)
            {
                //send bump message to the object's parent object
                objectCollider.transform.parent.gameObject.SendMessage("bump", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                //if no objects are in the way
                int destinationTileTag = destinationMap.getTileTag(transform.position + movement);

                RaycastHit bridgeHit =
                    MapCollider.getBridgeHitOfPosition(transform.position + movement + new Vector3(0, 0.1f, 0));
                if (bridgeHit.collider != null || destinationTileTag != 1)
                {
                    //wall tile tag

                    if (bridgeHit.collider == null && !surfing && destinationTileTag == 2)
                    {
                        //(water tile tag)
                    }
                    else
                    {
                        if (surfing && destinationTileTag != 2f)
                        {
                            //disable surfing if not headed to water tile
                            updateAnimation("walk", walkFPS);
                            speed   = walkSpeed;
                            surfing = false;
                            StartCoroutine("dismount");
                            BgmHandler.main.PlayMain(accessedAudio, accessedAudioLoopStartSamples);
                        }

                        if (destinationMap != currentMap)
                        {
                            //if moving onto a new map
                            currentMap          = destinationMap;
                            accessedMapSettings = destinationMap.gameObject.GetComponent <MapSettings>();
                            if (accessedAudio != accessedMapSettings.getBGM())
                            {
                                //if audio is not already playing
                                accessedAudio = accessedMapSettings.getBGM();
                                accessedAudioLoopStartSamples = accessedMapSettings.getBGMLoopStartSamples();
                                BgmHandler.main.PlayMain(accessedAudio, accessedAudioLoopStartSamples);
                            }
                            destinationMap.BroadcastMessage("repair", SendMessageOptions.DontRequireReceiver);
                            if (accessedMapSettings.mapNameBoxTexture != null)
                            {
                                MapName.display(accessedMapSettings.mapNameBoxTexture, accessedMapSettings.mapName,
                                                accessedMapSettings.mapNameColor);
                            }
                            Debug.Log(destinationMap.name + "   " + accessedAudio.name);
                        }

                        if (transparentCollider != null)
                        {
                            //send bump message to the transparents's parent object
                            transparentCollider.transform.parent.gameObject.SendMessage("bump",
                                                                                        SendMessageOptions.DontRequireReceiver);
                        }

                        ableToMove = true;
                        yield return(StartCoroutine(move(movement)));
                    }
                }
            }
        }

        //if unable to move anywhere, then set moving to false so that the player stops animating.
        if (!ableToMove)
        {
            Invoke("playBump", 0.05f);
            moving    = false;
            animPause = true;
        }
    }
コード例 #21
0
    public Vector3 getForwardVector(int direction, bool checkForBridge)
    {
        //set initial vector3 based off of direction
        Vector3 movement = getForwardVectorRaw(direction);

        //Check destination map	and bridge																//0.5f to adjust for stair height
        //cast a ray directly downwards from the position directly in front of the player		//1f to check in line with player's head
        RaycastHit[] hitColliders = Physics.RaycastAll(transform.position + movement + new Vector3(0, 1.5f, 0),
                                                       Vector3.down);
        RaycastHit mapHit    = new RaycastHit();
        RaycastHit bridgeHit = new RaycastHit();

        //cycle through each of the collisions
        if (hitColliders.Length > 0)
        {
            for (int i = 0; i < hitColliders.Length; i++)
            {
                //if map has not been found yet
                if (mapHit.collider == null)
                {
                    //if a collision's gameObject has a mapCollider, it is a map. set it to be the destination map.
                    if (hitColliders[i].collider.gameObject.GetComponent <MapCollider>() != null)
                    {
                        mapHit         = hitColliders[i];
                        destinationMap = mapHit.collider.gameObject.GetComponent <MapCollider>();
                    }
                }
                else if (bridgeHit.collider != null && checkForBridge)
                {
                    //if both have been found
                    i = hitColliders.Length; //stop searching
                }
                //if bridge has not been found yet
                if (bridgeHit.collider == null && checkForBridge)
                {
                    //if a collision's gameObject has a BridgeHandler, it is a bridge.
                    if (hitColliders[i].collider.gameObject.GetComponent <BridgeHandler>() != null)
                    {
                        bridgeHit = hitColliders[i];
                    }
                }
                else if (mapHit.collider != null)
                {
                    //if both have been found
                    i = hitColliders.Length; //stop searching
                }
            }
        }

        if (bridgeHit.collider != null)
        {
            //modify the forwards vector to align to the bridge.
            movement -= new Vector3(0, (transform.position.y - bridgeHit.point.y), 0);
        }
        //if no bridge at destination
        else if (mapHit.collider != null)
        {
            //modify the forwards vector to align to the mapHit.
            movement -= new Vector3(0, (transform.position.y - mapHit.point.y), 0);
        }


        float currentSlope     = Mathf.Abs(MapCollider.getSlopeOfPosition(transform.position, direction));
        float destinationSlope =
            Mathf.Abs(MapCollider.getSlopeOfPosition(transform.position + getForwardVectorRaw(), direction,
                                                     checkForBridge));
        float yDistance = Mathf.Abs((transform.position.y + movement.y) - transform.position.y);

        yDistance = Mathf.Round(yDistance * 100f) / 100f;

        //Debug.Log("currentSlope: "+currentSlope+", destinationSlope: "+destinationSlope+", yDistance: "+yDistance);

        //if either slope is greater than 1 it is too steep.
        if (currentSlope <= 1 && destinationSlope <= 1)
        {
            //if yDistance is greater than both slopes there is a vertical wall between them
            if (yDistance <= currentSlope || yDistance <= destinationSlope)
            {
                return(movement);
            }
        }
        return(Vector3.zero);
    }
コード例 #22
0
    void Start()
    {
        if (!surfing)
        {
            updateMount(false);
        }

        updateAnimation("walk", walkFPS);
        StartCoroutine("animateSprite");
        animPause = true;

        reflect(false);
        followerScript.reflect(false);

        updateDirection(direction);

        StartCoroutine(control());


        //Check current map
        RaycastHit[] hitRays         = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down);
        int          closestIndex    = -1;
        float        closestDistance = float.PositiveInfinity;

        if (hitRays.Length > 0)
        {
            for (int i = 0; i < hitRays.Length; i++)
            {
                if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                {
                    if (hitRays[i].distance < closestDistance)
                    {
                        closestDistance = hitRays[i].distance;
                        closestIndex    = i;
                    }
                }
            }
        }
        if (closestIndex != -1)
        {
            currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
        }
        else
        {
            //if no map found
            //Check for map in front of player's direction
            hitRays         = Physics.RaycastAll(transform.position + Vector3.up + getForwardVectorRaw(), Vector3.down);
            closestIndex    = -1;
            closestDistance = float.PositiveInfinity;
            if (hitRays.Length > 0)
            {
                for (int i = 0; i < hitRays.Length; i++)
                {
                    if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                    {
                        if (hitRays[i].distance < closestDistance)
                        {
                            closestDistance = hitRays[i].distance;
                            closestIndex    = i;
                        }
                    }
                }
            }
            if (closestIndex != -1)
            {
                currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
            }
            else
            {
                Debug.Log("no map found");
            }
        }


        if (currentMap != null)
        {
            accessedMapSettings = currentMap.gameObject.GetComponent <MapSettings>();
            if (accessedAudio != accessedMapSettings.getBGM())
            {
                //if audio is not already playing
                accessedAudio = accessedMapSettings.getBGM();
                accessedAudioLoopStartSamples = accessedMapSettings.getBGMLoopStartSamples();
                BgmHandler.main.PlayMain(accessedAudio, accessedAudioLoopStartSamples);
            }
            if (accessedMapSettings.mapNameBoxTexture != null)
            {
                MapName.display(accessedMapSettings.mapNameBoxTexture, accessedMapSettings.mapName,
                                accessedMapSettings.mapNameColor);
            }
        }


        //check position for transparent bumpEvents
        Collider transparentCollider = null;

        Collider[] hitColliders = Physics.OverlapSphere(transform.position, 0.4f);
        if (hitColliders.Length > 0)
        {
            for (int i = 0; i < hitColliders.Length; i++)
            {
                if (hitColliders[i].name.ToLowerInvariant().Contains("_transparent"))
                {
                    if (!hitColliders[i].name.ToLowerInvariant().Contains("player") &&
                        !hitColliders[i].name.ToLowerInvariant().Contains("follower"))
                    {
                        transparentCollider = hitColliders[i];
                    }
                }
            }
        }
        if (transparentCollider != null)
        {
            //send bump message to the object's parent object
            transparentCollider.transform.parent.gameObject.SendMessage("bump", SendMessageOptions.DontRequireReceiver);
        }

        //DEBUG
        if (accessedMapSettings != null)
        {
            WildPokemonInitialiser[] encounterList =
                accessedMapSettings.getEncounterList(WildPokemonInitialiser.Location.Standard);
            string namez = "";
            for (int i = 0; i < encounterList.Length; i++)
            {
                namez += PokemonDatabase.getPokemon(encounterList[i].ID).getName() + ", ";
            }
            Debug.Log("Wild Pokemon for map \"" + accessedMapSettings.mapName + "\": " + namez);
        }
        //

        GlobalVariables.global.resetFollower();
    }
コード例 #23
0
    /*/
     * /// Checks the position for player and returns the next position to check
     * private Vector3 checkPosition(Vector3 position){
     *      playerAtPosition = false;
     *      positionIsBlocked = false;
     *
     *      Vector3 nextPosition = position;
     *
     *
     *      Vector3 movement = new Vector3(0,0,0);
     *      if(trainer.direction == 0){
     *              movement = new Vector3(0,0,1f);}
     *      else if(trainer.direction == 1){
     *              movement = new Vector3(1f,0,0);}
     *      else if(trainer.direction == 2){
     *              movement = new Vector3(0,0,-1f);}
     *      else if(trainer.direction == 3){
     *              movement = new Vector3(-1f,0,0);}
     *
     *      float currentTileTag = trainer.currentMap.getTileTag(position);
     *      //check current tileTag for stairs(3)
     *      if(Mathf.Floor(currentTileTag) == 3f){
     *              //check if stair direction is same as trainer direction
     *              if(Mathf.Round(((currentTileTag) - 3f)*10) == trainer.direction){
     *                      movement += new Vector3(0,0.5f,0);}
     *              else{
     *                      float flippedDirection = trainer.direction + 2;
     *                      if(flippedDirection > 3){
     *                              flippedDirection -= 4;}
     *                      if(Mathf.Round(((currentTileTag) - 3f)*10) == flippedDirection){
     *                              movement += new Vector3(0,-0.5f,0);}
     *              }
     *      }
     *      float destinationTileTag = trainer.currentMap.getTileTag(position+movement);
     *      //check destination tileTag for stairs(3)
     *      if(Mathf.Floor(destinationTileTag) == 3f){
     *              if(Mathf.Round(((destinationTileTag) - 3f)*10) == trainer.direction){
     *                      movement += new Vector3(0,0.5f,0);}
     *      } //else if its stair-top(4)
     *      else if(Mathf.Floor(destinationTileTag) == 4f){
     *              if(Mathf.Round(((destinationTileTag) - 4f)*10) == trainer.direction){
     *                      movement += new Vector3(0,-0.5f,0);}
     *      }
     *
     *      destinationTileTag = trainer.currentMap.getTileTag(position+movement);
     *      //check destination tileTag for impassibles
     *      if(Mathf.Floor(destinationTileTag) == 0f || Mathf.Floor(destinationTileTag) == 2f){
     *              positionIsBlocked = true;}
     *      else if(trainer.trainerSurfing){ //if a surf trainer, normal tiles are impassible
     *              if(Mathf.Floor(destinationTileTag) == 1f || Mathf.Floor(destinationTileTag) == 5f){
     *                      positionIsBlocked = true;}
     *      }
     *      else if(Mathf.Floor(destinationTileTag) == 6f){
     *              positionIsBlocked = true;}
     *
     *      nextPosition = position + movement;
     *      //check nextPosition for objects/followers and check for the player
     *      Collider[] hitColliders = Physics.OverlapSphere (nextPosition, 0.2f);
     *      if (hitColliders.Length > 0){
     *              for (int i = 0; i < hitColliders.Length; i++){
     *                      if(hitColliders[i].name == "Player_Transparent"){
     *                              playerAtPosition = true;
     *                              i = hitColliders.Length;}
     *                      else if(hitColliders[i].name == "Follower_Transparent" ||
     *                              hitColliders[i].name.Contains("_Object")){
     *                              positionIsBlocked = true;
     *                              i = hitColliders.Length;}
     *              }
     *      }
     *
     *      return nextPosition;
     * }
     * //*/

    /// Checks the position for player and returns the next position to check
    private Vector3 checkPosition(Vector3 position)
    {
        playerAtPosition  = false;
        positionIsBlocked = false;

        Vector3 nextPosition = position;

        Vector3 forwardsVector = new Vector3(0, 0, 0);

        if (trainer.direction == 0)
        {
            forwardsVector = new Vector3(0, 0, 1f);
        }
        else if (trainer.direction == 1)
        {
            forwardsVector = new Vector3(1f, 0, 0);
        }
        else if (trainer.direction == 2)
        {
            forwardsVector = new Vector3(0, 0, -1f);
        }
        else if (trainer.direction == 3)
        {
            forwardsVector = new Vector3(-1f, 0, 0);
        }

        Vector3 movement = forwardsVector;


        //Check destination map																	//0.5f to adjust for stair height
        MapCollider destinationMap = trainer.currentMap;

        //cast a ray directly downwards from the position directly in front of the npc			//1f to check in line with player's head
        RaycastHit[] mapHitColliders = Physics.RaycastAll(position + movement + new Vector3(0, 1.5f, 0), Vector3.down);
        RaycastHit   mapHit          = new RaycastHit();

        //cycle through each of the collisions
        if (mapHitColliders.Length > 0)
        {
            for (int i = 0; i < mapHitColliders.Length; i++)
            {
                //if a collision's gameObject has a mapCollider, it is a map. set it to be the destination map.
                if (mapHitColliders[i].collider.gameObject.GetComponent <MapCollider>() != null)
                {
                    mapHit         = mapHitColliders[i];
                    destinationMap = mapHit.collider.gameObject.GetComponent <MapCollider>();
                    i = mapHitColliders.Length;
                }
            }
        }

        //check for a bridge at the destination
        RaycastHit bridgeHit = MapCollider.getBridgeHitOfPosition(position + movement + new Vector3(0, 1.5f, 0));

        if (bridgeHit.collider != null)
        {
            //modify the forwards vector to align to the bridge.
            movement -= new Vector3(0, (position.y - bridgeHit.point.y), 0);
        }
        //if no bridge at destination
        else if (mapHit.collider != null)
        {
            //modify the forwards vector to align to the mapHit.
            movement -= new Vector3(0, (position.y - mapHit.point.y), 0);
        }


        float currentSlope     = Mathf.Abs(MapCollider.getSlopeOfPosition(position, trainer.direction));
        float destinationSlope = Mathf.Abs(MapCollider.getSlopeOfPosition(position + forwardsVector, trainer.direction));
        float yDistance        = Mathf.Abs((position.y + movement.y) - position.y);

        yDistance = Mathf.Round(yDistance * 100f) / 100f;

        //if either slope is greater than 1 it is too steep.
        if (currentSlope <= 1 && destinationSlope <= 1)
        {
            //if yDistance is greater than both slopes there is a vertical wall between them
            if (yDistance <= currentSlope || yDistance <= destinationSlope)
            {
                //check destination tileTag for impassibles
                int destinationTileTag = destinationMap.getTileTag(position + movement);
                if (destinationTileTag == 1)
                {
                    positionIsBlocked = true;
                }
                else
                {
                    if (trainer.trainerSurfing)                     //if a surf trainer, normal tiles are impassible
                    {
                        if (destinationTileTag != 2)
                        {
                            positionIsBlocked = true;
                        }
                    }
                    else                      //if not a surf trainer, surf tiles are impassible
                    {
                        if (destinationTileTag == 2)
                        {
                            positionIsBlocked = true;
                        }
                    }
                }

                //check destination for objects/player/follower
                Collider[] hitColliders = Physics.OverlapSphere(position + movement, 0.4f);
                if (hitColliders.Length > 0)
                {
                    for (int i = 0; i < hitColliders.Length; i++)
                    {
                        if (hitColliders[i].name == "Player_Transparent")
                        {
                            playerAtPosition = true;
                        }
                        else if (hitColliders[i].name == "Follower_Transparent" ||
                                 hitColliders[i].name.ToLowerInvariant().Contains("_object"))
                        {
                            positionIsBlocked = true;
                        }
                    }
                }
            }
        }
        return(position + movement);
    }
コード例 #24
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "MapCollider")
     {
         if (GameData.instance.atTitleScreen)
         {
             return;
         }
         MapCollider mapCollider = col.gameObject.GetComponent <MapCollider>();
         currentArea = mapCollider.mapArea;
         int mapArea = (int)mapCollider.mapArea;
         MapManager.instance.currentMapGrassTilemap = mapCollider.grassTilemap.GetComponent <TilemapRenderer>();
         canUseBike = mapCollider.canUseBike; //set the bool for whether the player can use the bike
         if (forceBikeMaps.Contains(currentArea))
         {
             walkSurfBikeState = MovementState.Bike;                                     //if the map forces the player to use the bike, set the movement state to the bike
         }
         else if (!canUseBike && walkSurfBikeState == MovementState.Bike)
         {
             walkSurfBikeState = MovementState.Walk;
         }
         if (currentArea == Map.Route17)
         {
             forcePlayerBikeDownwards = true;                            //if the player is on Route 17 (Cycling Road), force the player to move downwards
         }
         else
         {
             forcePlayerBikeDownwards = false;
         }
         if (GameData.instance.WaterEncounterMaps.Contains(currentArea))
         {
             areaHasWaterEncounters = true;
         }
         else
         {
             areaHasWaterEncounters = false;
         }
         if (GameData.instance.MapGrassEncounterTableIndices[mapArea] != -1)
         {
             currentAreaTable = PokemonData.encounters[GameData.instance.MapGrassEncounterTableIndices[mapArea]];
         }
         else
         {
             currentAreaTable = null;
         }
         if (currentArea == Map.House)
         {
             return;                           //if the current area is a house, don't change the music
         }
         int songIndex = (int)SoundManager.MapSongs[mapArea];
         if (SoundManager.instance.currentSong != songIndex && walkSurfBikeState == MovementState.Walk && !inBattle && !CreditsHandler.instance.isPlayingCredits)
         {
             if (SoundManager.instance.isFadingSong)
             {
                 SoundManager.instance.StopFadeSong();
             }
             SoundManager.instance.FadeToSong(songIndex);
         }
     }
     if (col.tag == "Warp")
     {
         TileWarp tileWarp = col.GetComponent <TileWarp>();
         onWarpTile      = true;
         currentWarpTile = tileWarp;
     }
 }
コード例 #25
0
    void Start()
    {
        if (!surfing)
        {
            updateMount(false);
        }

        updateAnimation("walk", walkFPS);
        #if UNITY_STANDALONE_WIN
        if (SaveData.currentSave.getCVariable("female") == 0)
        {
            GlobalVariables.global.SetRPCSmallImageKey("m_" + SaveData.currentSave.playerOutfit, SaveData.currentSave.playerName);
        }
        else
        {
            GlobalVariables.global.SetRPCSmallImageKey("f_" + SaveData.currentSave.playerOutfit, SaveData.currentSave.playerName);
        }
        #endif
        StartCoroutine(animateSprite());
        animPause = true;

        reflect(false);
        followerScript.reflect(false);

        updateDirection(direction);

        StartCoroutine(control());


        //Check current map
        RaycastHit[] hitRays = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down);
        int          closestIndex;
        float        closestDistance;

        CheckHitRaycastDistance(hitRays, out closestIndex, out closestDistance);

        if (closestIndex >= 0)
        {
            currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
        }
        else
        {
            //if no map found
            //Check for map in front of player's direction
            hitRays = Physics.RaycastAll(transform.position + Vector3.up + getForwardVectorRaw(), Vector3.down);

            CheckHitRaycastDistance(hitRays, out closestIndex, out closestDistance);

            if (closestIndex >= 0)
            {
                currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
            }
            else
            {
                GlobalVariables.global.debug("no map found");
            }
        }


        if (currentMap != null)
        {
            accessedMapSettings = currentMap.gameObject.GetComponent <MapSettings>();
            AudioClip audioClip        = accessedMapSettings.getBGM();
            int       loopStartSamples = accessedMapSettings.getBGMLoopStartSamples();

            if (accessedAudio != audioClip)
            {
                //if audio is not already playing
                accessedAudio = audioClip;
                accessedAudioLoopStartSamples = loopStartSamples;
                BgmHandler.main.PlayMain(accessedAudio, accessedAudioLoopStartSamples);
            }
            if (accessedMapSettings.mapNameBoxTexture != null)
            {
                MapName.display(accessedMapSettings.mapNameBoxTexture, accessedMapSettings.mapName,
                                accessedMapSettings.mapNameColor);
            }
        }


        //check position for transparent bumpEvents
        Collider   transparentCollider = null;
        Collider[] hitColliders        = Physics.OverlapSphere(transform.position, 0.4f);

        transparentCollider = hitColliders.LastOrDefault(collider => collider.name.ToLowerInvariant().Contains("_transparent") &&
                                                         !collider.name.ToLowerInvariant().Contains("player") &&
                                                         !collider.name.ToLowerInvariant().Contains("follower"));

        if (transparentCollider != null)
        {
            //send bump message to the object's parent object
            transparentCollider.transform.parent.gameObject.SendMessage("bump", SendMessageOptions.DontRequireReceiver);
        }

        //DEBUG
        if (accessedMapSettings != null)
        {
            string pkmnNames = "";
            foreach (var encounter in accessedMapSettings.getEncounterList(WildPokemonInitialiser.Location.Standard))
            {
                pkmnNames += PokemonDatabase.getPokemon(encounter.ID).getName() + ", ";
            }
            GlobalVariables.global.debug("Wild Pokemon for map \"" + accessedMapSettings.mapName + "\": " + pkmnNames);

            /*if(GlobalVariables.global.presence.largeImageKey != accessedMapSettings.discordImageKey || accessedMapSettings.discordDetails != "")
             * {
             *  if(GlobalVariables.global.presence.largeImageKey != accessedMapSettings.discordImageKey)
             *      GlobalVariables.global.SetRPCLargeImageKey(accessedMapSettings.discordImageKey, accessedMapSettings.mapName);
             *  if(accessedMapSettings.discordDetails != "")
             *      GlobalVariables.global.SetRPCDetails(accessedMapSettings.discordDetails);
             *  GlobalVariables.global.UpdatePresence();
             * }*/
        }
        //

        GlobalVariables.global.resetFollower();
    }
コード例 #26
0
 // Use this for initialization
 void Start()
 {
     inst = this;
 }
コード例 #27
0
ファイル: MapGen.cs プロジェクト: GameDeva/Codename-Slash
 // Change the static colliders of the scene/map
 public void ChangeMapColliders(MapCollider colliderType)
 {
     CurrentMapColliderType = colliderType;
 }