//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions //---------------------- // Protected Functions //---------------------- // Private Functions /// <summary> /// Source: http://wiki.unity3d.com/index.php?title=LookAtMouse /// </summary> private void LookAtMouse() { float speed = 10; Vector3 direction = JCS_Utility.VectorDirection(mDirection); // Generate a plane that intersects the transform's position with an upwards normal. Plane playerPlane = new Plane(direction, mShootAction.SpawnPoint.position); // Generate a ray from the cursor position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Determine the point where the cursor ray intersects the plane. // This will be the point that the object must look towards to be looking at the mouse. // Raycasting to a Plane object only gives us a distance, so we'll have to take the distance, // then find the point along that ray that meets that distance. This will be the point // to look at. float hitdist = 0.0f; // If the ray is parallel to the plane, Raycast will return false. if (playerPlane.Raycast(ray, out hitdist)) { // Get the point along the ray that hits the calculated distance. Vector3 targetPoint = ray.GetPoint(hitdist); // Determine the target rotation. This is the rotation if the transform looks at the target point. Quaternion targetRotation = Quaternion.LookRotation(targetPoint - mShootAction.SpawnPoint.position); // Smoothly rotate towards the target point. mShootAction.SpawnPoint.rotation = Quaternion.Slerp(mShootAction.SpawnPoint.rotation, targetRotation, speed * Time.deltaTime); } }
/// <summary> /// Initialize the focus selector. /// </summary> /// <param name="rbs"></param> public void SetFocusSelector(JCS_RollSelectorButton rbs) { // if still animating disabled. if (mAnimating) { return; } // record down the last focus buttons index. mLastScrollIndex = mFocusBtn.ScrollIndex; // assign new focus button! this.mFocusBtn = rbs; foreach (JCS_RollSelectorButton btn in mButtons) { btn.SetInteractable(false); } // only enable this mFocusBtn.SetInteractable(true); // show in front. JCS_Utility.MoveToTheLastChild(mFocusBtn.transform); // Active anim, so can set the focused button to center. FindScrollIndex(); }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions //---------------------- // Protected Functions //---------------------- // Private Functions /// <summary> /// /// </summary> private void DoAbsorbEffect() { if (mAbsorbEffect) { mAbsorbEffectTimer += Time.deltaTime; if (mTimeToAbsorb < mAbsorbEffectTimer) { // start the effect mGoStraightAction.MoveSpeed += (0.1f - mGoStraightAction.MoveSpeed) / mTimeToAbsorb * Time.deltaTime; if (JCS_Utility.WithInRange(-mAcceptTimeRange, mAcceptTimeRange, mGoStraightAction.MoveSpeed)) { //mGoStraightAction.MoveSpeed = mRecordMoveSpeed; // end the effect. mAbsorbEffect = false; } } } else { mGoStraightAction.MoveSpeed += (mRecordMoveSpeed - mGoStraightAction.MoveSpeed) / mAbsorbBackFriction * Time.deltaTime; } }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions #if (UNITY_EDITOR) /// <summary> /// Show the resize panel, for debugging usage. /// </summary> public void ShowResizePanel() { if (mImage == null) { mImage = JCS_Utility.ForceGetComponent <Image>(this); } else { if (mShowResizePanel && mImage.enabled) { return; } } // Show it. mImage.enabled = true; // Set image. Just a white sprite! mImage.sprite = mImageSprite; // Set color. mImage.color = mResizePanelColor; mShowResizePanel = true; }
private void Start() { // everytime it reload the scene. // move to the last child make sure everything get cover by this. JCS_Utility.MoveToTheLastChild(this.transform); this.mStartingPosition = this.transform.localPosition; }
/// <summary> /// Refresh all languages text in game. /// </summary> public void RefreshLangTexts() { this.mLangTexts = JCS_Utility.RemoveEmptySlotIncludeMissing(this.mLangTexts); foreach (JCS_LangText txt in mLangTexts) { txt.Refresh(); } }
/// <summary> /// Read the .ini/.properties file for this editor window. /// </summary> public static void ReadINIFile() { INI_FILE_PATH = JCS_Utility.PathCombine(Application.dataPath, "/JCSUnity/Editors/ini/"); string path = JCS_Utility.PathCombine(INI_FILE_PATH, EDITOR_PROPERTIES_FILENAME); EDITOR_INI = JCS_INIFileReader.ReadINIFile(path); }
/* Functions */ private void Awake() { /* Down compatible. */ this.mSpriteRenderer = this.GetComponent <SpriteRenderer>(); // clean up empty slot. mSpriteRenderers = JCS_Utility.RemoveEmptySlot <SpriteRenderer>(mSpriteRenderers); }
/// <summary> /// Last screenshot image's file index. /// </summary> public static int LastImageFileIndex() { var gs = JCS_GameSettings.instance; var prefix = gs.SCREENSHOT_FILENAME; var ext = gs.SCREENSHOT_EXTENSION; return(JCS_Utility.LastFileIndex(SavePath(), prefix, ext)); }
//---------------------- // Protected Variables //======================================== // setter / getter //------------------------------ //======================================== // Unity's function //------------------------------ private void Awake() { instance = this; // get all the scene layer in the scene. // so it could be manage mJCSOrderLayer = JCS_Utility.FindObjectsOfTypeAllInHierarchy <JCS_OrderLayer>(); }
/* Functions */ private void Awake() { if (mTextContainer == null) { mTextContainer = this.GetComponentInChildren <Text>(); } mDistanceTileAction = JCS_Utility.ForceGetComponent <JCS_3DDistanceTileAction>(mTextContainer); }
/// <summary> /// Decide what item to drop base on /// the array list we have! /// </summary> /// <returns> item to drop. </returns> private JCS_Item ItemDropped() { JCS_Item item = null; float totalChance = 0; // add all possiblity chance together. for (int index = 0; index < mItemSet.Length; ++index) { totalChance += mItemSet[index].dropRate; } float dropIndex = JCS_Random.Range(0, totalChance + 1); float accumMaxDropRate = 0; float accumMinDropRate = 0; for (int index = 0; index < mItemSet.Length; ++index) { accumMaxDropRate += mItemSet[index].dropRate; if (index == 0) { if (JCS_Utility.WithInRange(0, mItemSet[0].dropRate, dropIndex)) { item = mItemSet[0].item; break; } continue; } // 比如: 10, 20, 30, 40 // Loop 1: 0 ~ 10 // Loop 2: 20(30-10) ~ 30 // Loop 3: 30(60-30) ~ 60 // Loop 4: 40(100-60) ~ 100 每個都減掉上一個的Drop Rate! if (JCS_Utility.WithInRange(accumMinDropRate, accumMaxDropRate, dropIndex)) { item = mItemSet[index].item; break; } accumMinDropRate += mItemSet[index].dropRate; } // meaning the last one. if (item == null && mItemSet.Length != 0 && mItemSet[mItemSet.Length - 1].dropRate != 0) { item = mItemSet[mItemSet.Length - 1].item; } return(item); }
/** * 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_Utility.SpawnGameObject(settingPath); // take away clone sign. hierarchyObj.name = hierarchyObj.name.Replace("(Clone)", ""); return(hierarchyObj); }
/* Functions */ protected override void Awake() { base.Awake(); // get all function pointer/formula. this.mEasingRed = JCS_Utility.GetEasing(mEaseTypeR); this.mEasingGreen = JCS_Utility.GetEasing(mEaseTypeG); this.mEasingBlue = JCS_Utility.GetEasing(mEaseTypeB); this.mEasingAlpha = JCS_Utility.GetEasing(mEaseTypeA); }
//** In Game Dialogue (Game Layer) /// <summary> /// Spawn the setting dialogue. /// </summary> public static void PopSettingDialogue() { if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.PLAYER_DIALOGUE)) { return; } JCS_Utility.SpawnGameObject(SETTING_PANEL); //PauseGame(true); }
/// <summary> /// Spawn the talke dialogue. /// </summary> public static void PopTalkDialogue() { if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.PLAYER_DIALOGUE)) { return; } JCS_Utility.SpawnGameObject(TALK_DIALOGUE); PauseGame(true); }
/// <summary> /// Re-order all the object. /// </summary> /// <param name="arr"> sorted object. </param> private void OriganizeChildOrder(JCS_GUIComponentLayer[] arr) { for (int index = 0; index < arr.Length; ++index) { // this will make gui ontop of each other. JCS_Utility.MoveToTheLastChild(arr[index].transform); // make sure is sorted already. arr[index].Sorted = true; } }
//---------------------- // Protected Variables //======================================== // setter / getter //------------------------------ //======================================== // Unity's function //------------------------------ private void Awake() { SpriteRenderer sp = this.GetComponent <SpriteRenderer>(); Vector2 spriteRect = JCS_Utility.GetSpriteRendererRectWithNoScale(sp); mWidth = spriteRect.x; mHeight = spriteRect.y; mOriginPosition = this.transform.position; }
//** (Application Layer) /// <summary> /// Spawn the connect dialgoue. /// </summary> public static void PopIsConnectDialogue() { if (!CheckIfOkayToSpawnDialogue(JCS_DialogueType.SYSTEM_DIALOGUE)) { return; } JCS_Utility.SpawnGameObject(IS_CONNECT_DIALOGUE); PauseGame(true); }
/*******************************************/ /* Private Variables */ /*******************************************/ /*******************************************/ /* Protected Variables */ /*******************************************/ /*******************************************/ /* setter / getter */ /*******************************************/ /*******************************************/ /* Unity's function */ /*******************************************/ private void Start() { this.animationSets = JCS_Utility.RemoveEmptySlot(this.animationSets); /* Register callback */ { JCS_Input.joystickPluggedCallback += JoystickPluggedCallback; JCS_Input.joystickUnPluggedCallback += JoystickUnPluggedCallback; } JCS_Input.InputCallbackOnce(); }
/* Functions */ private void Awake() { this.mSelections = JCS_Utility.RemoveEmptySlot(mSelections); // let them know the grouper. foreach (JCS_ButtonSelection bs in mSelections) { bs.ButtonSelectionGroup = this; } selectionChanged = EmptyCallbackSelectionChanged; }
/// <summary> /// Check the mouse if over the panel. /// </summary> /// <param name="rootPanel"> if there are root child plz use this to get the correct calculation </param> /// <returns> true: is over, false: not over </returns> public bool IsOnThere(RectTransform rootPanel) { if (GetObjectType() == JCS_UnityObjectType.UI) { if (JCS_Utility.MouseOverGUI(this.mRectTransform, rootPanel)) { return(true); } } return(false); }
private void Test() { if (!mTestWithKey) { return; } if (Input.GetKeyDown(mMoveLastKey)) { JCS_Utility.MoveToTheLastChild(this.transform); } }
/// <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_Utility.SpawnGameObject(obj); obj.ShowDialogue(); obj.SetKeyCode(KeyCode.None); return(obj); }
private void OrganizedLinked() { mManagedList = JCS_Utility.RemoveEmptySlotIncludeMissing(mManagedList); for (int index = 0; index < mManagedList.Count; ++index) { JCS_TransformLinkedObject node = mManagedList[index]; Vector3 newOffset = mIndexOffset * index; node.TransformTweener.DoTween(newOffset); } }
/// <summary> /// Force to clean all the children, this will make sure the /// transform have 0 children transform. /// </summary> /// <param name="trans"> transform you want to remove all /// the children under. </param> /// <returns> /// All the children under as a list. /// </returns> public static List <Transform> ForceDetachChildren(Transform trans) { List <Transform> childs = null; while (trans.childCount != 0) { List <Transform> tmpChilds = JCS_Utility.DetachChildren(trans); childs = MergeList(tmpChilds, childs); } return(childs); }
/// <summary> /// Spawn a white screen. /// </summary> public static void PopJCSWhiteScreen() { string path = JCS_UISettings.WHITE_SCREEN_PATH; JCS_WhiteScreen ws = JCS_Utility.SpawnGameObject(path).GetComponent <JCS_WhiteScreen>(); if (ws == null) { JCS_Debug.LogError("GameObject without `JCS_WhiteScreen` Component attached!!!"); return; } JCS_SceneManager.instance.SetJCSWhiteScreen(ws); }
/// <summary> /// Re-order all the object. /// </summary> /// <param name="arr">sorted object. </param> private void OriganizeChildOrder(JCS_PanelLayer[] arr) { for (int index = 0; index < arr.Length; ++index) { var layer = arr[index]; // this will make gui ontop of each other. JCS_Utility.MoveToTheLastChild(layer.transform); // make sure is sorted already. layer.Sorted = true; } }
/// <summary> /// Redo next component. /// </summary> public void RedoComponent() { JCS_UndoRedoComponent redoComp = JCS_Utility.ListPopBack(mRedoComp); if (redoComp == null) { return; } redoComp.Redo(); mUndoComp.Add(redoComp); }
/*******************************************/ /* Self-Define */ /*******************************************/ //---------------------- // Public Functions /// <summary> /// Undo next component. /// </summary> public void UndoComponent() { JCS_UndoRedoComponent undoComp = JCS_Utility.ListPopBack(mUndoComp); if (undoComp == null) { return; } undoComp.Undo(); mRedoComp.Add(undoComp); }