示例#1
0
        public void CreateUnit(UnitType unit, ProvinceIdentifier province)
        {
            Province mapProvince = _map.GetProvince(province.Province, province.Nation);

            // Get city location
            Vector2 cityPosition = mapProvince.center;

            GameObject soldierGO = Instantiate(_prefabProvider.GetUnitTransform(UnitPrefabType.BASIC_SOLDIER)).gameObject;

            soldierGO.transform.Rotate(Vector3.up, 180);
            GameObjectAnimator soldier = soldierGO.WMSK_MoveTo(cityPosition);

            soldier.autoRotation      = false;
            soldier.terrainCapability = TERRAIN_CAPABILITY.OnlyGround;

            var guid = Guid.NewGuid();

            // Set tank ownership
            soldier.attrib["player"] = 1;
            soldier.attrib["uuid"]   = guid.ToString();
            var createdUnit = _gameState.CreateUnit(new WorldMapGameUnit()
            {
                UnitType = unit,
                Guid     = guid,
                Name     = "SuccessfullyCreated!"
            });

            soldierGO.GetComponent <GameUnitBehavior>().UnitAttributes = createdUnit;
        }
示例#2
0
    GameObjectAnimator placeArmy(Vector2 mapPosition)
    {
        //   GameObject tankGO = Instantiate(Resources.Load<GameObject>("Prefabs/Army"));
        // GameObject tankGO = Instantiate(Resources.Load<GameObject>("Tank/CompleteTank"));
        // GameObject tankGO = Instantiate(Resources.Load<GameObject>
        // ("SpartanKing/SpartanKing2"));
        GameObject tankGO = Instantiate(Resources.Load <GameObject>
                                            ("ToonyTinyPeople/TT_ww1/EarlyEraArmy"));

        //("SD_Character/Character/4Hero/Prefabs/Chara_4Hero 1"));
        SkinnedMeshRenderer[] smrs = tankGO.GetComponentsInChildren <SkinnedMeshRenderer>();
        foreach (SkinnedMeshRenderer smr in smrs)
        {
            if (smr.name.StartsWith("flagcl"))
            {
                Debug.Log("Does this happen?");
                smr.material = Resources.Load("Flags/Materials/" + State.getNations()[4].getNationName(), typeof(Material)) as Material;
            }
        }
        GameObjectAnimator tank = tankGO.WMSK_MoveTo(mapPosition);

        //tank.autoRotation = true;
        tank.preserveOriginalRotation = true;
        tank.transform.localScale     = new Vector3(0.5f, 0.5f, 0.5f);
        tank.terrainCapability        = TERRAIN_CAPABILITY.OnlyGround;
        tank.autoScale = true;
        tank.group     = 1;
        tank.transform.localRotation = Quaternion.Euler(-30f, 180f, 0f);
        tank.BlocksRayCast           = true;
        // tank.transform.rotation = Quaternion.Euler(-45.0f, 0f, -45.0f);
        //tank.transform.Rotate(0, -45, 0, Space.Self);
        // Set tank ownership
        tank.attrib["player"] = 1;
        return(tank);
    }
示例#3
0
    public void placeArmyOnMap(int provIndex, Nation nation, int id)
    {
        map = WMSK.instance;
        GameObject armyPrefabInstance = Instantiate(Resources.Load <GameObject>
                                                        ("ToonyTinyPeople/TT_ww1/EarlyEraArmy"));

        WorldMapStrategyKit.Province prov = map.GetProvince(provIndex);
        if (nation.getType() == MyEnum.NationType.major || nation.getType() == MyEnum.NationType.minor)
        {
            if (State.GerEra() == MyEnum.Era.Early)
            {
                armyPrefabInstance = Instantiate(Resources.Load <GameObject>
                                                 // ("ToonyTinyPeople/TT_ww1/EarlyEraArmy"));
                                                     ("ToonyTinyPeople/TT_ww1/EarlyEraArmy"));
            }
        }
        else
        {
            {
                armyPrefabInstance = Instantiate(Resources.Load <GameObject>
                                                     ("Model_Warrior/barbOne"));
            }
        }

        Vector2            position = prov.center;
        GameObjectAnimator army     = armyPrefabInstance.WMSK_MoveTo(position);

        army.gameObject.AddComponent <GenericSoldierController>();
        army.name = id.ToString();



        SkinnedMeshRenderer[] smrs = armyPrefabInstance.GetComponentsInChildren <SkinnedMeshRenderer>();
        foreach (SkinnedMeshRenderer smr in smrs)
        {
            if (smr.name.StartsWith("flagcl"))
            {
                Debug.Log("Army of " + nation.getNationName());
                smr.material = Resources.Load("Flags/Materials/" + nation.getNationName(), typeof(Material)) as Material;
            }
        }
        if (nation.getType() == MyEnum.NationType.major || nation.getType() == MyEnum.NationType.minor)
        {
            army.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
        }
        else
        {
            army.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
        }
        army.preserveOriginalRotation = true;
        army.terrainCapability        = TERRAIN_CAPABILITY.OnlyGround;
        army.autoScale = true;
        army.group     = 1;
        army.transform.localRotation = Quaternion.Euler(-30f, 180f, 0f);
        army.BlocksRayCast           = true;

        army.attrib["owner"] = nation.getIndex();
        army.attrib["id"]    = id;
    }
