Ejemplo n.º 1
0
    void InitController()
    {
        destination   = GetComponent <AIDestinationSetter>();
        aipathscript  = GetComponent <AIPath>();
        anim          = GetComponent <Animator>();
        baseCollider  = GetComponent <Collider>();
        baseRigidbody = GetComponent <Rigidbody>();
        con           = GetComponent <StateController>();
        seek          = GetComponent <Seeker>();
        smooth        = GetComponent <SimpleSmoothModifier>();

        currentHealth = enemyStats.Health;

        if (aipathscript != null)
        {
            aipathscript.maxSpeed           = enemyStats.runSpeed;
            aipathscript.endReachedDistance = enemyStats.attackRange;
        }

        if (startPosition == null)
        {
            SetStartPosition(transform);
        }

        if (healthBar != null)
        {
            Vector3 hbPos = new Vector3(transform.position.x, transform.position.y + healthBarOffset, transform.position.z);
            Canvas  hb    = Instantiate(healthBar, hbPos, transform.rotation, transform);
            healthBar    = hb;
            bar          = healthBar.transform.Find("Slider").GetComponent <Slider>();
            bar.maxValue = enemyStats.Health;
            bar.value    = currentHealth;
        }
    }
Ejemplo n.º 2
0
 public List<Vector3> Smooth(List<Vector3> vectorPath, SimpleSmoothModifier.SmoothType smoothType)
 {
     switch (smoothType) {
     default:
         return pathSmoother.SmoothSimple (vectorPath);
     case SimpleSmoothModifier.SmoothType.Bezier:
         return pathSmoother.SmoothBezier (vectorPath);
     case SimpleSmoothModifier.SmoothType.OffsetSimple:
         return pathSmoother.SmoothOffsetSimple (vectorPath);
     case SimpleSmoothModifier.SmoothType.CurvedNonuniform:
         return pathSmoother.CurvedNonuniform (vectorPath);
     }
 }
Ejemplo n.º 3
0
    void InitAStar()
    {
        aStarSeeker = gameObject.AddComponent <Seeker>();
        aStarSeeker.startEndModifier.exactStartPoint = StartEndModifier.Exactness.Exact;
        aStarSeeker.startEndModifier.exactEndPoint   = StartEndModifier.Exactness.Exact;
        aStarSeeker.startEndModifier.mask            = soldierGeneralInfo.pathFindObstacleMask;

        aStarFunnelModifier = gameObject.AddComponent <FunnelModifier>();

        aStarSimpleSmoothModifier = gameObject.AddComponent <SimpleSmoothModifier>();

        aStarSeeker.startEndModifier.priority = 3;
        aStarFunnelModifier.priority          = 2;
        aStarSimpleSmoothModifier.priority    = 1;
    }
Ejemplo n.º 4
0
    public virtual void Die()
    {
        if (isPlayer != true)
        {
            //Destroy(gameObject);


            isAlive = false;
            Bounds b = gameObject.collider.bounds;
            Destroy(gameObject.collider);
            GraphUpdateObject guo = new GraphUpdateObject(b);
            AstarPath.active.UpdateGraphs(guo, 0.0f);
            AstarPath.active.FlushGraphUpdates();
            anim.Play("human_death");
            CharacterController cc = GetComponent(typeof(CharacterController)) as CharacterController;
            cc.enabled   = false;
            this.enabled = false;


            Sapien sa = gameObject.GetComponent <Sapien>();
            if (sa != null)
            {
                Destroy(sa);
            }
            SimpleSmoothModifier ssm = gameObject.GetComponent <SimpleSmoothModifier>();
            if (ssm != null)
            {
                Destroy(ssm);
            }
            Seeker s = gameObject.GetComponent <Seeker>();
            if (s != null)
            {
                Destroy(s);
            }
            CapsuleCollider cap = gameObject.GetComponent <CapsuleCollider>();
            if (cap != null)
            {
                Destroy(cap);
            }
        }
        else
        {
            anim.Play("human_death");
        }
    }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 1;

        SimpleSmoothModifier ob = target as SimpleSmoothModifier;

        ob.smoothType = (SimpleSmoothModifier.SmoothType)EditorGUILayout.EnumPopup(new GUIContent("Smooth Type"), ob.smoothType);

        EditorGUIUtility.LookLikeInspector();

        if (ob.smoothType == SimpleSmoothModifier.SmoothType.Simple)
        {
            ob.uniformLength = EditorGUILayout.Toggle(new GUIContent("Uniform Segment Length", "Toggle to divide all lines in equal length segments"), ob.uniformLength);

            if (ob.uniformLength)
            {
                ob.maxSegmentLength = EditorGUILayout.FloatField(new GUIContent("Max Segment Length", "The length of each segment in the smoothed path. A high value yields rough paths and low value yields very smooth paths, but is slower"), ob.maxSegmentLength);
                ob.maxSegmentLength = ob.maxSegmentLength < 0 ? 0 : ob.maxSegmentLength;
            }
            else
            {
                ob.subdivisions = EditorGUILayout.IntField(new GUIContent("Subdivisions", "The number of times to subdivide (divide in half) the path segments. [0...inf] (recommended [1...10])"), ob.subdivisions);
                if (ob.subdivisions < 0)
                {
                    ob.subdivisions = 0;
                }
            }

            ob.iterations = EditorGUILayout.IntField(new GUIContent("Iterations", "Number of times to apply smoothing"), ob.iterations);
            ob.iterations = ob.iterations < 0 ? 0 : ob.iterations;

            ob.strength = EditorGUILayout.Slider(new GUIContent("Strength", "Determines how much smoothing to apply in each smooth iteration. 0.5 usually produces the nicest looking curves"), ob.strength, 0.0F, 1.0F);
        }
        else if (ob.smoothType == SimpleSmoothModifier.SmoothType.OffsetSimple)
        {
            ob.iterations = EditorGUILayout.IntField(new GUIContent("Iterations", "Number of times to apply smoothing"), ob.iterations);
            ob.iterations = ob.iterations < 0 ? 0 : ob.iterations;
            ob.iterations = ob.iterations > 12 ? 12 : ob.iterations;

            ob.offset = EditorGUILayout.FloatField(new GUIContent("Offset", "Offset to apply in each smoothing iteration"), ob.offset);
            if (ob.offset < 0)
            {
                ob.offset = 0;
            }
        }
        else if (ob.smoothType == SimpleSmoothModifier.SmoothType.Bezier)
        {
            ob.subdivisions = EditorGUILayout.IntField(new GUIContent("Subdivisions", "The number of times to subdivide (divide in half) the path segments. [0...inf] (recommended [1...10])"), ob.subdivisions);
            if (ob.subdivisions < 0)
            {
                ob.subdivisions = 0;
            }

            ob.bezierTangentLength = EditorGUILayout.FloatField(new GUIContent("Tangent Length", "Tangent length factor"), ob.bezierTangentLength);
        }
        else if (ob.smoothType == SimpleSmoothModifier.SmoothType.CurvedNonuniform)
        {
            ob.maxSegmentLength = EditorGUILayout.FloatField(new GUIContent("Max Segment Length", "The length of each segment in the smoothed path. A high value yields rough paths and low value yields very smooth paths, but is slower"), ob.maxSegmentLength);
            ob.maxSegmentLength = ob.maxSegmentLength < 0 ? 0 : ob.maxSegmentLength;
        }
        else
        {
            DrawDefaultInspector();
        }

        //GUILayout.Space (5);

        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;
    }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
0
 public List<Vector3> SmoothPath(List<Vector3> vectorPath, bool likeSlime, SimpleSmoothModifier.SmoothType smoothType = SimpleSmoothModifier.SmoothType.Simple)
 {
     if (likeSlime) {
         return slimeHandler.SmoothLikeSlime (vectorPath);
     }
     return slimeHandler.Smooth (vectorPath, smoothType);
 }
