Browse Source

Pathfinding implementiert

bolt_update
laurids 4 years ago
parent
commit
79f3aea63c
17 changed files with 883 additions and 96 deletions
  1. +60
    -55
      Assets/GWConquest/Prefabs/DistrictIcon.prefab
  2. +76
    -0
      Assets/GWConquest/Prefabs/GarrisonArmyGroup.prefab
  3. +34
    -21
      Assets/GWConquest/Scenes/GalaxyMap.unity
  4. +12
    -1
      Assets/GWConquest/Scripts/Formation.cs
  5. +176
    -0
      Assets/GWConquest/Scripts/Pathfinding.cs
  6. +11
    -0
      Assets/GWConquest/Scripts/Pathfinding.cs.meta
  7. +9
    -0
      Assets/GWConquest/Scripts/Planet.cs
  8. +28
    -1
      Assets/GWConquest/Scripts/UI/DistrictIcon.cs
  9. +34
    -4
      Assets/GWConquest/Scripts/UI/DragDropElement.cs
  10. +57
    -6
      Assets/GWConquest/Scripts/UI/GarrisonArmyGroupUI.cs
  11. +2
    -2
      Assets/GWConquest/Scripts/UI/GarrisonUI.cs
  12. +18
    -3
      Assets/GWConquest/Scripts/UI/PlanetViewUI.cs
  13. +17
    -0
      Assets/GWConquest/Scripts/Util.cs
  14. +22
    -0
      Assets/Photon/PhotonBolt/project.json
  15. +1
    -1
      Packages/manifest.json
  16. +324
    -0
      Packages/packages-lock.json
  17. +2
    -2
      ProjectSettings/ProjectVersion.txt

+ 60
- 55
Assets/GWConquest/Prefabs/DistrictIcon.prefab View File

@ -623,8 +623,8 @@ GameObject:
- component: {fileID: 2621911208907321623}
- component: {fileID: 6530463141977457202}
- component: {fileID: 1344012077935187005}
- component: {fileID: 2232505496370496088}
- component: {fileID: 2633643605963840149}
- component: {fileID: 1193427619120291309}
m_Layer: 5
m_Name: DistrictIcon
m_TagString: Untagged
@ -670,6 +670,7 @@ MonoBehaviour:
nameText: {fileID: 2621911207336838694}
PlayerIndicator: {fileID: 5754297686137200875}
EnemyIndicator: {fileID: 1670534954343448542}
animator: {fileID: 2633643605963840149}
--- !u!114 &1344012077935187005
MonoBehaviour:
m_ObjectHideFlags: 0
@ -683,60 +684,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
target: {fileID: 0}
--- !u!114 &2232505496370496088
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2621911208907323112}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 3
m_Colors:
m_NormalColor: {r: 0.08235294, g: 0.08235294, b: 0.08235294, a: 0.72156864}
m_HighlightedColor: {r: 0.28100002, g: 0.28100002, b: 0.28100002, a: 0.5137255}
m_PressedColor: {r: 0.28235295, g: 0.28235295, b: 0.28235295, a: 0.5137255}
m_SelectedColor: {r: 0.28235295, g: 0.28235295, b: 0.28235295, a: 0.50980395}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 2621911208064913514}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6530463141977457202}
m_MethodName: OnClicked
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!95 &2633643605963840149
Animator:
serializedVersion: 3
@ -756,6 +703,64 @@ Animator:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &1193427619120291309
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2621911208907323112}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0b148fe25e99eb48b9724523833bab1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Delegates:
- eventID: 4
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6530463141977457202}
m_MethodName: OnClicked
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- eventID: 0
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6530463141977457202}
m_MethodName: OnPointerEnter
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument: Highlighted
m_BoolArgument: 0
m_CallState: 2
- eventID: 1
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6530463141977457202}
m_MethodName: OnPointerExit
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument: Normal
m_BoolArgument: 0
m_CallState: 2
--- !u!1 &2621911208936950809
GameObject:
m_ObjectHideFlags: 0


+ 76
- 0
Assets/GWConquest/Prefabs/GarrisonArmyGroup.prefab View File

