private void SelectCurveType(LevelComponent inComponent, PointGroup inGroup, eCurveType inNewSelectedCurve) { eCurveType currentCurveType = inGroup.mCurveType; if (currentCurveType != inNewSelectedCurve) { // Determine the new point. switch (inNewSelectedCurve) { case eCurveType.Point: CutOrAddGroupPointsTo(inComponent, inGroup, 1); break; case eCurveType.Quadratic: CutOrAddGroupPointsTo(inComponent, inGroup, 3); break; case eCurveType.Cubic: CutOrAddGroupPointsTo(inComponent, inGroup, 4); break; } // Set it. inGroup.mCurveType = inNewSelectedCurve; } }
public static double Convert(double input, eCurveType curve) { input = Math.Min(input, 1.0); input = Math.Max(input, 0.0); switch (curve) { default: case eCurveType.LINEAR: return(input); case eCurveType.S_CURVE: return((2.0 - (Math.Cos(input * Math.PI) + 1.0)) / 2.0); case eCurveType.SINE: return(Math.Sign((input * Math.PI) / 2.0)); case eCurveType.SQRD: return(input * input); case eCurveType._3RD: return(input * input * input); case eCurveType.TO_THE_HALF: return(Math.Pow(input, 0.5)); case eCurveType.TO_THE_ONE_OVER_THREE: return(Math.Pow(input, 1.0 / 3.0)); } }
public Fade(float fadeTimeMS, float startValue, float endValue, eCurveType curve) { this.Curve = curve; this.fadeTimeMS = fadeTimeMS; this.startValue = startValue; this.endValue = endValue; isComplete = false; }
public PointGroup() { // mID = inID; mBundleID = 0; mSpawnChance = 100; mPoints = new List <PointInfo>(); mSpawnType = eSpawnType.None; mCurveType = eCurveType.Linear; }
// So, like, this method does sort of two things. // Set up your gui. What's the layout, where do things go, order, etc. // Pull from the gui the current selection values void OnGUI() { GUI.changed = false; if (Selection.activeTransform != null && Selection.activeTransform.GetComponent <LevelComponent>() != null) { mLastChosenLevelComponent = Selection.activeTransform.GetComponent <LevelComponent>(); } if (mLastChosenLevelComponent != null) { // Pull out the point groups List <PointGroup> selectedGroups = mLastChosenLevelComponent.PointGroups; // Here goes the form. // New Group GUILayout.BeginArea(new Rect(0, 0, 100, 40)); if (GUILayout.Button("New Group")) { CreateNewGroup(mLastChosenLevelComponent); } GUILayout.EndArea(); // Depending on if a group is selected if (mCurrentSelectedGroup != null) { // Spawn Type area GUILayout.BeginArea(new Rect(300, 0, 200, 75)); GUILayout.BeginVertical(); string[] selectionTypes = new string[(int)eSpawnType.Max]; for (int selectedPurposeIndex = 0; selectedPurposeIndex < (int)eSpawnType.Max; selectedPurposeIndex++) { selectionTypes[selectedPurposeIndex] = ((eSpawnType)selectedPurposeIndex).ToString(); } GUILayout.Label("Spawn Type"); mCurrentSelectedGroup.mSpawnType = (eSpawnType)GUILayout.SelectionGrid((int)mCurrentSelectedGroup.mSpawnType, selectionTypes, 2); GUILayout.EndVertical(); GUILayout.EndArea(); // Bundle ID area GUILayout.BeginArea(new Rect(300, 75, 200, 75)); GUILayout.BeginVertical(); GUILayout.Label("Bundle ID"); mCurrentSelectedGroup.mBundleID = (int)GUILayout.HorizontalSlider(mCurrentSelectedGroup.mBundleID, 0, 100); GUILayout.EndVertical(); GUILayout.EndArea(); // Individual object spawn % GUILayout.BeginArea(new Rect(300, 110, 200, 75)); GUILayout.BeginVertical(); GUILayout.Label("Object Spawn %"); mCurrentSelectedGroup.mSpawnChance = (int)GUILayout.HorizontalSlider(mCurrentSelectedGroup.mSpawnChance, 0, 100); GUILayout.EndVertical(); GUILayout.EndArea(); // Curve Type area GUILayout.BeginArea(new Rect(300, 150, 200, 75)); GUILayout.BeginVertical(); string[] curveTypes = new string[(int)eCurveType.Max]; for (int curveIndex = 0; curveIndex < (int)eCurveType.Max; curveIndex++) { curveTypes[curveIndex] = ((eCurveType)curveIndex).ToString(); } GUILayout.Label("Curve Type (will modify pts)"); eCurveType selectedCurve = (eCurveType)GUILayout.SelectionGrid((int)mCurrentSelectedGroup.mCurveType, curveTypes, 2); SelectCurveType(mLastChosenLevelComponent, mCurrentSelectedGroup, selectedCurve); GUILayout.EndVertical(); GUILayout.EndArea(); } // Points Area GUILayout.BeginArea(new Rect(0, 140, 100, 40)); // New Point Button GUI.enabled = (mCurrentSelectedGroup != null); if (GUILayout.Button("New Point")) { AddNewPoint(mLastChosenLevelComponent, mSelectedGroupIndex); } GUI.enabled = true; GUILayout.EndArea(); // Points Area GUILayout.BeginArea(new Rect(100, 140, 200, 100)); EditorGUILayout.BeginVertical(); GUILayout.Label("Points"); mSelectedPointsScrollPosition = GUILayout.BeginScrollView( mSelectedPointsScrollPosition, false, true); GUILayout.BeginHorizontal(); GUILayout.Label("Index"); GUILayout.Label("Pos"); GUILayout.EndHorizontal(); List <string> pointGridItems = new List <string>(); PointGroup currentGroup = null; currentGroup = mLastChosenLevelComponent.GetGroup(mSelectedGroupIndex); if (currentGroup != null) { List <PointInfo> points = currentGroup.mPoints; for (int pointIndex = 0; pointIndex < points.Count; pointIndex++) { PointInfo currentPoint = points[pointIndex]; string newItem = "index" + pointIndex + " | " + (currentPoint.mPosition + mLastChosenLevelComponent.transform.position); pointGridItems.Add(newItem); } int grabbedPointIndex = GUILayout.SelectionGrid(-1, pointGridItems.ToArray(), 1); // Attempt to re-select that item if (grabbedPointIndex >= 0 && grabbedPointIndex < points.Count) { PointInfo selectedPoint = points[grabbedPointIndex]; mSelectedPointIndex = grabbedPointIndex; SelectPoint(mLastChosenLevelComponent, selectedPoint, mSelectedPointIndex); } } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.EndArea(); //====================Area for existing items======================== GUILayout.BeginArea(new Rect(0, 240, 400, 100)); mSelectedGroupsScrollPosition = GUILayout.BeginScrollView( mSelectedGroupsScrollPosition, false, true); GUILayout.Label("Existing Groups"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Index"); GUILayout.Label("#pts"); GUILayout.Label("Bundle"); GUILayout.Label("SpawnType"); GUILayout.Label("Spawn Chance"); GUILayout.Label("CurveType"); EditorGUILayout.EndHorizontal(); List <string> gridItems = new List <string>(); for (int groupIndex = 0; groupIndex < selectedGroups.Count; groupIndex++) { PointGroup currentPointGroup = selectedGroups[groupIndex]; string purposes = currentPointGroup.mSpawnType.ToString(); string newItem = "index" + groupIndex + " | " + currentPointGroup.mPoints.Count.ToString() + " | " + currentPointGroup.mBundleID + " | " + purposes + " | " + currentPointGroup.mSpawnChance + " | " + currentPointGroup.mCurveType.ToString(); gridItems.Add(newItem); } mSelectedGroupGridIndex = GUILayout.SelectionGrid(mSelectedGroupGridIndex, gridItems.ToArray(), 1); if (mSelectedGroupGridIndex >= 0 && mSelectedGroupGridIndex < gridItems.Count) { mSelectedGroupIndex = mSelectedGroupGridIndex; } GUILayout.EndScrollView(); GUILayout.EndArea(); // Reselect the group PointGroup newGroup = null; newGroup = mLastChosenLevelComponent.GetGroup(mSelectedGroupIndex); if (newGroup != null && newGroup != mCurrentSelectedGroup) { // Reset the selected point mSelectedPointIndex = -1; ObjectDestroyUpdate(true); // Select the new point mCurrentSelectedGroup = newGroup; } //================================================================== GUILayout.BeginArea(new Rect(0, 340, 300, 50)); GUILayout.BeginHorizontal(); GUI.enabled = (mCurrentSelectedGroup != null); if (GUILayout.Button("Delete Selected Group")) { DeletePointGroup(mLastChosenLevelComponent, mCurrentSelectedGroup); } GUI.enabled = (mLastSelectedPointInfo != null); if (GUILayout.Button("Delete Selected Point")) { DeletePointInfo(mLastChosenLevelComponent, mCurrentSelectedGroup, mLastSelectedPointInfo); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.EndArea(); // Bundle Area GUILayout.BeginArea(new Rect(0, 390, 300, 100)); mSelectedBundlesScrollPosition = GUILayout.BeginScrollView( mSelectedBundlesScrollPosition, false, true); GUILayout.Label("Bundles"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("BundleID"); GUILayout.Label("Spawn Chance"); EditorGUILayout.EndHorizontal(); List <Bundle> currentBundles = mLastChosenLevelComponent.Bundles; List <string> bundleGridItems = new List <string>(); foreach (Bundle currentBundle in currentBundles) { string newItem = currentBundle.mBundleID + " | " + currentBundle.mSpawnChance; bundleGridItems.Add(newItem); } mLastSelectedBundleIndex = GUILayout.SelectionGrid(mLastSelectedBundleIndex, bundleGridItems.ToArray(), 4); if (mLastSelectedBundleIndex >= 0 && mLastSelectedBundleIndex < currentBundles.Count) { mLastSelectedBundle = currentBundles[mLastSelectedBundleIndex]; } else { mLastSelectedBundle = null; } GUILayout.EndScrollView(); GUILayout.EndArea(); // Bundle buttons // Add GUILayout.BeginArea(new Rect(300, 390, 200, 100)); GUILayout.BeginVertical(); GUILayout.Label("ID " + mNewBundleID); mNewBundleID = (int)GUILayout.HorizontalSlider(mNewBundleID, 0, 100); GUILayout.Label("Spawn Chance " + mNewSpawnChance); mNewSpawnChance = GUILayout.HorizontalSlider(mNewSpawnChance, 0f, 100f); if (GUILayout.Button("Add/Update Bundle")) { mLastChosenLevelComponent.SetBundleChance(mNewBundleID, mNewSpawnChance); } GUILayout.EndVertical(); GUILayout.EndArea(); // Delete GUILayout.BeginArea(new Rect(0, 490, 300, 50)); GUILayout.BeginHorizontal(); GUI.enabled = (mLastSelectedBundle != null); if (GUILayout.Button("Delete Selected Bundle")) { mLastChosenLevelComponent.RemoveBundle(mLastSelectedBundle.mBundleID); } GUILayout.EndHorizontal(); GUILayout.EndArea(); // Done with all the layouts. OnDrawGizmos(); if (GUI.changed) { EditorUtility.SetDirty(mLastChosenLevelComponent); } } else { GUILayout.Label("Please select an item of type LevelComponent from the Hierachy, then click me!"); } }
public static double Lerp(double start, double end, double lerp, eCurveType curve) { return((end - start) * Convert(lerp, curve) + start); }
public void AddCurve(eCurveType curveType) { Byte[] CurvePrototype = new Byte[CurveLenght * 2]; Curves.Add(CurvePrototype); CurveTypes.Add(curveType); // @todo Pattern Generator auf generischen Datentyp umstellen switch (curveType) { case eCurveType.Sine: for (int i = 0; i < CurveLenght; i++) { CurvePrototype[i] = (Byte)((Math.Sin(2 * Math.PI / CurveLenght * i) + 1) / 2 * Byte.MaxValue); } break; case eCurveType.Cosine: for (int i = 0; i < CurveLenght; i++) { CurvePrototype[i] = (Byte)((-Math.Cos(2 * Math.PI / CurveLenght * i) + 1) / 2 * Byte.MaxValue); } break; case eCurveType.Pulse: Byte[] temp = new Byte[CurveLenght / 10]; for (int i = 0; i < temp.Length; i++) { temp[i] = (Byte)((float)1 / (2 * Math.PI) * Math.Exp(-(Math.Pow(3 / temp.Length * i, 2) / 2)) * Byte.MaxValue); } CurvePrototype[CurveLenght / 2] = Byte.MaxValue; for (int i = 1; i < temp.Length; i++) { CurvePrototype[CurveLenght / 2 + i] = temp[i]; CurvePrototype[CurveLenght / 2 - i] = temp[i]; } break; case eCurveType.Triangle: for (int i = 0; i < CurveLenght / 2; i++) { CurvePrototype[i] = (Byte)(Byte.MaxValue / CurveLenght * 2 * i); CurvePrototype[CurveLenght / 2 + i] = (Byte)(Byte.MaxValue - Byte.MaxValue / CurveLenght * 2 * i); } break; case eCurveType.Sawtooth: for (int i = 0; i < CurveLenght; i++) { CurvePrototype[i] = (Byte)(Byte.MaxValue / CurveLenght * i); } break; default: break; } /// Prepare second part for optimized moving Window for (int i = CurveLenght; i < 2 * CurveLenght; i++) { CurvePrototype[i] = CurvePrototype[i - CurveLenght]; } }