Пример #1
0
    public static Vector3 GetTargetCenter(ISkillTarget target)
    {
        SkillRunner runner = target as SkillRunner;

        if (runner != null && runner.GetComponent <Collider>() != null)
        {
            AiObject aiObj = runner as AiObject;
            if (aiObj != null)
            {
                return(aiObj.center);
            }
            else
            {
                return(AiUtil.GetColliderCenter(runner.GetComponent <Collider>()));
            }
        }
        else
        {
            //CreationSkillRunner creation = runner as CreationSkillRunner;
            //if (creation != null)
            //return creation.transform.TransformPoint(creation.LocalBounds.center);
            // else
            // return target.GetPosition();
        }
        return(Vector3.zero);
    }
Пример #2
0
    public static Vector3 GetShootPosition(ISkillTarget target)
    {
        SkillRunner runner = target as SkillRunner;

        if (runner != null && runner.GetComponent <Collider>() != null)
        {
            AiObject aiObj = runner as AiObject;
            if (aiObj != null)
            {
                if (aiObj.model != null)
                {
                    Rigidbody[] rigids = aiObj.model.GetComponentsInChildren <Rigidbody>();
                    if (rigids != null && rigids.Length > 0)
                    {
                        return(rigids[Random.Range(0, rigids.Length)].worldCenterOfMass);
                    }
                }

                return(aiObj.center);
            }
            else
            {
                return(AiUtil.GetColliderCenter(runner.GetComponent <Collider>()));
            }
        }
        else
        {
            //CreationSkillRunner creation = runner as CreationSkillRunner;
            //if (creation != null)
            //	return creation.transform.TransformPoint(creation.LocalBounds.center);
            //else
            //	return target.GetPosition();
        }
        return(Vector3.zero);
    }
Пример #3
0
 void RemoveActiveAiObjects(AiObject aiObj)
 {
     if (mActiveAiObjects.Contains(aiObj))
     {
         mActiveAiObjects.Remove(aiObj);
     }
 }
Пример #4
0
    protected virtual void RPC_S2C_ResponseAnimatorState(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth)
        {
            return;
        }

        AiObject ai = Runner as AiObject;

        if (ai == null)
        {
            return;
        }

        /*bool rifleState = */ stream.Read <bool> ();
        byte[] data = stream.Read <byte[]> ();

        //if (ai is AiPuja)
        //    ((AiPuja)ai).RifleAim(rifleState);

        //if (ai is AiPaja)
        //    ((AiPaja)ai).BazookaAim(rifleState);

        using (MemoryStream ms = new MemoryStream(data))
            using (BinaryReader reader = new BinaryReader(ms)) {
                int count = BufferHelper.ReadInt32(reader);
                for (int i = 0; i < count; i++)
                {
                    string name  = BufferHelper.ReadString(reader);
                    bool   state = BufferHelper.ReadBoolean(reader);
                    ai.SetBool(name, state);
                }
            }
    }
Пример #5
0
    protected void RPC_S2C_SetIKPosition(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        AvatarIKGoal goal         = stream.Read <AvatarIKGoal> ();
        Vector3      goalPosition = stream.Read <Vector3> ();
        AiObject     ai           = Runner as AiObject;

        if (ai != null)
        {
            switch (goal)
            {
            case AvatarIKGoal.LeftFoot:
                ai.SetLeftFootIKPosition(goalPosition);
                break;

            case AvatarIKGoal.LeftHand:
                ai.SetLeftHandIKPosition(goalPosition);
                break;

            case AvatarIKGoal.RightFoot:
                ai.SetRightFootIKPosition(goalPosition);
                break;

            case AvatarIKGoal.RightHand:
                ai.SetRightHandIKPosition(goalPosition);
                break;

            default:
                break;
            }
        }
    }
Пример #6
0
 void RegisterActiveAiObjects(AiObject aiObj)
 {
     if (!mActiveAiObjects.Contains(aiObj))
     {
         mActiveAiObjects.Add(aiObj);
     }
 }
