Beispiel #1
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        RaycastModifier ob = target as RaycastModifier;

#if UNITY_LE_4_3
        EditorGUI.indentLevel = 1;
#else
        EditorGUI.indentLevel = 0;
        Undo.RecordObject(ob, "modify settings on Raycast Modifier");
#endif

        if (ob.iterations < 0)
        {
            ob.iterations = 0;
        }

        ob.useRaycasting = EditorGUILayout.Toggle(new GUIContent("Use Physics Raycasting"), ob.useRaycasting);

        if (ob.useRaycasting)
        {
            EditorGUI.indentLevel++;
            ob.thickRaycast = EditorGUILayout.Toggle(new GUIContent("Use Thick Raycast", "Checks around the line between two points, not just the exact line.\n" +
                                                                    "Make sure the ground is either too far below or is not inside the mask since otherwise the raycast might always hit the ground"), ob.thickRaycast);
            if (ob.thickRaycast)
            {
                EditorGUI.indentLevel++;
                ob.thickRaycastRadius = EditorGUILayout.FloatField(new GUIContent("Thick Raycast Radius"), ob.thickRaycastRadius);
                if (ob.thickRaycastRadius < 0)
                {
                    ob.thickRaycastRadius = 0;
                }
                EditorGUI.indentLevel--;
            }

#if UNITY_LE_4_3
            ob.raycastOffset = EditorGUILayout.Vector3Field("Raycast Offset", ob.raycastOffset);
#else
            ob.raycastOffset = EditorGUILayout.Vector3Field(new GUIContent("Raycast Offset", "Offset from the original positions to perform the raycast.\n" +
                                                                           "Can be useful to avoid the raycast intersecting the ground or similar things you do not want to it intersect."), ob.raycastOffset);
#endif
            EditorGUILayout.PropertyField(serializedObject.FindProperty("mask"));

            EditorGUI.indentLevel--;
        }

        ob.useGraphRaycasting = EditorGUILayout.Toggle(new GUIContent("Use Graph Raycasting", "Raycasts on the graph to see if it hits any unwalkable nodes"), ob.useGraphRaycasting);

        ob.subdivideEveryIter = EditorGUILayout.Toggle(new GUIContent("Subdivide Every Iteration", "Subdivides the path every iteration to be able to find shorter paths"), ob.subdivideEveryIter);

        Color preCol = GUI.color;
        GUI.color  *= new Color(1, 1, 1, 0.5F);
        ob.Priority = EditorGUILayout.IntField(new GUIContent("Priority", "Higher priority modifiers are executed first\nAdjust this in Seeker-->Modifier Priorities"), ob.Priority);
        GUI.color   = preCol;

        if (ob.gameObject.GetComponent <Seeker> () == null)
        {
            EditorGUILayout.HelpBox("No seeker found, modifiers are usually used together with a Seeker component", MessageType.Warning);
        }
    }
Beispiel #2
0
    public void Init_Server(float speed)
    {
        _speed = new SKU.Attribute(speed);
        GetComponent <AttributeManager>().Add(AttributeType.Speed, _speed);

        _aiPath = gameObject.AddComponent <AIPath>();
        _aiPath.pickNextWaypointDist = 0.5f;
        AIDestinationSetter destination = gameObject.AddComponent <AIDestinationSetter>();

        destination.target = _end;

        RaycastModifier modifier = gameObject.AddComponent <RaycastModifier>();

        modifier.thickRaycast       = true;
        modifier.thickRaycastRadius = 0.5f;
    }
Beispiel #3
0
        private void BeAutoPath()
        {
            // 增加RVO网格控制
            m_RvoController = gameObject.AddComponent <RVOController>();
            m_RvoController.agentTimeHorizon    = 0.4f; // 检测代理碰撞的时间间隔
            m_RvoController.obstacleTimeHorizon = 0.6f; // 检测其他障碍碰撞的时间间隔
            m_RvoController.collidesWith        = RVOLayer.DefaultAgent;
            m_RvoController.maxNeighbours       = 2;
            m_RvoController.locked = false;

            // 寻路插件
            m_AiPath                         = gameObject.AddComponent <AIPath>();
            m_AiPath.radius                  = GetComponent <CircleCollider2D>().radius;
            m_AiPath.height                  = 1;
            m_AiPath.slowdownDistance        = 0; // 无需减速
            m_AiPath.enableRotation          = true;
            m_AiPath.orientation             = OrientationMode.YAxisForward;
            m_AiPath.slowWhenNotFacingTarget = false;
            m_AiPath.whenCloseToDestination  = CloseToDestinationMode.ContinueToExactDestination;
            m_AiPath.rotationSpeed           = m_RotationSpeed;
            m_AiPath.pickNextWaypointDist    = 1;
            m_AiPath.repathRate              = 0.2f;
            m_AiPath.whenCloseToDestination  = CloseToDestinationMode.Stop;
            // 增加平滑曲线
            m_SimpleSmooth = gameObject.AddComponent <SimpleSmoothModifier>();
            m_SimpleSmooth.maxSegmentLength = 1f;
            m_SimpleSmooth.iterations       = 5;
            RaycastModifier m_raycast = gameObject.AddComponent <RaycastModifier>();

            m_raycast.quality            = RaycastModifier.Quality.Low;
            m_raycast.useRaycasting      = false;
            m_raycast.useGraphRaycasting = true;

            m_Seeker            = GetComponent <Seeker>();
            m_Seeker.drawGizmos = true;

            // 设置初始速度
            m_AiPath.velocity2D = m_RvoController.velocity;

            m_PlayerCompt = Global.gApp.CurScene.GetMainPlayerComp();
            m_PlayerGo    = Global.gApp.CurScene.GetMainPlayer();
        }
