コード例 #1
0
 private void Start()
 {
     if (showDebug)
     {
         Debug.Log(base.name + " Start ");
     }
     alignmentTransform = base.transform;
     startSocket        = connectedSocket;
     if (startSocket != null)
     {
         Connect(connectedSocket);
     }
     if (!(CircuitSounds.instance == null))
     {
         return;
     }
     if (showDebug)
     {
         Debug.Log(base.name + " Trying to make instance ");
     }
     if (instanceofCircuitSounds != null)
     {
         if (showDebug)
         {
             Debug.Log(base.name + " Circuit Sounds gameobject set ");
         }
         Object.Instantiate(instanceofCircuitSounds);
     }
 }
コード例 #2
0
        private SpringJoint Attach(PowerSocket socket, Vector3 anchor, Vector3 connectedAnchor)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " Attach ");
            }
            SpringJoint springJoint = base.gameObject.AddComponent <SpringJoint>();

            springJoint.anchor = base.transform.InverseTransformPoint(anchor);
            springJoint.autoConfigureConnectedAnchor = false;
            Rigidbody componentInParent = socket.GetComponentInParent <Rigidbody>();

            if (componentInParent != null)
            {
                springJoint.connectedBody   = componentInParent;
                springJoint.connectedAnchor = componentInParent.transform.InverseTransformPoint(connectedAnchor);
                springJoint.enableCollision = true;
            }
            else
            {
                springJoint.connectedAnchor = connectedAnchor;
            }
            springJoint.spring = spring;
            springJoint.damper = damper;
            return(springJoint);
        }
コード例 #3
0
        private void Disconnect()
        {
            if (showDebug)
            {
                Debug.Log(base.name + " Disconnect ");
            }
            Circuit.Disconnect(this);
            SignalScriptNode1 component = GetComponent <SignalScriptNode1>();

            if (component != null)
            {
                component.SendSignal(2f);
            }
            Object.Destroy(springIn);
            Object.Destroy(springOut);
            ignoreSocketConnect = connectedSocket;
            connectedSocket     = null;
        }
コード例 #4
0
        public static PowerSocket Scan(Vector3 pos)
        {
            PowerSocket result = null;
            float       num    = 0f;

            for (int i = 0; i < all.Count; i++)
            {
                PowerSocket powerSocket = all[i];
                float       num2        = 1f - (pos - powerSocket.transform.position).magnitude / powerSocket.radius;
                if (!(num2 < 0f))
                {
                    num2 = Mathf.Pow(num2, powerSocket.power);
                    if (num < num2)
                    {
                        num    = num2;
                        result = powerSocket;
                    }
                }
            }
            return(result);
        }
コード例 #5
0
        public void ApplyState(NetStream state)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " Apply State ");
            }
            uint        num         = state.ReadNetId();
            PowerSocket powerSocket = (num == 0) ? null : PowerSocket.FindById(num);

            if (connectedSocket != powerSocket)
            {
                if (connectedSocket != null)
                {
                    Disconnect();
                }
                if (powerSocket != null)
                {
                    Connect(powerSocket);
                }
            }
        }
コード例 #6
0
        private bool Connect(PowerSocket scan)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " Connect ");
            }
            SignalScriptNode1 component = GetComponent <SignalScriptNode1>();

            if (component != null)
            {
                component.SendSignal(1f);
            }
            if (!Circuit.Connect(this, scan))
            {
                ignoreSocketConnect = scan;
                return(false);
            }
            connectedSocket = scan;
            springIn        = Attach(scan, alignmentTransform.position + torque * alignmentTransform.forward, connectedSocket.transform.position + (torque + tensionDistance) * connectedSocket.transform.forward);
            springOut       = Attach(scan, alignmentTransform.position - torque * alignmentTransform.forward, connectedSocket.transform.position - (torque + tensionDistance / 2f) * connectedSocket.transform.forward);
            return(true);
        }
コード例 #7
0
        private void FixedUpdate()
        {
            if (ReplayRecorder.isPlaying || NetGame.isClient)
            {
                return;
            }
            bool flag = false;

            if (grablist.Length != 0)
            {
                for (int i = 0; i < grablist.Length; i++)
                {
                    if (GrabManager.IsGrabbedAny(grablist[i]))
                    {
                        flag = true;
                    }
                }
            }
            if (flag && connectedSocket == null)
            {
                PowerSocket powerSocket = PowerSocket.Scan(alignmentTransform.position);
                if (powerSocket != null && powerSocket != ignoreSocketConnect && powerSocket.connected == null)
                {
                    if (Connect(powerSocket))
                    {
                        if (parent.current != 0f)
                        {
                            SendPlug(PlugEventType.PlugPower);
                        }
                        else
                        {
                            SendPlug(PlugEventType.PlugNoPower);
                        }
                        canBreak    = false;
                        breakableIn = breakDelay;
                        return;
                    }
                    Collider[] array = Physics.OverlapSphere(base.transform.position, 5f);
                    for (int j = 0; j < array.Length; j++)
                    {
                        Rigidbody componentInParent = array[j].GetComponentInParent <Rigidbody>();
                        if (componentInParent != null && !componentInParent.isKinematic)
                        {
                            componentInParent.AddExplosionForce(20000f, base.transform.position, 5f);
                            Human componentInParent2 = componentInParent.GetComponentInParent <Human>();
                            if (componentInParent2 != null)
                            {
                                componentInParent2.MakeUnconscious();
                            }
                        }
                    }
                    SendPlug(PlugEventType.Short);
                }
            }
            if (!flag)
            {
                ignoreSocketConnect = null;
                canBreak            = true;
            }
            if (breakableIn > 0f)
            {
                breakableIn -= Time.fixedDeltaTime;
                return;
            }
            if (reattachableIn > 0f)
            {
                reattachableIn -= Time.fixedDeltaTime;
                if (reattachableIn < 0f)
                {
                    ignoreSocketConnect = null;
                }
            }
            if (!(connectedSocket != null))
            {
                return;
            }
            springIn.spring  = ((!flag) ? spring : (spring / 2f));
            springOut.spring = ((!flag) ? spring : (spring / 2f));
            float num = (alignmentTransform.position - alignmentTransform.forward * dispacementTolerance - connectedSocket.transform.position).magnitude - dispacementTolerance;

            if (springIn != null && springOut != null && num > breakTreshold)
            {
                if (parent.current != 0f)
                {
                    SendPlug(PlugEventType.UnplugPower);
                }
                else
                {
                    SendPlug(PlugEventType.UnplugNoPower);
                }
                Disconnect();
                reattachableIn = reattachDelay;
            }
        }