Esempio n. 1
0
        public static TSMatrix4x4 TransformToMatrix(ref TSTransform transform)
        {
            TSMatrix4x4 result;

            TRS(transform.localPosition, transform.localRotation, transform.localScale, out result);
            return(result);
        }
Esempio n. 2
0
 public void Awake()
 {
     trb         = this.transform.parent.GetComponent <TSRigidBody>();
     tsTransform = this.transform.parent.GetComponent <TSTransform>();
     minLength   = restLength - springTravel;
     maxLength   = restLength + springTravel;
 }
Esempio n. 3
0
    private static void InitializeGameObject(GameObject go, TSVector position, TSQuaternion rotation)
    {
        ICollider[] tsColliders = go.GetComponentsInChildren <ICollider>();
        if (tsColliders != null)
        {
            for (int index = 0, length = tsColliders.Length; index < length; index++)
            {
                PhysicsManager.instance.AddBody(tsColliders[index]);
            }
        }

        TSTransform rootTSTransform = go.GetComponent <TSTransform>();

        if (rootTSTransform != null)
        {
            rootTSTransform.Initialize();

            rootTSTransform.position = position;
            rootTSTransform.rotation = rotation;
        }

        TSTransform[] tsTransforms = go.GetComponentsInChildren <TSTransform>();
        if (tsTransforms != null)
        {
            for (int index = 0, length = tsTransforms.Length; index < length; index++)
            {
                TSTransform tsTransform = tsTransforms[index];

                if (tsTransform != rootTSTransform)
                {
                    tsTransform.Initialize();
                }
            }
        }

        TSTransform2D rootTSTransform2D = go.GetComponent <TSTransform2D>();

        if (rootTSTransform2D != null)
        {
            rootTSTransform2D.Initialize();

            rootTSTransform2D.position = new TSVector2(position.x, position.y);
            rootTSTransform2D.rotation = rotation.ToQuaternion().eulerAngles.z;
        }

        TSTransform2D[] tsTransforms2D = go.GetComponentsInChildren <TSTransform2D>();
        if (tsTransforms2D != null)
        {
            for (int index = 0, length = tsTransforms2D.Length; index < length; index++)
            {
                TSTransform2D tsTransform2D = tsTransforms2D[index];

                if (tsTransform2D != rootTSTransform2D)
                {
                    tsTransform2D.Initialize();
                }
            }
        }
    }
Esempio n. 4
0
    /// <summary>
    /// OnTapLocation - call this to handle distributing and processing taps across a synchronized network game session
    /// Responds to taps and decides what to do
    /// </summary>
    /// <param name="tapLocation">location where tap/click took place</param>
    private void OnTapLocation(TSVector tapLocation)
    {
        // Handle powerup taps
        GameObject tlsc = TrueSyncManager.SyncedInstantiate(Resources.Load("Prefabs/TapLocationSphereCheck") as GameObject, tapLocation, TSQuaternion.identity);

        tlsc.GetComponent <TapLocationSphereCheck>().Owner = localOwner;

        // Find any status effect that may have been tapped
        FP           shortestDistance = 1000;
        StatusEffect nearestSe        = null;

        foreach (StatusEffect se in StatusEffectSystem.spawnedStatusEffects)
        {
            FP dist = TSVector.Distance(se.tsTransform.position, tapLocation);
            if (dist <= se.GetComponent <TSSphereCollider>().radius&& dist < shortestDistance)
            {
                shortestDistance = dist;
                nearestSe        = se;
            }
        }
        if (nearestSe != null) // Found a status effect to handle
        {
            return;            // exit this method to handle status effect within its own framework
        }
        // Shows where click took place (position marker):
        GameObject positionMarker = TrueSyncManager.SyncedInstantiate(PositionMarkerGO, tapLocation, TSQuaternion.identity);

        positionMarker.transform.position = tapLocation.ToVector();
        positionMarker.name = "Position Marker";    // Identify this marker game object in unity editor

        TSTransform tst = positionMarker.GetComponent <TSTransform>();

        tst.scale = TSVector.one * PlayerConfig.Instance.MinTapDistance;
        Renderer rend = positionMarker.GetComponent <Renderer>();

        if (TSVector.Distance(lastValidTapLocation, tapLocation) >= PlayerConfig.Instance.MinTapDistanceFromPrevious)
        {
            TapNearLine(tapLocation);
            rend.material.color = Color.black;
        }
        else
        {
            rend.material.color = Color.red;
        }

        DOTween.ToAlpha(() => rend.material.color, x => rend.material.color = x, 0, 5f).OnComplete(() =>
        {
            TrueSyncManager.Destroy(positionMarker);
        });

        lastValidTapLocation = tapLocation;
    }