示例#4
0
    void ArmyMouseDown(GameObjectAnimator army)
    {
        // Changes tank color to white
        Renderer renderer = army.GetComponentInChildren <Renderer>();

        renderer.sharedMaterial.color = Color.white;
        // Sprite newSprite = Resources.Load<Sprite>("/Sprites/AustrianInfantry1.png");
        // obj.GetComponent<SpriteRenderer>().sprite = newSprite;
    }
示例#5
0
        /// <summary>
        /// This function adds a standard sphere primitive to the map. The difference here is that the pivot of the sphere is centered in the sphere. So we make use of pivotY property to specify it and
        /// this way the positioning over the terrain will work. Otherwise, the sphere will be cut by the terrain (the center of the sphere will be on the ground - and we want the sphere on top of the terrain).
        /// </summary>
        void AddSphere()
        {
            GameObject         sphere   = Instantiate(Resources.Load <GameObject> ("Sphere/Sphere"));
            Vector2            position = map.GetCity("Lhasa", "China").unity2DLocation;
            GameObjectAnimator anim     = sphere.WMSK_MoveTo(position, 0, 0, HEIGHT_OFFSET_MODE.RELATIVE_TO_GROUND, true);

            anim.pivotY = 0.5f;
            map.FlyToLocation(position, 2f, 0.1f);
        }
示例#6
0
        // Create tank instance and add it to the map
        GameObjectAnimator DropTankOnPosition(Vector2 mapPosition)
        {
            GameObject tankGO = Instantiate(Resources.Load <GameObject> ("Tank/CompleteTank"));

            tank                   = tankGO.WMSK_MoveTo(mapPosition);
            tank.type              = (int)UNIT_TYPE.TANK;
            tank.autoRotation      = true;
            tank.terrainCapability = TERRAIN_CAPABILITY.OnlyGround;
            return(tank);
        }
 void makeAttack(GameObjectAnimator earlyArmy)
 {
     if (flag == true)
     {
         Vector2 armyLocation = earlyArmy.currentMap2DLocation;
         earlyArmy.autoRotation             = false;
         earlyArmy.preserveOriginalRotation = true;
         this.animator.SetBool(key_is_attacking, true);
         this.animator.SetBool(key_isWalking, false);
         //  animator.Play(shootBurst);
     }
 }
示例#8
0
    void ArmyHover(GameObjectAnimator army)
    {
        // Changes tank color - but first we store original color inside its attribute bag
        Renderer renderer = army.GetComponentInChildren <Renderer>();

        army.attrib["color"] = renderer.sharedMaterial.color;
        // army.GetComponent<Animator>().SetTrigger("MakeAttack");
        // army.GetComponent<Animator>().SetBool(key_isAttack01, true);

        //Sprite newSprite = Resources.Load<Sprite>("/Sprites/AustrianInfantry1.png");
        //obj.GetComponent<SpriteRenderer>().color = Color.white;
        renderer.material.color = Color.yellow; // notice how I use material and not sharedmaterial - this is to prevent affecting all clone instances - we just want to color this one, so we need to make this material unique.
    }
