Roll ModuleAdvancedLookAtConstraint into ReStock

pull/822/head
Andrew Cassidy 4 years ago
parent 084e10aeb0
commit 073b7d2948
No known key found for this signature in database
GPG Key ID: 963017B38FD477A1

@ -32,7 +32,7 @@
MODULE
{
name = ModuleAdvancedLookAtConstraint
name = ModuleRestockLookAtConstraint
CONSTRAINLOOKFX
{
@ -241,7 +241,7 @@
MODULE
{
name = ModuleAdvancedLookAtConstraint
name = ModuleRestockLookAtConstraint
CONSTRAINLOOKFX
{

@ -138,7 +138,7 @@ PART
MODULE
{
name = ModuleAdvancedLookAtConstraint
name = ModuleRestockLookAtConstraint
CONSTRAINLOOKFX
{

@ -235,7 +235,7 @@ PART
MODULE
{
name = ModuleAdvancedLookAtConstraint
name = ModuleRestockLookAtConstraint
CONSTRAINLOOKFX
{

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Restock
{
public class ModuleRestockLookAtConstraint : PartModule
{
[System.Serializable]
public class LookConstraint
{
string rotatorsName;
string targetName;
// Cached components
Transform target;
Transform rotator;
Part part;
public LookConstraint(ConfigNode node, Part p)
{
node.TryGetValue("rotatorsName", ref rotatorsName);
node.TryGetValue("targetName", ref targetName);
part = p;
rotator = p.FindModelTransform(rotatorsName);
target = p.FindModelTransform(targetName);
}
public void UpdateRotators()
{
if (rotator != null && target != null)
{
Vector3 targetPostition = new Vector3(target.position.x,
target.position.y,
target.position.z);
Vector3 lookPos = target.position - rotator.position;
var rotation = Quaternion.LookRotation(lookPos, target.up);
rotator.rotation = rotation;
}
}
}
public List<LookConstraint> constraints;
public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);
constraints = new List<LookConstraint>();
ConfigNode[] cnodes = node.GetNodes("CONSTRAINLOOKFX");
Debug.Log(String.Format("[ModuleAdvancedLookAtConstraint]: Loading {0} constraints", cnodes.Length));
for (int i = 0; i < cnodes.Length; i++)
{
constraints.Add(new LookConstraint(cnodes[i], this.part));
}
Debug.Log(String.Format("[ModuleAdvancedLookAtConstraint]: Loaded {0} constraints", constraints.Count));
}
public override void OnStart(StartState state)
{
if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor)
{
if (constraints == null || constraints.Count == 0)
{
ConfigNode cfg;
foreach (UrlDir.UrlConfig pNode in GameDatabase.Instance.GetConfigs("PART"))
{
if (pNode.name.Replace("_", ".") == part.partInfo.name)
{
cfg = pNode.config;
ConfigNode node = cfg.GetNodes("MODULE").Single(n => n.GetValue("name") == moduleName);
OnLoad(node);
}
}
}
}
}
void LateUpdate()
{
if (constraints != null)
{
for (int i = 0; i < constraints.Count; i++)
{
constraints[i].UpdateRotators();
}
}
}
}
}

@ -55,6 +55,7 @@
<Compile Include="ModuleRestockDepthMask.cs" />
<Compile Include="ModuleRestockHeatEffects.cs" />
<Compile Include="ModuleRestockISRUAnimation.cs" />
<Compile Include="ModuleRestockLookAtConstraint.cs" />
<Compile Include="ModuleRestockModifyFairingMaterials.cs" />
<Compile Include="ModuleRestockModifyMaterials.cs" />
<Compile Include="PartModuleExtensions.cs" />

Loading…
Cancel
Save