Пример #7
0
    bool Match(AiObject aiObj)
    {
        //if (aiObj == null || !aiObj.isActive || aiObj.enemy != null || aiObj.dead)
        //    return false;

        return(AiUtil.GetChild(aiObj.transform, "faece") != null);
    }
Пример #8
0
    void OnSpawned(GameObject go)
    {
        if (go == null)
        {
            return;
        }

        go.transform.parent = transform;

        AiObject aiObj = go.GetComponent <AiObject>();

        if (aiObj != null)
        {
            if (mTDInfo != null)
            {
                aiObj.tdInfo = mTDInfo;
            }

            RegisterAiObjects(aiObj);
        }

        if (OnSpawndEvent != null)
        {
            OnSpawndEvent(go);
        }
    }
Пример #9
0
 void OnAiDestroy(AiObject aiObj)
 {
     if (aiObj != null && objs.Contains(aiObj.gameObject))
     {
         objs.Remove(aiObj.gameObject);
     }
 }
Пример #10
0
    public virtual void OnDeath(AiObject aiObj)
    {
        mDeath = true;

        if (mDelete)
        {
            Delete();
        }
    }
Пример #11
0
    protected virtual void OnDeath(AiObject aiObj)
    {
        if (aiObj == null)
        {
            return;
        }

        mKilledCount++;
    }
Пример #12
0
    public void SpawnRandom()
    {
        //Vector3 screenPosition = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2, Screen.height/2, Camera.main.nearClipPlane+5)); //will get the middle of the screen

        Vector3 screenPosition = cam.ScreenToWorldPoint(new Vector3(Random.Range(0, Screen.width), Random.Range(Screen.height * 1.1f, Screen.height * 1.2f), 0));

        screenPosition.z = 0;

        AiObject enemy = Instantiate(enemyPrefab, screenPosition, Quaternion.identity, transform);
    }
Пример #13
0
    public void RegisterAiObject(AiObject aiObj)
    {
        aiObject = aiObj;

        //AiImplementSingle[] impSingles = GetComponentsInChildren<AiImplementSingle>();
        //foreach (AiImplementSingle imp in impSingles)
        //{
        //    imp.Initialize(aiObject);
        //}
    }
Пример #14
0
 public virtual void ClearDeathEvent()
 {
     if (clone != null)
     {
         AiObject aiObj = clone.GetComponent <AiObject>();
         if (aiObj != null)
         {
             aiObj.DeathHandlerEvent -= OnDeath;
         }
     }
 }
Пример #15
0
    protected override void OnSpawnedChild(GameObject obj)
    {
        base.OnSpawnedChild(obj);

        AiObject aiObj = obj.GetComponent <AiObject>();

        if (aiObj != null)
        {
            aiObj.lifePercent = hpPercent;
        }
    }
Пример #16
0
    protected virtual void RPC_S2C_SetLookAtPosition(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        Vector3  lookAtPosition = stream.Read <Vector3> ();
        AiObject ai             = Runner as AiObject;

        if (ai != null && lookAtPosition != Vector3.zero)
        {
            ai.LookAtPosition(lookAtPosition);
        }
    }
Пример #17
0
    protected virtual void RPC_S2C_SetLookAtWeight(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        float    weight = stream.Read <float> ();
        AiObject ai     = Runner as AiObject;

        if (ai != null)
        {
            ai.LookAtWeight(weight);
        }
    }
Пример #18
0
    protected void RPC_S2C_SetIKRotationWeight(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        AvatarIKGoal goal  = stream.Read <AvatarIKGoal> ();
        float        value = stream.Read <float> ();
        AiObject     ai    = Runner as AiObject;

        if (ai != null)
        {
            ai.SetIKRotationWeight(goal, value);
        }
    }
Пример #19
0
    protected virtual void RPC_S2C_SetInteger_Int(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        int      id    = stream.Read <int> ();
        int      value = stream.Read <int> ();
        AiObject ai    = Runner as AiObject;

        if (ai != null)
        {
            ai.SetInteger(id, value);
        }
    }