Beispiel #4
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUI.indentLevel = 1;

        RaycastModifier ob = target as RaycastModifier;

        ob.useRaycasting = EditorGUILayout.Toggle(new GUIContent("Use Physics Raycasting"), ob.useRaycasting);

        if (ob.useRaycasting)
        {
            EditorGUI.indentLevel++;

            EditorGUI.indentLevel--;
        }

        Color preCol = GUI.color;

        GUI.color  *= new Color(1, 1, 1, 0.5F);
        ob.Priority = EditorGUILayout.IntField(new GUIContent("Priority", "Higher priority modifiers are executed first\nAdjust this in Seeker-->Modifier Priorities"), ob.Priority);
        GUI.color   = preCol;
    }
Beispiel #5
0
        /// <summary>
        /// 僵尸变聪明
        /// </summary>
        public void BeAutoPath()
        {
            m_AutomaticPath = true;
            // 如果不笨则增加寻路算法
            if (m_AiPath == null)
            {
                // 获取碰撞体
                m_collider = GetComponent <CircleCollider2D>();

                // 增加RVO网格控制
                m_rvoController = gameObject.AddComponent <RVOController>();
                m_rvoController.agentTimeHorizon    = 0.4f; // 检测代理碰撞的时间间隔
                m_rvoController.obstacleTimeHorizon = 0.6f; // 检测其他障碍碰撞的时间间隔
                //m_rvoController.collidesWith = (RVOLayer)(-1);
                m_rvoController.collidesWith  = RVOLayer.DefaultAgent;
                m_rvoController.maxNeighbours = 2;
                m_rvoController.locked        = false;

                // 寻路插件
                m_AiPath                         = gameObject.AddComponent <AIPath>();
                m_AiPath.radius                  = GetComponent <CircleCollider2D>().radius;
                m_AiPath.height                  = 1;
                m_AiPath.slowdownDistance        = 0; // 无需减速
                m_AiPath.enableRotation          = true;
                m_AiPath.orientation             = OrientationMode.YAxisForward;
                m_AiPath.slowWhenNotFacingTarget = false;
                m_AiPath.whenCloseToDestination  = CloseToDestinationMode.ContinueToExactDestination;
                m_AiPath.rotationSpeed           = 240 * (m_BaseSpeed / 2.5f);
                m_AiPath.pickNextWaypointDist    = 1;



                // 增加平滑曲线
                m_simpleSmooth = gameObject.AddComponent <SimpleSmoothModifier>();
                m_simpleSmooth.maxSegmentLength = 1f;
                m_simpleSmooth.iterations       = 5;
                RaycastModifier m_raycast = gameObject.AddComponent <RaycastModifier>();
                m_raycast.quality = RaycastModifier.Quality.Low;
                //m_raycast.use2DPhysics = false;
                m_raycast.useRaycasting      = false;
                m_raycast.useGraphRaycasting = true;

                m_seeker               = GetComponent <Seeker>();
                m_seeker.drawGizmos    = false;
                m_seeker.pathCallback += pathCall; // 路径完成后的回调
                Transform targetTsf = GetTargetNode();
                //transform.localEulerAngles = new Vector3(0, 0, EZMath.SignedAngleBetween(m_Player.transform.position - transform.position, Vector3.up));
                m_seeker.StartPath(transform.position, targetTsf.position);

                // 设置初始速度
                m_rvoController.velocity = (targetTsf.position - transform.position).normalized * m_BaseSpeed * m_HitSpeedScale; // 直接设置初始速度
                m_rvoController.SetTarget(targetTsf.position, m_rvoController.velocity.magnitude, m_rvoController.velocity.magnitude);
                m_AiPath.velocity2D = m_rvoController.velocity;

                PathInit.curPathNum++;
            }
            else
            {
                EnablePath();
            }
        }