예제 #1
0
        static bool Basketball(Faction upsFaction)
        {
            var database = LandfallUnitDatabase.GetDatabase();
            //添加一个单位
            var customUnitBase = FindBluePrintByName("Stoner");
            var newUnit        = new UnitBlueprint(customUnitBase);

            newUnit.Entity.Name = "TestUnit";
            upsFaction.Units    = new UnitBlueprint[] { newUnit };
            database.AddUnitWithID(newUnit);
            //定制石头
            //使用巨石为模板实例化一个篮球
            var prefabRoot = new GameObject("PrefabRoot");

            prefabRoot.transform.position = Vector3.zero;
            var basketballWeapon = GameObject.Instantiate(customUnitBase.RightWeapon, prefabRoot.transform);

            //basketballWeapon.SetActive(false);
            basketballWeapon.name = "Thrower_Basketball";
            basketballWeapon.transform.position = new Vector3(0, -100, 0);
            var basketballArmor = GameObject.Instantiate(customUnitBase.RightWeapon.GetComponent <RangeWeapon>().objectToSpawn, prefabRoot.transform);

            //var basketballArmor = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            basketballArmor.transform.parent = prefabRoot.transform;
            //basketballArmor.SetActive(false);
            basketballArmor.name = "B_Basketball";
            //basketballArmor.transform.position = new Vector3(0, -100, 0);
            //加载网格
            var basketballModel = ab.LoadAsset <GameObject>("Basketball");

            if (basketballModel == null)
            {
                modeEntry.Logger.Log("未能正确加载预制体");
                return(false);
            }
            //替换mesh
            var rock1 = basketballWeapon.transform.Find("rock");

            rock1.GetComponent <MeshFilter>().mesh        = basketballModel.GetComponent <MeshFilter>().mesh;
            rock1.GetComponent <MeshRenderer>().materials = basketballModel.GetComponent <MeshRenderer>().materials;
            //
            var rock2 = basketballArmor.transform.Find("rock");

            rock2.GetComponent <MeshFilter>().mesh        = basketballModel.GetComponent <MeshFilter>().mesh;
            rock2.GetComponent <MeshRenderer>().materials = basketballModel.GetComponent <MeshRenderer>().materials;
            GameObject.Destroy(rock2.GetComponent <MeshCollider>());
            rock2.gameObject.AddComponent <SphereCollider>().radius = 0.005565071f;
            //防止销毁
            GameObject.DontDestroyOnLoad(prefabRoot);
            var remover = basketballArmor.GetComponent <RemoveAfterSeconds>();

            basketballArmor.AddComponent <RemoveAdder>().Init(remover);
            GameObject.Destroy(remover);
            //GameObject.Destroy(basketballArmor.GetComponent<RemoveAfterSeconds>());
            newUnit.RightWeapon = basketballWeapon;
            basketballWeapon.GetComponent <RangeWeapon>().objectToSpawn = basketballArmor;
            //
            modeEntry.Logger.Log("添加单位 " + newUnit.Entity.Name + " 到派系 " + upsFaction.Entity.Name);
            return(true);
        }
