Ejemplo n.º 1
0
    public override void Generate()
    {
        // Grabs Ship information
        int   id         = gameObject.transform.parent.GetComponent <Ship>().GetID();
        int   Size       = gameObject.transform.parent.GetComponent <Ship>().GetSize();
        float ShipHeight = 0;

        GenerateColor();
        for (int index = 0; index < Size; index++)
        {
            // Add gameobject and sprite component
            GameObject temp = new GameObject();
            temp.name             = index.ToString();
            temp.transform.parent = gameObject.transform;
            temp.AddComponent <tk2dSprite>();
            tk2dSprite tempSprite = temp.GetComponent <tk2dSprite>();

            // Find Suitable ID
            id = Utility.Wrap <int>(id, 0, collection.spriteCollection.spriteDefinitions.Length - 1);
            while (collection.spriteCollection.spriteDefinitions[id].name == "")
            {
                id += (int)Random.Range(0, 4);
                id  = Utility.Wrap <int>(id, 0, collection.spriteCollection.Count - 1);
            }

            // Create Sprite
            tempSprite.SwitchCollectionAndSprite(collection.spriteCollection, id);
            tempSprite.Build();


            // Choose Location to position new Sprite
            // Based on the progress of the height of the ship, place a
            // sprite just above the previously placed midsection sprite.
            float randomNumber = 0;
            float heightSpace  = 0;
            if (ShipHeight != 0)
            {
                heightSpace  = ShipHeight + tempSprite.GetBounds().size.y;
                randomNumber = Random.Range(heightSpace - heightSpace / 5, heightSpace - heightSpace / 9);
                ShipHeight  += randomNumber - ShipHeight;
            }
            else
            {
                ShipHeight  += tempSprite.GetBounds().size.y;
                randomNumber = Random.Range(ShipHeight / 5, Mathf.Abs(ShipHeight - ShipHeight / 9));

                temp.transform.localPosition = new Vector3(0, .1f, .025f + index * .025f);
                id += (int)Random.Range(0, 4);
                temp.renderer.material.SetColor("_Color", color);
                continue;
            }
            temp.transform.localPosition += new Vector3(0, randomNumber, .025f + index * .025f);
            id += (int)Random.Range(0, 4);
            temp.renderer.material.SetColor("_Color", color);
        }
        DuplicateToOtherHalf();
    }
Ejemplo n.º 2
0
	public void Initialize(float screenWidth, float screenHeight, float ratio){
		//float nativeResolutionX = cam.nativeResolutionWidth; 
		//float nativeResolutionY = cam.nativeResolutionHeight; 
		//float ratio = cam.CameraSettings.orthographicPixelsPerMeter;
		
		//enabled = true;
		float lenthUnit = 1 / ratio;
		//transform.localScale = new Vector3(lenthUnit * nativeResolutionX, 
		//	lenthUnit * nativeResolutionY, 1);
		//screenSize = new Vector2(screenWidth, screenHeight);
		white = transform.GetComponent<tk2dSprite>();
		white.scale = new Vector3(lenthUnit * screenWidth / white.GetBounds().size.x, 
			lenthUnit * screenHeight / white.GetBounds().size.y, 1);
	}
Ejemplo n.º 3
0
    void AlignToCamera()
    {
        // Align score
        tmpPos   = score.transform.localPosition;
        tmpPos.y = -Camera.main.orthographicSize;
        tmpPos.x = -(Camera.main.aspect * Camera.main.orthographicSize);
        score.transform.localPosition = tmpPos;

        // Align score label
        tmpPos   = ScoreLabel.transform.localPosition;
        tmpPos.y = score.transform.localPosition.y + (score.GetEstimatedMeshBoundsForString(score.text).size.y * 1.1f);
        tmpPos.x = score.transform.localPosition.x;
        ScoreLabel.transform.localPosition = tmpPos;

        // Align bonus
        tmpPos   = Bonus.transform.localPosition;
        tmpPos.y = ScoreLabel.transform.localPosition.y + ScoreLabel.GetBounds().size.y;
        tmpPos.x = score.transform.localPosition.x;
        Bonus.transform.localPosition = tmpPos;

        // Align bonus label
        tmpPos   = BonusLabel.transform.localPosition;
        tmpPos.y = Bonus.transform.localPosition.y + (Bonus.GetEstimatedMeshBoundsForString(Bonus.text).size.y * 1.1f);
        tmpPos.x = score.transform.localPosition.x;
        BonusLabel.transform.localPosition = tmpPos;

        lastAspect = Camera.main.aspect;
    }
