SpawnGameObject() public static method

Spawn a gmae object.
public static SpawnGameObject ( string objectPath, Vector3 position = newVector3(), Quaternion rotation = newQuaternion() ) : GameObject
objectPath string path of the game object
position Vector3 position of the game object spawn
rotation Quaternion rotation of the game object spawn
return GameObject
        private void Start()
        {
            // pop the fade screen.
            string path = JCS_UISettings.FADE_SCREEN_PATH;

            this.mFadeScreen = JCS_Util.SpawnGameObject(path).GetComponent <JCS_FadeScreen>();
        }
        /* Functions */

        protected void Awake()
        {
            mTargetList = new JCS_Vector <JCS_Player>();

            mAudioListener = this.GetComponent <AudioListener>();

            // find the camera in the scene first
            mJCS_2DCamera = (JCS_2DCamera)FindObjectOfType(typeof(JCS_2DCamera));

            // if still null spawn a default one!
            if (mJCS_2DCamera == null)
            {
                JCS_Debug.LogError("There is not JCS_2DCamera attach to, spawn a default one!");

                // Spawn a Default one!
                this.mJCS_2DCamera = JCS_Util.SpawnGameObject(
                    JCS_2DCamera.JCS_2DCAMERA_PATH,
                    transform.position,
                    transform.rotation).GetComponent <JCS_2DCamera>();
            }

            mJCS_2DCamera.SetFollowTarget(this.transform);

            // record down the fild of view
            mTargetFieldOfView = mJCS_2DCamera.fieldOfView;
        }
        /// <summary>
        /// Initialize damage text to the array.
        /// </summary>
        private void InitDamageTextToArray()
        {
            mDamageTexts = new JCS_Vector <JCS_DamageText>(mNumberOfHandle);

            if (mDamageText == null)
            {
                return;
            }

            for (int count = 0; count < mNumberOfHandle; ++count)
            {
                // spawn a new game object,
                // and get the component
                JCS_DamageText dt = JCS_Util.SpawnGameObject(
                    mDamageText,
                    mDamageText.transform.position,
                    mDamageText.transform.rotation) as JCS_DamageText;

                // add to array
                mDamageTexts.set(count, dt);

                // set parent
                dt.transform.SetParent(this.transform);
            }
        }
        /// <summary>
        /// Spawn all particle base on the count.
        /// </summary>
        public void SpawnParticles()
        {
            // check if particles already spawned?
            if (mParticleSpawned)
            {
                return;
            }

            if (mParticle == null)
            {
                JCS_Debug.Log(
                    "No particle assign!");
                return;
            }

            for (int index = 0;
                 index < mNumOfParticle;
                 ++index)
            {
                JCS_Particle trans = (JCS_Particle)JCS_Util.SpawnGameObject(mParticle);
                mParticles.push(trans);

                // disable the object
                trans.gameObject.SetActive(false);

                if (mSetChild)
                {
                    // set parent
                    trans.transform.SetParent(this.transform);
                }
            }

            mParticleSpawned = true;
        }
Beispiel #5
0
        /**
         * Utils
         */

        /// <summary>
        /// Create the Game Object during editing time.
        /// </summary>
        /// <returns></returns>
        private static GameObject CreateHierarchyObject(string settingPath)
        {
            // spawn the game object.
            GameObject hierarchyObj = JCS_Util.SpawnGameObject(settingPath);

            // take away clone sign.
            hierarchyObj.name = hierarchyObj.name.Replace("(Clone)", "");

            return(hierarchyObj);
        }
        /// <summary>
        /// Spawn the talke dialogue.
        /// </summary>
        public static void PopTalkDialogue()
        {
            if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.PLAYER_DIALOGUE))
            {
                return;
            }

            JCS_Util.SpawnGameObject(TALK_DIALOGUE);

            PauseGame(true);
        }
        //** In Game Dialogue (Game Layer)

        /// <summary>
        /// Spawn the setting dialogue.
        /// </summary>
        public static void PopSettingDialogue()
        {
            if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.PLAYER_DIALOGUE))
            {
                return;
            }

            JCS_Util.SpawnGameObject(SETTING_PANEL);

            //PauseGame(true);
        }
        //** (Application Layer)

        /// <summary>
        /// Spawn the connect dialgoue.
        /// </summary>
        public static void PopIsConnectDialogue()
        {
            if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.SYSTEM_DIALOGUE))
            {
                return;
            }

            JCS_Util.SpawnGameObject(IS_CONNECT_DIALOGUE);

            PauseGame(true);
        }
        /// <summary>
        /// Spawn a white screen.
        /// </summary>
        public static void PopJCSWhiteScreen()
        {
            string          path = JCS_UISettings.WHITE_SCREEN_PATH;
            JCS_WhiteScreen ws   = JCS_Util.SpawnGameObject(path).GetComponent <JCS_WhiteScreen>();

            if (ws == null)
            {
                JCS_Debug.LogError("GameObject without `JCS_WhiteScreen` Component attached!!!");
                return;
            }

            JCS_SceneManager.instance.SetWhiteScreen(ws);
        }
        /// <summary>
        /// Pop one single dialogue.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private JCS_DialogueObject PopDialogue(JCS_DialogueObject obj)
        {
            if (obj == null)
            {
                return(null);
            }

            obj = (JCS_DialogueObject)JCS_Util.SpawnGameObject(obj);
            obj.Show();
            obj.OpenKey = KeyCode.None;

            return(obj);
        }
        /// <summary>
        /// Pop the JCS_BlackSlideScreen object.
        /// </summary>
        public static void PopJCSBlackSlideScreen()
        {
            string path             = JCS_UISettings.BLACK_SLIDE_SCREEN_PATH;
            JCS_BlackSlideScreen bs = JCS_Util.SpawnGameObject(path).GetComponent <JCS_BlackSlideScreen>();

            if (bs == null)
            {
                JCS_Debug.LogError("GameObject without \"JCS_BlackScreen\" Component attached!!!");
                return;
            }

            JCS_SceneManager.instance.SetBlackSlideScreen(bs);
        }
        /* Functions */

        private void Awake()
        {
            InitCamera();

            //
            if (mPanelHolder == null)
            {
                // spawn a default one!
                this.mPanelHolder = JCS_Util.SpawnGameObject(
                    mPanelHolderPath,
                    transform.position,
                    transform.rotation).GetComponent <JCS_SlideScreenPanelHolder>();
            }
        }
        /* Functions */

        private void Awake()
        {
            instance = this;

            if (ShouldSpawnResizablePanels())
            {
                // Spawn the four aspect screen panels.
                this.mTopASP    = JCS_Util.SpawnGameObject(mResizableScreenPanelPath).GetComponent <JCS_ResizableScreenPanel>();
                this.mBottomASP = JCS_Util.SpawnGameObject(mResizableScreenPanelPath).GetComponent <JCS_ResizableScreenPanel>();
                this.mLeftASP   = JCS_Util.SpawnGameObject(mResizableScreenPanelPath).GetComponent <JCS_ResizableScreenPanel>();
                this.mRightASP  = JCS_Util.SpawnGameObject(mResizableScreenPanelPath).GetComponent <JCS_ResizableScreenPanel>();

                // Set the ASP direction.
                this.mTopASP.PlaceDirection    = JCS_2D4Direction.TOP;
                this.mBottomASP.PlaceDirection = JCS_2D4Direction.BOTTOM;
                this.mLeftASP.PlaceDirection   = JCS_2D4Direction.LEFT;
                this.mRightASP.PlaceDirection  = JCS_2D4Direction.RIGHT;
            }
        }
        /// <summary>
        /// Spawn a random transform.
        /// </summary>
        public void SpawnATransform()
        {
            int spawnIndex = JCS_Random.Range(0, mSpawnList.Count);

            // check null ref.
            if (mSpawnList[spawnIndex] == null)
            {
                JCS_Debug.Log("Can't spawn a null reference. Plz check the spawn list if there are transform attach or empty slot.");
                return;
            }

            // spawn a object
            Transform objSpawned = (Transform)JCS_Util.SpawnGameObject(
                mSpawnList[spawnIndex],
                this.transform.position);


            // randomize the position a bit.
            Vector3 randPos = JCS_Util.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.position,
                new Vector3(mRandPosRangeX, mRandPosRangeY, mRandPosRangeZ),
                new JCS_Bool3(mRandPosX, mRandPosY, mRandPosZ));

            // randomize the rotation a bit.
            Vector3 randRot = JCS_Util.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.eulerAngles,
                new Vector3(mRandRotRangeX, mRandRotRangeY, mRandRotRangeZ),
                new JCS_Bool3(mRandRotationX, mRandRotationY, mRandRotationZ));

            // randomize the rotation a bit.
            Vector3 randScale = JCS_Util.ApplyRandVector3(
                // use the current spawner position.
                objSpawned.transform.localScale,
                new Vector3(mRandScaleRangeX, mRandScaleRangeY, mRandScaleRangeZ),
                new JCS_Bool3(mRandScaleX, mRandScaleY, mRandScaleZ));

            objSpawned.transform.position    = randPos;
            objSpawned.transform.eulerAngles = randRot;
            objSpawned.transform.localScale  = randScale;
        }
        /// <summary>
        /// Pop all the dialogues in the array.
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private JCS_DialogueObject[] PopDialogue(JCS_DialogueObject[] list)
        {
            if (list.Length == 0)
            {
                return(null);
            }

            for (int index = 0; index < list.Length; ++index)
            {
                if (list[index] == null)
                {
                    continue;
                }

                list[index] = (JCS_DialogueObject)JCS_Util.SpawnGameObject(list[index]);
                list[index].Hide();
            }

            return(list);
        }
        /// <summary>
        /// Spawn the text pool base on number of handle.
        /// </summary>
        private void SpawnTextPool()
        {
            if (mLogText == null)
            {
                JCS_Debug.LogReminder( 
                    "No log text assign in the text pool...");

                return;
            }


            // NOTE(JenChieh): this might change in
            // the future.
            // Get the log system from the 
            // same transfrom/node.
            JCS_IGLogSystem logSystem = this.GetComponent<JCS_IGLogSystem>();


            mLogTexts = new JCS_Vector<JCS_LogText>(mNumberOfHandle);

            for (int count = 0;
                count < mNumberOfHandle;
                ++count)
            {
                // spawn a new game object, 
                // and get the component
                JCS_LogText logText = (JCS_LogText)JCS_Util.SpawnGameObject(mLogText);

                // add to array
                mLogTexts.set(count, logText);

                // set parent
                JCS_Util.SetParentWithoutLosingInfo(logText.transform, this.transform);

                // NOTE(JenChieh): this might change in
                // the future.
                // set the log system if there is one.
                logText.SetIGLogSystem(logSystem);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Algorithm to do the main action from this event.
        /// </summary>
        public void SpawnObjects()
        {
            Transform spawnTrans = null;

            for (int counter = 0;
                 counter < mObjectsToSpawn;
                 ++counter)
            {
                // get the random object from the list.
                spawnTrans = mObjectList.GetRandomObjectFromList();

                // check if null.
                if (spawnTrans == null)
                {
                    JCS_Debug.LogError(
                        "Spawning object detect that are null references... Could not spawn the object!");

                    break;
                }


                // spawn the object by transform.
                // and get the object which we just spawned.
                spawnTrans = (Transform)JCS_Util.SpawnGameObject(spawnTrans, this.transform.position);

                // apply random position
                spawnTrans.transform.position = RandTransform(spawnTrans.position);

                // apply random rotation
                spawnTrans.transform.eulerAngles = RandDegree(spawnTrans.eulerAngles);

                JCS_ApplyDamageTextToLiveObjectAction adtaThis    = this.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>();
                JCS_ApplyDamageTextToLiveObjectAction adtaSpawned = spawnTrans.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>();
                if (adtaThis != null && adtaSpawned != null)
                {
                    // copy the apply damage text information to spawned object!
                    adtaSpawned.CopyToThis(adtaThis);
                }
            }
        }
        //////////// 2D //////////////////////////

        /// <summary>
        /// Iniialize the camera.
        /// </summary>
        private void InitCamera()
        {
            if (m2DCamera == null)
            {
                JCS_Debug.LogError("There is not JCS_2DCamera attach to, spawn a default one!");

                // Spawn a Default one!
                this.m2DCamera = JCS_Util.SpawnGameObject(
                    JCS_2DCamera.JCS_2DCAMERA_PATH,
                    transform.position,
                    transform.rotation).GetComponent <JCS_2DCamera>();
            }

            // if still null, setting error!!
            if (m2DCamera == null)
            {
                JCS_Debug.LogError("The object spawn does not have the `JCS_2DCamera` component");
                return;
            }

            // set target to follow!
            m2DCamera.SetFollowTarget(this.transform);
        }
Beispiel #19
0
        private static void ConvertTo2D()
        {
            // create settings
            CreateSettings();

            // create managers
            CreateManagers();

            Create2DCamera();

            // BGM player
            CreateBGMPlayer();

            // create canvas
            GameObject canvasObj = CreateJCSCanvas();

            const string desc_path = "UI/JCS Describe Panel";
            GameObject   desc_obj  = JCS_Util.SpawnGameObject(desc_path);

            desc_obj.name = desc_obj.name.Replace("(Clone)", "");
            desc_obj.transform.SetParent(canvasObj.transform);
            desc_obj.transform.localPosition = Vector3.zero;
        }
Beispiel #20
0
        /* Functions */

        private void Awake()
        {
            this.mAppRect = this.GetComponent <RectTransform>();
            this.mCanvas  = this.GetComponent <Canvas>();

            if (JCS_UISettings.instance.RESIZE_UI)
            {
                // resizable UI in order to resize the UI correctly
                mResizeUI = JCS_Util.SpawnGameObject(RESIZE_UI_PATH).GetComponent <JCS_ResizeUI>();
                mResizeUI.transform.SetParent(this.transform);
            }

            JCS_UIManager.instance.AddCanvas(this);

            if (mDisplayOnAwake)
            {
                Show();
            }
            else
            {
                Hide();
            }
        }
        /// <summary>
        /// Create new linked node object by N count.
        /// </summary>
        /// <param name="n"> Number of linked object to create. </param>
        /// <param name="startIndex"> Starting index to create. </param>
        /// <returns> List of created linked object. </returns>
        public List <JCS_TransformLinkedObject> NewLinked(int n = 1, int startIndex = 0)
        {
            if (mClone == null)
            {
                JCS_Debug.LogReminder("Can't create new linked node without the clone");
                return(null);
            }

            if (n <= 0)
            {
                JCS_Debug.LogReminder("Can't create new linked node N lower than 1");
                return(null);
            }

            var lst = new List <JCS_TransformLinkedObject>();

            int maxIndex = startIndex + n;

            for (int index = startIndex; index < maxIndex; ++index)
            {
                var newNode = JCS_Util.SpawnGameObject(mClone) as JCS_TransformLinkedObject;

                // Set to it centers.
                {
                    newNode.transform.SetParent(this.transform);
                    newNode.transform.localPosition = Vector3.zero;
                    newNode.transform.localScale    = Vector3.one;
                }

                lst.Add(newNode);
                mManagedList.Insert(index, newNode);
            }

            OrganizedLinked();

            return(lst);
        }
        /// <summary>
        /// Do the spawning.
        /// </summary>
        private void DoSpawn()
        {
            for (int index = 0;
                 index < mSpawnCount;
                 ++index)
            {
                Transform newTrans = (Transform)JCS_Util.SpawnGameObject(mTransformPool.GetRandomObject());

                if (mSamePosition)
                {
                    newTrans.position = this.transform.position;
                }
                if (mSameRotation)
                {
                    newTrans.rotation = this.transform.rotation;
                }
                if (mSameScale)
                {
                    newTrans.localScale = this.transform.localScale;
                }

                // Random Effect
                if (mRandPos)
                {
                    AddRandomPosition(newTrans);
                }
                if (mRandRot)
                {
                    AddRandomRotation(newTrans);
                }
                if (mRandScale)
                {
                    AddRandomScale(newTrans);
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// Shoot a bullet.
        /// </summary>
        /// <param name="bulletSpeed"></param>
        /// <param name="pos"></param>
        /// <param name="direction"></param>
        /// <param name="damages"></param>
        /// <param name="index"></param>
        /// <param name="inSequence"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public JCS_Bullet Shoot(float bulletSpeed, Vector3 pos, bool direction, int[] damages, int index = 0, bool inSequence = false, Transform target = null)
        {
            if (mPlayer != null)
            {
                if (mPlayer.CharacterState != JCS_2DCharacterState.NORMAL)
                {
                    return(null);
                }
            }

            int hit = damages.Length;

            Vector3 spawnPos = pos + mSpanwPointOffset;

            spawnPos = RandTransform(spawnPos);

            JCS_Bullet bullet = (JCS_Bullet)JCS_Util.SpawnGameObject(mBullet, spawnPos, mSpawnPoint.rotation);

            // no object spawns
            if (bullet == null)
            {
                return(null);
            }

            // set the attacker.
            SetAttackerInfo(bullet);

            float tempBulletSpeed = bulletSpeed;

            // default: facing left
            if (!direction)
            {
                tempBulletSpeed = -tempBulletSpeed;
            }

            // set bullet speed
            bullet.MoveSpeed = tempBulletSpeed;

            // Do devication Effect
            DeviationEffect(bullet.transform);

            if (bullet is JCS_2DBullet)
            {
                bullet.GetComponent <JCS_3DGoStraightAction>().MoveSpeed = bulletSpeed;
            }


            if (mTrackSoot &&
                target != null)
            {
                JCS_2DTrackAction ta = bullet.GetComponent <JCS_2DTrackAction>();
                if (ta != null)
                {
                    ta.TargetTransform = target;

                    // set to center
                    float newIndex = index - (hit / 2.0f);

                    // apply effect
                    ta.Index = newIndex;
                }
            }

            if (mAbilityFormat != null)
            {
                JCS_ApplyDamageTextToLiveObjectAction adta = bullet.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>();
                if (adta != null)
                {
                    // set the Ability Format
                    adta.AbilityFormat = mAbilityFormat;
                    adta.Hit           = hit;

                    adta.DamageApplying = damages;

                    // if hit equal to 0,
                    // meaning this bullet is in the sequence
                    if (inSequence)
                    {
                        adta.InSequence = true;
                    }

                    adta.TargetTransform = target;
                }
            }

            // part of the SFX
            mRandomMultiSoundAction.PlayRandomSound();

            return(bullet);
        }
        /// <summary>
        /// Drop an item.
        /// </summary>
        /// <param name="item"> item u want to spawn </param>
        /// <param name="index"> index to know the force this is pushing to. </param>
        /// <param name="isEven"> is the index even number? </param>
        /// <param name="isGravity"> do gravity effect. </param>
        /// <param name="spreadEffect"> do spread effect. </param>
        /// <param name="rotateDrop"> rotate while dropping. </param>
        /// <param name="waveEffect"> do wave effect while on the ground. </param>
        /// <param name="destroyFade"> while picking it up will fade and destroy. </param>
        private void DropAnItem(
            JCS_Item item,
            int index,
            bool isEven,
            bool isGravity,
            bool spreadEffect,
            bool rotateDrop,
            bool waveEffect,
            bool destroyFade)
        {
            JCS_Item newItem = (JCS_Item)JCS_Util.SpawnGameObject(
                item,
                this.transform.position,
                this.transform.rotation);

            bool isEvenIndex = ((index % 2) == 0) ? true : false;

            if (isGravity)
            {
                JCS_OneJump oj = newItem.gameObject.AddComponent <JCS_OneJump>();

                float gapDirection = mSpreadGap;
                if (isEvenIndex)
                {
                    gapDirection = -mSpreadGap;
                }

                oj.BounceBackfromWall = BounceBackfromWall;

                float gapForce = 0;

                if (spreadEffect)
                {
                    if (isEven)
                    {
                        if (!isEvenIndex)
                        {
                            gapForce = (gapDirection * (index - 1)) + gapDirection;
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                    // if total is odd
                    else
                    {
                        if (isEvenIndex)
                        {
                            gapForce = (gapDirection * (index));
                        }
                        else
                        {
                            gapForce = (gapDirection * (index)) + gapDirection;
                        }
                    }
                }

                float jumpForce = mJumpForce;
                if (mRandomizeJumpForce)
                {
                    jumpForce += JCS_Random.Range(-mRandomizeJumpForceForce, mRandomizeJumpForceForce);
                }

                oj.DoForce(gapForce, jumpForce, mIncludeDepth);

                if (rotateDrop)
                {
                    JCS_ItemRotation irx = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                    irx.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                    irx.Effect          = true;
                    irx.RotateDirection = JCS_Vector3Direction.FORWARD;

                    // if z axis interact in game
                    if (mIncludeDepth)
                    {
                        // add rotation on y axis.
                        JCS_ItemRotation iry = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                        iry.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        iry.Effect          = true;
                        iry.RotateDirection = JCS_Vector3Direction.UP;

                        // add rotation on z axis.
                        JCS_ItemRotation irz = newItem.gameObject.AddComponent <JCS_ItemRotation>();
                        irz.RotateSpeed     = JCS_Random.Range(-mRotateSpeed, mRotateSpeed);
                        irz.Effect          = true;
                        irz.RotateDirection = JCS_Vector3Direction.RIGHT;
                    }
                }
            }

            if (waveEffect)
            {
                JCS_3DConstWaveEffect cwe = newItem.gameObject.AddComponent <JCS_3DConstWaveEffect>();
                cwe.SetObjectType(newItem.GetObjectType());
                cwe.Effect = true;
            }

            if (destroyFade)
            {
                JCS_DestroyObjectWithTime dowt = newItem.gameObject.AddComponent <JCS_DestroyObjectWithTime>();
                dowt.FadeTime    = mFadeTime;
                dowt.DestroyTime = mDestroyTime;

                Renderer[] renderers = newItem.GetComponentsInChildren <Renderer>();

                foreach (Renderer rdr in renderers)
                {
                    JCS_FadeObject fo = rdr.gameObject.AddComponent <JCS_FadeObject>();

                    dowt.FadeObjects.Add(fo);

                    // set the object type the same.
                    fo.SetObjectType(item.GetObjectType());
                    fo.UpdateUnityData();
                }
            }
        }