@ -630,6 +630,80 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &6977842000702312986
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5877545363568524576}
- component: {fileID: 5190676494961839772}
- component: {fileID: 720641137575629014}
m_Layer: 5
m_Name: MovingIcon
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &5877545363568524576
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6977842000702312986}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 655251527113343146}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 60, y: 60}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5190676494961839772
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6977842000702312986}
m_CullTransparentMesh: 0
--- !u!114 &720641137575629014
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6977842000702312986}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: ea5c7bf8256c9664ca24278963abd4c5, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &7417185904032749486
GameObject:
m_ObjectHideFlags: 0
@ -901,6 +975,7 @@ RectTransform:
- {fileID: 1735239398645695616}
- {fileID: 6169903382938894854}
- {fileID: 3924166688070369494}
- {fileID: 5877545363568524576}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -937,6 +1012,7 @@ MonoBehaviour:
RelocateEntryPrefab: {fileID: 3135597628127235541, guid: f7fcfb373d28af6429824ae43fb4b4aa,
type: 3}
RelocateEntryOffset: 25
MovingIcon: {fileID: 6977842000702312986}
--- !u!1 &8965718175585305324
GameObject:
m_ObjectHideFlags: 0


+ 34
- 21
Assets/GWConquest/Scenes/GalaxyMap.unity View File

@ -4652,8 +4652,8 @@ RectTransform:
m_Father: {fileID: 1548826460}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.4108699}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 4, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
@ -4936,7 +4936,7 @@ RectTransform:
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 4, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
@ -16111,8 +16111,8 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 71338309}
m_HandleRect: {fileID: 71338308}
m_Direction: 2
m_Value: 1
m_Size: 0.5891301
m_Value: 0
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -36314,7 +36314,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &765894939
RectTransform:
m_ObjectHideFlags: 0
@ -65343,7 +65343,7 @@ RectTransform:
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
@ -72933,9 +72933,9 @@ RectTransform:
m_Father: {fileID: 1022689915}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 60.3, y: -4}
m_AnchorMin: {x: 0.5, y: 1}
m_AnchorMax: {x: 0.5, y: 1}
m_AnchoredPosition: {x: -2.7000008, y: -4}
m_SizeDelta: {x: 110, y: 68}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1596931836
@ -75026,7 +75026,7 @@ RectTransform:
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 4, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
@ -75083,7 +75083,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &1659880902
RectTransform:
m_ObjectHideFlags: 0
@ -80357,6 +80357,11 @@ PrefabInstance:
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5877545363568524576, guid: 3da507d0addcecc4688100db8c4e4304,
type: 3}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 8873205197795550154, guid: 3da507d0addcecc4688100db8c4e4304,
type: 3}
propertyPath: m_Name
@ -85824,7 +85829,7 @@ PrefabInstance:
- target: {fileID: 7870129596896663125, guid: 8b0edf9c7ac699a4da4b06f9b352ff47,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 419
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7870129596896663125, guid: 8b0edf9c7ac699a4da4b06f9b352ff47,
type: 3}
@ -85834,7 +85839,7 @@ PrefabInstance:
- target: {fileID: 7870129596896663125, guid: 8b0edf9c7ac699a4da4b06f9b352ff47,
type: 3}
propertyPath: m_SizeDelta.x
value: 838
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7870129596896663125, guid: 8b0edf9c7ac699a4da4b06f9b352ff47,
type: 3}
@ -85854,7 +85859,7 @@ PrefabInstance:
- target: {fileID: 7870129596896663125, guid: 8b0edf9c7ac699a4da4b06f9b352ff47,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7870129596896663125, guid: 8b0edf9c7ac699a4da4b06f9b352ff47,
type: 3}
@ -89277,10 +89282,10 @@ RectTransform:
m_Father: {fileID: 2009225604}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: -400, y: -47.890015}
m_SizeDelta: {x: 545, y: -115.7854}
m_AnchoredPosition: {x: 15, y: -47.890015}
m_SizeDelta: {x: 130, y: -115.7854}
m_Pivot: {x: 0, y: 0.5}
--- !u!114 &1906939933
MonoBehaviour:
@ -97708,7 +97713,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 247}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!114 &2089647853
MonoBehaviour:
@ -100586,11 +100591,19 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 321296368, guid: f8bffe0306e53cb4b958afe65a7c7b2c, type: 3}
propertyPath: m_AnchorMax.x
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 321296368, guid: f8bffe0306e53cb4b958afe65a7c7b2c, type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 321296368, guid: f8bffe0306e53cb4b958afe65a7c7b2c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1069889124, guid: f8bffe0306e53cb4b958afe65a7c7b2c, type: 3}
propertyPath: m_AnchoredPosition.y
value: -0.000015258789
objectReference: {fileID: 0}
- target: {fileID: 2443912949472084106, guid: f8bffe0306e53cb4b958afe65a7c7b2c,
type: 3}


