Example #1
0
        public override void OnTriggerEnter(Collider collider)
        {
            if (targetTransform == null)
            {
                return;
            }

            UnitPlayer player = collider.gameObject.GetComponent <UnitPlayer>();

            if (player != null)
            {
                //for effect, check parent class
                if (!spawnEffectAtOrigin)
                {
                    effPos = player.transform.position;
                }
                targetEffPos = targetTransform.position;

                player.thisT.position = targetTransform.position;

                Triggered();
            }
        }
Example #2
0
        Vector2 DrawUnitConfigurator(float startX, float startY, UnitPlayer unit)
        {
            Vector2 v2 = DrawUnitBaseStats(startX, startY, unit, true);

            startY = v2.y;

            startY += 10;

            int objID = GetObjectIDFromHList(unit.turretObj, objHList);

            cont = new GUIContent("Turret Object:", "The pivot transform on the unit to track the shoot direction");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            objID          = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), objID, objHLabelList);
            unit.turretObj = (objHList[objID] == null) ? null : objHList[objID].transform;

            objID = GetObjectIDFromHList(unit.weaponMountPoint, objHList);
            cont  = new GUIContent("WeaponMount:", "The transform where the weapon object to be anchored to as child object");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            objID = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, height), objID, objHLabelList);
            unit.weaponMountPoint = (objHList[objID] == null) ? null : objHList[objID].transform;

            startY += 10;

            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), "Weapons", headerStyle);

            cont = new GUIContent("Enable All   -  ", "Check to enable all weapons");
            EditorGUI.LabelField(new Rect(startX + spaceX + 50, startY, width, height), cont);
            unit.enableAllWeapons = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY, width, height), unit.enableAllWeapons);

            if (!unit.enableAllWeapons)
            {
                int enabledCount = 0;
                for (int i = 0; i < weaponDB.weaponList.Count; i++)
                {
                    Weapon weapon = weaponDB.weaponList[i];

                    bool enabled       = unit.weaponList.Contains(weapon);
                    bool enabledCached = enabled;

                    TDSEditorUtility.DrawSprite(new Rect(startX + 20, startY += spaceY, 30, 30), weapon.icon, weapon.desp);
                    cont = new GUIContent(weapon.weaponName, weapon.desp);
                    EditorGUI.LabelField(new Rect(startX + 65, startY + 15, width, height), cont);
                    enabled = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY + 15, width, height), enabled);
                    startY += 14;

                    if (enabled != enabledCached)
                    {
                        if (enabled)
                        {
                            unit.weaponList.Insert(enabledCount, weapon);
                        }
                        else
                        {
                            unit.weaponList.Remove(weapon);
                        }
                    }

                    if (enabled)
                    {
                        enabledCount += 1;
                    }
                }

                startY += 10;
            }
            if (GUI.Button(new Rect(startX + spaceX + width - 100, startY += spaceY, 100, height - 2), "Weapon Editor"))
            {
                WeaponEditorWindow.Init();
            }


            startY += 20;


            unit.enableAbility = EditorGUI.Toggle(new Rect(startX, startY += spaceY, width, height), unit.enableAbility);
            EditorGUI.LabelField(new Rect(startX + 20, startY, width, height), "Abilities", headerStyle);

            if (unit.enableAbility)
            {
                cont = new GUIContent("Enable All   -  ", "Check to enable all abilities");
                EditorGUI.LabelField(new Rect(startX + spaceX + 50, startY, width, height), cont);
                unit.enableAllAbilities = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY, width, height), unit.enableAllAbilities);

                if (!unit.enableAllAbilities)
                {
                    int enabledCount = 0;
                    for (int i = 0; i < abilityDB.abilityList.Count; i++)
                    {
                        Ability ability = abilityDB.abilityList[i];

                        bool enabled       = unit.abilityIDList.Contains(ability.ID);
                        bool enabledCached = enabled;

                        TDSEditorUtility.DrawSprite(new Rect(startX + 20, startY += spaceY, 30, 30), ability.icon);
                        cont = new GUIContent(ability.name, ability.desp);
                        EditorGUI.LabelField(new Rect(startX + 65, startY + 15, width, height), cont);
                        enabled = EditorGUI.Toggle(new Rect(startX + spaceX + width - 15, startY + 15, width, height), enabled);
                        startY += 14;

                        if (enabled != enabledCached)
                        {
                            if (enabled)
                            {
                                unit.abilityIDList.Insert(enabledCount, ability.ID);
                            }
                            else
                            {
                                unit.abilityIDList.Remove(ability.ID);
                            }
                        }

                        if (enabled)
                        {
                            enabledCount += 1;
                        }
                    }

                    startY += 10;
                }
                if (GUI.Button(new Rect(startX + spaceX + width - 100, startY += spaceY, 100, height - 2), "Ability Editor"))
                {
                    AbilityEditorWindow.Init();
                }
            }

            startY += 10;


            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), "Movement & Control", headerStyle);

            cont = new GUIContent("EnableTurretAiming:", "Check to allow turret object to rotate and aim towards cursor position");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.enableTurretRotate = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.enableTurretRotate);

            cont = new GUIContent("Turret Aim Mode:", "The way in which the turret aim direction will be calculated");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            if (unit.enableTurretRotate)
            {
                int aimMode = (int)unit.turretAimMode;
                contL = new GUIContent[turretAimModeLabel.Length];
                for (int i = 0; i < contL.Length; i++)
                {
                    contL[i] = new GUIContent(turretAimModeLabel[i], turretAimModeTooltip[i]);
                }
                aimMode            = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, 15), new GUIContent(""), aimMode, contL);
                unit.turretAimMode = (_TurretAimMode)aimMode;
            }
            else
            {
                EditorGUI.LabelField(new Rect(startX + spaceX, startY, width, height), "-");
            }

            cont = new GUIContent("Aim At Move Dir.:", "Check to have the unit's aim locked with it's move direction");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            if (unit.enableTurretRotate)
            {
                EditorGUI.LabelField(new Rect(startX + spaceX, startY, width, height), "-");
            }
            else
            {
                unit.aimAtTravelDirection = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.aimAtTravelDirection);
            }

            startY += 10;

            cont = new GUIContent("FaceTravelDirection:", "Enable to have the unit's transform rotates to face its travel direction");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.faceTravelDirection = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.faceTravelDirection);

            cont = new GUIContent("x-axis movement:", "Check to enabled unit movement in x-axis");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.enabledMovementX = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.enabledMovementX);

            cont = new GUIContent("z-axis movement:", "Check to enabled unit movement in z-axis");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.enabledMovementZ = EditorGUI.Toggle(new Rect(startX + spaceX, startY, width, height), unit.enabledMovementZ);

            startY += 10;

            int mode = (int)unit.movementMode;

            cont = new GUIContent("Movement Mode:", "The way in which the movement of the unit is handled with regard to the input");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            contL = new GUIContent[movementModeLabel.Length];
            for (int i = 0; i < contL.Length; i++)
            {
                contL[i] = new GUIContent(movementModeLabel[i], movementModeTooltip[i]);
            }
            mode = EditorGUI.Popup(new Rect(startX + spaceX, startY, width, 15), new GUIContent(""), mode, contL);
            unit.movementMode = (_MovementMode)mode;

            cont = new GUIContent("Move Speed:", "The move speed of the unit");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.moveSpeed = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.moveSpeed);

            cont = new GUIContent("Boost Speed Mul:", "Speed-Multiplier(rigid mode)/Acceleration-Multiplier(free-form mode) when using boost (left-shift by default)");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.boostMultiplier = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.boostMultiplier);

            cont = new GUIContent("Boost Energy Rate:", "Energy consumption rate (per second) when using boost (left-shift by default)\n0.3 being 30% of total energy per second");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.boostEnergyRate = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.boostEnergyRate);

            if (unit.movementMode == _MovementMode.FreeForm)
            {
                cont = new GUIContent("Acceleration:", "The acceleration of the unit");
                EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
                unit.acceleration = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.acceleration);

                cont = new GUIContent("Decceleration:", "The rate of the unit losing it's speed");
                EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
                unit.decceleration = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.decceleration);

                cont = new GUIContent("Active Braking:", "Stopping power when using active braking (space by default)");
                EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
                unit.activeBrakingRate = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 40, height), unit.activeBrakingRate);
            }

            startY += 10;


            cont = new GUIContent("Enable Limit ", "Check to limit player movement to a defined area");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
            unit.useLimit = EditorGUI.Toggle(new Rect(startX + spaceX, startY, 30, height), unit.useLimit);

            if (unit.useLimit)
            {
                cont         = new GUIContent("Show", "");
                limitFoldout = EditorGUI.Foldout(new Rect(startX + spaceX + 40, startY, spaceX, height), limitFoldout, cont);

                if (limitFoldout)
                {
                    cont = new GUIContent("x-axis (min/max):", "Stopping power when using active braking (space by default)");
                    EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
                    unit.minPosX = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 70, height), unit.minPosX);
                    unit.maxPosX = EditorGUI.DelayedFloatField(new Rect(startX + spaceX + 75, startY, 70, height), unit.maxPosX);

                    cont = new GUIContent("z-axis (min/max):", "Stopping power when using active braking (space by default)");
                    EditorGUI.LabelField(new Rect(startX, startY += spaceY, width, height), cont);
                    unit.minPosZ = EditorGUI.DelayedFloatField(new Rect(startX + spaceX, startY, 70, height), unit.minPosZ);
                    unit.maxPosZ = EditorGUI.DelayedFloatField(new Rect(startX + spaceX + 75, startY, 70, height), unit.maxPosZ);
                }
            }

            startY += 10;

            Vector2 v3 = DrawDestroyEffectObj(startX, startY + spaceY, unit);

            startY = v3.y + 20;


            GUIStyle style = new GUIStyle("TextArea");

            style.wordWrap = true;
            cont           = new GUIContent("Unit description (to be used in runtime): ", "");
            EditorGUI.LabelField(new Rect(startX, startY += spaceY, 400, 20), cont);
            unit.desp = EditorGUI.DelayedTextField(new Rect(startX, startY + spaceY - 3, 270, 150), unit.desp, style);


            return(new Vector2(startX, startY + 200));
        }
