Пример #1
0
 public UiAnimationFade(GameObject gameobject, float duration, FadeType fadeType) : base(gameobject)
 {
     Canvas = gameobject.GetOrAddComponent<CanvasGroup>();
     Canvas.alpha = fadeType == FadeType.In ? 0f : Canvas.alpha;
     Duration = duration;
     Fade = fadeType;
 }
Пример #2
0
 public UiAnimationScale(GameObject gameobject, Vector3 from, Vector3 to, float duration) : base(gameobject)
 {
     Canvas = gameobject.GetOrAddComponent<CanvasGroup>();
     Duration = duration;
     To = to;
     From = from;
 }
Пример #3
0
    protected override void Init()
    {
        base.Init();

        SceneType = Define.Scene.Game;

        Dictionary <int, Data.Stat> dict = Managers.Data.StatDict;

        gameObject.GetOrAddComponent <CursorController>();

        GameObject player = Managers.Game.Spawn(Define.WorldObject.Player, "UnityChan");

        Camera.main.gameObject.GetOrAddComponent <CameraController>().SetPlayer(player);
        GameObject go = new GameObject {
            name = "SpawningPool"
        };
        SpawningPool pool = go.GetOrAddComponent <SpawningPool>();

        pool.SetKeepMonsterCount(5);
    }
Пример #4
0
        private GameObject SpawnNewCompanion(string guid)
        {
            AIActor orLoadByGuid = EnemyDatabase.GetOrLoadByGuid(guid);
            Vector3 vector       = Owner.transform.position;

            if (GameManager.Instance.CurrentLevelOverrideState == GameManager.LevelOverrideState.FOYER)
            {
                vector += new Vector3(1.125f, -0.3125f, 0f);
            }
            GameObject          extantCompanion2 = UnityEngine.Object.Instantiate <GameObject>(orLoadByGuid.gameObject, vector, Quaternion.identity);
            CompanionController orAddComponent   = extantCompanion2.GetOrAddComponent <CompanionController>();

            orAddComponent.Initialize(gun.CurrentOwner as PlayerController);
            if (orAddComponent.specRigidbody)
            {
                PhysicsEngine.Instance.RegisterOverlappingGhostCollisionExceptions(orAddComponent.specRigidbody, null, false);
            }

            return(extantCompanion2);
        }
Пример #5
0
        /// <summary>
        /// 创建界面
        /// </summary>
        /// <param name="uiFormInstance">界面实例</param>
        /// <param name="uiGroup">界面所属的界面组</param>
        /// <param name="userData">用户自定义数据</param>
        /// <returns>界面</returns>
        public override UIForm CreateUIForm(object uiFormInstance, UIGroup uiGroup, object userData)
        {
            GameObject gameObject = uiFormInstance as GameObject;

            if (gameObject == null)
            {
                Debug.LogError("要创建的界面的实例为空");
                return(null);
            }

            Transform transform = gameObject.transform;

            transform.SetParent(uiGroup.UIGroupHelper.transform);
            transform.localScale = Vector3.one;

            //挂载UIForm脚本
            UIForm uiForm = gameObject.GetOrAddComponent <UIForm>();

            return(uiForm);
        }
Пример #6
0
    public override void Init()
    {
        Items.Clear();

        GameObject grid = transform.Find("ItemGrid").gameObject;

        foreach (Transform child in grid.transform)
        {
            Destroy(child.gameObject);
        }

        for (int i = 0; i < 20; i++)
        {
            GameObject        go   = Managers.Resource.Instantiate("UI/Scene/UI_Inventory_Item", grid.transform);
            UI_Inventory_Item item = go.GetOrAddComponent <UI_Inventory_Item>();
            Items.Add(item);
        }

        RefreshUI();
    }
Пример #7
0
        public PoolGameObject RequestPoolGameObject(string prefabName, Vector3 pos)
        {
            CreatePool();
            PoolGameObject temp = GetFromPool(prefab);

            if (temp == null)
            {
                Resources.Load <PoolGameObject>();
                GameObject go = GameObject.Instantiate(prefab);
                temp = go.GetOrAddComponent <PoolGameObject>();
                temp.transform.position = pos;
                temp.SetParent(pool.transform);
                if (!mPool.ContainsKey(prefab.name))
                {
                    mPool.Add(prefab.name, new Queue <PoolGameObject>());
                }
            }
            mPool[prefab.name].Enqueue(temp);
            return(temp);
        }
Пример #8
0
    public T MakeWorldSpaceUI <T>(Transform parent = null, string name = null) where T : UI_Base
    {
        if (string.IsNullOrEmpty(name))
        {
            name = typeof(T).Name;
        }
        GameObject go = Managers.Resource.Instantiate($"UI/WorldSpace/{name}");

        if (parent != null)
        {
            go.transform.SetParent(parent);
        }

        Canvas canvas = go.GetOrAddComponent <Canvas>();

        canvas.renderMode  = RenderMode.WorldSpace;
        canvas.worldCamera = Camera.main;

        return(Util.GetOrAddComponent <T>(go));
    }
Пример #9
0
    protected override void Init()
    {
        base.Init();

        SceneType = Define.Scene.Game;
        //Managers.UI.ShowSceneUI<UI_Inven>();
        gameObject.GetOrAddComponent <CursorController>();

        GameObject player = Managers.Game.Spawn(Define.WorldObject.Player, "UnityChan");

        Camera.main.gameObject.GetOrAddComponent <CameraController>().SetPlayer(player);

        //Managers.Game.Spawn(Define.WorldObject.Monster, "Knight");
        GameObject go = new GameObject {
            name = "SpawningPool"
        };
        SpawningPool pool = go.GetOrAddComponent <SpawningPool>();

        pool.SetKeepMonsterCount(5);
    }