예제 #2
0
        static bool Load(UnityModManager.ModEntry _modEntry)
        {
            modeEntry = _modEntry;
            //新增一个派系
            _modEntry.Logger.Log("1------------->");
            var database   = LandfallUnitDatabase.GetDatabase();
            var factions   = database.GetFactions();
            var upsFaction = ScriptableObject.CreateInstance <Faction>();

            upsFaction.Init();
            _modEntry.Logger.Log("2------------->");
            upsFaction.Entity.Name = "Bilibili Ups";
            //必须设置派系图标不然会报错
            _modEntry.Logger.Log("3------------->");
            upsFaction.Entity.Icon = factions[0].Entity.Icon;
            database.AddFactionWithID(upsFaction);
            _modEntry.Logger.Log("添加派系:" + upsFaction.Entity.Name);
            //加载AssetBundle
            var path = Application.dataPath + "/../Mods/FactionOfBilibiliUPs/res.ab";

            modeEntry.Logger.Log("资源文件加载路径:" + path);
            ab = AssetBundle.LoadFromFile(path);
            if (ab == null)
            {
                modeEntry.Logger.Log("未能正确加载资源文件");
                return(false);
            }
            //Basketball(upsFaction);
            if (!ReverseMaceSpinner(upsFaction))
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
        void SpawnProp(CharacterItem prop, PropItemData propData)
        {
            Weapon        component = prop.GetComponent <Weapon>();
            CharacterItem component2;

            if (component == null)
            {
                component2 = Main.unitRoot.GetComponent <UnitRig>().SpawnProp(prop, propData, Stitcher.TransformCatalog.RigType.Human, Team.Blue, null, true).GetComponent <CharacterItem>();
            }
            else
            {
                //处理已存在的武器

                //Main.unitRoot.GetComponent<Unit>().WeaponHandler.UseHands();
                Quaternion rotation = Main.unitRoot.GetComponentInChildren <WeaponHandler>().transform.rotation;

                List <GameObject> targetList = null;
                if (propData.m_equip == UnitRig.EquipType.LEFT)
                {
                    targetList = lastLeftWeapons;
                }
                else if (propData.m_equip == UnitRig.EquipType.RIGHT)
                {
                    targetList = lastRightWeapons;
                }
                if (targetList.Count != 0)
                {
                    for (int i = 0; i < targetList.Count; i++)
                    {
                        GameObject.Destroy(targetList[i]);
                    }
                    targetList.Clear();
                }
                var handType = HoldingHandler.HandType.Left;
                if (propData.m_equip == UnitRig.EquipType.LEFT)
                {
                    handType = HoldingHandler.HandType.Left;
                }
                else if (propData.m_equip == UnitRig.EquipType.RIGHT)
                {
                    handType = HoldingHandler.HandType.Right;
                }
                component2 = LandfallUnitDatabase
                             .GetDatabase()
                             .m_unitEditorBlueprint
                             .SetWeapon(Main.unitRoot.GetComponent <Unit>(), Team.Blue, prop.gameObject, propData, handType, rotation, targetList)
                             .GetComponent <WeaponItem>();
            }
        }
예제 #4
0
        public void CodeOnSpawn(Unit unit, LandfallUnitDatabase db)
        {
            WebTabsID webTabsID = unit.GetComponent <WebTabsID>();

            if (webTabsID)
            {
                if (webTabsID && WebUtils.scaleDictionaries.ContainsKey(webTabsID.id))
                {
                    var boneDict = WebUtils.scaleDictionaries[webTabsID.id];
                    foreach (string key in boneDict.Keys)
                    {
                        if (key != null && boneDict.ContainsKey(key))
                        {
                            unit.ScaleBodyPart(key, boneDict[key]);
                        }
                    }
                }
            }
        }
예제 #5
0
        void Start()
        {
            LandfallUnitDatabase database = LandfallUnitDatabase.GetDatabase();

            weapons = database.Weapons;

            heads             = database.GetPropsOfType(UnitRig.GearType.HEAD);
            necks             = database.GetPropsOfType(UnitRig.GearType.NECK);
            shoulders         = database.GetPropsOfType(UnitRig.GearType.SHOULDER);
            torsos            = database.GetPropsOfType(UnitRig.GearType.TORSO);
            arms              = database.GetPropsOfType(UnitRig.GearType.ARMS);
            wrists            = database.GetPropsOfType(UnitRig.GearType.WRISTS);
            hands             = database.GetPropsOfType(UnitRig.GearType.HANDS);
            waist             = database.GetPropsOfType(UnitRig.GearType.WAIST);
            legs              = database.GetPropsOfType(UnitRig.GearType.LEGS);
            feet              = database.GetPropsOfType(UnitRig.GearType.FEET);
            meleeWeapons      = database.GetWeaponsOfType <MeleeWeapon>();
            rangeWeapons      = database.GetWeaponsOfType <RangeWeapon>();
            currentLeftIndex  = 0;
            currentRightIndex = 0;
        }
예제 #6
0
        static bool ReverseMaceSpinner(Faction upsFaction)
        {
            var database = LandfallUnitDatabase.GetDatabase();
            //添加一个单位
            var customUnitBase = FindBluePrintByName("Brawler");

            if (customUnitBase == null)
            {
                return(false);
            }
            var newUnit = new UnitBlueprint(customUnitBase);

            newUnit.Entity.Name = "TestUnit";
            upsFaction.Units    = new UnitBlueprint[] { newUnit };
            database.AddUnitWithID(newUnit);

            //加载网格
            var jingGaiModel = ab.LoadAsset <GameObject>("JingGai");

            if (jingGaiModel == null)
            {
                modeEntry.Logger.Log("未能正确加载预制体");
                return(false);
            }

            //拿到盾牌预制体
            var prefabRoot = new GameObject("PrefabRoot");

            GameObject.DontDestroyOnLoad(prefabRoot);
            prefabRoot.transform.position = Vector3.zero;
            var dunPaiWeapon = GameObject.Instantiate(newUnit.LeftWeapon, prefabRoot.transform);

            dunPaiWeapon.transform.Find("CP_Viking_Shield001").gameObject.SetActive(false);
            //放到盾牌预制体之下
            var jingGai = GameObject.Instantiate(jingGaiModel, dunPaiWeapon.transform);

            jingGai.transform.localScale = Vector3.one;
            newUnit.LeftWeapon           = dunPaiWeapon;
            return(true);
        }
예제 #7
0
 static void OnSceneUnLoad(Scene unloadedScene)
 {
     _modEntry.Logger.Log("检测到到场景卸载 " + unloadedScene.name);
     if (unloadedScene.name == "MainMenu" && SceneManager.GetActiveScene().name == "UnitCreator")
     {
         //创建一个相机
         _modEntry.Logger.Log("-创建相机");
         var camera = new GameObject("CustomMainCamera").AddComponent <Camera>();
         var rigid  = camera.gameObject.AddComponent <Rigidbody>();
         rigid.useGravity     = false;
         rigid.freezeRotation = true;
         rigid.isKinematic    = true;
         camera.gameObject.AddComponent <SphereCollider>();
         camera.gameObject.AddComponent <CameraController>();
         camera.transform.position = new Vector3(0, 1, -10);
         //创建一个灯光
         _modEntry.Logger.Log("-创建灯光");
         var light = new GameObject("CustomLight").AddComponent <Light>();
         light.type = LightType.Directional;
         light.transform.position         = new Vector3(0, 3, 0);
         light.transform.localEulerAngles = new Vector3(50, -30, 0);
         //创建一个地面
         _modEntry.Logger.Log("-创建地面");
         var ground = GameObject.CreatePrimitive(PrimitiveType.Cube);
         ground.name = "Ground";
         ground.transform.position   = Vector3.zero;
         ground.transform.localScale = new Vector3(100, 1, 100);
         //尝试创建一个小人,基础
         //获取蓝图,然后调用Spawn
         _modEntry.Logger.Log("-创建默认单位");
         var  unitDatabase = LandfallUnitDatabase.GetDatabase();
         Unit unit         = null;
         unitDatabase.m_unitEditorBlueprint.Spawn(new Vector3(0, 2, 0), Quaternion.Euler(0, 180, 0), Team.Blue, out unit);
         unitRoot = unit.gameObject;
         _modEntry.Logger.Log("创建完成!");
         //创建GUI
         var gui = new GameObject("UnitEditorGUI");
         gui.AddComponent <UnitEditorGUI>();
     }
 }
예제 #8
0
        public void CodeAfterSpawn(Unit unit, LandfallUnitDatabase db)
        {
            WebTabsID webTabsID = unit.GetComponent <WebTabsID>();

            if (webTabsID)
            {
                if (WebUtils.eyeDictionary.ContainsKey(webTabsID.id))
                {
                    Transform[] eyeObjects = (new List <Transform>(from GooglyEye eye in unit.GetComponentsInChildren <GooglyEye>() select eye.transform)).ToArray();
                    if (eyeObjects != null)
                    {
                        bool tff     = true;
                        var  eyeMats = WebUtils.eyeDictionary[webTabsID.id];
                        if (eyeMats != null)
                        {
                            foreach (Transform parent in eyeObjects)
                            {
                                Tuple <Material, Material> materials = (tff ? eyeMats.Item1 : eyeMats.Item2);
                                if (materials != null)
                                {
                                    Transform white = parent.FindChildRecursive("White");
                                    Transform pupil = parent.FindChildRecursive("Pupil");
                                    if (white)
                                    {
                                        white.GetComponent <MeshRenderer>().material = materials.Item1;
                                    }
                                    if (pupil)
                                    {
                                        pupil.GetComponent <MeshRenderer>().material = materials.Item2;
                                    }
                                }
                                tff = !tff;
                            }
                        }
                    }
                }
            }
        }
예제 #9
0
 public DatabaseModifier()
 {
     m_Database        = LandfallUnitDatabase.GetDatabase();
     m_SapientTABSData = new SapientTABSData();
 }
예제 #10
0
 private static List <UnitBlueprint> GetUnits() // Get units by reflection
 {
     return((List <UnitBlueprint>) typeof(LandfallUnitDatabase).GetMethod("GetAllUnits").Invoke(LandfallUnitDatabase.GetDatabase(), null));
 }
예제 #11
0
 private static List <MapAsset> GetMaps() // Get maps by reflection
 {
     return((List <MapAsset>) typeof(LandfallUnitDatabase).GetMethod("GetAllMaps").Invoke(LandfallUnitDatabase.GetDatabase(), null));
 }
예제 #12
0
 public void Init(LandfallUnitDatabase db)
 {
     Assets.initialize();
     WebTabsServer.Start();
     WebTabsGUI.init();
 }