示例#1
0
    //绘制战斗格子
    void DrawBattleBlock(Vector3 pos, Color c, int x, int y)
    {
        //Debug.DrawRay(pos, Vector3.up, c, 1f);

        var parent = GameObject.Find("decal parent");

        if (parent == null)
        {
            parent = new GameObject("decal parent");
        }

        var obj = EasyDecal.Project(m_DecalPrefab, pos, Quaternion.identity);

        obj.transform.SetParent(parent.transform);

        obj.LateBake();

        var bPos = new BattleBlockVector(x, y);
        var bbd  = new BattleBlockData();

        bbd.BattlePos  = bPos;
        bbd.WorldPos   = pos;
        bbd.gameObject = obj.gameObject;
        battleBlocks.Add(bbd);
    }
    public override void OnEnable()
    {
        base.OnEnable();

        FootstepsComponents.OnAdd().Subscribe(entity =>
        {
            var footstepsComponent = entity.GetComponent <FootstepsComponent>();
            var viewComponent      = entity.GetComponent <ViewComponent>();

            float rotation;
            RaycastHit hit;
            EasyDecal decal;

            footstepsComponent.Footsteps.OnAdd().Subscribe(index =>
            {
                if (Physics.Linecast(footstepsComponent.Foots[index].position, footstepsComponent.Foots[index].position + 0.1f * Vector3.down, out hit))
                {
                    rotation = viewComponent.Transforms[0].eulerAngles.y;
                    decal    = EasyDecal.ProjectAt(FootprintPrefab, null, hit.point, hit.normal, rotation, 0.5f * Vector3.one);
                    decal.AtlasRegionIndex = index;
                }
                footstepsComponent.Footsteps.Remove(index);
            }).AddTo(this.Disposer).AddTo(footstepsComponent.Disposer);
        }).AddTo(this.Disposer);
    }
示例#3
0
        public void Update()
        {
            if (Input.GetMouseButtonUp(0))
            {
                // Shoot a mouseRay thru the camera starting at the mouse's current screen space position
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                // Check if mouseRay hit something
                if (Physics.Raycast(ray, out hit, 200))
                {
                    // Draw a line along the projection axis for visalizing the projection process.
                    Debug.DrawLine(ray.origin, hit.point, Color.red);

                    // Instantiate the decal prefab according the mouseRay direction
                    //EasyDecal.ProjectAt(DecalPrefab.gameObject, hit.collider.gameObject, hit.point, -mouseRay.direction.normalized);

                    // Instantiate the decal prefab according the hit normal
                    EasyDecal decal = EasyDecal.ProjectAt(DecalPrefab.gameObject, hit.collider.gameObject, hit.point, hit.normal);

                    t = !t;

                    if (t)
                    {
                        decal.CancelFade();
                    }
                }
            }
        }
示例#4
0
 private void OnFadedOut(EasyDecal decal)
 {
     decal.transform.SetParent(null);
     decal.OnFadedOut -= OnFadedOut;
     PoolFactory.Despawn(decalDict[decal]);
     decalDict.Remove(decal);
 }
    private void Awake()
    {
        decal = GetComponent <EasyDecal>();

        prefabScale    = gameObject.transform.localScale;
        originalParent = transform.parent;

        decal.OnFadedOut += decal_OnFadedOut;
    }
    //Whenever a EasyDecal command instantiates a decal (either through Project, ProjectAt, Instantiate, etc...), this method will be used to spawn a decal from the EZ_Pooling pool rather than through EasyDecal's method.
    private static EasyDecal PoolInstantiation(GameObject decalPrefab, GameObject parent, Vector3 position, Quaternion rotation)
    {
        string    PoolName = decalPrefab.name;
        EasyDecal clone    = EZ_Pooling.EZ_PoolManager.GetPool(PoolName).Spawn(decalPrefab.transform, position, rotation).GetComponent <EasyDecal>();

        clone.Reset(true);

        return(clone);
    }
示例#7
0
    // Use this for initialization
    private void Start()
    {
        decal = GetComponent <EasyDecal>();

        var p = decal.Projector;

        if (p != null && p is BoxProjector)
        {
            BoxProjector bp = p as BoxProjector;
            bp.OnCandidatesProcessed += bp_OnCandidatesProcessed;
        }
    }