Пример #10
0
    public override void Init()
    {
        base.Init();

        Bind <GameObject>(typeof(GameObjects));
        GameObject gridPanel = Get <GameObject>((int)GameObjects.GridPanel);

        foreach (Transform child in gridPanel.transform)
        {
            Managers.Resource.Destroy(child.gameObject);
        }

        for (int i = 0; i < 8; i++)
        {
            GameObject item = Managers.UI.MakeSubItem <UI_Inven_Item>(gridPanel.transform).gameObject;

            UI_Inven_Item invenItem = item.GetOrAddComponent <UI_Inven_Item>();
            invenItem.SetInfo($"집행검{i}");
        }
    }
Пример #11
0
        /// <summary>
        /// Subscribes this gameobject to the action space
        /// </summary>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        private StratusActionDriver SubscribeToActions(GameObject gameObject)
        {
            if (this.actionsOwnerMap.ContainsKey(gameObject))
            {
                return(this.actionsOwnerMap[gameObject].owner);
            }

            if (StratusActions.debug)
            {
                StratusDebug.Log("Adding the GameObject to the ActionSpace");
            }

            StratusActionDriver owner     = new StratusActionDriver(gameObject);
            ActionsContainer    container = new ActionsContainer(gameObject, owner);

            this.activeActions.Add(container);
            this.actionsOwnerMap.Add(gameObject, container);
            gameObject.GetOrAddComponent <StratusActionsRegistration>();
            return(owner);
        }
Пример #12
0
        public VRCEUiPage(string name, string displayName)
        {
            // Get defaults
            GameObject avatarScreen = VRCEUi.AvatarScreen;
            VRCUiPage  avatarPage   = avatarScreen.GetComponent <VRCUiPage>();

            if (avatarScreen == null || avatarPage == null)
            {
                MVRCLogger.LogError("Could not find avatar screen!");
                Success = false;
                return;
            }

            // Create GameObject
            GameObject goControl = new GameObject(name);

            // Get positions
            Position = goControl.GetOrAddComponent <RectTransform>();

            // Set UI properties
            Control = goControl.transform;

            // Set control properties
            Page = goControl.AddComponent <VRCUiPage>();

            // Set required parts
            Control.SetParent(avatarScreen.transform.parent, false);

            // Change UI properties
            Page.AudioHide   = avatarPage.AudioHide;
            Page.AudioShow   = avatarPage.AudioShow;
            Page.displayName = displayName;
            Page.screenType  = avatarPage.screenType;

            // Add control events
            Page.onPageActivated   += () => OnPageActivated?.Invoke();
            Page.onPageDeactivated += () => OnpageDeatvitvated?.Invoke();

            // Finish
            Success = true;
        }
Пример #13
0
 private void OnDestroy(Projectile proj)
 {
     if (this.catchedEnemy != null)
     {
         string  guid           = this.catchedEnemy.EnemyGuid;
         Vector2 pos            = this.catchedEnemy.sprite.WorldBottomLeft;
         Vector2 blankPos       = this.catchedEnemy.sprite.WorldCenter;
         bool    isBlackPhantom = this.catchedEnemy.IsBlackPhantom;
         this.catchedEnemy.EraseFromExistence(true);
         AIActor             orLoadByGuid   = EnemyDatabase.GetOrLoadByGuid(guid);
         GameObject          gameObject     = UnityEngine.Object.Instantiate <GameObject>(orLoadByGuid.gameObject, pos, Quaternion.identity);
         CompanionController orAddComponent = gameObject.GetOrAddComponent <CompanionController>();
         if (isBlackPhantom)
         {
             gameObject.GetComponent <AIActor>().BecomeBlackPhantom();
         }
         orAddComponent.companionID = CompanionController.CompanionIdentifier.NONE;
         orAddComponent.Initialize(this.thrower);
         orAddComponent.behaviorSpeculator.MovementBehaviors.Add(new CompanionFollowPlayerBehavior());
         AIActor aiactor = gameObject.GetComponent <AIActor>();
         if (orAddComponent.healthHaver != null)
         {
             orAddComponent.healthHaver.PreventAllDamage = true;
         }
         if (orAddComponent.bulletBank != null)
         {
             orAddComponent.bulletBank.OnProjectileCreated += CatchProjectileBehaviour.OnPostProcessProjectile;
         }
         if (orAddComponent.aiShooter != null)
         {
             orAddComponent.aiShooter.PostProcessProjectile += CatchProjectileBehaviour.OnPostProcessProjectile;
         }
     }
     else
     {
         if (this.parentItem != null)
         {
             parentItem.thrown = false;
         }
     }
 }
Пример #14
0
        // Token: 0x060000A5 RID: 165 RVA: 0x00005A2C File Offset: 0x00003C2C
        private void OpenWindow(Type type, string resPath, Transform parent, UICallback callback)
        {
            UIBaseWindow uibaseWindow;
            bool         flag = this._windowPool.TryGetValue(resPath, out uibaseWindow);
            UIBaseWindow uibaseWindow2;

            if (flag)
            {
                uibaseWindow.gameObject.SetActive(true);
                uibaseWindow2 = uibaseWindow;
                this._windowPool.Remove(resPath);
            }
            else
            {
                GameObject gameObject = Resources.Load <GameObject>("UI/" + resPath);
                bool       flag2      = gameObject == null;
                if (flag2)
                {
                    Debug.LogError("OpenWindow failed: can not find prefab" + resPath);
                    if (callback != null)
                    {
                        callback(null);
                    }
                    return;
                }
                Debug.Log("UIresPath " + resPath);
                GameObject obj = Object.Instantiate <GameObject>(gameObject, parent);
                uibaseWindow2         = obj.GetOrAddComponent <UIBaseWindow>();
                uibaseWindow2.ResPath = resPath;
            }
            this.openedWindows.Add(uibaseWindow2);
            uibaseWindow2._uiService = this;
            uibaseWindow2.DoAwake();
            uibaseWindow2.DoStart();
            this._eventRegisterService.RegisterEvent(uibaseWindow2);
            this.RegisterUiEvent(uibaseWindow2);
            if (callback != null)
            {
                callback(uibaseWindow2);
            }
        }