Example #3
0
 public static int NewItem(UnitPlayer unit)
 {
     return(window._NewItem(unit));
 }
Example #4
0
 public static bool ExistInDB(UnitPlayer unit)
 {
     return(unitPlayerDB.unitList.Contains(unit));
 }
Example #5
0
        public override bool OnGUI()
        {
            if (!base.OnGUI())
            {
                return(true);
            }

            if (window == null)
            {
                Init();
            }

            List <UnitPlayer> unitList = unitPlayerDB.unitList;

            Undo.RecordObject(this, "window");
            Undo.RecordObject(unitPlayerDB, "unitPlayerDB");
            if (unitList.Count > 0 && selectID >= 0)
            {
                Undo.RecordObject(unitList[selectID], "unitPlayer");
            }


            if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save"))
            {
                SetDirtyTDS();
            }

            if (!UnitPlayer_DB.UpdatedToPost_2018_3())
            {
                GUI.color = new Color(0, 1f, 1f, 1f);
                if (GUI.Button(new Rect(Math.Max(260, window.position.width - 230), 5, 100, 25), "Copy Old DB"))
                {
                    UnitPlayer_DB.CopyFromOldDB();          Select(0);
                }
                GUI.color = Color.white;
            }


            EditorGUI.LabelField(new Rect(5, 7, 150, 17), "Add New Player Unit:");
            UnitPlayer newUnit = null;

            newUnit = (UnitPlayer)EditorGUI.ObjectField(new Rect(125, 7, 140, 17), newUnit, typeof(UnitPlayer), false);
            if (newUnit != null)
            {
                Select(NewItem(newUnit));
            }

            float startX = 5; float startY = 55;

            if (minimiseList)
            {
                if (GUI.Button(new Rect(startX, startY - 20, 30, 18), ">>"))
                {
                    minimiseList = false;
                }
            }
            else
            {
                if (GUI.Button(new Rect(startX, startY - 20, 30, 18), "<<"))
                {
                    minimiseList = true;
                }
            }

            Vector2 v2 = DrawUnitList(startX, startY, unitList);

            startX = v2.x + 25;

            if (unitList.Count == 0)
            {
                return(true);
            }


            Rect visibleRect = new Rect(startX, startY, window.position.width - startX - 10, window.position.height - startY - 5);
            Rect contentRect = new Rect(startX, startY, contentWidth - startY, contentHeight);



            scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect);

            UnitPlayer unitToEdit = selectedUnitList.Count != 0 ? selectedUnitList[0] : unitList[selectID];

            Undo.RecordObject(unitToEdit, "unitToEdit");

            EditorGUI.BeginChangeCheck();

            v2            = DrawUnitConfigurator(startX, startY, unitToEdit);
            contentWidth  = v2.x + 35;
            contentHeight = v2.y - 55;

            if (EditorGUI.EndChangeCheck() && selectID >= 0)
            {
                                        #if UNITY_2018_3_OR_NEWER
                //GameObject unitObj=PrefabUtility.LoadPrefabContents(AssetDatabase.GetAssetPath(unitList[selectID].gameObject));
                //UnitPlayer selectedUnit=unitObj.GetComponent<UnitPlayer>();
                //selectedUnit=unitList[selectID];
                //GameObject obj=PrefabUtility.SavePrefabAsset(selectedUnit.gameObject);

                string assetPath = AssetDatabase.GetAssetPath(unitList[selectID].gameObject);

                GameObject unitObj      = PrefabUtility.LoadPrefabContents(assetPath);
                UnitPlayer selectedUnit = unitObj.GetComponent <UnitPlayer>();

                EditorUtility.CopySerialized(unitList[selectID], selectedUnit);

                PrefabUtility.SaveAsPrefabAsset(unitObj, assetPath);
                PrefabUtility.UnloadPrefabContents(unitObj);
                                        #endif
            }

            srlObj.ApplyModifiedProperties();

            if (selectedUnitList.Count > 0 && TDSEditor.IsPrefabInstance(selectedUnitList[0].gameObject))
            {
                PrefabUtility.RecordPrefabInstancePropertyModifications(selectedUnitList[0]);
            }

            GUI.EndScrollView();


            if (GUI.changed)
            {
                SetDirtyTDS();
                for (int i = 0; i < selectedUnitList.Count; i++)
                {
                    EditorUtility.SetDirty(selectedUnitList[i]);
                }
            }

            return(true);
        }