Ejemplo n.º 4
0
    private void Update()
    {
        var bounds = sprite.GetBounds();

        colider.size   = bounds.size;
        colider.offset = new Vector2(bounds.center.x, bounds.center.y);
    }
Ejemplo n.º 5
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (tkAnimator.CurrentFrame == 2 && !FunctionLock)
     {
         FunctionLock = true;
         var        bounds  = weaponSprite.GetBounds();
         Collider2D colider =
             Physics2D.OverlapBox(bounds.center + weaponTrans.position, bounds.size, 0, 1 << LayerMask.NameToLayer("Player"));
         if (colider != null)
         {
             if (Mathf.Abs(monsterTrans.position.y - PlayerContorller.Instance.transform.position.y) <= 20)
             {
                 //怪物在角色右边,给向左的击打,速度方向为负
                 if (monsterTrans.position.x >= PlayerContorller.Instance.transform.position.x)
                 {
                     PlayerContorller.Instance.StartCoroutine(PlayerContorller.Instance.GetHitMove(-50, 0.3f));
                     PlayerContorller.Instance.ShowHitEffect("击打");
                 }
                 else
                 {
                     PlayerContorller.Instance.StartCoroutine(PlayerContorller.Instance.GetHitMove(50, 0.3f));
                     PlayerContorller.Instance.ShowHitEffect("击打");
                 }
                 PlayerContorller.Instance.TakeDamage(monsterStateInfo.PhysicalAttack, monsterStateInfo.MagicAttack);
             }
         }
     }
 }
Ejemplo n.º 6
0
    private GameObject CreateButton(string name, string img, Entity.Type type, Vector2 offset)
    {
        GameObject ret = new GameObject();

        ret.name                    = name;
        ret.transform.parent        = this.transform;
        ret.transform.localPosition = offset;
        ret.SetActive(false);

        tk2dSprite sprite = ret.AddComponent <tk2dSprite>();

        sprite.SetSprite(GetComponent <tk2dSprite>().Collection, m_theme + img);

        BoxCollider2D box = ret.AddComponent <BoxCollider2D>();

        box.size      = sprite.GetBounds().size;
        box.isTrigger = true;

        UIUnit unit = ret.AddComponent <UIUnit>();

        unit.m_buySound = m_buySound;
        unit.type       = type;
        unit.fab        = this;
        return(ret);
    }
Ejemplo n.º 7
0
	public void Initialize(){
		if(cam == null){	
			Debug.Log("cam is null");
			return;
		}
		
		float nativeResolutionX = cam.nativeResolutionWidth; 
		float nativeResolutionY = cam.nativeResolutionHeight; 
		float ratio = cam.CameraSettings.orthographicPixelsPerMeter;
		//Debug.Log(nativeResolutionX);
		sprite = GetComponent<tk2dSprite>();
		float lenthUnit = 1 / ratio;
		transform.localScale = new Vector3(lenthUnit * nativeResolutionX / sprite.GetBounds().size.x, 
			lenthUnit * nativeResolutionY / sprite.GetBounds().size.y, 1);
		//m_material = gameObject.renderer.material;
		//Color color = m_material.GetColor("_Color");
		//Debug.Log(color);
		//color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
		//m_material.SetColor("_Color", color);
	}