+ 12
- 1
Assets/GWConquest/Scripts/Formation.cs View File

@ -4,7 +4,7 @@ using System;
namespace GWConquest
{
public class Formation : Bolt.EntityBehaviour<IFormationState>
public class Formation : Bolt.EntityBehaviour<IFormationState>, IMovable<Zone>
{
public static Formation selectedFormation;
@ -214,6 +214,17 @@ namespace GWConquest
}
}
public float GetModifierForTransition(Zone origin, Zone target)
{
return 1f;
}
public bool CanMoveTo(Zone origin, Zone target)
{
return true;
}
}

+ 176
- 0
Assets/GWConquest/Scripts/Pathfinding.cs View File

@ -0,0 +1,176 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace GWConquest
{
public class PathfindingGraph<T> where T : class
{
public class Node
{
public T zone;
public List<Connection> connections = new List<Connection>();
}
public class Connection
{
public Node target;
public float length;
}
public class Path
{
public List<T> zones;
public float totalDistance;
public override string ToString()
{
if(zones.Count == 0)
{
return "Empty Path";
}
else
{
string str = zones[0].ToString();
for(int i = 1; i < zones.Count; i++)
{
str = str + " -> " + zones[i].ToString();
}
str += " (Distance: " + totalDistance + ")";
return str;
}
}
}
private Dictionary<T, Node> nodeMap = new Dictionary<T, Node>();
public PathfindingGraph(IEnumerable<T> zones)
{
foreach(T zone in zones)
{
Node n = new Node { zone = zone };
nodeMap.Add(zone, n);
}
}
public void AddConnection(T zone1, T zone2, float length)
{
nodeMap[zone1].connections.Add(new Connection
{
target = nodeMap[zone2],
length = length
});
nodeMap[zone2].connections.Add(new Connection
{
target = nodeMap[zone1],
length = length
});
}
private class DjikstraResult
{
public Dictionary<Node, float> distances;
public Dictionary<Node, Node> previous;
}
private DjikstraResult Djikstra(IMovable<T> movable, Node startNode, Node endNode = null)
{
//Initialisation
Dictionary<Node, float> distances = new Dictionary<Node, float>();
Dictionary<Node, Node> previous = new Dictionary<Node, Node>();
foreach(Node n in nodeMap.Values)
{
distances[n] = float.MaxValue;
previous[n] = null;
}
distances[startNode] = 0f;
List<Node> Q = new List<Node>(nodeMap.Values);
//Loop
while(Q.Count > 0)
{
Node u = Q.ArgMin(n => distances[n]);
Q.Remove(u);
//Break condition
if(endNode != null && endNode == u)
{
break;
}
foreach(Connection c in u.connections)
{
Node v = c.target;
if(Q.Contains(v) && movable.CanMoveTo(u.zone,v.zone))
{
//Distance update
float distanceBetween = c.length * movable.GetModifierForTransition(u.zone, v.zone);
float alternate = distances[u] + distanceBetween;
if(alternate < distances[v])
{
distances[v] = alternate;
previous[v] = u;
}
}
}
}
return new DjikstraResult { previous = previous, distances = distances };
}
private Path GetPathFromResult(DjikstraResult result, Node node)
{
List<T> list = new List<T>();
Node u = node;
while(u != null)
{
list.Insert(0, u.zone);
u = result.previous[u];
}
return new Path { zones = list, totalDistance = result.distances[node] };
}
public Path FindShortestPath(IMovable<T> movable, T startZone, T endZone)
{
Node startNode = nodeMap[startZone];
Node endNode = nodeMap[endZone];
var result = Djikstra(movable, startNode, endNode);
if(result.distances[endNode] < float.MaxValue)
{
return GetPathFromResult(result, endNode);
}
else
{
return null;
}
}
public Dictionary<T, Path> FindAllPaths(IMovable<T> movable, T startZone)
{
Node startNode = nodeMap[startZone];
var result = Djikstra(movable, startNode);
var dict = new Dictionary<T, Path>();
foreach(Node n in nodeMap.Values)
{
if(n != startNode && result.distances[n] < float.MaxValue)
{
dict.Add(n.zone, GetPathFromResult(result, n));
}
}
return dict;
}
}
public interface IMovable<T>
{
float GetModifierForTransition(T origin, T target);
bool CanMoveTo(T origin, T target);
}
}

+ 11
- 0
Assets/GWConquest/Scripts/Pathfinding.cs.meta View File

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