Пример #15
0
        private void UpdatePhysicsConfiguration()
        {
            if (HandControllerDataProvider.HandPhysicsEnabled)
            {
                // If we are using hand physics, we need to make sure
                // the physics companion is setup properly.
                if (PhysicsCompanionGameObject != null)
                {
                    PhysicsCompanionGameObject.SetActive(true);
                    PhysicsCompanionGameObject.transform.localPosition = GameObject.transform.localPosition;
                    PhysicsCompanionGameObject.transform.localRotation = GameObject.transform.localRotation;
                    return;
                }

                PhysicsCompanionGameObject = new GameObject($"{GameObject.name}_Physics");
                PhysicsCompanionGameObject.transform.SetParent(GameObject.transform.parent, false);
                PhysicsCompanionGameObject.transform.localPosition = GameObject.transform.localPosition;
                PhysicsCompanionGameObject.transform.localRotation = GameObject.transform.localRotation;

                // Setup the kinematic rigidbody on the actual controller game object.
                Rigidbody controllerRigidbody = GameObject.GetOrAddComponent <Rigidbody>();
                controllerRigidbody.mass                   = .46f; // 0.46 Kg average human hand weight
                controllerRigidbody.isKinematic            = true;
                controllerRigidbody.useGravity             = false;
                controllerRigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;

                // Make the physics proxy a fixed joint rigidbody to the controller
                // and give it an adamantium coated connection so it doesn't break.
                Rigidbody physicsRigidbody = PhysicsCompanionGameObject.GetOrAddComponent <Rigidbody>();
                physicsRigidbody.mass = .46f; // 0.46 Kg average human hand weight
                physicsRigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
                FixedJoint fixedJoint = PhysicsCompanionGameObject.GetOrAddComponent <FixedJoint>();
                fixedJoint.connectedBody = controllerRigidbody;
                fixedJoint.breakForce    = float.MaxValue;
                fixedJoint.breakTorque   = float.MaxValue;
            }
            else if (PhysicsCompanionGameObject != null)
            {
                PhysicsCompanionGameObject.SetActive(false);
            }
        }
        private void CreateCompanion(PlayerController owner)
        {
            if (PreventRespawnOnFloorLoad)
            {
                return;
            }

            if (string.IsNullOrEmpty(CompanionGuid))
            {
                return;
            }

            AIActor m_NewAIActor = EnemyDatabase.GetOrLoadByGuid(CompanionGuid);
            Vector3 vector       = owner.transform.position;

            if (GameManager.Instance.CurrentLevelOverrideState == GameManager.LevelOverrideState.FOYER)
            {
                vector += new Vector3(1.125f, -0.3125f, 0f);
            }
            m_extantCompanion = Instantiate(m_NewAIActor.gameObject, vector, Quaternion.identity);

            if (m_extantCompanion)
            {
                CompanionController orAddComponent = m_extantCompanion.GetOrAddComponent <CompanionController>();
                orAddComponent.Initialize(owner);

                if (orAddComponent.specRigidbody)
                {
                    PhysicsEngine.Instance.RegisterOverlappingGhostCollisionExceptions(orAddComponent.specRigidbody, null, false);
                }

                if (m_HammersHidden)
                {
                    orAddComponent.enabled = false;
                    m_extantCompanion.GetComponent <AIActor>().ToggleRenderers(false);
                    m_extantCompanion.GetComponent <AIActor>().IsGone = true;
                    m_extantCompanion.GetComponent <AIActor>().behaviorSpeculator.InterruptAndDisable();
                    orAddComponent.specRigidbody.CollideWithOthers = false;
                }
            }
        }
Пример #17
0
        void Init()
        {
            cachedScale = transform.localScale;
            cachedLayer = gameObject.layer;

            var singleRenderer = GetComponent <Renderer>();
            var spriteRenderer = singleRenderer as SpriteRenderer;
            var meshRenderer   = singleRenderer as MeshRenderer;

            if (spriteRenderer == null && meshRenderer == null)
            {
                Debug.LogError("Danmaku Prefab (" + name +
                               ") has neither SpriteRenderer or MeshRenderer. Attach one or the other to it.");
                Destroy(this);
                return;
            }

            ParticleSystem system = null;

            if (danmakuSystemPrefab != null)
            {
                system = Instantiate(danmakuSystemPrefab);
            }
            if (system == null)
            {
                GameObject runtimeObject =
                    Instantiate(Resources.Load("Danmaku Particle System")) as
                    GameObject ?? new GameObject(name);
                system = runtimeObject.GetOrAddComponent <ParticleSystem>();
            }
            if (meshRenderer)
            {
                type = system.gameObject.AddComponent <MeshDanmaku>();
            }
            else
            {
                type = system.gameObject.AddComponent <SpriteDanmaku>();
            }
            type.Init(singleRenderer, this);
            type.gameObject.SetActive(true);
        }
