Ejemplo n.º 1
0
        internal void Awake()
        {
            int unit_cnt = 5;

            speed   = 1f;
            angle   = 0f;
            form    = new UnitFormation();
            sprites = new List <prop>();

            form.SetFormation(unit_cnt, formTypes.auto);

            form.onEndMove     += Form_onEndMove;
            form.onEndRotate   += Form_onEndRotate;
            form.onStartMove   += Form_onStartMove;
            form.onStartRotate += Form_onStartRotate;

            transform.position = form.Get_leader_coord();

            for (int i = 0; i < unit_cnt; i++)
            {
                GameObject newUnit = Instantiate(unitPrefab);
                var        prop    = newUnit.GetComponent <prop>();
                sprites.Add(prop);
                //
                //int arrayIdx = Random.Range(0, unitSprites.Length);
                //Sprite unitSprite = unitSprites[arrayIdx];
                //string unitName = unitSprite.name;
                //
                newUnit.name = "man" + i;
                //     newUnit.transform.position = new Vector3(Random.Range(-1*sz,1*sz),0,Random.Range(-1*sz,1*sz));

                newUnit.transform.position = form.positions[i];
                //     newUnit.transform.Rotate( new Vector3(1f, 0f, 0f) , 45);
                //
                prop.unitName = newUnit.name;
                prop.speed    = 0.3f;

                //newUnit.GetComponent<SpriteRenderer>().sprite = unitSprite;

                prop.MoveTo(form.positions[i]);
            }


            //            form.MoveFormation(new Vector3(Random.Range(-100, 100), 0, Random.Range(-100, 100)));

            MouseEvents.mouseClick.AddListener(onClick);
        }
Ejemplo n.º 2
0
        public void MakeRandomSprite(int sz = 5)
        {
            int j = 0;

            group_formation = new UnitFormation();

            group_formation.Init();
            group_formation.Row3Formation(sz);


            for (int i = 0; i < sz; i++)
            {
                //GameObject newUnit = PrefabUtility.InstantiatePrefab(unitPrefab)  as GameObject;     
                GameObject newUnit = Instantiate(unitPrefab);
                var prop = newUnit.GetComponent<prop>();

                //
                int arrayIdx = Random.Range(0, unitSprites.Length);
                Sprite unitSprite = unitSprites[arrayIdx];
                string unitName = prop.anim.runtimeAnimatorController.name;
                Debug.Log("controller=" + prop.anim.runtimeAnimatorController.name);
                //     
                newUnit.name = unitSprite.name;
                //     newUnit.transform.position = new Vector3(Random.Range(-1*sz,1*sz),0,Random.Range(-1*sz,1*sz));

                newUnit.transform.position = new Vector3(i * 0.5f - ((i / 5) * 0.5f * 5f), 0, (i / 5) * 0.5f);
                //     newUnit.transform.Rotate( new Vector3(1f, 0f, 0f) , 45);
                //
                prop.unitName = unitSprite.name;
                prop.unit_type_name = "Man";
                prop.speed = 0.5f;

                newUnit.GetComponent<SpriteRenderer>().sprite = unitSprite;

                prop.MoveTo(group_formation.positions[i]);

                //prop.MoveTo(new Vector3(Random.Range(-100, 100), 0, Random.Range(-100, 100)));
                //prop.MoveTo(new Vector3(Random.Range(105, 110), 0, Random.Range(105, 110)));
                //prop.MoveTo(new Vector3(Random.Range(-105, -110), 0, Random.Range(-105, -110)));
            }
        }
Ejemplo n.º 3
0
 private void Form_onEndMove(UnitFormation data)
 {
     Debug.Log("End move");
     //  IdleAnimation();
 }
Ejemplo n.º 4
0
 private void Form_onEndRotate(UnitFormation data)
 {
     Debug.Log("End rotate");
     // IdleAnimation();
 }
Ejemplo n.º 5
0
 private void Form_onStartRotate(UnitFormation data)
 {
     Debug.Log("Start rotate");
     WalkAnimation();
 }
Ejemplo n.º 6
0
 private void Form_onStartMove(UnitFormation data)
 {
     Debug.Log("Start move");
     WalkAnimation();
 }
Ejemplo n.º 7
0
 // Start is called before the first frame update
 void Start()
 {
     _face = unitFacing.E;
     _form = new UnitFormation();
 }