Пример #20
0
    //[RPC]
    //protected virtual void RPC_S2C_SetFloat_String(uLink.BitStream stream)
    //{
    //	if (IsController || null == Runner) return;
    //	string name = stream.Read<string>();
    //	float value = stream.Read<float>();

    //	AiObject ai = Runner as AiObject;
    //	if (ai != null)
    //	{
    //		ai.SetFloat(name,value);
    //	}
    //}

    //[RPC]
    //protected virtual void RPC_S2C_SetFloat_Int(uLink.BitStream stream)
    //{
    //	if (IsController || null == Runner) return;
    //	int id = stream.Read<int>();
    //	float value = stream.Read<float>();
    //	AiObject ai = Runner as AiObject;
    //	if (ai != null)
    //	{
    //		ai.SetFloat(id, value);
    //	}
    //}

    //[RPC]
    //protected virtual void RPC_S2C_SetFloat_String_1(uLink.BitStream stream)
    //{
    //	if (IsController || null == Runner) return;
    //	string name = stream.Read<string>();
    //	float value = stream.Read<float>();
    //	float dampTime = stream.Read<float>();
    //	float deltaTime = stream.Read<float>();

    //	AiObject ai = Runner as AiObject;
    //	if (ai != null)
    //	{
    //		ai.SetFloat(name, value, dampTime, deltaTime);
    //	}

    //}

    //[RPC]
    //protected virtual void RPC_S2C_RPC_C2S_SetFloat_Int_1(uLink.BitStream stream)
    //{
    //	if (IsController || null == Runner) return;
    //	int id = stream.Read<int>();
    //	float value = stream.Read<float>();
    //	float dampTime = stream.Read<float>();
    //	float deltaTime = stream.Read<float>();
    //	AiObject ai = Runner as AiObject;
    //	if (ai != null)
    //	{
    //		ai.SetFloat(id, value, dampTime, deltaTime);
    //	}
    //}

    protected virtual void RPC_S2C_SetBool_String(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        string   name  = stream.Read <string> ();
        bool     value = stream.Read <bool> ();
        AiObject ai    = Runner as AiObject;

        if (ai != null)
        {
            ai.SetBool(name, value);
        }
    }
Пример #21
0
    protected void RPC_S2C_SetIKRotation(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        AvatarIKGoal goal         = stream.Read <AvatarIKGoal> ();
        Quaternion   goalPosition = stream.Read <Quaternion> ();
        AiObject     ai           = Runner as AiObject;

        if (ai != null)
        {
            ai.SetIKRotation(goal, goalPosition);
        }
    }
Пример #22
0
    void OnAnimatorIK(int layerIndex)
    {
        //if (layerIndex != 1)
        //    return;

        AiObject aiObject = GetComponent <AiObject>();

        if (aiObject == null)
        {
            return;
        }

        if (GameConfig.IsMultiMode && !aiObject.IsController)
        {
            return;
        }

        if (effect <= PETools.PEMath.Epsilon)
        {
            aiObject.LookAtWeight(0.0f);
            aiObject.SetLeftHandIKWeight(0.0f);
            aiObject.SetRightHandIKWeight(0.0f);
        }
        else
        {
            aiObject.LookAtWeight(effect);

            Vector3 lookAtPosition = Vector3.zero;
            if (aimTarget != Vector3.zero)
            {
                lookAtPosition = aimTarget;
            }
            else
            {
                Transform eye         = aiObject.GetBoneTransform(HumanBodyBones.Head);
                Vector3   eyePosition = transform.InverseTransformPoint(eye.position);
                lookAtPosition = transform.TransformPoint(new Vector3(0.0f, eyePosition.y, 1.0f));
            }

            aiObject.LookAtPosition(lookAtPosition);

            aiObject.SetLeftHandIKWeight(1.0f);
            aiObject.SetRightHandIKWeight(1.0f);

            aiObject.SetLeftHandIKPosition(IKLeft.position);
            aiObject.SetRightHandIKPosition(IKRight.position);
        }
    }