Ejemplo n.º 9
0
    public override void OnInspectorGUI()
    {
#if UNITY_LE_4_3
        EditorGUI.indentLevel = 1;
#else
        EditorGUI.indentLevel = 0;
#endif

        SimpleSmoothModifier ob = target as SimpleSmoothModifier;

        ob.smoothType = (SimpleSmoothModifier.SmoothType)EditorGUILayout.EnumPopup(new GUIContent("Smooth Type"), ob.smoothType);

#if UNITY_LE_4_3
        EditorGUIUtility.LookLikeInspector();
#else
        Undo.RecordObject(ob, "changed settings on Simple Smooth Modifier");
#endif

        if (ob.smoothType == SimpleSmoothModifier.SmoothType.Simple)
        {
            ob.uniformLength = EditorGUILayout.Toggle(new GUIContent("Uniform Segment Length", "Toggle to divide all lines in equal length segments"), ob.uniformLength);

            if (ob.uniformLength)
            {
                ob.maxSegmentLength = EditorGUILayout.FloatField(new GUIContent("Max Segment Length", "The length of each segment in the smoothed path. A high value yields rough paths and low value yields very smooth paths, but is slower"), ob.maxSegmentLength);
                ob.maxSegmentLength = ob.maxSegmentLength < 0 ? 0 : ob.maxSegmentLength;
            }
            else
            {
                ob.subdivisions = EditorGUILayout.IntField(new GUIContent("Subdivisions", "The number of times to subdivide (divide in half) the path segments. [0...inf] (recommended [1...10])"), ob.subdivisions);
                if (ob.subdivisions < 0)
                {
                    ob.subdivisions = 0;
                }
            }

            ob.iterations = EditorGUILayout.IntField(new GUIContent("Iterations", "Number of times to apply smoothing"), ob.iterations);
            ob.iterations = ob.iterations < 0 ? 0 : ob.iterations;

            ob.strength = EditorGUILayout.Slider(new GUIContent("Strength", "Determines how much smoothing to apply in each smooth iteration. 0.5 usually produces the nicest looking curves"), ob.strength, 0.0F, 1.0F);
        }
        else if (ob.smoothType == SimpleSmoothModifier.SmoothType.OffsetSimple)
        {
            ob.iterations = EditorGUILayout.IntField(new GUIContent("Iterations", "Number of times to apply smoothing"), ob.iterations);
            ob.iterations = ob.iterations < 0 ? 0 : ob.iterations;
            ob.iterations = ob.iterations > 12 ? 12 : ob.iterations;

            ob.offset = EditorGUILayout.FloatField(new GUIContent("Offset", "Offset to apply in each smoothing iteration"), ob.offset);
            if (ob.offset < 0)
            {
                ob.offset = 0;
            }
        }
        else if (ob.smoothType == SimpleSmoothModifier.SmoothType.Bezier)
        {
            ob.subdivisions = EditorGUILayout.IntField(new GUIContent("Subdivisions", "The number of times to subdivide (divide in half) the path segments. [0...inf] (recommended [1...10])"), ob.subdivisions);
            if (ob.subdivisions < 0)
            {
                ob.subdivisions = 0;
            }

            ob.bezierTangentLength = EditorGUILayout.FloatField(new GUIContent("Tangent Length", "Tangent length factor"), ob.bezierTangentLength);
        }
        else if (ob.smoothType == SimpleSmoothModifier.SmoothType.CurvedNonuniform)
        {
            ob.maxSegmentLength = EditorGUILayout.FloatField(new GUIContent("Max Segment Length", "The length of each segment in the smoothed path. A high value yields rough paths and low value yields very smooth paths, but is slower"), ob.maxSegmentLength);
            ob.factor           = EditorGUILayout.FloatField(new GUIContent("Roundness Factor", "How much to smooth the path. A higher value will give a smoother path, but might take the character far off the optimal path."), ob.factor);
            ob.maxSegmentLength = ob.maxSegmentLength < 0 ? 0 : ob.maxSegmentLength;
        }
        else
        {
            DrawDefaultInspector();
        }

        //GUILayout.Space (5);

        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);
        }
    }
Ejemplo n.º 10
0
    public static void ShowModifiers()
    {
        Seeker               seeker       = m_AI.GetComponent <Seeker>();
        AlternativePath      altPath      = m_AI.GetComponent <AlternativePath>();
        FunnelModifier       funnel       = m_AI.GetComponent <FunnelModifier>();
        SimpleSmoothModifier simpleSmooth = m_AI.GetComponent <SimpleSmoothModifier>();

        GUILayout.BeginHorizontal();
        GUILayout.Space(25);
        // seeker
        if (seeker == null)
        {
            if (GUILayout.Button("Add Seeker", GUILayout.Height(25), GUILayout.MinWidth(150)))
            {
                seeker = m_AI.gameObject.AddComponent <Seeker>();
            }
        }
        else
        if (GUILayout.Button("Remove Seeker", GUILayout.Height(25), GUILayout.MinWidth(150)))
        {
            DestroyImmediate(seeker);
        }

        // funnel modifier
        if (funnel == null)
        {
            if (GUILayout.Button("Add Funnel", GUILayout.Height(25), GUILayout.MinWidth(150)))
            {
                funnel = m_AI.gameObject.AddComponent <FunnelModifier>();
            }
        }
        else
        if (GUILayout.Button("Remove Funnel", GUILayout.Height(25), GUILayout.MinWidth(150)))
        {
            DestroyImmediate(funnel);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Space(25);
        // simple smooth
        if (simpleSmooth == null)
        {
            if (GUILayout.Button("Add Simple Smooth", GUILayout.Height(25), GUILayout.MinWidth(150)))
            {
                simpleSmooth = m_AI.gameObject.AddComponent <SimpleSmoothModifier>();
            }
        }
        else
        if (GUILayout.Button("Remove Simple Smooth", GUILayout.Height(25), GUILayout.MinWidth(150)))
        {
            DestroyImmediate(simpleSmooth);
        }

        // alternative path
        if (altPath == null)
        {
            if (GUILayout.Button("Add Alternative Path", GUILayout.Height(25), GUILayout.MinWidth(150)))
            {
                altPath = m_AI.gameObject.AddComponent <AlternativePath>();
            }
        }
        else
        if (GUILayout.Button("Remove Alternative Path", GUILayout.Height(25), GUILayout.MinWidth(150)))
        {
            DestroyImmediate(altPath);
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(5);

        if (m_AI.AStarAutoPrioritize)
        {
            int priority = 1;
            if (simpleSmooth != null)
            {
                simpleSmooth.priority = priority++;
            }
            if (funnel != null)
            {
                funnel.priority = priority++;
            }
            if (altPath != null)
            {
                altPath.priority = priority++;
            }
        }
    }