Example #6
0
        void Awake()
        {
            instance=this;

            Application.targetFrameRate=60;

            //get the unit in game
            player = (UnitPlayer)FindObjectOfType(typeof(UnitPlayer));

            //setup the collision rules
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerShootObject(), !shootObject);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerCollectible(), !collectible);

            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTerrain(), true);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTrigger(), true);

            //clear all the spawner and tracker sicne it's a new game
            UnitTracker.Clear();
            UnitSpawnerTracker.Clear();

            //this is not required, each individual unit and spawner will register itself to the tracker
            //UnitTracker.ScanForUnit();
            //UnitSpawnerTracker.ScanForSpawner();
        }
Example #7
0
        //for when the unit is destroy by game mechanic
        public void Destroyed(UnitPlayer player = null)
        {
            if (destroyed)
            {
                return;
            }

            //if(player==null) Debug.LogWarning("unit destroyed by not source player has been detected", null);

            destroyed = true;

            //spawn a unit if spawnUponDestroy is assigned
            if (spawnUponDestroy != null)
            {
                //loop as many as required
                for (int i = 0; i < spawnUponDestroyCount; i++)
                {
                    //instantiate the unit
                    //GameObject unitObj=(GameObject)Instantiate(spawnUponDestroy.gameObject, thisT.position, thisT.rotation);
                    GameObject unitObj = ObjectPoolManager.Spawn(spawnUponDestroy.gameObject, thisT.position, thisT.rotation);
                    unitObj.layer = thisObj.layer;

                    //pass on the wave info
                    Unit unitInstance = unitObj.GetComponent <Unit>();
                    if (waveID >= 0)
                    {
                        unitInstance.SetWaveID(spawner, waveID);
                        spawner.AddUnitToWave(unitInstance);
                    }
                    else if (spawner != null)
                    {
                        spawner.AddUnit(unitInstance);
                    }
                }
            }

            //check if the unit is going to drop any collectible
            if (useDropManager)                 //if useDropManager is enabled, inform CollectibleDropManager
            {
                CollectibleDropManager.UnitDestroyed(thisT.position);
            }
            else
            {
                //check chance and spawn the item
                if (dropObject != null && Random.value < dropChance)
                {
                    ObjectPoolManager.Spawn(dropObject.gameObject, thisT.position, Quaternion.identity);
                }
            }


            if (player != null)
            {
                //applies the bonus value for when the unit is destroyed.
                //if(valueCredits>0) GameControl.GainCredits(valueCredits);
                if (valueScore > 0)
                {
                    GameControl.GainScore(valueScore);
                }

                if (valuePerkC > 0)
                {
                    player.GainPerkCurrency(valuePerkC);
                }
                if (valueExp > 0)
                {
                    player.GainExp(valueExp);
                }
                if (valueHitPoint > 0)
                {
                    player.GainHitPoint(valueHitPoint);
                }
                if (valueEnergy > 0)
                {
                    player.GainEnergy(valueEnergy);
                }
            }

            //if(isPlayer) GetUnitPlayer().DeleteSave();

            //shake camera
            TDS.CameraShake(destroyCamShake);

            float delay = uAnimation != null?uAnimation.Destroyed() : 0;

            ClearUnit(true, delay);
        }
