Ejemplo n.º 1
0
    public IEnumerator DestroySegmentAFter(float delay)
    {
        //Debug.Log ("startedCoroutine");
        yield return(new WaitForSeconds(delay));

        DestroySegment(UtilityScript.transformToCartesian(transform.position));
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        frameCounter++;
        if (frameCounter % tick == 0)
        {
            if (arrowFlying)
            {
                vel = myRbd.velocity;
                this.transform.rotation = Quaternion.Euler(new Vector3(0, 0, Mathf.Atan2(vel.y, vel.x) * Mathf.Rad2Deg));
                RaycastHit2D hit = Physics2D.Raycast(arrowHead.position, vel.normalized, ArrowCheckDistance, checkLayers);

                if (hit.collider != null)
                {
                    FreezeArrow();
                    Debug.Log("ARROW HIT :" + hit.transform.gameObject.name);
                    if (hit.collider.gameObject.tag == "WalkerUnit")
                    {
                        IDamagableInterface target = UtilityScript.RecursevlyLookForInterface(hit.transform);
                        //GenericTrackWalker walkerScript = RecursevlyLookForScriptInParents(hit.collider.gameObject.transform);
                        this.transform.SetParent(hit.transform);

                        if (target != null)
                        {
                            target.ArrowHit(arrowDamage, hit.collider);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
    List <Vector2> GetWalkingPointsFromSprite(Sprite _sprite)
    {
        List <Vector2> wPoints = new List <Vector2>();
        Vector3        max     = _sprite.bounds.max;
        Vector3        min     = _sprite.bounds.min;

        Vector2[] vertices = _sprite.vertices;

        for (int j = 0; j < vertices.Length; j++)
        {
            vertices[j] = new Vector2(vertices[j].x * spriteScale.x, vertices[j].y * spriteScale.y);
            Debug.Log("Sprite position in for loop " + spritePosition);
            vertices[j] = vertices[j] + UtilityScript.V3toV2(spritePosition);
            //   Debug.Log("New vertex prev pos: " + vertices[j] + "; added vector : " + UtilityScript.V3toV2(spritePosition) + " new position: " + vertices[j] + UtilityScript.V3toV2(spritePosition));
        }
        Dictionary <float, float> points = new Dictionary <float, float>();

        foreach (Vector2 v in vertices)
        {
            if (points.ContainsKey(v.x))
            {
                if (points[v.x] < v.y)
                {
                    points[v.x] = v.y;
                }
            }
            else
            {
                // Debug.Log(_sprite.bounds.min);
                if (v.y != min.y)
                {
                    bool tooClose = false;
                    foreach (KeyValuePair <float, float> kvp in points)
                    {
                        if (Mathf.Abs(kvp.Key - v.x) < minXDiff)
                        {
                            tooClose = true;
                        }
                    }
                    if (!tooClose)
                    {
                        points.Add(v.x, v.y);
                    }
                }
            }
        }
        foreach (KeyValuePair <float, float> kvp in points)
        {
            wPoints.Add(new Vector2(kvp.Key, kvp.Value));
        }
        if (side == EnemyWalkingTrackSide.Left)
        {
            wPoints = wPoints.OrderBy(v => v.x).ToList();
        }
        else
        {
            wPoints = wPoints.OrderByDescending(v => v.x).ToList();
        }
        return(wPoints);
    }
Ejemplo n.º 4
0
    void Utility(GameObject tile)
    {
        UtilityScript script = tile.gameObject.GetComponent <UtilityScript>() as UtilityScript;

        currentSpace = script.space;
        if (currentSpace == targetSpace)
        {
            if (script.owned)
            {
                if (!script.mortgaged && script.ownerNo != playerNo)
                {
                    int cost = script.multiplier[script.UtilitiesOwned() - 1] * (gameObject.transform.parent.gameObject.GetComponent <PlayerControllerScript>().dice1 + gameObject.transform.parent.gameObject.GetComponent <PlayerControllerScript>().dice2);
                    gameObject.transform.Find("Player UI").gameObject.transform.Find("Pay Rent").gameObject.SetActive(true);
                    gameObject.transform.Find("Player UI").gameObject.transform.Find("Pay Rent").gameObject.GetComponent <PayRentScript>().Setup(script.ownerNo, cost);
                }
                else
                {
                    MoveDone();
                }
            }
            else
            {
                gameObject.transform.Find("Player UI").gameObject.transform.Find("Property Available").gameObject.SetActive(true);
                gameObject.transform.Find("Player UI").gameObject.transform.Find("Property Available").gameObject.transform.Find("Buy").gameObject.GetComponent <BuyScript>().Setup(tile);
            }
        }
    }
Ejemplo n.º 5
0
	// Use this for initialization
	void Start () 
	{
		instance = this;
		_camPos = _cam.transform;
		_originalPos = _camPos.localPosition;
		shakeAmt = 2f;
	
	}
Ejemplo n.º 6
0
    void MakeBumpEffect(Vector2 cPoint)
    {
        SoundManager.play_crash();
        CamShakeManager.PlayShake(0.2f, 0.2f);
        Vector3    spawnPos  = UtilityScript.transformToCartesian(new Vector3(cPoint.x, cPoint.y, 0.0f));
        GameObject bumpMaker = Instantiate(bumpEffect, spawnPos, Quaternion.identity) as GameObject;

        bumpMaker.transform.SetParent(meshTransform);
    }
 // Use this for initialization
 void OnTriggerEnter2D(Collider2D other)
 {
     Debug.Log("On trigger EnTER HEART");
     if ((UnitSpawnManager.instance.enemyLayerMask.value & (1 << other.gameObject.layer)) > 0)
     {
         Debug.Log("Enemy Got To heart");
         GenericTrackWalker walkerScript = UtilityScript.RecursevlyLookForWalkerClass(other.transform);
         walkerScript.Die(true);
         GameController.instance.EnemyReachedHeart();
         // IDamagableInterface unit = UtilityScript.RecursevlyLookForInterface(other.transform);
     }
 }
Ejemplo n.º 8
0
    void SegmentTriggerBehaviour.Enter(Collider2D other, SegmentController segmentController)
    {
        if (other.gameObject.tag == "Shot" || other.gameObject.tag == "PiercingShot" || other.gameObject.tag == "StarPulse")
        {
            Vector3    explodePosition   = UtilityScript.transformToCartesian(other.transform.position);
            GameObject explosionInstance = MonoBehaviour.Instantiate(segmentController.shotFart, explodePosition, Quaternion.identity) as GameObject;

            CamShakeManager.PlayShake(0.1f, 0.5f);
            //SoundManager.PlayExplosionClip();
            // segmentController.mesh.transform.GetChild(0).gameObject.SetActive(false);
            explosionInstance.transform.SetParent(segmentController.mesh.transform);
        }
    }
    private void Update()
    {
        int   rayCount      = 50;
        float angle         = 0f;
        float angleIncrease = fov / rayCount;
        float viewDistance  = 10f;


        Vector3[] vertices  = new Vector3[rayCount + 1 + 1];
        Vector2[] uv        = new Vector2[vertices.Length];
        int[]     triangles = new int[rayCount * 3];

        vertices[0] = origin;

        int vertexIndex   = 1;
        int triangleIndex = 0;

        for (int i = 0; i <= rayCount; i++)
        {
            Vector3      vertex;
            RaycastHit2D raycastHit2D = Physics2D.Raycast(origin, UtilityScript.GetVectorFromAngle(angle), viewDistance, layerMask);
            if (raycastHit2D.collider == null)
            {
                //No hit
                vertex = origin + UtilityScript.GetVectorFromAngle(angle) * viewDistance;
            }
            else
            {
                //Hit object
                vertex = raycastHit2D.point;
            }

            vertices[vertexIndex] = vertex;

            if (i > 0)
            {
                triangles[triangleIndex + 0] = 0;
                triangles[triangleIndex + 1] = vertexIndex - 1;
                triangles[triangleIndex + 2] = vertexIndex;

                triangleIndex += 3;
            }
            vertexIndex++;
            angle -= angleIncrease;
        }

        mesh.vertices  = vertices;
        mesh.uv        = uv;
        mesh.triangles = triangles;
    }
 protected virtual void DoAttack()
 {
     genericWalkerAnimator.SetTrigger("Attack");
     if (hitList != null)
     {
         if (hitList.Length > 0)
         {
             foreach (RaycastHit2D hit in hitList)
             {
                 UtilityScript.RecursevlyLookForInterface(hit.transform).NormalHit(startingDamage, hit.collider);
                 //hit.collider.gameObject.GetComponent<IDamagableInterface>().ReceiveDamage(startingDamage);
             }
         }
     }
     previousAttackTime = Time.time;
 }
 void SegmentTriggerBehaviour.Enter(Collider2D other, SegmentController segmentController)
 {
     if (other.gameObject.tag == "Shot")
     {
         ShotDestroyerScript SDS = other.GetComponent <ShotDestroyerScript> ();
         if (SDS.IsUsed == false)                    //if the shot has not yet hit something, destroy the segment and mark the shot used
         {
             Vector3 spawnPos = UtilityScript.transformToCartesian(other.transform.position);
             segmentController.DestroySegment(spawnPos);
             SDS.IsUsed = true;
         }
     }
     else if (other.gameObject.tag == "PiercingShot" || other.gameObject.tag == "StarPulse")
     {
         Vector3 spawnPos = UtilityScript.transformToCartesian(other.transform.position);
         segmentController.DestroySegment(spawnPos);
     }
 }
Ejemplo n.º 12
0
    void InstantiateAndInitUnit(WalkerScriptableObject _walker)
    {
        GameObject         enemyInstance;
        GenericTrackWalker gtwScript;

        if (_walker.type == WalkerType.Enemy)
        {
            enemyInstance = Instantiate(_walker.Prefab, UtilityScript.V2toV3(trackLeft.walkingPoints[0]), Quaternion.identity) as GameObject;
            gtwScript     = enemyInstance.GetComponent <GenericTrackWalker>();
            gtwScript.InitGenericWalker(_walker.startingHealth, _walker.startingDamage, _walker.startingSpeed, _walker.startingAttackSpeed, _walker.type, trackLeft, friendlyLayerMask);
        }
        else
        {
            enemyInstance = Instantiate(_walker.Prefab, UtilityScript.V2toV3(trackLeft.walkingPoints[trackLeft.Points - 1]), Quaternion.identity) as GameObject;
            gtwScript     = enemyInstance.GetComponent <GenericTrackWalker>();
            gtwScript.InitGenericWalker(_walker.startingHealth, _walker.startingDamage, _walker.startingSpeed, _walker.startingAttackSpeed, _walker.type, trackLeft, enemyLayerMask);
        }
        gtwScript.StartFollowTrack();
    }
Ejemplo n.º 13
0
    IEnumerator SpawnPlayerAfter(IDictionary <string, string> playerKeys, Vector2 SpawnPos, int playerI, string name, int team)
    {
        Vector3    SpawnPosition = new Vector3(SpawnPos.x, SpawnPos.y, 0);
        GameObject pie           = Instantiate(PhaseInEffect, UtilityScript.transformToCartesian(SpawnPosition), Quaternion.identity) as GameObject;

        pie.transform.SetParent(GameManager.GMInstance.transform);
        yield return(new WaitForSeconds(PhaseInDelay));

        SoundManager.play_spawn();
        GameObject localPlayer = MonoBehaviour.Instantiate(localPlayerPrefabs [(playerI % (localPlayerPrefabs.Length))], SpawnPosition, new Quaternion()) as GameObject;

        localPlayer.transform.SetParent(GameManager.GMInstance.root.transform);
        LivingPlayers.Add(localPlayer);
        //SpriteRenderer PlayerSR = localPlayer.GetComponentInChildren<SpriteRenderer> ();
        //Debug.Log ("GETTING COLOR AT INDEX " + playerI);
        //PlayerSR.color = playerColors[(playerI % (playerColors.Count))];

        LocalPlayerController LCP = localPlayer.GetComponent <LocalPlayerController> ();

        LCP.team        = playerI;
        LCP.playerIndex = playerI;
        LCP.setKeys(playerKeys);
        LCP.PlayerName = name;

        //playerTexts [team].text = LCP.PlayerName + ", ";
        //playerTexts [team].enabled = true;

        cameraLoc.updatePlayers = true;

        if (usePowerUps)
        {
            PUS.spawnPowerups = true;
        }

        if (useEnvironmentEffects)
        {
            EM.enableEnvironmentEffects = true;
        }
    }
Ejemplo n.º 14
0
    private void EasePauseMenu()
    {
        float currentTime = Time.realtimeSinceStartup - m_PauseMenuEase.StartTime;
        float valueChange;

        if (m_PauseMenuEase.IsEasingIn)
        {
            valueChange = -m_PauseMenuEase.StartValue;
        }
        else
        {
            valueChange = 1f - m_PauseMenuEase.StartValue;
        }

        float value;

        // check if done with ease
        if (currentTime > m_PauseMenuEase.Duration)
        {
            // done with ease
            value = m_PauseMenuEase.StartValue + valueChange;
            m_PauseMenuEase.IsFinished = true;
        }
        else
        {
            value = UtilityScript.LinearTween(currentTime, m_PauseMenuEase.StartValue, valueChange, m_PauseMenuEase.Duration);
        }

        // set time to value
        Time.timeScale = value;

        if (value == m_PauseMenuEase.StartValue + valueChange)
        {
            m_PauseMenuEase.IsFinished = true;
        }
    }
Ejemplo n.º 15
0
    IEnumerator MultiSpawnPlayerAfter(Vector3 SpawnPosition, int playerI, LocalPlayerSender LPS)
    {
        GameObject pie = Instantiate(PhaseInEffect, UtilityScript.transformToCartesian(SpawnPosition), Quaternion.identity) as GameObject;

        pie.transform.SetParent(GameManager.GMInstance.root.transform);
        yield return(new WaitForSeconds(PhaseInDelay));

        SoundManager.play_spawn();
        GameObject localPlayer = MonoBehaviour.Instantiate(localPlayerPrefabs [(playerI % (localPlayerPrefabs.Length))], SpawnPosition, new Quaternion()) as GameObject;

        localPlayer.transform.SetParent(GameManager.GMInstance.root.transform);
        LivingPlayers.Add(localPlayer);
        //SpriteRenderer PlayerSR = localPlayer.GetComponentInChildren<SpriteRenderer> ();
        //Debug.Log ("GETTING COLOR AT INDEX " + playerI);
        //PlayerSR.color = playerColors[(playerI % (playerColors.Count))];
        LocalPlayerController LCP = localPlayer.GetComponent <LocalPlayerController> ();

        LCP.PlayerName          = playerNames [playerI % playerNames.Length];
        LPS.myPlayerOnTheServer = LCP;
        LCP.playerIndex         = playerI;

        //playerTexts [playerI].text = LCP.PlayerName + ": " + teamScores [playerI];
        //playerTexts [playerI].enabled = true;

        cameraLoc.updatePlayers = true;

        if (usePowerUps)
        {
            PUS.spawnPowerups = true;
        }

        if (useEnvironmentEffects)
        {
            EM.enableEnvironmentEffects = true;
        }
    }
Ejemplo n.º 16
0
 /// <summary>
 /// This needs to be the first function call in the FixedUpdate of PolarPhysicsObjects!
 /// </summary>
 protected void StartUpdate()
 {
     if (physics != null)           //if this object has physics that moved beyond a whole circle (eg +181 or -181 degrees) it needs to be moved by +-360 degrees
     {
         if (physics.transform.position.x > Mathf.PI * widthMultiplier)
         {
             Vector3 tmp = physics.transform.position;
             tmp.x -= 2 * Mathf.PI * widthMultiplier;
             physics.transform.position = tmp;
         }
         else if (physics.transform.position.x < -Mathf.PI * widthMultiplier)
         {
             Vector3 tmp = physics.transform.position;
             tmp.x += 2 * Mathf.PI * widthMultiplier;
             physics.transform.position = tmp;
         }
     }
     if (rigidbody != null)           //if this object has physics unscale the velocity and scale so you don't need to scale when adding to it
     {
         Vector2 tmpvel = rigidbody.velocity;
         tmpvel -= oldVelocity;
         tmpvel.Scale(new Vector2(oldscale, oldscale));
         oldVelocity += tmpvel;
         oldVelocity.Scale(new Vector2(1f / oldscale, 1f));
         oldVelocity.x = Mathf.Clamp(oldVelocity.x, -maxHorizontalSpeed * widthMultiplier, maxHorizontalSpeed * widthMultiplier);
         oldVelocity.y = Mathf.Clamp(oldVelocity.y, -maxVerticalSpeed, maxVerticalSpeed);
         //if(!UtilityScript.isVector2NanOrInf(oldVelocity))
         rigidbody.velocity = oldVelocity;
         oldscale           = scaleMultiplier / rigidbody.position.y;
     }
     if (physics != null && mesh != null)           //if it has a mesh and physics it synchronizes the positions
     {
         float angle = physics.transform.position.x / widthMultiplier;
         mesh.transform.position = UtilityScript.transformToCartesian(physics.transform.position);
         mesh.transform.rotation = Quaternion.Euler(0, 0, (angle) * 180f / Mathf.PI + 90f);
     }
     for (int i = 0; i < colliders.Length; i++)       //enables the 'modulo' colliders if they need be enabled
     {
         Collider2D col = colliders [i];
         if (!col.enabled)
         {
             continue;
         }
         Bounds  bounds  = col.bounds;
         Vector3 min     = bounds.min;
         Vector3 max     = bounds.max;
         Boolean mincond = min.x <-Mathf.PI *widthMultiplier,
                                  maxcond = max.x> Mathf.PI * widthMultiplier;
         if (mincond || maxcond)
         {
             collidercopies [i].enabled = true;
             Vector2 offset = collidercopies [i].offset;
             if (mincond)
             {
                 offset.x = colliders[i].offset.x + (2 * Mathf.PI * widthMultiplier) / (physics.transform.lossyScale.x);
             }
             else
             {
                 offset.x = colliders[i].offset.x - (2 * Mathf.PI * widthMultiplier) / (physics.transform.lossyScale.x);
             }
             collidercopies [i].offset = offset;
         }
         else
         {
             collidercopies [i].enabled = false;
         }
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Created by Jason , 提示信息框
 /// </summary>
 /// <param name="content">内容</param>
 /// <param name="title">标题</param>
 /// <param name="width">宽度</param>
 /// <param name="height">高度</param>
 /// <param name="isSuccess">成功 or 警告 类型的信息  true: 成功类型提示  false:警告类型提示</param>
 /// <param name="funName">调用的JS函数名</param>
 protected void ShowMessage(string content, string title = null, int width = 260, int height = 100, bool isSuccess = false, string funName = null)
 {
     TempData[BaseDict.CustomScript] = UtilityScript.ShowMessage(content, title, width, height, isSuccess, funName);
 }
 public void SetAimDirection(Vector3 aimDirection)
 {
     startingAngle = UtilityScript.GetAngleFromVectorFloat(aimDirection) - fov / 2f;
 }
Ejemplo n.º 19
0
	// Use this for initialization
	void Start () 
	{
		instance = this;
		shakeAmt = 2f;
	
	}
Ejemplo n.º 20
0
 // Use this for initialization
 void Start()
 {
     instance = this;
     shakeAmt = 2f;
 }
 public static void RemoveCorrectKeyInput(KeyCode code, Action downKey)
 {
     UtilityScript.RemoveInputChecker(code, downKey);
 }