예제 #1
0
 /// <summary>
 /// This method is called when a socket change state.
 /// </summary>
 public static void SocketChangedState(SocketBehaviour socket, OccupancyType occupancy)
 {
     if (OnSocketChangedState != null)
     {
         OnSocketChangedState.Invoke(socket, occupancy);
     }
 }
예제 #2
0
 /// <summary>
 /// This method is called when a part is placed.
 /// </summary>
 public static void PlacedPart(PartBehaviour part, SocketBehaviour socket)
 {
     if (OnPlacedPart != null)
     {
         OnPlacedPart.Invoke(part, socket);
     }
 }
예제 #3
0
        private void OnEnable()
        {
            Target = (SocketBehaviour)target;

            MainEditor.LoadAddons(Target, AddOnTarget.SocketBehaviour);

            Target.PartOffsets = Target.PartOffsets.ToList().OrderBy(item => item.Part.Id).ToList();
        }
예제 #4
0
 public void AttachToSocket(GameObject socket, SocketBehaviour sb)
 {
     this.sb       = sb;
     CurrentLength = maxLength; //(socket.transform.position - cordBase.transform.position).magnitude;
     AddRopePoint(socket.transform.position, socket.transform);
     transform.SetParent(socket.transform);
     isHooked = true;
 }
예제 #5
0
        /// <summary>
        /// This method allows to remove a socket from the manager cache.
        /// </summary>
        public void RemoveSocket(SocketBehaviour socket)
        {
            if (socket == null)
            {
                return;
            }

            Sockets.Remove(socket);
        }
예제 #6
0
        /// <summary>
        /// This method allows to add a socket from the manager cache.
        /// </summary>
        public void AddSocket(SocketBehaviour socket)
        {
            if (socket == null)
            {
                return;
            }

            Sockets.Add(socket);
        }
    private void OnPartPlaced(PartBehaviour part, SocketBehaviour socket)
    {
        if (part.GetComponent <AddonRemoveGrass>() == null)
        {
            return;
        }

        if (RemoveGrass)
        {
            StartCoroutine(RemoveGrassToPosition(part.transform.position, RemoveGrassRadius));
        }
    }
예제 #8
0
    static void Main(string[] args)
    {
        Documentation_SRB_ToByteArray_Pbap();
        new MiscFeatureTestCsXXXX.Documentation().Discovery2F();
        Documentation_SRB_Simple();
        chaosaSrb2();
        //xxxTrySockets();
        Parse();
        //
        Trace.Fail("continue?");
        SocketBehaviour.MyMain();
        //
        jarmhartWorkee();
        jarmhartOrig();
        ServiceElement e;

        e = new ServiceElement(ElementType.TextString, "Hello world");
        e = new ServiceElement(ElementType.TextString, new byte[] { (byte)'h', (byte)'i', });
        e = new ServiceElement(ElementType.Uuid16, (UInt16)0x1101);
    }
예제 #9
0
    private void OnPartPlaced(PartBehaviour part, SocketBehaviour socket)
    {
        if (BuildManager.Instance.BuildingSupport != SupportType.TerrainCollider)
        {
            return;
        }

        if (part.GetComponent <AddonRemoveGrass>() == null)
        {
            return;
        }

        if (RemoveGrass)
        {
            if (!TerrainManager.Instance.CheckDetailtAt(transform.position, RemoveGrassRadius))
            {
                return;
            }

            StartCoroutine(RemoveGrassToPosition(part.transform.position, RemoveGrassRadius));
        }
    }
예제 #10
0
        /// <summary>
        /// This method allows to create a preview.
        /// </summary>
        public virtual PartBehaviour CreatePreview(GameObject prefab)
        {
            if (prefab == null)
            {
                return(null);
            }

            CurrentPreview = Instantiate(prefab).GetComponent <PartBehaviour>();
            CurrentPreview.transform.eulerAngles = Vector3.zero;
            CurrentRotationOffset = Vector3.zero;

            if (Physics.Raycast(GetRay(), out RaycastHit Hit, Mathf.Infinity, BuildManager.Instance.FreeLayers, QueryTriggerInteraction.Ignore))
            {
                CurrentPreview.transform.position = Hit.point;
            }

            CurrentPreview.ChangeState(StateType.Preview);

            SelectedPrefab = prefab.GetComponent <PartBehaviour>();

            if (UsePreviewCamera == true)
            {
                CurrentPreview.gameObject.SetLayerRecursively(PreviewLayer);
            }

            EventHandlers.PreviewCreated(CurrentPreview);

            CurrentSocket = null;

            LastSocket = null;

            AllowPlacement = false;

            HasSocket = false;

            return(CurrentPreview);
        }