Example #8
0
 void OnPlayerLevelUp(UnitPlayer player)
 {
     PlaySound(playerLevelUpClip);
 }
Example #9
0
        //apply the effect to player
        void ApplyEffectSelf(UnitPlayer player)
        {
            //gain life
            if(life>0) GameControl.GainLife();

            //gain hit-point
            if(hitPoint>0){
                float hitPointGained=player.GainHitPoint(hitPoint);

                Vector3 offsetPos=new Vector3(0, Random.value+0.5f, 0);
                new TextOverlay(transform.position+offsetPos, "+"+hitPointGained.ToString("f0"), new Color(0.3f, 1f, 0.3f, 1));
            }

            //gain energy
            if(energy>0){
                float energyGained=player.GainEnergy(energy);

                Vector3 offsetPos=new Vector3(0, Random.value+0.5f, 0);
                new TextOverlay(transform.position+offsetPos, "+"+energyGained.ToString("f0"), new Color(.3f, .3f, 1f, 1));
            }

            //not in used
            if(credit>0){
                GameControl.GainCredits(credit);

                Vector3 offsetPos=new Vector3(0, Random.value+0.5f, 0);
                new TextOverlay(transform.position+offsetPos, "+$"+credit.ToString("f0"), new Color(.5f, .75f, 1, 1));
            }

            //gain score
            if(score>0){
                GameControl.GainScore(score);

                Vector3 offsetPos=new Vector3(0, Random.value+0.5f, 0);
                new TextOverlay(transform.position+offsetPos, "+"+score.ToString("f0"), new Color(.1f, 1f, 1, 1));
            }

            //gain ammo
            if(ammo!=0){
                player.GainAmmo(ammoID, ammo);

                Vector3 offsetPos=new Vector3(0, Random.value+0.5f, 0);
                new TextOverlay(transform.position+offsetPos, "+ammo");
            }

            //effects
            if(effect!=null && effect.duration>0){
                player.ApplyEffect(effect);
            }

            //gain weapon
            if(gainWeapon && weaponList.Count>0){
                int playerWeaponID=player.weaponList[player.weaponID].ID;
                int rand=randomWeapon ? Random.Range(0, weaponList.Count) : 0 ;
                if(randomWeapon && weaponList.Count>1){
                    int count=0;
                    while(weaponList[rand].ID==playerWeaponID){
                        rand=Random.Range(0, weaponList.Count);
                        count+=1;
                        if(count>50) break;
                    }
                }

                bool replaceWeapon=weaponType==_WeaponType.Replacement;
                bool temporaryWeapon=weaponType==_WeaponType.Temporary;
                player.AddWeapon(weaponList[rand], replaceWeapon, temporaryWeapon, tempWeapDuration);
            }
        }
