mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Roll ModuleAdvancedLookAtConstraint into ReStock
This commit is contained in:
parent
084e10aeb0
commit
073b7d2948
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
MODULE
|
MODULE
|
||||||
{
|
{
|
||||||
name = ModuleAdvancedLookAtConstraint
|
name = ModuleRestockLookAtConstraint
|
||||||
|
|
||||||
CONSTRAINLOOKFX
|
CONSTRAINLOOKFX
|
||||||
{
|
{
|
||||||
@ -241,7 +241,7 @@
|
|||||||
|
|
||||||
MODULE
|
MODULE
|
||||||
{
|
{
|
||||||
name = ModuleAdvancedLookAtConstraint
|
name = ModuleRestockLookAtConstraint
|
||||||
|
|
||||||
CONSTRAINLOOKFX
|
CONSTRAINLOOKFX
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
@ -138,7 +138,7 @@ PART
|
|||||||
|
|
||||||
MODULE
|
MODULE
|
||||||
{
|
{
|
||||||
name = ModuleAdvancedLookAtConstraint
|
name = ModuleRestockLookAtConstraint
|
||||||
|
|
||||||
CONSTRAINLOOKFX
|
CONSTRAINLOOKFX
|
||||||
{
|
{
|
||||||
|
@ -235,7 +235,7 @@ PART
|
|||||||
|
|
||||||
MODULE
|
MODULE
|
||||||
{
|
{
|
||||||
name = ModuleAdvancedLookAtConstraint
|
name = ModuleRestockLookAtConstraint
|
||||||
|
|
||||||
CONSTRAINLOOKFX
|
CONSTRAINLOOKFX
|
||||||
{
|
{
|
||||||
|
95
Source/Restock/ModuleRestockLookAtConstraint.cs
Normal file
95
Source/Restock/ModuleRestockLookAtConstraint.cs
Normal file
@ -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="ModuleRestockDepthMask.cs" />
|
||||||
<Compile Include="ModuleRestockHeatEffects.cs" />
|
<Compile Include="ModuleRestockHeatEffects.cs" />
|
||||||
<Compile Include="ModuleRestockISRUAnimation.cs" />
|
<Compile Include="ModuleRestockISRUAnimation.cs" />
|
||||||
|
<Compile Include="ModuleRestockLookAtConstraint.cs" />
|
||||||
<Compile Include="ModuleRestockModifyFairingMaterials.cs" />
|
<Compile Include="ModuleRestockModifyFairingMaterials.cs" />
|
||||||
<Compile Include="ModuleRestockModifyMaterials.cs" />
|
<Compile Include="ModuleRestockModifyMaterials.cs" />
|
||||||
<Compile Include="PartModuleExtensions.cs" />
|
<Compile Include="PartModuleExtensions.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user