예제 #11
0
        /// <summary>
        /// Inicializar servidor socket en un puerto determinado
        /// </summary>
        /// <param name="port">Puerto a utilizar</param>
        public SocketServer(int port = 555)
        {
            var  config = ConfigurationManager.Get <ISocketAdapterConfiguration>();
            bool secure = Helper.SSL.Status == SSLCertificateStatus.Loaded && !config.OverrideSecure;

            m_webSocketServer = new WebSocketServer(port, secure);
            if (secure)
            {
                m_webSocketServer.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
                m_webSocketServer.SslConfiguration.ServerCertificate   = Helper.SSL.GlobalCertificate;
                Debug.WriteLine(this, "Inicializando SocketServer con SSL", VerbosityLevel.Info);
            }

            m_webSocketServer.AddWebSocketService("/", () =>
            {
                var socketBehaviour = new SocketBehaviour();

                socketBehaviour.OnSocketOpen  += (s, e) => OnSocketOpen?.Invoke(this, e);
                socketBehaviour.OnSocketClose += (s, e) => OnSocketClose?.Invoke(this, e);

                return(socketBehaviour);
            });
            m_webSocketServer.Start();
        }
예제 #12
0
 private void OnPlacedPart(PartBehaviour part, SocketBehaviour socket)
 {
     UpdateMeshData();
 }
예제 #13
0
        /// <summary>
        /// This method allows to update the placement preview.
        /// </summary>
        public void UpdatePreview()
        {
            HasSocket = false;

            if (CameraType == RayType.TopDown)
            {
                Physics.Raycast(GetRay(), out TopDownHit, Mathf.Infinity, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()), QueryTriggerInteraction.Ignore);
            }

            if (RayDetection == DetectionType.Overlap)
            {
                SocketBehaviour[] Sockets =
                    PhysicExtension.GetNeighborsTypesBySphere <SocketBehaviour>(GetTransform.position, ActionDistance,
                                                                                LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()));

                if (Sockets.Length > 0)
                {
                    UpdateSnapsMovement(Sockets);
                }
                else
                {
                    UpdateFreeMovement();
                }
            }
            else
            {
                SocketBehaviour Socket = null;

                if (Physics.Raycast(GetRay(), out RaycastHit Hit, ActionDistance, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower())))
                {
                    if (Hit.collider.GetComponent <SocketBehaviour>() != null)
                    {
                        Socket = Hit.collider.GetComponent <SocketBehaviour>();
                    }
                }

                Debug.Log(Socket);

                if (Socket != null)
                {
                    UpdateSnapsMovement(new SocketBehaviour[1] {
                        Socket
                    });
                }
                else
                {
                    UpdateFreeMovement();
                }
            }

            if (CurrentMode == BuildMode.Placement || CurrentMode == BuildMode.Edition)
            {
                foreach (SocketBehaviour Socket in BuildManager.Instance.Sockets)
                {
                    if (Socket != null)
                    {
                        Socket.EnableColliderByPartType(SelectedPrefab.Type);
                    }
                }
            }

            AllowPlacement = !HasCollision();

            if (AllowPlacement && CurrentPreview.RequireSockets && !HasSocket)
            {
                AllowPlacement = false;
            }

            if (AllowPlacement && OutOfRangeDistance != 0)
            {
                AllowPlacement = Vector3.Distance(GetTransform.position, CurrentPreview.transform.position) < ActionDistance;
            }

            CurrentPreview.gameObject.ChangeAllMaterialsColorInChildren(CurrentPreview.Renderers.ToArray(),
                                                                        AllowPlacement ? BuildManager.Instance.PreviewAllowedColor : BuildManager.Instance.PreviewDeniedColor, SelectedPrefab.PreviewColorLerpTime, SelectedPrefab.PreviewUseColorLerpTime);
        }
예제 #14
0
        /// <summary>
        /// This method allows to place a part.
        /// </summary>
        public PartBehaviour PlacePrefab(PartBehaviour part, Vector3 position, Vector3 rotation, Vector3 scale, GroupBehaviour group = null, SocketBehaviour socket = null)
        {
            GameObject PlacedTemp = Instantiate(part.gameObject, position, Quaternion.Euler(rotation));

            PlacedTemp.transform.localScale = scale;

            PartBehaviour PlacedPart = PlacedTemp.GetComponent <PartBehaviour>();

            if (group == null)
            {
                if (socket != null)
                {
                    if (socket.AttachedPart.HasGroup)
                    {
                        PlacedTemp.transform.SetParent(socket.AttachedPart.transform.parent, true);
                    }
                }
                else
                {
                    GameObject Group = new GameObject("Group (" + PlacedPart.GetInstanceID() + ")", typeof(GroupBehaviour));

                    PlacedTemp.transform.SetParent(Group.transform, true);
                }
            }
            else
            {
                PlacedTemp.transform.SetParent(group.transform, true);
            }

            PlacedPart.EntityInstanceId = PlacedPart.GetInstanceID();

            EventHandlers.PlacedPart(PlacedPart, socket);

            PlacedPart.ChangeState(DefaultState);

            return(PlacedPart);
        }