Пример #18
0
    public void SetServer(List <ServerInfo> servers)
    {
        Items.Clear();
        // 그리드 산하의 모든 아이템UI 날림
        GameObject grid = GetComponentInChildren <GridLayoutGroup>().gameObject;

        foreach (Transform child in grid.transform)
        {
            Destroy(child.gameObject);
        }

        for (int i = 0; i < servers.Count; i++)
        {
            GameObject go = Managers.Resource.Instantiate("UI/Popup/UI_SelectServerPopup_Item", grid.transform);
            UI_SelectServerPopup_Item item = go.GetOrAddComponent <UI_SelectServerPopup_Item>();
            Items.Add(item); // 이제 리스트에서 접근가능

            item.Info = servers[i];
        }
        RefreshUI();
    }
 private void Initialize()
 {
     if (Object.op_Equality((Object)this._prefab, (Object)null))
     {
         return;
     }
     if (Object.op_Equality((Object)this._center, (Object)null))
     {
         this._center = ((Component)this).get_transform();
     }
     this._userMaxCount = this._createNumRange.RandomRange();
     for (int index = 0; index < this._userMaxCount; ++index)
     {
         GameObject gameObject = new GameObject(string.Format("alone_butterfly_{0}", (object)index.ToString("00")));
         gameObject.get_transform().SetParent(((Component)this).get_transform(), false);
         AloneButterfly butterfly = gameObject.GetOrAddComponent <AloneButterfly>();
         butterfly.Initialize(this, this._prefab);
         ObservableExtensions.Subscribe <Unit>(Observable.TakeUntilDestroy <Unit>((IObservable <M0>)ObservableTriggerExtensions.OnDestroyAsObservable((Component)butterfly), (Component)this), (Action <M0>)(_ => this._use.Remove(butterfly)));
         this._use.Add(butterfly);
     }
 }
Пример #20
0
        /// <summary> Adds a passed view to the view stack to show it </summary>
        /// <param name="newView"> The new view to show in the stack </param>
        /// <param name="currentViewToHide"> Any part of the current view on the view stack that should be set to hidden </param>
        /// <param name="siblingIndex">Index where to add the new view in the view stack, default -1 will add it at the end</param>
        public GameObject ShowView(GameObject newView, GameObject currentViewToHide = null, int siblingIndex = -1)
        {
            if (newView.IsPartOfEditorOnlyPrefab())   // If its a prefab first create an instance from it
            {
                var name = newView.name;
                newView      = Instantiate(newView);
                newView.name = name;
            }

            gameObject.AddChild(newView, siblingIndex: siblingIndex);
            if (newView.GetComponentInParents <Canvas>() != null)  // The view is in a UI
            {
                newView.GetOrAddComponent <RectTransform>().SetAnchorsStretchStretch();
            }
            EventBus.instance.Publish(EventConsts.catView + EventConsts.SHOW, newView);
            if (currentViewToHide != null)
            {
                GetRootViewOf(currentViewToHide).SetActiveV2(false);
            }
            return(newView);
        }
Пример #21
0
        public static tk2dSpriteAnimationClip AddAnimation(this GameObject obj, string name, string spriteDirectory, int fps, AnimationType type, DirectionType directionType = DirectionType.None, FlipType flipType = FlipType.None)
        {
            AIAnimator           aiAnimator = obj.GetOrAddComponent <AIAnimator>();
            DirectionalAnimation animation  = aiAnimator.GetDirectionalAnimation(name, directionType, type);

            if (animation == null)
            {
                animation = new DirectionalAnimation()
                {
                    AnimNames = new string[0],
                    Flipped   = new FlipType[0],
                    Type      = directionType,
                    Prefix    = string.Empty
                };
            }

            animation.AnimNames = animation.AnimNames.Concat(new string[] { name }).ToArray();
            animation.Flipped   = animation.Flipped.Concat(new FlipType[] { flipType }).ToArray();
            aiAnimator.AssignDirectionalAnimation(name, animation, type);
            return(BuildAnimation(aiAnimator, name, spriteDirectory, fps));
        }
Пример #22
0
    public override void Init()
    {
        base.Init();

        Bind <GameObject>(typeof(GameObjects));

        GameObject gridPanel = Get <GameObject>((int)GameObjects.GridPanel);

        foreach (Transform child in gridPanel.transform)
        {
            Managers.Resource.Destroy(child.gameObject);
        }

        for (int i = 0; i < 8; ++i)
        {
            GameObject item = Managers.Ui.MakeSubItem <UiInvenItem>(parent: gridPanel.transform).gameObject;

            UiInvenItem itemInfo = item.GetOrAddComponent <UiInvenItem>();
            itemInfo.SetInfo($"mtf {i}");
        }
    }
Пример #23
0
        public Factory(TObj typeObject, GameObject gameObject, GameObject parentObject, bool allowMultiple = false, bool startInactive = false)
        {
            TypeObject   = typeObject;
            GameObject   = gameObject ? gameObject : new GameObject();
            ParentObject = parentObject;
            if (parentObject)
            {
                GameObject.transform.SetParent(parentObject.transform);
            }
            GameObject.SetActive(!startInactive);

            if (allowMultiple)
            {
                Component = GameObject.AddComponent <TCom>();
            }
            else
            {
                Component = GameObject.GetOrAddComponent <TCom>();
            }
            Component.SetLogLevel(TypeObject.LogLevel);
        }
Пример #24
0
        public void ExampleUsage1()
        {
            GameObject myGo = new GameObject();
            // Adding children GameObjects via AddChild:
            GameObject myChildGo = myGo.AddChild(new GameObject());

            // Getting the parent of the child via GetParent:
            Assert.AreSame(myGo, myChildGo.GetParent());

            // Lazy-initialization of the GameObject in case it does not yet exist:
            GameObject child1 = myGo.GetOrAddChild("Child 1");
            // Lazy-initialization of the Mono in case it does not yet exist:
            MyExampleMono1 myMono1 = child1.GetOrAddComponent <MyExampleMono1>();
            // Calling the 2 methods again results always in the same mono:
            var myMono1_ref2 = myGo.GetOrAddChild("Child 1").GetOrAddComponent <MyExampleMono1>();

            Assert.AreSame(myMono1, myMono1_ref2);

            myGo.Destroy();                    // Destroy the gameobject
            Assert.IsTrue(myGo.IsDestroyed()); // Check if it was destroyed
        }
