Board development complete.

This commit is contained in:
shadow8t4 2018-05-16 05:11:34 +01:00 committed by Gitea
parent 13243ff54d
commit 1c02e728a0
29 changed files with 799 additions and 139 deletions

39
Angels and Demons/.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,39 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Unity Editor",
"type": "unity",
"request": "launch"
},
{
"name": "Windows Player",
"type": "unity",
"request": "launch"
},
{
"name": "OSX Player",
"type": "unity",
"request": "launch"
},
{
"name": "Linux Player",
"type": "unity",
"request": "launch"
},
{
"name": "iOS Player",
"type": "unity",
"request": "launch"
},
{
"name": "Android Player",
"type": "unity",
"request": "launch"
}
]
}

56
Angels and Demons/.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,56 @@
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitignore":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}

View file

@ -1,14 +1,13 @@
using UnityEngine; using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using System.Collections.Generic; using UnityEngine;
using UnityEditor.SceneManagement;
namespace GitMerge namespace GitMerge {
{
/// <summary> /// <summary>
/// The window that lets you perform merges on scenes and prefabs. /// The window that lets you perform merges on scenes and prefabs.
/// </summary> /// </summary>
public class GitMergeWindow : EditorWindow public class GitMergeWindow : EditorWindow {
{
private VCS vcs = new VCSGit (); private VCS vcs = new VCSGit ();
//EditorPrefs keys for settings //EditorPrefs keys for settings
@ -22,10 +21,8 @@ namespace GitMerge
//The MergeManager that has the actual merging logic //The MergeManager that has the actual merging logic
private MergeManager manager; private MergeManager manager;
public bool mergeInProgress public bool mergeInProgress {
{ get {
get
{
return manager != null; return manager != null;
} }
} }
@ -33,10 +30,8 @@ namespace GitMerge
private Vector2 scrollPosition = Vector2.zero; private Vector2 scrollPosition = Vector2.zero;
private int tab = 0; private int tab = 0;
[MenuItem ("Window/GitMerge")] [MenuItem ("Window/GitMerge")]
static void OpenEditor() static void OpenEditor () {
{
var window = EditorWindow.GetWindow (typeof (GitMergeWindow), false, "GitMerge"); var window = EditorWindow.GetWindow (typeof (GitMergeWindow), false, "GitMerge");
//In case we're merging and the scene becomes edited, //In case we're merging and the scene becomes edited,
//the shown SerializedProperties should be repainted //the shown SerializedProperties should be repainted
@ -44,62 +39,48 @@ namespace GitMerge
window.minSize = new Vector2 (500, 100); window.minSize = new Vector2 (500, 100);
} }
void OnEnable() void OnEnable () {
{
LoadSettings (); LoadSettings ();
} }
private static void LoadSettings() private static void LoadSettings () {
{ if (EditorPrefs.HasKey (epAutomerge)) {
if(EditorPrefs.HasKey(epAutomerge))
{
automerge = EditorPrefs.GetBool (epAutomerge); automerge = EditorPrefs.GetBool (epAutomerge);
} } else {
else
{
automerge = true; automerge = true;
} }
if(EditorPrefs.HasKey(epAutofocus)) if (EditorPrefs.HasKey (epAutofocus)) {
{
autofocus = EditorPrefs.GetBool (epAutofocus); autofocus = EditorPrefs.GetBool (epAutofocus);
} } else {
else
{
autofocus = true; autofocus = true;
} }
} }
void OnHierarchyChange() void OnHierarchyChange () {
{
//Repaint if we changed the scene //Repaint if we changed the scene
this.Repaint (); this.Repaint ();
} }
//Always check for editor state changes, and abort the active merge process if needed //Always check for editor state changes, and abort the active merge process if needed
void Update() void Update () {
{ if (MergeAction.inMergePhase &&
if(MergeAction.inMergePhase (EditorApplication.isCompiling ||
&& (EditorApplication.isCompiling EditorApplication.isPlayingOrWillChangePlaymode)) {
|| EditorApplication.isPlayingOrWillChangePlaymode))
{
ShowNotification (new GUIContent ("Aborting merge due to editor state change.")); ShowNotification (new GUIContent ("Aborting merge due to editor state change."));
AbortMerge (); AbortMerge ();
} }
} }
private void AbortMerge() private void AbortMerge () {
{
manager.AbortMerge (); manager.AbortMerge ();
manager = null; manager = null;
} }
void OnGUI() void OnGUI () {
{
Resources.DrawLogo (); Resources.DrawLogo ();
DrawTabButtons (); DrawTabButtons ();
switch(tab) switch (tab) {
{
case 0: case 0:
OnGUISceneTab (); OnGUISceneTab ();
break; break;
@ -117,16 +98,13 @@ namespace GitMerge
/// <summary> /// <summary>
/// Tab that offers scene merging. /// Tab that offers scene merging.
/// </summary> /// </summary>
private void OnGUISceneTab() private void OnGUISceneTab () {
{ GUILayout.Label ("Open Scene: " + EditorSceneManager.GetActiveScene().ToString());
GUILayout.Label("Open Scene: " + EditorApplication.currentScene); if (EditorSceneManager.GetActiveScene().ToString() != "" &&
if(EditorApplication.currentScene != "" !mergeInProgress &&
&& !mergeInProgress GUILayout.Button ("Start merging this scene", GUILayout.Height (80))) {
&& GUILayout.Button("Start merging this scene", GUILayout.Height(80)))
{
var mm = new MergeManagerScene (this, vcs); var mm = new MergeManagerScene (this, vcs);
if(mm.InitializeMerge()) if (mm.InitializeMerge ()) {
{
manager = mm; manager = mm;
} }
} }
@ -137,17 +115,13 @@ namespace GitMerge
/// <summary> /// <summary>
/// Tab that offers prefab merging. /// Tab that offers prefab merging.
/// </summary> /// </summary>
private void OnGUIPrefabTab() private void OnGUIPrefabTab () {
{
GameObject prefab; GameObject prefab;
if(!mergeInProgress) if (!mergeInProgress) {
{
GUILayout.Label ("Drag your prefab here to start merging:"); GUILayout.Label ("Drag your prefab here to start merging:");
if(prefab = EditorGUILayout.ObjectField(null, typeof(GameObject), false, GUILayout.Height(60)) as GameObject) if (prefab = EditorGUILayout.ObjectField (null, typeof (GameObject), false, GUILayout.Height (60)) as GameObject) {
{
var mm = new MergeManagerPrefab (this, vcs); var mm = new MergeManagerPrefab (this, vcs);
if(mm.InitializeMerge(prefab)) if (mm.InitializeMerge (prefab)) {
{
manager = mm; manager = mm;
} }
} }
@ -159,26 +133,22 @@ namespace GitMerge
/// <summary> /// <summary>
/// Tab that offers various settings for the tool. /// Tab that offers various settings for the tool.
/// </summary> /// </summary>
private void OnGUISettingsTab() private void OnGUISettingsTab () {
{
var vcsPath = vcs.exe (); var vcsPath = vcs.exe ();
var vcsPathNew = EditorGUILayout.TextField ("Path to git.exe", vcsPath); var vcsPathNew = EditorGUILayout.TextField ("Path to git.exe", vcsPath);
if(vcsPath != vcsPathNew) if (vcsPath != vcsPathNew) {
{
vcs.SetPath (vcsPathNew); vcs.SetPath (vcsPathNew);
} }
var amNew = EditorGUILayout.Toggle ("Automerge", automerge); var amNew = EditorGUILayout.Toggle ("Automerge", automerge);
if(automerge != amNew) if (automerge != amNew) {
{
automerge = amNew; automerge = amNew;
EditorPrefs.SetBool (epAutomerge, automerge); EditorPrefs.SetBool (epAutomerge, automerge);
} }
GUILayout.Label ("(Automerge new/deleted GameObjects/Components upon merge start)"); GUILayout.Label ("(Automerge new/deleted GameObjects/Components upon merge start)");
var afNew = EditorGUILayout.Toggle ("Auto Highlight", autofocus); var afNew = EditorGUILayout.Toggle ("Auto Highlight", autofocus);
if(autofocus != afNew) if (autofocus != afNew) {
{
autofocus = afNew; autofocus = afNew;
EditorPrefs.SetBool (epAutofocus, autofocus); EditorPrefs.SetBool (epAutofocus, autofocus);
} }
@ -189,18 +159,13 @@ namespace GitMerge
/// If no merge is in progress, draws the buttons to switch between tabs. /// If no merge is in progress, draws the buttons to switch between tabs.
/// Otherwise, draws the "abort merge" button. /// Otherwise, draws the "abort merge" button.
/// </summary> /// </summary>
private void DrawTabButtons() private void DrawTabButtons () {
{ if (!mergeInProgress) {
if(!mergeInProgress)
{
string[] tabs = { "Merge Scene", "Merge Prefab", "Settings" }; string[] tabs = { "Merge Scene", "Merge Prefab", "Settings" };
tab = GUI.SelectionGrid (new Rect (72, 36, 300, 22), tab, tabs, 3); tab = GUI.SelectionGrid (new Rect (72, 36, 300, 22), tab, tabs, 3);
} } else {
else
{
GUI.backgroundColor = new Color (1, 0.4f, 0.4f, 1); GUI.backgroundColor = new Color (1, 0.4f, 0.4f, 1);
if(GUI.Button(new Rect(72, 36, 300, 22), "Abort merge")) if (GUI.Button (new Rect (72, 36, 300, 22), "Abort merge")) {
{
manager.AbortMerge (); manager.AbortMerge ();
manager = null; manager = null;
} }
@ -211,14 +176,11 @@ namespace GitMerge
/// <summary> /// <summary>
/// Displays all MergeActions and the "apply merge" button if a merge is in progress. /// Displays all MergeActions and the "apply merge" button if a merge is in progress.
/// </summary> /// </summary>
private void DisplayMergeProcess() private void DisplayMergeProcess () {
{ if (mergeInProgress) {
if(mergeInProgress)
{
var done = DisplayMergeActions (); var done = DisplayMergeActions ();
GUILayout.BeginHorizontal (); GUILayout.BeginHorizontal ();
if(done && GUILayout.Button("Apply merge")) if (done && GUILayout.Button ("Apply merge")) {
{
manager.CompleteMerge (); manager.CompleteMerge ();
manager = null; manager = null;
} }
@ -230,8 +192,7 @@ namespace GitMerge
/// Displays all GameObjectMergeActions. /// Displays all GameObjectMergeActions.
/// </summary> /// </summary>
/// <returns>True, if all MergeActions are flagged as "merged".</returns> /// <returns>True, if all MergeActions are flagged as "merged".</returns>
private bool DisplayMergeActions() private bool DisplayMergeActions () {
{
scrollPosition = GUILayout.BeginScrollView (scrollPosition, false, true); scrollPosition = GUILayout.BeginScrollView (scrollPosition, false, true);
GUILayout.BeginVertical (GUILayout.MinWidth (480)); GUILayout.BeginVertical (GUILayout.MinWidth (480));
@ -239,8 +200,7 @@ namespace GitMerge
GUI.skin.label.normal.textColor = Color.black; GUI.skin.label.normal.textColor = Color.black;
var done = true; var done = true;
foreach(var actions in manager.allMergeActions) foreach (var actions in manager.allMergeActions) {
{
actions.OnGUI (); actions.OnGUI ();
done = done && actions.merged; done = done && actions.merged;
} }

View file

@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using UnityEditor.SceneManagement;
using System.Collections.Generic; using System.Collections.Generic;
namespace GitMerge namespace GitMerge
@ -21,7 +22,7 @@ namespace GitMerge
public bool InitializeMerge(GameObject prefab) public bool InitializeMerge(GameObject prefab)
{ {
if(!EditorApplication.SaveCurrentSceneIfUserWantsTo()) if(!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{ {
return false; return false;
} }
@ -38,8 +39,8 @@ namespace GitMerge
ourPrefab = prefab; ourPrefab = prefab;
//Open a new Scene that will only display the prefab //Open a new Scene that will only display the prefab
previouslyOpenedScene = EditorApplication.currentScene; previouslyOpenedScene = EditorSceneManager.GetActiveScene().ToString();
EditorApplication.NewScene(); EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
//make the new scene empty //make the new scene empty
Object.DestroyImmediate(Camera.main.gameObject); Object.DestroyImmediate(Camera.main.gameObject);
@ -141,7 +142,7 @@ namespace GitMerge
{ {
if(!string.IsNullOrEmpty(previouslyOpenedScene)) if(!string.IsNullOrEmpty(previouslyOpenedScene))
{ {
EditorApplication.OpenScene(previouslyOpenedScene); EditorSceneManager.OpenScene(previouslyOpenedScene);
previouslyOpenedScene = ""; previouslyOpenedScene = "";
} }
} }

View file

@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using UnityEditor.SceneManagement;
using System.Collections.Generic; using System.Collections.Generic;
namespace GitMerge namespace GitMerge
@ -17,19 +18,19 @@ namespace GitMerge
isMergingScene = true; isMergingScene = true;
//Ask if the scene should be saved, because... //Ask if the scene should be saved, because...
if(!EditorApplication.SaveCurrentSceneIfUserWantsTo()) if(!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{ {
return false; return false;
} }
//...we are reloading it to prevent objects from not having a scene id. //...we are reloading it to prevent objects from not having a scene id.
EditorApplication.OpenScene(EditorApplication.currentScene); EditorSceneManager.OpenScene(EditorSceneManager.GetActiveScene().ToString());
MergeAction.inMergePhase = false; MergeAction.inMergePhase = false;
ObjectDictionaries.Clear(); ObjectDictionaries.Clear();
//checkout "their" version //checkout "their" version
GetTheirVersionOf(EditorApplication.currentScene); GetTheirVersionOf(EditorSceneManager.GetActiveScene().ToString());
AssetDatabase.Refresh(); AssetDatabase.Refresh();
//find all of "our" objects //find all of "our" objects
@ -37,7 +38,7 @@ namespace GitMerge
ObjectDictionaries.SetAsOurObjects(ourObjects); ObjectDictionaries.SetAsOurObjects(ourObjects);
//add "their" objects //add "their" objects
EditorApplication.OpenSceneAdditive(theirFilename); EditorSceneManager.OpenScene(theirFilename);
//delete scene file //delete scene file
AssetDatabase.DeleteAsset(theirFilename); AssetDatabase.DeleteAsset(theirFilename);
@ -91,7 +92,7 @@ namespace GitMerge
ObjectDictionaries.DestroyTheirObjects(); ObjectDictionaries.DestroyTheirObjects();
ObjectDictionaries.Clear(); ObjectDictionaries.Clear();
EditorApplication.SaveScene(); EditorSceneManager.SaveOpenScenes();
allMergeActions = null; allMergeActions = null;
@ -112,7 +113,7 @@ namespace GitMerge
base.AbortMerge(); base.AbortMerge();
//Save scene //Save scene
EditorApplication.SaveScene(); EditorSceneManager.SaveOpenScenes();
} }
} }
} }

Binary file not shown.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 37962f192a2e24b1ab2b8d25958f2e17
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ddf6409ba9464744b426077d9f8f194
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e0e5fcafbd13a41df84a38ad88cf5d89
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,5 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6f41f0233cb7644e4a83e5f5543ed237 guid: 5208081e0c9554b408a216e7bbde1f99
folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:

Binary file not shown.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7453ff1d2cbcf4c6483f203ee524077f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 27cf7281b7c8649f4a2f237c6cc0876c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 10bacab99ba8a424886194f09ac0549f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bed2e0f0ee6474bf6ad36acc1d4655df
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,443 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BoardManager : MonoBehaviour
{
// Global reference to the canvas' width and height.
private float canvaswidth;
private float canvasheight;
// Variable to change spacing of the board from the edges of the canvas.
private float canvasspacing = 80f;
public Image board;
// Board size references.
private float boardwidth;
private float boardheight;
// Might want to make this part modular in the future.
private float numberofspaces = 11;
// Spaces for the board need to be spawned and resized based on canvas.
private float spacespacing;
public Button blackspaceasset;
public Transform blackspacetransform;
public Image whitespaceasset;
public Transform whitespacetransform;
// Image assets for the board spaces.
public Sprite angelimage;
public Image demonimage;
// Keep references of all the space GameObjects.
private Button[] blackspaces = new Button[61];
private Image[] whitespaces = new Image[60];
// Use this for initialization
void Start ()
{
canvasheight = this.GetComponentInParent<RectTransform>().rect.height;
canvaswidth = this.GetComponentInParent<RectTransform>().rect.width;
boardheight = board.GetComponent<RectTransform>().rect.height;
boardwidth = board.GetComponent<RectTransform>().rect.width;
spacespacing = ((canvaswidth - canvasspacing)/11f);
SpawnInitialBoard();
}
private void UpdateBoardScale()
{
canvasheight = this.GetComponentInParent<RectTransform>().rect.height;
canvaswidth = this.GetComponentInParent<RectTransform>().rect.width;
if(canvaswidth > canvasheight)
{
board.rectTransform.sizeDelta = new Vector2(canvasheight - canvasspacing, canvasheight - canvasspacing);
}
else
{
board.rectTransform.sizeDelta = new Vector2(canvaswidth - canvasspacing, canvaswidth - canvasspacing);
}
boardheight = board.GetComponent<RectTransform>().rect.height;
boardwidth = board.GetComponent<RectTransform>().rect.width;
spacespacing = ((boardwidth)/11f);
UpdatePieceScale();
}
private Button SpawnBlackSpace(int i)
{
Button bsbutton;
bsbutton = Instantiate(blackspaceasset, blackspacetransform);
bsbutton.name += "" + i;
bsbutton.onClick.AddListener(delegate{ButtonAction(bsbutton);});
return bsbutton;
}
private Image SpawnWhiteSpace()
{
Image wsimage;
wsimage = Instantiate(whitespaceasset, whitespacetransform);
return wsimage;
}
private void SpawnInitialBoard()
{
for(int i = 0; i < blackspaces.Length; ++i)
{
Button temp;
temp = SpawnBlackSpace(i);
temp.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
float x = (spacespacing*i*2 + (temp.GetComponent<RectTransform>().rect.width / 2f)) % (boardwidth) - ((boardwidth) / 2f);
float y = (boardheight / 2f) - ((temp.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor(i/(11f/2f))));
temp.transform.localPosition = new Vector3(x, y, 0);
blackspaces[i] = temp;
if(i < blackspaces.Length - 1)
{
Image tempimage;
tempimage = SpawnWhiteSpace();
tempimage.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
x = (spacespacing*i*2 + (tempimage.GetComponent<RectTransform>().rect.width / 2f)*3) % (boardwidth) - ((boardwidth) / 2f);
y = (boardheight / 2f) - ((tempimage.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor((i + 1)/(11.01f/2f))));
tempimage.transform.localPosition = new Vector3(x, y, 0);
whitespaces[i] = tempimage;
}
}
}
private void UpdatePieceScale()
{
for(int i = 0; i < blackspaces.Length; ++i)
{
Button temp = blackspaces[i];
temp.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
float x = (spacespacing*i*2 + (temp.GetComponent<RectTransform>().rect.width / 2f)) % (boardwidth) - ((boardwidth) / 2f);
float y = (boardheight / 2f) - ((temp.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor(i/(11f/2f))));
temp.transform.localPosition = new Vector3(x, y, 0);
blackspaces[i] = temp;
if(i < blackspaces.Length - 1)
{
Image tempimage = whitespaces[i];
tempimage.GetComponent<RectTransform>().sizeDelta = new Vector2(spacespacing, spacespacing);
x = (spacespacing*i*2 + (tempimage.GetComponent<RectTransform>().rect.width / 2f)*3) % (boardwidth) - ((boardwidth) / 2f);
y = (boardheight / 2f) - ((tempimage.GetComponent<RectTransform>().rect.height / 2f) + spacespacing*(Mathf.Floor((i + 1)/(11.01f/2f))));
tempimage.transform.localPosition = new Vector3(x, y, 0);
whitespaces[i] = tempimage;
}
}
}
// Update is called once per frame
void Update ()
{
UpdateBoardScale();
}
public void ButtonAction(Button b)
{
int buttonindex = 0;
int.TryParse(b.name.Replace("Move Selection(Clone)", ""), out buttonindex);
Vector2 boardcoords = ConvertButtonIndex(buttonindex);
// This is completely incorrect and will most likely need a switch case of some kind in the future.
Debug.Log("Board coordinates: " + boardcoords.x + " " + boardcoords.y);
ChangeSpaces(boardcoords);
}
private Vector2 ConvertButtonIndex(int i)
{
Vector2 temp;
temp.x = (i*2)%11;
temp.y = 0;
switch(i)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
return temp;
case 6:
case 7:
case 8:
case 9:
case 10:
temp.y = 1;
return temp;
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
temp.y = 2;
return temp;
case 17:
case 18:
case 19:
case 20:
case 21:
temp.y = 3;
return temp;
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
temp.y = 4;
return temp;
case 28:
case 29:
case 30:
case 31:
case 32:
temp.y = 5;
return temp;
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
temp.y = 6;
return temp;
case 39:
case 40:
case 41:
case 42:
case 43:
temp.y = 7;
return temp;
case 44:
case 45:
case 46:
case 47:
case 48:
case 49:
temp.y = 8;
return temp;
case 50:
case 51:
case 52:
case 53:
case 54:
temp.y = 9;
return temp;
case 55:
case 56:
case 57:
case 58:
case 59:
case 60:
temp.y = 10;
return temp;
default:
return temp;
}
}
private int ConvertImageIndex(Vector2 bc)
{
int i = 0;
switch(Mathf.RoundToInt(bc.y))
{
case 0:
i = (Mathf.RoundToInt(bc.x) - 1)/2;
break;
case 1:
i = (Mathf.RoundToInt(bc.x))/2;
i += 5;
break;
case 2:
i = (Mathf.RoundToInt(bc.x) - 1)/2;
i += 11;
break;
case 3:
i = (Mathf.RoundToInt(bc.x))/2;
i += 16;
break;
case 4:
i = (Mathf.RoundToInt(bc.x) - 1)/2;
i += 22;
break;
case 5:
i = (Mathf.RoundToInt(bc.x))/2;
i += 27;
break;
case 6:
i = (Mathf.RoundToInt(bc.x) - 1)/2;
i += 33;
break;
case 7:
i = (Mathf.RoundToInt(bc.x))/2;
i += 38;
break;
case 8:
i = (Mathf.RoundToInt(bc.x) - 1)/2;
i += 44;
break;
case 9:
i = (Mathf.RoundToInt(bc.x))/2;
i += 49;
break;
case 10:
i = (Mathf.RoundToInt(bc.x) - 1)/2;
i += 55;
break;
default:
break;
}
return i;
}
private void ChangeSpaces(Vector2 bc)
{
Vector2 tempbc = bc;
int wsi = 0;
if(bc.x > 0 && bc.x < (numberofspaces - 1))
{
if(bc.y > 0)
{
Debug.Log(
"changing space:" +
(bc.x) + " " + (bc.y - 1)
);
tempbc = bc;
tempbc.y -= 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
if(bc.y < (numberofspaces - 1))
{
Debug.Log(
"changing space:" +
(bc.x) + " " + (bc.y + 1)
);
tempbc = bc;
tempbc.y += 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
Debug.Log(
"changing spaces:" +
(bc.x - 1) + " " + (bc.y) + "\t" +
(bc.x + 1) + " " + (bc.y)
);
tempbc = bc;
tempbc.x -= 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
tempbc.x += 2;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
else if(bc.y > 0 && bc.y < (numberofspaces - 1))
{
if(bc.x == 0)
{
Debug.Log(
"changing space:" +
(bc.x + 1) + " " + (bc.y)
);
tempbc = bc;
tempbc.x += 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
if(bc.x == (numberofspaces - 1))
{
Debug.Log(
"changing space:" +
(bc.x - 1) + " " + (bc.y)
);
tempbc = bc;
tempbc.x -= 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
Debug.Log(
"changing spaces:" +
(bc.x) + " " + (bc.y - 1) + "\t" +
(bc.x) + " " + (bc.y + 1)
);
tempbc = bc;
tempbc.y -= 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
tempbc.y += 2;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
else
{
if(bc.x == 0)
{
Debug.Log(
"changing space:" +
(bc.x + 1) + " " + (bc.y)
);
tempbc = bc;
tempbc.x += 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
if(bc.x == (numberofspaces - 1))
{
Debug.Log(
"changing space:" +
(bc.x - 1) + " " + (bc.y)
);
tempbc = bc;
tempbc.x -= 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
if(bc.y > 0)
{
Debug.Log(
"changing space:" +
(bc.x) + " " + (bc.y - 1)
);
tempbc = bc;
tempbc.y -= 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
if(bc.y < (numberofspaces - 1))
{
Debug.Log(
"changing space:" +
(bc.x) + " " + (bc.y + 1)
);
tempbc = bc;
tempbc.y += 1;
wsi = ConvertImageIndex(tempbc);
whitespaces[wsi].sprite = angelimage;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8b4ca8083201141f388e345f2beecffb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 50c0d0a843af248dc8b1be7ac3b4c63e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View file

@ -0,0 +1,84 @@
fileFormatVersion: 2
guid: 80e6f163eb4504e0cbd7e886f3ea4f6d
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 5
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: b7b8277dba3c0425892944924e2372d0
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant: