Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.tag == "Unit")
                {
                    target       = hit.transform.gameObject;
                    targetScript = hit.transform.GetComponent <UnitInfoTag>();
                    grabbing     = true;
                    targetPlane  = new Plane(Vector3.up, target.transform.position);
                    float enter = 0;
                    targetPlane.Raycast(ray, out enter);
                    localOrigin = ray.GetPoint(enter);
                    targetUnit  = simulator.GetUnit(targetScript.uuid);
                    if (targetUnit.owner != simulator.isClient)//0:host 1:client
                    {
                        grabbing     = false;
                        target       = null;
                        targetScript = null;
                    }
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (grabbing)
            {
                Ray   ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
                float enter = 0;
                targetPlane.Raycast(ray, out enter);
                Debug.Log(localOrigin - ray.GetPoint(enter));
                Vector3 vel = localOrigin - ray.GetPoint(enter);
                Command c   = new Command();
                c.sent  = false;
                c.vx    = vel.x;
                c.vz    = vel.z;
                c.uuid  = targetUnit.uuid;
                c.owner = simulator.isClient;

                simulator.commands.Add(c);
                //targetScript.rg.AddForce(vel, ForceMode.VelocityChange);

                /*
                 * CommandData c = new CommandData();
                 * c.sent = false;
                 * c.when = manager.elapsedTime;
                 * c.vx = vel.x;
                 * c.vz = vel.z;
                 * c.x = targetScript.transform.position.x;
                 * c.z = targetScript.transform.position.z;
                 *
                 * targetScript.command = c;*/
                grabbing = false;
            }
        }
    }
Ejemplo n.º 2
0
    void SimulateCollision(List <Unit> targets)
    {
        List <bool>          clean = new List <bool>();
        List <CollisionInfo> infos = new List <CollisionInfo>();

        //Simulate Collision:manipulate only veloity and position
        PhysicsSimulator.SimulateCollision(targets, mapBehaviour, this, clean, infos);

        for (int i = 0; i < targets.Count; i++)
        {
            if (clean[i])
            {
                PhysicsSimulator.ApplyIntegral(targets[i]);
            }
            else
            {
                PhysicsSimulator.SimulateIntegral(targets[i], Time.deltaTime, mapBehaviour);
                PhysicsSimulator.ApplyIntegral(targets[i]);
            }
        }
        for (int i = 0; i < infos.Count; i++)
        {
            CollisionInfo collision = infos[i];
            // Stop healing buff
            infos[i].me.buff    &= ~BuffFlag.BUFF_HEALING;
            infos[i].other.buff &= ~BuffFlag.BUFF_HEALING;
            UnitInfoTag unitInfoTag = FindInstance(collision.me.uuid);
            if (unitInfoTag != null)
            {
                unitInfoTag.CollisionEvent(collision);
            }
        }
        List <Unit> remains = new List <Unit>();

        for (int i = 0; i < targets.Count; i++)
        {
            Unit curUnit = targets[i];
            //死亡判定
            if (isClient == 0 && !curUnit.isDead)
            {
                if (curUnit.HP <= 0)
                {
                    curUnit.isDead = true;
                }
                else if (isOutOfBounds(curUnit))     //ユニットが範囲外に出たときの死亡判定
                {
                    curUnit.isDead = true;
                }
            }
            if (!curUnit.isDead)
            {
                remains.Add(curUnit);
            }
        }
        units = remains;
        checkGameSet();
    }
Ejemplo n.º 3
0
    public BasicUnit GetBasicUnit(int uuid)
    {
        UnitInfoTag info = GetUnitInfoTag(uuid);

        if (info != null)
        {
            return(info.basicUnit);
        }
        return(null);
    }
Ejemplo n.º 4
0
    void UpdateInstances()
    {
        List <UnitInfoTag> remains = new List <UnitInfoTag>();

        for (int i = 0; i < instances.Count; i++)
        {
            if (GetUnit(instances[i].uuid) == null)
            {
                if (instances[i].basicUnit != null && !instances[i].basicUnit.isDead)
                {
                    instances[i].basicUnit.isDead = true;
                }
                Destroy(instances[i].gameObject);
                UpdateUnitNumberText();
            }
            else
            {
                remains.Add(instances[i]);
            }
        }
        instances = remains;
        for (int i = 0; i < units.Count; i++)
        {
            bool found = false;
            for (int j = 0; j < instances.Count; j++)
            {
                if (units[i].uuid == instances[j].uuid)
                {
                    instances[j].Apply(units[i]);
                    found = true;
                    //Schin update CD ready emotion
                    //this process has moved to inside Update() of BasicUnit
                    break;
                }
            }
            if (!found)
            {
                var        prefab = (GameObject)Resources.Load(UnitTypeIndexMapper.map[units[i].type]);
                GameObject g      = Instantiate(prefab);
                units[i].HP = g.GetComponent <UnitSpec>().MaxHP;
                units[i].MP = g.GetComponent <UnitSpec>().MaxMP;
                UnitInfoTag tag = g.GetComponent <UnitInfoTag>();
                tag.sim = this;
                tag.Apply(units[i]);
                tag.InitializeBasicUnit(units[i]);
                tag.SetOwned(units[i].owner == isClient);
                instances.Add(tag);
            }
        }
    }