예제 #15
0
        /// <summary>
        /// This method allows to place the current preview.
        /// </summary>
        public virtual void PlacePrefab()
        {
            if (!AllowPlacement)
            {
                return;
            }

            if (CurrentPreview == null)
            {
                return;
            }

            if (CurrentEditionPreview != null)
            {
                Destroy(CurrentEditionPreview.gameObject);
            }

            if (UseForNetwork)
            {
                BuildManager.Instance.PlacePrefabForNetwork(SelectedPrefab,
                                                            CurrentPreview.transform.position,
                                                            CurrentPreview.transform.eulerAngles,
                                                            CurrentPreview.transform.localScale);
            }
            else
            {
                BuildManager.Instance.PlacePrefab(SelectedPrefab,
                                                  CurrentPreview.transform.position,
                                                  CurrentPreview.transform.eulerAngles,
                                                  CurrentPreview.transform.localScale,
                                                  null,
                                                  CurrentSocket);
            }

            if (Source != null)
            {
                if (PlacementClips.Length != 0)
                {
                    Source.PlayOneShot(PlacementClips[Random.Range(0, PlacementClips.Length)]);
                }
            }

            CurrentRotationOffset = Vector3.zero;

            CurrentSocket = null;

            LastSocket = null;

            AllowPlacement = false;

            HasSocket = false;

            if (CurrentMode == BuildMode.Placement && ResetModeAfterPlacement)
            {
                ChangeMode(BuildMode.None);
            }

            if (CurrentPreview != null)
            {
                Destroy(CurrentPreview.gameObject);
            }
        }
