Beispiel #1
0
 private void Start()
 {
     m_obstacleConstructor = GetComponentInParent <ObstacleConstructor>();
     foreach (UISpawnObstacleButton button in m_buttons)
     {
         button.SetObstacleConstructor(m_obstacleConstructor);
     }
 }
    // Use this for initialization
    void Start()
    {
        // Create a pool for platforms of size 10
        ObjectPooler.instance.CreatePool(platform, 10);

        obstacleConstructor = GetComponent <ObstacleConstructor>();
        constructionPoint   = GameObject.Find("PlatformConstructionPoint").transform;
        platformWidth       = platform.GetComponent <BoxCollider2D>().size.x;
    }
Beispiel #3
0
 public void SetActive(bool value)
 {
     if (null == m_obstacleConstructor)
     {
         m_obstacleConstructor = GetComponentInParent <ObstacleConstructor>();
     }
     if (!m_obstacleConstructor.GetTerritory().GetIsAvailable())
     {
         return;
     }
     gameObject.SetActive(value);
 }
Beispiel #4
0
 public void SetObstacleConstructor(ObstacleConstructor obstacleConstructor)
 {
     m_obstacleConstructor = obstacleConstructor;
     if (GameManager.Instance.GetLocalPlayer() == PlayerEntity.Player.Player1)
     {
         m_imageUnit.sprite = m_spriteSyca;
     }
     else
     {
         m_imageUnit.sprite = m_spriteArca;
     }
     m_obstaclePrice = m_obstacleConstructor.GetObstacleCost(m_obstacleType);
     transform.Find(Constant.ListOfMisc.s_Image).Find(Constant.ListOfMisc.s_CostText).GetComponent <Text>().text = m_obstaclePrice.ToString();
 }
    public bool TestIfRecalculatePathUnit(ObstacleConstructor obstacleConstructor)
    {
        Territory obstacleTerritory = obstacleConstructor.GetTerritory();

        if (m_objective != m_nexusEnemy)
        {
            return(false);
        }
        if (IsUnitPastTerritory(obstacleTerritory))
        {
            return(false);
        }
        return(true);
    }
Beispiel #6
0
    public void RpcInitOnConstruction(GameObject parent, PlayerEntity.Player playerNumber)
    {
        m_obstacleConstructor = parent.GetComponent <ObstacleConstructor>();
        transform.SetParent(parent.transform);
        transform.rotation = parent.transform.rotation;
        m_bombEffect       = parent.transform.GetComponentInChildren <ParticleSystem>();
        m_obstacleConstructor.SetCurrentState(ObstacleConstructor.EState.Invulnerable);
        GetComponentInChildren <ParticleSystem>().Play();

        InitPosition();

        m_initPosition = transform.position;
        if (isServer)
        {
            StartCoroutine(Construct(playerNumber));
        }
    }
Beispiel #7
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        m_pathCorners = m_playerUnit.GetAgent().path.corners;
        RaycastHit enter;
        float      minDistance = Mathf.Infinity;

        for (int i = 0; i < m_pathCorners.Length - 1; i++)
        {
            Vector2 line    = new Vector2(m_pathCorners[i + 1].x - m_pathCorners[i].x, m_pathCorners[i + 1].z - m_pathCorners[i].z);
            Vector2 lineDir = line.normalized;
            Ray     lineRay = new Ray(m_pathCorners[i], lineDir);
            Debug.DrawLine(m_pathCorners[i], m_pathCorners[i + 1], Color.green, 1000, false);

            for (int j = 0; j < m_listObstacles.Count; j++)
            {
                ObstacleConstructor obstacle    = m_listObstacles[j];
                Vector3             obstaclePos = obstacle.transform.position;
                Vector3             obstacleRot = obstacle.transform.eulerAngles;
                Vector3             obstacleNormal;
                if (obstacleRot.y == 90)
                {
                    obstacleNormal = Vector3.right;
                }
                else
                {
                    obstacleNormal = Vector3.forward;
                }

                GameObject plan = new GameObject();
                plan.AddComponent <BoxCollider>();
                plan.transform.position = obstaclePos;
                plan.GetComponent <BoxCollider>().transform.localScale += new Vector3(5f, 5f, 5f);

                if (plan.GetComponent <BoxCollider>().Raycast(lineRay, out enter, Vector3.Distance(m_pathCorners[i], m_pathCorners[i + 1])))
                {
                    Vector3 hitPoint = enter.point;
                    if (Vector3.Distance(hitPoint, obstaclePos) < 5f)
                    {
                        float distance = Vector3.Distance(hitPoint, m_pathCorners[i]);
                        if ((distance < minDistance) && (distance > Vector3.Distance(m_playerUnit.transform.position, m_pathCorners[i])))
                        {
                            minDistance     = distance;
                            m_indexObstacle = j;
                        }
                    }
                }
                Destroy(plan);
            }
        }

        // Prepare pour Build Obstacles


        ActiveObstacle activeObstacle = m_listObstacles[m_indexObstacle].transform.GetComponentInChildren <ActiveObstacle>();

        if (null != activeObstacle)
        {
            PlayerEntity.Player playerNumber = activeObstacle.GetPlayerNumber();
            if (playerNumber == PlayerEntity.Player.Player1)
            {
                m_aiDestroyObstacle.SetIndex(m_indexObstacle);
                animator.SetTrigger(Constant.BotTransition.s_destroyObstacle);
            }
        }
        m_aiBuildObstacles.SetTypeBuild(m_buildType);
        m_aiBuildObstacles.SetIndex(m_indexObstacle);

        animator.SetTrigger(Constant.BotTransition.s_buildObstacle);
    }