+ 9
- 0
Assets/GWConquest/Scripts/Planet.cs View File

@ -54,6 +54,8 @@ namespace GWConquest
[HideInInspector]
public List<PlanetConnection> connections = new List<PlanetConnection>();
public PathfindingGraph<Zone> pathfindingGraph;
public Zone GetMainZone(ZoneType type)
{
if (GetZones(type) == null) return null;
@ -93,6 +95,13 @@ namespace GWConquest
zone.planet = this;
}
pathfindingGraph = new PathfindingGraph<Zone>(groundZones);
foreach(DistrictConnection conn in GetComponentsInChildren<DistrictConnection>())
{
float connLength = Vector3.Distance(conn.district1.transform.position, conn.district2.transform.position);
pathfindingGraph.AddConnection(conn.district1.Zone, conn.district2.Zone, connLength);
}
if (showPlanetName)
{
IngameUI ui = FindObjectOfType<IngameUI>();


+ 28
- 1
Assets/GWConquest/Scripts/UI/DistrictIcon.cs View File

@ -13,7 +13,10 @@ namespace GWConquest
public StrengthIndicator PlayerIndicator;
public StrengthIndicator EnemyIndicator;
private District district;
public Animator animator;
public District district { get; private set; }
private bool isSelected = false;
public void SetDistrict(District d)
{
@ -24,9 +27,33 @@ namespace GWConquest
public void OnClicked()
{
animator.SetTrigger("Pressed");
isSelected = true;
FindObjectOfType<PlanetViewUI>().SelectZone(district.Zone);
}
public void OnDeselected()
{
isSelected = false;
animator.SetTrigger("Normal");
}
public void OnPointerEnter()
{
if(!isSelected)
{
animator.SetTrigger("Highlighted");
}
}
public void OnPointerExit()
{
if(!isSelected)
{
animator.SetTrigger("Normal");
}
}
public void UpdateIndicator()
{
IEnumerable<Formation> formations = district.Zone.Formations;


+ 34
- 4
Assets/GWConquest/Scripts/UI/DragDropElement.cs View File

@ -8,6 +8,10 @@ namespace GWConquest
private bool isDragging = false;
private Vector3 origPosition;
private Vector3 mouseOffset;
private Vector3 startMousePosition;
private Transform origParent;
private bool hasMoved = false;
public RectTransform rectTransform
{
@ -23,8 +27,10 @@ namespace GWConquest
{
BoltLog.Info("Started dragging");
isDragging = true;
hasMoved = false;
origPosition = rectTransform.localPosition;
mouseOffset = rectTransform.position - mousePos;
startMousePosition = mousePos;
mouseOffset = rectTransform.position - mousePos;
}
}
@ -32,16 +38,35 @@ namespace GWConquest
{
Vector3 mousePos = Input.mousePosition;
rectTransform.position = mousePos + mouseOffset;
if (mousePos != startMousePosition)
{
if (!hasMoved)
{
hasMoved = true;
OnDragBegin();
origParent = rectTransform.parent;
rectTransform.SetParent(rectTransform.GetComponentInParent<Canvas>().transform);
}
}
rectTransform.position = mousePos + mouseOffset;
if (Input.GetButtonUp("Left Click"))
{
isDragging = false;
if(OnDragFinished())
if(hasMoved)
{
rectTransform.localPosition = origPosition;
if (OnDragFinished())
{
rectTransform.SetParent(origParent);
rectTransform.localPosition = origPosition;
}
}
hasMoved = false;
}
}
}
@ -50,5 +75,10 @@ namespace GWConquest
{
return false;
}
public virtual void OnDragBegin()
{
}
}
}

+ 57
- 6
Assets/GWConquest/Scripts/UI/GarrisonArmyGroupUI.cs View File