Ejemplo n.º 8
0
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        time += Time.deltaTime;
        if (time >= DelayTime)
        {
            if (Input.GetButtonDown("Attack"))
            {
                animator.SetTrigger("AttackLink");
            }
        }

        if (tkAnimator.CurrentFrame == 2 && !FunctionLock)
        {
            FunctionLock = true;
            var          bounds   = weaponSprite.GetBounds();
            Collider2D[] coliders =
                Physics2D.OverlapBoxAll(bounds.center + weaponTrans.position, bounds.size, 0, 1 << LayerMask.NameToLayer("Monster"));
            if (coliders.Length != 0)
            {
                foreach (var colider in coliders)
                {
                    var monster = (ITakeDamage)colider.gameObject.GetComponent(typeof(ITakeDamage));
                    if (monster == null)
                    {
                        continue;
                    }
                    else if (!monster.InAttackArea())
                    {
                        continue;
                    }
                    else if (monster.IsDie())
                    {
                        continue;
                    }
                    else
                    {
                        if (!monster.IsLying())
                        {
                            if (monster.TakeDamage("小砍2") && !monster.IsFlying())
                            {
                                monster.HitFly(10, 40);
                            }
                            else
                            {
                                monster.HitBack(50, 0.17f);
                            }
                        }
                        monster.ShowHitEffect("小砍2");
                    }
                }
            }
        }
    }
Ejemplo n.º 9
0
	public void Initialize(float screenWidth, float screenHeight, float ratio){
		if(!isInit){
			isInit = true;
		}
		isEndBeginAni = false;
		enabled = true;
		sprite = transform.GetChild(0).GetComponent<tk2dSprite>();//GetComponent<tk2dSprite>();
		textMesh = transform.GetChild(1).GetComponent<tk2dTextMesh>();
		xLenth = (1 / ratio) * screenWidth / 2 + sprite.GetBounds().size.x;
		//if(callbackPtr != null)
		//	endAniCallBack = callbackPtr;
	}
Ejemplo n.º 10
0
    // ------------------------------------------------------------------------------------------------------------------------------------------
    // MEMBER CONSTANTS
    // ------------------------------------------------------------------------------------------------------------------------------------------

    // ------------------------------------------------------------------------------------------------------------------------------------------
    // MEMBER VARIABLES
    // ------------------------------------------------------------------------------------------------------------------------------------------

    // ------------------------------------------------------------------------------------------------------------------------------------------
    // MEMBER METHODS
    // ------------------------------------------------------------------------------------------------------------------------------------------

    // ------------------------------------------------------------------------------------------------------------------------------------------
    // Use this for initialization
    // ------------------------------------------------------------------------------------------------------------------------------------------
    void Start()
    {
        // resize background central bar to fit the screen width
        Vector3 barSize    = m_centralBar.transform.localScale;
        float   barWidth   = m_centralBar.GetBounds().size.x;
        Camera  cam        = Camera.main;
        float   worldWidth = (Screen.width * 2.0f * cam.orthographicSize) / Screen.height;
        float   dBarW      = worldWidth - (2.0f * m_borderBar.GetBounds().size.x);

        barSize.x          = dBarW / barWidth;
        m_centralBar.scale = barSize;
    }
Ejemplo n.º 11
0
    // ------------------------------------------------------------------------------------------------------------------------------------------
    // MEMBER METHODS
    // ------------------------------------------------------------------------------------------------------------------------------------------


    // ------------------------------------------------------------------------------------------------------------------------------------------
    // Use this for initialization After Awake
    // ------------------------------------------------------------------------------------------------------------------------------------------
    void Start()
    {
        // resize the current Sprite to fit with the  width of the screen
        localSprite = GetComponent <tk2dSprite>();
        Vector3 spriteScale = localSprite.scale;
        float   spriteWidth = localSprite.GetBounds().size.x;
        Camera  cam         = Camera.main;
        float   worldWidth  = (Screen.width * 2.0f * cam.orthographicSize) / Screen.height;

        //New Calculated spriteScale from camera resize * number of times should be multiplied
        spriteScale.x     = spriteScale.x * (worldWidth / spriteWidth);
        localSprite.scale = spriteScale;
    }
