Esempio n. 1
0
        public void AddWeapon(Weapon prefab, bool replaceWeapon=false, bool temporary=false, float temporaryTimer=30)
        {
            GameObject obj=MountWeapon((GameObject)Instantiate(prefab.gameObject));

            //replace weapon and temporary are mutually exclusive
            if(replaceWeapon){
                Destroy(weaponList[weaponID].gameObject);
                weaponList[weaponID]=obj.GetComponent<Weapon>();
            }
            else if(temporary){
                tempWeapReturnID=weaponID;
                weaponList[weaponID].gameObject.SetActive(false);

                if(weaponList[weaponID].temporary) RemoveWeapon();

                weaponID=weaponList.Count;
                weaponList.Add(obj.GetComponent<Weapon>());

                weaponList[weaponList.Count-1].temporary=true;
                if(temporaryTimer>0) StartCoroutine(TemporaryWeaponTimer(weaponList[weaponList.Count-1], temporaryTimer));
            }
            else{
                weaponID=weaponList.Count;
                weaponList.Add(obj.GetComponent<Weapon>());
            }

            weaponList[weaponID].Reset();

            TDS.SwitchWeapon(weaponList[weaponID]);
        }
Esempio n. 2
0
        IEnumerator TemporaryWeaponTimer(Weapon weapon, float time)
        {
            Effect effect=new Effect();
            effect.ID=999;
            effect.duration=time;
            effect.icon=weapon.icon;
            ApplyEffect(effect);

            while(effect.duration>0 && weapon!=null) yield return null;

            effect.duration=-1;
            if(weapon!=null) RemoveWeapon();
        }
Esempio n. 3
0
 public static int NewItem(Weapon weapon)
 {
     return window._NewItem(weapon);
 }
Esempio n. 4
0
        int _NewItem(Weapon weapon)
        {
            if(weaponDB.weaponList.Contains(weapon)) return selectID;

            weapon.ID=GenerateNewID(weaponIDList);
            weaponIDList.Add(weapon.ID);

            weaponDB.weaponList.Add(weapon);

            UpdateLabel_Weapon();

            return weaponDB.weaponList.Count-1;
        }