Ejemplo n.º 5
0
 void UpdateInstances()
 {
     for (int i = 0; i < units.Count; i++)
     {
         bool found = false;
         for (int j = 0; j < instances.Count; j++)
         {
             if (units[i].uuid == instances[j].uuid)
             {
                 instances[j].Apply(units[i]);
                 found = true;
                 break;
             }
         }
         if (!found)
         {
             GameObject  g   = Instantiate(prefabs[0]);
             UnitInfoTag tag = g.GetComponent <UnitInfoTag>();
             tag.Apply(units[i]);
             tag.SetOwned(units[i].owner == isClient);
             instances.Add(tag);
         }
     }
 }
Ejemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (!DragEnabled)
        {
            grabbing     = false;
            target       = null;
            targetScript = null;
            return;
        }
        if (target == null)
        {
            grabbing     = false;
            target       = null;
            targetScript = null;
        }
        if (target != null && Input.GetKeyDown(KeyCode.Escape)) // Tinaxd Press Esc to cancel dragging
        {
            target.GetComponent <BasicUnit>().NotifyDragEnd();
            grabbing     = false;
            target       = null;
            targetScript = null;
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.tag == "Unit")
                {
                    target       = hit.transform.gameObject;
                    targetScript = hit.transform.GetComponent <UnitInfoTag>();
                    grabbing     = true;
                    targetPlane  = new Plane(Vector3.up, target.transform.position);
                    float enter = 0;
                    targetPlane.Raycast(ray, out enter);
                    localOrigin = ray.GetPoint(enter);
                    targetUnit  = simulator.GetUnit(targetScript.uuid);
                    if (targetUnit.owner != simulator.isClient)//0:host 1:client
                    {
                        grabbing     = false;
                        target       = null;
                        targetScript = null;
                    }
                    else // Tinaxd show DragUI
                    {
                        target.GetComponent <BasicUnit>().NotifyDragStart();
                    }
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (grabbing)
            {
                Ray   ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
                float enter = 0;
                targetPlane.Raycast(ray, out enter);
//                Debug.Log(localOrigin - ray.GetPoint(enter));
                Vector3 vel = localOrigin - ray.GetPoint(enter);
                vel *= 2;
                DragType dt = DragType.NORMAL;
                vel = GetVelocity(vel);
                switch (dt)
                {
                case DragType.NORMAL:
                    UnitMovedCmd c = new UnitMovedCmd();
                    c.sent  = false;
                    c.vx    = vel.x;
                    c.vz    = vel.z;
                    c.uuid  = targetUnit.uuid;
                    c.owner = simulator.isClient;

                    simulator.commands.Add(c);
                    break;

                case DragType.ARCHER:
                    //target.GetComponent<BasicUnit>().DragMode = DragType.NORMAL;
                    NewUnitCmd cmd = new NewUnitCmd
                    {
                        fromUnitId = target.GetComponent <BasicUnit>().unit.uuid,
                        velocity   = new Vector3(vel.x * 3, 0, vel.z * 3),
                        unitType   = 2,   // Unit type Arrow
                    };

                    simulator.commands.Add(cmd);
                    break;

                case DragType.FIREBALL:
                    //target.GetComponent<BasicUnit>().DragMode = DragType.NORMAL;
                    NewUnitCmd cmd2 = new NewUnitCmd
                    {
                        fromUnitId = target.GetComponent <BasicUnit>().unit.uuid,
                        velocity   = new Vector3(vel.x * 3, 0, vel.z * 3),
                        unitType   = 3,   // Unit type Fireball
                    };

                    simulator.commands.Add(cmd2);
                    break;
                }
                //targetScript.rg.AddForce(vel, ForceMode.VelocityChange);

                /*
                 * CommandData c = new CommandData();
                 * c.sent = false;
                 * c.when = manager.elapsedTime;
                 * c.vx = vel.x;
                 * c.vz = vel.z;
                 * c.x = targetScript.transform.position.x;
                 * c.z = targetScript.transform.position.z;
                 *
                 * targetScript.command = c;*/
                grabbing = false;
                target.GetComponent <BasicUnit>().NotifyDragEnd(); // Tinaxd disable DragUI
            }
        }
        ballisticsSimulator.lr.enabled = grabbing;
        // Tinaxd update DragUI
        if (grabbing)
        {
            Ray   ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
            var   basicUnit = target.GetComponent <BasicUnit>();
            float enter     = 0;
            targetPlane.Raycast(ray, out enter);
            var     point = ray.GetPoint(enter);
            Vector3 diff  = -point + localOrigin;
            diff *= 2;
            diff  = GetVelocity(diff);
            ballisticsSimulator.UpdateTrails(target.transform.position, diff);
            basicUnit.NotifyDragUpdate(point);
        }
    }