コード例 #1
0
        static LookPoints GetLookPoints(vLookTarget lookTarget)
        {
            LookPoints points        = new LookPoints();
            var        centerArea    = lookTarget.centerArea;
            var        sizeArea      = lookTarget.sizeArea;
            var        lookTransform = lookTarget.transform;

            points.frontTopLeft     = new Vector3(centerArea.x - sizeArea.x, centerArea.y + sizeArea.y, centerArea.z - sizeArea.z);
            points.frontTopRight    = new Vector3(centerArea.x + sizeArea.x, centerArea.y + sizeArea.y, centerArea.z - sizeArea.z);
            points.frontBottomLeft  = new Vector3(centerArea.x - sizeArea.x, centerArea.y - sizeArea.y, centerArea.z - sizeArea.z);
            points.frontBottomRight = new Vector3(centerArea.x + sizeArea.x, centerArea.y - sizeArea.y, centerArea.z - sizeArea.z);
            points.backTopLeft      = new Vector3(centerArea.x - sizeArea.x, centerArea.y + sizeArea.y, centerArea.z + sizeArea.z);
            points.backTopRight     = new Vector3(centerArea.x + sizeArea.x, centerArea.y + sizeArea.y, centerArea.z + sizeArea.z);
            points.backBottomLeft   = new Vector3(centerArea.x - sizeArea.x, centerArea.y - sizeArea.y, centerArea.z + sizeArea.z);
            points.backBottomRight  = new Vector3(centerArea.x + sizeArea.x, centerArea.y - sizeArea.y, centerArea.z + sizeArea.z);

            points.frontTopLeft     = lookTransform.TransformPoint(points.frontTopLeft);
            points.frontTopRight    = lookTransform.TransformPoint(points.frontTopRight);
            points.frontBottomLeft  = lookTransform.TransformPoint(points.frontBottomLeft);
            points.frontBottomRight = lookTransform.TransformPoint(points.frontBottomRight);
            points.backTopLeft      = lookTransform.TransformPoint(points.backTopLeft);
            points.backTopRight     = lookTransform.TransformPoint(points.backTopRight);
            points.backBottomLeft   = lookTransform.TransformPoint(points.backBottomLeft);
            points.backBottomRight  = lookTransform.TransformPoint(points.backBottomRight);
            return(points);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            var oldSkin = GUI.skin;

            serializedObject.Update();

            if (skin != null)
            {
                GUI.skin = skin;
            }
            vLookTarget lTarget = (vLookTarget)target;

            GUILayout.BeginVertical("Look Target", "window");

            GUILayout.Space(30);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script"));
            EditorGUILayout.HelpBox("This component works with the vHeadTrack. Create a Collider and check the Trigger option to limit the area range to detect with the vHeadTrack if this object can be look at. Make sure to add the tag in the tagsToDetect list", MessageType.Info);
            GUILayout.Space(10);
            lTarget.ignoreHeadTrackAngle = EditorGUILayout.Toggle("Ignore HeadTrack Angle Limit", lTarget.ignoreHeadTrackAngle);
            lTarget.visibleCheckType     = (vLookTarget.VisibleCheckType)EditorGUILayout.EnumPopup("Visible check type", lTarget.visibleCheckType);
            lTarget.lookPointTarget      = (Transform)EditorGUILayout.ObjectField("LookPointTarget", lTarget.lookPointTarget, typeof(Transform), true);
            lTarget.useLimitToDetect     = EditorGUILayout.Toggle("Use Limit To Detect", lTarget.useLimitToDetect);
            if (lTarget.useLimitToDetect)
            {
                lTarget.minDistanceToDetect = EditorGUILayout.FloatField("Min Distance To Detect", lTarget.minDistanceToDetect);
            }
            EditorGUILayout.HelpBox("The LookPointTarget is actual position that your character will look at.", MessageType.Info);

            if (lTarget.visibleCheckType != vLookTarget.VisibleCheckType.None)
            {
                GUILayout.BeginVertical("box");
                GUILayout.Box("Area to check if is visible", GUILayout.ExpandWidth(true));
                lTarget.centerArea = EditorGUILayout.Vector3Field("Center Area", lTarget.centerArea);
                if (lTarget.visibleCheckType == vLookTarget.VisibleCheckType.BoxCast)
                {
                    lTarget.sizeArea = EditorGUILayout.Vector3Field("Size Area", lTarget.sizeArea);
                    EditorGUILayout.HelpBox("The box area is usage for multiple  raycast for box corners", MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox("The center area is usage for single raycast\n See the green sphere gizmo", MessageType.Info);
                }
                GUILayout.EndVertical();
            }
            lTarget.HideObject = EditorGUILayout.Toggle("Is Hide", lTarget.HideObject);
            GUI.skin           = oldSkin;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onEnterLook"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onExitLook"));
            GUILayout.EndVertical();
            serializedObject.ApplyModifiedProperties();
            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
            GUI.skin = oldSkin;
        }
コード例 #3
0
        /// <summary>
        /// Check if anny corner points of LookTarget area is visible from observer
        /// </summary>
        /// <param name="lookTarget">principal transform of lookTarget</param>
        /// <param name="from">observer point</param>
        /// <param name="debug">Draw lines </param>
        /// <returns></returns>
        public static bool IsVisible(this vLookTarget lookTarget, Vector3 from, bool debug = false)
        {
            if (lookTarget.HideObject)
            {
                return(false);
            }
            LookPoints points = GetLookPoints(lookTarget);

            if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.None)
            {
                return(true);
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.SingleCast)
            {
                if (CastPoint(from, lookTarget.transform.TransformPoint(lookTarget.centerArea), lookTarget.transform, debug))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.BoxCast)
            {
                if (CastPoint(from, points.frontTopLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontTopRight, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomRight, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopRight, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomRight, lookTarget.transform, debug))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Check if anny corner points of LookTarget area is visible from observer
        /// </summary>
        /// <param name="lookTarget">principal transform of lookTarget</param>
        /// <param name="from">observer point</param>
        /// <param name="layerMask">Layer to check</param>
        /// <param name="debug">Draw lines </param>
        /// <returns></returns>
        public static bool IsVisible(this vLookTarget lookTarget, Vector3 from, LayerMask layerMask, bool debug = false)
        {
            if (lookTarget.HideObject)
            {
                return(false);
            }

            if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.None)
            {
                if (lookTarget.useLimitToDetect && Vector3.Distance(from, lookTarget.transform.position) > lookTarget.minDistanceToDetect)
                {
                    return(false);
                }

                return(true);
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.SingleCast)
            {
                if (lookTarget.useLimitToDetect && Vector3.Distance(from, lookTarget.centerArea) > lookTarget.minDistanceToDetect)
                {
                    return(false);
                }
                if (CastPoint(from, lookTarget.transform.TransformPoint(lookTarget.centerArea), lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.BoxCast)
            {
                if (lookTarget.useLimitToDetect && Vector3.Distance(from, lookTarget.transform.position) > lookTarget.minDistanceToDetect)
                {
                    return(false);
                }
                LookPoints points = GetLookPoints(lookTarget);

                if (CastPoint(from, points.frontTopLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontTopRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }
            }
            return(false);
        }