private void Start()
        {
            m_parent = transform.GetComponentInParent <S_SnapToObject>();
            if (m_parent == null)
            {
                Debug.LogError("LE_GUISnapButtonParticleSys: could not find S_SnapToObject in parent.");
                Destroy(this);
                return;
            }
            ParticleSystem particleSys = GetComponent <ParticleSystem>();

            if (particleSys == null)
            {
                Debug.LogError("LE_GUISnapButtonParticleSys: could not find ParticleSystem.");
                Destroy(this);
                return;
            }
            m_particleSysRenderer = particleSys.GetComponent <Renderer>();
            if (m_particleSysRenderer == null)
            {
                Debug.LogError("LE_GUISnapButtonParticleSys: could not find Renderer for ParticleSystem.");
                Destroy(this);
                return;
            }
            m_particleSysRenderer.sharedMaterial = m_closedMaterial;
        }
示例#2
0
 public void LoadSnapCounter(string snapPointUID, S_SnapToObject snapInstance)
 {
     if (m_snapPointUIDsToObjUIDs.ContainsKey(snapPointUID))
     {
         snapInstance.IncSnapCounter();
     }
 }
示例#3
0
 public static void AddObjectSnapping(LE_GUI3dObject p_gui3d, LE_Object p_newObject)
 {
     for (int j = 0; j < p_newObject.ObjectSnapPoints.Length; j++)
     {
         if (p_newObject.ObjectSnapPoints[j] != null)
         {
             Material matLine = null;
             Material matFill = null;
             if (p_newObject.IsDrawSnapToObjectUI)
             {
                 matLine = (Material)Resources.Load("SnapToObjectUIMaterial_Line");
                 matFill = (Material)Resources.Load("SnapToObjectUIMaterial_Fill");
             }
             S_SnapToObject snapInstance = p_newObject.ObjectSnapPoints[j].InstatiateSnapSystem((GameObject)GameObject.Instantiate(Resources.Load("ObjectSnapButtonVisuals")), p_newObject.IsDrawSnapToObjectUI, matLine, matFill);
             if (snapInstance != null)
             {
                 string snapPointUID = GetSnapPointUID(p_newObject.UID, j);
                 p_gui3d.AddSnapPoint(snapPointUID, snapInstance);
                 // deactivate if snap UI is hidden right now
                 if (!p_gui3d.IsSnapToObjectActive)
                 {
                     snapInstance.gameObject.SetActive(false);
                 }
                 // restore the already snapped object states
                 p_gui3d.LoadSnapCounter(snapPointUID, snapInstance);
             }
         }
         else
         {
             Debug.LogError("LE_GUI3dObject: AddObjectSnapping: object '" + p_newObject.name + "' has a nullpointer in the ObjectSnapPoints array at index '" + j + "'!");
         }
     }
 }
示例#4
0
 public void AddSnapPoint(string p_snapPointUID, S_SnapToObject p_snapInstance)
 {
     if (!m_snapPointUIDsToSnapPoints.ContainsKey(p_snapPointUID))
     {
         m_snapPointUIDsToSnapPoints.Add(p_snapPointUID, p_snapInstance);
     }
     else
     {
         Debug.LogError("LE_GUI3dObject: AddSnapPoint: a snap point instance with the UID '" + p_snapPointUID + "' already exists!");
     }
 }
示例#5
0
 public static void DestroySnapSystem(S_SnapToObject p_system)
 {
     if (p_system != null)
     {
         GameObject.Destroy(p_system);
         GameObject.Destroy(p_system.GetComponent <SphereCollider>());
         Transform[] transforms = p_system.GetComponentsInChildren <Transform>(true);
         for (int i = 0; i < transforms.Length; i++)
         {
             if (transforms[i].name == BUTTON_VISUALS_NAME)
             {
                 GameObject.Destroy(transforms[i].gameObject);
             }
         }
     }
 }