Esempio n. 5
0
    /// <summary>
    // get the target ship to attack.
    /// <summary>
    TSVector gettargetmove()
    {
        TSTransform gam = getclosesttarget();

        if (gam != null)
        {
            return(gam.position);
        }
        else
        {
            return(new TSVector(0, 0, 0));
        }
    }
Esempio n. 6
0
    /**
     * @brief Initial setup when game is started.
     **/
    public void Start()
    {
        //CBGlobalEventDispatcher.Instance.AddEventListener((int)EVENT_ID.EVENT_FRAME_TICK, OnSyncedUpdate);
        //KBEngine.Event.registerOut("recieveFrameTick", this, "OnSyncedUpdate");


        tsRigidBody = GetComponent <TSRigidBody>();

        tsTransform = GetComponent <TSTransform>();


        Debug.Log("PlayerContorl::start:" + tsRigidBody + ",tsTransform:" + tsTransform);

        // if is first player then changes ball's color to black
    }
Esempio n. 7
0
    /// <summary>
    /// Check if cloak should be turned off.
    /// </summary>
    /// <returns>the result of the check.</returns>
    public bool asigncloacked()
    {
        TSTransform temp = checkclosest();

        if (temp != null)
        {
            cloaked = false;
            return(false);
        }
        else
        {
            cloaked = true;
            return(true);
        }
    }
Esempio n. 8
0
    public override void OnSyncedUpdate()
    {
        frame++;
        int objSize          = objStack.Count;
        FP  positionCheckSum = FP.Zero;
        FP  rotationCheckSum = FP.Zero;

        for (int i = 0; i < objSize; i++)
        {
            GameObject  obj        = objStack[i];
            TSTransform tTransform = obj.GetComponent <TSTransform>();
            positionCheckSum += (tTransform.position.x + tTransform.position.y + tTransform.position.z);
            rotationCheckSum += (tTransform.rotation.x + tTransform.rotation.y + tTransform.rotation.z + tTransform.rotation.w);
        }

        Debug.Log("frame :" + frame + " positionCheckSum: " + positionCheckSum.ToString("F8") + " rotationCheckSum: " + rotationCheckSum.ToString("F8"));
    }
Esempio n. 9
0
    public override void OnSyncedUpdate()
    {
        frame++;
        int objSize          = objStack.Count;
        FP  positionCheckSum = FP.Zero;
        FP  rotationCheckSum = FP.Zero;

        for (int i = 0; i < objSize; i++)
        {
            GameObject obj = objStack[i];
            obj.SetActive(true);
            TSTransform  tTransform = obj.GetComponent <TSTransform>();
            TSVector     position   = tTransform.position;
            TSQuaternion rotation   = tTransform.rotation;
            positionCheckSum += (position.x + position.y + position.z);
            rotationCheckSum += (rotation.x + rotation.y + rotation.z + rotation.w);
        }

        //Debug.Log("frame :" + frame + " positionCheckSum: " + positionCheckSum.ToString("F8") + " rotationCheckSum: " + rotationCheckSum.ToString("F8"));
    }
Esempio n. 10
0
    public void OnSyncedStart()
    {
        tsRigidBody = GetComponent <TSRigidBody>();

        tsTransform = GetComponent <TSTransform>();

        actions = GetComponent <Actions>();

        controller = GetComponent <PlayerController>();

        foreach (PlayerController.Arsenal a in controller.arsenal)
        {
            weapon_list.Add(a.name);
        }
        if (projectilePrefab == null)
        {
            projectilePrefab = (GameObject)Resources.Load("Perfabs/bullet");
        }

        Debug.Log("PlayerContorl::start:" + tsRigidBody + ",tsTransform:" + tsTransform + ",projectilePrefab:" + projectilePrefab);
    }
    /// <summary>
    /// The initialisation function, transfers variables from the _shipscript and initialises everything else.
    /// </summary>
    public void Start()
    {
        World           = GameObject.Find("World");
        shipscript      = GetComponent <_Ship>();
        acceleration    = 4;
        turnspeed       = shipscript.MaxAngularSpeed;
        transformts     = GetComponent <TSTransform>();
        unitcom         = GameObject.Find("Controllers").GetComponent <UnitMovementcommandcontroller>();
        waitforpushaway = (int)shipscript.MaxAngularSpeed % 5;
        int i = 0;

        foreach (Transform gam in transform)
        {
            if (gam.name == "Ship")
            {
                startmeshpos.Add(gam.transform.localPosition);
                Vector3 starttrans = gam.transform.localPosition;
                starttrans.z = Mathf.Lerp(-3000, startmeshpos[i].z, 1);
                gam.transform.localPosition = starttrans;
                i++;
            }
        }
    }