Пример #25
0
        protected override void DoEffect(PlayerController user)
        {
            //walls_check
            RoomHandler room;

            room = GameManager.Instance.Dungeon.data.GetAbsoluteRoomFromPosition(Vector2Extensions.ToIntVector2(user.CenterPosition, VectorConversions.Round));
            CellData cellaim      = room.GetNearestCellToPosition(user.CenterPosition);
            CellData cellaimmunis = room.GetNearestCellToPosition(user.CenterPosition - new Vector2(0, 1));

            //if not in or near wall
            if (cellaim.HasWallNeighbor(true, true) == false && cellaimmunis.HasWallNeighbor(true, true) == false)
            {
                //Destroy last instance of object if availible
                if (m_Gun != null)
                {
                    UnityEngine.GameObject.DestroyObject(m_Gun);
                }


                //make new gun
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(Sheila.Gun, this.LastOwner.transform.position + new Vector3(0.6f, 1.05f, -6f), Quaternion.identity);
                gameObject.GetComponent <tk2dBaseSprite>().PlaceAtLocalPositionByAnchor(this.LastOwner.specRigidbody.UnitCenter, tk2dBaseSprite.Anchor.MiddleCenter);

                gameObject.GetOrAddComponent <TurretController>();
                m_Gun_position = this.LastOwner.transform.position + new Vector3(0.6f, 1.05f, -6f);
                m_Gun          = gameObject;
                AkSoundEngine.PostEvent("Play_tur_place", base.gameObject);
                AkSoundEngine.PostEvent("Play_tur_place", base.gameObject);
                AkSoundEngine.PostEvent("Play_tur_place", base.gameObject);
                AkSoundEngine.PostEvent("Play_tur_place", base.gameObject);
            }
            else
            {
                //reset wall bool

                //refund charge
                FieldInfo remainingTimeCooldown = typeof(PlayerItem).GetField("remainingTimeCooldown", BindingFlags.NonPublic | BindingFlags.Instance);
                remainingTimeCooldown.SetValue(this.gameObject, 0);
            }
        }
Пример #26
0
        void GenerateSphereCollider(GameObject boneCollider, Vector2[] points)
        {
            float l = float.MaxValue;
            float r = float.MinValue;
            float d = float.MaxValue;
            float u = float.MinValue;

            for (int i = 0; i < points.Length; i++)
            {
                if (points[i].x < l)
                {
                    l = points[i].x;
                }

                if (points[i].x > r)
                {
                    r = points[i].x;
                }

                if (points[i].y < d)
                {
                    d = points[i].y;
                }

                if (points[i].y > u)
                {
                    u = points[i].y;
                }
            }

            float radius = Mathf.Max(Mathf.Abs(l - r), Mathf.Abs(d - u)) / 2 * physicsOptions.colliderSize;

            if (radius >= 0.001F)
            {
                SphereCollider sphere = boneCollider.GetOrAddComponent <SphereCollider>();
                sphere.radius         = radius;
                sphere.center         = new Vector3(l + r, u + d, 0) / 2;
                sphere.sharedMaterial = physicsOptions.colliderMaterial;
            }
        }
Пример #27
0
        private void KaliberSynergy()
        {
            AIActor orLoadByGuid;
            bool    isHoleyKin = false;

            if (UnityEngine.Random.value <= 0.5f)
            {
                orLoadByGuid = EnemyDatabase.GetOrLoadByGuid(RnGEnemyDatabase.GetRnGEnemyGuid(RnGEnemyDatabase.RnGEnemyType.BulletmanBroccoli));
            }
            else
            {
                orLoadByGuid = EnemyDatabase.GetOrLoadByGuid(RnGEnemyDatabase.GetRnGEnemyGuid(RnGEnemyDatabase.RnGEnemyType.BulletmanKaliber));
                isHoleyKin   = true;
            }
            IntVector2?nearestAvailableCell = this.m_owner.CurrentRoom.GetNearestAvailableCell(this.m_owner.transform.position.XY(), new IntVector2?(orLoadByGuid.Clearance), new CellTypes?(CellTypes.FLOOR), false, null);

            if (nearestAvailableCell == null)
            {
                return;
            }
            GameObject          gameObject     = UnityEngine.Object.Instantiate <GameObject>(orLoadByGuid.gameObject, (nearestAvailableCell.Value.ToVector2()).ToVector3ZUp(0f), Quaternion.identity);
            CompanionController orAddComponent = gameObject.GetOrAddComponent <CompanionController>();

            orAddComponent.companionID = CompanionController.CompanionIdentifier.NONE;
            orAddComponent.Initialize(this.m_owner);
            orAddComponent.behaviorSpeculator.MovementBehaviors.Add(new CompanionFollowPlayerBehavior());
            AIActor aiactor = gameObject.GetComponent <AIActor>();

            aiactor.HitByEnemyBullets         = true;
            aiactor.healthHaver.ModifyDamage += this.ModifyDamageForCompanions;
            if (UnityEngine.Random.value <= 0.05f)
            {
                aiactor.BecomeBlackPhantom();
                aiactor.aiShooter.GetBulletEntry((aiactor.behaviorSpeculator.AttackBehaviors[0] as ShootGunBehavior).OverrideBulletName).ProjectileData.damage = isHoleyKin ? 5 : 10;
            }
            else
            {
                aiactor.aiShooter.GetBulletEntry((aiactor.behaviorSpeculator.AttackBehaviors[0] as ShootGunBehavior).OverrideBulletName).ProjectileData.damage = isHoleyKin ? 7 : 15;
            }
        }
