分類: Unity
Unity C# 籌碼疊加與數值進位功能
下注時籌碼疊加,並同時計算下注金額與籌碼單位換算。
Unity-Time時間類(2)
前篇介紹的是Time.time與Time.deltaTime,本篇則是介紹有關時間縮放及停止的Time.timeScale。閱讀更多»
Unity-Time時間類(1)
Time是在Unity中獲取時間資訊的一種class,本篇將介紹Time中的time、deltaTime。閱讀更多»
C#return實例
C#Shuffle Example
在遊戲裡常常會遇到同樣成員的一組Array或List需要隨機排列,這時候就會需要用到洗牌(Shuffle)的概念。本篇將實作利用for循環達到洗牌效果的範例。閱讀更多»
C#Update-Do something every amount
在Unity C# Script中,在Update底下滿足某些條件時,會發生一直重複執行的情況,本篇主要介紹如何避免這種情況,以及如何做到滿足條件後僅執行一次funtion。閱讀更多»
Unity3d-C#可視化自定義class
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEditor; [System.Serializable] public class People { public GameObject person; public string name; public int age; public float height; public Vector3 location; public int[] itemarray = new int[0]; } public class PeopleList : MonoBehaviour { public List<People> people_list = new List<People>(); // Use this for initialization void AddNew() { people_list.Add(new People()); } // Update is called once per frame void Remove(int index) { people_list.RemoveAt(index); } } [CustomEditor(typeof(PeopleList))] public class PeopleListEditor : Editor { PeopleList N; SerializedObject GetTarget; SerializedProperty TheNewList; int ListSize; void OnEnable() { N = (PeopleList)target; GetTarget = new SerializedObject(N); TheNewList = GetTarget.FindProperty("people_list");// Find the List in our script and create a refrence of it } public override void OnInspectorGUI() { GetTarget.Update(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Define the list size with a number"); ListSize = TheNewList.arraySize; ListSize = EditorGUILayout.IntField("List Size", ListSize); if (ListSize != TheNewList.arraySize) { while (ListSize > TheNewList.arraySize) { TheNewList.InsertArrayElementAtIndex(TheNewList.arraySize); } while (ListSize < TheNewList.arraySize) { TheNewList.DeleteArrayElementAtIndex(TheNewList.arraySize - 1); } } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); //Or add a new item to the List<> with a button EditorGUILayout.LabelField("Add a new item with a button"); if (GUILayout.Button("Add New")) { N.people_list.Add(new People()); } EditorGUILayout.Space(); EditorGUILayout.Space(); for (int i = 0; i < TheNewList.arraySize; i++) { SerializedProperty TheNewListRef = TheNewList.GetArrayElementAtIndex(i); SerializedProperty Person = TheNewListRef.FindPropertyRelative("person"); SerializedProperty Name = TheNewListRef.FindPropertyRelative("name"); SerializedProperty Age = TheNewListRef.FindPropertyRelative("age"); SerializedProperty Height = TheNewListRef.FindPropertyRelative("height"); SerializedProperty Location = TheNewListRef.FindPropertyRelative("location"); SerializedProperty Itemarray = TheNewListRef.FindPropertyRelative("itemarray"); EditorGUILayout.LabelField("List (" + i.ToString() + ")"); Person.objectReferenceValue = EditorGUILayout.ObjectField("Person Object", Person.objectReferenceValue, typeof(GameObject), true); Name.stringValue = EditorGUILayout.TextField("Person Name", Name.stringValue); Age.intValue = EditorGUILayout.IntField("Person Age", Age.intValue); Height.floatValue = EditorGUILayout.FloatField("Person Height", Height.floatValue); Location.vector3Value = EditorGUILayout.Vector3Field("Person Location", Location.vector3Value); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Item Array"); if (GUILayout.Button("Add New Item", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) { Itemarray.InsertArrayElementAtIndex(Itemarray.arraySize); Itemarray.GetArrayElementAtIndex(Itemarray.arraySize - 1).intValue = 0; } for (int a = 0; a < Itemarray.arraySize; a++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Item Index (" + a.ToString() + ")", GUILayout.MaxWidth(120)); Itemarray.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("", Itemarray.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100)); if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15))) { Itemarray.DeleteArrayElementAtIndex(a); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); //Remove this index from the List EditorGUILayout.LabelField("Remove an index from the List<> with a button"); if (GUILayout.Button("Remove This Index (" + i.ToString() + ")")) { TheNewList.DeleteArrayElementAtIndex(i); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); } GetTarget.ApplyModifiedProperties(); } }
C#-MoneyUpdate(金幣跳動效果)
本篇主要說明金幣跳動效果的程式碼架構,我們先來看完成的效果。
閱讀更多»