lonestar

0x10c-inspired space game based on the DCPU-16
git clone git://squid-tech.com/lonestar.git
Log | Files | Refs | README

commit b416757a32cc34158b07f02e54d1447add5a74ca
parent b74148a1db5dca33caa9ade030c96fa0e9d5bdf0
Author: Josh Moore <jxm5210@rit.edu>
Date:   Sun, 24 Nov 2019 21:35:02 -0500

Load ship XML files into the game

Diffstat:
Msrc/LoneStar/Assets/Materials/FrameMaterial.mat | 4++--
Msrc/LoneStar/Assets/Materials/ScreenMaterial.mat | 4+++-
Asrc/LoneStar/Assets/Resources/ShipParts.meta | 8++++++++
Asrc/LoneStar/Assets/Resources/ShipParts/default.meta | 8++++++++
Asrc/LoneStar/Assets/Resources/ShipParts/default/HULL.prefab | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/LoneStar/Assets/Resources/ShipParts/default/HULL.prefab.meta | 7+++++++
Msrc/LoneStar/Assets/Scripts/PlayerController.cs | 6++++++
Asrc/LoneStar/Assets/Scripts/ShipLoader.cs | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/LoneStar/Assets/Scripts/ShipLoader.cs.meta | 11+++++++++++
9 files changed, 241 insertions(+), 3 deletions(-)

