Beispiel #1
0
 public void ResetThis()
 {
     clickState                 = CLICKSTATE.HIDDEN;
     canClick                   = true;
     transform.localScale       = Vector3.one;
     transform.localEulerAngles = Vector3.zero;
 }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        view = GetComponent <PhotonView>();
        object[] data = view.InstantiationData;
        faction = (FACTION)data[0];

        es             = GameObject.Find("EventSystem").GetComponent <EventSystem>();
        currClickState = CLICKSTATE.UNITCONTROL_MODE;
        money          = 1000;
    }
Beispiel #3
0
    public void Flip()
    {
        if (clickState == CLICKSTATE.FLIPPED)
        {
            LeanTween.cancel(gameObject);

            clickState = CLICKSTATE.ANIMATING;
            SoundManager.instance.Play(SOUNDTYPE.FLIPCARD);
            LeanTween.rotateY(gameObject, 270, 0.25f).setOnComplete(() => {
                sprite.sprite = app.poolManager.textures[0];

                LeanTween.rotateY(gameObject, 360, 0.25f).setOnComplete(() => {
                    clickState = CLICKSTATE.HIDDEN;
                    canClick   = true;
                });
            });
        }
    }
Beispiel #4
0
    void OnMouseUp()
    {
        if (!canClick)
        {
            return;
        }

        canClick = false;

        if (clickState == CLICKSTATE.HIDDEN)
        {
            Instantiate(particleClick, transform.position, Quaternion.identity);

            clickState = CLICKSTATE.FLIPPED;
            SoundManager.instance.Play(SOUNDTYPE.CLICK_CARD);
            LeanTween.cancel(gameObject);
            LeanTween.rotateY(gameObject, 90, 0.25f).setOnComplete(() => {
                sprite.sprite = app.poolManager.textures[idxType];
                LeanTween.rotateY(gameObject, 180, 0.25f).setOnComplete(() => {
                    app.Notify(NOTIFYEVENT.FLIPPED, this, this);
                });
            });
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (enemiesInEnvironment == null || buildingsInEnvironment == null)
        {
            if (GameObject.Find("Environment") == null)
            {
                return;
            }
            enemiesInEnvironment   = GameObject.Find("Environment").transform.Find("Enemies");
            buildingsInEnvironment = GameObject.Find("Environment").transform.Find("Structures");
            return;
        }

        if (view.IsMine && GameManager.Instance.gameStart == false && spawnedBase == false)
        {
            if (SpawnGhostStructure(GameManager.Instance.basePrefab))
            {
                Vector3 finalPos = towerGhostHitInfo.point;
                finalPos.y += GameManager.Instance.basePrefab.transform.localScale.y * 0.5f;
                GameManager.Instance.SpawnBuilding("Base", GridGenerator.Instance.PositionSnapToGrid(finalPos), faction);
                spawnedBase = true;
            }
        }

        if (view.IsMine && GameManager.Instance.gameStart)
        {
            switch (currClickState)
            {
            case CLICKSTATE.UNITCONTROL_MODE:

            {
                // Move
                if (Input.GetKeyUp(KeyCode.Mouse0) && selectedUnits.Count > 0)
                {
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hitInfo;
                    //    Physics.Raycast(ray, out hitInfo);

                    if (Physics.Raycast(ray, out hitInfo))
                    {
                        if (!es.IsPointerOverGameObject())
                        {
                            EnemyBase   leaderEnemy = null;
                            float       lowestCost  = float.MaxValue;
                            NavMeshPath path;

                            foreach (EnemyBase enemy in selectedUnits)
                            {
                                if (!enemy)
                                {
                                    continue;
                                }
                                if (hitInfo.transform.GetComponent <EntityBase>() && hitInfo.transform.GetComponent <EntityBase>().faction != faction)
                                {
                                    enemy.targetEntity = hitInfo.transform.GetComponent <EntityBase>();
                                    enemy.agent.SetDestination(enemy.targetEntity.transform.position);
                                    enemy.agent.isStopped = false;
                                }
                                else
                                {
                                    path = new NavMeshPath();
                                    enemy.agent.CalculatePath(hitInfo.point, path);
                                    if (path.status != NavMeshPathStatus.PathInvalid)
                                    {
                                        enemy.agent.SetDestination(hitInfo.point);
                                        enemy.agent.isStopped = false;
                                        if (enemy.agent.remainingDistance < lowestCost)
                                        {
                                            lowestCost  = enemy.agent.remainingDistance;
                                            leaderEnemy = enemy;
                                        }
                                    }
                                    enemy.targetEntity = null;
                                }
                            }
                            Debug.Log(leaderEnemy);

                            Debug.Log("Find Path");
                        }
                    }
                    else
                    {
                        if (!es.IsPointerOverGameObject())
                        {
                            DeleteSelectedEnemies();
                        }
                    }
                }
                // Select
                if (selectedUnits.Count <= 0)
                {
                    DraggingUpdate();
                }
            }
            break;

            case CLICKSTATE.PLACE_MODE:
            {
                GameObject towerPrefab = null;
                switch (buildingType)
                {
                case "Barricade":
                    towerPrefab = GameManager.Instance.barricadePrefab;
                    break;

                case "Harvester":
                    towerPrefab = GameManager.Instance.harversterPrefab;
                    break;

                case "Turret":
                    towerPrefab = GameManager.Instance.turretPrefab;
                    break;
                }
                // Place State
                if (SpawnGhostStructure(towerPrefab))
                {
                    if (Input.GetKeyUp(KeyCode.Mouse0) && !es.IsPointerOverGameObject())
                    {
                        Vector3 finalPos = towerGhostHitInfo.point;
                        finalPos.y += towerPrefab.transform.localScale.y * 0.5f;
                        GameManager.Instance.SpawnBuilding(buildingType, GridGenerator.Instance.PositionSnapToGrid(finalPos), faction);
                        currClickState = CLICKSTATE.UNITCONTROL_MODE;
                    }
                }
            }
            break;
            }
            UpdateResources();
        }
    }