Esempio n. 5
0
        Vector2 DrawWeaponConfigurator(float startX, float startY, Weapon weapon)
        {
            //float cachedX=startX;
            //float cachedY=startY;

            TDSEditorUtility.DrawSprite(new Rect(startX, startY, 60, 60), weapon.icon);
            startX+=65;

            float offsetY=TDSEditor.IsPrefab(weapon.gameObject) ? 5 : 0 ;

            cont=new GUIContent("Name:", "The ability name to be displayed in game");
            EditorGUI.LabelField(new Rect(startX, startY+=offsetY, width, height), cont);
            weapon.weaponName=EditorGUI.TextField(new Rect(startX+spaceX-65, startY, width-5, height), weapon.weaponName);

            cont=new GUIContent("Icon:", "The ability icon to be displayed in game, must be a sprite");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.icon=(Sprite)EditorGUI.ObjectField(new Rect(startX+spaceX-65, startY, width-5, height), weapon.icon, typeof(Sprite), false);

            cont=new GUIContent("Prefab:", "The prefab object of the unit\nClick this to highlight it in the ProjectTab");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            EditorGUI.ObjectField(new Rect(startX+spaceX-65, startY, width-5, height), weapon.gameObject, typeof(GameObject), false);

            startX-=65;
            startY+=spaceY;	//cachedY=startY;

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

            cont=new GUIContent("Shoot Object:", "The prefab of the bullet/object fired by the weapon\nMust be a prefab with ShootObject component attached on it");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.shootObject=(GameObject)EditorGUI.ObjectField(new Rect(startX+spaceX, startY, width, height), weapon.shootObject, typeof(GameObject), false);

            cont=new GUIContent("ShootPoint:", "The transform which indicate the position where the shootObject will be fired from (Optional)\nEach shootPoint assigned will fire a shootObject instance in each attack\nIf left empty, the weapon transform itself will be use as the shootPoint\nThe orientation of the shootPoint matter as they dictate the orientation of the firing direction.\n");
            shootPointFoldout=EditorGUI.Foldout(new Rect(startX, startY+=spaceY, spaceX, height), shootPointFoldout, cont);
            int shootPointCount=weapon.shootPointList.Count;
            shootPointCount=EditorGUI.IntField(new Rect(startX+spaceX, startY, 40, height), shootPointCount);

            if(shootPointCount!=weapon.shootPointList.Count){
                while(weapon.shootPointList.Count<shootPointCount) weapon.shootPointList.Add(null);
                while(weapon.shootPointList.Count>shootPointCount) weapon.shootPointList.RemoveAt(weapon.shootPointList.Count-1);
            }

            if(shootPointFoldout){
                for(int i=0; i<weapon.shootPointList.Count; i++){
                    int objID=GetObjectIDFromHList(weapon.shootPointList[i], objHList);
                    EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), "    - Element "+(i+1));
                    objID = EditorGUI.Popup(new Rect(startX+spaceX, startY, width, height), objID, objHLabelList);
                    weapon.shootPointList[i] = (objHList[objID]==null) ? null : objHList[objID].transform;
                }
            }

            cont=new GUIContent("Shoot Point Delay:", "The delay in seconds between subsequent shot in each shoot point");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            if(weapon.shootPointList.Count>1)
                weapon.shootPointDelay=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), weapon.shootPointDelay);
            else
                EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-");

            startY+=5;

            cont=new GUIContent("Range:", "The effective range of the weapon.");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.range=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), weapon.range);

            cont=new GUIContent("Cooldown:", "The cooldown in seconds between subsequent shot");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.cooldown=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), weapon.cooldown);

            cont=new GUIContent("Clip Size:", "How many times the weapon can be fired before it needs a reload. Set to -1 if the weapon can be fired indefinitely without reloading");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.clipSize=EditorGUI.IntField(new Rect(startX+spaceX, startY, 40, height), weapon.clipSize);

            cont=new GUIContent("Ammo Cap:", "How many ammo of the weapon the player can keep. Set to -1 if the weapon has unlimited ammo cap");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.ammoCap=EditorGUI.IntField(new Rect(startX+spaceX, startY, 40, height), weapon.ammoCap);

            cont=new GUIContent("Reload Duration:", "The duration in seconds to reload the weapon");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.reloadDuration=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), weapon.reloadDuration);

            startY+=5;

            cont=new GUIContent("Recoil:", "The recoil magnitude of the weapon. The higher the value, the less accurate the weapon become when fired continously");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.recoilMagnitude=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), weapon.recoilMagnitude);

            cont=new GUIContent("Recoil Cam Shake:", "The camera shake magnitude whenever the weapon is fired");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.recoilCamShake=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), weapon.recoilCamShake);

            startY+=5;

            cont=new GUIContent("Spread:", "The number of shoot object split from each shoot point. This is to create a shotgun effect");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.spread=EditorGUI.IntField(new Rect(startX+spaceX, startY, 40, height), weapon.spread);
            weapon.spread=Mathf.Max(1, weapon.spread);

            cont=new GUIContent("Spread Angle:", "The angle (in degree) between each spread");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            if(weapon.spread>1)
                weapon.spreadAngle=EditorGUI.FloatField(new Rect(startX+spaceX, startY, 40, height), weapon.spreadAngle);
            else
                EditorGUI.LabelField(new Rect(startX+spaceX, startY, 40, height), "-");

            startY+=10;

            Vector2 v2=DrawAttackStats(startX, startY+spaceY, weapon.aStats);
            startY=v2.y+20;

            startY+=30;

            //int abilityIdx=weapon.ability==null ? 0 : TDSEditor.GetEffectIndex(weapon.ability.ID);
            //if(abilityIdx==0) weapon.ability=null;
            int abilityIdx=weapon.abilityID>=0 ? TDSEditor.GetAbilityIndex(weapon.abilityID) : 0 ;

            TDSEditorUtility.DrawSprite(new Rect(startX+spaceX+width-40, startY+spaceY-45, 40, 40), abilityIdx>0 ? abilityDB.abilityList[abilityIdx-1].icon : null);
            if(GUI.Button(new Rect(startX+spaceX, startY-2, 40, height-2), "Edit ")) AbilityEditorWindow.Init();

            cont=new GUIContent("AltAttack(Ability):", "Ability that is being used as the weapon alternate fire mode (optional)");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY-5, width, height), cont, headerStyle);

            abilityIdx=EditorGUI.Popup(new Rect(startX+spaceX, startY, width, height), abilityIdx, abilityLabel);
            if(abilityIdx>0) weapon.abilityID=abilityDB.abilityList[abilityIdx-1].ID;
            else weapon.abilityID=-1;

            //if(abilityIdx>0) weapon.ability=abilityDB.abilityList[abilityIdx-1];
            //else weapon.ability=null;

            startY+=15;

            cont=new GUIContent("Shoot SFX:", "Audio clip to play when the weapon fires (optional)");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.shootSFX=(AudioClip)EditorGUI.ObjectField(new Rect(startX+spaceX, startY, width, height), weapon.shootSFX, typeof(AudioClip), false);

            cont=new GUIContent("Reload SFX:", "Audio clip to play when the weapon reloads (optional)");
            EditorGUI.LabelField(new Rect(startX, startY+=spaceY, width, height), cont);
            weapon.reloadSFX=(AudioClip)EditorGUI.ObjectField(new Rect(startX+spaceX, startY, width, height), weapon.reloadSFX, typeof(AudioClip), false);

            startY+=15;

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

            return new Vector2(startX, startY+200);
        }
Esempio n. 6
0
 public static void SwitchWeapon(Weapon weapon)
 {
     if(onSwitchWeaponE!=null) onSwitchWeaponE(weapon);
 }
Esempio n. 7
0
 public static bool ExistInDB(Weapon weapon)
 {
     return weaponDB.weaponList.Contains(weapon);
 }