Beispiel #8
0
 /// <summary>
 /// Call on start of ObstacleConstructor, register all of them to the game manager
 /// </summary>
 public void AddObstacleConstructorToList(ObstacleConstructor obstacle)
 {
     m_listOfObstacles.Add(obstacle);
 }
Beispiel #9
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        ObstacleConstructor currentObstacle = m_listObstacleConstructors[m_ind];

        if (currentObstacle.GetCurrentState() == ObstacleConstructor.EState.Buildable)
        {
            NavMeshHit hit;
            NavMesh.SamplePosition(m_spawnunit.GetTarget().transform.position, out hit, Vector3.Distance(m_spawnunit.transform.position, m_spawnunit.GetTarget().transform.position) + 100, NavMesh.AllAreas);
            NavMeshAgent tempAgent = m_spawnunit.gameObject.GetComponent <NavMeshAgent>();
            if (tempAgent == null)
            {
                if (tempAgent == null)
                {
                    tempAgent = m_spawnunit.gameObject.AddComponent <NavMeshAgent>();
                }
            }
            tempAgent.CalculatePath(hit.position, m_newPath);

            //get intersection navmesh vs ckcollider
            Vector3[]  pathCorners = m_newPath.corners;
            RaycastHit colliderHit;
            //m_isCollider = (m_ind == m_listObstacleConstructors.Length - 1);

            for (int i = 0; i < pathCorners.Length - 1; i++)
            {
                Vector2 line    = new Vector2(pathCorners[i + 1].x - pathCorners[i].x, pathCorners[i + 1].z - pathCorners[i].z);
                Vector2 lineDir = line.normalized;
                Ray     lineRay = new Ray(pathCorners[i], lineDir);

                Debug.DrawLine(pathCorners[i], pathCorners[i + 1], Color.green, 1000, false);
                if (m_colliderOnAreaCollider.Raycast(lineRay, out colliderHit, Vector3.Distance(pathCorners[i], pathCorners[i + 1])))
                {
                    if (m_ind == 0)
                    {
                        animator.SetTrigger(Constant.BotTransition.s_return);
                    }
                    else
                    {
                        m_isCollider = true;
                        break;
                    }
                }
            }

            if (null != m_virtualWall)
            {
                Destroy(m_virtualWall);
            }

            if (m_isCollider)
            {
                Destroy(m_virtualArea);
                // Prepare pour Build Obstacles

                m_aiBuildObstacles.SetTypeBuild(ActiveObstacle.ObstacleType.SimpleWall);
                m_aiBuildObstacles.SetIndex(m_ind - 2);
                m_aiBuildObstacles.SetObstacleConstructorList(m_listObstacleConstructors);

                animator.SetTrigger(Constant.BotTransition.s_buildObstacle);
            }

            // construct virtual wall to calculate new path
            m_virtualWall = new GameObject();
            m_virtualWall.AddComponent <NavMeshObstacle>();
            m_virtualWall.GetComponent <NavMeshObstacle>().size = new Vector3(3, 3, 3);
            m_virtualWall.transform.position = currentObstacle.transform.position;
            m_virtualWall.GetComponent <NavMeshObstacle>().carving = true;
        }
        if (m_ind < m_listObstacleConstructors.Count - 1)
        {
            m_ind += 1;
        }
    }