示例#6
0
        public S_SnapToObject InstatiateSnapSystem(GameObject p_buttonVisuals, bool p_isDrawUI, Material p_materialLine, Material p_materialFill)
        {
            // check params
            if (m_point == null)
            {
                Debug.LogError("LE_ObjectSnapPoint: InstatiateSnapSystem: the Transform property 'Point' is null! Set it in the inspector!");
                return(null);
            }
            if (m_prefabs == null || m_prefabs.Length == 0)
            {
                Debug.LogError("LE_ObjectSnapPoint: InstatiateSnapSystem: the Prefabs property array is null or has no entries!");
                return(null);
            }
            // instantiate S_SnapToObject system
            if (m_snapSysInstance != null)
            {
                Debug.LogError("LE_ObjectSnapPoint: InstatiateSnapSystem: the system was already initialized!");
                GameObject.Destroy(m_snapSysInstance);
            }
            m_snapSysInstance         = Point.gameObject.AddComponent <S_SnapToObject>();
            m_snapSysInstance.Prefabs = Prefabs;
            m_snapSysInstance.IsDeactivatedAfterSnap = true;
            m_snapSysInstance.IsDestroyedAfterSnap   = false;
            m_snapSysInstance.IsDrawUI       = p_isDrawUI;
            m_snapSysInstance.UImaterialLine = p_materialLine;
            m_snapSysInstance.UImaterialFill = p_materialFill;
            // create the snap button
            SphereCollider btnCollider = Point.gameObject.AddComponent <SphereCollider>();

            btnCollider.radius = SnapButtonSize * 0.5f;
            btnCollider.center = SnapButtonLocalOffset;
            // place snap button visuals at the right place
            p_buttonVisuals.name = BUTTON_VISUALS_NAME;             // name has to be constant to allow destruction
            if (p_buttonVisuals != null)
            {
                p_buttonVisuals.transform.parent        = Point;
                p_buttonVisuals.transform.localPosition = m_snapButtonLocalOffset;
                p_buttonVisuals.transform.localScale    = Vector3.one * m_snapButtonSize;
                p_buttonVisuals.transform.localRotation = Quaternion.identity;
            }
            else
            {
                Debug.LogWarning("LE_ObjectSnapPoint: InstatiateSnapSystem: p_buttonVisuals is null! The snap button will be invisible for the user!");
            }
            return(m_snapSysInstance);
        }
示例#7
0
 private int GetSnapPointIndex(LE_Object p_obj, S_SnapToObject p_snapScript)
 {
     if (p_obj != null)
     {
         for (int i = 0; i < p_obj.ObjectSnapPoints.Length; i++)
         {
             if (p_obj.ObjectSnapPoints[i].SnapSystemInstance == p_snapScript)
             {
                 return(i);
             }
         }
         Debug.LogError("LE_GUI3dObject: GetSnapPointIndex: p_snapScript is not a SnapSystemInstance of p_obj!");
         return(-1);
     }
     else
     {
         Debug.LogError("LE_GUI3dObject: GetSnapPointIndex: p_obj is null!");
         return(-1);
     }
 }
示例#8
0
        public override bool Execute()
        {
            if (!base.Execute())
            {
                return(false);
            }

            if (m_snapPrefab == null)
            {
                Debug.LogError("LE_CmdSnapObjectToObject: Execute: could not execute, m_snapPrefab is null!");
                return(false);
            }

            if (m_sourceObj.Obj == null)
            {
                Debug.LogError("LE_CmdSnapObjectToObject: Execute: could not execute, m_sourceObj is null!");
                return(false);
            }

            if (m_sourceSnapPointIndex >= m_sourceObj.Obj.ObjectSnapPoints.Length)
            {
                Debug.LogError("LE_CmdSnapObjectToObject: Execute: could not execute, m_sourceSnapPointIndex('" + m_sourceSnapPointIndex + "') is not a valid[0," + (m_sourceObj.Obj.ObjectSnapPoints.Length - 1) + "] snap point index!");
                return(false);
            }

            S_SnapToObject snapSys = m_sourceObj.Obj.ObjectSnapPoints[m_sourceSnapPointIndex].SnapSystemInstance;

            if (snapSys == null)
            {
                Debug.LogError("LE_CmdSnapObjectToObject: Execute: could not execute, m_sourceSnapPointIndex('" + m_sourceSnapPointIndex + "') leads to a null SnapSystemInstance!");
                return(false);
            }

            snapSys.OnAfterObjectSnapped += OnAfterObjectSnapped;
            snapSys.PlacePrefab(m_snapPrefab);
            snapSys.OnAfterObjectSnapped -= OnAfterObjectSnapped;

            return(true);
        }
示例#9
0
 public void MarkSnapPointAsUsed(LE_Object p_sourceObj, LE_Object p_destinationObj, S_SnapToObject p_snapScript)
 {
     if (p_sourceObj != null)
     {
         int snapPointIndex = GetSnapPointIndex(p_sourceObj, p_snapScript);
         MarkSnapPointAsUsed(p_sourceObj, p_destinationObj, snapPointIndex);
     }
     else
     {
         Debug.LogError("LE_GUI3dObject: MarkSnapPointAsUsed: could not find LE_Object of snap source!");
     }
 }