示例#8
0
        private void SetTarget(Ray mouseRay)
        {
            if (Input.GetMouseButtonUp(0))
            {
                RaycastHit hit;

                // Check if mouseRay hit something
                if (Physics.Raycast(mouseRay, out hit, MAXDISTANCE))
                {
                    agent.SetDestination(hit.point);

                    EasyDecal.ProjectAt(TargetPointDecalPrefab, hit.collider.gameObject, hit.point + decalOffset, Quaternion.identity);
                }
            }
        }
示例#9
0
    public override void OnEnable()
    {
        base.OnEnable();
        BulletComponents.OnAdd().Subscribe(entity =>
        {
            var bulletComponent = entity.GetComponent <BulletComponent>();
            var viewComponent   = entity.GetComponent <ViewComponent>();
            var capsuleCollider = entity.GetComponent <CapsuleCollider>();

            bulletComponent.radius = 0.5f * Mathf.Max(2 * capsuleCollider.radius, capsuleCollider.height);
        }).AddTo(this.Disposer);

        NetwrokTimeline.OnForward(data =>
        {
            var bulletComponent = data.Entity.GetComponent <BulletComponent>();
            var viewComponent   = data.Entity.GetComponent <ViewComponent>();
            var capsuleCollider = data.Entity.GetComponent <CapsuleCollider>();

            if (bulletComponent.velocity == FixVector3.zero)
            {
                return(null);
            }

            var direction   = (FixVector3)viewComponent.Transforms[0].forward;
            var offset      = (FixVector3)capsuleCollider.center + bulletComponent.radius * direction;
            var origin      = (FixVector3)viewComponent.Transforms[0].position + offset;
            var maxDistance = bulletComponent.velocity.magnitude * data.DeltaTime;

            RaycastHit hit;

            if (Physics.Raycast((Vector3)origin, (Vector3)direction, out hit, (float)maxDistance))
            {
                viewComponent.Transforms[0].position = (Vector3)(origin + hit.distance * direction - offset);
                // Here we cannot directly use hit.normal as the direction,
                // because our collider may be simplified and does not match the model,
                // our scaling on the y-axis is relatively large to ensure that the decal can be printed on the model.
                EasyDecal.ProjectAt(GetMaterial(hit.collider.name).BulletHole, null, hit.point, viewComponent.Transforms[0].forward, 0, new Vector3(bulletComponent.holeSize, GetMaterial(hit.collider.name).DetectionDepth, bulletComponent.holeSize));
                StartCoroutine(AsyncImpectEffect(hit.collider.name, hit.point, Quaternion.identity));
                bulletComponent.velocity = FixVector3.zero;
                PoolFactory.Despawn(data.Entity);
            }
            else
            {
                viewComponent.Transforms[0].position = (Vector3)(origin + maxDistance * direction - offset);
            }
            return(null);
        }).AddTo(this.Disposer);
    }
示例#10
0
        private void Update()
        {
            if (Input.GetMouseButtonUp(0))
            {
                // Shoot a mouseRay thru the camera starting at the mouse's current screen space position
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                RaycastHit initialHit;

                // Check if mouseRay hit something
                if (Physics.Raycast(ray, out initialHit, 200))
                {
                    // Set the first hit as parent of the decal
                    GameObject parent   = initialHit.collider.gameObject;
                    Vector3    position = initialHit.point;

                    RaycastHit[] hits          = Physics.SphereCastAll(ray, CastRadius, Vector3.Distance(Camera.main.transform.position, position) + 2);
                    Vector3      averageNormal = initialHit.normal;

                    // Check if sphere cast hit something
                    if (hits.Length > 0)
                    {
                        foreach (RaycastHit hit in hits)
                        {
                            // Draw a line along the projection axis for visalizing the projection process.
                            Debug.DrawLine(ray.origin, hit.point, Color.red);

                            // Sum all collison point normals
                            averageNormal += hit.normal;
                        }
                    }

                    // Normalize normal
                    averageNormal /= hits.Length + 1;

                    // Instantiate the decal prefab according the hit normal
                    EasyDecal.ProjectAt(DecalPrefab.gameObject, parent, position, averageNormal);

                    if (ImpactParticles != null)
                    {
                        Quaternion rot = Quaternion.FromToRotation(Vector3.up, averageNormal);

                        GameObject.Instantiate(ImpactParticles, position, rot);
                    }
                }
            }
        }
    private void Awake()
    {
        decal = GetComponent <EasyDecal>();
        //float rand = Random.Range(0.0f, 1.0f);
        //if (rand < 0.98f)
        //{
        //	int newRand = Random.Range(0, materials.Length-1);
        //	decal.DecalMaterial = materials[newRand];
        //} else
        //{
        //	decal.DecalMaterial = materials[1];
        //}

        prefabScale    = gameObject.transform.localScale;
        originalParent = transform.parent;

        decal.OnFadedOut += decal_OnFadedOut;
    }
