예제 #1
0
        private IEnumerator getHeroFSMs()
        {
            while (GameManager.instance == null || HeroController.instance == null)
            {
                yield return(null);
            }

            KnightGameObject = GameObject.Find("Knight");
            KnightSprite     = KnightGameObject.GetComponent <tk2dSprite>();
            ProxyFSM         = FSMUtility.LocateFSM(KnightGameObject, "ProxyFSM");
            SpellControl     = FSMUtility.LocateFSM(KnightGameObject, "Spell Control");
            NailArtControl   = FSMUtility.LocateFSM(KnightGameObject, "Nail Arts");
            KnightPhysics    = KnightGameObject.GetComponent <Rigidbody2D>();
            //_baseGravityScale = KnightPhysics.gravityScale;
            //_baseGravityScale = 1f;

            setupFlamePillar();
            GhostKnight       = new GameObject("GhostKnight", typeof(Rigidbody2D), typeof(SpriteRenderer), typeof(BoxCollider2D), typeof(ghostknight));
            GhostKnight.layer = 0;
            BoxCollider2D gkCollide     = GhostKnight.GetComponent <BoxCollider2D>();
            BoxCollider2D knightCollide = KnightGameObject.GetComponent <BoxCollider2D>();

            gkCollide.size             = new Vector2(knightCollide.size.x + 0.4f, knightCollide.size.y + 1.2f);
            gkCollide.autoTiling       = knightCollide.autoTiling;
            gkCollide.edgeRadius       = knightCollide.edgeRadius;
            gkCollide.offset           = new Vector2(knightCollide.offset.x, knightCollide.offset.y + 1.2f);
            gkCollide.isTrigger        = true;
            GhostImage                 = GhostKnight.GetComponent <Texture2D>();
            GhostSprite                = GhostKnight.GetComponent <SpriteRenderer>();
            GhostSprite.sprite         = Sprite.Create(textures.WarpSprites[0], new Rect(0, 0, 512, 512), new Vector2(0.5f, 0.5f), 400);
            GhostSprite.color          = Color.clear;
            GhostPhysics               = GhostKnight.GetComponent <Rigidbody2D>();
            GhostPhysics.drag          = 0;
            GhostPhysics.gravityScale  = 0f;
            GhostPhysics.simulated     = true;
            GhostPhysics.isKinematic   = true;
            GhostPhysics.interpolation = RigidbodyInterpolation2D.Interpolate;

            CeilingDetectionObject = new GameObject("CeilingDetect", typeof(Rigidbody2D), typeof(SpriteRenderer), typeof(BoxCollider2D), typeof(ceilingdetect));
            CeilingDetectionObject.transform.parent        = KnightGameObject.transform;
            CeilingDetectionObject.transform.localPosition = new Vector3(0, 1.5f, 0);
            _ceilingdetect = CeilingDetectionObject.GetComponent <ceilingdetect>();
            BoxCollider2D cdCollider2D = CeilingDetectionObject.GetComponent <BoxCollider2D>();

            cdCollider2D.size = new Vector2(1f, 3f);
            Bounds bounds = cdCollider2D.bounds;

            bounds.center          = CeilingDetectionObject.transform.position;
            cdCollider2D.isTrigger = true;
            Rigidbody2D cdFakePhysics = CeilingDetectionObject.GetComponent <Rigidbody2D>();

            cdFakePhysics.isKinematic = true;

            // Basically replaces the "CheckCollisionSide" FSM action
            FloorDetectionObject = new GameObject("FloorDetect", typeof(Rigidbody2D), typeof(SpriteRenderer), typeof(BoxCollider2D), typeof(ceilingdetect), typeof(DebugColliders));
            FloorDetectionObject.transform.parent = KnightGameObject.transform;
            FloorDetectionObject.GetComponent <DebugColliders>().zDepth = 0f;
            FloorDetectionObject.layer = 0;
            // CheckCollisionSide detects from this distance
            FloorDetectionObject.transform.localPosition = new Vector3(0f, -0.7f, 0);
            _floordetect = FloorDetectionObject.GetComponent <ceilingdetect>();
            BoxCollider2D fCollider2D = FloorDetectionObject.GetComponent <BoxCollider2D>();

            fCollider2D.size = new Vector2(0.5f, 1.4f);
            Bounds fbounds = fCollider2D.bounds;

            fbounds.center        = FloorDetectionObject.transform.position;
            fCollider2D.isTrigger = true;
            Rigidbody2D fFakePhysics = FloorDetectionObject.GetComponent <Rigidbody2D>();

            fFakePhysics.isKinematic = true;

            KnightLaserObject = new GameObject("LaserGenerator", typeof(laserControl), typeof(LineRenderer));
            KnightLaserObject.transform.position = KnightGameObject.transform.position;
            KnightLaserObject.transform.parent   = KnightGameObject.transform;
            KnightLaser    = KnightLaserObject.GetComponent <laserControl>();
            KnightLaser.lr = KnightLaserObject.GetComponent <LineRenderer>();

            GhostKnight.layer = 0;
            DontDestroyOnLoad(KnightLaserObject);
            DontDestroyOnLoad(GhostKnight);
            DontDestroyOnLoad(CeilingDetectionObject);
            DontDestroyOnLoad(FloorDetectionObject);
            Modding.Logger.LogDebug("Found Spell control and nail art control FSMs");
            //CameraController = GameObject.Find("CameraParent");
            Modding.ReflectionHelper.CacheFields <CameraTarget>();
            ReflectionHelper.CacheFields <HeroController>();
        }