Пример #23
0
    protected virtual void RPC_S2C_SetLayerWeight(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        if (hasOwnerAuth || null == Runner)
        {
            return;
        }
        int   layerIndex = stream.Read <int> ();
        float weight     = stream.Read <float> ();

        AiObject ai = Runner as AiObject;

        if (ai != null)
        {
            ai.SetLayerWeight(layerIndex, weight);
        }
    }
Пример #24
0
    public override void ClearDeathEvent()
    {
        base.ClearDeathEvent();

        foreach (GameObject obj in objs)
        {
            if (obj != null)
            {
                AiObject aiObj = obj.GetComponent <AiObject>();
                if (aiObj != null)
                {
                    aiObj.DeathHandlerEvent -= OnDeath;
                }
            }
        }
    }
Пример #25
0
    protected override void OnSpawned(GameObject obj)
    {
        base.OnSpawned(obj);

        if (!objs.Contains(obj))
        {
            objs.Add(obj);
        }

        AiObject ai = obj.GetComponent <AiObject>();

        if (ai != null)
        {
            ai.DestroyHandlerEvent += OnAiDestroy;
        }
    }
Пример #26
0
    protected virtual void Start()
    {
        seeker   = GetComponentInChildren <AiSeeker>();
        aiObject = GetComponent <AiObject>();

        alignCorrection = new Quaternion();
        alignCorrection.SetLookRotation(forwardVector, Vector3.up);
        alignCorrection = Quaternion.Inverse(alignCorrection);

        //groundLayers = AiManager.Manager.groundedLayer;

        if (habit == LifeArea.LA_Water || habit == LifeArea.LA_Sky)
        {
            gravity = 0.0f;
        }
    }
Пример #27
0
    protected override void OnDeath(AiObject aiObj)
    {
        base.OnDeath(aiObj);


        if (mMissionID > 0)
        {
//            GameGui_N.Instance.mMissionTrackGui.SetMonsterLeft(mMissionID, KilledCount);
        }

        //if (KilledCount >= m_data.m_Count)
        //{
        //    PlayerFactory.mMainPlayer.ProcessTowerMission(m_missionID, true);

        //    DestroyObject(this.gameObject, 0.1f);
        //}
    }
Пример #28
0
    public void RegisterAiObjects(AiObject aiObj)
    {
        if (!mAiObjects.Contains(aiObj))
        {
            aiObj.transform.parent = transform;

            aiObj.DeathHandlerEvent    += OnAiObjectDeath;
            aiObj.DestroyHandlerEvent  += OnAiObjectDestroy;
            aiObj.ActiveHandlerEvent   += OnAiObjectActive;
            aiObj.InactiveHandlerEvent += OnAiObjectDeActive;

            mAiObjects.Add(aiObj);

            RegisterActiveAiObjects(aiObj);

            AddGroupMaxHP(aiObj);
        }
    }
Пример #29
0
    public override void OnSpawned(GameObject obj)
    {
        base.OnSpawned(obj);

        AiObject aiObj = obj.GetComponent <AiObject>();

        if (aiObj != null)
        {
            aiObj.tdInfo = transform;
        }

        SPGroup spGroup = obj.GetComponent <SPGroup>();

        if (spGroup != null)
        {
            spGroup.tdInfo = transform;
        }
    }
Пример #30
0
    public void InitItem(AiObject enemy)
    {
        mShowObj = enemy;

        //AiNpcObject npc = mShowObj as AiNpcObject;
        //if (npc != null)
        //    mHeadSpr.spriteName = npc.m_NpcIcon;
        //else
        //{
        //    AiDataObject monster = mShowObj as AiDataObject;
        //    if (monster != null)
        //    {
        //        mHeadSpr.spriteName = AiAsset.AiDataBlock.GetIconName(monster.dataId);
        //    }
        //    else {
        //        Debug.LogError("mShowObj is not npc or monster");
        //    }
        //}
        mHeadSpr.MakePixelPerfect();
        mHeadSpr.transform.localScale = new Vector3(32, 32, 1);
    }