示例#9
0
    void RestoreArmyColor(GameObjectAnimator army)
    {
        // Restores original tank color
        Renderer renderer  = army.GetComponentInChildren <Renderer>();
        Color    tankColor = army.attrib["color"]; // get back the original color from attribute bag

        renderer.sharedMaterial.color = tankColor;
        // army.GetComponent<Animator>().SetTrigger("MakeIdle");
        //  army.GetComponent<Animator>().SetBool(key_isRun, false);
        //army.GetComponent<Animator>().SetBool(key_isAttack01, false);

        // obj.GetComponentInChildren<SpriteRenderer>().color = Color.blue;
    }
    void makeIdle(GameObjectAnimator earlyArmy)
    {
        animator.StopPlayback();

        //  Debug.Log("Why do you suck so much?");
        earlyArmy.autoRotation             = true;
        earlyArmy.preserveOriginalRotation = true;
        this.animator.SetBool(key_is_attacking, false);
        this.animator.SetBool(key_isWalking, false);
        this.animator.SetBool(key_is_attacking, false);
        this.animator.SetBool(key_isIdle, true);

        this.animator.StopPlayback();
        animator.Play(idle);
    }
示例#11
0
    public void ToggleProvinceResources()
    {
        map = WMSK.instance;

        App app = UnityEngine.Object.FindObjectOfType <App>();
        Dictionary <int, assemblyCsharp.Province> provinces = State.getProvinces();

        if (State.GetResourceIcons().Count == 0)
        {
            for (int k = 0; k < map.provinces.Length; k++)
            {
                GameObject resourceIcon = Instantiate
                                              (Resources.Load <GameObject>("ResourceMap/" + provinces[k].getResource()));
                Vector2            position = map.GetProvince(k).center;
                GameObjectAnimator icon     = resourceIcon.WMSK_MoveTo(position, true, 1f);

                //  icon.WMSK_MoveTo(position, true, 1.6f);
                icon.transform.localScale = new Vector3(0.5f, 0.5f, 1.0f);
                // resourceIcon.SetActive(false);
                icon.autoScale = true;
                icon.group     = 0;
                //   icon.GetComponent<SpriteRenderer>().enabled = false;
                icon.visible = false;
                State.addResourceIcon(icon);
            }
            map.VGOToggleGroupVisibility(0, false);
        }
        else if (!resourceTogle.isOn)
        {
            map.VGOToggleGroupVisibility(0, false);
        }

        else if (resourceTogle.isOn)
        {
            map.VGOToggleGroupVisibility(0, true);

            // State.GetResourceIcons()[k].GetComponent<SpriteRenderer>().enabled = true;
            // State.GetResourceIcons()[k].SetActive(true);
        }



        // Instantiate the sprite, face it to up and position it into the map
        //goldIcon.transform.localRotation = Quaternion.Euler(90, 180, 180);
        //goldIcon.transform.localScale = Misc.Vector3one * 1f;
        // GameObject star = Instantiate(Resources.Load<GameObject>("Sprites/StarSprite"));
    }
示例#12
0
        /// <summary>
        /// Creates a tank instance and adds it to specified city
        /// </summary>
        void DropTankOnCity()
        {
            // Get a random big city
            int cityIndex = map.GetCityIndex("Paris", "France");

            // Get city location
            Vector2 cityPosition = map.cities [cityIndex].unity2DLocation;

            GameObject tankGO = Instantiate(Resources.Load <GameObject> ("Tank/CompleteTank"));

            tank = tankGO.WMSK_MoveTo(cityPosition);
            tank.autoRotation      = true;
            tank.terrainCapability = TERRAIN_CAPABILITY.OnlyGround;

            // Set tank ownership
            tank.attrib["player"] = 1;
        }
    void MoveUnitWithPathFinding(Vector2 destination)
    {
        army = map.VGOLastClicked;
        bool canMove = false;

        Debug.Log("Are we going to move now?");
        animator.SetBool(key_isWalking, true);
        // animator.Play(walk);

        // army.GetComponent<Animator>().SetBool(key_isRun, true);
        canMove = army.MoveTo(destination, 0.33f);
        Debug.Log(canMove);
        selected = false;
        if (!canMove)
        {
            Debug.Log("Can't move to destination!");
        }
        // animator.Play(walk);
    }