@ -1,9 +1,10 @@
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace GWConquest
{
public class GarrisonArmyGroupUI : MonoBehaviour
public class GarrisonArmyGroupUI : DragDropElement
{
public RectTransform ArrowTransform;
@ -16,12 +17,19 @@ namespace GWConquest
public GameObject RelocateEntryPrefab;
public float RelocateEntryOffset;
public GameObject MovingIcon;
private Formation formation;
private bool relocatePanelShowing;
private float relocateEntryHeight;
private bool isSelected;
private GarrisonUI garrisonUI;
public void Init(Formation f)
{
garrisonUI = GetComponentInParent<GarrisonUI>();
formation = f;
if (formation.IsExpandedInMenu)
{
@ -50,7 +58,13 @@ namespace GWConquest
GetComponentInParent<GarrisonUI>().Rebuild();
}
public void UpdateButtons(bool isSelected)
public void SetSelected(bool sel)
{
isSelected = sel;
UpdateButtons();
}
public void UpdateButtons()
{
if (isSelected)
{
@ -69,7 +83,7 @@ namespace GWConquest
public void SelectFormation()
{
GetComponentInParent<GarrisonUI>().SelectFormation(formation, null);
garrisonUI.SelectFormation(formation, null);
}
public void ToggleRelocatePanel()
@ -79,7 +93,7 @@ namespace GWConquest
ButtonsLarge.SetActive(!relocatePanelShowing && formation.IsExpandedInMenu);
Corners.SetActive(!relocatePanelShowing);
GetComponentInParent<GarrisonUI>().ToggleRelocatePanel(relocatePanelShowing, formation);
garrisonUI.ToggleRelocatePanel(relocatePanelShowing, formation);
if (relocatePanelShowing)
{
@ -92,12 +106,17 @@ namespace GWConquest
if (formation.currentZone != null)
{
var zones = formation.currentZone.planet.groundZones.Where(z => (!z.attackZone && z != formation.currentZone));
var pathfinding = formation.currentZone.planet.pathfindingGraph;
var allPaths = pathfinding.FindAllPaths(formation, formation.currentZone);
var zones = allPaths.Keys;
float entryY = RelocateEntryOffset;
foreach (Zone z in zones)
{
Debug.LogFormat("Path to zone {0}: {1}", z, allPaths[z]);
var entryGO = Instantiate(RelocateEntryPrefab);
var entryRT = entryGO.GetComponent<RectTransform>();
entryRT.SetParent(relocatePanelRT);
@ -121,8 +140,40 @@ namespace GWConquest
public void RelocateFormation(Zone z)
{
GetComponentInParent<GarrisonUI>().Deselect();
garrisonUI.Deselect();
formation.MoveToZone(z, GameManager.Instance.GroundTransitionLengthFactor);
}
public override void OnDragBegin()
{
foreach(Graphic g in GetComponentsInChildren<Graphic>())
{
g.enabled = false;
}
MovingIcon.SetActive(true);
Vector3 mousePos = Input.mousePosition;
MovingIcon.GetComponent<RectTransform>().position = mousePos;
}
public override bool OnDragFinished()
{
foreach(DistrictIcon di in FindObjectsOfType<DistrictIcon>())
{
RectTransform diRT = di.GetComponent<RectTransform>();
Vector3 mousePos = Input.mousePosition;
if(RectTransformUtility.RectangleContainsScreenPoint(diRT, mousePos))
{
RelocateFormation(di.district.Zone);
break;
}
}
MovingIcon.SetActive(false);
foreach (Graphic g in GetComponentsInChildren<Graphic>())
{
g.enabled = true;
}
return true;
}
}
}

+ 2
- 2
Assets/GWConquest/Scripts/UI/GarrisonUI.cs View File

@ -152,7 +152,7 @@ namespace GWConquest
}
}
GarrisonArmyGroupUI ui = ArmyGroupMap[selectedFormation].GetComponent<GarrisonArmyGroupUI>();
ui.UpdateButtons(false);
ui.SetSelected(false);
}
selectedFormation = f;
@ -166,7 +166,7 @@ namespace GWConquest
if (selectedFormation != null && ArmyGroupMap.ContainsKey(selectedFormation))
{
GarrisonArmyGroupUI ui = ArmyGroupMap[selectedFormation].GetComponent<GarrisonArmyGroupUI>();
ui.UpdateButtons(true);
ui.SetSelected(true);
if (selectedUnit != null)
{


+ 18
- 3
Assets/GWConquest/Scripts/UI/PlanetViewUI.cs View File

@ -172,12 +172,21 @@ namespace GWConquest
SpaceEnemyIndicator.UpdateWithBars(enemyStrength, EnemyPlayer?.Color);
}
public void SelectZone(Zone district)
public void SelectZone(Zone zone)
{
selectedZone = district;
selectedZone = zone;
if(district.GetComponent<District>() != null)
District d = selectedZone.GetComponent<District>();
if(d != null)
{
foreach (DistrictIcon icon in districtIcons)
{
if (icon.district != d)
{
icon.OnDeselected();
}
}
ShowGroundPanel();
}
else
@ -243,6 +252,11 @@ namespace GWConquest
public void Deselect()
{
foreach (DistrictIcon icon in districtIcons)
{
icon.OnDeselected();
}
selectedZone = null;
if(GroundPanel.gameObject.activeSelf)
{
@ -253,5 +267,6 @@ namespace GWConquest
HideZonePanel();
}
}
}
}

+ 17
- 0
Assets/GWConquest/Scripts/Util.cs View File

@ -160,6 +160,23 @@ namespace GWConquest
else return default;
}
public static T ArgMin<T>(this IEnumerable<T> dict, Func<T, float> selector)
{
float minValue = float.MaxValue;
T minArg = default;
foreach(var entry in dict)
{
float val = selector(entry);
if(val <= minValue)
{
minValue = val;
minArg = entry;
}
}
return minArg;
}
}
}