Пример #28
0
        void GenerateCircleCollider2D(GameObject boneCollider, Vector2[] points)
        {
            float l = float.MaxValue;
            float r = float.MinValue;
            float d = float.MaxValue;
            float u = float.MinValue;

            for (int i = 0; i < points.Length; i++)
            {
                if (points[i].x < l)
                {
                    l = points[i].x;
                }

                if (points[i].x > r)
                {
                    r = points[i].x;
                }

                if (points[i].y < d)
                {
                    d = points[i].y;
                }

                if (points[i].y > u)
                {
                    u = points[i].y;
                }
            }

            float radius = Mathf.Max(Mathf.Abs(l - r), Mathf.Abs(d - u)) / 2 * physicsOptions.colliderSize;

            if (radius >= 0.001F)
            {
                CircleCollider2D circle2D = boneCollider.GetOrAddComponent <CircleCollider2D>();
                circle2D.radius         = radius;
                circle2D.offset         = new Vector2(l + r, u + d) / 2;
                circle2D.sharedMaterial = physicsOptions.colliderMaterial2D;
            }
        }
Пример #29
0
        void GenerateBoxCollider2D(GameObject boneCollider, Vector2[] points)
        {
            float l = float.MaxValue;
            float r = float.MinValue;
            float d = float.MaxValue;
            float u = float.MinValue;

            for (int i = 0; i < points.Length; i++)
            {
                if (points[i].x < l)
                {
                    l = points[i].x;
                }

                if (points[i].x > r)
                {
                    r = points[i].x;
                }

                if (points[i].y < d)
                {
                    d = points[i].y;
                }

                if (points[i].y > u)
                {
                    u = points[i].y;
                }
            }

            Vector2 size = new Vector2(Mathf.Abs(l - r), Mathf.Abs(d - u)) * physicsOptions.colliderSize;

            if (size.x >= 0.055F || size.y >= 0.055F)
            {
                BoxCollider2D box2D = boneCollider.GetOrAddComponent <BoxCollider2D>();
                box2D.size           = new Vector2(Mathf.Max(size.x, 0.055F), Mathf.Max(size.y, 0.055F));
                box2D.offset         = new Vector2(l + r, u + d) / 2;
                box2D.sharedMaterial = physicsOptions.colliderMaterial2D;
            }
        }
Пример #30
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="res">ResHelper.</param>
    protected override void onBaseResLoadCompleteSyncCall()
    {
        if (bundle != null)
        {
            asset = bundle.LoadAsset <GameObject>(modelName);
            bundle.Unload(false);
            bundle = null;
            if (asset == null)
            {
                return;
            }
            #if UNITY_EDITOR
            EditorHelper.SetEditorShader(asset);
            #endif
            var refholder = asset.GetOrAddComponent <InstanceAssetRefHolder>();
            refholder.resType   = ResourceType.Model;
            refholder.assetName = modelName;
            //加载模型贴图资源
            var matHolder = asset.GetComponent <PrefabRenderHolder>();
            if (matHolder != null)
            {
                texResRefs.Clear();
                meshResRefs.Clear();
                //GameObject.DestroyImmediate(matHolder, true);
                SyncLoadMatsTex(matHolder.rendersMatTexInfo, texResRefs);
                SyncLoadPrefabMesh(matHolder.rendersMeshInfo, meshResRefs);

                matHolder.rendersMatTexInfo = null;
                matHolder.rendersMeshInfo   = null;
            }
            //加载动作clip资源
            clipHolder = asset.GetComponent <AnimationHolder>();
            if (clipHolder != null)
            {
                clipHolder.SyncLoadClips();
                depAnimList = clipHolder.depAnimList;
                GameObject.DestroyImmediate(clipHolder, true);
            }
        }
    }
Пример #31
0
    //몬스터를 스폰해주는 함수
    IEnumerator ReserveSpawn()
    {
        //몬스터를 생성하지는 않았지만 예약을 일단 함.
        _reserveCount++;
        yield return(new WaitForSeconds(Random.Range(1.0f, _spawnTime)));

        //몬스터를 실질적으로 생성해줍니다. (여기서 AddMonsterCount의 값을1 증가 시켜 줌.
        GameObject go = Managers.Game.Spawn(Define.WorldObject.Monster, "Knight");

        //직전에 생성한 오브젝트에 NavMeshAgent가 추가 또는 가져와줍니다.
        NavMeshAgent nma = go.GetOrAddComponent <NavMeshAgent>();

        Vector3 randPos;

        while (true)
        {
            yield return(null);

            //sectionA지역에_spawnRadius 지름의 원을 그려 랜덤좌표를 찍음.
            Vector3 randDir = Random.insideUnitSphere * _spawnRadius + Define.sectionA;

            //상공에서 Raycast를 쏘기 위해 높이를 임시로 100으로 해줌.
            randDir.y = 100.0f;

            RaycastHit hit;
            //맵의 높이가 다 다름으로 상공에서 Raycast를 쏴서 높이를 구하는 것
            Debug.DrawRay(randDir, Vector3.down * 100.0f, Color.red, 1);
            //True -> Raycast가 땅에 부딪쳤을 시.
            //False -> 땅이 아닌 나무 위, 돌 위등 다른 오브젝트가 부딪친 것(몬스터를 스폰하지 않음)
            if (Physics.Raycast(randDir, Vector3.down, out hit, 100.0f, LayerMask.GetMask("Ground")))
            {
                //높이를 구해주고 해당 높이로 설정
                randPos   = hit.point;
                randPos.y = randPos.y + 0.3f;
                break;
            }
        }
        _reserveCount--; //0, 1, 2, 3, 4, 5,
        go.transform.position = randPos;
    }
