コード例 #1
0
    private void LateUpdate()
    {
        if (mFog == null)
        {
            mFog = FOWSystem.Instance;
            if (mFog == null)
            {
                mFog = FindObjectOfType(typeof(FOWSystem)) as FOWSystem;
            }
        }

        if (mFog == null || !mFog.enabled)
        {
            enabled = false;
            return;
        }
        float     invScale = 1f / mFog.worldSize;
        Transform t        = mFog.transform;
        float     x        = t.position.x - mFog.worldSize * 0.5f;
        float     z        = t.position.z - mFog.worldSize * 0.5f;
        Vector4   p        = new Vector4(x * invScale, z * invScale, invScale, mFog.blendFactor);

        mMat.SetColor("_Unexplored", mUnexploredColor);
        mMat.SetColor("_Explored", mExploredColor);
        mMat.SetVector("_Params", p);
        mMat.SetTexture("_FogTex0", mFog.texture0);
        mMat.SetTexture("_FogTex1", mFog.texture1);
    }
コード例 #2
0
ファイル: FOWEffect.cs プロジェクト: yh821/Zombie
    // Called by camera to apply image effect
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (mFog == null)
        {
            mFog = FOWSystem.instance;
            if (mFog == null)
            {
                mFog = FindObjectOfType(typeof(FOWSystem)) as FOWSystem;
            }
        }

        if (mFog == null || !mFog.enabled)
        {
            enabled = false;
            return;
        }

        // Calculate the inverse modelview-projection matrix to convert screen coordinates to world coordinates
        mInverseMVP = (mCam.projectionMatrix * mCam.worldToCameraMatrix).inverse;

        float     invScale = 1f / mFog.worldSize;
        Transform t        = mFog.transform;
        float     x        = t.position.x - mFog.worldSize * 0.5f;
        float     z        = t.position.z - mFog.worldSize * 0.5f;

        if (mMat == null)
        {
            mMat           = new Material(shader);
            mMat.hideFlags = HideFlags.HideAndDontSave;
        }

        Vector4 camPos = mCam.transform.position;

        // This accounts for Anti-aliasing on Windows flipping the depth UV coordinates.
        // Despite the official documentation, the following approach simply doesn't work:
        // http://docs.unity3d.com/Documentation/Components/SL-PlatformDifferences.html

        if (QualitySettings.antiAliasing > 0)
        {
            RuntimePlatform pl = Application.platform;

            if (pl == RuntimePlatform.WindowsEditor || pl == RuntimePlatform.WindowsPlayer)
            {
                camPos.w = 1f;
            }
        }

        Vector4 p = new Vector4(-x * invScale, -z * invScale, invScale, mFog.blendFactor);

        mMat.SetColor("_Unexplored", unexploredColor);
        mMat.SetColor("_Explored", exploredColor);
        mMat.SetVector("_CamPos", camPos);
        mMat.SetVector("_Params", p);
        mMat.SetMatrix("_InverseMVP", mInverseMVP);
        mMat.SetTexture("_FogTex0", mFog.texture0);
        mMat.SetTexture("_FogTex1", mFog.texture1);

        Graphics.Blit(source, destination, mMat);
    }
コード例 #3
0
 protected virtual void OnDestroy()
 {
     if (mRevealer != null)
     {
         FOWSystem.DeleteRevealer(mRevealer);
         mRevealer = null;
     }
 }
コード例 #4
0
	// Called by camera to apply image effect
	void OnRenderImage (RenderTexture source, RenderTexture destination)
	{
		if (mFog == null)
		{
			mFog = FOWSystem.instance;
			if (mFog == null) mFog = FindObjectOfType(typeof(FOWSystem)) as FOWSystem;
		}

		if (mFog == null || !mFog.enabled)
		{
			enabled = false;
			return;
		}

		// Calculate the inverse modelview-projection matrix to convert screen coordinates to world coordinates
		mInverseMVP = (mCam.projectionMatrix * mCam.worldToCameraMatrix).inverse;

		float invScale = 1f / mFog.worldSize;
		Transform t = mFog.transform;
		float x = t.position.x - mFog.worldSize * 0.5f;
		float z = t.position.z - mFog.worldSize * 0.5f;

		if (mMat == null)
		{
			mMat = new Material(shader);
			mMat.hideFlags = HideFlags.HideAndDontSave;
		}

		Vector4 camPos = mCam.transform.position;

		// This accounts for Anti-aliasing on Windows flipping the depth UV coordinates.
		// Despite the official documentation, the following approach simply doesn't work:
		// http://docs.unity3d.com/Documentation/Components/SL-PlatformDifferences.html

		if (QualitySettings.antiAliasing > 0)
		{
			RuntimePlatform pl = Application.platform;

			if (pl == RuntimePlatform.WindowsEditor ||
				pl == RuntimePlatform.WindowsPlayer ||
				pl == RuntimePlatform.WindowsWebPlayer)
			{
				camPos.w = 1f;
			}
		}

		Vector4 p = new Vector4(-x * invScale, -z * invScale, invScale, mFog.blendFactor);
		mMat.SetColor("_Unexplored", unexploredColor);
		mMat.SetColor("_Explored", exploredColor);
		mMat.SetVector("_CamPos", camPos);
		mMat.SetVector("_Params", p);
		mMat.SetMatrix("_InverseMVP", mInverseMVP);
		mMat.SetTexture("_FogTex0", mFog.texture0);
		mMat.SetTexture("_FogTex1", mFog.texture1);

		Graphics.Blit(source, destination, mMat);
	}
コード例 #5
0
ファイル: FOWRevealer.cs プロジェクト: whztt07/mobahero_src
 public void DoDestroy()
 {
     if (this.onlygrass)
     {
         return;
     }
     FOWSystem.DeleteRevealer(this.mRevealer);
     this.mRevealer = null;
 }
コード例 #6
0
    private void Start()
    {
        this.instance = base.GetComponent <FOWSystem>();
        this.instance.CreateInstance();
        this.instance.enableFog(true);
        this.instance.Init();
        FOWEffect fOWEffect = this.instance.BindCam(Camera.main.camera);

        fOWEffect.manualstart();
        this.instance.DoStart("map16");
    }
コード例 #7
0
        public void AddTempRevealer(Vector3 position, float radius, int leftMS)
        {
            if (leftMS <= 0)
            {
                return;
            }

            FOWTempRevealer tmpRevealer = new FOWTempRevealer();

            tmpRevealer.InitInfo(position, radius, leftMS);
            FOWSystem.AddRevealer(tmpRevealer);
            m_revealers.Add(tmpRevealer);
        }
コード例 #8
0
 public void AddCharactor(int charaID)
 {
     if (!FOWCharactorRevealer.Contains(charaID))
     {
         if (FOWCharactorRevealer.CheckIsValid(charaID))
         {
             FOWCharactorRevealer revealer = new FOWCharactorRevealer();
             revealer.InitInfo(charaID);
             FOWSystem.AddRevealer(revealer);
             m_revealers.Add(revealer);
         }
     }
 }
コード例 #9
0
 protected void UpdateRevealers(int deltaMS)
 {
     for (int i = m_revealers.Count - 1; i >= 0; i--)
     {
         IFOWRevealer revealer = m_revealers[i];
         revealer.Update(deltaMS);
         if (!revealer.IsValid())
         {
             m_revealers.RemoveAt(i);
             FOWSystem.RemoveRevealer(revealer);
             revealer.Release();
         }
     }
 }
コード例 #10
0
ファイル: FOWRevealer.cs プロジェクト: whztt07/mobahero_src
 public void Create(Transform transform, float rad, FOWSystem.LOSChecks typ = FOWSystem.LOSChecks.EveryUpdate, bool _onlygrass = false)
 {
     this.mTrans    = transform;
     this.onlygrass = _onlygrass;
     if (!_onlygrass)
     {
         this.range.y            = rad;
         this.range.x            = 2f;
         this.lineOfSightCheck   = typ;
         this.mRevealer          = FOWSystem.CreateRevealer(typ);
         this.mRevealer.outer    = rad;
         this.mRevealer.los      = typ;
         this.mRevealer.pos      = transform.position;
         this.mRevealer.prvpos   = this.mRevealer.pos;
         this.mRevealer.isActive = true;
         this.isActive           = true;
     }
     this.unit = transform.gameObject.GetComponent <Units>();
 }
コード例 #11
0
    void LateUpdate()
    {
        if (mNextUpdate < Time.time)
        {
            mNextUpdate = Time.time + 0.075f + Random.value * 0.05f;

            if (FOWSystem.instance == null)
            {
                enabled = false;
                return;
            }

            if (mUpdate)
            {
                mRenderers = GetComponentsInChildren <Renderer>();
            }

            bool visible = FOWSystem.IsVisible(mTrans.position);

            if (mUpdate || mIsVisible != visible)
            {
                mUpdate    = false;
                mIsVisible = visible;

                for (int i = 0, imax = mRenderers.Length; i < imax; ++i)
                {
                    Renderer ren = mRenderers[i];

                    if (ren)
                    {
                        ren.enabled = mIsVisible;
                    }
                    else
                    {
                        mUpdate     = true;
                        mNextUpdate = Time.time;
                    }
                }
            }
        }
    }
コード例 #12
0
    public short[,] GetMapHeightInfo(FOWSystem self)
    {
        Vector3 origin      = self.transform.position - new Vector3(self.mapSize / 2f, 0, self.mapSize / 2f);
        Vector3 pos         = origin;
        int     heightRange = (int)(self.heightRange.y - self.heightRange.x);

        pos.y += heightRange;
        bool useSphereCast = self.raycastRadius > 0f;
        int  textureSize   = self.mapSize / self.pixScale;

        short[,] heights = new short[textureSize, textureSize];
        for (int z = 0; z < textureSize; ++z)
        {
            pos.z = origin.z + z * self.pixScale;

            for (int x = 0; x < textureSize; ++x)
            {
                pos.x = origin.x + x * self.pixScale;

                RaycastHit hit;

                if (useSphereCast)
                {
                    if (Physics.SphereCast(new Ray(pos, Vector3.down), self.raycastRadius, out hit, heightRange, self.raycastMask))
                    {
                        heights[x, z] = WorldToGridHeight(pos.y - hit.distance - self.raycastRadius);
                        continue;
                    }
                }
                else if (Physics.Raycast(new Ray(pos, Vector3.down), out hit, heightRange, self.raycastMask))
                {
                    heights[x, z] = WorldToGridHeight(pos.y - hit.distance);
                    continue;
                }
                heights[x, z] = 0;
            }
        }
        return(heights);
    }
コード例 #13
0
    /// <summary>
    /// Checks to see if the specified position has been explored.
    /// </summary>

    static public bool IsExplored(Vector3 pos)
    {
        FOWSystem sys = instance;

        if (sys == null)
        {
            return(true);
        }
        if (sys.mBuffer0 == null)
        {
            return(false);
        }
        pos -= sys.mOrigin;

        float worldToTex = (float)sys.textureSize / sys.worldSize;
        int   cx         = Mathf.RoundToInt(pos.x * worldToTex);
        int   cy         = Mathf.RoundToInt(pos.z * worldToTex);

        cx = Mathf.Clamp(cx, 0, sys.textureSize - 1);
        cy = Mathf.Clamp(cy, 0, sys.textureSize - 1);
        return(sys.mBuffer0[cx + cy * sys.textureSize].g > 0);
    }
コード例 #14
0
    /// <summary>
    /// Ensure that the thread gets terminated.
    /// </summary>

    void OnDestroy()
    {
        if (mThread != null)
        {
            mThread.Abort();
            while (mThread.IsAlive)
            {
                Thread.Sleep(1);
            }
            mThread = null;
        }

        // Save the Fog of War data
        if (onSave != null)
        {
            onSave();
        }

        // Clear the callback and the instance reference
        onLoad   = null;
        onSave   = null;
        instance = null;
    }
コード例 #15
0
ファイル: Entity.cs プロジェクト: whztt07/mobahero_src
    public override void PreDeath(Units attacker)
    {
        this.m_CoroutineManager.StopAllCoroutine();
        base.EnableAction(false);
        this.data.OnDeath(attacker);
        this.surface.OnDeath(attacker);
        this.animController.OnDeath(attacker);
        if (this.aiManager != null)
        {
            this.aiManager.OnDeath(attacker);
        }
        if (this.moveController != null)
        {
            this.moveController.OnStop();
        }
        if (this.atkController != null)
        {
            this.atkController.OnStop();
        }
        Singleton <TriggerManager> .Instance.SendUnitStateEvent(UnitEvent.UnitPrognosisDeath, this, null, null);

        if (attacker != null && (attacker.isHero || attacker.isPlayer) && attacker.unique_id != this.unique_id)
        {
            base.LastHurtHero = attacker;
        }
        if (base.isLocalUnit)
        {
            if (GlobalSettings.FogMode >= 2)
            {
                FOWSystem.CreateStaticTimeRevealer(base.transform.position, 1f, 3f);
            }
            else if (GlobalSettings.FogMode == 1)
            {
                FogMgr.Instance.AddFogItem(base.transform.position, 1f, 3f);
            }
        }
    }
コード例 #16
0
 public void CreateInstance()
 {
     FOWSystem.instance = this;
 }
コード例 #17
0
 void OnDestroy()
 {
     FOWSystem.DeleteRevealer(mRevealer);
     mRevealer = null;
 }