Ejemplo n.º 12
0
    private void UpdatePartSprite()
    {
        for (int i = 0; i < m_lstPartSprite.Count; i++)
        {
            m_lstPartSprite[i].SetSprite(m_tk2dSpriteAnimator.CurrentSpriteId);

            m_lstPartSprite[i].SortingOrder = 600 - (int)m_owner.Transform.position.y + m_lstPartSprite[i].SortingLevel;

            var    bounds    = m_weaponSprite.GetBounds();
            Bounds newbounds = new Bounds(bounds.center + m_owner.Transform.position, bounds.extents * 4);
            m_owner.m_attackBounds = newbounds;
        }
    }
Ejemplo n.º 13
0
    void GrabbingUpdate(bool isMotion, bool isRetract)
    {
        mGrabCurDelay += Time.deltaTime;

        Vector3 neckPos = neck.position;

        Vector2 dir = (isRetract || mGrabTarget == null ? mGrabDest : mGrabTarget.position) - neckPos;
        float   len = dir.magnitude;

        dir /= len;

        len -= grabLenOfs;

        bool done = mGrabCurDelay >= grabDelay || !isMotion;

        float curLen;

        if (isRetract)
        {
            curLen = done ? 0.0f : Ease.Out(mGrabCurDelay, grabDelay, len, -len);
        }
        else
        {
            curLen = done ? len : Ease.In(mGrabCurDelay, grabDelay, 0.0f, len);
        }

        OrientHead(dir, false);

        Vector3 headPos    = head.position;
        Vector2 newHeadPos = neckPos;

        newHeadPos   += dir * curLen;
        head.position = new Vector3(newHeadPos.x, newHeadPos.y, headPos.z);

        //orient neck to head
        neck.rotation = head.rotation;

        //properly scale neck
        mNeckSprite.scale = Vector3.one;
        Bounds  neckBounds   = mNeckSprite.GetBounds();
        Vector3 newNeckScale = Vector3.one;

        newNeckScale.y    = curLen / neckBounds.size.y;
        mNeckSprite.scale = newNeckScale;

        if (isMotion && done)
        {
            SwitchState(isRetract ? State.Retracted : State.Grabbed);
        }
    }
Ejemplo n.º 14
0
    void Start()
    {
        m_renderer          = gameObject.AddComponent <LineRenderer>();
        m_renderer.material = Resources.Load("Line") as Material;

        tk2dSprite sprite = gameObject.GetComponent <tk2dSprite>();

        m_maxLength = sprite.GetBounds().extents.x * 2;

        m_renderer.SetPosition(0, gameObject.transform.position + new Vector3(-m_maxLength / 2, -10, 0));
        m_renderer.SetPosition(1, gameObject.transform.position + new Vector3(m_maxLength / 2, -10, 0));

        m_renderer.startWidth = 2;
        m_renderer.endWidth   = 2;
    }
Ejemplo n.º 15
0
    void Start()
    {
        // Position
        sprite = GetComponent <tk2dSprite>();
        bounds = sprite.GetBounds();

        transform.Translate(
            (-Camera.main.aspect * Camera.main.orthographicSize) + 0.1f,
            Camera.main.orthographicSize - 0.1f,
            0
            );

        // Begin tracking
        CurrentRound = SixthsGameState.Round;
    }
Ejemplo n.º 16
0
    // ------------------------------------------------------------------------------------------------------------------------------------------
    // MEMBER METHODS
    // ------------------------------------------------------------------------------------------------------------------------------------------

    // ------------------------------------------------------------------------------------------------------------------------------------------
    // Use this for initialization Before Start
    // ------------------------------------------------------------------------------------------------------------------------------------------
    void Awake()
    {
        Camera cam = Camera.main;

        //Getting the aspect ratio - if is smaller than our 960x640 calculate how much has to be scale to fit with the actual screen
        localSprite = GetComponent <tk2dSprite>();
        float targetWidth = Global.k_baseAspect * Screen.height;

        if (Screen.width < targetWidth)
        {
            //calculate how many times we have to scale our image to fit to the aspect ratio of the camera
            float finalScale = cam.orthographicSize * 2 / localSprite.GetBounds().size.y;
            localSprite.scale = new Vector3(finalScale, finalScale, localSprite.transform.localScale.z);
        }
    }
