Exemplo n.º 1
0
    private void OnEnable()
    {
        if (base.GetComponent <CharacterController>())
        {
            return;
        }
        if (this.m_host == null)
        {
            return;
        }
        Transform transformByType = GameObjectPath.GetTransformByType <PalGameObjectBase>(base.transform);

        if (transformByType == null)
        {
            transformByType = GameObjectPath.GetTransformByType <Animator>(base.transform);
        }
        if (transformByType != null && this.m_host != null && this.m_host != transformByType)
        {
            this.InitHost();
            Transform parent = base.transform.parent;
            if (parent != null)
            {
                Collider component = parent.GetComponent <Collider>();
                if (component != null)
                {
                    parent.gameObject.layer = 17;
                }
            }
            if (this.m_host.GetComponent <PalNPC>() != null && base.GetComponent <Collider>())
            {
                base.GetComponent <Collider>().isTrigger = true;
            }
        }
    }
Exemplo n.º 2
0
    private void InitHost()
    {
        Transform transformByType = GameObjectPath.GetTransformByType <PalGameObjectBase>(base.transform);

        if (transformByType != null)
        {
            this.m_host = transformByType.transform;
        }
        else
        {
            this.m_host = GameObjectPath.GetTransformByType <Animator>(base.transform);
        }
        if (this.m_host == null)
        {
            this.m_host = base.transform;
        }
    }
Exemplo n.º 3
0
    private void InitRange()
    {
        Transform transformByType = GameObjectPath.GetTransformByType <Animator>(base.transform);

        if (transformByType == null)
        {
            Debug.LogError(this.myTransform.name + "往上面没有找到 Animator");
            return;
        }
        this.range = transformByType.FindChild("Range");
        if (this.range == null)
        {
            this.range = new GameObject("Range")
            {
                transform =
                {
                    parent = transformByType
                }
            }.transform;
        }
        SphereCollider sphereCollider = this.range.GetComponent <SphereCollider>();

        if (sphereCollider == null)
        {
            sphereCollider = this.range.gameObject.AddComponent <SphereCollider>();
        }
        sphereCollider.radius    = (this.watchDistance + this.listenRadius) / 2f;
        sphereCollider.isTrigger = true;
        this.range.localPosition = new Vector3(0f, 0f, this.watchDistance - sphereCollider.radius);
        this.perceptionRange     = this.range.GetComponent <PerceptionRange>();
        if (this.perceptionRange == null)
        {
            this.perceptionRange = this.range.gameObject.AddComponent <PerceptionRange>();
        }
        this.perceptionRange.perception = this;
        this.range.gameObject.layer     = this.IgnoreLayer;
    }
Exemplo n.º 4
0
    private void Update()
    {
        if (!this.bActive)
        {
            base.enabled = false;
            return;
        }
        this.curInterval -= Time.deltaTime;
        float num = Time.realtimeSinceStartup - this.lastTime - this.HighLevelP;

        //if (num > PalMain.MinDeltaTime)
        //{
        //	this.lastTime = Time.realtimeSinceStartup;
        //	this.HighLevelP += this.relayP;
        //	return;
        //}
        this.HighLevelP = 0f;
        this.lastTime   = Time.realtimeSinceStartup;
        if (this.curInterval < 0f)
        {
            this.curInterval = this.prosInterval;
            if (this.targetsCanBePercept.Count > 0)
            {
                bool flag = false;
                foreach (KeyValuePair <Transform, List <PerceptionTarget> > current in this.targetsCanBePercept)
                {
                    Transform key = current.Key;
                    if (key == null)
                    {
                        Transform transformByType = GameObjectPath.GetTransformByType <Agent>(base.transform);
                        if (transformByType != null)
                        {
                            Debug.LogWarning(transformByType.name + " 没有找到 目标宿主 进行一次情况");
                        }
                        flag = true;
                        break;
                    }
                    bool flag2 = false;
                    foreach (PerceptionTarget current2 in current.Value)
                    {
                        if (!(current2 == null))
                        {
                            if (this.IsExsitInFrustum(current2.transform) && this.IsCanSeen(current2))
                            {
                                flag2 = true;
                                break;
                            }
                        }
                    }
                    if (flag2)
                    {
                        if (!this.hostsCanBeSeen.Contains(key))
                        {
                            this.hostsCanBeSeen.Add(key);
                            if (this.OnBeSeenEvent != null)
                            {
                                this.OnBeSeenEvent(key);
                            }
                            this.SendMessageToUScript(key, true);
                        }
                    }
                    else if (this.hostsCanBeSeen.Contains(key))
                    {
                        this.hostsCanBeSeen.Remove(key);
                        if (this.OnBeNotSeenEvent != null)
                        {
                            this.OnBeNotSeenEvent(key);
                        }
                        this.SendMessageToUScript(key, false);
                    }
                    int num2 = this.hostsCanBeListened.IndexOf(key);
                    if (this.IsExsitInListenRange(key))
                    {
                        if (num2 < 0)
                        {
                            this.hostsCanBeListened.Add(key);
                        }
                    }
                    else if (num2 > -1)
                    {
                        this.hostsCanBeListened.RemoveAt(num2);
                    }
                }
                if (flag)
                {
                    this.targetsCanBePercept.Clear();
                }
            }
            else
            {
                this.hostsCanBeSeen.Clear();
                this.hostsCanBeListened.Clear();
            }
        }
        if (this.bShowFrustum && this.meshRenderer != null && this.meshRenderer.material != null)
        {
            Vector3 position = this.myTransform.position;
            this.meshRenderer.material.SetFloat("_Distance", this.watchDistance);
            this.meshRenderer.material.SetVector("_ObjPos", new Vector4(position.x, position.y, position.z, 1f));
        }
        if (this.bShowFrustum != this.meshRenderer.enabled)
        {
            this.meshRenderer.enabled = this.bShowFrustum;
        }
    }