+ 22
- 0
Assets/Photon/PhotonBolt/project.json View File

@ -91,6 +91,28 @@
"ExtrapolationMaxFrames": 9,
"SnapMagnitude": 10.0
}
},
{
"Name": "PathQueue",
"Enabled": true,
"Expanded": true,
"ReplicationMode": 1,
"Priority": 1,
"PropertyType": {
"$type": "Bolt.Compiler.PropertyTypeArray, bolt.compiler",
"ElementCount": 32,
"ElementType": {
"$type": "Bolt.Compiler.PropertyTypeInteger, bolt.compiler",
"MaxValue": 255
}
},
"AssetSettings": {
"$type": "Bolt.Compiler.PropertyStateSettings, bolt.compiler",
"ExtrapolationErrorTolerance": 0.25,
"_ExtrapolationCorrectionFrames": 6,
"ExtrapolationMaxFrames": 9,
"SnapMagnitude": 10.0
}
}
],
"PacketMaxBits": 512,


+ 1
- 1
Packages/manifest.json View File

@ -4,7 +4,7 @@
"com.unity.2d.sprite": "1.0.0",
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.2.0",
"com.unity.ide.vscode": "1.2.1",
"com.unity.postprocessing": "2.3.0",
"com.unity.test-framework": "1.1.14",
"com.unity.timeline": "1.2.10",


+ 324
- 0
Packages/packages-lock.json View File

@ -0,0 +1,324 @@
{
"dependencies": {
"com.unity.2d.common": {
"version": "2.0.2",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.2d.sprite": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.2d.sprite": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.collab-proxy": {
"version": "1.2.16",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
"version": "1.0.0",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "1.1.4",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.1"
},
"url": "https://packages.unity.com"
},
"com.unity.ide.vscode": {
"version": "1.2.1",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.postprocessing": {
"version": "2.3.0",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.14",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.timeline": {
"version": "1.2.10",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.ugui": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.ui": "1.0.0"
}
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.androidjni": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.animation": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.assetbundle": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.audio": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.cloth": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0"
}
},
"com.unity.modules.director": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.animation": "1.0.0"
}
},
"com.unity.modules.imageconversion": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.imgui": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.jsonserialize": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.particlesystem": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.physics": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.physics2d": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.screencapture": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.imageconversion": "1.0.0"
}
},
"com.unity.modules.subsystems": {
"version": "1.0.0",
"depth": 1,
"source": "builtin",
"dependencies": {
"com.unity.modules.jsonserialize": "1.0.0"
}
},
"com.unity.modules.terrain": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.terrainphysics": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.terrain": "1.0.0"
}
},
"com.unity.modules.tilemap": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics2d": "1.0.0"
}
},
"com.unity.modules.ui": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.uielements": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
}
},
"com.unity.modules.umbra": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.unityanalytics": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
}
},
"com.unity.modules.unitywebrequest": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.unitywebrequestassetbundle": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0"
}
},
"com.unity.modules.unitywebrequestaudio": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.audio": "1.0.0"
}
},
"com.unity.modules.unitywebrequesttexture": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0"
}
},
"com.unity.modules.unitywebrequestwww": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0"
}
},
"com.unity.modules.vehicles": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0"
}
},
"com.unity.modules.video": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0"
}
},
"com.unity.modules.vr": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
},
"com.unity.modules.wind": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.modules.xr": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.subsystems": "1.0.0"
}
}
}
}

+ 2
- 2
ProjectSettings/ProjectVersion.txt View File

@ -1,2 +1,2 @@
m_EditorVersion: 2019.3.14f1
m_EditorVersionWithRevision: 2019.3.14f1 (2b330bf6d2d8)
m_EditorVersion: 2019.4.5f1
m_EditorVersionWithRevision: 2019.4.5f1 (81610f64359c)

Loading…
Cancel
Save