示例#12
0
    private void DrawBattleBlock(Vector3 pos, Color c, int x, int y)
    {
        var parent = FindOrCreateBlocksParent();

        var obj = EasyDecal.Project(m_DecalPrefab, pos, Quaternion.identity);

        obj.transform.SetParent(parent.transform);

        //obj.LateBake();
        //StartCoroutine(SetDecalsHidenFrames(obj));

        var bPos = new BattleBlockVector(x, y);
        var bbd  = new BattleBlockData();

        bbd.BattlePos  = bPos;
        bbd.WorldPos   = pos;
        bbd.gameObject = obj.gameObject;
        battleBlocks.Add(bbd);
    }
示例#13
0
    //绘制战斗格子,默认不显示
    void DrawBattleBlock(Vector3 pos, Color c, int x, int y, Vector3 normal, BattleboxBlock boxBlock)
    {
        var parent = FindOrCreateBlocksParent();

        var block = Resources.Load <GameObject>("BattleboxBlock");
        var obj   = EasyDecal.Project(block, pos, Quaternion.identity);

        obj.Quality  = 2;
        obj.Distance = 0.05f;
        obj.transform.SetParent(parent.transform, false);

        var bPos = new BattleBlockVector(x, y);
        var bbd  = new BattleBlockData();

        bbd.BattlePos  = bPos;
        bbd.WorldPos   = pos;
        bbd.gameObject = obj.gameObject;
        bbd.BoxBlock   = boxBlock;
        battleBlocks.Add(bbd);
    }
示例#14
0
 public void Awake()
 {
     m_bindCollider  = gameObject.GetComponent <BoxCollider>();
     m_bindEasyDecal = gameObject.GetComponent <EasyDecal>();
 }