Ejemplo n.º 17
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (tkAnimator.CurrentFrame == 3 && !FunctionLock)
     {
         FunctionLock = true;
         var          bounds   = weaponSprite.GetBounds();
         Collider2D[] coliders =
             Physics2D.OverlapBoxAll(bounds.center + weaponTrans.position, bounds.size, 0);
         if (coliders.Length != 0)
         {
             foreach (var colider in coliders)
             {
                 var monster = (ITakeDamage)colider.gameObject.GetComponent(typeof(ITakeDamage));
                 if (monster == null)
                 {
                     continue;
                 }
                 else if (!monster.InAttackArea())
                 {
                     continue;
                 }
                 else if (monster.IsDie())
                 {
                     continue;
                 }
                 else
                 {
                     if (!monster.IsFlying())
                     {
                         if (!monster.IsLying())
                         {
                             monster.HitFly(10, 40);
                         }
                         else
                         {
                             monster.HitFly(9, 40);
                         }
                     }
                     //damage.HitBack(65, 0.4f);
                     monster.ShowHitEffect("小砍3");
                     monster.TakeDamage("小砍3");
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
    public void Update()
    {
        m_tk2DSprite.SortingOrder = 600 - (int)m_effectObj.transform.position.y + 4;

        if (Time.time - m_createTimeSave >= m_delayShowTimeDelta)
        {
            m_effectObj.SetActive(true);
            m_rig2d.velocity = m_velocity;

            //检测碰撞
            if (m_bCanHit)
            {
                var coliders = Physics2D.OverlapBoxAll(m_tk2DSprite.GetBounds().center + m_effectObj.transform.position, m_tk2DSprite.GetBounds().extents, 0);
                for (int i = 0; i < coliders.Length; i++)
                {
                    int transId = coliders[i].transform.parent.parent.GetInstanceID();

                    Actor actor;
                    CharacterManager.Instance.m_dicActors.TryGetValue(transId, out actor);
                    if (actor != null && actor is Hero == false)
                    {
                        actor.BeHit(m_owner);
                        m_bCanHit = false;
                        //m_hitCount++;
                        if (m_skillEffectData.AutoDestory == 1)
                        {
                            m_effectObj.SetActive(false);
                        }
                    }
                }
            }
        }

        if (m_skillEffectData.LifeTime != 0 && m_showTimeSave != -1 && Time.time - m_showTimeSave > m_skillEffectData.LifeTime)
        {
            m_effectObj.SetActive(false);
        }
    }
Ejemplo n.º 19
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     time += Time.deltaTime;
     if (time >= DelayTime)
     {
         if (Input.GetButtonDown("Attack"))
         {
             animator.SetTrigger("AttackLink");
         }
     }
     if (tkAnimator.CurrentFrame == 2 && !FunctionLock)
     {
         FunctionLock = true;
         var bounds = weaponSprite.GetBounds();
         //获得所有击中的怪物列表,排除掉Y轴不适合的
         Collider2D[] coliders =
             Physics2D.OverlapBoxAll(bounds.center + weaponTrans.position, bounds.size, 0, 1 << LayerMask.NameToLayer("Monster"));
         if (coliders.Length != 0)
         {
             foreach (var colider in coliders)
             {
                 var monster = (ITakeDamage)colider.gameObject.GetComponent(typeof(ITakeDamage));
                 if (monster == null)
                 {
                     continue;
                 }
                 else if (!monster.InAttackArea())
                 {
                     continue;
                 }
                 else if (monster.IsDie())
                 {
                     continue;
                 }
                 else
                 {
                     if (monster.IsLying())
                     {
                         //躺着挨打
                         monster.TakeDamage("小砍1");
                     }
                     else if (monster.IsFlying())
                     {
                         //在空中挨打
                         monster.SetFlySpeed(5);
                         monster.TakeDamage("小砍1");
                     }
                     else
                     {
                         //这一击是否会导致怪物死亡
                         if (monster.TakeDamage("小砍1"))
                         {
                             int r = Random.Range(1, 4);
                             if (r == 1)
                             {
                                 monster.ExecuteDie();
                             }
                             else
                             {
                                 monster.HitFly(2, 10);
                             }
                         }
                         else
                         {
                             //击退
                             monster.HitBack(55, 0.22f);
                         }
                     }
                     monster.ShowHitEffect("小砍1");
                 }
             }
         }
     }
 }
Ejemplo n.º 20
0
    // ------------------------------------------------------------------------------------------------------------------------------------------
    // FallDownAsteroids: Move the asteroids down with different speed
    // ------------------------------------------------------------------------------------------------------------------------------------------
    public void FallDownAsteroids()
    {
        //Move Down the Asteroids with the velocity of each class
        transform.Translate(Vector3.down * Time.deltaTime * m_velocity);
        // Loss a live and Destroy the Asteroid if the user has not destroyed before arriving to London :)
        float posToDestroy = Camera.main.transform.localPosition.y - Camera.main.orthographicSize - m_sprite.GetBounds().size.y;

        if (transform.localPosition.y < posToDestroy)
        {
            //We have missed to destroy the Asteroid so we have loss a live!
            AsteroidsMgr.Instance.DeleteOneAsteroidFromList(gameObject);

            //Create a new Asteroid to make it Funnier
            AsteroidsMgr.Instance.CreateRandomAsteroid();

            //loss a live
            if (AsteroidsRainMng.Instance)
            {
                AsteroidsRainMng.Instance.LossALive();
            }
        }
    }
Ejemplo n.º 21
0
	public void Initialize(float screenWidth, float screenHeight, float ratio){
		sprite = transform.GetChild(0).GetComponent<tk2dSprite>();//GetComponent<tk2dSprite>();
		textMesh = transform.GetChild(1).GetComponent<tk2dTextMesh>();
		xLenth = (1 / ratio) * screenWidth / 2 + sprite.GetBounds().size.x;
		enabled = true;
	}
Ejemplo n.º 22
0
    public void create(int scrollType, float scrollSpeed, Transform parent, string spriteName, float depth, bool useOverLayer = false)
    {
        _scrollSpeed = scrollSpeed;

        // 첫번째 이미지를 가져온다...
        GameObject gobj = new GameObject("background");

        gobj.transform.parent = parent;        //

        tk2dSprite spr = gobj.AddComponent <tk2dSprite>();
        tk2dSpriteCollectionData scd = GameManager.resourceManager.getSpriteCollection(spriteName);

        spr.SetSprite(scd, scd.FirstValidDefinitionIndex);
        spr.renderer.material = scd.FirstValidDefinition.material;
        spr.Build();

        _scrollType = scrollType;

        _width  = spr.GetBounds().extents.x *2.0f;
        _height = spr.GetBounds().extents.y *2.0f;

        _needNum = Mathf.RoundToInt((GameManager.me.tk2dGameCamera.targetResolution.y) / _height) + 2;

        _indexNum = new int[_needNum];

        _sprites    = new tk2dSprite[_needNum];
        _transforms = new Transform[_needNum];

        _vectors = new Vector3[_needNum];

        _tempNum = new int[_needNum];

        int i = 0;

        for (i = 0; i < _needNum; ++i)
        {
            _vectors[i] = Vector3.zero;

            if (i == 0)
            {
                _sprites[i] = spr;
            }
            else
            {
                GameObject tempGobj = new GameObject("background");
                tempGobj.transform.parent = parent;                //

                _sprites[i] = tempGobj.AddComponent <tk2dSprite>();
                tk2dSpriteCollectionData tScd = GameManager.resourceManager.getSpriteCollection(spriteName);
                _sprites[i].SetSprite(tScd, tScd.GetSpriteIdByName(spriteName));
                _sprites[i].renderer.material = tScd.FirstValidDefinition.material;
                _sprites[i].Build();
            }

            _indexNum[i]   = i;
            _transforms[i] = _sprites[i].transform;
        }

        _vectors[0]   = _transforms[0].position;
        _vectors[0].x = GameManager.me.tk2dGameCamera.targetResolution.x / 2.0f;
        _vectors[0].y = GameManager.me.tk2dGameCamera.targetResolution.y / 2.0f;
        _vectors[0].z = depth;

        for (i = 0; i < _needNum; ++i)
        {
            _transforms[i].position = _vectors[0];
        }

        _hasOverLayer = useOverLayer;
        if (useOverLayer)
        {
            createOverLayer(spriteName);
        }
        //createOverLayer(spriteName);

        resetPosition();
    }
Ejemplo n.º 23
0
        private IEnumerator HandlePopup()
        {
            float   elapsed     = 0f;
            Vector2 startOffset = Vector2.zero;

            if (specRigidbody)
            {
                startOffset = (m_cachedPosition + m_CachedPositionOffset + new Vector2(m_ParachuteSprite.GetBounds().size.x / 2, 0));
            }
            else if (UseObjectSizeOverride)
            {
                startOffset = (m_cachedPosition + m_CachedPositionOffset + new Vector2(OverrideObjectSize.x, 0));
            }
            else
            {
                startOffset = (m_cachedPosition + m_CachedPositionOffset + new Vector2(sprite.GetBounds().size.x / 2, 0));
            }
            Vector2 HeighestPointPosition = (startOffset + new Vector2(DropHeightHorizontalOffset, PopUpHeight));
            int     cachedLayer           = gameObject.layer;
            int     cachedOutlineLayer    = cachedLayer;

            while (elapsed < PopupSpeed)
            {
                elapsed += BraveTime.DeltaTime;
                if (!StartsIntheAir)
                {
                    m_Anchor.position = Vector2.Lerp(startOffset, HeighestPointPosition, (elapsed / PopupSpeed));
                }
                SetObjectScale(Vector2.Lerp(new Vector2(m_startScale, m_startScale), m_cachedScale, (elapsed / PopupSpeed)));
                yield return(null);
            }
            gameObject.layer = cachedLayer;
            SpriteOutlineManager.ChangeOutlineLayer(sprite, cachedOutlineLayer);
            switchState = State.ParaDrop;
            yield break;
        }
Ejemplo n.º 24
0
        private void Start()
        {
            // Delay initial configuration for ItemCrate version to avoid possible misalignment since GameObjects get instantiated initially from zero position.
            // Item crate object comes with this controller pre-attached. So position may not be correct frame 1. ;)
            if (!Configured && IsItemCrate)
            {
                StartCoroutine(DelayedAutoConfiguration());
                return;
            }
            m_ParentEnemy        = aiActor;
            m_CachedRotation     = transform.rotation;
            m_cachedPosition     = transform.position;
            m_CachedLayer        = gameObject.layer;
            m_CachedSpriteZDepth = sprite.HeightOffGround;
            m_maxSway            = MaxSwayAngle;

            if (knockbackDoer)
            {
                knockbackDoer.SetImmobile(true, "Paradrop Protection");
            }

            if (m_ParentEnemy)
            {
                m_cachedScale = m_ParentEnemy.EnemyScale;
            }
            else
            {
                m_cachedScale = Vector2.one;
            }

            if (m_ParentEnemy && m_ParentEnemy.HasShadow && m_ParentEnemy.ShadowObject)
            {
                m_ParentEnemy.ShadowObject.GetComponent <tk2dSprite>().renderer.enabled = false;
            }

            if (m_ParentEnemy)
            {
                m_ParentEnemy.behaviorSpeculator.enabled = false;
                if (m_ParentEnemy.aiAnimator)
                {
                    m_ParentEnemy.aiAnimator.FacingDirection = -90;
                }
                if (m_ParentEnemy.aiShooter)
                {
                    m_ParentEnemy.aiShooter.AimAtPoint(m_ParentEnemy.CenterPosition - new Vector2(0, 2));
                    m_ParentEnemy.aiShooter.ToggleGunAndHandRenderers(false, "ParaDrop");
                }
            }

            if (specRigidbody && !IsItemCrate)
            {
                specRigidbody.CollideWithOthers = false;
            }
            if (healthHaver)
            {
                healthHaver.PreventAllDamage = true;
                healthHaver.IsVulnerable     = false;
            }

            if (ParentObjectExplodyBarrel && !IsItemCrate)
            {
                m_CachedExplosionData = ExpandUtility.GenerateExplosionData();
            }

            // MeshRenderer pre-disabled via added components in Unity Editor for The Item Drop host object.
            if (!IsItemCrate)
            {
                sprite.renderer.enabled = false;
            }

            m_Parachute = Instantiate(ExpandPrefabs.EX_Parachute, Vector3.zero, Quaternion.identity);
            m_ParachuteSpriteAnimator          = m_Parachute.GetComponent <tk2dSpriteAnimator>();
            m_ParachuteSprite                  = m_Parachute.GetComponent <tk2dSprite>();
            m_ParachuteSprite.renderer.enabled = false;
            if (IsItemCrate)
            {
                m_ParachuteSprite.HeightOffGround += 3f;
                m_ParachuteSprite.UpdateZDepth();
            }


            // Despite my absolute shit math skills I somehow got this right. :P
            // (this correctly sets the parachute above the host object's sprite)
            float ParachuteXSize    = (m_ParachuteSprite.GetBounds().size.x / 2);
            float ObjectUnitCenterX = m_cachedPosition.x;
            float ObjectUnitCenterY = m_cachedPosition.y;

            if (UseObjectSizeOverride)
            {
                ObjectUnitCenterX += OverrideObjectSize.x;
                ObjectUnitCenterY += OverrideObjectSize.y;
            }
            else if (specRigidbody)
            {
                specRigidbody.Reinitialize(); // Make sure rigidbody colliders are at current object's position
                ObjectUnitCenterX = specRigidbody.GetPixelCollider(ColliderType.HitBox).UnitCenter.x;
                ObjectUnitCenterY = specRigidbody.GetPixelCollider(ColliderType.HitBox).UnitTopCenter.y;
            }

            m_Parachute.transform.position = new Vector2((ObjectUnitCenterX - ParachuteXSize), ObjectUnitCenterY);

            m_Parachute.layer = gameObject.layer;

            if (IsItemCrate)
            {
                GameObject EXItemBoxAnchor = new GameObject("EX ItemBox Anchor")
                {
                    layer = gameObject.layer
                };
                EXItemBoxAnchor.transform.position = m_ParachuteSprite.WorldBottomCenter;
                m_ItemBoxAnchor = EXItemBoxAnchor;
                EXItemBoxAnchor.transform.SetParent(m_Parachute.transform);
                gameObject.transform.SetParent(EXItemBoxAnchor.transform);
            }
            else
            {
                gameObject.transform.SetParent(m_Parachute.transform);
            }

            // m_Anchor = Instantiate(ExpandPrefabs.EX_ParadropAnchor, m_ParachuteSprite.WorldBottomCenter, Quaternion.identity).transform;
            m_Anchor = new GameObject("EXParaDropAnchor")
            {
                layer = gameObject.layer
            }.transform;
            m_Anchor.transform.position = m_ParachuteSprite.WorldBottomCenter;
            m_Parachute.transform.SetParent(m_Anchor);

            m_CachedPositionOffset = (m_Anchor.position - m_cachedPosition.ToVector3ZUp());

            switchState   = State.PopIntoAir;
            m_Initialized = true;
        }