Example #1
0
 protected static void AddDecalObject()
 {
     foreach (var obj in Selection.gameObjects)
     {
         DecalObject.GetOrCreate(obj);
     }
 }
Example #2
0
    public static void CreateNewDecal()
    {
        Camera     cam      = SceneView.lastActiveSceneView.camera;
        GameObject newDecal = new GameObject("New Decal");

        RaycastHit placementInfo;
        GameObject targetObj = null;

        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out placementInfo, 25f))
        {
            newDecal.transform.position = placementInfo.point;
            newDecal.transform.rotation = Quaternion.LookRotation(-placementInfo.normal);
            targetObj = placementInfo.collider.gameObject;
        }
        else
        {
            newDecal.transform.position = cam.transform.position + (cam.transform.forward * 25f);
        }

        newDecal.transform.localScale = new Vector3(1f, 1f, 0.5f);

        DecalObject dObj = newDecal.AddComponent <DecalObject>();

        dObj.targetObject = targetObj;

        Selection.activeGameObject = newDecal;
    }
Example #3
0
    public void OnSceneGUI()
    {
        Event curEvent = Event.current;

        if (curEvent.control)
        {
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        }

        DecalObject dObj = (DecalObject)target;

        if (curEvent.control && (curEvent.type == EventType.MouseDown || curEvent.type == EventType.MouseDrag))
        {
            Ray clickRay             = HandleUtility.GUIPointToWorldRay(curEvent.mousePosition);
            List <RaycastHit> allHit = new List <RaycastHit>(Physics.RaycastAll(clickRay, 100f, dObj.layersToAffect.value));
            allHit.Sort((h1, h2) => h1.distance.CompareTo(h2.distance));

            for (int i = 0; i < allHit.Count; i++)
            {
                if (!allHit[i].collider.gameObject.GetComponent <MeshFilter>())
                {
                    continue;
                }

                dObj.transform.position = allHit[i].point;
                dObj.transform.rotation = Quaternion.LookRotation(-allHit[i].normal) * Quaternion.Euler(Vector3.forward * -angleOffset);
                dObj.targetObject       = allHit[i].collider.gameObject;
                dObj.UpdateDecalMesh();
                break;
            }
        }

        if (curEvent.type == EventType.KeyDown)
        {
            if (curEvent.keyCode == KeyCode.Z)
            {
                Vector3 oldSize = dObj.transform.localScale;
                oldSize.x *= 0.9f;
                oldSize.y *= 0.9f;
                dObj.transform.localScale = oldSize;
            }
            else if (curEvent.keyCode == KeyCode.X)
            {
                Vector3 oldSize = dObj.transform.localScale;
                oldSize.x *= 1.1f;
                oldSize.y *= 1.1f;
                dObj.transform.localScale = oldSize;
            }
        }
    }
Example #4
0
    public override void OnInspectorGUI()
    {
        DecalObject dObj = (DecalObject)target;

        EditorGUIUtility.LookLikeControls(140f);
        GUILayout.Space(5f);

        dObj.material = (Material)EditorGUILayout.ObjectField("Material:", dObj.material, typeof(Material));

        GUILayout.Space(5f);

        DarkRef.GUISeparator();
        EditorGUILayout.LabelField("Sprite List:");
        if (dObj.material != null && dObj.material.mainTexture != null)
        {
            dObj.curSprite = DrawSpriteList(dObj.curSprite, dObj.material.mainTexture);

            if (dObj.curSprite != null && dObj.curSprite.texture != dObj.material.mainTexture)
            {
                dObj.curSprite = null;
            }
        }
        DarkRef.GUISeparator();

        GUILayout.Space(10f);

        dObj.maxAngle       = EditorGUILayout.Slider("Max Angle:", dObj.maxAngle, 1f, 90f);
        dObj.pushOffset     = EditorGUILayout.FloatField("Push Offset:", Mathf.Max(0f, dObj.pushOffset));
        dObj.layersToAffect = LayerMaskField("Layers To Affect:", dObj.layersToAffect);
        dObj.optimized      = EditorGUILayout.Toggle("Optimized Projection:", dObj.optimized);

        GUILayout.Space(10f);

        EditorGUILayout.ObjectField("Target Object:", dObj.targetObject, typeof(GameObject));
        EditorGUILayout.FloatField("Projection Depth:", dObj.transform.lossyScale.z);

        GUILayout.Space(10f);

        EditorGUILayout.HelpBox("CTRL + Click to drag the reposition the decal on a surface", MessageType.None);
        EditorGUILayout.HelpBox("Z and X to decrease/increase decal dimensions", MessageType.None);

        if (GUI.changed)
        {
            EditorUtility.SetDirty(dObj);
            dObj.UpdateDecalMesh();
        }
    }