Example #10
0
        void Start()
        {
            player=GameControl.GetPlayer();

            joystickAim.transform.parent.gameObject.SetActive(player.enableTurretRotate);
            fireButton.SetActive(!player.enableTurretRotate);

            if(!UIMainControl.EnableItemSelectTab()) weaponAbilityTabButton.SetActive(false);
        }
Example #11
0
 void Awake()
 {
     instance = (UnitPlayer)target;
     LoadDB();
 }
Example #12
0
        //Update is called once per frame
        void Update()
        {
            if(player==null){
                player=GameControl.GetPlayer();
                if(player==null) return;
            }

            if(player.IsDestroyed()) return;

            if(joystickMove.GetMagnitude()>0) player.Move(joystickMove.GetValue());
            if(joystickAim.GetMagnitude()>0){
                player.AimTurretDPad(joystickAim.GetValue());
                player.FireWeapon();
            }
        }
Example #13
0
 void Awake()
 {
     instance = (UnitPlayer)target;
     LoadDB();
 }
        public override bool OnGUI()
        {
            if (!base.OnGUI())
            {
                return(true);
            }

            if (window == null)
            {
                Init();
            }

            List <UnitPlayer> unitList = unitPlayerDB.unitList;

            Undo.RecordObject(this, "window");
            Undo.RecordObject(unitPlayerDB, "unitPlayerDB");
            if (unitList.Count > 0 && selectID >= 0)
            {
                Undo.RecordObject(unitList[selectID], "unitPlayer");
            }


            if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save"))
            {
                SetDirtyTDS();
            }

            EditorGUI.LabelField(new Rect(5, 7, 150, 17), "Add New Player Unit:");
            UnitPlayer newUnit = null;

            newUnit = (UnitPlayer)EditorGUI.ObjectField(new Rect(125, 7, 140, 17), newUnit, typeof(UnitPlayer), false);
            if (newUnit != null)
            {
                Select(NewItem(newUnit));
            }

            float startX = 5; float startY = 55;

            if (minimiseList)
            {
                if (GUI.Button(new Rect(startX, startY - 20, 30, 18), ">>"))
                {
                    minimiseList = false;
                }
            }
            else
            {
                if (GUI.Button(new Rect(startX, startY - 20, 30, 18), "<<"))
                {
                    minimiseList = true;
                }
            }

            Vector2 v2 = DrawUnitList(startX, startY, unitList);

            startX = v2.x + 25;

            if (unitList.Count == 0)
            {
                return(true);
            }


            Rect visibleRect = new Rect(startX, startY, window.position.width - startX - 10, window.position.height - startY - 5);
            Rect contentRect = new Rect(startX, startY, contentWidth - startY, contentHeight);



            scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect);

            UnitPlayer unitToEdit = selectedUnitList.Count != 0 ? selectedUnitList[0] : unitList[selectID];

            Undo.RecordObject(unitToEdit, "unitToEdit");

            v2            = DrawUnitConfigurator(startX, startY, unitToEdit);
            contentWidth  = v2.x + 35;
            contentHeight = v2.y - 55;

            srlObj.ApplyModifiedProperties();

            if (selectedUnitList.Count > 0 && TDSEditor.IsPrefabInstance(selectedUnitList[0].gameObject))
            {
                PrefabUtility.RecordPrefabInstancePropertyModifications(selectedUnitList[0]);
            }

            GUI.EndScrollView();


            if (GUI.changed)
            {
                SetDirtyTDS();
                for (int i = 0; i < selectedUnitList.Count; i++)
                {
                    EditorUtility.SetDirty(selectedUnitList[i]);
                }
            }

            return(true);
        }
Example #15
0
        //apply the effect to player
        void ApplyEffectSelf(UnitPlayer player)
        {
            //gain life
            if (life > 0)
            {
                GameControl.GainLife();
            }

            //gain hit-point
            if (hitPoint > 0)
            {
                float hitPointGained = player.GainHitPoint(hitPoint);

                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(transform.position + offsetPos, "+" + hitPointGained.ToString("f0"), new Color(0.3f, 1f, 0.3f, 1));
            }

            //gain energy
            if (energy > 0)
            {
                float energyGained = player.GainEnergy(energy);

                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(transform.position + offsetPos, "+" + energyGained.ToString("f0"), new Color(.3f, .3f, 1f, 1));
            }

            //not in used
            if (credit > 0)
            {
                GameControl.GainCredits(credit);

                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(transform.position + offsetPos, "+$" + credit.ToString("f0"), new Color(.5f, .75f, 1, 1));
            }

            //gain score
            if (score > 0)
            {
                GameControl.GainScore(score);

                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(transform.position + offsetPos, "+" + score.ToString("f0"), new Color(.1f, 1f, 1, 1));
            }

            //gain ammo
            if (ammo != 0)
            {
                player.GainAmmo(ammoID, ammo);

                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(transform.position + offsetPos, "+ammo");
            }

            //gain exp
            if (exp != 0)
            {
                player.GainExp(exp);

                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(transform.position + offsetPos, "+exp", new Color(1f, 1f, 1, 1));
            }

            //gain perk currency
            if (perkCurrency != 0)
            {
                player.GainPerkCurrency(perkCurrency);

                Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);
                new TextOverlay(transform.position + offsetPos, "+perk points", new Color(1f, 1f, 1, 1));
            }


            //effects
            if (effectIdx >= 0)
            {
                player.ApplyEffect(EffectDB.CloneItem(effectIdx));
            }
            //if(effect!=null && effect.duration>0) player.ApplyEffect(effect);

            //gain weapon
            if (gainWeapon && weaponList.Count > 0)
            {
                int playerWeaponID = player.weaponList[player.weaponID].ID;
                int rand           = randomWeapon ? Random.Range(0, weaponList.Count) : 0;
                if (randomWeapon && weaponList.Count > 1)
                {
                    int count = 0;
                    while (weaponList[rand].ID == playerWeaponID)
                    {
                        rand   = Random.Range(0, weaponList.Count);
                        count += 1;
                        if (count > 50)
                        {
                            break;
                        }
                    }
                }

                bool replaceWeapon   = weaponType == _WeaponType.Replacement;
                bool temporaryWeapon = weaponType == _WeaponType.Temporary;
                player.AddWeapon(weaponList[rand], replaceWeapon, temporaryWeapon, tempWeapDuration);
            }
        }
Example #16
0
 public static bool ExistInDB(UnitPlayer unit)
 {
     return unitPlayerDB.unitList.Contains(unit);
 }
Example #17
0
 public void SetPlayer(UnitPlayer unit)
 {
     player = unit;
     Init();
 }
Example #18
0
        public void _PlayerDestroyed()
        {
            if(respawning) return;

            //player unit is destroyed, check playerLife and respawn player if need be

            playerLife-=1;

            if(playerLife<=0){	//playerLife's used up, game over
                GameOver(false);
                return;
            }

            respawning=true;	//set respawning flag to true to prevent duplicate spawn

            //create a duplicate of current player unit so the selected weapon and ability is retained
            GameObject obj=(GameObject)Instantiate(player.gameObject, player.thisT.position, player.thisT.rotation);
            player=obj.GetComponent<UnitPlayer>();

            //set the new player unit to false to give it a little delay before showing it again
            obj.SetActive(false);

            //call the coroutine which will do the delay and reactivate the new unit
            StartCoroutine(ActivateRepawnPlayer());
        }