示例#15
0
        //------------------------------------
        // Methods
        //------------------------------------

        private void Start()
        {
            // Register the proxy collection
            EasyDecal.SetStaticProxyCollection(ProxyCollection);
        }
 private void decal_OnFadedOut(EasyDecal obj)
 {
     EZ_Pooling.EZ_PoolManager.GetPool(PoolName).Despawn(obj.transform);
 }
    //private void InitializeDecals()
    //{
    //    decalsInPool = new Queue<EasyDecal>();
    //    decalsActiveInWorld = new Queue<GameObject>();

    //    for (int i = 0; i < maxDecals; i++)
    //    {
    //        InstantiateDecal();
    //    }
    //}

    //private void InstantiateDecal()
    //{
    //    GameObject spawned = Instantiate(bloodSplatPrefab, decalManager.transform);
    //    //spawned.transform.SetParent(decalManager.transform);
    //    int rand = Random.Range(0, bloodSplatterTextures.Length);
    //    spawned.GetComponent<Renderer>().material.SetTexture("_MainTex", bloodSplatterTextures[rand]);

    //    //decalsInPool.Enqueue(spawned);
    //    spawned.SetActive(false);
    //}

    private void spawnDecal(ParticleCollisionEvent particleCollisionEvent, GameObject surface)
    {
        float randScale = Random.Range(decalSizeMin, decalSizeMax);
        float randAngle = Random.Range(0, 180);

        //decal.transform.parent = particleCollisionEvent.colliderComponent.gameObject.transform;
        //decal.transform.position = particleCollisionEvent.intersection;
        //decal.transform.rotation = Quaternion.FromToRotation(-Vector3.forward, particleCollisionEvent.normal);
        //float randScale = Random.Range(decalSizeMin, decalSizeMax);

        //decal.transform.localScale = new Vector3(randScale, randScale, randScale);
        //float randAngle = Random.Range(0, 180);

        //if (Mathf.Abs(Vector3.Dot(transform.up, Vector3.down)) < 0.125f)
        //{
        //    decal.transform.localEulerAngles += new Vector3(0, 0, randAngle);
        //} else
        //{
        //    decal.transform.localEulerAngles += new Vector3(0, randAngle, 0);
        //}

        //float castRadius = 1f;

        //RaycastHit[] hits = Physics.SphereCastAll(particleCollisionEvent.intersection, castRadius, Vector3.zero, Vector3.Distance(Camera.main.transform.position, particleCollisionEvent.intersection) + 2);
        //Vector3 averageNormal = particleCollisionEvent.normal;

        //// Check if sphere cast hit something
        //if (hits.Length > 0)
        //{
        //    Debug.Log(hits.Length);
        //    foreach (RaycastHit hit in hits)
        //    {
        //	    // Sum all collison point normals
        //	    averageNormal += hit.normal;
        //    }
        //}

        //// Normalize normal
        //averageNormal /= hits.Length + 1;

        float dotUpDown = Vector3.Dot(particleCollisionEvent.normal, Vector3.down);

        if ((dotUpDown >= -1.01f && dotUpDown <= -0.99f) || (dotUpDown > 0.99f && dotUpDown <= 1.01f))
        {
            //decal.GetComponent<Renderer>().material.color = particleColorGradient.Evaluate(Random.Range(0f, 1f));
            EasyDecal decal = EasyDecal.ProjectAt(bloodSplatPrefab.gameObject, particleCollisionEvent.colliderComponent.gameObject, particleCollisionEvent.intersection, particleCollisionEvent.normal, randAngle, new Vector3(randScale, 0.06f, randScale));
            //decal.transform.position -= decal.transform.up * 0.01f;
            //if (Mathf.Abs(Vector3.Dot(decal.transform.up, Vector3.down)) < 0.125f)
            //{
            //    //decalsOnWalls.Add(decal);
            //}

            float dotDown = Vector3.Dot(decal.transform.up, Vector3.down);

            if ((dotDown > 0.99f && dotDown <= 1.01f))
            {
                decalsOnCeiling.Add(decal);
            }
            else
            {
                if (decalsOnCeiling.Contains(decal))
                {
                    decalsOnCeiling.Remove(decal);
                }
            }
        }
        else
        {
            float rand = Random.Range(0f, 1f);
            //float rand = 0.01f;
            if (rand <= 0.11f)
            {
                float     randScaleDripX = Random.Range(0.35f, 0.6f);
                float     randScaleDripZ = Random.Range(0.15f, 0.24f);
                EasyDecal decal          = EasyDecal.ProjectAt(bloodDripPrefab.gameObject, particleCollisionEvent.colliderComponent.gameObject, particleCollisionEvent.intersection, particleCollisionEvent.normal, 0, new Vector3(randScaleDripX, 0.06f, randScaleDripZ));
                decal.Baked = false;
                decal.transform.rotation = Quaternion.LookRotation(Vector3.up, particleCollisionEvent.normal);
                decal.transform.RotateAround(decal.transform.position, particleCollisionEvent.normal, 90);
            }
            else
            {
                EasyDecal decal = EasyDecal.ProjectAt(bloodSplatPrefab.gameObject, particleCollisionEvent.colliderComponent.gameObject, particleCollisionEvent.intersection, particleCollisionEvent.normal, randAngle, new Vector3(randScale, 0.06f, randScale));
            }
        }

        //if (decalsOnWalls.Count > 0 && !CR_Running)
        //{
        //	StartCoroutine(moveDown());
        //}

        //decal.SetActive(true);
        //decalsActiveInWorld.Enqueue(decal);

        //if (decalsInPool.Count < maxDecals-1) {
        //    decalsInPool.Enqueue(decal);
        //} else
        //{
        //    EasyDecal oldestDecal = decalsInPool.Dequeue();
        //    //oldestDecal.des
        //}

        //if (Mathf.Abs(Vector3.Dot(decal.transform.up, Vector3.down)) < 0.125f)
        //{
        //    StartCoroutine(moveDown(decal));
        //}

        //decal = EasyDecal.ProjectAt(bloodSplatPrefab.gameObject, decalManager, particleCollisionEvent.intersection, particleCollisionEvent.normal);
        //decal.enabled = true;

        //decalsActiveInWorld.Enqueue(decal);
    }