示例#14
0
    private void PlaceResourcesOnMap()
    {
        App app = UnityEngine.Object.FindObjectOfType <App>();

        for (int k = 0; k < map.provinces.Length; k++)
        {
            GameObject resourceIcon = Instantiate
                                          (Resources.Load <GameObject>("ResourceMap/" + provinces[k].getResource()));
            Vector2            position = map.GetProvince(k).center;
            GameObjectAnimator icon     = resourceIcon.WMSK_MoveTo(position, true, 1f);

            //  icon.WMSK_MoveTo(position, true, 1.6f);
            icon.transform.localScale = new Vector3(0.5f, 0.5f, 1.0f);
            // resourceIcon.SetActive(false);
            icon.autoScale = true;
            icon.group     = 0;
            //   icon.GetComponent<SpriteRenderer>().enabled = false;
            icon.visible = false;
            State.addResourceIcon(icon);
        }
        // map.VGOToggleGroupVisibility(0, false);
    }
    private void selectArmy(GameObjectAnimator clickedArmy)
    {
        army = clickedArmy;
        //  animator = army.gameObject.GetComponent<Animator>();
        Debug.Log("GLOBAL EVENT: Left button pressed on " + army.name);

        // ArmyMouseDown(army);
        int provIndex = map.provinceLastClicked;

        ///// Debug.Log(provIndex);
        //  assemblyCsharp.Province province = State.getProvinces()[provIndex];
        //  province.SetRayBlocked(true);
        //  IEnumerator wait = Wait(2f);
        if (selected == false)
        {
            selected = true;
        }
        else
        {
            selected = false;
        }
    }
    void makeWalk(GameObjectAnimator army)
    {
        Debug.Log("Name: " + army.name);

        this.animator.SetBool(key_isIdle, false);

        army.autoRotation = true;
        // army.preserveOriginalRotation = false;
        // army.GetComponent<Animator>().SetBool(key_isRun, true);
        //  this.animator.SetBool(key_weaponDrawn, true);
        // army.GetComponent<Animator>().SetBool(key_weaponDrawn, true);

        // animator.Play(drawWeapon);
        //System.Threading.Thread.Sleep(400);
        this.animator.SetBool(key_isWalking, true);
        this.animator.SetBool(key_isWalking, false);
        //   army.GetComponent<Animator>().SetBool(key_weaponDrawn, false);
        //   army.GetComponent<Animator>().SetBool(key_isWalking, true);
        // animator.Play(walk);
        //this.animator.SetBool(key_weaponDrawn, false);
        animator.Play(walk);
    }
示例#17
0
        /// <summary>
        /// Creates lots of ships and tanks. Called from main UI button.
        /// </summary>
        void MassCreate()
        {
            int numberOfUnits = 50;

            units = new List <GameObjectAnimator> ();
            // add tanks
            for (int k = 0; k < numberOfUnits; k++)
            {
                Vector2            cityPosition = GetRandomCityPosition();
                GameObjectAnimator newTank      = DropTankOnPosition(cityPosition);
                newTank.gameObject.hideFlags = HideFlags.HideInHierarchy;                 // don't show in hierarchy to avoid clutter
                units.Add(newTank);
            }
            // add ships
            for (int k = 0; k < numberOfUnits; k++)
            {
                Vector2            waterPosition = GetRandomWaterPosition();
                GameObjectAnimator newShip       = DropShipOnPosition(waterPosition);
                newShip.gameObject.hideFlags = HideFlags.HideInHierarchy;                 // don't show in hierarchy to avoid clutter
                units.Add(newShip);
            }
        }
示例#18
0
        /// <summary>
        /// Creates a tank instance and adds it to specified city
        /// </summary>
        void DropTankOnCity()
        {
            // Get a random big city
            int cityIndex = map.GetCityIndex("Paris", "France");

            // Get city location
            Vector2 cityPosition = map.cities [cityIndex].unity2DLocation;

            if (tank != null)
            {
                DestroyImmediate(tank.gameObject);
            }
            tank = DropTankOnPosition(cityPosition);

            // Zoom into tank
            map.FlyToLocation(cityPosition, 2.0f, 0.15f);

            // Enable move on click in this demo
            enableAddTowerOnClick = false;
            enableClickToMoveShip = false;
            enableClickToMoveTank = true;
        }