예제 #16
0
        /// <summary>
        /// This method allows to move the preview only on available socket(s).
        /// </summary>
        public void UpdateSnapsMovement(SocketBehaviour[] sockets)
        {
            if (CurrentPreview == null)
            {
                return;
            }

            float ClosestAngle = Mathf.Infinity;

            CurrentSocket = null;

            for (int i = 0; i < sockets.Length; i++)
            {
                PartBehaviour Part = sockets[i].AttachedPart;

                if (Part == null || Part.Sockets.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < Part.Sockets.Length; x++)
                {
                    SocketBehaviour Socket = RayDetection == DetectionType.Overlap ? Part.Sockets[x] : sockets[i];

                    if (Socket != null)
                    {
                        if (Socket.gameObject.activeSelf && !Socket.IsDisabled)
                        {
                            if (Socket.AllowPart(SelectedPrefab) && !Part.AvoidAnchoredOnSocket)
                            {
                                if (RayDetection == DetectionType.Overlap)
                                {
                                    if ((Socket.transform.position - (CameraType != RayType.TopDown ? GetTransform.position : TopDownHit.point)).sqrMagnitude <
                                        Mathf.Pow(CameraType != RayType.TopDown ? ActionDistance : SnapThreshold, 2))
                                    {
                                        float Angle = Vector3.Angle(GetRay().direction, Socket.transform.position - GetRay().origin);

                                        if (Angle < ClosestAngle && Angle < OverlapAngles)
                                        {
                                            ClosestAngle = Angle;

                                            if (CameraType != RayType.TopDown && CurrentSocket == null)
                                            {
                                                CurrentSocket = Socket;
                                            }
                                            else
                                            {
                                                CurrentSocket = Socket;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    CurrentSocket = Socket;
                                }
                            }
                        }
                    }
                }
            }

            if (CurrentSocket != null)
            {
                PartOffset Offset = CurrentSocket.GetOffsetPart(SelectedPrefab.Id);

                if (CurrentSocket.CheckOccupancy(SelectedPrefab))
                {
                    return;
                }

                if (Offset != null)
                {
                    CurrentPreview.transform.position = CurrentSocket.transform.position + CurrentSocket.transform.TransformVector(Offset.Position);

                    CurrentPreview.transform.rotation = CurrentSocket.transform.rotation * (CurrentPreview.RotateOnSockets ? Quaternion.Euler(Offset.Rotation + CurrentRotationOffset) : Quaternion.Euler(Offset.Rotation));

                    if (Offset.UseCustomScale)
                    {
                        CurrentPreview.transform.localScale = Offset.Scale;
                    }

                    LastSocket = CurrentSocket;

                    HasSocket = true;

                    return;
                }
            }

            UpdateFreeMovement();
        }
예제 #17
0
        public void UpdateFreeMovement()
        {
            if (CurrentPreview == null)
            {
                return;
            }

            float Distance = OutOfRangeDistance == 0 ? ActionDistance : OutOfRangeDistance;

            if (Physics.Raycast(GetRay(), out RaycastHit Hit, Distance, BuildManager.Instance.FreeLayers))
            {
                if (PreviewMovementType == MovementType.Normal)
                {
                    if (PreviewMovementOnlyAllowed)
                    {
                        CurrentPreview.transform.position = Hit.point + CurrentPreview.PreviewOffset;

                        if (!HasCollision())
                        {
                            lastAllowedPosition = Hit.point + CurrentPreview.PreviewOffset;
                        }
                        else
                        {
                            CurrentPreview.transform.position = lastAllowedPosition;
                        }
                    }
                    else
                    {
                        CurrentPreview.transform.position = Hit.point + CurrentPreview.PreviewOffset;
                    }
                }
                else if (PreviewMovementType == MovementType.Grid)
                {
                    CurrentPreview.transform.position = MathExtension.PositionToGridPosition(PreviewGridSize, PreviewGridOffset, Hit.point + CurrentPreview.PreviewOffset);
                }
                else if (PreviewMovementType == MovementType.Smooth)
                {
                    CurrentPreview.transform.position = Vector3.Lerp(CurrentPreview.transform.position, Hit.point + CurrentPreview.PreviewOffset, PreviewSmoothTime * Time.deltaTime);
                }

                if (!CurrentPreview.RotateAccordingSlope)
                {
                    if (LockRotation)
                    {
                        CurrentPreview.transform.rotation = GetTransform.rotation * SelectedPrefab.transform.localRotation * Quaternion.Euler(CurrentRotationOffset);
                    }
                    else
                    {
                        CurrentPreview.transform.rotation = Quaternion.Euler(CurrentRotationOffset);
                    }
                }
                else
                {
                    if (Hit.collider is TerrainCollider)
                    {
                        float SampleHeight = Hit.collider.GetComponent <UnityEngine.Terrain>().SampleHeight(Hit.point);

                        if (Hit.point.y - .1f < SampleHeight)
                        {
                            CurrentPreview.transform.rotation = Quaternion.FromToRotation(GetTransform.up, Hit.normal) * Quaternion.Euler(CurrentRotationOffset)
                                                                * GetTransform.rotation * SelectedPrefab.transform.localRotation * Quaternion.Euler(CurrentRotationOffset);
                        }
                        else
                        {
                            CurrentPreview.transform.rotation = GetTransform.rotation * SelectedPrefab.transform.localRotation * Quaternion.Euler(CurrentRotationOffset);
                        }
                    }
                    else
                    {
                        CurrentPreview.transform.rotation = GetTransform.rotation * SelectedPrefab.transform.localRotation * Quaternion.Euler(CurrentRotationOffset);
                    }
                }

                return;
            }

            if (LockRotation)
            {
                CurrentPreview.transform.rotation = GetTransform.rotation * SelectedPrefab.transform.localRotation * Quaternion.Euler(CurrentRotationOffset);
            }
            else
            {
                CurrentPreview.transform.rotation = Quaternion.Euler(CurrentRotationOffset);
            }

            Transform StartTransform = (CurrentPreview.GroundUpperHeight == 0) ? GetTransform : BuilderCamera.transform;

            Vector3 LookDistance = StartTransform.position + StartTransform.forward * Distance;

            if (CurrentPreview.UseGroundUpper)
            {
                LookDistance.y = Mathf.Clamp(LookDistance.y, GetTransform.position.y - CurrentPreview.GroundUpperHeight,
                                             GetTransform.position.y + CurrentPreview.GroundUpperHeight);
            }
            else
            {
                if (!CurrentPreview.FreePlacement)
                {
                    if (Physics.Raycast(CurrentPreview.transform.position + new Vector3(0, 0.3f, 0),
                                        Vector3.down, out Hit, Mathf.Infinity, BuildManager.Instance.FreeLayers, QueryTriggerInteraction.Ignore))
                    {
                        LookDistance.y = Hit.point.y;
                    }
                }
                else
                {
                    LookDistance.y = Mathf.Clamp(LookDistance.y, GetTransform.position.y,
                                                 GetTransform.position.y);
                }
            }

            if (PreviewMovementType == MovementType.Normal)
            {
                CurrentPreview.transform.position = LookDistance;
            }
            else if (PreviewMovementType == MovementType.Grid)
            {
                CurrentPreview.transform.position = MathExtension.PositionToGridPosition(PreviewGridSize, PreviewGridOffset, LookDistance + CurrentPreview.PreviewOffset);
            }
            else if (PreviewMovementType == MovementType.Smooth)
            {
                CurrentPreview.transform.position = Vector3.Lerp(CurrentPreview.transform.position, LookDistance, PreviewSmoothTime * Time.deltaTime);
            }

            CurrentSocket = null;

            LastSocket = null;

            HasSocket = false;
        }