コード例 #18
0
 void Awake()
 {
     mTrans    = transform;
     mRevealer = FOWSystem.CreateRevealer();
 }
コード例 #19
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUILayout.PropertyField(mWorldSize, new GUIContent("地图刷新尺寸"));
        EditorGUILayout.PropertyField(mHeightRange, new GUIContent("地图高度范围"));
        EditorGUILayout.PropertyField(mPixScale, new GUIContent("像素缩放"));
        EditorGUILayout.PropertyField(mUpdateFrequency, new GUIContent("刷新间隔"));
        EditorGUILayout.PropertyField(mTextureBlendTime, new GUIContent("渐变时间"));
        EditorGUILayout.PropertyField(mBlurIterations, new GUIContent("模糊强度"));
        EditorGUILayout.PropertyField(mMapSize, new GUIContent("地图总尺寸"));
        serializedObject.ApplyModifiedProperties();

        FOWSystem fow = target as FOWSystem;

        _heightRange = Mathf.RoundToInt(fow.heightRange.y - fow.heightRange.x);
        mAssPath     = EditorGUILayout.ObjectField("替换的文件", mAssPath, typeof(TextAsset), false) as TextAsset;

        if (GUILayout.Button("生成地图高度数据"))
        {
            string path = "D:\\mapheight.bytes";
            if (mAssPath != null)
            {
                path = AssetDatabase.GetAssetPath(mAssPath);
            }

            mHeights = GetMapHeightInfo(fow);
            WriteToFile(path, fow.mapSize, mHeights);
            Debug.Log("生成bytes成功:" + path);
        }

        if (GUILayout.Button("导出当且数据到JPG"))
        {
            mHeights = GetMapHeightInfo(fow);

            Color[] colors = new Color[fow.mapSize * fow.mapSize];
            for (int y = 0, sizeY = fow.mapSize; y < sizeY; y++)
            {
                int yw = y * sizeY;
                for (int x = 0, sizeX = fow.mapSize; x < sizeX; x++)
                {
                    int pix = mHeights[x, y];
                    if (pix < 8)
                    {
                        colors[x + yw] = Color.white;
                    }
                    else if (pix < 16)
                    {
                        colors[x + yw] = Color.green;
                    }
                    else if (pix < 24)
                    {
                        colors[x + yw] = Color.blue;
                    }
                    else
                    {
                        colors[x + yw] = Color.red;
                    }
                }
            }

            Texture2D tt2d = new Texture2D(fow.mapSize, fow.mapSize);
            tt2d.SetPixels(colors);
            tt2d.Apply();

            byte[] imageBytes = tt2d.EncodeToJPG();
            using (FileStream file = new FileStream("D:\\mapheight.jpg", FileMode.Create))
            {
                file.Write(imageBytes, 0, imageBytes.Length);
                file.Close();
                Debug.Log("生成jpg成功:D:\\mapheight.jpg");
            }
        }
    }
コード例 #20
0
 void Awake()
 {
     instance = this;
 }
コード例 #21
0
 protected virtual void Start()
 {
     mTrans    = transform;
     mRevealer = FOWSystem.CreateRevealer();
 }
コード例 #22
0
    // 用相机呼叫来应用图像效果
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (mFog == null)
        {
            mFog = FOWSystem.instance;
            if (mFog == null)
            {
                mFog = FindObjectOfType(typeof(FOWSystem)) as FOWSystem;
            }
        }

        if (mFog == null || !mFog.enabled)
        {
            enabled = false;
            return;
        }

        // 计算逆模型-投影矩阵,将屏幕坐标转换为世界坐标
        mInverseMVP = (mCam.projectionMatrix * mCam.worldToCameraMatrix).inverse;

        float     invScale = 1f / mFog.worldSize;
        Transform t        = mFog.transform;
        float     x        = t.position.x - mFog.worldSize * 0.5f;
        float     z        = t.position.z - mFog.worldSize * 0.5f;

        if (mMat == null)
        {
            mMat           = new Material(shader);
            mMat.hideFlags = HideFlags.HideAndDontSave;
        }

        Vector4 camPos = mCam.transform.position;

        // 这是反锯齿的窗口翻转的深度UV坐标
        // 尽管有官方文件,以下方法根本不起作用:
        // http://docs.unity3d.com/Documentation/Components/SL-PlatformDifferences.html

        if (QualitySettings.antiAliasing > 0)
        {
            RuntimePlatform pl = Application.platform;

            if (pl == RuntimePlatform.WindowsEditor ||
                pl == RuntimePlatform.WindowsPlayer ||
                pl == RuntimePlatform.WindowsWebPlayer)
            {
                camPos.w = 1f;
            }
        }

        Vector4 p = new Vector4(-x * invScale, -z * invScale, invScale, mFog.blendFactor);

        mMat.SetColor("_Unexplored", unexploredColor);
        mMat.SetColor("_Explored", exploredColor);
        mMat.SetVector("_CamPos", camPos);
        mMat.SetVector("_Params", p);
        mMat.SetMatrix("_InverseMVP", mInverseMVP);
        mMat.SetTexture("_FogTex0", mFog.texture0);
        mMat.SetTexture("_FogTex1", mFog.texture1);

        Graphics.Blit(source, destination, mMat);
    }
