コード例 #1
0
    int UpdateVisuals()
    {
        int retVal = 0;

        if (GrabTarget != null)
        {
            retVal = 1;

            Tracer.SetPosition(0, transform.position);
            Tracer.SetPosition(1, GrabTarget.transform.position);
        }
        else
        {
            Tracer.SetPosition(0, Vector3.zero);
            Tracer.SetPosition(1, Vector3.zero);
        }

        if (isServer)
        {
            //Dynamic
            for (int i = 0; i < 1; ++i)
            {
                //Add to list to fit connection count
                if (RepairParticles.Count < MissingPartsID.Count)
                {
                    GameObject spawnedRepairParticle = Instantiate(RepairParticlePrefab, Vector3.zero, Quaternion.identity);
                    ParticleSystem.MainModule main   = spawnedRepairParticle.GetComponent <ParticleSystem>().main;
                    main.startColor = Tracker.ThePlayerControlPanel.TheResourceManager.PlayerColor[transform.root.GetComponent <UnitID>().ID].TrimEmissionColor;
                    spawnedRepairParticle.transform.parent = transform.root;
                    NetworkServer.Spawn(spawnedRepairParticle);
                    RepairParticles.Add(spawnedRepairParticle);
                    RpcRepairParticleColor(spawnedRepairParticle, Tracker.ThePlayerControlPanel.TheResourceManager.PlayerColor[transform.root.GetComponent <UnitID>().ID].TrimEmissionColor);
                    //Recheck
                    i -= 1;
                }
                //remove from list to fit connection count
                if (RepairParticles.Count > MissingPartsID.Count)
                {
                    Destroy(RepairParticles[RepairParticles.Count - 1]);
                    RepairParticles.RemoveAt(RepairParticles.Count - 1);
                    //Recheck
                    i -= 1;
                }
            }

            for (int i = 0; i < RepairParticles.Count; ++i)
            {
                retVal = 1;
                ShipSchematic theShipSchematic = transform.root.GetComponent <ShipSchematic>();
                //RpcRepairParticle(RepairParticles[i], transform.root.gameObject, new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[2]));
                if (RepairParticles[i] != null)
                {
                    RepairParticles[i].transform.localPosition = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[2]);
                }
                //RepairParticles[i].transform.localPosition = Vector3.zero;
            }
        }

        return(retVal);
    }
