Пример #1
0
        public static PropHatch LoadPropHatchFromCfg(ConfigNode node)
        {
            Vector3 position = Vector3.zero;
            Vector3 scale    = Vector3.one;

            if (!node.HasValue("closedPropIndex"))
            {
                Debug.LogWarning("[FreeIVA] Prop hatch closedPropIndex not found: Skipping hatch.");
                return(null);
            }
            PropHatch propHatch = new PropHatch();

            propHatch.ClosedPropIndex = int.Parse(node.GetValue("closedPropIndex"));

            if (node.HasValue("closedPropName"))
            {
                propHatch.ClosedPropName = node.GetValue("closedPropName");
            }

            if (node.HasValue("openPropName"))
            {
                propHatch.OpenPropName = node.GetValue("openPropName");
            }

            if (node.HasValue("attachNodeId"))
            {
                propHatch.AttachNodeId = node.GetValue("attachNodeId");
            }

            if (node.HasValue("position"))
            {
                string   posString = node.GetValue("position");
                string[] p         = posString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries);
                if (p.Length != 3)
                {
                    Debug.LogWarning("[FreeIVA] Invalid prop hatch position definition \"" + posString + "\": Must be in the form x, y, z.");
                    return(null);
                }
                else
                {
                    propHatch.LocalPosition = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2]));
                }
            }
            else
            {
                Debug.LogWarning("[FreeIVA] PropHatch does not have a position");
            }
            Debug.Log("# PropHatch position: " + propHatch.LocalPosition);

            if (node.HasValue("scale"))
            {
                string   scaleString = node.GetValue("scale");
                string[] s           = scaleString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries);
                if (s.Length != 3)
                {
                    Debug.LogWarning("[FreeIVA] Invalid prop hatch scale definition \"" + scaleString + "\": Must be in the form x, y, z.");
                    return(null);
                }
                else
                {
                    propHatch.Scale = new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2]));
                }
            }

            if (node.HasValue("rotation"))
            {
                string   rotationString = node.GetValue("rotation");
                string[] s = rotationString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries);
                if (s.Length != 3)
                {
                    Debug.LogWarning("[FreeIVA] Invalid prop hatch rotation definition \"" + rotationString + "\": Must be in the form x, y, z.");
                    return(null);
                }
                else
                {
                    propHatch.Rotation = Quaternion.Euler(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2]));
                }
            }

            if (node.HasValue("HatchOpenSoundFile"))
            {
                propHatch.HatchOpenSoundFile = node.GetValue("HatchOpenSoundFile");
            }
            if (node.HasValue("HatchCloseSoundFile"))
            {
                propHatch.HatchCloseSoundFile = node.GetValue("HatchCloseSoundFile");
            }

            if (node.HasNode("HideWhenOpen"))
            {
                ConfigNode[] hideNodes = node.GetNodes("HideWhenOpen");
                foreach (var hideNode in hideNodes)
                {
                    if (!hideNode.HasValue("name"))
                    {
                        Debug.LogWarning("[FreeIVA] HideWhenOpen name not found.");
                        continue;
                    }
                    string propName = hideNode.GetValue("name");

                    if (hideNode.HasValue("position"))
                    {
                        string   posString = hideNode.GetValue("position");
                        string[] p         = posString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries);
                        if (p.Length != 3)
                        {
                            Debug.LogWarning("[FreeIVA] Invalid HideWhenOpen position definition \"" + posString + "\": Must be in the form x, y, z.");
                            continue;
                        }
                        else
                        {
                            Vector3 propPos = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2]));
                            propHatch.HideWhenOpen.Add(new KeyValuePair <Vector3, string>(propPos, propName));
                        }
                    }
                }
            }

            if (node.HasNode("InternalCollider"))
            {
                ConfigNode hatchColliderNode = node.GetNode("InternalCollider");
                if (hatchColliderNode != null)
                {
                    propHatch.Collider = InternalCollider.LoadFromCfg(hatchColliderNode);
                }
            }
            return(propHatch);
        }
Пример #2
0
        public override void OnLoad(ConfigNode node)
        {
            if (node.HasNode("Hatch"))
            {
                ConfigNode[] hatchNodes = node.GetNodes("Hatch");
                foreach (var hn in hatchNodes)
                {
                    IHatch h = Hatch.LoadFromCfg(hn);
                    if (h != null)
                    {
                        Hatches.Add(h);
                    }
                }
                PersistenceManager.instance.AddHatches(part.name, Hatches);
            }
            Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count);

            if (node.HasNode("PropHatch"))
            {
                ConfigNode[] propHatchNodes = node.GetNodes("PropHatch");
                foreach (var phn in propHatchNodes)
                {
                    PropHatch ph = PropHatch.LoadPropHatchFromCfg(phn);
                    if (ph != null)
                    {
                        Hatches.Add(ph);
                    }
                }
                PersistenceManager.instance.AddHatches(part.name, Hatches);
            }

            if (node.HasNode("MeshHatch"))
            {
                ConfigNode[] meshHatchNodes = node.GetNodes("MeshHatch");
                foreach (var mhn in meshHatchNodes)
                {
                    MeshHatch mh = MeshHatch.LoadMeshHatchFromCfg(mhn);
                    if (mh != null)
                    {
                        Hatches.Add(mh);
                    }
                }
                PersistenceManager.instance.AddHatches(part.name, Hatches);
            }
            //if (node.HasNode("PropHatchAnimated"))
            //{
            //    ConfigNode[] propHatchAnimatedNodes = node.GetNodes("PropHatchAnimated");
            //    foreach (var phan in propHatchAnimatedNodes)
            //    {
            //        PropHatchAnimated pha = PropHatchAnimated.LoadPropHatchFromCfg(phan);
            //        if (pha != null)
            //        {
            //            Hatches.Add(pha);
            //            if (pha.Collider != null)
            //                InternalColliders.Add(pha.Collider);
            //        }
            //    }
            //    PersistenceManager.instance.AddHatches(part.name, Hatches);
            //}
            Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count);

            if (node.HasNode("InternalCollider"))
            {
                ConfigNode[] colliderNodes = node.GetNodes("InternalCollider");
                foreach (var cn in colliderNodes)
                {
                    InternalCollider ic = InternalCollider.LoadFromCfg(cn);
                    if (ic != null)
                    {
                        InternalColliders.Add(ic);
                    }
                }
                PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders);
                Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count);
            }
            else if (InternalColliders != null && InternalColliders.Count > 0)
            {
                PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders);
                Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count);
            }
        }