Example #5
0
    public void BloodSplat()
    {
        int randCount = DarkRef.RandomRange((int)splatCount.x, (int)splatCount.y);

        for (int i = 0; i < randCount; i++)
        {
            if (Physics.Raycast(tr.position, Random.onUnitSphere, out hit, Random.Range(splatDistance.x, splatDistance.y), splatLayers.value))
            {
                DecalObject splat = (DecalObject)Instantiate(splatDecal, hit.point, Quaternion.LookRotation(-hit.normal));
                splat.transform.parent = hit.transform;
                splat.transform.Rotate(Vector3.forward * Random.value * 360f, Space.Self);

                splat.targetObject   = hit.collider.gameObject;
                splat.pushOffset     = splatOffset;
                splat.layersToAffect = splatLayers;
            }
        }
    }
Example #6
0
 public static void DrawMesh(this CommandBuffer buf, DecalObject obj)
 {
     buf.DrawMesh(obj.mesh, obj.matrix, obj.mat);
 }
Example #7
0
    private void OnHit(RaycastHit hit)
    {
        ricochetValue++;
        float limbForceMult = 1f;

        travelDist += hit.distance;
        bool ignoreBulletHole = false;

        if (!isVisuals)
        {
            bs = hit.collider.GetComponent <BaseStats>();
            lb = hit.collider.GetComponent <Limb>();

            damage = Mathf.RoundToInt(damage * dmgCurve.Evaluate(travelDist));

            if (damage > 0)
            {
                if (bs != null)
                {
                    bool hitMarkerEnabled = false;
                    if (player && wManager != null && bs.curHealth > 0 && bs.hitIndication)
                    {
                        hitMarkerEnabled = true;
                    }

                    bool canDamage = true;
                    bs.headshot = false;

                    if (Topan.Network.isConnected)
                    {
                        Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();
                        if (damageView != null && damage > 0)
                        {
                            BotVitals hitBot = bs.GetComponent <BotVitals>();

                            if (GeneralVariables.gameModeHasTeams)
                            {
                                byte ownerTeam  = (player) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team;
                                byte targetTeam = /* (hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                                if (targetTeam == ownerTeam)
                                {
                                    if (!friendlyFire)
                                    {
                                        canDamage = false;
                                    }

                                    hitMarkerEnabled = false;
                                }
                            }
                            else
                            {
                            }

                            if (canDamage)
                            {
                                if (isServer && (damageView.ownerID == 0 || hitBot))
                                {
                                    bs.ApplyDamageNetwork((byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)4);
                                }
                                else
                                {
                                    damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)4);
                                }
                            }
                        }
                        else
                        {
                            bs.ApplyDamageMain(damage, true);
                        }
                    }
                    else
                    {
                        bs.ApplyDamageMain(damage, true);
                    }

                    if (hitMarkerEnabled)
                    {
                        wManager.HitTarget(bs.curHealth <= 0);
                    }

                    if (canDamage)
                    {
                        PlayerVitals playerPV = bs.GetComponent <PlayerVitals>();
                        if (bs.isLocalPlayer && playerPV != null)
                        {
                            playerPV.HitIndicator(startPos);
                        }
                    }
                }
                else if (lb != null && lb.rootStats != null)
                {
                    bs = lb.rootStats;
                    lb.ragdollVelocity = tr.forward * force * limbForceMult;
                    damage             = Mathf.RoundToInt(damage * lb.realDmgMult);

                    bool hitMarkerEnabled = false;
                    if (player && wManager != null && bs.curHealth > 0 && bs.hitIndication)
                    {
                        hitMarkerEnabled = true;
                    }

                    bs.headshot = (lb.limbType == Limb.LimbType.Head);

                    if (Topan.Network.isConnected)
                    {
                        Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();
                        if (damageView != null)
                        {
                            BotVitals hitBot    = bs.GetComponent <BotVitals>();
                            bool      canDamage = true;

                            if (GeneralVariables.gameModeHasTeams)
                            {
                                byte ownerTeam  = (player || botIndex <= -1) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team;
                                byte targetTeam = /*(hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                                if (targetTeam == ownerTeam)
                                {
                                    if (!friendlyFire)
                                    {
                                        canDamage = false;
                                    }

                                    hitMarkerEnabled = false;
                                }
                            }
                            else
                            {
                            }

                            if (canDamage)
                            {
                                if (isServer && (damageView.ownerID == 0 || hitBot))
                                {
                                    bs.ApplyDamageNetwork((byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)lb.limbType);
                                }
                                else
                                {
                                    damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)lb.limbType);
                                }
                            }
                        }
                        else
                        {
                            bs.ApplyDamageMain(damage, true);
                        }
                    }
                    else
                    {
                        bs.ApplyDamageMain(damage, true);
                    }

                    limbForceMult = 3f;

                    if (hitMarkerEnabled)
                    {
                        wManager.HitTarget(bs.curHealth <= 0);
                    }
                }
            }
        }

        bulletHoleIndex = 0;
        hitEffectIndex  = 0;
        string hitTag = hit.collider.tag;

        if (hitTag == "Dirt")
        {
            hitEffectIndex = 1;
        }
        else if (hitTag == "Metal")
        {
            hitEffectIndex = 2;
        }
        else if (hitTag == "Wood")
        {
            hitEffectIndex = 3;
        }
        else if (hitTag == "Flesh" || hitTag == "Player - Flesh")
        {
            bulletHoleIndex = -1;
            hitEffectIndex  = 4;
        }
        else if (hitTag == "Water")
        {
            bulletHoleIndex = -1;
            hitEffectIndex  = 5;
        }

        Quaternion rot = Quaternion.LookRotation(hit.normal);

        if (bulletHoleIndex >= 0 && !ignoreBulletHole)
        {
            Transform hole = PoolManager.Instance.RequestInstantiate(bulletHoles[bulletHoleIndex], hit.point + (hit.normal * 0.01f), rot).transform;

            if (!hit.collider.gameObject.isStatic && hit.rigidbody)
            {
                hole.KeepUniformScale(hit.transform);
            }

            float randomSize = Random.Range(bulletDecalSize.x, bulletDecalSize.y);
            hole.localScale = new Vector3(randomSize, randomSize, 1f);

            Vector3 euler = hole.localEulerAngles;
            euler.z = Random.value * 360f;
            hole.localEulerAngles = euler;

            DecalObject dObj = hole.GetChild(0).GetComponent <DecalObject>();
            dObj.targetObject = hit.collider.gameObject;
            dObj.UpdateDecalMesh();
        }

        PoolManager.Instance.RequestParticleEmit(hitEffectIndex, hit.point + (hit.normal * 0.06f), rot);

        Rigidbody rigid = hit.rigidbody;

        if ((lb == null || (lb != null && (lb.rootStats == null || lb.rootStats.curHealth <= 0))) && rigid != null && !rigid.isKinematic)
        {
            rigid.AddForce(tr.forward * force * limbForceMult, ForceMode.Impulse);
        }

        if (ricochetAmount > 0 && ricochetValue <= ricochetAmount)
        {
            if (Vector3.Angle(dir, hit.normal) - 90f <= ricochetAngle)
            {
                tr.rotation    = Quaternion.LookRotation(Vector3.Reflect(dir, hit.normal));
                speed         *= 0.75f;
                damage         = Mathf.RoundToInt(damage * Random.Range(0.5f, 0.6f));
                gravityVector *= 0.5f;
                tr.position   += tr.forward * speed * Time.deltaTime;
                newPos         = tr.position;
            }
            else
            {
                AddToPool();
            }
        }

        if (smokeInstance != null)
        {
            smokeInstance.SetPosition(1, hit.point);
            smokeInstance = null;
        }

        if (currentWhiz != null)
        {
            currentWhiz.transform.parent   = null;
            currentWhiz.transform.position = hit.point;
            currentWhiz = null;
            noWhizSound = false;
        }

        tracer.SetActive(false);
        glow.SetActive(false);
        AddToPool();
    }
Example #8
0
 public void Remove(DecalObject obj)
 {
     objects.Remove(obj);
 }
Example #9
0
 public void Add(DecalObject obj)
 {
     Remove(obj);
     objects.Add(obj);
 }