示例#19
0
        /// <summary>
        /// Creates a tank instance and adds it to specified city
        /// </summary>
        void DropTankOnCity()
        {
            // Get a random big city
            int cityIndex = map.GetCityIndex("Lhasa", "China");

            // Get city location
            Vector2 cityPosition = map.cities [cityIndex].unity2DLocation;

            if (tank != null)
            {
                DestroyImmediate(tank);
            }
            GameObject tankGO = Instantiate(Resources.Load <GameObject> ("Tank/CompleteTank"));

            tank                   = tankGO.WMSK_MoveTo(cityPosition);
            tank.type              = (int)UNIT_TYPE.TANK;
            tank.autoRotation      = true;
            tank.terrainCapability = TERRAIN_CAPABILITY.OnlyGround;

            // Zoom into tank
            map.FlyToLocation(cityPosition, 2.0f, 0.15f);
        }
示例#20
0
    GameObjectAnimator PlaceArmy(Vector2 mapPosition)
    {
        //   GameObject tankGO = Instantiate(Resources.Load<GameObject>("Prefabs/Army"));
        // GameObject tankGO = Instantiate(Resources.Load<GameObject>("Tank/CompleteTank"));
        // GameObject tankGO = Instantiate(Resources.Load<GameObject>
        // ("SpartanKing/SpartanKing2"));
        GameObject tankGO = Instantiate(Resources.Load <GameObject>
                                            ("SD_Character/Character/4Hero/Prefabs/Chara_4Hero"));

        GameObjectAnimator tank = tankGO.WMSK_MoveTo(mapPosition);

        tank.autoRotation = true;

        tank.autoScale            = true;
        tank.transform.localScale = new Vector3(1, 1, 1);
        tank.terrainCapability    = TERRAIN_CAPABILITY.OnlyGround;
        // Set tank ownership
        tank.attrib["player"] = 1;
        float   degrees = 45;
        Vector3 to      = new Vector3(degrees, 0, 0);

        tank.transform.localRotation = Quaternion.Euler(-45.0f, -45.0f, -45.0f);
        return(tank);
    }
示例#21
0
 public static void addResourceIcon(GameObjectAnimator icon)
 {
     ResourceIcons.Add(icon);
 }
    // Use this for initialization
    void Start()
    {
        animator = GetComponent <Animator>();
        map      = WMSK.instance;
        army     = GetComponent <GameObjectAnimator>();


        this.animator.SetBool(key_isWalking, false);
        this.animator.SetBool(key_is_attacking, false);
        // this.animator.SetBool(key_weaponDrawn, false);
        this.animator.SetBool(key_isIdle, true);
        // animator.Play(idle);
        map.pathFindingEnableCustomRouteMatrix = true;

        /* map.OnVGOPointerEnter = delegate (GameObjectAnimator army) {
         *   Debug.Log("GLOBAL EVENT: Mouse entered " + army.name);
         *   if (army.GetComponent<Animator>() != null)
         * };
         *
         *
         * map.OnVGOPointerExit = delegate (GameObjectAnimator army)
         * {
         *   Debug.Log("GLOBAL EVENT: Mouse exited " + army.name);
         *   if (army.GetComponentInChildren<Renderer>().material.color == Color.yellow)
         *   {
         *       if (army.GetComponent<Animator>() != null)
         *           makeIdle(army);
         *   }
         * }; */

        map.OnClick += (float x, float y, int buttonIndex) => {
            flag = true;
            if (selected == false)
            {
                return;
            }
            if (provinceClicked == map.provinceLastClicked)
            {
                //   wait = false;
                return;
            }
            Debug.Log("Name" + army.name);
            // Debug.Log("selected " + selectedName);


            if (buttonIndex == 1)
            {
                Debug.Log("Righ Click on Destination");


                //  makeWalk(army);
                //  System.Threading.Thread.Sleep(500);
                //  Invoke("MoveUnitWithPathFinding", 4);

                MoveUnitWithPathFinding(new Vector2(x, y));
            }
        };

        map.OnVGOCountryEnter += makeAttack;
        map.OnVGOMoveEnd      += makeIdle;
        map.OnVGOMoveStart    += makeWalk;

        map.OnVGOPointerDown += selectArmy;
    }
示例#23
0
 void makeWalk(GameObjectAnimator army)
 {
     army.autoRotation = true;
     // army.preserveOriginalRotation = false;
     army.GetComponent <Animator>().SetBool(key_isRun, true);
 }