コード例 #23
0
	/// <summary>
	/// Set the instance.
	/// </summary>

	void Awake () { instance = this; }
コード例 #24
0
ファイル: FOWSystem.cs プロジェクト: sqeety/FogOfWarProjector
    /// <summary>
    /// Set the instance.
    /// </summary>

    void Awake()
    {
        mInstance = this;
    }
コード例 #25
0
        private void DoEventDispatch(SkillDataKey skill_key, Units targetUnit, Units casterUnit)
        {
            if (targetUnit == null || casterUnit == null)
            {
                return;
            }
            SkillData data = GameManager.Instance.SkillData.GetData(skill_key);

            if (data == null)
            {
                return;
            }
            Skill skillOrAttackById = casterUnit.getSkillOrAttackById(data.skillId);

            if (skillOrAttackById == null)
            {
                return;
            }
            if (skillOrAttackById.IsAttack)
            {
                targetUnit.SetAttackedYouTarget(casterUnit);
                Singleton <TriggerManager> .Instance.SendUnitStateEvent(UnitEvent.UnitAttackHitOther, casterUnit, null, null);
            }
            if (skillOrAttackById.IsSkill)
            {
                if (targetUnit.unique_id != base.unit.unique_id)
                {
                    casterUnit.SetSkillHitedTarget(targetUnit);
                }
                if (casterUnit.isEnemy)
                {
                    targetUnit.SetSkillHitedYouTarget(casterUnit);
                }
                Singleton <TriggerManager> .Instance.SendUnitStateEvent(UnitEvent.UnitSkillHitOther, casterUnit, null, null);

                if (skillOrAttackById.skillIndex != 3)
                {
                    Singleton <TriggerManager> .Instance.SendUnitStateEvent(UnitEvent.UnitConjureQWE_HitOther, casterUnit, null, null);
                }
            }
            Singleton <TriggerManager> .Instance.SendUnitStateEvent(UnitEvent.UnitHit, targetUnit, null, null);

            if (skillOrAttackById.IsAttack)
            {
                Singleton <TriggerManager> .Instance.SendUnitStateEvent(UnitEvent.UnitBeAttackHit, targetUnit, null, null);
            }
            if (skillOrAttackById.IsSkill)
            {
                Singleton <TriggerManager> .Instance.SendUnitStateEvent(UnitEvent.UnitBeSkillHit, targetUnit, null, null);
            }
            if (StringUtils.CheckValid(base.unit.attackForTargetBuff))
            {
                ActionManager.AddBuff(base.unit.attackForTargetBuff, targetUnit, casterUnit, true, string.Empty);
                casterUnit.attackForTargetBuff = string.Empty;
            }
            if (!casterUnit.isLocalUnit && targetUnit != null && targetUnit.isLocalUnit)
            {
                if (casterUnit.m_nVisibleState >= 2)
                {
                    casterUnit.m_fVisibleTimer = 3f;
                }
                if (GlobalSettings.FogMode == 1)
                {
                    if (casterUnit != null && FogMgr.Instance.IsInFog(casterUnit) && targetUnit.isLocalUnit)
                    {
                        FogMgr.Instance.AddFogItem(casterUnit, 1f, 3f);
                    }
                }
                else if (GlobalSettings.FogMode >= 2 && casterUnit != null && !FOWSystem.Instance.IsVisible(casterUnit.transform.position) && targetUnit.isLocalUnit)
                {
                    FOWSystem.CreateStaticTimeRevealer(casterUnit.transform.position, 1f, 3f);
                }
            }
            if (targetUnit == PlayerControlMgr.Instance.GetPlayer())
            {
                Singleton <TriggerManager> .Instance.SendGameStateEvent(GameEvent.MainPlayerHitted);
            }
        }