Пример #32
0
    public static void InitializeAccessory(GameObject selectedObject, bool initializeTransform = false)
    {
        var gameObject = selectedObject;

        gameObject.layer = 10;
        if (gameObject == null)
        {
            return;
        }

        CmpAccessory accComponent;

        if (initializeTransform)
        {
            var newWrapper = new GameObject(gameObject.name + "_acc");

            if (gameObject.transform.parent != null)
            {
                newWrapper.transform.position    = Vector3.zero;
                newWrapper.transform.eulerAngles = Vector3.zero;
                newWrapper.transform.localScale  = Vector3.one;
                newWrapper.transform.SetParent(gameObject.transform.parent, false);
            }

            var newRoot = new GameObject("N_move");
            newRoot.transform.position    = gameObject.transform.position;
            newRoot.transform.eulerAngles = Vector3.zero;
            newRoot.transform.localScale  = Vector3.one;

            newRoot.transform.parent    = newWrapper.transform;
            gameObject.transform.parent = newRoot.transform;
            accComponent = newWrapper.GetOrAddComponent <CmpAccessory>();
        }
        else
        {
            accComponent = gameObject.GetOrAddComponent <CmpAccessory>();
        }

        accComponent.ReassignAllObjects();
    }
Пример #33
0
            public static void syncNode(ref uint availableSyncOperations, GameObject nodeGameObject, uint nodeHandle, GameObject voxelTerrainGameObject)
            {
                OctreeNode octreeNode = nodeGameObject.GetComponent<OctreeNode>();
                CuOctreeNode cuOctreeNode = CubiquityDLL.GetOctreeNode(nodeHandle);

                ////////////////////////////////////////////////////////////////////////////////
                // Has anything in this node or its children changed? If so, we may need to syncronise the node's properties, mesh and
                // structure. Each of these can be tested against a timestamp. We may also need to do this recursively on child nodes.
                ////////////////////////////////////////////////////////////////////////////////
                if (cuOctreeNode.nodeOrChildrenLastChanged > octreeNode.nodeAndChildrenLastSynced)
                {
                    bool resyncedProperties = false; // See comments where this is tested - it's a bit of a hack

                    ////////////////////////////////////////////////////////////////////////////////
                    // 1st test - Have the properties of the node changed?
                    ////////////////////////////////////////////////////////////////////////////////
                    if (cuOctreeNode.propertiesLastChanged > octreeNode.propertiesLastSynced)
                    {
                        octreeNode.renderThisNode = cuOctreeNode.renderThisNode != 0;
                        octreeNode.height = cuOctreeNode.height;
                        octreeNode.propertiesLastSynced = CubiquityDLL.GetCurrentTime();
                        resyncedProperties = true;
                    }

                    ////////////////////////////////////////////////////////////////////////////////
                    // 2nd test - Has the mesh changed and do we have time to syncronise it?
                    ////////////////////////////////////////////////////////////////////////////////
                    if ((cuOctreeNode.meshLastChanged > octreeNode.meshLastSynced) && (availableSyncOperations > 0))
                    {
                        if (cuOctreeNode.hasMesh == 1)
                        {
                            // Set up the rendering mesh
                            VolumeRenderer volumeRenderer = voxelTerrainGameObject.GetComponent<VolumeRenderer>();
                            if (volumeRenderer != null)
                            {
                                MeshFilter meshFilter = nodeGameObject.GetOrAddComponent<MeshFilter>() as MeshFilter;
                                if(meshFilter.sharedMesh == null)
                                {
                                    meshFilter.sharedMesh = new Mesh();
                                }
                                MeshRenderer meshRenderer = nodeGameObject.GetOrAddComponent<MeshRenderer>() as MeshRenderer;

                                if (voxelTerrainGameObject.GetComponent<Volume>().GetType() == typeof(TerrainVolume))
                                {
                                    MeshConversion.BuildMeshFromNodeHandleForTerrainVolume(meshFilter.sharedMesh, nodeHandle, false);
                                }
                                else if (voxelTerrainGameObject.GetComponent<Volume>().GetType() == typeof(ColoredCubesVolume))
                                {
                                    MeshConversion.BuildMeshFromNodeHandleForColoredCubesVolume(meshFilter.sharedMesh, nodeHandle, false);
                                }

                                meshRenderer.enabled = volumeRenderer.enabled && octreeNode.renderThisNode;

                                // For syncing materials, shadow properties, etc.
                                syncNodeWithVolumeRenderer(nodeGameObject, volumeRenderer, false);
                            }

                            // Set up the collision mesh
                            VolumeCollider volumeCollider = voxelTerrainGameObject.GetComponent<VolumeCollider>();
                            if (volumeCollider != null)
                            {
                                bool useCollider = volumeCollider.useInEditMode || Application.isPlaying;

                                if (useCollider)
                                {
                                    // I'm not quite comfortable with this. For some reason we have to create this new mesh, fill it,
                                    // and set it as the collider's shared mesh, whereas I would rather just pass the collider's sharedMesh
                                    // straight to the functon that fills it. For some reason that doesn't work properly, and we see
                                    // issues with objects falling through terrain or not updating when part of the terrain is deleted.
                                    // It's to be investigated further... perhaps we could try deleting and recreating the MeshCollider?
                                    // Still, the approach below seems to work properly.
                                    Mesh collisionMesh = new Mesh();
                                    if (voxelTerrainGameObject.GetComponent<Volume>().GetType() == typeof(TerrainVolume))
                                    {
                                        MeshConversion.BuildMeshFromNodeHandleForTerrainVolume(collisionMesh, nodeHandle, true);
                                    }
                                    else if (voxelTerrainGameObject.GetComponent<Volume>().GetType() == typeof(ColoredCubesVolume))
                                    {
                                        MeshConversion.BuildMeshFromNodeHandleForColoredCubesVolume(collisionMesh, nodeHandle, true);
                                    }

                                    MeshCollider meshCollider = nodeGameObject.GetOrAddComponent<MeshCollider>() as MeshCollider;
                                    meshCollider.sharedMesh = collisionMesh;
                                }
                            }
                        }
                        // If there is no mesh in Cubiquity then we make sure there isn't one in Unity.
                        else
                        {
                            MeshCollider meshCollider = nodeGameObject.GetComponent<MeshCollider>() as MeshCollider;
                            if (meshCollider)
                            {
                                Utility.DestroyOrDestroyImmediate(meshCollider);
                            }

                            MeshRenderer meshRenderer = nodeGameObject.GetComponent<MeshRenderer>() as MeshRenderer;
                            if (meshRenderer)
                            {
                                Utility.DestroyOrDestroyImmediate(meshRenderer);
                            }

                            MeshFilter meshFilter = nodeGameObject.GetComponent<MeshFilter>() as MeshFilter;
                            if (meshFilter)
                            {
                                Utility.DestroyOrDestroyImmediate(meshFilter);
                            }
                        }

                        octreeNode.meshLastSynced = CubiquityDLL.GetCurrentTime();
                        availableSyncOperations--;
                    }

                    // We want to syncronize the properties before the mesh, so that the enabled flag can be set correctly when the mesh
                    // is created. But we also want to syncronize properties after the mesh, so we can apply the correct enabled flag to
                    // existing meshes when the node's 'renderThisNode' flag has changed. Therefore we set the 'resyncedProperties' flag
                    // previously to let ourseves know that we should come back an finish the propertiy syncing here. It's a bit of a hack.
                    if (resyncedProperties)
                    {
                        VolumeRenderer volumeRenderer = voxelTerrainGameObject.GetComponent<VolumeRenderer>();
                        if(volumeRenderer != null)
                        {
                            syncNodeWithVolumeRenderer(nodeGameObject, volumeRenderer, false);
                        }

                        VolumeCollider volumeCollider = voxelTerrainGameObject.GetComponent<VolumeCollider>();
                        if (volumeCollider != null)
                        {
                            syncNodeWithVolumeCollider(nodeGameObject, volumeCollider, false);
                        }
                    }

                    uint[, ,] childHandleArray = new uint[2, 2, 2];
                    childHandleArray[0, 0, 0] = cuOctreeNode.childHandle000;
                    childHandleArray[0, 0, 1] = cuOctreeNode.childHandle001;
                    childHandleArray[0, 1, 0] = cuOctreeNode.childHandle010;
                    childHandleArray[0, 1, 1] = cuOctreeNode.childHandle011;
                    childHandleArray[1, 0, 0] = cuOctreeNode.childHandle100;
                    childHandleArray[1, 0, 1] = cuOctreeNode.childHandle101;
                    childHandleArray[1, 1, 0] = cuOctreeNode.childHandle110;
                    childHandleArray[1, 1, 1] = cuOctreeNode.childHandle111;

                    ////////////////////////////////////////////////////////////////////////////////
                    // 3rd test - Has the structure of the octree node changed (gained or lost children)?
                    ////////////////////////////////////////////////////////////////////////////////
                    if (cuOctreeNode.structureLastChanged > octreeNode.structureLastSynced)
                    {
                        //Now syncronise any children
                        for (uint z = 0; z < 2; z++)
                        {
                            for (uint y = 0; y < 2; y++)
                            {
                                for (uint x = 0; x < 2; x++)
                                {
                                    if (childHandleArray[x, y, z] != 0xFFFFFFFF)
                                    {
                                        uint childNodeHandle = childHandleArray[x, y, z];

                                        if (octreeNode.GetChild(x, y, z) == null)
                                        {
                                            octreeNode.SetChild(x, y, z, OctreeNode.CreateOctreeNode(childNodeHandle, nodeGameObject));
                                        }
                                    }
                                    else
                                    {
                                        if (octreeNode.GetChild(x, y, z))
                                        {
                                            Utility.DestroyOrDestroyImmediate(octreeNode.GetChild(x, y, z));
                                            octreeNode.SetChild(x, y, z, null);
                                        }
                                    }
                                }
                            }
                        }

                        octreeNode.structureLastSynced = CubiquityDLL.GetCurrentTime();
                    }

                    ////////////////////////////////////////////////////////////////////////////////
                    // The last step of syncronization is to apply it recursively to our children.
                    ////////////////////////////////////////////////////////////////////////////////
                    for (uint z = 0; z < 2; z++)
                    {
                        for (uint y = 0; y < 2; y++)
                        {
                            for (uint x = 0; x < 2; x++)
                            {
                                if (octreeNode.GetChild(x, y, z) != null && availableSyncOperations > 0)
                                {
                                    OctreeNode.syncNode(ref availableSyncOperations, octreeNode.GetChild(x, y, z), childHandleArray[x, y, z], voxelTerrainGameObject);
                                }
                            }
                        }
                    }

                    // We've reached the end of our syncronization process. If there are still sync operations available then
                    // we did less work then we could have, which implies we finished. Therefore mark the whole tree as synced.
                    if (availableSyncOperations > 0)
                    {
                        octreeNode.nodeAndChildrenLastSynced = CubiquityDLL.GetCurrentTime();
                    }
                }
            }