Esempio n. 12
0
    /// <summary>
    /// get the closest Gameobject.
    /// </summary>
    /// <returns>the closest gameobject</returns>
    TSTransform checkclosest()
    {
        TSTransform output = null;

        TSTransform[] objs     = unitcontrol.targetsout(parent.ShipColor).ToArray();
        float         distance = Mathf.Infinity;

        for (int i = 0; i < objs.Length; i++)
        {
            if (objs[i] != null && objs[i].gameObject != null)
            {
                float dis = Vector3.Distance(objs[i].transform.localPosition, transform.parent.localPosition);
                if (distance > dis)
                {
                    distance = dis;
                    if (dis < 2000)
                    {
                        output = objs[i];
                    }
                }
            }
        }
        return(output);
    }
Esempio n. 13
0
    /// <summary>
    // called every second to update the AIs orders to adapt to the situation.
    /// <summary>
    public void GiveOrderwait(int waittime)
    {
        if (TrueSyncManager.Time > 0 && randominst != null)
        {
            ships.Clear();
            ships = unitcontrol.teammembersout(team);
            List <TSTransform> temp           = unitcontrol.targetsout(team);
            List <GameObject>  removableships = new List <GameObject>();
            List <TSTransform> enemyremovable = new List <TSTransform>();
            foreach (GameObject ship in ships)
            {
                if (ship == null || ship.gameObject == null)
                {
                    removableships.Add(ship);
                }
            }
            foreach (GameObject remov in removableships)
            {
                ships.Remove(remov);
            }
            foreach (TSTransform ship in temp)
            {
                if (ship == null || ship.gameObject == null)
                {
                    enemyremovable.Add(ship);
                }
            }
            foreach (TSTransform remov in enemyremovable)
            {
                temp.Remove(remov);
            }
            debugmaxcount = ships.Count.ToString() + " out of " + UnitMovementcommandcontroller.getmaxshipnumbers().ToString();
            if (startpos == new TSVector(0, 0, 0) && ships.Count > 0)
            {
                startpos = ships[0].GetComponent <TSTransform>().position + new TSVector(1, 0, 0);
            }
            Target = getclosesttarget();

            if (((ismission == false && ships.Count > 0) || (crosslevelvar.campaign == true && crosslevelvar.campaignlevel.objective == MainMenuCampaignControlScript.eMissionObjective.Survive)) && unitcontrol)
            {
                BuyShip();
            }

            if (temp.Count != 0)
            {
                enemyships = temp.ToArray();
            }
            if (ships != null && ships.Count != 0 && ships.Count > 4)
            {
                state = AIstate.attacking;
            }
            if (ships != null && ships.Count != 0 && ships.Count <= 3)
            {
                state = AIstate.retreating;
            }
            if (ships != null && ships.Count != 0 && ships.Count > 2 && ships.Count < 4)
            {
                state = AIstate.maintain;
            }
            if (ships != null && ships.Count != 0 && state == AIstate.retreating && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, startpos) < 1000)
            {
                state = AIstate.holding;
            }
            if (ships != null && ships != null && ships.Count != 0 && ships[0] && Target != null && ships[0].gameObject != null && state == AIstate.holding && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, Target.GetComponent <TSTransform>().position) < 1000)
            {
                state = AIstate.attacking;
            }
            if (ships != null && ships.Count != 0 && state == AIstate.maintain && ships.Count > 0 && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, startpos) < 1000)
            {
                state = AIstate.retreating;
            }
            if (ships != null && ships.Count != 0 && state == AIstate.maintain && ships.Count > 0 && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, startpos) > 1000)
            {
                state = AIstate.attacking;
            }
            if (ismission && timepassedactual > 30)
            {
                state = AIstate.attacking;
            }
            if (ismission && timepassedactual < 30)
            {
                state = AIstate.holding;
            }
            if (ismission && unitcontrol.crosslevelholder.campaignlevel.objective == MainMenuCampaignControlScript.eMissionObjective.Survive)
            {
                state = AIstate.attacking;
            }
            int i = 0;

            foreach (GameObject ship in ships)
            {
                if (Target != null && ship.gameObject != null && state == AIstate.attacking)
                {
                    ship.GetComponent <_Ship>().asignMoveOrder(Target.GetComponent <TSTransform>().position, Target.gameObject, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                }
                if (ship.gameObject != null && state == AIstate.retreating)
                {
                    ship.GetComponent <_Ship>().asignMoveOrder(TargetPosition(i, startpos, ships.Count), null, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                }
                if (ship.gameObject != null && state == AIstate.holding)
                {
                    _Ship shipscript = ship.GetComponent <_Ship>();
                    if (shipscript.HullType == eHullType.Light)
                    {
                        shipscript.asignMoveOrder(startpos, null, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                    }
                    else
                    {
                        shipscript.asignMoveOrder(ship.GetComponent <TSTransform>().position, null, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                    }
                }
                i++;
            }
        }
    }
    /// <summary>
    /// Deterministic update function that, well , deterministically updates everything.
    /// </summary>
    public void SpecUpdate()
    {
        timepassedsincespawn++;
        if (turnspeed < shipscript.MaxAngularSpeed)
        {
            turnspeed = turnspeed + 0.003;
        }
        else
        {
            turnspeed = shipscript.MaxAngularSpeed;
        }
        thisposdif = Lastpos - transform.position;
        Lastpos    = transform.position;
        if (timepassedsincespawn <= 180)
        {
            int i = 0;
            foreach (GameObject ship in shipscript.meshes)
            {
                Vector3 starttrans = ship.transform.localPosition;
                starttrans.z = Mathf.Lerp(-3000, startmeshpos[i].z, (1 / (180 / timepassedsincespawn)));
                debugtest    = (1 / (180 / timepassedsincespawn));
                ship.transform.localPosition = starttrans;
                i++;
            }
        }
        if (shipscript && timepassedsincespawn > 180)
        {
            distancetotarget = TSVector.Distance(transformts.position, localtarget);
            if (started == false)
            {
                maxspeed = shipscript.MaxSpeed * 30;
                started  = true;
            }

            if (shipscript.WeaponTarget != null)
            {
                maxspeed = shipscript.MaxSpeed * 30;
            }
            else
            {
                maxspeed = shipscript.averagespeed * 30;
            }

            if (TrueSyncManager.Time > 0)
            {
                currentlymoving = false;

                if (distancetotarget > 10 || shipscript.HullType == eHullType.Light || shipscript.HullType == eHullType.Corvette)
                {
                    if (localtarget != null && distancetotarget < mindecdistance)
                    {
                        if (speed > 0)
                        {
                            speed = speed - acceleration / 2;
                        }
                    }
                    else
                    {
                        if (accelerating == true && speed < maxspeed)
                        {
                            speed += acceleration;
                        }
                        else if (speed > maxspeed)
                        {
                            accelerating = false;
                        }
                    }
                    if (speed > maxspeed)
                    {
                        speed = maxspeed;
                    }
                    if (shipscript.HullType == eHullType.Light || shipscript.HullType == eHullType.Corvette)
                    {
                        speed = maxspeed;
                    }
                    if (Target != new TSVector(0, 0, 0) && moving == true && distancetotarget > 150)
                    {
                        Look(Target);
                    }
                    if ((Target != new TSVector(0, 0, 0) && moving == true) || shipscript.HullType == eHullType.Light || shipscript.HullType == eHullType.Corvette)
                    {
                        Move(speed);
                    }
                }
                else if (shipscript.HullType != eHullType.Light && shipscript.HullType != eHullType.Corvette && speed > 0)
                {
                    Move(speed);
                }

                if (distancetotarget < 400)
                {
                    shipscript.movetonextstoredorder();
                }
            }
        }
        else
        {
            shipscript = GetComponent <_Ship>();
        }
        waitforpushaway++;
        if ((Closestoverall && shipscript.HullType != eHullType.Light && shipscript.HullType != eHullType.Corvette) && TSVector.Distance(Closestoverall.position, transformts.position) < 300 && Closestoverall.shipscript.HullType != eHullType.Light && Closestoverall.shipscript.HullType != eHullType.Corvette)
        {
            TSVector forwards = transformts.position - Closestoverall.position;
            transformts.position = transformts.position + (forwards * 0.005);
        }

        if (waitforpushaway > 10 && shipscript.HullType != eHullType.Light)
        {
            waitforpushaway = 0;
            TSTransform closest = getclosesttarget();
            if (closest != null)
            {
                Closestoverall = closest;
            }
        }
    }