コード例 #2
0
    void OnTriggerEnter(Collider other)
    {
        if (!isServer)
        {
            return;
        }
        if (GrabTargetPartID == -1)
        {
            return;
        }
        if (GrabTarget == null)
        {
            return;
        }

        if (other.tag == "Block")
        {
            if (other.gameObject == GrabTarget)
            {
                ShipSchematic theShipSchematic = transform.root.GetComponent <ShipSchematic>();
                GrabTarget.transform.parent           = transform.root;
                GrabTarget.transform.localPosition    = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Position[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Position[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Position[2]);
                GrabTarget.transform.localEulerAngles = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Rotation[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Rotation[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Rotation[2]);
                theShipSchematic.TrackedBlocks[MissingPartsID[GrabTargetPartID]] = GrabTarget;

                //Physics
                GrabTarget.layer = LayerMask.NameToLayer("Attached");
                ApplyLayerToChilds(GrabTarget.transform, "Attached");
                GrabTarget.GetComponent <Rigidbody>().isKinematic    = true;
                GrabTarget.GetComponent <BoxCollider>().isTrigger    = false;
                GrabTarget.GetComponent <NetworkTransform>().enabled = false;

                //Rpc info
                GameObject rpcGrabbedObject = GrabTarget;
                GameObject rpcRoot          = transform.root.gameObject;
                Vector3    rpcPosition      = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Position[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Position[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Position[2]);
                Vector3    rpcRotation      = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Rotation[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Rotation[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[GrabTargetPartID]].Rotation[2]);

                //Cancel
                GrabTarget.GetComponent <ShipAdjacentCheck>().BeingGrabbed = false;
                MissingPartsID.RemoveAt(GrabTargetPartID);
                GrabTargetPartID = -1;
                GrabTarget       = null;

                //Loop
                theShipSchematic.RequestAdjacentCheck();
                transform.root.GetComponent <ShipMeshCombine>().RequestCombine();

                RpcGrabCollide(rpcGrabbedObject, rpcRoot, rpcPosition, rpcRotation);
            }
        }
    }
コード例 #3
0
    int UpdateRegenTimers()
    {
        int retVal = 0;

        if (transform.root.GetComponent <ShipSchematic>().StartRegeneratingTimer < 5)
        {
            return(retVal);
        }
        //Regenerates missing parts if its not grabbing a nearby block
        for (int i = 0; i < MissingPartsID.Count; i++)
        {
            retVal = 1;

            ShipSchematic theShipSchematic = transform.root.GetComponent <ShipSchematic>();
            //if (GrabTargetPartID != i || GrabTarget == null)
            //{
            //}
            //else theShipSchematic.TrackedBlockRegenTimers[MissingPartsID[i]] = 0;
            theShipSchematic.TrackedBlockRegenTimers[MissingPartsID[i]] += Time.deltaTime;
            if (theShipSchematic.TrackedBlockRegenTimers[MissingPartsID[i]] >= 4)
            {
                bool   checkAdjacent = false;
                string partName      = theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Name;
                for (int j = 0; j < Tracker.NetworkBlocks.Count; j++)
                {
                    partName = partName.Replace(Tracker.NetworkBlocks[j].name, "");
                    if (partName == "Builder")
                    {
                        GameObject spawnedBlock = Instantiate(Tracker.NetworkBlocks[j], Vector3.zero, Quaternion.identity);
                        spawnedBlock.name = Tracker.NetworkBlocks[j].name;
                        NetworkServer.Spawn(spawnedBlock);
                        spawnedBlock.transform.parent                                = transform.root;
                        spawnedBlock.transform.localPosition                         = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[2]);
                        spawnedBlock.transform.localEulerAngles                      = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Rotation[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Rotation[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Rotation[2]);
                        theShipSchematic.TrackedBlocks[MissingPartsID[i]]            = spawnedBlock;
                        spawnedBlock.GetComponent <ShipAdjacentCheck>().BeingGrabbed = false;

                        //Physics
                        spawnedBlock.layer = LayerMask.NameToLayer("Attached");
                        ApplyLayerToChilds(spawnedBlock.transform, "Attached");
                        spawnedBlock.GetComponent <Rigidbody>().isKinematic    = true;
                        spawnedBlock.GetComponent <BoxCollider>().isTrigger    = false;
                        spawnedBlock.GetComponent <NetworkTransform>().enabled = false;

                        //Rpc info
                        GameObject rpcGrabbedObject = spawnedBlock;
                        GameObject rpcRoot          = transform.root.gameObject;
                        Vector3    rpcPosition      = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Position[2]);
                        Vector3    rpcRotation      = new Vector3(theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Rotation[0], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Rotation[1], theShipSchematic.GetSchematic().Parts[MissingPartsID[i]].Rotation[2]);

                        if (GrabTarget != null)
                        {
                            GrabTarget.GetComponent <ShipAdjacentCheck>().BeingGrabbed = false;
                        }

                        //Loop
                        checkAdjacent = true;

                        //Cancel
                        theShipSchematic.TrackedBlockRegenTimers[MissingPartsID[i]] = 0;
                        MissingPartsID.RemoveAt(i);
                        GrabTargetPartID = -1;
                        GrabTarget       = null;
                        checkAdjacent    = true;
                        i -= 1;
                        RpcRegen(rpcGrabbedObject, rpcRoot, rpcPosition, rpcRotation);
                        break;
                    }
                }
                if (checkAdjacent)
                {
                    transform.root.GetComponent <ShipMeshCombine>().RequestCombine();
                    theShipSchematic.RequestAdjacentCheck();
                }
            }
        }
        return(retVal);
    }