diff --git a/src/LoneStar/Assets/Materials/FrameMaterial.mat b/src/LoneStar/Assets/Materials/FrameMaterial.mat @@ -71,7 +71,7 @@ Material: - _GlossMapScale: 1 - _Glossiness: 0.5 - _GlossyReflections: 0 - - _Metallic: 0 + - _Metallic: 0.306 - _Mode: 0 - _OcclusionStrength: 1 - _Outline: 0.004 @@ -82,6 +82,6 @@ Material: - _UVSec: 0 - _ZWrite: 1 m_Colors: - - _Color: {r: 0.5283019, g: 0.33984333, b: 0, a: 1} + - _Color: {r: 0.5943396, g: 0.5694197, b: 0.5242524, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/src/LoneStar/Assets/Materials/ScreenMaterial.mat b/src/LoneStar/Assets/Materials/ScreenMaterial.mat @@ -90,8 +90,9 @@ Material: - _Metallic: 0 - _Mode: 0 - _OcclusionStrength: 1 + - _Outline: 0.005 - _Parallax: 0.02 - - _Shininess: 0.078125 + - _Shininess: 0.01 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 @@ -100,5 +101,6 @@ Material: m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _OutlineColor: {r: 0, g: 0, b: 0, a: 1} - _ReflectColor: {r: 1, g: 1, b: 1, a: 0.5} - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1} diff --git a/src/LoneStar/Assets/Resources/ShipParts.meta b/src/LoneStar/Assets/Resources/ShipParts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e1e56456caace78448342a81fe5d915a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/LoneStar/Assets/Resources/ShipParts/default.meta b/src/LoneStar/Assets/Resources/ShipParts/default.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 66b53b994b4bd7f4c8ab1669f45b5055 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/LoneStar/Assets/Resources/ShipParts/default/HULL.prefab b/src/LoneStar/Assets/Resources/ShipParts/default/HULL.prefab @@ -0,0 +1,94 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4054225631670465291 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4054225631670465287} + - component: {fileID: 4054225631670465286} + - component: {fileID: 4054225631670465289} + - component: {fileID: 4054225631670465288} + m_Layer: 0 + m_Name: HULL + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4054225631670465287 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4054225631670465291} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -1.959, y: 1.52, z: 4.14} + m_LocalScale: {x: 0.1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &4054225631670465286 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4054225631670465291} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &4054225631670465289 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4054225631670465291} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!65 &4054225631670465288 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4054225631670465291} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} diff --git a/src/LoneStar/Assets/Resources/ShipParts/default/HULL.prefab.meta b/src/LoneStar/Assets/Resources/ShipParts/default/HULL.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 241fc7d3d329aa74e8f27eb226333a08 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/LoneStar/Assets/Scripts/PlayerController.cs b/src/LoneStar/Assets/Scripts/PlayerController.cs @@ -12,10 +12,16 @@ public class PlayerController : NetworkBehaviour { if (!isLocalPlayer) { + // SERVER // prevent duplicate cameras and audio listeners in clients gameObject.GetComponent<Camera>().enabled = false; gameObject.GetComponent<AudioListener>().enabled = false; } + + // load the player's ship + ShipLoader loader = new ShipLoader("default"); + + loader.loadShip(GameObject.Find("Ships"), this); } void OnGUI() diff --git a/src/LoneStar/Assets/Scripts/ShipLoader.cs b/src/LoneStar/Assets/Scripts/ShipLoader.cs @@ -0,0 +1,102 @@ +´╗┐using System.Collections; +using System.Collections.Generic; +using System.Xml.Linq; +using System; +using UnityEngine; +using Mirror; + +public class ShipLoader +{ + // how much to scale loaded walls, etc by + const float SHIP_SCALE = 3; + + string shipname; + + List<Vector3> hullPoints; + List<string> hullTypes; + + + // objects + GameObject HULL_DEFAULT = Resources.Load<GameObject>("ShipParts/default/HULL"); + + public ShipLoader(string name) + { + this.shipname = name; + } + + // Load ship XML from a file, assemble the ship, then place the player inside their ship + //\TODO server-side this, so the player sends their XML and the server handles it + public void loadShip(GameObject ships, PlayerController player) + { + hullPoints = new List<Vector3>(); + hullTypes = new List<string>(); + + XElement shipRoot; + + if (Application.isEditor) + { + shipRoot = XElement.Load("Build/Ships/" + shipname + ".ship"); + } + else + { + shipRoot = XElement.Load("Ships/" + shipname + ".ship"); + } + + XElement hull = shipRoot.Element("hull"); + + // load hull points + foreach (XElement wall in hull.Elements()) + { + string type = wall.Attribute("type").Value; + int posX = Int32.Parse(wall.Attribute("posX").Value); + int posY = Int32.Parse(wall.Attribute("posY").Value); + + hullPoints.Add(new Vector3(posX * SHIP_SCALE, 0, posY * SHIP_SCALE)); + hullTypes.Add(type); + } + + float avgX = 0; + float avgY = 0; + + foreach (Vector3 p in hullPoints) + { + avgX = avgX + p.x; + avgY = avgY + p.z; + } + + avgX = avgX / hullPoints.Count; + avgY = avgY / hullPoints.Count; + + GameObject shipObject = new GameObject(); + shipObject.name = shipname; + shipObject.transform.position = new Vector3(avgX, -SHIP_SCALE / 2, avgY); + + // create hull walls + for (int i = 0; i < hullPoints.Count - 1; i++) + { + // calculate angle between wall pieces + Vector3 offs = (hullPoints[i] - hullPoints[i + 1]); + float angle = Vector3.SignedAngle(offs, new Vector3(0,0,1), new Vector3(0, -1, 0)); + + GameObject wallObject = UnityEngine.Object.Instantiate(HULL_DEFAULT, (hullPoints[i] + hullPoints[i + 1]) / 2, Quaternion.identity); + + // scale wall based on whether it's a corner piece or not + if (Math.Abs(angle) % 90 == 45) + { + wallObject.transform.localScale = new Vector3(0.1f, SHIP_SCALE, (float)(SHIP_SCALE * Math.Sqrt(2))); + } + else + { + wallObject.transform.localScale = new Vector3(0.1f, SHIP_SCALE, SHIP_SCALE); + } + + // parent the wall to the ship object + wallObject.transform.eulerAngles = new Vector3(0, angle, 0); + wallObject.transform.parent = shipObject.transform; + } + + // parent the ship to the Ships object + shipObject.transform.position = new Vector3(0, 0, 0); + shipObject.transform.parent = ships.transform; + } +} diff --git a/src/LoneStar/Assets/Scripts/ShipLoader.cs.meta b/src/LoneStar/Assets/Scripts/ShipLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ce1ad38f8f8d6d1418577a32b4272fcc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: